From be881725b39926f62df437c2805ac9203fea5737 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Tue, 11 Oct 2016 19:19:20 +0300 Subject: [PATCH 001/311] gg-11595 : WIP. --- .../cache/DynamicCacheChangeRequest.java | 4 ++ .../processors/cache/GridCacheProcessor.java | 42 +++++++++++++++---- .../processors/cache/IgniteCacheProxy.java | 26 ++++++++++-- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java index ee2755f136159..917b6d1f76eb7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java @@ -217,6 +217,10 @@ public void stop(boolean stop) { this.stop = stop; } + public boolean restart() { + return true; + } + /** * @return Cache name. */ 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 e3c567912cfad..823a0d8a6a9b6 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 @@ -437,12 +437,12 @@ private void validate(IgniteConfiguration c, else if (cc.getRebalanceMode() == SYNC) { if (delay < 0) { U.warn(log, "Ignoring SYNC rebalance mode with manual rebalance start (node will not wait for " + - "rebalancing to be finished): " + U.maskName(cc.getName()), + "rebalancing to be finished): " + U.maskName(cc.getName()), "Node will not wait for rebalance in SYNC mode: " + U.maskName(cc.getName())); } else { U.warn(log, "Using SYNC rebalance mode with rebalance delay (node will wait until rebalancing is " + - "initiated for " + delay + "ms) for cache: " + U.maskName(cc.getName()), + "initiated for " + delay + "ms) for cache: " + U.maskName(cc.getName()), "Node will wait until rebalancing is initiated for " + delay + "ms for cache: " + U.maskName(cc.getName())); } } @@ -563,7 +563,7 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near if (!F.isEmpty(ctx.config().getCacheConfiguration())) { if (depMode != CONTINUOUS && depMode != SHARED) U.warn(log, "Deployment mode for cache is not CONTINUOUS or SHARED " + - "(it is recommended that you change deployment mode and restart): " + depMode, + "(it is recommended that you change deployment mode and restart): " + depMode, "Deployment mode for cache is not CONTINUOUS or SHARED."); } @@ -1785,8 +1785,12 @@ public void blockGateway(DynamicCacheChangeRequest req) { IgniteCacheProxy proxy = jCacheProxies.get(maskNull(req.cacheName())); if (proxy != null) { - if (req.stop()) + if (req.stop()) { + if (req.restart()) + proxy.restart(); + proxy.gate().stopped(); + } else proxy.closeProxy(); } @@ -1799,8 +1803,16 @@ public void blockGateway(DynamicCacheChangeRequest req) { private void stopGateway(DynamicCacheChangeRequest req) { assert req.stop() : req; + IgniteCacheProxy proxy; + // Break the proxy before exchange future is done. - IgniteCacheProxy proxy = jCacheProxies.remove(maskNull(req.cacheName())); + if (req.restart()) { + proxy = jCacheProxies.get(maskNull(req.cacheName())); + + proxy.restart(); + } + else + proxy = jCacheProxies.remove(maskNull(req.cacheName())); if (proxy != null) proxy.gate().onStopped(); @@ -1849,7 +1861,12 @@ public void onExchangeDone( String masked = maskNull(cacheCtx.name()); - jCacheProxies.put(masked, new IgniteCacheProxy(cache.context(), cache, null, false)); + IgniteCacheProxy existing = jCacheProxies.get(masked); + + if (existing != null && existing.isRestarting()) + existing.onRestarted(cache.context(), cache); + else + jCacheProxies.put(masked, new IgniteCacheProxy(cache.context(), cache, null, false)); } } @@ -1869,10 +1886,19 @@ else if (req.close() && req.initiatingNodeId().equals(ctx.localNodeId())) { if (proxy.context().affinityNode()) { GridCacheAdapter cache = caches.get(masked); - if (cache != null) - jCacheProxies.put(masked, new IgniteCacheProxy(cache.context(), cache, null, false)); + if (cache != null) { + IgniteCacheProxy existing = jCacheProxies.get(masked); + + if (existing != null && existing.isRestarting()) + existing.onRestarted(cache.context(), cache); + else + jCacheProxies.put(masked, new IgniteCacheProxy(cache.context(), cache, null, false)); + } } else { + if (req.restart()) + proxy.restart(); + proxy.context().gate().onStopped(); prepareCacheStop(req); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index a999062cc47f1..4180265a49b10 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -108,14 +108,14 @@ public class IgniteCacheProxy extends AsyncSupportAdapter ctx; + private volatile GridCacheContext ctx; /** Gateway. */ - private GridCacheGateway gate; + private volatile GridCacheGateway gate; /** Delegate. */ @GridToStringInclude - private IgniteInternalCache delegate; + private volatile IgniteInternalCache delegate; /** Operation context. */ private CacheOperationContext opCtx; @@ -132,6 +132,8 @@ public class IgniteCacheProxy extends AsyncSupportAdapter(ctx, delegate, opCtx); + + restarting = false; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(IgniteCacheProxy.class, this); From e6d82d8da50b9af9607a914e00da3937d839862a Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Wed, 12 Oct 2016 19:20:50 +0300 Subject: [PATCH 002/311] gg-11595 : WIP. --- .../IgniteCacheRestartingException.java | 60 +++++++++++++++++++ .../processors/cache/GridCacheProcessor.java | 27 ++++----- .../processors/cache/IgniteCacheProxy.java | 27 +++++++-- 3 files changed, 93 insertions(+), 21 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java b/modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java new file mode 100644 index 0000000000000..2e78411de9a3f --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java @@ -0,0 +1,60 @@ +/* + * 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; + +import org.apache.ignite.lang.IgniteFuture; +import org.jetbrains.annotations.Nullable; + +public class IgniteCacheRestartingException extends IgniteException { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final IgniteFuture restartFut; + + /** + * @param restartFut Restart future. + * @param msg Error message. + */ + public IgniteCacheRestartingException(IgniteFuture restartFut, String msg) { + this(restartFut, msg, null); + } + + /** + * @param restartFut Restart future. + * @param msg Error message. + * @param cause Optional nested exception (can be {@code null}). + */ + public IgniteCacheRestartingException( + IgniteFuture restartFut, + String msg, + @Nullable Throwable cause) { + super(msg, cause); + + this.restartFut = restartFut; + } + + /** + * @return Future that will be completed when cache is restarted. + */ + public IgniteFuture restartFuture() { + return restartFut; + } + +} 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 823a0d8a6a9b6..c8e756d8dc9c1 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 @@ -164,7 +164,7 @@ public class GridCacheProcessor extends GridProcessorAdapter { private final Map stoppedCaches = new ConcurrentHashMap<>(); /** Map of proxies. */ - private final Map> jCacheProxies; + private final ConcurrentMap> jCacheProxies; /** Caches stop sequence. */ private final Deque stopSeq; @@ -1743,13 +1743,16 @@ private void prepareCacheStart( ClusterNode locNode = ctx.discovery().localNode(); + IgniteCacheProxy proxy = jCacheProxies.get(maskNull(cfg.getName())); + boolean affNodeStart = !clientStartOnly && CU.affinityNode(locNode, nodeFilter); boolean clientNodeStart = locNode.id().equals(initiatingNodeId); + boolean proxyRestart = proxy != null && proxy.isRestarting() && !caches.containsKey(maskNull(cfg.getName())); if (sharedCtx.cacheContext(CU.cacheId(cfg.getName())) != null) return; - if (affNodeStart || clientNodeStart) { + if (affNodeStart || clientNodeStart || proxyRestart) { if (clientNodeStart && !affNodeStart) { if (nearCfg != null) ccfg.setNearConfiguration(nearCfg); @@ -1771,6 +1774,9 @@ private void prepareCacheStart( startCache(cacheCtx.cache()); onKernalStart(cacheCtx.cache()); + + if (proxyRestart) + proxy.onRestarted(cacheCtx, cacheCtx.cache()); } } @@ -1861,12 +1867,7 @@ public void onExchangeDone( String masked = maskNull(cacheCtx.name()); - IgniteCacheProxy existing = jCacheProxies.get(masked); - - if (existing != null && existing.isRestarting()) - existing.onRestarted(cache.context(), cache); - else - jCacheProxies.put(masked, new IgniteCacheProxy(cache.context(), cache, null, false)); + jCacheProxies.putIfAbsent(masked, new IgniteCacheProxy(cache.context(), cache, null, false)); } } @@ -1886,14 +1887,8 @@ else if (req.close() && req.initiatingNodeId().equals(ctx.localNodeId())) { if (proxy.context().affinityNode()) { GridCacheAdapter cache = caches.get(masked); - if (cache != null) { - IgniteCacheProxy existing = jCacheProxies.get(masked); - - if (existing != null && existing.isRestarting()) - existing.onRestarted(cache.context(), cache); - else - jCacheProxies.put(masked, new IgniteCacheProxy(cache.context(), cache, null, false)); - } + if (cache != null) + jCacheProxies.putIfAbsent(masked, new IgniteCacheProxy(cache.context(), cache, null, false)); } else { if (req.restart()) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index 4180265a49b10..38837f0135905 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -30,6 +30,8 @@ import java.util.NoSuchElementException; import java.util.Set; import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.Lock; import javax.cache.Cache; import javax.cache.CacheException; @@ -41,6 +43,7 @@ import javax.cache.processor.EntryProcessorException; import javax.cache.processor.EntryProcessorResult; import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCacheRestartingException; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.cache.CacheEntry; @@ -69,6 +72,7 @@ import org.apache.ignite.internal.processors.query.GridQueryProcessor; import org.apache.ignite.internal.util.GridCloseableIteratorAdapter; import org.apache.ignite.internal.util.GridEmptyIterator; +import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.future.IgniteFutureImpl; import org.apache.ignite.internal.util.lang.GridCloseableIterator; import org.apache.ignite.internal.util.lang.GridClosureException; @@ -132,7 +136,7 @@ public class IgniteCacheProxy extends AsyncSupportAdapter> restartFut = new AtomicReference<>(null); /** * Empty constructor required for {@link Externalizable}. @@ -533,7 +537,7 @@ private QueryCursor query( if (needToConvert) { Map.Entry entry = (Map.Entry)next; - return (R) new CacheEntryImpl<>(entry.getKey(), entry.getValue()); + return (R)new CacheEntryImpl<>(entry.getKey(), entry.getValue()); } return (R)next; @@ -2157,6 +2161,11 @@ public void closeProxy() { * @return Previous projection set on this thread. */ private CacheOperationContext onEnter(GridCacheGateway gate, CacheOperationContext opCtx) { + GridFutureAdapter restartFut = this.restartFut.get(); + + if (restartFut != null && !restartFut.isDone()) + throw new IgniteCacheRestartingException(new IgniteFutureImpl<>(restartFut), "Cache is restarting: " + ctx.name()); + return lock ? gate.enter(opCtx) : gate.enterNoLock(opCtx); } @@ -2286,21 +2295,29 @@ public V getTopologySafe(K key) { } public boolean isRestarting() { - return restarting; + return restartFut.get() != null; } public void restart() { - restarting = true; + GridFutureAdapter restartFut = new GridFutureAdapter<>(); + + GridFutureAdapter currentFut = this.restartFut.get(); + + this.restartFut.compareAndSet(currentFut, restartFut); } public void onRestarted(GridCacheContext ctx, IgniteInternalCache delegate) { + GridFutureAdapter restartFut = this.restartFut.get(); + + assert restartFut != null; + this.ctx = ctx; this.delegate = delegate; this.gate = ctx.gate(); internalProxy = new GridCacheProxyImpl<>(ctx, delegate, opCtx); - restarting = false; + restartFut.onDone(); } /** {@inheritDoc} */ From cb9c18ccfc937b4a880eddb5df5d0389de9c7bee Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Thu, 13 Oct 2016 15:54:39 +0300 Subject: [PATCH 003/311] gg-11595 : WIP. --- .../ignite/IgniteCacheRestartingException.java | 3 +++ .../org/apache/ignite/internal/IgniteKernal.java | 2 +- .../cache/DynamicCacheChangeRequest.java | 13 +++++++++++++ .../processors/cache/GridCacheProcessor.java | 4 +++- .../processors/cache/IgniteCacheProxy.java | 16 ++++++++++++++-- .../cache/IgniteDynamicCacheStartSelfTest.java | 16 ++++++++-------- 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java b/modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java index 2e78411de9a3f..b2f44112f8b28 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java @@ -21,6 +21,9 @@ import org.apache.ignite.lang.IgniteFuture; import org.jetbrains.annotations.Nullable; +/** + * Exception thrown from ignite cache API if cache is restarting. + */ public class IgniteCacheRestartingException extends IgniteException { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index 29691e6669cc9..f8d4110e0a1e2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -2720,7 +2720,7 @@ public IgniteInternalFuture destroyCacheAsync(String cacheName, boolean check guard(); try { - return ctx.cache().dynamicDestroyCache(cacheName, checkThreadTx); + return ctx.cache().dynamicDestroyCache(cacheName, checkThreadTx, false); } finally { unguard(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java index 917b6d1f76eb7..a827bcd872c4d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java @@ -62,6 +62,9 @@ public class DynamicCacheChangeRequest implements Serializable { /** Stop flag. */ private boolean stop; + /** Restart flag. */ + private boolean restart; + /** Close flag. */ private boolean close; @@ -217,10 +220,20 @@ public void stop(boolean stop) { this.stop = stop; } + /** + * @return {@code True} if this is a restart request. + */ public boolean restart() { return true; } + /** + * @param restart New restart flag. + */ + public void restart(boolean restart) { + this.restart = restart; + } + /** * @return Cache name. */ 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 c8e756d8dc9c1..787d0a8f4ada3 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 @@ -2469,7 +2469,7 @@ public IgniteInternalFuture dynamicStartCache( * @param checkThreadTx If {@code true} checks that current thread does not have active transactions. * @return Future that will be completed when cache is destroyed. */ - public IgniteInternalFuture dynamicDestroyCache(String cacheName, boolean checkThreadTx) { + public IgniteInternalFuture dynamicDestroyCache(String cacheName, boolean checkThreadTx, boolean restart) { if (checkThreadTx) checkEmptyTransactions(); @@ -2477,6 +2477,8 @@ public IgniteInternalFuture dynamicDestroyCache(String cacheName, boolean che t.stop(true); + t.restart(restart); + return F.first(initiateCacheChanges(F.asList(t), false)); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index 38837f0135905..68b41588a09d9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -30,7 +30,6 @@ import java.util.NoSuchElementException; import java.util.Set; import java.util.UUID; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.Lock; import javax.cache.Cache; @@ -136,6 +135,7 @@ public class IgniteCacheProxy extends AsyncSupportAdapter> restartFut = new AtomicReference<>(null); /** @@ -1827,7 +1827,7 @@ public void setCacheManager(CacheManager cacheMgr) { IgniteInternalFuture fut; try { - fut = ctx.kernalContext().cache().dynamicDestroyCache(ctx.name(), true); + fut = ctx.kernalContext().cache().dynamicDestroyCache(ctx.name(), true, false); } finally { onLeave(gate); @@ -2294,10 +2294,16 @@ public V getTopologySafe(K key) { } } + /** + * @return Restart future. + */ public boolean isRestarting() { return restartFut.get() != null; } + /** + * Restarts this cache proxy. + */ public void restart() { GridFutureAdapter restartFut = new GridFutureAdapter<>(); @@ -2306,6 +2312,12 @@ public void restart() { this.restartFut.compareAndSet(currentFut, restartFut); } + /** + * Mark this proxy as restarted. + * + * @param ctx New cache context. + * @param delegate New delegate. + */ public void onRestarted(GridCacheContext ctx, IgniteInternalCache delegate) { GridFutureAdapter restartFut = this.restartFut.get(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java index c9cd750c72f7c..5a12ebb5a881c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java @@ -195,7 +195,7 @@ public void testStartStopCacheMultithreadedSameNode() throws Exception { GridTestUtils.runMultiThreaded(new Callable() { @Override public Object call() throws Exception { - futs.add(kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true)); + futs.add(kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true, false)); return null; } @@ -262,7 +262,7 @@ public void testStartCacheMultithreadedDifferentNodes() throws Exception { @Override public Object call() throws Exception { IgniteEx kernal = grid(ThreadLocalRandom.current().nextInt(nodeCount())); - futs.add(kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true)); + futs.add(kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true, false)); return null; } @@ -325,7 +325,7 @@ private void checkStartStopCacheSimple(CacheAtomicityMode mode) throws Exception for (int g = 0; g < nodeCount(); g++) caches[g] = grid(g).cache(DYNAMIC_CACHE_NAME); - kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true).get(); + kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true, false).get(); for (int g = 0; g < nodeCount(); g++) { final IgniteKernal kernal0 = (IgniteKernal) grid(g); @@ -378,7 +378,7 @@ public void testStartStopCacheAddNode() throws Exception { } // Undeploy cache. - kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true).get(); + kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true, false).get(); startGrid(nodeCount() + 1); @@ -455,7 +455,7 @@ public void testDeployFilter() throws Exception { }, IllegalArgumentException.class, null); } - kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true).get(); + kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true, false).get(); stopGrid(nodeCount() + 1); stopGrid(nodeCount()); @@ -522,7 +522,7 @@ public void testClientCache() throws Exception { for (int g = 0; g < nodeCount() + 1; g++) assertEquals("1", ignite(g).cache(DYNAMIC_CACHE_NAME).get("1")); - kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true).get(); + kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true, false).get(); } finally { stopGrid(nodeCount()); @@ -564,7 +564,7 @@ public void testStartFromClientNode() throws Exception { for (int g = 0; g < nodeCount() + 1; g++) assertEquals("1", ignite(g).cache(DYNAMIC_CACHE_NAME).get("1")); - kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true).get(); + kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true, false).get(); } finally { stopGrid(nodeCount()); @@ -610,7 +610,7 @@ public void testStartNearCacheFromClientNode() throws Exception { for (int g = 0; g < nodeCount() + 1; g++) assertEquals("1", ignite(g).cache(DYNAMIC_CACHE_NAME).get("1")); - kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true).get(); + kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, true, false).get(); } finally { stopGrid(nodeCount()); From ed45f2238361e5bbbe907fdeb4b7a3d7b2b051dd Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Thu, 27 Oct 2016 16:02:28 +0300 Subject: [PATCH 004/311] gg-11595 : Support for restore with concurrent cache operations. --- .../processors/cache/IgniteCacheProxy.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index 68b41588a09d9..9fe015e9a8605 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -87,6 +87,7 @@ import org.apache.ignite.lang.IgniteBiPredicate; import org.apache.ignite.lang.IgniteClosure; import org.apache.ignite.lang.IgniteFuture; +import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.mxbean.CacheMetricsMXBean; import org.apache.ignite.plugin.security.SecurityPermission; import org.jetbrains.annotations.Nullable; @@ -2307,9 +2308,19 @@ public boolean isRestarting() { public void restart() { GridFutureAdapter restartFut = new GridFutureAdapter<>(); - GridFutureAdapter currentFut = this.restartFut.get(); + final GridFutureAdapter currentFut = this.restartFut.get(); - this.restartFut.compareAndSet(currentFut, restartFut); + boolean changed = this.restartFut.compareAndSet(currentFut, restartFut); + + if (changed && currentFut != null) + restartFut.listen(new IgniteInClosure>() { + @Override public void apply(IgniteInternalFuture future) { + if (future.error() != null) + currentFut.onDone(future.error()); + else + currentFut.onDone(); + } + }); } /** From e95c68b77cbd3ad30d9f6d0b332137fb26000a41 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Thu, 27 Oct 2016 16:35:46 +0300 Subject: [PATCH 005/311] gg-11595 : Minors. --- .../ignite/internal/processors/cache/IgniteCacheProxy.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index 9fe015e9a8605..ebb0bfaafe804 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -2341,6 +2341,8 @@ public void onRestarted(GridCacheContext ctx, IgniteInternalCache delegate) { internalProxy = new GridCacheProxyImpl<>(ctx, delegate, opCtx); restartFut.onDone(); + + this.restartFut.compareAndSet(restartFut, null); } /** {@inheritDoc} */ From 7a44f1ebccf4fe0f26f54e070bbacbf24fbee3d7 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Fri, 16 Dec 2016 18:56:24 +0300 Subject: [PATCH 006/311] gg-11701 : WIP. --- .../distributed/near/GridNearGetFuture.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java index ff4e8380d74a2..53042ced3c0ba 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java @@ -44,6 +44,8 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtFuture; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.GridLeanMap; @@ -390,7 +392,7 @@ private void map( catch (IgniteCheckedException e) { // Fail the whole thing. if (e instanceof ClusterTopologyCheckedException) - fut.onNodeLeft((ClusterTopologyCheckedException) e); + fut.onNodeLeft((ClusterTopologyCheckedException)e); else fut.onResult(e); } @@ -429,6 +431,15 @@ private Map map( // Allow to get cached value from the local node. boolean allowLocRead = !forcePrimary || cctx.localNode().equals(affNodes.get(0)); + // When persistence is enabled, only reading from partitions with OWNING state is allowed. + if (allowLocRead && cctx.shared().database().persistenceEnabled()) { + GridDhtLocalPartition locPart = cctx.topology().localPartition(part, topVer, false); + + GridDhtPartitionState locPartState = locPart != null ? locPart.state() : GridDhtPartitionState.EVICTED; + + allowLocRead = (locPartState == GridDhtPartitionState.OWNING); + } + while (true) { GridNearCacheEntry entry = allowLocRead ? (GridNearCacheEntry)near.peekEx(key) : null; @@ -989,7 +1000,8 @@ void onResult(final GridNearGetResponse res) { IgniteInternalFuture topFut = cctx.affinity().affinityReadyFuture(rmtTopVer); topFut.listen(new CIX1>() { - @Override public void applyx(IgniteInternalFuture fut) throws IgniteCheckedException { + @Override public void applyx( + IgniteInternalFuture fut) throws IgniteCheckedException { AffinityTopologyVersion readyTopVer = fut.get(); // This will append new futures to compound list. From cc568f9f6823de04f0beeca45ada4160a58307e4 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Wed, 21 Dec 2016 16:11:36 +0300 Subject: [PATCH 007/311] gg-11701 : WIP --- .../dht/GridPartitionedSingleGetFuture.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java index 1744cbd5029d0..8f759f2c1f03c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java @@ -58,6 +58,7 @@ import org.apache.ignite.plugin.extensions.communication.Message; import org.jetbrains.annotations.Nullable; +import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.OWNING; /** @@ -214,7 +215,17 @@ public void init() { */ @SuppressWarnings("unchecked") private void map(AffinityTopologyVersion topVer) { - ClusterNode node = mapKeyToNode(topVer); + boolean allowLocalRead = true; + + if (cctx.shared().database().persistenceEnabled()) { + GridDhtLocalPartition locPart = cctx.topology().localPartition(key, false); + + GridDhtPartitionState locPartState = locPart != null ? locPart.state() : EVICTED; + + allowLocalRead = (locPartState == OWNING); + } + + ClusterNode node = mapKeyToNode(topVer, allowLocalRead); if (node == null) { assert isDone() : this; @@ -225,7 +236,7 @@ private void map(AffinityTopologyVersion topVer) { if (isDone()) return; - if (node.isLocal()) { + if (node.isLocal() && allowLocalRead) { Map map = Collections.singletonMap(key, false); final GridDhtFuture> fut = cctx.dht().getDhtAsync(node.id(), @@ -336,7 +347,7 @@ private void map(AffinityTopologyVersion topVer) { * @param topVer Topology version. * @return Primary node or {@code null} if future was completed. */ - @Nullable private ClusterNode mapKeyToNode(AffinityTopologyVersion topVer) { + @Nullable private ClusterNode mapKeyToNode(AffinityTopologyVersion topVer, boolean allowLocalRead) { int part = cctx.affinity().partition(key); List affNodes = cctx.affinity().nodes(part, topVer); @@ -347,7 +358,7 @@ private void map(AffinityTopologyVersion topVer) { return null; } - boolean fastLocGet = (!forcePrimary || affNodes.get(0).isLocal()) && + boolean fastLocGet = allowLocalRead && (!forcePrimary || affNodes.get(0).isLocal()) && cctx.allowFastLocalRead(part, affNodes, topVer); if (fastLocGet && localGet(topVer, part)) @@ -485,13 +496,13 @@ public void onResult(UUID nodeId, GridNearSingleGetResponse res) { if (skipVals) setSkipValueResult(true, verVal.version()); else - setResult(verVal.value() , verVal.version()); + setResult(verVal.value(), verVal.version()); } else { if (skipVals) setSkipValueResult(false, null); else - setResult(null , null); + setResult(null, null); } } else { From 721f255eb2de1d8207e35328e2dec6514c22500d Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Wed, 28 Dec 2016 18:58:38 +0300 Subject: [PATCH 008/311] gg-11701 : Fixed preloading. --- .../dht/GridDhtLocalPartition.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) 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 d57c0128e37c6..9c315a81f93b5 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 @@ -110,7 +110,7 @@ public class GridDhtLocalPartition implements Comparable, private final long createTime = U.currentTimeMillis(); /** Eviction history. */ - private volatile Map evictHist = new HashMap<>(); + private final Map evictHist = new HashMap<>(); /** Lock. */ private final ReentrantLock lock = new ReentrantLock(); @@ -451,17 +451,11 @@ public boolean preloadingPermitted(KeyCacheObject key, GridCacheVersion ver) { if (state() != MOVING) return false; - Map evictHist0 = evictHist; + GridCacheVersion ver0 = evictHist.get(key); - if (evictHist0 != null) { - GridCacheVersion ver0 = evictHist0.get(key); - - // Permit preloading if version in history - // is missing or less than passed in. - return ver0 == null || ver0.isLess(ver); - } - - return false; + // Permit preloading if version in history + // is missing or less than passed in. + return ver0 == null || ver0.isLess(ver); } /** @@ -532,7 +526,8 @@ private boolean casState(long reservations, GridDhtPartitionState toState) { return update; } - } else + } + else return state.compareAndSet(reservations, (reservations & 0xFFFF) | ((long)toState.ordinal() << 32)); } @@ -558,7 +553,7 @@ boolean own() { log.debug("Owned partition: " + this); // No need to keep history any more. - evictHist = null; + evictHist.clear(); return true; } @@ -602,7 +597,7 @@ boolean markLost() { log.debug("Marked partition as LOST: " + this); // No need to keep history any more. - evictHist = null; + evictHist.clear(); return true; } @@ -691,7 +686,7 @@ private boolean addEvicting() { * */ private void clearEvicting() { - boolean free = false; + boolean free = false; while (true) { int cnt = evictGuard.get(); From bed897dc01960dcbb7219ad948973e0f27bfa564 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Wed, 28 Dec 2016 19:31:51 +0300 Subject: [PATCH 009/311] gg-11701 : Fixed force keys request for single get. --- .../dht/GridDhtGetSingleFuture.java | 2 +- .../dht/GridPartitionedSingleGetFuture.java | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java index 81d2570e9594a..091ad4fba2be6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java @@ -209,7 +209,7 @@ private void map() { topVer); if (fut != null) { - if (F.isEmpty(fut.invalidPartitions())) { + if (!F.isEmpty(fut.invalidPartitions())) { if (retries == null) retries = new HashSet<>(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java index 8f759f2c1f03c..f34d8a944fb4a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java @@ -214,7 +214,7 @@ public void init() { * @param topVer Topology version. */ @SuppressWarnings("unchecked") - private void map(AffinityTopologyVersion topVer) { + private void map(final AffinityTopologyVersion topVer) { boolean allowLocalRead = true; if (cctx.shared().database().persistenceEnabled()) { @@ -281,6 +281,23 @@ private void map(AffinityTopologyVersion topVer) { }); } } + else if (node.isLocal() && !allowLocalRead) { + GridDhtFuture fut = cctx.dht().dhtPreloader().request(Collections.singleton(key), topVer); + + if (fut != null & !F.isEmpty(fut.invalidPartitions())) { + AffinityTopologyVersion updTopVer = cctx.discovery().topologyVersionEx(); + + assert updTopVer.compareTo(topVer) > 0 : "Got invalid partitions for local node but topology " + + "version did not change [topVer=" + topVer + ", updTopVer=" + updTopVer + + ", invalidParts=" + fut.invalidPartitions() + ']'; + + // Remap recursively. + map(updTopVer); + } + else { + map(topVer); + } + } else { synchronized (this) { assert this.node == null; From 07535d92cd37cc949188434eb7ded2fc8d2e0647 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Wed, 28 Dec 2016 19:48:15 +0300 Subject: [PATCH 010/311] gg-11701 : Added check to multiple get. --- .../distributed/dht/GridDhtGetFuture.java | 2 +- .../dht/GridPartitionedGetFuture.java | 13 +++++- .../dht/GridPartitionedSingleGetFuture.java | 43 ++++++------------- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java index 2c3435def24b6..671c141d55bad 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java @@ -182,7 +182,7 @@ void init() { retries.addAll(fut.invalidPartitions()); } - fut.listen(new CI1>() { + fut.listen(new CI1>() { @Override public void apply(IgniteInternalFuture fut) { try { fut.get(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java index cf329ef4cc285..6859cb779bb3d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java @@ -59,6 +59,8 @@ import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; +import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; +import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.OWNING; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture.SINGLE_GET_MSG_SINCE; /** @@ -401,6 +403,14 @@ private boolean map( boolean fastLocGet = (!forcePrimary || affNodes.get(0).isLocal()) && cctx.allowFastLocalRead(part, affNodes, topVer); + if (fastLocGet && cctx.shared().database().persistenceEnabled()) { + GridDhtLocalPartition locPart = cctx.topology().localPartition(key, false); + + GridDhtPartitionState locPartState = locPart != null ? locPart.state() : EVICTED; + + fastLocGet = (locPartState == OWNING); + } + if (fastLocGet && localGet(key, part, locVals)) return false; @@ -752,7 +762,8 @@ void onResult(final GridNearGetResponse res) { topFut.listen(new CIX1>() { @SuppressWarnings("unchecked") - @Override public void applyx(IgniteInternalFuture fut) throws IgniteCheckedException { + @Override public void applyx( + IgniteInternalFuture fut) throws IgniteCheckedException { AffinityTopologyVersion topVer = fut.get(); // This will append new futures to compound list. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java index f34d8a944fb4a..6c70b1244d0ee 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java @@ -215,17 +215,7 @@ public void init() { */ @SuppressWarnings("unchecked") private void map(final AffinityTopologyVersion topVer) { - boolean allowLocalRead = true; - - if (cctx.shared().database().persistenceEnabled()) { - GridDhtLocalPartition locPart = cctx.topology().localPartition(key, false); - - GridDhtPartitionState locPartState = locPart != null ? locPart.state() : EVICTED; - - allowLocalRead = (locPartState == OWNING); - } - - ClusterNode node = mapKeyToNode(topVer, allowLocalRead); + ClusterNode node = mapKeyToNode(topVer); if (node == null) { assert isDone() : this; @@ -236,7 +226,7 @@ private void map(final AffinityTopologyVersion topVer) { if (isDone()) return; - if (node.isLocal() && allowLocalRead) { + if (node.isLocal()) { Map map = Collections.singletonMap(key, false); final GridDhtFuture> fut = cctx.dht().getDhtAsync(node.id(), @@ -281,23 +271,6 @@ private void map(final AffinityTopologyVersion topVer) { }); } } - else if (node.isLocal() && !allowLocalRead) { - GridDhtFuture fut = cctx.dht().dhtPreloader().request(Collections.singleton(key), topVer); - - if (fut != null & !F.isEmpty(fut.invalidPartitions())) { - AffinityTopologyVersion updTopVer = cctx.discovery().topologyVersionEx(); - - assert updTopVer.compareTo(topVer) > 0 : "Got invalid partitions for local node but topology " + - "version did not change [topVer=" + topVer + ", updTopVer=" + updTopVer + - ", invalidParts=" + fut.invalidPartitions() + ']'; - - // Remap recursively. - map(updTopVer); - } - else { - map(topVer); - } - } else { synchronized (this) { assert this.node == null; @@ -364,7 +337,7 @@ else if (node.isLocal() && !allowLocalRead) { * @param topVer Topology version. * @return Primary node or {@code null} if future was completed. */ - @Nullable private ClusterNode mapKeyToNode(AffinityTopologyVersion topVer, boolean allowLocalRead) { + @Nullable private ClusterNode mapKeyToNode(AffinityTopologyVersion topVer) { int part = cctx.affinity().partition(key); List affNodes = cctx.affinity().nodes(part, topVer); @@ -375,9 +348,17 @@ else if (node.isLocal() && !allowLocalRead) { return null; } - boolean fastLocGet = allowLocalRead && (!forcePrimary || affNodes.get(0).isLocal()) && + boolean fastLocGet = (!forcePrimary || affNodes.get(0).isLocal()) && cctx.allowFastLocalRead(part, affNodes, topVer); + if (fastLocGet && cctx.shared().database().persistenceEnabled()) { + GridDhtLocalPartition locPart = cctx.topology().localPartition(key, false); + + GridDhtPartitionState locPartState = locPart != null ? locPart.state() : EVICTED; + + fastLocGet = (locPartState == OWNING); + } + if (fastLocGet && localGet(topVer, part)) return null; From 6cbe8a5a8ea5e4dacb8c5a859cb15aea5b3f38af Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Mon, 9 Jan 2017 18:22:15 +0300 Subject: [PATCH 011/311] gg-11701 : Fixed partition update counters comparison. --- .../internal/processors/cache/GridCacheContext.java | 7 +++++++ .../distributed/dht/GridDhtPartitionTopologyImpl.java | 9 +++++---- .../cache/distributed/dht/GridPartitionedGetFuture.java | 8 -------- .../distributed/dht/GridPartitionedSingleGetFuture.java | 8 -------- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java index 3b128de95b1a0..f3f6af2aa3899 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java @@ -58,6 +58,7 @@ import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter; @@ -1971,6 +1972,12 @@ private boolean hasPartition(int part, List affNodes, AffinityTopol GridDhtPartitionTopology top = topology(); + if (shared().database().persistenceEnabled()) { + GridDhtLocalPartition locPart = top.localPartition(part, topVer, false); + + return locPart != null && locPart.state() == OWNING; + } + return (top.rebalanceFinished(topVer) && (isReplicated() || affNodes.contains(locNode))) || (top.partitionState(localNodeId(), part) == OWNING); } 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 f22c263a1505f..d86b438a1f0e3 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 @@ -1899,13 +1899,14 @@ private void removeNode(UUID nodeId) { continue; T2 cntr0 = res.get(part.id()); - Long cntr1 = part.initialUpdateCounter(); + Long cntr1 = part.state() == MOVING ? part.initialUpdateCounter() : part.updateCounter(); + Long cntr2 = part.updateCounter(); - if (skipZeros && cntr1 == 0L) + if (skipZeros && cntr1 == 0L && cntr2 == 0L) continue; - if (cntr0 == null || cntr1 > cntr0.get1()) - res.put(part.id(), new T2(cntr1, part.updateCounter())); + if (cntr0 == null || cntr1 > cntr0.get1() || (cntr1.equals(cntr0.get1()) && cntr2 > cntr0.get2())) + res.put(part.id(), new T2<>(cntr1, cntr2)); } return res; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java index 6859cb779bb3d..6224ed7ac1801 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java @@ -403,14 +403,6 @@ private boolean map( boolean fastLocGet = (!forcePrimary || affNodes.get(0).isLocal()) && cctx.allowFastLocalRead(part, affNodes, topVer); - if (fastLocGet && cctx.shared().database().persistenceEnabled()) { - GridDhtLocalPartition locPart = cctx.topology().localPartition(key, false); - - GridDhtPartitionState locPartState = locPart != null ? locPart.state() : EVICTED; - - fastLocGet = (locPartState == OWNING); - } - if (fastLocGet && localGet(key, part, locVals)) return false; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java index 6c70b1244d0ee..df447e2d2edbc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java @@ -351,14 +351,6 @@ private void map(final AffinityTopologyVersion topVer) { boolean fastLocGet = (!forcePrimary || affNodes.get(0).isLocal()) && cctx.allowFastLocalRead(part, affNodes, topVer); - if (fastLocGet && cctx.shared().database().persistenceEnabled()) { - GridDhtLocalPartition locPart = cctx.topology().localPartition(key, false); - - GridDhtPartitionState locPartState = locPart != null ? locPart.state() : EVICTED; - - fastLocGet = (locPartState == OWNING); - } - if (fastLocGet && localGet(topVer, part)) return null; From 3c276c9e092b6f6b4baf0b550ad89cb85ab9c42f Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Tue, 10 Jan 2017 13:25:09 +0300 Subject: [PATCH 012/311] gg-11701 : Implicit lateAffinityAssignment mode when persistence is enabled. --- .../cache/CacheAffinitySharedManager.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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 abe33b03cede6..459723c35b682 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 @@ -115,7 +115,12 @@ public class CacheAffinitySharedManager extends GridCacheSharedManagerAdap @Override protected void start0() throws IgniteCheckedException { super.start0(); - lateAffAssign = cctx.kernalContext().config().isLateAffinityAssignment(); + if (cctx.database().persistenceEnabled() && !cctx.kernalContext().config().isLateAffinityAssignment()) + U.quietAndWarn(log, + "Persistence is enabled, but late affinity assignment is disabled. " + + "Since it is required for persistence mode, it will be implicitly enabled."); + + lateAffAssign = cctx.kernalContext().config().isLateAffinityAssignment() || cctx.database().persistenceEnabled(); cctx.kernalContext().event().addLocalEventListener(discoLsnr, EVT_NODE_LEFT, EVT_NODE_FAILED); } @@ -488,7 +493,7 @@ else if (req.stop()) /** * */ - public void removeAllCacheInfo(){ + public void removeAllCacheInfo() { caches.clear(); registeredCaches.clear(); @@ -690,7 +695,8 @@ public void removeDhtAssignmentFetchFuture(GridDhtAssignmentFetchFuture fut) { * @param nodeId Node ID. * @param res Response. */ - private void processAffinityAssignmentResponse(Integer cacheId, UUID nodeId, GridDhtAffinityAssignmentResponse res) { + private void processAffinityAssignmentResponse(Integer cacheId, UUID nodeId, + GridDhtAffinityAssignmentResponse res) { if (log.isDebugEnabled()) log.debug("Processing affinity assignment response [node=" + nodeId + ", res=" + res + ']'); @@ -1263,8 +1269,7 @@ private void initAffinityOnNodeJoin(GridDhtPartitionsExchangeFuture fut, WaitRebalanceInfo rebalanceInfo, boolean latePrimary, Map>> affCache) - throws IgniteCheckedException - { + throws IgniteCheckedException { assert lateAffAssign; AffinityTopologyVersion topVer = fut.topologyVersion(); From b3f7ae3bf903a0a6357163029ed310647877c8fc Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Tue, 10 Jan 2017 14:25:24 +0300 Subject: [PATCH 013/311] gg-11701 : Replaced redundant checks with assertions. --- .../processors/cache/GridCacheContext.java | 15 +++++++-------- .../cache/distributed/near/GridNearGetFuture.java | 9 ++------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java index f3f6af2aa3899..fd0ececf23639 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java @@ -58,7 +58,6 @@ import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; -import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter; @@ -1951,7 +1950,13 @@ public Collection cacheKeysView(Collection keys) { * @return {@code True} if cache 'get' operation is allowed to get entry locally. */ public boolean allowFastLocalRead(int part, List affNodes, AffinityTopologyVersion topVer) { - return affinityNode() && rebalanceEnabled() && hasPartition(part, affNodes, topVer); + boolean result = affinityNode() && rebalanceEnabled() && hasPartition(part, affNodes, topVer); + + // When persistence is enabled, only reading from partitions with OWNING state is allowed. + assert !result || !ctx.cache().context().database().persistenceEnabled() || + topology().partitionState(localNodeId(), part) == OWNING; + + return result; } /** @@ -1972,12 +1977,6 @@ private boolean hasPartition(int part, List affNodes, AffinityTopol GridDhtPartitionTopology top = topology(); - if (shared().database().persistenceEnabled()) { - GridDhtLocalPartition locPart = top.localPartition(part, topVer, false); - - return locPart != null && locPart.state() == OWNING; - } - return (top.rebalanceFinished(topVer) && (isReplicated() || affNodes.contains(locNode))) || (top.partitionState(localNodeId(), part) == OWNING); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java index 53042ced3c0ba..302c83fe2ab0c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java @@ -432,13 +432,8 @@ private Map map( boolean allowLocRead = !forcePrimary || cctx.localNode().equals(affNodes.get(0)); // When persistence is enabled, only reading from partitions with OWNING state is allowed. - if (allowLocRead && cctx.shared().database().persistenceEnabled()) { - GridDhtLocalPartition locPart = cctx.topology().localPartition(part, topVer, false); - - GridDhtPartitionState locPartState = locPart != null ? locPart.state() : GridDhtPartitionState.EVICTED; - - allowLocRead = (locPartState == GridDhtPartitionState.OWNING); - } + assert !allowLocRead || !cctx.shared().database().persistenceEnabled() || + cctx.topology().partitionState(cctx.localNodeId(), part) == GridDhtPartitionState.OWNING; while (true) { GridNearCacheEntry entry = allowLocRead ? (GridNearCacheEntry)near.peekEx(key) : null; From ecead988090e6a65ffdbb4098252ea26287fe36e Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Wed, 11 Jan 2017 18:09:25 +0300 Subject: [PATCH 014/311] gg-11701 : Merge with 8.0.2.ea2 --- .../distributed/dht/GridDhtPartitionTopologyImpl.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 0d7e6f9a65da0..afb5a93238ea5 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 @@ -1895,14 +1895,18 @@ private void removeNode(UUID nodeId) { for (int i = 0; i < locParts.length(); i++) { GridDhtLocalPartition part = locParts.get(i); - if (part == null || (skipZeros && part.updateCounter() == 0L)) + if (part == null) continue; T2 cntr0 = res.get(part.id()); Long initCntr = part.state() == MOVING ? part.initialUpdateCounter() : part.updateCounter(); + Long updateCntr = part.updateCounter(); + + if (skipZeros && initCntr == 0 && updateCntr == 0) + continue; - if (cntr0 == null || initCntr >= cntr0.get1()) - res.put(part.id(), new T2<>(initCntr, part.updateCounter())); + if (cntr0 == null || initCntr > cntr0.get1() || initCntr.equals(cntr0.get1()) && updateCntr > cntr0.get2()) + res.put(part.id(), new T2<>(initCntr, updateCntr)); } return res; From adc0422592a18a7c2635e45185ef17852cd41952 Mon Sep 17 00:00:00 2001 From: Glukos Date: Fri, 13 Jan 2017 20:23:06 +0300 Subject: [PATCH 015/311] GG-11595: Remote exception wrapped on proxy level --- .../cache/CacheStoppedException.java | 12 ++++++++++ .../cache/DynamicCacheChangeRequest.java | 2 +- .../processors/cache/IgniteCacheProxy.java | 15 +++++++++--- .../dht/atomic/GridDhtAtomicCache.java | 23 ++----------------- .../GridNearAtomicSingleUpdateFuture.java | 12 ++-------- .../atomic/GridNearAtomicUpdateFuture.java | 13 ++--------- .../colocated/GridDhtColocatedLockFuture.java | 13 ++--------- .../distributed/near/GridNearLockFuture.java | 13 ++--------- .../IgniteTxImplicitSingleStateImpl.java | 4 ++-- .../cache/transactions/IgniteTxStateImpl.java | 4 ++-- 10 files changed, 39 insertions(+), 72 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java new file mode 100644 index 0000000000000..eb114101faa9d --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java @@ -0,0 +1,12 @@ +package org.apache.ignite.internal.processors.cache; + +import org.apache.ignite.IgniteCheckedException; + +/** + * Used to report attempts of accessing stopped cache. + */ +public class CacheStoppedException extends IgniteCheckedException { + public CacheStoppedException(String cacheName) { + super("Failed to perform cache operation (cache is stopped): " + cacheName); + } +} \ No newline at end of file diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java index a827bcd872c4d..1db677c498cd5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java @@ -224,7 +224,7 @@ public void stop(boolean stop) { * @return {@code True} if this is a restart request. */ public boolean restart() { - return true; + return restart; } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index ebb0bfaafe804..7a12eb281ec2a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -2081,6 +2081,13 @@ public IgniteCache skipStore() { * @return Cache exception. */ private RuntimeException cacheException(IgniteCheckedException e) { + GridFutureAdapter restartFut = this.restartFut.get(); + + if (restartFut != null && !restartFut.isDone() && e.hasCause(CacheStoppedException.class)) { + throw new IgniteCacheRestartingException( + new IgniteFutureImpl<>(restartFut), "Cache is restarting: " + ctx.name()); + } + return CU.convertToCacheException(e); } @@ -2162,10 +2169,12 @@ public void closeProxy() { * @return Previous projection set on this thread. */ private CacheOperationContext onEnter(GridCacheGateway gate, CacheOperationContext opCtx) { - GridFutureAdapter restartFut = this.restartFut.get(); + GridFutureAdapter restartFut = this.restartFut.get(); - if (restartFut != null && !restartFut.isDone()) - throw new IgniteCacheRestartingException(new IgniteFutureImpl<>(restartFut), "Cache is restarting: " + ctx.name()); + if (restartFut != null && !restartFut.isDone()) { + throw new IgniteCacheRestartingException( + new IgniteFutureImpl<>(restartFut), "Cache is restarting: " + ctx.name()); + } return lock ? gate.enter(opCtx) : gate.enterNoLock(opCtx); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index f0a9f3b621873..fb1a86a5d0321 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -44,25 +44,7 @@ import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.pagemem.wal.StorageException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; -import org.apache.ignite.internal.processors.cache.CacheInvokeEntry; -import org.apache.ignite.internal.processors.cache.CacheInvokeResult; -import org.apache.ignite.internal.processors.cache.CacheLazyEntry; -import org.apache.ignite.internal.processors.cache.CacheMetricsImpl; -import org.apache.ignite.internal.processors.cache.CacheObject; -import org.apache.ignite.internal.processors.cache.CacheOperationContext; -import org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException; -import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap; -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.GridCacheMapEntry; -import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory; -import org.apache.ignite.internal.processors.cache.GridCacheOperation; -import org.apache.ignite.internal.processors.cache.GridCacheReturn; -import org.apache.ignite.internal.processors.cache.GridCacheUpdateAtomicResult; -import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy; -import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtFuture; @@ -1675,8 +1657,7 @@ public void updateAllAsyncInternal0( try { if (top.stopping()) { - res.addFailedKeys(keys, new IgniteCheckedException("Failed to perform cache operation " + - "(cache is stopped): " + name())); + res.addFailedKeys(keys, new CacheStoppedException(name())); completionCb.apply(req, res); 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 4860eb437a8ac..f3d256a4e546d 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 @@ -31,14 +31,7 @@ import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; -import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException; -import org.apache.ignite.internal.processors.cache.EntryProcessorResourceInjectorProxy; -import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.GridCacheOperation; -import org.apache.ignite.internal.processors.cache.GridCacheReturn; -import org.apache.ignite.internal.processors.cache.GridCacheTryPutFailedException; -import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; @@ -390,8 +383,7 @@ private void updateNear(GridNearAtomicUpdateRequest req, GridNearAtomicUpdateRes try { if (cache.topology().stopping()) { - onDone(new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " + - cache.name())); + onDone(new CacheStoppedException(cache.name())); return; } 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 71f35e9dcd619..9d33afa6f3348 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 @@ -33,15 +33,7 @@ import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; -import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException; -import org.apache.ignite.internal.processors.cache.EntryProcessorResourceInjectorProxy; -import org.apache.ignite.internal.processors.cache.GridCacheAffinityManager; -import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.GridCacheOperation; -import org.apache.ignite.internal.processors.cache.GridCacheReturn; -import org.apache.ignite.internal.processors.cache.GridCacheTryPutFailedException; -import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache; import org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo; @@ -502,8 +494,7 @@ private void updateNear(GridNearAtomicUpdateRequest req, GridNearAtomicUpdateRes try { if (cache.topology().stopping()) { - onDone(new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " + - cache.name())); + onDone(new CacheStoppedException(cache.name())); return; } 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 65d971ae630d8..feaae8100adff 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 @@ -34,15 +34,7 @@ import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; -import org.apache.ignite.internal.processors.cache.CacheObject; -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.GridCacheLockTimeoutException; -import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate; -import org.apache.ignite.internal.processors.cache.GridCacheMvccFuture; -import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; @@ -681,8 +673,7 @@ private void mapOnTopology(final boolean remap, @Nullable final Runnable c) { try { if (cctx.topology().stopping()) { - onDone(new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " + - cctx.name())); + onDone(new CacheStoppedException(cctx.name())); return; } 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 7d07177f691ab..ab95bc7091df9 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 @@ -35,15 +35,7 @@ import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; -import org.apache.ignite.internal.processors.cache.CacheObject; -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.GridCacheLockTimeoutException; -import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate; -import org.apache.ignite.internal.processors.cache.GridCacheMvccFuture; -import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; @@ -815,8 +807,7 @@ synchronized void mapOnTopology(final boolean remap) { try { if (cctx.topology().stopping()) { - onDone(new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " + - cctx.name())); + onDone(new CacheStoppedException(cctx.name())); return; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxImplicitSingleStateImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxImplicitSingleStateImpl.java index f13891609813c..c9f3cbd15c2c6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxImplicitSingleStateImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxImplicitSingleStateImpl.java @@ -26,6 +26,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.CacheWriteSynchronizationMode; import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException; +import org.apache.ignite.internal.processors.cache.CacheStoppedException; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; @@ -144,8 +145,7 @@ public class IgniteTxImplicitSingleStateImpl extends IgniteTxLocalStateAdapter { cacheCtx.topology().readLock(); if (cacheCtx.topology().stopping()) { - fut.onDone(new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " + - cacheCtx.name())); + fut.onDone(new CacheStoppedException(cacheCtx.name())); return null; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java index 1985266bfb326..42aba77800944 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java @@ -28,6 +28,7 @@ import org.apache.ignite.cache.CacheInterceptor; import org.apache.ignite.cache.CacheWriteSynchronizationMode; import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException; +import org.apache.ignite.internal.processors.cache.CacheStoppedException; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; @@ -284,8 +285,7 @@ public class IgniteTxStateImpl extends IgniteTxLocalStateAdapter { nonLocCtx.topology().readLock(); if (nonLocCtx.topology().stopping()) { - fut.onDone(new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " + - nonLocCtx.name())); + fut.onDone(new CacheStoppedException(nonLocCtx.name())); return null; } From 4505066481d4fff601a14d344dc8059f5dbe73de Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Sat, 14 Jan 2017 00:32:08 +0300 Subject: [PATCH 016/311] GG-11595: + serialVersionUid --- .../ignite/internal/processors/cache/CacheStoppedException.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java index eb114101faa9d..9e0d6a7927b04 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java @@ -6,6 +6,8 @@ * Used to report attempts of accessing stopped cache. */ public class CacheStoppedException extends IgniteCheckedException { + private static final long serialVersionUID = 0L; + public CacheStoppedException(String cacheName) { super("Failed to perform cache operation (cache is stopped): " + cacheName); } From 982740774b95156cb100b0c0123530d3c3ab2337 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Tue, 17 Jan 2017 16:54:57 +0300 Subject: [PATCH 017/311] IGNITE-3477 - Fixed rejected execution exception on node stop. --- .../processors/cache/GridCacheTtlManager.java | 27 ++++++++---- .../cache/IgniteCacheOffheapManagerImpl.java | 44 +++++++++++-------- .../service/GridServiceProcessor.java | 10 +++++ 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java index 98b9edff13997..795ddbe3e206b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java @@ -70,19 +70,30 @@ public class GridCacheTtlManager extends GridCacheManagerAdapter { /** {@inheritDoc} */ @Override protected void start0() throws IgniteCheckedException { - boolean cleanupDisabled = cctx.kernalContext().isDaemon() || - !cctx.config().isEagerTtl() || - CU.isAtomicsCache(cctx.name()) || - CU.isMarshallerCache(cctx.name()) || - CU.isUtilityCache(cctx.name()) || - (cctx.kernalContext().clientNode() && cctx.config().getNearConfiguration() == null); + if (cleanupDisabled()) + return; - if (cleanupDisabled) + pendingEntries = (!cctx.isLocal() && cctx.config().getNearConfiguration() != null) ? new GridConcurrentSkipListSetEx() : null; + } + + /** {@inheritDoc} */ + @Override protected void onKernalStart0() throws IgniteCheckedException { + if (cleanupDisabled()) return; cctx.shared().ttl().register(this); + } - pendingEntries = (!cctx.isLocal() && cctx.config().getNearConfiguration() != null) ? new GridConcurrentSkipListSetEx() : null; + /** + * @return {@code Tu} + */ + private boolean cleanupDisabled() { + return cctx.kernalContext().isDaemon() || + !cctx.config().isEagerTtl() || + CU.isAtomicsCache(cctx.name()) || + CU.isMarshallerCache(cctx.name()) || + CU.isUtilityCache(cctx.name()) || + (cctx.kernalContext().clientNode() && cctx.config().getNearConfiguration() == null); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index fcc14a6a61ee5..6a1b1bf9325c8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -761,35 +761,43 @@ protected final String treeName(int p) { IgniteInClosure2X c, int amount ) throws IgniteCheckedException { - if (pendingEntries != null) { - GridCacheVersion obsoleteVer = null; + if (!busyLock.enterBusy()) + return false; - long now = U.currentTimeMillis(); + try { + if (pendingEntries != null) { + GridCacheVersion obsoleteVer = null; - GridCursor cur = pendingEntries.find(START_PENDING_ROW, new PendingRow(now, 0)); + long now = U.currentTimeMillis(); - int cleared = 0; + GridCursor cur = pendingEntries.find(START_PENDING_ROW, new PendingRow(now, 0)); - while (cur.next()) { - PendingRow row = cur.get(); + int cleared = 0; - if (amount != -1 && cleared > amount) - return true; + while (cur.next()) { + PendingRow row = cur.get(); - assert row.key != null && row.link != 0 && row.expireTime != 0 : row; + if (amount != -1 && cleared > amount) + return true; - if (pendingEntries.remove(row) != null) { - if (obsoleteVer == null) - obsoleteVer = cctx.versions().next(); + assert row.key != null && row.link != 0 && row.expireTime != 0 : row; - c.apply(cctx.cache().entryEx(row.key), obsoleteVer); - } + if (pendingEntries.remove(row) != null) { + if (obsoleteVer == null) + obsoleteVer = cctx.versions().next(); + + c.apply(cctx.cache().entryEx(row.key), obsoleteVer); + } - cleared++; + cleared++; + } } - } - return false; + return false; + } + finally { + busyLock.leaveBusy(); + } } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java index ab04e7eecc4b0..21acbe4525f95 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java @@ -350,6 +350,8 @@ CU.UTILITY_CACHE_NAME, new ServiceEntriesListener(), null, null U.shutdownNow(GridServiceProcessor.class, depExe, log); + depExe = null; + Exception err = new IgniteCheckedException("Operation has been cancelled (node is stopping)."); cancelFutures(depFuts, err); @@ -1416,6 +1418,10 @@ private class ServiceEntriesListener implements CacheEntryUpdatedListener Date: Tue, 17 Jan 2017 20:13:14 +0300 Subject: [PATCH 018/311] Code style --- .../IgniteCacheRestartingException.java | 1 - .../cache/CacheStoppedException.java | 21 +++++++++++++++++++ .../processors/cache/GridCacheProcessor.java | 6 +++--- .../processors/cache/IgniteCacheProxy.java | 17 +++++++-------- .../dht/atomic/GridDhtAtomicCache.java | 2 +- .../GridNearAtomicSingleUpdateFuture.java | 10 ++++++++- .../atomic/GridNearAtomicUpdateFuture.java | 11 +++++++++- .../colocated/GridDhtColocatedLockFuture.java | 11 +++++++++- .../distributed/near/GridNearLockFuture.java | 11 +++++++++- 9 files changed, 72 insertions(+), 18 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java b/modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java index b2f44112f8b28..a3a749070cec1 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteCacheRestartingException.java @@ -59,5 +59,4 @@ public IgniteCacheRestartingException( public IgniteFuture restartFuture() { return restartFut; } - } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java index 9e0d6a7927b04..9299c16a1f64c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStoppedException.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.apache.ignite.internal.processors.cache; import org.apache.ignite.IgniteCheckedException; @@ -6,8 +23,12 @@ * Used to report attempts of accessing stopped cache. */ public class CacheStoppedException extends IgniteCheckedException { + /** */ private static final long serialVersionUID = 0L; + /** + * @param cacheName Cache name. + */ public CacheStoppedException(String cacheName) { super("Failed to perform cache operation (cache is stopped): " + cacheName); } 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 f9661660d7e19..560efe756656a 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 @@ -439,12 +439,12 @@ private void validate(IgniteConfiguration c, else if (cc.getRebalanceMode() == SYNC) { if (delay < 0) { U.warn(log, "Ignoring SYNC rebalance mode with manual rebalance start (node will not wait for " + - "rebalancing to be finished): " + U.maskName(cc.getName()), + "rebalancing to be finished): " + U.maskName(cc.getName()), "Node will not wait for rebalance in SYNC mode: " + U.maskName(cc.getName())); } else { U.warn(log, "Using SYNC rebalance mode with rebalance delay (node will wait until rebalancing is " + - "initiated for " + delay + "ms) for cache: " + U.maskName(cc.getName()), + "initiated for " + delay + "ms) for cache: " + U.maskName(cc.getName()), "Node will wait until rebalancing is initiated for " + delay + "ms for cache: " + U.maskName(cc.getName())); } } @@ -565,7 +565,7 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near if (!F.isEmpty(ctx.config().getCacheConfiguration())) { if (depMode != CONTINUOUS && depMode != SHARED) U.warn(log, "Deployment mode for cache is not CONTINUOUS or SHARED " + - "(it is recommended that you change deployment mode and restart): " + depMode, + "(it is recommended that you change deployment mode and restart): " + depMode, "Deployment mode for cache is not CONTINUOUS or SHARED."); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index 48acb4f6b936f..ae4f34ad9aa94 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -2188,10 +2188,9 @@ public IgniteCache skipStore() { private RuntimeException cacheException(IgniteCheckedException e) { GridFutureAdapter restartFut = this.restartFut.get(); - if (restartFut != null && !restartFut.isDone() && e.hasCause(CacheStoppedException.class)) { - throw new IgniteCacheRestartingException( - new IgniteFutureImpl<>(restartFut), "Cache is restarting: " + ctx.name()); - } + if (restartFut != null && !restartFut.isDone() && e.hasCause(CacheStoppedException.class)) + throw new IgniteCacheRestartingException(new IgniteFutureImpl<>(restartFut), "Cache is restarting: " + + ctx.name()); return CU.convertToCacheException(e); } @@ -2276,10 +2275,9 @@ public void closeProxy() { private CacheOperationContext onEnter(GridCacheGateway gate, CacheOperationContext opCtx) { GridFutureAdapter restartFut = this.restartFut.get(); - if (restartFut != null && !restartFut.isDone()) { - throw new IgniteCacheRestartingException( - new IgniteFutureImpl<>(restartFut), "Cache is restarting: " + ctx.name()); - } + if (restartFut != null && !restartFut.isDone()) + throw new IgniteCacheRestartingException(new IgniteFutureImpl<>(restartFut), "Cache is restarting: " + + ctx.name()); return lock ? gate.enter(opCtx) : gate.enterNoLock(opCtx); } @@ -2458,7 +2456,8 @@ public void onRestarted(GridCacheContext ctx, IgniteInternalCache delegate) { this.ctx = ctx; this.delegate = delegate; - this.gate = ctx.gate(); + + gate = ctx.gate(); internalProxy = new GridCacheProxyImpl<>(ctx, delegate, opCtx); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index 4012727c35ae1..0560198d6f31b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -48,6 +48,7 @@ import org.apache.ignite.internal.processors.cache.CacheMetricsImpl; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.CacheOperationContext; +import org.apache.ignite.internal.processors.cache.CacheStoppedException; import org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException; import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap; import org.apache.ignite.internal.processors.cache.GridCacheContext; @@ -61,7 +62,6 @@ import org.apache.ignite.internal.processors.cache.GridDeferredAckMessageSender; import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtFuture; 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 d049df14db528..a39838a13868e 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 @@ -31,7 +31,15 @@ import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; +import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException; +import org.apache.ignite.internal.processors.cache.CacheStoppedException; +import org.apache.ignite.internal.processors.cache.EntryProcessorResourceInjectorProxy; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheOperation; +import org.apache.ignite.internal.processors.cache.GridCacheReturn; +import org.apache.ignite.internal.processors.cache.GridCacheTryPutFailedException; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; 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 e264cbba41f56..33225ce8d9be0 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 @@ -33,7 +33,16 @@ import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; +import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException; +import org.apache.ignite.internal.processors.cache.CacheStoppedException; +import org.apache.ignite.internal.processors.cache.EntryProcessorResourceInjectorProxy; +import org.apache.ignite.internal.processors.cache.GridCacheAffinityManager; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheOperation; +import org.apache.ignite.internal.processors.cache.GridCacheReturn; +import org.apache.ignite.internal.processors.cache.GridCacheTryPutFailedException; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache; import org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo; 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 51a182b6d0d01..bdfa9c674bb96 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 @@ -34,7 +34,16 @@ import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; +import org.apache.ignite.internal.processors.cache.CacheObject; +import org.apache.ignite.internal.processors.cache.CacheStoppedException; +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.GridCacheLockTimeoutException; +import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate; +import org.apache.ignite.internal.processors.cache.GridCacheMvccFuture; +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.dht.GridDhtCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; 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 45910166f264e..c69ddcfdb17d5 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 @@ -35,7 +35,16 @@ import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; +import org.apache.ignite.internal.processors.cache.CacheObject; +import org.apache.ignite.internal.processors.cache.CacheStoppedException; +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.GridCacheLockTimeoutException; +import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate; +import org.apache.ignite.internal.processors.cache.GridCacheMvccFuture; +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.dht.GridDhtCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; From 9b40d0eaab7054d00e40d7b2c6ef8ee6a9cc915b Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 17 Jan 2017 20:44:15 +0300 Subject: [PATCH 019/311] ignite-gg-8.0.2.ea2 igfs test fix --- .../processors/cache/GridCacheMapEntry.java | 31 ------------ .../processors/cache/GridCacheProcessor.java | 9 ++-- .../cache/IgniteCacheOffheapManagerImpl.java | 48 +++++++++++++++++++ .../query/h2/opt/GridH2TreeIndex.java | 2 +- 4 files changed, 55 insertions(+), 35 deletions(-) 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 9f018883024e1..ee39ed9a28ef7 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 @@ -205,40 +205,9 @@ protected GridCacheMapEntry( protected void value(@Nullable CacheObject val) { assert Thread.holdsLock(this); - // In case we deal with IGFS cache, count updated data - if (cctx.cache().isIgfsDataCache() && - cctx.kernalContext().igfsHelper().isIgfsBlockKey(keyValue(false))) { - int newSize = valueLength0(val, null); - int oldSize = valueLength0(this.val, null); - - int delta = newSize - oldSize; - - if (delta != 0 && !cctx.isNear()) - cctx.cache().onIgfsDataSizeChanged(delta); - } - this.val = val; } - /** - * Isolated method to get length of IGFS block. - * - * @param val Value. - * @param valBytes Value bytes. - * @return Length of value. - */ - private int valueLength0(@Nullable CacheObject val, @Nullable IgniteBiTuple valBytes) { - byte[] bytes = val != null ? (byte[])val.value(cctx.cacheObjectContext(), false) : null; - - if (bytes != null) - return bytes.length; - - if (valBytes == null) - return 0; - - return valBytes.get1().length - (((valBytes.get2() == CacheObject.TYPE_BYTE_ARR) ? 0 : 6)); - } - /** {@inheritDoc} */ @Override public int memorySize() throws IgniteCheckedException { byte[] kb; 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 560efe756656a..8fe5c26bae665 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 @@ -2062,9 +2062,12 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, if (desc == null) continue; - // requestId must be null because on different node will be different byte [] and we get duplicate discovery data - // see TcpDiscoveryNodeAddedMessage#addDiscoveryData 'Arrays.equals(curData, discoDataEntry.getValue())' - DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(null, cache.name(), null); + + // RequestId must be null because on different node will be different byte [] and + // we get duplicate discovery data, for more details see + // TcpDiscoveryNodeAddedMessage#addDiscoveryData. + DynamicCacheChangeRequest req = new DynamicCacheChangeRequest( + null, cache.name(), null); req.startCacheConfiguration(desc.cacheConfiguration()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index 6a1b1bf9325c8..ffa7f60fa18fd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -929,6 +929,8 @@ public CacheDataStoreImpl( if (pendingEntries != null && expireTime != 0) pendingEntries.put(new PendingRow(expireTime, dataRow.link())); + + updateIgfsMetrics(key, (old != null ? old.value() : null), val); } finally { busyLock.leaveBusy(); @@ -969,6 +971,8 @@ public CacheDataStoreImpl( if (dataRow != null) rowStore.removeRow(dataRow.link()); + + updateIgfsMetrics(key, (dataRow != null ? dataRow.value() : null), null); } finally { busyLock.leaveBusy(); @@ -1037,6 +1041,50 @@ public CacheDataStoreImpl( storageSize.set(size); cntr.set(updCntr); } + + /** + * @param key Key. + * @param oldVal Old value. + * @param newVal New value. + */ + private void updateIgfsMetrics( + KeyCacheObject key, + CacheObject oldVal, + CacheObject newVal + ) throws IgniteCheckedException { + // In case we deal with IGFS cache, count updated data + if (cctx.cache().isIgfsDataCache() && + !cctx.isNear() && + cctx.kernalContext() + .igfsHelper() + .isIgfsBlockKey(key.value(cctx.cacheObjectContext(), false))) { + int oldSize = valueLength(oldVal); + int newSize = valueLength(newVal); + + int delta = newSize - oldSize; + + if (delta != 0) + cctx.cache().onIgfsDataSizeChanged(delta); + } + } + + /** + * Isolated method to get length of IGFS block. + * + * @param val Value. + * @return Length of value. + */ + private int valueLength(@Nullable CacheObject val) { + if (val == null) + return 0; + + byte[] bytes = val.value(cctx.cacheObjectContext(), false); + + if (bytes != null) + return bytes.length; + else + return 0; + } } /** diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java index 0f93f52553459..729309abfa958 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java @@ -521,7 +521,7 @@ else if (lower != null && upper == null) else if (lower == null) rows = tree.headMap(upper).values(); else - rows = tree.subMap(lower, true, upper, true).values(); + rows = tree.subMap(lower, false, upper, false).values(); return new GridCursorIteratorWrapper<>(rows.iterator()); } From 05506692b8bc8009481cb988f21d8ccd82b99e23 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Wed, 18 Jan 2017 00:01:26 +0300 Subject: [PATCH 020/311] Optimize cache destroying during restoration from snapshot. --- .../main/java/org/apache/ignite/internal/IgniteKernal.java | 2 +- .../internal/processors/cache/GridCacheProcessor.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index 3fb45d172fffa..3ea50824bc6e7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -2899,7 +2899,7 @@ public IgniteInternalFuture destroyCachesAsync(Collection cacheNames, guard(); try { - return ctx.cache().dynamicDestroyCaches(cacheNames, checkThreadTx); + return ctx.cache().dynamicDestroyCaches(cacheNames, checkThreadTx, false); } finally { unguard(); 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 8fe5c26bae665..a9f183a791a51 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 @@ -2551,7 +2551,8 @@ public IgniteInternalFuture dynamicDestroyCache(String cacheName, boolean che * @param checkThreadTx If {@code true} checks that current thread does not have active transactions. * @return Future that will be completed when cache is destroyed. */ - public IgniteInternalFuture dynamicDestroyCaches(Collection cacheNames, boolean checkThreadTx) { + public IgniteInternalFuture dynamicDestroyCaches(Collection cacheNames, boolean checkThreadTx, + boolean restart) { if (checkThreadTx) checkEmptyTransactions(); @@ -2561,6 +2562,9 @@ public IgniteInternalFuture dynamicDestroyCaches(Collection cacheName DynamicCacheChangeRequest t = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, ctx.localNodeId()); t.stop(true); + t.destroy(true); + + t.restart(restart); reqs.add(t); } From e1ba328a21e3491e7afbc155e772a3e2c228cf9b Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Wed, 18 Jan 2017 14:24:15 +0300 Subject: [PATCH 021/311] Minor --- .../cache/distributed/dht/GridPartitionedGetFuture.java | 2 -- .../cache/distributed/dht/GridPartitionedSingleGetFuture.java | 1 - 2 files changed, 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java index cd88584911d3d..548e1f0f0abcc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java @@ -59,8 +59,6 @@ import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; -import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; -import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.OWNING; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture.SINGLE_GET_MSG_SINCE; /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java index c576248a9fd50..ec4a3e9809b1a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java @@ -58,7 +58,6 @@ import org.apache.ignite.plugin.extensions.communication.Message; import org.jetbrains.annotations.Nullable; -import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.OWNING; /** From 738caa1a9fe0f3d9c74bbfdf57f8aa759f715059 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Wed, 18 Jan 2017 17:44:37 +0300 Subject: [PATCH 022/311] Fixed missing typeId for indices configured using CacheTypeMetadata, which could lead to "Releasing write lock on a page that was not locked" exception. --- .../ignite/internal/processors/query/GridQueryProcessor.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 520090710d3e7..f5a2b8e27e43d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -435,6 +435,8 @@ private void initializeCache(GridCacheContext cctx) throws IgniteCheckedEx if (altTypeId != null) types.put(altTypeId, desc); + desc.typeId(typeId.valType != null ? typeId.valType.getName().hashCode() : typeId.valTypeId); + desc.registered(idx.registerType(ccfg.getName(), desc)); } } From 8e7fade935fb38a703e4a7e56c77878eb3c347ea Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 18 Jan 2017 19:00:36 +0300 Subject: [PATCH 023/311] ignite-gg-8.0.2.ea2 ifgs test fix --- .../cluster/GridClusterStateProcessor.java | 15 +++++++++------ .../processors/igfs/IgfsProcessorSelfTest.java | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java index fa6910d6c22f1..8d16d14c75269 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java @@ -43,6 +43,7 @@ import org.apache.ignite.internal.cluster.ClusterGroupAdapter; import org.apache.ignite.internal.managers.discovery.CustomEventListener; import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener; +import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; import org.apache.ignite.internal.processors.GridProcessorAdapter; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.ClusterState; @@ -440,8 +441,10 @@ private Exception onActivate(ChangeGlobalStateContext cgsCtx) { if (!client) { sharedCtx.database().lock(); - if (sharedCtx.pageStore() != null) - sharedCtx.pageStore().onActivate(ctx); + IgnitePageStoreManager pageStore = sharedCtx.pageStore(); + + if (pageStore != null) + pageStore.onActivate(ctx); sharedCtx.wal().onActivate(ctx); @@ -449,14 +452,14 @@ private Exception onActivate(ChangeGlobalStateContext cgsCtx) { for (CacheConfiguration cfg : cfgs) { if (CU.isSystemCache(cfg.getName())) - if (sharedCtx.pageStore() != null) - sharedCtx.pageStore().initializeForCache(cfg); + if (pageStore != null) + pageStore.initializeForCache(cfg); } for (CacheConfiguration cfg : cfgs) { if (!CU.isSystemCache(cfg.getName())) - if (sharedCtx.pageStore() != null) - sharedCtx.pageStore().initializeForCache(cfg); + if (pageStore != null) + pageStore.initializeForCache(cfg); } sharedCtx.database().onActivate(ctx); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsProcessorSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsProcessorSelfTest.java index c8549705ee162..69d11ad5f93e9 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsProcessorSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsProcessorSelfTest.java @@ -230,7 +230,7 @@ public void testCreate() throws Exception { for (int i = 0; i < nodesCount(); i++) { IgfsEntryInfo fileInfo = - (IgfsEntryInfo)grid(i).cachex(metaCacheName).localPeek(info.fileId(), ONHEAP_PEEK_MODES, null); + (IgfsEntryInfo)grid(i).cachex(metaCacheName).localPeek(info.fileId(), null, null); assertNotNull(fileInfo); assertNotNull(fileInfo.listing()); From 306923f0adb7e6e55991192c49907ffcf8ce701c Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Wed, 18 Jan 2017 23:28:45 +0700 Subject: [PATCH 024/311] GG-11785 Fix for NPE: we should iterate over valid caches. --- .../ignite/internal/processors/query/GridQueryProcessor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index f5a2b8e27e43d..42be691cdcad9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -197,8 +197,8 @@ public GridQueryProcessor(GridKernalContext ctx) throws IgniteCheckedException { // Schedule queries detail metrics eviction. qryDetailMetricsEvictTask = ctx.timeout().schedule(new Runnable() { @Override public void run() { - for (IgniteCacheProxy cache : ctx.cache().jcaches()) - cache.context().queries().evictDetailMetrics(); + for (GridCacheContext ctxs : ctx.cache().context().cacheContexts()) + ctxs.queries().evictDetailMetrics(); } }, QRY_DETAIL_METRICS_EVICTION_FREQ, QRY_DETAIL_METRICS_EVICTION_FREQ); } From 0d710096a340375ef49603dbbb8f75263dcbe465 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 18 Jan 2017 19:46:57 +0300 Subject: [PATCH 025/311] ignite-gg-8.0.2.ea2 fix CacheExchangeMessageDuplicatedStateTest.testExchangeMessages --- .../cache/CacheExchangeMessageDuplicatedStateTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java index ed186ac68bc3b..ac7222af5d5ed 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java @@ -93,25 +93,25 @@ public class CacheExchangeMessageDuplicatedStateTest extends GridCommonAbstractT { CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setName(AFF1_CACHE1); - ccfg.setAffinity(new RendezvousAffinityFunction()); + ccfg.setAffinity(new RendezvousAffinityFunction(false,512)); ccfgs.add(ccfg); } { CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setName(AFF1_CACHE2); - ccfg.setAffinity(new RendezvousAffinityFunction()); + ccfg.setAffinity(new RendezvousAffinityFunction(false,512)); ccfgs.add(ccfg); } { CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setName(AFF2_CACHE1); - ccfg.setAffinity(new FairAffinityFunction()); + ccfg.setAffinity(new FairAffinityFunction(false,512)); ccfgs.add(ccfg); } { CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setName(AFF2_CACHE2); - ccfg.setAffinity(new FairAffinityFunction()); + ccfg.setAffinity(new FairAffinityFunction(false,512)); ccfgs.add(ccfg); } { From fc7af8668e603cdc45bc8c6f97cf2d2be64b1fb8 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 18 Jan 2017 19:49:04 +0300 Subject: [PATCH 026/311] ignite-gg-8.0.2.ea2 fix GridPartitionedBackupLoadSelfTest.testBackupLoad --- .../distributed/near/GridPartitionedBackupLoadSelfTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridPartitionedBackupLoadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridPartitionedBackupLoadSelfTest.java index 5c3eacf0b899b..af0e062b583d1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridPartitionedBackupLoadSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridPartitionedBackupLoadSelfTest.java @@ -111,11 +111,11 @@ public void testBackupLoad() throws Exception { IgniteCache cache = jcache(i); if (grid(i).affinity(null).isBackup(grid(i).localNode(), 1)) { - assert cache.localPeek(1, CachePeekMode.ONHEAP) == 1; + assert cache.localPeek(1) == 1; jcache(i).localClear(1); - assert cache.localPeek(1, CachePeekMode.ONHEAP) == null; + assert cache.localPeek(1) == null; // Store is called in putx method, so we reset counter here. cnt.set(0); From adefeae40a4688b51efd8bce8522a21e8ca32865 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Wed, 18 Jan 2017 20:21:19 +0300 Subject: [PATCH 027/311] GG-11868 Snapshots: error on restoring #2 -adding assert --- .../internal/processors/cache/database/tree/BPlusTree.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java index aef72173a5a8d..bb0f01cd67883 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java @@ -1597,6 +1597,8 @@ public final long destroy() throws IgniteCheckedException { try (Page meta = page(metaPageId)) { ByteBuffer metaBuf = writeLock(meta); // No checks, we must be out of use. + assert metaBuf != null; + try { for (long pageId : getFirstPageIds(metaBuf)) { assert pageId != 0; From 5b010c27646aa61620b47d245f92676fafaa0815 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 18 Jan 2017 20:58:44 +0300 Subject: [PATCH 028/311] ignite-gg-8.0.2.ea2 localPeek --- .../dht/GridCacheDhtPreloadDisabledSelfTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadDisabledSelfTest.java index 52f31d57fb8be..61c7d376f9c20 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadDisabledSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadDisabledSelfTest.java @@ -188,7 +188,7 @@ public void testDisabledPreloader() throws Exception { assertNull(near(cache1).peekEx(i)); assertNotNull((dht(cache1).peekEx(i))); - assertEquals(Integer.toString(i), cache1.localPeek(i, CachePeekMode.ONHEAP)); + assertEquals(Integer.toString(i), cache1.localPeek(i)); } int nodeCnt = 3; @@ -202,7 +202,7 @@ public void testDisabledPreloader() throws Exception { IgniteCache c = g.cache(null); for (int i = 0; i < keyCnt; i++) - assertNull(c.localPeek(i, CachePeekMode.ONHEAP)); + assertNull(c.localPeek(i)); } Collection keys = new LinkedList<>(); @@ -226,12 +226,12 @@ public void testDisabledPreloader() throws Exception { IgniteCache c = gg.cache(null); for (int i = 0; i < keyCnt; i++) - assertNull(c.localPeek(i, CachePeekMode.ONHEAP)); + assertNull(c.localPeek(i)); } } for (Integer i : keys) - assertEquals(i.toString(), cache1.localPeek(i, CachePeekMode.ONHEAP)); + assertEquals(i.toString(), cache1.localPeek(i)); } catch (Error | Exception e) { error("Test failed.", e); From 4e81e9479580d67b3505cf810714e776a767c376 Mon Sep 17 00:00:00 2001 From: Evgeny Stanilovskiy Date: Thu, 19 Jan 2017 11:46:21 +0300 Subject: [PATCH 029/311] ignite-4557 Fixed wrong affinity manager call. --- .../processors/cache/GridCacheAffinityManager.java | 6 +++--- .../distributed/dht/GridDhtPartitionTopologyImpl.java | 4 ++-- .../dht/preloader/GridDhtPartitionDemander.java | 8 ++++---- .../cache/distributed/dht/preloader/GridDhtPreloader.java | 2 +- .../cache/distributed/near/GridNearGetFuture.java | 2 +- .../cache/distributed/near/GridNearTxFinishFuture.java | 2 +- .../cache/GridCacheAbstractFullApiSelfTest.java | 6 +++--- .../cache/IgniteCacheConfigVariationsFullApiTest.java | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java index f22687e54042c..c7e2f6b290f73 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java @@ -378,8 +378,8 @@ public Collection remoteNodes(Iterable keys, AffinityTopologyVersio * @param topVer Topology version. * @return {@code true} if given key belongs to local node. */ - public boolean localNode(Object key, AffinityTopologyVersion topVer) { - return localNode(partition(key), topVer); + public boolean keyLocalNode(Object key, AffinityTopologyVersion topVer) { + return partitionLocalNode(partition(key), topVer); } /** @@ -387,7 +387,7 @@ public boolean localNode(Object key, AffinityTopologyVersion topVer) { * @param topVer Topology version. * @return {@code true} if given partition belongs to local node. */ - public boolean localNode(int part, AffinityTopologyVersion topVer) { + public boolean partitionLocalNode(int part, AffinityTopologyVersion topVer) { assert part >= 0 : "Invalid partition: " + part; return nodes(part, topVer).contains(cctx.localNode()); 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 f83f93a5aced8..4c8b8148a2ea7 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 @@ -622,7 +622,7 @@ else if (!node2part.nodeId().equals(loc.id())) { for (int p = 0; p < num; p++) { GridDhtLocalPartition locPart = localPartition(p, topVer, false, false); - if (cctx.affinity().localNode(p, topVer)) { + if (cctx.affinity().partitionLocalNode(p, topVer)) { // This partition will be created during next topology event, // which obviously has not happened at this point. if (locPart == null) { @@ -763,7 +763,7 @@ private GridDhtLocalPartition localPartition(int p, state = loc != null ? loc.state() : null; - boolean belongs = cctx.affinity().localNode(p, topVer); + boolean belongs = cctx.affinity().partitionLocalNode(p, topVer); if (loc != null && state == EVICTED) { locParts.set(p, loc = null); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java index d2efd24420014..2f39e98f95aba 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java @@ -651,7 +651,7 @@ public void handleSupplyMessage( for (Map.Entry e : supply.infos().entrySet()) { int p = e.getKey(); - if (cctx.affinity().localNode(p, topVer)) { + if (cctx.affinity().partitionLocalNode(p, topVer)) { GridDhtLocalPartition part = top.localPartition(p, topVer, true); assert part != null; @@ -721,7 +721,7 @@ public void handleSupplyMessage( // Only request partitions based on latest topology version. for (Integer miss : supply.missed()) { - if (cctx.affinity().localNode(miss, topVer)) + if (cctx.affinity().partitionLocalNode(miss, topVer)) fut.partitionMissed(id, miss); } @@ -1416,7 +1416,7 @@ private void demandFromNode( for (Map.Entry e : supply.infos().entrySet()) { int p = e.getKey(); - if (cctx.affinity().localNode(p, topVer)) { + if (cctx.affinity().partitionLocalNode(p, topVer)) { GridDhtLocalPartition part = top.localPartition(p, topVer, true); assert part != null; @@ -1493,7 +1493,7 @@ private void demandFromNode( // Only request partitions based on latest topology version. for (Integer miss : s.supply().missed()) { - if (cctx.affinity().localNode(miss, topVer)) + if (cctx.affinity().partitionLocalNode(miss, topVer)) fut.partitionMissed(node.id(), miss); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java index c5fab1ab5afe1..518739dd47029 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java @@ -289,7 +289,7 @@ private IgniteCheckedException stopError() { } // If partition belongs to local node. - if (cctx.affinity().localNode(p, topVer)) { + if (cctx.affinity().partitionLocalNode(p, topVer)) { GridDhtLocalPartition part = top.localPartition(p, topVer, true); assert part != null; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java index 302c83fe2ab0c..b2a7906e31171 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java @@ -725,7 +725,7 @@ private Map loadEntries( info.unmarshalValue(cctx, cctx.deploy().globalLoader()); // Entries available locally in DHT should not be loaded into near cache for reading. - if (!cctx.affinity().localNode(info.key(), cctx.affinity().affinityTopologyVersion())) { + if (!cctx.affinity().keyLocalNode(info.key(), cctx.affinity().affinityTopologyVersion())) { GridNearCacheEntry entry = savedEntries.get(info.key()); if (entry == null) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishFuture.java index 9acab56ae2d8e..aed1ab0ac18de 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishFuture.java @@ -350,7 +350,7 @@ else if (err != null) GridCacheContext cacheCtx = e.context(); try { - if (e.op() != NOOP && !cacheCtx.affinity().localNode(e.key(), topVer)) { + if (e.op() != NOOP && !cacheCtx.affinity().keyLocalNode(e.key(), topVer)) { GridCacheEntryEx entry = cacheCtx.cache().peekEx(e.key()); if (entry != null) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java index 2c86322b8194f..1343151ce7d38 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java @@ -5875,7 +5875,7 @@ public CheckEntriesTask(Collection keys) { ctx = ctx.near().dht().context(); for (String key : keys) { - if (ctx.affinity().localNode(key, ctx.discovery().topologyVersionEx())) { + if (ctx.affinity().keyLocalNode(key, ctx.discovery().topologyVersionEx())) { GridCacheEntryEx e = ctx.cache().entryEx(key); assert e != null : "Entry is null [idx=" + idx + ", key=" + key + ", ctx=" + ctx + ']'; @@ -5912,7 +5912,7 @@ private static class CheckCacheSizeTask extends TestIgniteIdxRunnable { int size = 0; for (String key : map.keySet()) - if (ctx.affinity().localNode(key, ctx.discovery().topologyVersionEx())) + if (ctx.affinity().keyLocalNode(key, ctx.discovery().topologyVersionEx())) size++; assertEquals("Incorrect key size on cache #" + idx, size, ignite.cache(ctx.name()).localSize(ALL)); @@ -6155,7 +6155,7 @@ public CheckKeySizeTask(Collection keys) { int size = 0; for (String key : keys) - if (ctx.affinity().localNode(key, ctx.discovery().topologyVersionEx())) + if (ctx.affinity().keyLocalNode(key, ctx.discovery().topologyVersionEx())) size++; assertEquals("Incorrect key size on cache #" + idx, size, ignite.cache(null).localSize(ALL)); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigVariationsFullApiTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigVariationsFullApiTest.java index b746883e9034d..d3cdf799c8892 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigVariationsFullApiTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigVariationsFullApiTest.java @@ -5557,7 +5557,7 @@ private static class CheckEntriesTask extends TestIgniteIdxRunnable { ctx = ctx.near().dht().context(); for (String key : keys) { - if (ctx.affinity().localNode(key, ctx.discovery().topologyVersionEx())) { + if (ctx.affinity().keyLocalNode(key, ctx.discovery().topologyVersionEx())) { GridCacheEntryEx e = ctx.cache().entryEx(key); assert e != null : "Entry is null [idx=" + idx + ", key=" + key + ", ctx=" + ctx + ']'; @@ -5600,7 +5600,7 @@ private static class CheckCacheSizeTask extends TestIgniteIdxRunnable { int size = 0; for (String key : map.keySet()) - if (ctx.affinity().localNode(key, ctx.discovery().topologyVersionEx())) + if (ctx.affinity().keyLocalNode(key, ctx.discovery().topologyVersionEx())) size++; assertEquals("Incorrect key size on cache #" + idx, size, ignite.cache(ctx.name()).localSize(ALL)); @@ -5861,7 +5861,7 @@ public CheckKeySizeTask(Collection keys, String s) { int size = 0; for (String key : keys) - if (ctx.affinity().localNode(key, ctx.discovery().topologyVersionEx())) + if (ctx.affinity().keyLocalNode(key, ctx.discovery().topologyVersionEx())) size++; assertEquals("Incorrect key size on cache #" + idx, size, ignite.cache(cacheName).localSize(ALL)); From fbb66ce8df4b4156069701b777dbdb5371bd4df5 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Thu, 19 Jan 2017 14:23:28 +0300 Subject: [PATCH 030/311] Fixed NPE on cache restart. --- .../ignite/internal/processors/cache/GridCacheProcessor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 a9f183a791a51..5b37ed4c41b20 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 @@ -1882,7 +1882,8 @@ private void stopGateway(DynamicCacheChangeRequest req) { if (req.restart()) { proxy = jCacheProxies.get(maskNull(req.cacheName())); - proxy.restart(); + if (proxy != null) + proxy.restart(); } else proxy = jCacheProxies.remove(maskNull(req.cacheName())); From c3f9fe73a09cc27e49e44c2c4df0ee0f385a38ee Mon Sep 17 00:00:00 2001 From: agura Date: Wed, 18 Jan 2017 18:04:45 +0300 Subject: [PATCH 031/311] ignite-4499 Drop node from topology in case when connection creation is impossible --- .../apache/ignite/IgniteSystemProperties.java | 3 + .../tcp/TcpCommunicationSpi.java | 16 + .../ignite/spi/discovery/tcp/ClientImpl.java | 88 ++++- .../ignite/spi/discovery/tcp/ServerImpl.java | 61 ++-- .../messages/TcpDiscoveryAbstractMessage.java | 21 ++ .../tcp/TcpCommunicationSpiDropNodesTest.java | 322 ++++++++++++++++++ .../TcpCommunicationSpiFaultyClientTest.java | 270 +++++++++++++++ .../ignite/testframework/GridTestNode.java | 1 + .../junits/GridAbstractTest.java | 2 + .../IgniteSpiCommunicationSelfTestSuite.java | 5 + .../IgniteCacheAbstractQuerySelfTest.java | 3 - 11 files changed, 756 insertions(+), 36 deletions(-) create mode 100644 modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiDropNodesTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiFaultyClientTest.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 a355d71fea270..1e8adb2fb69b7 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -65,6 +65,9 @@ public final class IgniteSystemProperties { */ public static final String IGNITE_NO_DISCO_ORDER = "IGNITE_NO_DISCO_ORDER"; + /** Defines reconnect delay in milliseconds for client node that was failed forcible. */ + public static final String IGNITE_DISCO_FAILED_CLIENT_RECONNECT_DELAY = "IGNITE_DISCO_FAILED_CLIENT_RECONNECT_DELAY"; + /** * If this system property is set to {@code false} - no checks for new versions will * be performed by Ignite. By default, Ignite periodically checks for the new diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java index 097c31b6dcca4..68efd39a73bc3 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java @@ -96,6 +96,7 @@ import org.apache.ignite.internal.util.typedef.CI2; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.X; +import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.LT; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; @@ -3018,6 +3019,21 @@ else if (X.hasCause(e, SocketTimeoutException.class)) "operating system firewall is disabled on local and remote hosts) " + "[addrs=" + addrs + ']'); + if (getSpiContext().node(node.id()) != null && (CU.clientNode(node) || !CU.clientNode(getLocalNode())) && + X.hasCause(errs, ConnectException.class, SocketTimeoutException.class, HandshakeTimeoutException.class, + IgniteSpiOperationTimeoutException.class)) { + LT.warn(log, "TcpCommunicationSpi failed to establish connection to node, node will be dropped from " + + "cluster [" + + "rmtNode=" + node + + ", err=" + errs + + ", connectErrs=" + Arrays.toString(errs.getSuppressed()) + ']'); + + getSpiContext().failNode(node.id(), "TcpCommunicationSpi failed to establish connection to node [" + + "rmtNode=" + node + + ", errs=" + errs + + ", connectErrs=" + Arrays.toString(errs.getSuppressed()) + ']'); + } + throw errs; } diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java index d5adad2a188c8..334812c3ddfe9 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java @@ -48,6 +48,7 @@ import org.apache.ignite.IgniteClientDisconnectedException; import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.cache.CacheMetrics; import org.apache.ignite.cluster.ClusterMetrics; import org.apache.ignite.cluster.ClusterNode; @@ -98,6 +99,7 @@ import org.jsr166.ConcurrentHashMap8; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_DISCO_FAILED_CLIENT_RECONNECT_DELAY; import static org.apache.ignite.events.EventType.EVT_CLIENT_NODE_DISCONNECTED; import static org.apache.ignite.events.EventType.EVT_CLIENT_NODE_RECONNECTED; import static org.apache.ignite.events.EventType.EVT_NODE_FAILED; @@ -164,6 +166,9 @@ class ClientImpl extends TcpDiscoveryImpl { /** */ protected MessageWorker msgWorker; + /** Force fail message for local node. */ + private TcpDiscoveryNodeFailedMessage forceFailMsg; + /** */ @GridToStringExclude private int joinCnt; @@ -448,6 +453,8 @@ else if (state == DISCONNECTED) { msg.warning(warning); + msg.force(true); + msgWorker.addMessage(msg); } } @@ -1386,6 +1393,14 @@ else if (msg == SPI_STOP) { else leaveLatch.countDown(); } + else if (msg instanceof TcpDiscoveryNodeFailedMessage && + ((TcpDiscoveryNodeFailedMessage)msg).failedNodeId().equals(locNode.id())) { + TcpDiscoveryNodeFailedMessage msg0 = (TcpDiscoveryNodeFailedMessage)msg; + + assert msg0.force() : msg0; + + forceFailMsg = msg0; + } else if (msg instanceof SocketClosedMessage) { if (((SocketClosedMessage)msg).sock == currSock) { currSock = null; @@ -1402,25 +1417,45 @@ else if (msg instanceof SocketClosedMessage) { } } else { - if (log.isDebugEnabled()) - log.debug("Connection closed, will try to restore connection."); + if (forceFailMsg != null) { + if (log.isDebugEnabled()) { + log.debug("Connection closed, local node received force fail message, " + + "will not try to restore connection"); + } + + queue.addFirst(SPI_RECONNECT_FAILED); + } + else { + if (log.isDebugEnabled()) + log.debug("Connection closed, will try to restore connection."); - assert reconnector == null; + assert reconnector == null; - final Reconnector reconnector = new Reconnector(join); - this.reconnector = reconnector; - reconnector.start(); + final Reconnector reconnector = new Reconnector(join); + this.reconnector = reconnector; + reconnector.start(); + } } } } else if (msg == SPI_RECONNECT_FAILED) { - reconnector.cancel(); - reconnector.join(); + if (reconnector != null) { + reconnector.cancel(); + reconnector.join(); - reconnector = null; + reconnector = null; + } + else + assert forceFailMsg != null; if (spi.isClientReconnectDisabled()) { if (state != SEGMENTED && state != STOPPED) { + if (forceFailMsg != null) { + U.quietAndWarn(log, "Local node was dropped from cluster due to network problems " + + "[nodeInitiatedFail=" + forceFailMsg.creatorNodeId() + + ", msg=" + forceFailMsg.warning() + ']'); + } + if (log.isDebugEnabled()) { log.debug("Failed to restore closed connection, reconnect disabled, " + "local node segmented [networkTimeout=" + spi.netTimeout + ']'); @@ -1435,7 +1470,9 @@ else if (msg == SPI_RECONNECT_FAILED) { if (state == STARTING || state == CONNECTED) { if (log.isDebugEnabled()) { log.debug("Failed to restore closed connection, will try to reconnect " + - "[networkTimeout=" + spi.netTimeout + ", joinTimeout=" + spi.joinTimeout + ']'); + "[networkTimeout=" + spi.netTimeout + + ", joinTimeout=" + spi.joinTimeout + + ", failMsg=" + forceFailMsg + ']'); } state = DISCONNECTED; @@ -1458,7 +1495,36 @@ else if (msg == SPI_RECONNECT_FAILED) { UUID newId = UUID.randomUUID(); - if (log.isInfoEnabled()) { + if (forceFailMsg != null) { + long delay = IgniteSystemProperties.getLong(IGNITE_DISCO_FAILED_CLIENT_RECONNECT_DELAY, + 10_000); + + if (delay > 0) { + U.quietAndWarn(log, "Local node was dropped from cluster due to network problems, " + + "will try to reconnect with new id after " + delay + "ms (reconnect delay " + + "can be changed using IGNITE_DISCO_FAILED_CLIENT_RECONNECT_DELAY system " + + "property) [" + + "newId=" + newId + + ", prevId=" + locNode.id() + + ", locNode=" + locNode + + ", nodeInitiatedFail=" + forceFailMsg.creatorNodeId() + + ", msg=" + forceFailMsg.warning() + ']'); + + Thread.sleep(delay); + } + else { + U.quietAndWarn(log, "Local node was dropped from cluster due to network problems, " + + "will try to reconnect with new id [" + + "newId=" + newId + + ", prevId=" + locNode.id() + + ", locNode=" + locNode + + ", nodeInitiatedFail=" + forceFailMsg.creatorNodeId() + + ", msg=" + forceFailMsg.warning() + ']'); + } + + forceFailMsg = null; + } + else if (log.isInfoEnabled()) { log.info("Client node disconnected from cluster, will try to reconnect with new id " + "[newId=" + newId + ", prevId=" + locNode.id() + ", locNode=" + locNode + ']'); } diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java index 585c153823f74..b509fc56227d8 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java @@ -785,6 +785,8 @@ private void interruptPing(TcpDiscoveryNode node) { msg.warning(warning); + msg.force(true); + msgWorker.addMessage(msg); } } @@ -4650,8 +4652,12 @@ private void processNodeFailedMessage(TcpDiscoveryNodeFailedMessage msg) { else { boolean contains; + UUID creatorId = msg.creatorNodeId(); + + assert creatorId != null : msg; + synchronized (mux) { - contains = failedNodes.containsKey(sndNode); + contains = failedNodes.containsKey(sndNode) || ring.node(creatorId) == null; } if (contains) { @@ -4663,25 +4669,29 @@ private void processNodeFailedMessage(TcpDiscoveryNodeFailedMessage msg) { } } - UUID nodeId = msg.failedNodeId(); + UUID failedNodeId = msg.failedNodeId(); long order = msg.order(); - TcpDiscoveryNode node = ring.node(nodeId); + TcpDiscoveryNode failedNode = ring.node(failedNodeId); - if (node != null && node.internalOrder() != order) { + if (failedNode != null && failedNode.internalOrder() != order) { if (log.isDebugEnabled()) log.debug("Ignoring node failed message since node internal order does not match " + - "[msg=" + msg + ", node=" + node + ']'); + "[msg=" + msg + ", node=" + failedNode + ']'); return; } - if (node != null) { - assert !node.isLocal() || !msg.verified() : msg; + if (failedNode != null) { + assert !failedNode.isLocal() || !msg.verified() : msg; - synchronized (mux) { - if (!failedNodes.containsKey(node)) - failedNodes.put(node, msg.senderNodeId() != null ? msg.senderNodeId() : getLocalNodeId()); + boolean skipUpdateFailedNodes = msg.force() && !msg.verified(); + + if (!skipUpdateFailedNodes) { + synchronized (mux) { + if (!failedNodes.containsKey(failedNode)) + failedNodes.put(failedNode, msg.senderNodeId() != null ? msg.senderNodeId() : getLocalNodeId()); + } } } else { @@ -4708,11 +4718,11 @@ private void processNodeFailedMessage(TcpDiscoveryNodeFailedMessage msg) { } if (msg.verified()) { - node = ring.removeNode(nodeId); + failedNode = ring.removeNode(failedNodeId); - interruptPing(node); + interruptPing(failedNode); - assert node != null; + assert failedNode != null; long topVer; @@ -4738,16 +4748,18 @@ private void processNodeFailedMessage(TcpDiscoveryNodeFailedMessage msg) { } synchronized (mux) { - failedNodes.remove(node); + failedNodes.remove(failedNode); - leavingNodes.remove(node); + leavingNodes.remove(failedNode); - failedNodesMsgSent.remove(node.id()); + failedNodesMsgSent.remove(failedNode.id()); - ClientMessageWorker worker = clientMsgWorkers.remove(node.id()); + if (!msg.force()) { // ClientMessageWorker will stop after sending force fail message. + ClientMessageWorker worker = clientMsgWorkers.remove(failedNode.id()); - if (worker != null) - worker.interrupt(); + if (worker != null) + worker.interrupt(); + } } if (msg.warning() != null && !msg.creatorNodeId().equals(getLocalNodeId())) { @@ -4759,10 +4771,10 @@ private void processNodeFailedMessage(TcpDiscoveryNodeFailedMessage msg) { } synchronized (mux) { - joiningNodes.remove(node.id()); + joiningNodes.remove(failedNode.id()); } - notifyDiscovery(EVT_NODE_FAILED, topVer, node); + notifyDiscovery(EVT_NODE_FAILED, topVer, failedNode); spi.stats.onNodeFailed(); } @@ -6357,7 +6369,12 @@ else if (msgLog.isDebugEnabled()) spi.failureDetectionTimeout() : spi.getSocketTimeout()); } - success = true; + boolean clientFailed = msg instanceof TcpDiscoveryNodeFailedMessage && + ((TcpDiscoveryNodeFailedMessage)msg).failedNodeId().equals(clientNodeId); + + assert !clientFailed || msg.force() : msg; + + success = !clientFailed; } catch (IgniteCheckedException | IOException e) { if (log.isDebugEnabled()) diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAbstractMessage.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAbstractMessage.java index 783a113ea1ff6..e982b2f32ea31 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAbstractMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAbstractMessage.java @@ -48,6 +48,9 @@ public abstract class TcpDiscoveryAbstractMessage implements Serializable { /** */ protected static final int CLIENT_ACK_FLAG_POS = 4; + /** */ + protected static final int FORCE_FAIL_FLAG_POS = 8; + /** Sender of the message (transient). */ private transient UUID sndNodeId; @@ -204,6 +207,24 @@ public void client(boolean client) { setFlag(CLIENT_FLAG_POS, client); } + /** + * Get force fail node flag. + * + * @return Force fail node flag. + */ + public boolean force() { + return getFlag(FORCE_FAIL_FLAG_POS); + } + + /** + * Sets force fail node flag. + * + * @param force Force fail node flag. + */ + public void force(boolean force) { + setFlag(FORCE_FAIL_FLAG_POS, force); + } + /** * @return Pending message index. */ diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiDropNodesTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiDropNodesTest.java new file mode 100644 index 0000000000000..b530e36e20e34 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiDropNodesTest.java @@ -0,0 +1,322 @@ +/* + * 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.spi.communication.tcp; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.events.Event; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.util.lang.GridAbsPredicate; +import org.apache.ignite.internal.util.nio.GridCommunicationClient; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiPredicate; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.lang.IgniteRunnable; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode; +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.events.EventType.EVT_NODE_FAILED; + +/** + * + */ +public class TcpCommunicationSpiDropNodesTest extends GridCommonAbstractTest { + /** IP finder. */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** Nodes count. */ + private static final int NODES_CNT = 4; + + /** Block. */ + private static volatile boolean block; + + /** Predicate. */ + private static IgniteBiPredicate pred; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setClockSyncFrequency(300000); + cfg.setFailureDetectionTimeout(1000); + + TestCommunicationSpi spi = new TestCommunicationSpi(); + + spi.setIdleConnectionTimeout(100); + spi.setSharedMemoryPort(-1); + + TcpDiscoverySpi discoSpi = (TcpDiscoverySpi) cfg.getDiscoverySpi(); + discoSpi.setIpFinder(IP_FINDER); + + cfg.setCommunicationSpi(spi); + cfg.setDiscoverySpi(discoSpi); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + block = false; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + + /** + * @throws Exception If failed. + */ + public void testOneNode() throws Exception { + pred = new IgniteBiPredicate() { + @Override public boolean apply(ClusterNode locNode, ClusterNode rmtNode) { + return block && rmtNode.order() == 3; + } + }; + + startGrids(NODES_CNT); + + final CountDownLatch latch = new CountDownLatch(1); + + grid(0).events().localListen(new IgnitePredicate() { + @Override + public boolean apply(Event event) { + latch.countDown(); + + return true; + } + }, EVT_NODE_FAILED); + + U.sleep(1000); // Wait for write timeout and closing idle connections. + + block = true; + + grid(0).compute().broadcast(new IgniteRunnable() { + @Override public void run() { + // No-op. + } + }); + + assertTrue(latch.await(15, TimeUnit.SECONDS)); + + assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + return grid(3).cluster().topologyVersion() == NODES_CNT + 1; + } + }, 5000)); + + for (int i = 0; i < 10; i++) { + U.sleep(1000); + + assertEquals(NODES_CNT - 1, grid(0).cluster().nodes().size()); + + int liveNodesCnt = 0; + + for (int j = 0; j < NODES_CNT; j++) { + IgniteEx ignite; + + try { + ignite = grid(j); + + log.info("Checking topology for grid(" + j + "): " + ignite.cluster().nodes()); + + ClusterNode locNode = ignite.localNode(); + + if (locNode.order() != 3) { + assertEquals(NODES_CNT - 1, ignite.cluster().nodes().size()); + + for (ClusterNode node : ignite.cluster().nodes()) + assertTrue(node.order() != 3); + + liveNodesCnt++; + } + } + catch (Exception e) { + log.info("Checking topology for grid(" + j + "): no grid in topology."); + } + } + + assertEquals(NODES_CNT - 1, liveNodesCnt); + } + } + + /** + * @throws Exception If failed. + */ + public void testTwoNodesEachOther() throws Exception { + pred = new IgniteBiPredicate() { + @Override public boolean apply(ClusterNode locNode, ClusterNode rmtNode) { + return block && (locNode.order() == 2 || locNode.order() == 4) && + (rmtNode.order() == 2 || rmtNode.order() == 4); + } + }; + + startGrids(NODES_CNT); + + final CountDownLatch latch = new CountDownLatch(1); + + grid(0).events().localListen(new IgnitePredicate() { + @Override + public boolean apply(Event event) { + latch.countDown(); + + return true; + } + }, EVT_NODE_FAILED); + + U.sleep(1000); // Wait for write timeout and closing idle connections. + + block = true; + + final CyclicBarrier barrier = new CyclicBarrier(2); + + IgniteInternalFuture fut1 = GridTestUtils.runAsync(new Callable() { + @Override public Void call() throws Exception { + barrier.await(); + + grid(1).compute().withNoFailover().broadcast(new IgniteRunnable() { + @Override public void run() { + // No-op. + } + }); + + return null; + } + }); + + IgniteInternalFuture fut2 = GridTestUtils.runAsync(new Callable() { + @Override public Void call() throws Exception { + barrier.await(); + + grid(3).compute().withNoFailover().broadcast(new IgniteRunnable() { + @Override public void run() { + // No-op. + } + }); + + return null; + } + }); + + assertTrue(latch.await(5, TimeUnit.SECONDS)); + + GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + return grid(2).cluster().nodes().size() == NODES_CNT - 1; + } + }, 5000); + + try { + fut1.get(); + } + catch (IgniteCheckedException e) { + // No-op. + } + + try { + fut2.get(); + } + catch (IgniteCheckedException e) { + // No-op. + } + + long failedNodeOrder = 1 + 2 + 3 + 4; + + for (ClusterNode node : grid(0).cluster().nodes()) + failedNodeOrder -= node.order(); + + for (int i = 0; i < 10; i++) { + U.sleep(1000); + + assertEquals(NODES_CNT - 1, grid(0).cluster().nodes().size()); + + int liveNodesCnt = 0; + + for (int j = 0; j < NODES_CNT; j++) { + IgniteEx ignite; + + try { + ignite = grid(j); + + log.info("Checking topology for grid(" + j + "): " + ignite.cluster().nodes()); + + ClusterNode locNode = ignite.localNode(); + + if (locNode.order() != failedNodeOrder) { + assertEquals(NODES_CNT - 1, ignite.cluster().nodes().size()); + + for (ClusterNode node : ignite.cluster().nodes()) + assertTrue(node.order() != failedNodeOrder); + + liveNodesCnt++; + } + } + catch (Exception e) { + log.info("Checking topology for grid(" + j + "): no grid in topology."); + } + } + + assertEquals(NODES_CNT - 1, liveNodesCnt); + } + } + + /** + * + */ + private static class TestCommunicationSpi extends TcpCommunicationSpi { + /** {@inheritDoc} */ + @Override protected GridCommunicationClient createTcpClient(ClusterNode node, int connIdx) throws IgniteCheckedException { + if (pred.apply(getLocalNode(), node)) { + Map attrs = new HashMap<>(node.attributes()); + + attrs.put(createAttributeName(ATTR_ADDRS), Collections.singleton("127.0.0.1")); + attrs.put(createAttributeName(ATTR_PORT), 47200); + attrs.put(createAttributeName(ATTR_EXT_ADDRS), Collections.emptyList()); + attrs.put(createAttributeName(ATTR_HOST_NAMES), Collections.emptyList()); + + ((TcpDiscoveryNode)node).setAttributes(attrs); + } + + return super.createTcpClient(node, connIdx); + } + + /** + * @param name Name. + */ + private String createAttributeName(String name) { + return getClass().getSimpleName() + '.' + name; + } + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiFaultyClientTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiFaultyClientTest.java new file mode 100644 index 0000000000000..0223cc39b72af --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiFaultyClientTest.java @@ -0,0 +1,270 @@ +/* + * 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.spi.communication.tcp; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +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.cluster.ClusterNode; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.events.Event; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.util.lang.GridAbsPredicate; +import org.apache.ignite.internal.util.nio.GridCommunicationClient; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.lang.IgniteRunnable; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode; +import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage; +import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeFailedMessage; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +import static org.apache.ignite.events.EventType.EVT_NODE_FAILED; + +/** + * Tests that faulty client will be failed if connection can't be established. + */ +public class TcpCommunicationSpiFaultyClientTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** Predicate. */ + private static final IgnitePredicate PRED = new IgnitePredicate() { + @Override public boolean apply(ClusterNode node) { + return block && node.order() == 3; + } + }; + + /** Client mode. */ + private static boolean clientMode; + + /** Block. */ + private static volatile boolean block; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setClockSyncFrequency(300000); + cfg.setFailureDetectionTimeout(1000); + cfg.setClientMode(clientMode); + + TestCommunicationSpi spi = new TestCommunicationSpi(); + + spi.setIdleConnectionTimeout(100); + spi.setSharedMemoryPort(-1); + + TcpDiscoverySpi discoSpi = (TcpDiscoverySpi) cfg.getDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + discoSpi.setClientReconnectDisabled(true); + + cfg.setCommunicationSpi(spi); + cfg.setDiscoverySpi(discoSpi); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + block = false; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + + /** + * @throws Exception If failed. + */ + public void testNoServerOnHost() throws Exception { + testFailClient(null); + } + + /** + * @throws Exception If failed. + */ + public void testNotAcceptedConnection() throws Exception { + testFailClient(new FakeServer()); + } + + /** + * @param srv Server. + * @throws Exception If failed. + */ + private void testFailClient(FakeServer srv) throws Exception { + IgniteInternalFuture fut = null; + + try { + if (srv != null) + fut = GridTestUtils.runMultiThreadedAsync(srv, 1, "fake-server"); + + clientMode = false; + + startGrids(2); + + clientMode = true; + + startGrid(2); + startGrid(3); + + U.sleep(1000); // Wait for write timeout and closing idle connections. + + final CountDownLatch latch = new CountDownLatch(1); + + grid(0).events().localListen(new IgnitePredicate() { + @Override + public boolean apply(Event event) { + latch.countDown(); + + return true; + } + }, EVT_NODE_FAILED); + + block = true; + + try { + grid(0).compute(grid(0).cluster().forClients()).withNoFailover().broadcast(new IgniteRunnable() { + @Override public void run() { + // No-op. + } + }); + } + catch (IgniteException e) { + // No-op. + } + + assertTrue(latch.await(3, TimeUnit.SECONDS)); + + assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + return grid(0).cluster().forClients().nodes().size() == 1; + } + }, 5000)); + + for (int i = 0; i < 5; i++) { + U.sleep(1000); + + log.info("Check topology (" + (i + 1) + "): " + grid(0).cluster().nodes()); + + assertEquals(1, grid(0).cluster().forClients().nodes().size()); + } + } + finally { + if (srv != null) { + srv.stop(); + + assert fut != null; + + fut.get(); + } + + stopAllGrids(); + } + } + + /** + * Server that emulates connection troubles. + */ + private static class FakeServer implements Runnable { + /** Server. */ + private final ServerSocket srv; + + /** Stop. */ + private volatile boolean stop; + + /** + * Default constructor. + */ + FakeServer() throws IOException { + this.srv = new ServerSocket(47200, 50, InetAddress.getByName("127.0.0.1")); + } + + /** + * + */ + public void stop() { + stop = true; + } + + /** {@inheritDoc} */ + @Override public void run() { + try { + while (!stop) { + try { + U.sleep(10); + } + catch (IgniteInterruptedCheckedException e) { + // No-op. + } + } + } + finally { + U.closeQuiet(srv); + } + } + } + + /** + * + */ + private static class TestCommunicationSpi extends TcpCommunicationSpi { + /** {@inheritDoc} */ + @Override protected GridCommunicationClient createTcpClient(ClusterNode node, int connIdx) throws IgniteCheckedException { + if (PRED.apply(node)) { + Map attrs = new HashMap<>(node.attributes()); + + attrs.put(createAttributeName(ATTR_ADDRS), Collections.singleton("127.0.0.1")); + attrs.put(createAttributeName(ATTR_PORT), 47200); + attrs.put(createAttributeName(ATTR_EXT_ADDRS), Collections.emptyList()); + attrs.put(createAttributeName(ATTR_HOST_NAMES), Collections.emptyList()); + + ((TcpDiscoveryNode)node).setAttributes(attrs); + } + + return super.createTcpClient(node, connIdx); + } + + /** + * @param name Name. + */ + private String createAttributeName(String name) { + return getClass().getSimpleName() + '.' + name; + } + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestNode.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestNode.java index e0e8eba0219fa..6365443542ac6 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestNode.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestNode.java @@ -82,6 +82,7 @@ public GridTestNode(UUID id) { private void initAttributes() { attrs.put(IgniteNodeAttributes.ATTR_BUILD_VER, "10"); attrs.put(IgniteNodeAttributes.ATTR_GRID_NAME, "null"); + attrs.put(IgniteNodeAttributes.ATTR_CLIENT_MODE, false); } /** diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java index b45e1732009cc..c68cfa116cadd 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java @@ -102,6 +102,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_DISCO_FAILED_CLIENT_RECONNECT_DELAY; import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.PRIMARY; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; @@ -173,6 +174,7 @@ public abstract class GridAbstractTest extends TestCase { static { System.setProperty(IgniteSystemProperties.IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE, "10000"); System.setProperty(IgniteSystemProperties.IGNITE_UPDATE_NOTIFIER, "false"); + System.setProperty(IGNITE_DISCO_FAILED_CLIENT_RECONNECT_DELAY, "1"); if (BINARY_MARSHALLER) GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName()); diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiCommunicationSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiCommunicationSelfTestSuite.java index 11fcfdab78728..77de3fcc54999 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiCommunicationSelfTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiCommunicationSelfTestSuite.java @@ -36,6 +36,8 @@ import org.apache.ignite.spi.communication.tcp.GridTcpCommunicationSpiTcpNoDelayOffSelfTest; import org.apache.ignite.spi.communication.tcp.GridTcpCommunicationSpiTcpSelfTest; import org.apache.ignite.spi.communication.tcp.IgniteTcpCommunicationRecoveryAckClosureSelfTest; +import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpiDropNodesTest; +import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpiFaultyClientTest; /** * Test suite for all communication SPIs. @@ -74,6 +76,9 @@ public static TestSuite suite() throws Exception { suite.addTest(new TestSuite(GridTcpCommunicationSpiConfigSelfTest.class)); + suite.addTest(new TestSuite(TcpCommunicationSpiFaultyClientTest.class)); + suite.addTest(new TestSuite(TcpCommunicationSpiDropNodesTest.class)); + return suite; } } diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java index 15f110ff9a392..eb019af8d91b0 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java @@ -66,9 +66,7 @@ import org.apache.ignite.events.CacheQueryExecutedEvent; import org.apache.ignite.events.CacheQueryReadEvent; import org.apache.ignite.events.Event; -import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.binary.BinaryMarshaller; -import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQuerySelfTest; import org.apache.ignite.internal.processors.cache.query.QueryCursorEx; import org.apache.ignite.internal.processors.query.GridQueryFieldMetadata; import org.apache.ignite.internal.util.tostring.GridToStringExclude; @@ -83,7 +81,6 @@ 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.jetbrains.annotations.Nullable; import org.jsr166.ConcurrentHashMap8; import static java.util.concurrent.TimeUnit.MILLISECONDS; From 6a88642543bd8391c678455ff1705a1a953b0299 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Fri, 20 Jan 2017 17:57:36 +0300 Subject: [PATCH 032/311] Revert: IGNITE-3477 - Fixed rejected execution exception on node stop. --- .../processors/cache/GridCacheTtlManager.java | 27 ++++-------- .../cache/IgniteCacheOffheapManagerImpl.java | 44 ++++++++----------- .../service/GridServiceProcessor.java | 10 ----- 3 files changed, 26 insertions(+), 55 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java index 795ddbe3e206b..98b9edff13997 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java @@ -70,30 +70,19 @@ public class GridCacheTtlManager extends GridCacheManagerAdapter { /** {@inheritDoc} */ @Override protected void start0() throws IgniteCheckedException { - if (cleanupDisabled()) - return; - - pendingEntries = (!cctx.isLocal() && cctx.config().getNearConfiguration() != null) ? new GridConcurrentSkipListSetEx() : null; - } - - /** {@inheritDoc} */ - @Override protected void onKernalStart0() throws IgniteCheckedException { - if (cleanupDisabled()) - return; - - cctx.shared().ttl().register(this); - } - - /** - * @return {@code Tu} - */ - private boolean cleanupDisabled() { - return cctx.kernalContext().isDaemon() || + boolean cleanupDisabled = cctx.kernalContext().isDaemon() || !cctx.config().isEagerTtl() || CU.isAtomicsCache(cctx.name()) || CU.isMarshallerCache(cctx.name()) || CU.isUtilityCache(cctx.name()) || (cctx.kernalContext().clientNode() && cctx.config().getNearConfiguration() == null); + + if (cleanupDisabled) + return; + + cctx.shared().ttl().register(this); + + pendingEntries = (!cctx.isLocal() && cctx.config().getNearConfiguration() != null) ? new GridConcurrentSkipListSetEx() : null; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index ffa7f60fa18fd..11e65d61e9f93 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -761,43 +761,35 @@ protected final String treeName(int p) { IgniteInClosure2X c, int amount ) throws IgniteCheckedException { - if (!busyLock.enterBusy()) - return false; - - try { - if (pendingEntries != null) { - GridCacheVersion obsoleteVer = null; + if (pendingEntries != null) { + GridCacheVersion obsoleteVer = null; - long now = U.currentTimeMillis(); + long now = U.currentTimeMillis(); - GridCursor cur = pendingEntries.find(START_PENDING_ROW, new PendingRow(now, 0)); + GridCursor cur = pendingEntries.find(START_PENDING_ROW, new PendingRow(now, 0)); - int cleared = 0; + int cleared = 0; - while (cur.next()) { - PendingRow row = cur.get(); + while (cur.next()) { + PendingRow row = cur.get(); - if (amount != -1 && cleared > amount) - return true; - - assert row.key != null && row.link != 0 && row.expireTime != 0 : row; + if (amount != -1 && cleared > amount) + return true; - if (pendingEntries.remove(row) != null) { - if (obsoleteVer == null) - obsoleteVer = cctx.versions().next(); + assert row.key != null && row.link != 0 && row.expireTime != 0 : row; - c.apply(cctx.cache().entryEx(row.key), obsoleteVer); - } + if (pendingEntries.remove(row) != null) { + if (obsoleteVer == null) + obsoleteVer = cctx.versions().next(); - cleared++; + c.apply(cctx.cache().entryEx(row.key), obsoleteVer); } - } - return false; - } - finally { - busyLock.leaveBusy(); + cleared++; + } } + + return false; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java index 21acbe4525f95..ab04e7eecc4b0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java @@ -350,8 +350,6 @@ CU.UTILITY_CACHE_NAME, new ServiceEntriesListener(), null, null U.shutdownNow(GridServiceProcessor.class, depExe, log); - depExe = null; - Exception err = new IgniteCheckedException("Operation has been cancelled (node is stopping)."); cancelFutures(depFuts, err); @@ -1418,10 +1416,6 @@ private class ServiceEntriesListener implements CacheEntryUpdatedListener Date: Mon, 23 Jan 2017 20:53:57 +0300 Subject: [PATCH 033/311] GG-11752: Fixed sporadic NPE on node start, was caused by bug in GridDhtForceKeyResponse handling --- .../ignite/internal/processors/cache/GridCacheMapEntry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ee39ed9a28ef7..e3dd3042f17b3 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 @@ -2969,7 +2969,7 @@ else if (deletedUnlocked()) cctx.cacheId(), key, val, - GridCacheOperation.CREATE, + val == null ? GridCacheOperation.DELETE : GridCacheOperation.CREATE, null, ver, expireTime, From 02505425aad9ff3b43e5de882f5aeb01a03257d0 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Tue, 24 Jan 2017 18:55:53 +0300 Subject: [PATCH 034/311] gg-11891 : Removed wrong assertion. Added Ignite DB tests for near caches. --- .../distributed/near/GridNearGetFuture.java | 4 - .../IgniteDbClientNearCachePutGetTest.java | 37 ++++ .../database/IgniteDbPutGetAbstractTest.java | 206 ++++++++++-------- 3 files changed, 151 insertions(+), 96 deletions(-) create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbClientNearCachePutGetTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java index b2a7906e31171..50a4f5b20f03e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java @@ -431,10 +431,6 @@ private Map map( // Allow to get cached value from the local node. boolean allowLocRead = !forcePrimary || cctx.localNode().equals(affNodes.get(0)); - // When persistence is enabled, only reading from partitions with OWNING state is allowed. - assert !allowLocRead || !cctx.shared().database().persistenceEnabled() || - cctx.topology().partitionState(cctx.localNodeId(), part) == GridDhtPartitionState.OWNING; - while (true) { GridNearCacheEntry entry = allowLocRead ? (GridNearCacheEntry)near.peekEx(key) : null; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbClientNearCachePutGetTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbClientNearCachePutGetTest.java new file mode 100644 index 0000000000000..fe4d64e87236e --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbClientNearCachePutGetTest.java @@ -0,0 +1,37 @@ +/* + * 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.database; + +public class IgniteDbClientNearCachePutGetTest extends IgniteDbPutGetAbstractTest { + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 1; + } + + /** {@inheritDoc} */ + @Override protected boolean indexingEnabled() { + return false; + } + + /** {@inheritDoc} */ + @Override protected boolean withClientNearCache() { + return true; + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java index 34745b461c371..6a0ab4fa98f40 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java @@ -47,9 +47,11 @@ import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.NearCacheConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter; import org.apache.ignite.internal.util.GridRandom; import org.apache.ignite.internal.util.typedef.PA; import org.apache.ignite.internal.util.typedef.X; @@ -68,6 +70,7 @@ public abstract class IgniteDbPutGetAbstractTest extends GridCommonAbstractTest { /** */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + private static final int KEYS_COUNT = 100_000; /** * @return Node count. @@ -79,12 +82,25 @@ public abstract class IgniteDbPutGetAbstractTest extends GridCommonAbstractTest */ protected abstract boolean indexingEnabled(); + /** + * @return {@code True} if cache operations should be called from client node with near cache. + */ + protected boolean withClientNearCache() { + return false; + } + + /** */ + private boolean client = false; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); MemoryConfiguration dbCfg = new MemoryConfiguration(); + if (client) + cfg.setClientMode(true); + if (isLargePage()) { dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); @@ -143,7 +159,8 @@ public abstract class IgniteDbPutGetAbstractTest extends GridCommonAbstractTest ccfg4.setAffinity(aff); - cfg.setCacheConfiguration(ccfg, ccfg2, ccfg3, ccfg4); + if (!client) + cfg.setCacheConfiguration(ccfg, ccfg2, ccfg3, ccfg4); TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); @@ -167,6 +184,14 @@ public abstract class IgniteDbPutGetAbstractTest extends GridCommonAbstractTest startGrids(gridCount()); + if (withClientNearCache()) { + client = true; + + startGrid(gridCount()); + + client = false; + } + awaitPartitionMapExchange(); } @@ -179,19 +204,39 @@ public abstract class IgniteDbPutGetAbstractTest extends GridCommonAbstractTest deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); } + /** + * @return Ignite instance for testing. + */ + private IgniteEx ig() { + if (withClientNearCache()) { + return grid(gridCount()); + } + + return grid(0); + } + + /** + * @return Cache for testing. + * @throws Exception If failed. + */ + private IgniteCache cache(String name) throws Exception { + if (withClientNearCache()) + return ig().getOrCreateNearCache(name, new NearCacheConfiguration()); + + return ig().cache(name); + } + /** * @return {@code True} if use large page. */ protected boolean isLargePage() { return false; - }; - - public void testGradualRandomPutAllRemoveAll() { - IgniteEx ig = grid(0); + } - IgniteCache cache = ig.cache(null); + public void testGradualRandomPutAllRemoveAll() throws Exception { + IgniteCache cache = cache(null); - final int cnt = 100_000; + final int cnt = KEYS_COUNT; Random rnd = BPlusTree.rnd; @@ -250,10 +295,8 @@ private void doPutRemoveAll(Random rnd, IgniteCache cache, Map /** * */ - public void testRandomRemove() { - IgniteEx ig = grid(0); - - IgniteCache cache = ig.cache(null); + public void testRandomRemove() throws Exception { + IgniteCache cache = cache(null); final int cnt = 50_000; @@ -289,13 +332,10 @@ public void testRandomRemove() { } } - /** */ - public void testRandomPut() { - IgniteEx ig = grid(0); - - IgniteCache cache = ig.cache(null); + public void testRandomPut() throws Exception { + IgniteCache cache = cache(null); final int cnt = 1_000; @@ -319,16 +359,13 @@ public void testRandomPut() { } } - /** * @throws Exception if failed. */ public void testPutGetSimple() throws Exception { - IgniteEx ig = grid(0); + IgniteCache cache = cache(null); - IgniteCache cache = ig.cache(null); - - GridCacheAdapter internalCache = ig.context().cache().internalCache(); + GridCacheAdapter internalCache = internalCache(cache); int k0 = 0; DbValue v0 = new DbValue(0, "value-0", 0L); @@ -350,9 +387,7 @@ public void testPutGetSimple() throws Exception { * @throws Exception if failed. */ public void testPutGetLarge() throws Exception { - IgniteEx ig = grid(0); - - IgniteCache cache = ig.cache(null); + IgniteCache cache = cache(null); final byte[] val = new byte[2048]; @@ -362,7 +397,7 @@ public void testPutGetLarge() throws Exception { Assert.assertArrayEquals(val, cache.get(0)); - final IgniteCache cache1 = ig.cache("large"); + final IgniteCache cache1 = cache("large"); final LargeDbValue large = new LargeDbValue("str1", "str2", randomInts(1024)); @@ -409,11 +444,9 @@ private int[] randomInts(final int size) { * @throws Exception if failed. */ public void testPutGetOverwrite() throws Exception { - IgniteEx ig = grid(0); - - final IgniteCache cache = ig.cache(null); + final IgniteCache cache = cache(null); - GridCacheAdapter internalCache = ig.context().cache().internalCache(); + GridCacheAdapter internalCache = internalCache(cache); final int k0 = 0; DbValue v0 = new DbValue(0, "value-0", 0L); @@ -439,11 +472,9 @@ public void testPutGetOverwrite() throws Exception { * @throws Exception if failed. */ public void testOverwriteNormalSizeAfterSmallerSize() throws Exception { - IgniteEx ig = grid(0); + final IgniteCache cache = cache(null); - final IgniteCache cache = ig.cache(null); - - GridCacheAdapter internalCache = ig.context().cache().internalCache(); + GridCacheAdapter internalCache = internalCache(cache); String[] vals = new String[] {"long-long-long-value", "short-value"}; final int k0 = 0; @@ -465,9 +496,7 @@ public void testOverwriteNormalSizeAfterSmallerSize() throws Exception { * @throws Exception if failed. */ public void testPutDoesNotTriggerRead() throws Exception { - IgniteEx ig = grid(0); - - final IgniteCache cache = ig.cache(null); + final IgniteCache cache = cache(null); cache.put(0, new DbValue(0, "test-value-0", 0)); } @@ -476,11 +505,9 @@ public void testPutDoesNotTriggerRead() throws Exception { * @throws Exception if failed. */ public void testPutGetMultipleObjects() throws Exception { - IgniteEx ig = grid(0); + final IgniteCache cache = cache(null); - final IgniteCache cache = ig.cache(null); - - GridCacheAdapter internalCache = ig.context().cache().internalCache(); + GridCacheAdapter internalCache = internalCache(cache); int cnt = 20_000; @@ -551,11 +578,9 @@ public void testPutGetMultipleObjects() throws Exception { * @throws Exception if failed. */ public void testSizeClear() throws Exception { - IgniteEx ig = grid(0); - - final IgniteCache cache = ig.cache(null); + final IgniteCache cache = cache(null); - GridCacheAdapter internalCache = ig.context().cache().internalCache(); + GridCacheAdapter internalCache = internalCache(cache); int cnt = 5000; @@ -584,13 +609,14 @@ public void testSizeClear() throws Exception { for (int i = 0; i < cnt; i++) assertNull(cache.get(i)); } + /** * @throws Exception if failed. */ public void testBounds() throws Exception { - IgniteEx ig = grid(0); + IgniteEx ig = ig(); - final IgniteCache cache = ig.cache(null); + final IgniteCache cache = cache(null); X.println("Put start"); @@ -646,7 +672,7 @@ public void testBounds() throws Exception { * @throws Exception if failed. */ public void testMultithreadedPut() throws Exception { - IgniteEx ig = grid(0); + IgniteEx ig = ig(); final IgniteCache cache = ig.cache(null); @@ -710,13 +736,11 @@ public void testMultithreadedPut() throws Exception { * @throws Exception if failed. */ public void testPutGetRandomUniqueMultipleObjects() throws Exception { - IgniteEx ig = grid(0); - - final IgniteCache cache = ig.cache(null); + final IgniteCache cache = cache(null); - GridCacheAdapter internalCache = ig.context().cache().internalCache(); + GridCacheAdapter internalCache = internalCache(cache); - int cnt = 100_000; + int cnt = KEYS_COUNT; Random rnd = new GridRandom(); @@ -779,13 +803,11 @@ private static int[] generateUniqueRandomKeys(int cnt, Random rnd) { * @throws Exception If failed. */ public void testPutPrimaryUniqueSecondaryDuplicates() throws Exception { - IgniteEx ig = grid(0); - - final IgniteCache cache = ig.cache(null); + final IgniteCache cache = cache(null); - GridCacheAdapter internalCache = ig.context().cache().internalCache(); + GridCacheAdapter internalCache = internalCache(cache); - int cnt = 100_000; + int cnt = KEYS_COUNT; Random rnd = new GridRandom(); @@ -825,13 +847,11 @@ public void testPutPrimaryUniqueSecondaryDuplicates() throws Exception { * @throws Exception if failed. */ public void testPutGetRandomNonUniqueMultipleObjects() throws Exception { - IgniteEx ig = grid(0); - - final IgniteCache cache = ig.cache(null); + final IgniteCache cache = cache(null); - GridCacheAdapter internalCache = ig.context().cache().internalCache(); + GridCacheAdapter internalCache = internalCache(cache); - int cnt = 100_000; + int cnt = KEYS_COUNT; Random rnd = new GridRandom(); @@ -873,13 +893,11 @@ public void testPutGetRandomNonUniqueMultipleObjects() throws Exception { * @throws Exception if failed. */ public void testPutGetRemoveMultipleForward() throws Exception { - IgniteEx ig = grid(0); + final IgniteCache cache = cache(null); - final IgniteCache cache = ig.cache(null); + GridCacheAdapter internalCache = internalCache(cache); - GridCacheAdapter internalCache = ig.context().cache().internalCache(); - - int cnt = 100_000; + int cnt = KEYS_COUNT; X.println("Put."); @@ -915,12 +933,10 @@ public void testPutGetRemoveMultipleForward() throws Exception { } } - public void _testRandomPutGetRemove() { - IgniteEx ig = grid(0); - - final IgniteCache cache = ig.cache(null); + public void _testRandomPutGetRemove() throws Exception { + final IgniteCache cache = cache(null); - int cnt = 100_000; + int cnt = KEYS_COUNT; Map map = new HashMap<>(cnt); @@ -930,7 +946,7 @@ public void _testRandomPutGetRemove() { Random rnd = new GridRandom(seed); - for (int i = 0 ; i < 1000_000; i++) { + for (int i = 0; i < 1000_000; i++) { if (i % 5000 == 0) X.println(" --> " + i); @@ -967,13 +983,11 @@ public void _testRandomPutGetRemove() { } public void testPutGetRemoveMultipleBackward() throws Exception { - IgniteEx ig = grid(0); - - final IgniteCache cache = ig.cache(null); + final IgniteCache cache = cache(null); - GridCacheAdapter internalCache = ig.context().cache().internalCache(); + GridCacheAdapter internalCache = internalCache(cache); - int cnt = 100_000; + int cnt = KEYS_COUNT; X.println("Put."); @@ -1013,11 +1027,9 @@ public void testPutGetRemoveMultipleBackward() throws Exception { * @throws Exception if failed. */ public void testIndexOverwrite() throws Exception { - IgniteEx ig = grid(0); - - final IgniteCache cache = ig.cache(null); + final IgniteCache cache = cache(null); - GridCacheAdapter internalCache = ig.context().cache().internalCache("non-primitive"); + GridCacheAdapter internalCache = internalCache(cache); X.println("Put start"); @@ -1058,13 +1070,13 @@ public void testIndexOverwrite() throws Exception { * @throws Exception if failed. */ public void testObjectKey() throws Exception { - IgniteEx ig = grid(0); + IgniteEx ig = ig(); - final IgniteCache cache = ig.cache("non-primitive"); + final IgniteCache cache = cache("non-primitive"); - GridCacheAdapter internalCache = ig.context().cache().internalCache("non-primitive"); + GridCacheAdapter internalCache = internalCache(cache); - int cnt = 100_000; + int cnt = KEYS_COUNT; Map map = new HashMap<>(); @@ -1103,7 +1115,7 @@ public void testObjectKey() throws Exception { * @throws Exception If failed. */ public void testIterators() throws Exception { - IgniteEx ignite = grid(0); + IgniteEx ignite = ig(); IgniteCache cache = ignite.cache("non-primitive"); @@ -1305,6 +1317,12 @@ private void checkScanPartition(Ignite ignite, } private void checkEmpty(final GridCacheAdapter internalCache, final Object key) throws Exception { + if (internalCache.isNear()) { + checkEmpty(((GridNearCacheAdapter)internalCache).dht(), key); + + return; + } + GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return internalCache.peekEx(key) == null; @@ -1432,13 +1450,17 @@ public LargeDbValue(final String str1, final String str2, final int[] arr) { /** {@inheritDoc} */ @Override public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; - final LargeDbValue that = (LargeDbValue) o; + final LargeDbValue that = (LargeDbValue)o; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) + return false; + if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) + return false; return Arrays.equals(arr, that.arr); From b19b250f585a72adc81dd1ea368a15c0986664ee Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Thu, 26 Jan 2017 13:27:17 +0300 Subject: [PATCH 035/311] GG-11891 - Removed incorrect assert --- .../database/IgniteDbClientNearCachePutGetTest.java | 4 +++- .../processors/database/IgniteDbPutGetAbstractTest.java | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbClientNearCachePutGetTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbClientNearCachePutGetTest.java index fe4d64e87236e..aa0819021e629 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbClientNearCachePutGetTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbClientNearCachePutGetTest.java @@ -18,8 +18,10 @@ package org.apache.ignite.internal.processors.database; +/** + * + */ public class IgniteDbClientNearCachePutGetTest extends IgniteDbPutGetAbstractTest { - /** {@inheritDoc} */ @Override protected int gridCount() { return 1; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java index 6a0ab4fa98f40..ce8f22521ebb4 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java @@ -70,7 +70,9 @@ public abstract class IgniteDbPutGetAbstractTest extends GridCommonAbstractTest { /** */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - private static final int KEYS_COUNT = 100_000; + + /** */ + private static final int KEYS_COUNT = 20_000; /** * @return Node count. @@ -176,7 +178,7 @@ protected boolean withClientNearCache() { @Override protected void beforeTest() throws Exception { deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - long seed = 1464583813940L; // System.currentTimeMillis(); + long seed = System.currentTimeMillis(); info("Seed: " + seed + "L"); @@ -345,7 +347,7 @@ public void testRandomPut() throws Exception { Random rnd = new GridRandom(seed); - for (int i = 0; i < 500_000; i++) { + for (int i = 0; i < 50_000; i++) { int k = rnd.nextInt(cnt); DbValue v0 = new DbValue(k, "test-value " + k, i); From 6796f83c9542008480a5d9320ea6cc4e92e0978c Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Thu, 26 Jan 2017 15:17:58 +0300 Subject: [PATCH 036/311] GG-11910 Impossible to create snapshot if previous failed --- .../ignite/testframework/config/GridTestProperties.java | 8 +++----- .../testframework/junits/multijvm/IgniteProcessProxy.java | 4 +++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java b/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java index d13f11738cd4b..f65ca517d5747 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java @@ -96,7 +96,7 @@ public final class GridTestProperties { // Load default properties. File cfgFile = getTestConfigurationFile(null, TESTS_PROP_FILE); - assert cfgFile.exists(); + assert cfgFile != null && cfgFile.exists(); assert !cfgFile.isDirectory(); dfltProps = Collections.unmodifiableMap(loadFromFile(new HashMap(), cfgFile)); @@ -307,13 +307,11 @@ private static Map loadFromFile(Map props, File fileProps.load(in); - for (Entry prop : fileProps.entrySet()) { + for (Entry prop : fileProps.entrySet()) props.put((String) prop.getKey(), (String) prop.getValue()); - } - for (Entry prop : props.entrySet()) { + for (Entry prop : props.entrySet()) prop.setValue(substituteProperties(prop.getValue())); - } } } catch (IOException e) { diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java index 15a520a57140f..396574c892788 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java @@ -161,7 +161,9 @@ public IgniteProcessProxy(IgniteConfiguration cfg, IgniteLogger log, Ignite locJ System.getProperty("surefire.test.class.path") ); - assert rmtNodeStartedLatch.await(30, TimeUnit.SECONDS): "Remote node has not joined [id=" + id + ']'; + boolean success = rmtNodeStartedLatch.await(30, TimeUnit.SECONDS); + + assert success : "Remote node has not joined [id=" + id + ']'; IgniteProcessProxy prevVal = gridProxies.putIfAbsent(cfg.getGridName(), this); From c5bc114b031a2109004abd7fc7f7ad21063cbc47 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Fri, 27 Jan 2017 11:02:31 +0700 Subject: [PATCH 037/311] GG-11904 Fixed restore for not existing ID. Minor refactoring. --- .../org/apache/ignite/internal/visor/VisorOneNodeTask.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorOneNodeTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorOneNodeTask.java index e4880a8b3048b..e992875056464 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorOneNodeTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorOneNodeTask.java @@ -19,7 +19,6 @@ import java.util.List; import org.apache.ignite.compute.ComputeJobResult; -import org.apache.ignite.internal.util.typedef.F; import org.jetbrains.annotations.Nullable; /** @@ -30,11 +29,11 @@ public abstract class VisorOneNodeTask extends VisorMultiNodeTask @Nullable @Override protected R reduce0(List results) { assert results.size() == 1; - ComputeJobResult res = F.first(results); + ComputeJobResult res = results.get(0); if (res.getException() == null) return res.getData(); throw res.getException(); } -} \ No newline at end of file +} From c258eab4336d16ae2951ff6852ec25f3896761d7 Mon Sep 17 00:00:00 2001 From: Evgeny Stanilovskiy Date: Wed, 1 Feb 2017 14:21:49 +0300 Subject: [PATCH 038/311] ignite-4557 Renamed affinity manager's methods to avoid key/partition confusion --- .../processors/cache/GridCacheAdapter.java | 10 ++-- .../cache/GridCacheAffinityManager.java | 54 +++++++------------ .../processors/cache/GridCacheContext.java | 17 ------ .../cache/GridCacheEvictionManager.java | 6 +-- .../processors/cache/GridCacheUtils.java | 20 ------- .../cache/IgniteCacheOffheapManagerImpl.java | 4 +- .../cache/affinity/GridCacheAffinityImpl.java | 16 +++--- .../CacheDataStructuresManager.java | 2 +- .../GridDistributedCacheAdapter.java | 8 +-- .../distributed/dht/GridDhtCacheAdapter.java | 2 +- .../distributed/dht/GridDhtCacheEntry.java | 2 +- .../dht/GridDhtLocalPartition.java | 4 +- .../distributed/dht/GridDhtTxRemote.java | 2 +- .../dht/GridPartitionedGetFuture.java | 2 +- .../dht/GridPartitionedSingleGetFuture.java | 2 +- .../dht/atomic/GridDhtAtomicCache.java | 12 ++--- .../GridNearAtomicSingleUpdateFuture.java | 2 +- .../atomic/GridNearAtomicUpdateFuture.java | 4 +- .../dht/colocated/GridDhtColocatedCache.java | 6 +-- .../colocated/GridDhtColocatedLockFuture.java | 4 +- .../preloader/GridDhtPartitionSupplier.java | 2 +- .../dht/preloader/GridDhtPreloader.java | 2 +- .../distributed/near/GridNearAtomicCache.java | 2 +- .../distributed/near/GridNearCacheEntry.java | 6 +-- .../distributed/near/GridNearGetFuture.java | 2 +- .../distributed/near/GridNearLockFuture.java | 2 +- ...OptimisticSerializableTxPrepareFuture.java | 2 +- .../GridNearOptimisticTxPrepareFuture.java | 2 +- .../GridNearPessimisticTxPrepareFuture.java | 2 +- .../near/GridNearTransactionalCache.java | 6 +-- .../cache/query/GridCacheQueryManager.java | 9 ++-- .../CacheContinuousQueryHandler.java | 2 +- .../CacheContinuousQueryManager.java | 2 +- .../cache/transactions/IgniteTxAdapter.java | 4 +- .../transactions/IgniteTxLocalAdapter.java | 4 +- .../transactions/TxDeadlockDetection.java | 2 +- .../datastreamer/DataStreamerImpl.java | 2 +- .../datastructures/GridCacheSetImpl.java | 2 +- .../datastructures/GridSetQueryPredicate.java | 2 +- .../processors/job/GridJobProcessor.java | 2 +- .../service/GridServiceProcessor.java | 2 +- .../cache/CacheAffinityCallSelfTest.java | 4 +- .../IgniteCachePeekModesAbstractTest.java | 4 +- ...tQueueFailoverDataConsistencySelfTest.java | 2 +- ...teCacheClientNodeChangingTopologyTest.java | 8 +-- .../TxOptimisticDeadlockDetectionTest.java | 2 +- .../TxPessimisticDeadlockDetectionTest.java | 2 +- .../processors/query/h2/IgniteH2Indexing.java | 2 +- .../query/h2/opt/GridH2IndexBase.java | 2 +- 49 files changed, 108 insertions(+), 158 deletions(-) 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 0b65bfc0308e8..97ca07770bcf3 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 @@ -780,7 +780,7 @@ public String toString() { boolean nearKey; if (!(modes.near && modes.primary && modes.backup)) { - boolean keyPrimary = ctx.affinity().primary(ctx.localNode(), part, topVer); + boolean keyPrimary = ctx.affinity().primaryByPartition(ctx.localNode(), part, topVer); if (keyPrimary) { if (!modes.primary) @@ -789,7 +789,7 @@ public String toString() { nearKey = false; } else { - boolean keyBackup = ctx.affinity().belongs(ctx.localNode(), part, topVer); + boolean keyBackup = ctx.affinity().partitionBelongs(ctx.localNode(), part, topVer); if (keyBackup) { if (!modes.backup) @@ -809,7 +809,7 @@ public String toString() { } } else { - nearKey = !ctx.affinity().belongs(ctx.localNode(), part, topVer); + nearKey = !ctx.affinity().partitionBelongs(ctx.localNode(), part, topVer); if (nearKey) { // Swap and offheap are disabled for near cache. @@ -3840,8 +3840,8 @@ IgniteInternalFuture globalLoadCacheAsync(@Nullable IgniteBiPredicate p /** {@inheritDoc} */ @Override public boolean apply(ClusterNode clusterNode) { return clusterNode.version().compareTo(PartitionSizeLongTask.SINCE_VER) >= 0 && - ((modes.primary && aff.primary(clusterNode, part, topVer)) || - (modes.backup && aff.backup(clusterNode, part, topVer))); + ((modes.primary && aff.primaryByPartition(clusterNode, part, topVer)) || + (modes.backup && aff.backupByPartition(clusterNode, part, topVer))); } }).nodes(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java index c7e2f6b290f73..a65d971db155f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java @@ -238,8 +238,8 @@ public Object affinityKey(Object key) { * @param topVer Topology version. * @return Affinity nodes. */ - public List nodes(Object key, AffinityTopologyVersion topVer) { - return nodes(partition(key), topVer); + public List nodesByKey(Object key, AffinityTopologyVersion topVer) { + return nodesByPartition(partition(key), topVer); } /** @@ -247,7 +247,7 @@ public List nodes(Object key, AffinityTopologyVersion topVer) { * @param topVer Topology version. * @return Affinity nodes. */ - public List nodes(int part, AffinityTopologyVersion topVer) { + public List nodesByPartition(int part, AffinityTopologyVersion topVer) { if (cctx.isLocal()) topVer = LOC_CACHE_TOP_VER; @@ -282,8 +282,8 @@ public AffinityAssignment assignment(AffinityTopologyVersion topVer) { * @param topVer Topology version. * @return Primary node for given key. */ - @Nullable public ClusterNode primary(Object key, AffinityTopologyVersion topVer) { - return primary(partition(key), topVer); + @Nullable public ClusterNode primaryByKey(Object key, AffinityTopologyVersion topVer) { + return primaryByPartition(partition(key), topVer); } /** @@ -291,8 +291,8 @@ public AffinityAssignment assignment(AffinityTopologyVersion topVer) { * @param topVer Topology version. * @return Primary node for given key. */ - @Nullable public ClusterNode primary(int part, AffinityTopologyVersion topVer) { - List nodes = nodes(part, topVer); + @Nullable public ClusterNode primaryByPartition(int part, AffinityTopologyVersion topVer) { + List nodes = nodesByPartition(part, topVer); if (nodes.isEmpty()) return null; @@ -306,8 +306,8 @@ public AffinityAssignment assignment(AffinityTopologyVersion topVer) { * @param topVer Topology version. * @return {@code True} if checked node is primary for given key. */ - public boolean primary(ClusterNode n, Object key, AffinityTopologyVersion topVer) { - return F.eq(primary(key, topVer), n); + public boolean primaryByKey(ClusterNode n, Object key, AffinityTopologyVersion topVer) { + return F.eq(primaryByKey(key, topVer), n); } /** @@ -316,8 +316,8 @@ public boolean primary(ClusterNode n, Object key, AffinityTopologyVersion topVer * @param topVer Topology version. * @return {@code True} if checked node is primary for given partition. */ - public boolean primary(ClusterNode n, int part, AffinityTopologyVersion topVer) { - return F.eq(primary(part, topVer), n); + public boolean primaryByPartition(ClusterNode n, int part, AffinityTopologyVersion topVer) { + return F.eq(primaryByPartition(part, topVer), n); } /** @@ -325,8 +325,8 @@ public boolean primary(ClusterNode n, int part, AffinityTopologyVersion topVer) * @param topVer Topology version. * @return Backup nodes. */ - public Collection backups(Object key, AffinityTopologyVersion topVer) { - return backups(partition(key), topVer); + public Collection backupsByKey(Object key, AffinityTopologyVersion topVer) { + return backupsByPartition(partition(key), topVer); } /** @@ -334,8 +334,8 @@ public Collection backups(Object key, AffinityTopologyVersion topVe * @param topVer Topology version. * @return Backup nodes. */ - public Collection backups(int part, AffinityTopologyVersion topVer) { - List nodes = nodes(part, topVer); + private Collection backupsByPartition(int part, AffinityTopologyVersion topVer) { + List nodes = nodesByPartition(part, topVer); assert !F.isEmpty(nodes); @@ -351,28 +351,14 @@ public Collection backups(int part, AffinityTopologyVersion topVer) * @param topVer Topology version. * @return {@code True} if checked node is a backup node for given partition. */ - public boolean backup(ClusterNode n, int part, AffinityTopologyVersion topVer) { - List nodes = nodes(part, topVer); + public boolean backupByPartition(ClusterNode n, int part, AffinityTopologyVersion topVer) { + List nodes = nodesByPartition(part, topVer); assert !F.isEmpty(nodes); return nodes.indexOf(n) > 0; } - /** - * @param keys keys. - * @param topVer Topology version. - * @return Nodes for the keys. - */ - public Collection remoteNodes(Iterable keys, AffinityTopologyVersion topVer) { - Collection> colcol = new GridLeanSet<>(); - - for (Object key : keys) - colcol.add(nodes(key, topVer)); - - return F.view(F.flatCollections(colcol), F.remoteNodes(cctx.localNodeId())); - } - /** * @param key Key to check. * @param topVer Topology version. @@ -390,7 +376,7 @@ public boolean keyLocalNode(Object key, AffinityTopologyVersion topVer) { public boolean partitionLocalNode(int part, AffinityTopologyVersion topVer) { assert part >= 0 : "Invalid partition: " + part; - return nodes(part, topVer).contains(cctx.localNode()); + return nodesByPartition(part, topVer).contains(cctx.localNode()); } /** @@ -399,11 +385,11 @@ public boolean partitionLocalNode(int part, AffinityTopologyVersion topVer) { * @param topVer Topology version. * @return {@code true} if given partition belongs to specified node. */ - public boolean belongs(ClusterNode node, int part, AffinityTopologyVersion topVer) { + public boolean partitionBelongs(ClusterNode node, int part, AffinityTopologyVersion topVer) { assert node != null; assert part >= 0 : "Invalid partition: " + part; - return nodes(part, topVer).contains(node); + return nodesByPartition(part, topVer).contains(node); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java index fd0ececf23639..c7bf4e9e7b5ab 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java @@ -1554,23 +1554,6 @@ private void map(GridDhtCacheEntry entry, Iterable nodes, } } - /** - * Checks if at least one of the given keys belongs to one of the given partitions. - * - * @param keys Collection of keys to check. - * @param movingParts Collection of partitions to check against. - * @return {@code True} if there exist a key in collection {@code keys} that belongs - * to one of partitions in {@code movingParts} - */ - public boolean hasKey(Iterable keys, Collection movingParts) { - for (K key : keys) { - if (movingParts.contains(affinity().partition(key))) - return true; - } - - return false; - } - /** * Check whether conflict resolution is required. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java index e22ace3295bb7..97cc28a9c870d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java @@ -775,7 +775,7 @@ private boolean evict0( return; // Don't track non-primary entries if evicts are synchronized. - if (!cctx.isNear() && evictSync && !cctx.affinity().primary(cctx.localNode(), e.partition(), topVer)) + if (!cctx.isNear() && evictSync && !cctx.affinity().primaryByPartition(cctx.localNode(), e.partition(), topVer)) return; if (!busyLock.enterBusy()) @@ -867,7 +867,7 @@ private void warnFirstEvict() { if (evictSyncAgr) { assert !cctx.isNear(); // Make sure cache is not NEAR. - if (cctx.affinity().backups( + if (cctx.affinity().backupsByKey( entry.key(), cctx.topology().topologyVersion()).contains(cctx.localNode()) && evictSync) @@ -1449,7 +1449,7 @@ void addEvent(DiscoveryEvent evt) { if (!evts.isEmpty()) break; - if (!cctx.affinity().primary(loc, it.next(), topVer)) + if (!cctx.affinity().primaryByPartition(loc, it.next(), topVer)) it.remove(); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java index 7e0e66e026fb7..3c234b9db1fd8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java @@ -943,26 +943,6 @@ public static void unwindEvicts(GridCacheSharedContext ctx) { unwindEvicts(cacheCtx); } - /** - * Gets primary node on which given key is cached. - * - * @param ctx Cache. - * @param key Key to find primary node for. - * @return Primary node for the key. - */ - @SuppressWarnings( {"unchecked"}) - @Nullable public static ClusterNode primaryNode(GridCacheContext ctx, Object key) { - assert ctx != null; - assert key != null; - - CacheConfiguration cfg = ctx.cache().configuration(); - - if (cfg.getCacheMode() != PARTITIONED) - return ctx.localNode(); - - return ctx.affinity().primary(key, ctx.affinity().affinityTopologyVersion()); - } - /** * @param asc {@code True} for ascending. * @return Descending order comparator. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index 11e65d61e9f93..06986316883a3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -245,7 +245,7 @@ private CacheDataStore dataStore(GridDhtLocalPartition part) { for (GridDhtLocalPartition locPart : cctx.topology().currentLocalPartitions()) { if (primary) { - if (cctx.affinity().primary(locNode, locPart.id(), topVer)) { + if (cctx.affinity().primaryByPartition(locNode, locPart.id(), topVer)) { cnt += locPart.size(); continue; @@ -253,7 +253,7 @@ private CacheDataStore dataStore(GridDhtLocalPartition part) { } if (backup) { - if (cctx.affinity().backup(locNode, locPart.id(), topVer)) + if (cctx.affinity().backupByPartition(locNode, locPart.id(), topVer)) cnt += locPart.size(); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java index 9e85bad610432..11361a27d384a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java @@ -82,21 +82,21 @@ public GridCacheAffinityImpl(GridCacheContext cctx) { @Override public boolean isPrimary(ClusterNode n, K key) { A.notNull(n, "n", key, "key"); - return cctx.affinity().primary(n, key, topologyVersion()); + return cctx.affinity().primaryByKey(n, key, topologyVersion()); } /** {@inheritDoc} */ @Override public boolean isBackup(ClusterNode n, K key) { A.notNull(n, "n", key, "key"); - return cctx.affinity().backups(key, topologyVersion()).contains(n); + return cctx.affinity().backupsByKey(key, topologyVersion()).contains(n); } /** {@inheritDoc} */ @Override public boolean isPrimaryOrBackup(ClusterNode n, K key) { A.notNull(n, "n", key, "key"); - return cctx.affinity().belongs(n, cctx.affinity().partition(key), topologyVersion()); + return cctx.affinity().partitionBelongs(n, cctx.affinity().partition(key), topologyVersion()); } /** {@inheritDoc} */ @@ -126,7 +126,7 @@ public GridCacheAffinityImpl(GridCacheContext cctx) { AffinityTopologyVersion topVer = topologyVersion(); for (int partsCnt = partitions(), part = 0; part < partsCnt; part++) { - for (ClusterNode affNode : cctx.affinity().nodes(part, topVer)) { + for (ClusterNode affNode : cctx.affinity().nodesByPartition(part, topVer)) { if (n.id().equals(affNode.id())) { parts.add(part); @@ -142,7 +142,7 @@ public GridCacheAffinityImpl(GridCacheContext cctx) { @Override public ClusterNode mapPartitionToNode(int part) { A.ensure(part >= 0 && part < partitions(), "part >= 0 && part < total partitions"); - return F.first(cctx.affinity().nodes(part, topologyVersion())); + return F.first(cctx.affinity().nodesByPartition(part, topologyVersion())); } /** {@inheritDoc} */ @@ -204,7 +204,7 @@ public GridCacheAffinityImpl(GridCacheContext cctx) { Map> res = new HashMap<>(nodesCnt, 1.0f); for (K key : keys) { - ClusterNode primary = cctx.affinity().primary(key, topVer); + ClusterNode primary = cctx.affinity().primaryByKey(key, topVer); if (primary == null) throw new IgniteException("Failed to get primary node [topVer=" + topVer + ", key=" + key + ']'); @@ -227,14 +227,14 @@ public GridCacheAffinityImpl(GridCacheContext cctx) { @Override public Collection mapKeyToPrimaryAndBackups(K key) { A.notNull(key, "key"); - return cctx.affinity().nodes(partition(key), topologyVersion()); + return cctx.affinity().nodesByPartition(partition(key), topologyVersion()); } /** {@inheritDoc} */ @Override public Collection mapPartitionToPrimaryAndBackups(int part) { A.ensure(part >= 0 && part < partitions(), "part >= 0 && part < total partitions"); - return cctx.affinity().nodes(part, topologyVersion()); + return cctx.affinity().nodesByPartition(part, topologyVersion()); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java index c1983df4f4d86..d864d3c01b988 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java @@ -455,7 +455,7 @@ private void removeSetData(IgniteUuid setId, AffinityTopologyVersion topVer) thr Collection keys = new ArrayList<>(BATCH_SIZE); for (SetItemKey key : set) { - if (!loc && !aff.primary(cctx.localNode(), key, topVer)) + if (!loc && !aff.primaryByKey(cctx.localNode(), key, topVer)) continue; keys.add(key); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java index 89c54c4700724..93e6eb00f990e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java @@ -282,7 +282,7 @@ private void removeAllAsync( } /** {@inheritDoc} */ - @Override public long localSizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException { + @Override public long localSizeLong(int part, CachePeekMode[] peekModes) throws IgniteCheckedException { PeekModes modes = parsePeekModes(peekModes, true); long size = 0; @@ -296,9 +296,9 @@ private void removeAllAsync( IgniteCacheOffheapManager offheap = ctx.offheap(); - if (ctx.affinity().primary(ctx.localNode(), partition, topVer) && modes.primary || - ctx.affinity().backup(ctx.localNode(), partition, topVer) && modes.backup) - size += offheap.entriesCount(partition); + if (ctx.affinity().primaryByPartition(ctx.localNode(), part, topVer) && modes.primary || + ctx.affinity().backupByPartition(ctx.localNode(), part, topVer) && modes.backup) + size += offheap.entriesCount(part); } return size; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java index 4dcba75558df7..13524396b679d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java @@ -938,7 +938,7 @@ public void sendTtlUpdateRequest(@Nullable final IgniteCacheExpiryPolicy expiryP AffinityTopologyVersion topVer = ctx.shared().exchange().readyAffinityVersion(); for (Map.Entry e : entries.entrySet()) { - List nodes = ctx.affinity().nodes(e.getKey(), topVer); + List nodes = ctx.affinity().nodesByKey(e.getKey(), topVer); for (int i = 0; i < nodes.size(); i++) { ClusterNode node = nodes.get(i); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java index b0ec4084b06f8..fa5ea9c12c1cc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java @@ -413,7 +413,7 @@ public Collection readers() throws GridCacheEntryRemovedException { } // If remote node is (primary?) or back up, don't add it as a reader. - if (cctx.affinity().belongs(node, partition(), topVer)) { + if (cctx.affinity().partitionBelongs(node, partition(), topVer)) { if (log.isDebugEnabled()) log.debug("Ignoring near reader because remote node is affinity node [locNodeId=" + cctx.localNodeId() + ", rmtNodeId=" + nodeId + ", key=" + key + ']'); 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 efc5ea74504c1..4a4f834b7dbd8 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 @@ -817,7 +817,7 @@ void onUnlock() { * @return {@code True} if local node is primary for this partition. */ public boolean primary(AffinityTopologyVersion topVer) { - return cctx.affinity().primary(cctx.localNode(), id, topVer); + return cctx.affinity().primaryByPartition(cctx.localNode(), id, topVer); } /** @@ -825,7 +825,7 @@ public boolean primary(AffinityTopologyVersion topVer) { * @return {@code True} if local node is backup for this partition. */ public boolean backup(AffinityTopologyVersion topVer) { - return cctx.affinity().backup(cctx.localNode(), id, topVer); + return cctx.affinity().backupByPartition(cctx.localNode(), id, topVer); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java index 6ad20c7566553..f3c49630a112e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java @@ -274,7 +274,7 @@ IgniteUuid remoteFutureId() { return true; // Check if we are on the backup node. - return !cacheCtx.affinity().backups(key, topVer).contains(cctx.localNode()); + return !cacheCtx.affinity().backupsByKey(key, topVer).contains(cctx.localNode()); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java index 548e1f0f0abcc..1a6f61c8c9b0a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java @@ -392,7 +392,7 @@ private boolean map( ) { int part = cctx.affinity().partition(key); - List affNodes = cctx.affinity().nodes(part, topVer); + List affNodes = cctx.affinity().nodesByPartition(part, topVer); if (affNodes.isEmpty()) { onDone(serverNotFoundError(topVer)); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java index ec4a3e9809b1a..6e438ed8069ab 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java @@ -341,7 +341,7 @@ private void map(final AffinityTopologyVersion topVer) { @Nullable private ClusterNode mapKeyToNode(AffinityTopologyVersion topVer) { int part = cctx.affinity().partition(key); - List affNodes = cctx.affinity().nodes(part, topVer); + List affNodes = cctx.affinity().nodesByPartition(part, topVer); if (affNodes.isEmpty()) { onDone(serverNotFoundError(topVer)); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index 0560198d6f31b..ac5fda260d34b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -2479,7 +2479,7 @@ private UpdateSingleResult updateSingle( assert !(newConflictVer instanceof GridCacheVersionEx) : newConflictVer; - boolean primary = !req.fastMap() || ctx.affinity().primary(ctx.localNode(), entry.partition(), + boolean primary = !req.fastMap() || ctx.affinity().primaryByPartition(ctx.localNode(), entry.partition(), req.topologyVersion()); Object writeVal = op == TRANSFORM ? req.entryProcessor(i) : req.writeValue(i); @@ -2569,7 +2569,7 @@ else if (conflictCtx.isMerge()) if (hasNear) { if (primary && updRes.sendToDht()) { - if (!ctx.affinity().belongs(node, entry.partition(), topVer)) { + if (!ctx.affinity().partitionBelongs(node, entry.partition(), topVer)) { // If put the same value as in request then do not need to send it back. if (op == TRANSFORM || writeVal != updRes.newValue()) { res.addNearValue(i, @@ -2700,7 +2700,7 @@ else if (F.contains(readers, node.id())) // Reader became primary or backup. Map storeMap = req.fastMap() ? F.view(putMap, new P1() { @Override public boolean apply(CacheObject key) { - return ctx.affinity().primary(ctx.localNode(), key, req.topologyVersion()); + return ctx.affinity().primaryByKey(ctx.localNode(), key, req.topologyVersion()); } }) : putMap; @@ -2726,7 +2726,7 @@ else if (F.contains(readers, node.id())) // Reader became primary or backup. Collection storeKeys = req.fastMap() ? F.view(rmvKeys, new P1() { @Override public boolean apply(Object key) { - return ctx.affinity().primary(ctx.localNode(), key, req.topologyVersion()); + return ctx.affinity().primaryByKey(ctx.localNode(), key, req.topologyVersion()); } }) : rmvKeys; @@ -2765,7 +2765,7 @@ else if (F.contains(readers, node.id())) // Reader became primary or backup. assert writeVal != null || op == DELETE : "null write value found."; - boolean primary = !req.fastMap() || ctx.affinity().primary(ctx.localNode(), entry.key(), + boolean primary = !req.fastMap() || ctx.affinity().primaryByKey(ctx.localNode(), entry.key(), req.topologyVersion()); Collection readers = null; @@ -2861,7 +2861,7 @@ else if (F.contains(readers, node.id())) // Reader became primary or backup. if (hasNear) { if (primary) { - if (!ctx.affinity().belongs(node, entry.partition(), topVer)) { + if (!ctx.affinity().partitionBelongs(node, entry.partition(), topVer)) { int idx = firstEntryIdx + i; if (req.operation() == TRANSFORM) { 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 a39838a13868e..7cfc146b836a4 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 @@ -559,7 +559,7 @@ private GridNearAtomicAbstractUpdateRequest mapSingleUpdate(AffinityTopologyVers else val = EntryProcessorResourceInjectorProxy.wrap(cctx.kernalContext(), (EntryProcessor)val); - ClusterNode primary = cctx.affinity().primary(cacheKey, topVer); + ClusterNode primary = cctx.affinity().primaryByKey(cacheKey, topVer); if (primary == null) throw new ClusterTopologyServerNotFoundException("Failed to map keys for cache (all partition nodes " + 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 33225ce8d9be0..66e82b8ce7837 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 @@ -949,7 +949,7 @@ else if (conflictRmvVals != null) { else val = EntryProcessorResourceInjectorProxy.wrap(cctx.kernalContext(), (EntryProcessor)val); - ClusterNode primary = cctx.affinity().primary(cacheKey.partition(), topVer); + ClusterNode primary = cctx.affinity().primaryByPartition(cacheKey.partition(), topVer); if (primary == null) throw new ClusterTopologyServerNotFoundException("Failed to map keys for cache (all partition nodes " + @@ -1001,7 +1001,7 @@ private List mapKey(KeyCacheObject key, AffinityTopologyVersion top // If we can send updates in parallel - do it. return fastMap ? cctx.topology().nodes(affMgr.partition(key), topVer) : - Collections.singletonList(affMgr.primary(key, topVer)); + Collections.singletonList(affMgr.primaryByKey(key, topVer)); } /** {@inheritDoc} */ 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 d5e83897ccacb..e53c59c1f2674 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 @@ -170,7 +170,7 @@ public GridDistributedCacheEntry entryExx( AffinityTopologyVersion topVer, boolean allowDetached ) { - return allowDetached && !ctx.affinity().primary(ctx.localNode(), key, topVer) ? + return allowDetached && !ctx.affinity().primaryByKey(ctx.localNode(), key, topVer) ? createEntry(key) : entryExx(key, topVer); } @@ -664,7 +664,7 @@ else if (!skipVals && ctx.config().isStatisticsEnabled()) assert topVer.compareTo(AffinityTopologyVersion.ZERO) > 0; // Send request to remove from remote nodes. - ClusterNode primary = ctx.affinity().primary(key, topVer); + ClusterNode primary = ctx.affinity().primaryByKey(key, topVer); if (primary == null) { if (log.isDebugEnabled()) @@ -784,7 +784,7 @@ public void removeLocks(long threadId, GridCacheVersion ver, Collection keys, AffinityTopologyVe boolean explicit = false; for (KeyCacheObject key : keys) { - if (!cctx.affinity().primary(cctx.localNode(), key, topVer)) { + if (!cctx.affinity().primaryByKey(cctx.localNode(), key, topVer)) { // Remove explicit locks added so far. for (KeyCacheObject k : keys) cctx.mvcc().removeExplicitLock(threadId, cctx.txKey(k), lockVer); @@ -1285,7 +1285,7 @@ private GridNearLockMapping map( ) throws IgniteCheckedException { assert mapping == null || mapping.node() != null; - ClusterNode primary = cctx.affinity().primary(key, topVer); + ClusterNode primary = cctx.affinity().primaryByKey(key, topVer); if (primary == null) throw new ClusterTopologyServerNotFoundException("Failed to lock keys " + diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java index 97d768a1e3887..b80ad04eb09c1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java @@ -287,7 +287,7 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage iter = (IgniteRebalanceIterator)sctx.entryIt; while (iter.hasNext()) { - if (!cctx.affinity().belongs(node, part, d.topologyVersion())) { + if (!cctx.affinity().partitionBelongs(node, part, d.topologyVersion())) { // Demander no longer needs this partition, // so we send '-1' partition and move on. s.missed(part); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java index 518739dd47029..8ada4b3d74605 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java @@ -349,7 +349,7 @@ private IgniteCheckedException stopError() { * @return Picked owners. */ private Collection pickedOwners(int p, AffinityTopologyVersion topVer) { - Collection affNodes = cctx.affinity().nodes(p, topVer); + Collection affNodes = cctx.affinity().nodesByPartition(p, topVer); int affCnt = affNodes.size(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java index 4d63ebb34cd52..28859540ebd4a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java @@ -161,7 +161,7 @@ public void processNearAtomicUpdateResponse( if (F.contains(failed, key)) continue; - if (ctx.affinity().belongs(ctx.localNode(), ctx.affinity().partition(key), req.topologyVersion())) { // Reader became backup. + if (ctx.affinity().partitionBelongs(ctx.localNode(), ctx.affinity().partition(key), req.topologyVersion())) { // Reader became backup. GridCacheEntryEx entry = peekEx(key); if (entry != null && entry.markObsolete(ver)) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java index a8e1ee695c13f..84ab1820404e0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java @@ -113,7 +113,7 @@ public GridNearCacheEntry( return false; } - if (cctx.affinity().backup(cctx.localNode(), part, topVer)) { + if (cctx.affinity().backupByPartition(cctx.localNode(), part, topVer)) { this.topVer = AffinityTopologyVersion.NONE; return false; @@ -163,7 +163,7 @@ public void initializeFromDht(AffinityTopologyVersion topVer) throws GridCacheEn } } - ClusterNode primaryNode = cctx.affinity().primary(key, topVer); + ClusterNode primaryNode = cctx.affinity().primaryByKey(key, topVer); if (primaryNode == null) this.topVer = AffinityTopologyVersion.NONE; @@ -699,7 +699,7 @@ private void primaryNode(UUID nodeId, AffinityTopologyVersion topVer) { ClusterNode primary = null; try { - primary = cctx.affinity().primary(part, topVer); + primary = cctx.affinity().primaryByPartition(part, topVer); } catch (IllegalStateException ignore) { // Do not have affinity history. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java index 50a4f5b20f03e..fb07ac4685e54 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java @@ -418,7 +418,7 @@ private Map map( ) { int part = cctx.affinity().partition(key); - List affNodes = cctx.affinity().nodes(part, topVer); + List affNodes = cctx.affinity().nodesByPartition(part, topVer); if (affNodes.isEmpty()) { onDone(serverNotFoundError(topVer)); 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 c69ddcfdb17d5..1759c1c9523d6 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 @@ -1371,7 +1371,7 @@ private GridNearLockMapping map( ) throws IgniteCheckedException { assert mapping == null || mapping.node() != null; - ClusterNode primary = cctx.affinity().primary(key, topVer); + ClusterNode primary = cctx.affinity().primaryByKey(key, topVer); if (primary == null) throw new ClusterTopologyServerNotFoundException("Failed to lock keys " + diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java index c464b36217fd8..a8448dcfd9680 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java @@ -529,7 +529,7 @@ private void map( GridCacheContext cacheCtx = entry.context(); List nodes = cacheCtx.isLocal() ? - cacheCtx.affinity().nodes(entry.key(), topVer) : + cacheCtx.affinity().nodesByKey(entry.key(), topVer) : cacheCtx.topology().nodes(cacheCtx.affinity().partition(entry.key()), topVer); txMapping.addMapping(nodes); 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 58e1d2841bb2f..b096c98cb3846 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 @@ -605,7 +605,7 @@ private GridDistributedTxMapping map( nodes = cacheCtx.topology().nodes(cached0.partition(), topVer); else nodes = cacheCtx.isLocal() ? - cacheCtx.affinity().nodes(entry.key(), topVer) : + cacheCtx.affinity().nodesByKey(entry.key(), topVer) : cacheCtx.topology().nodes(cacheCtx.affinity().partition(entry.key()), topVer); txMapping.addMapping(nodes); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java index f9a2f90787b3c..a4132f22b2b6b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java @@ -196,7 +196,7 @@ private void preparePessimistic() { GridCacheContext cacheCtx = txEntry.context(); List nodes = cacheCtx.isLocal() ? - cacheCtx.affinity().nodes(txEntry.key(), topVer) : + cacheCtx.affinity().nodesByKey(txEntry.key(), topVer) : cacheCtx.topology().nodes(cacheCtx.affinity().partition(txEntry.key()), topVer); ClusterNode primary = F.first(nodes); 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 d7b208608772e..c3517ac7f5189 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 @@ -479,7 +479,7 @@ private void processLockResponse(UUID nodeId, GridNearLockResponse res) { * @return {@code True} if entry is locally mapped as a primary or back up node. */ protected boolean isNearLocallyMapped(GridCacheEntryEx e, AffinityTopologyVersion topVer) { - return ctx.affinity().belongs(ctx.localNode(), e.partition(), topVer); + return ctx.affinity().partitionBelongs(ctx.localNode(), e.partition(), topVer); } /** @@ -551,7 +551,7 @@ protected boolean evictNearEntry(GridCacheEntryEx e, GridCacheVersion obsoleteVe topVer = cand.topologyVersion(); // Send request to remove from remote nodes. - ClusterNode primary = ctx.affinity().primary(key, topVer); + ClusterNode primary = ctx.affinity().primaryByKey(key, topVer); if (primary == null) { if (log.isDebugEnabled()) @@ -671,7 +671,7 @@ public void removeLocks(GridCacheVersion ver, Collection keys) { map = U.newHashMap(affNodes.size()); } - ClusterNode primary = ctx.affinity().primary(key, cand.topologyVersion()); + ClusterNode primary = ctx.affinity().primaryByKey(key, cand.topologyVersion()); if (primary == null) { if (log.isDebugEnabled()) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java index 081a27cb61765..3d42fd7838533 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java @@ -1234,11 +1234,11 @@ protected void runQuery(GridCacheQueryInfo qryInfo) { // Other types are filtered in indexing manager. if (!cctx.isReplicated() && qry.type() == SCAN && qry.partition() == null && cctx.config().getCacheMode() != LOCAL && !incBackups && - !cctx.affinity().primary(cctx.localNode(), key, topVer)) { + !cctx.affinity().primaryByKey(cctx.localNode(), key, topVer)) { if (log.isDebugEnabled()) log.debug("Ignoring backup element [row=" + row + ", cacheMode=" + cctx.config().getCacheMode() + ", incBackups=" + incBackups + - ", primary=" + cctx.affinity().primary(cctx.localNode(), key, topVer) + ']'); + ", primary=" + cctx.affinity().primaryByKey(cctx.localNode(), key, topVer) + ']'); continue; } @@ -1246,7 +1246,8 @@ protected void runQuery(GridCacheQueryInfo qryInfo) { V val = row.getValue(); if (log.isDebugEnabled()) { - ClusterNode primaryNode = CU.primaryNode(cctx, key); + ClusterNode primaryNode = cctx.affinity().primaryByKey(key, + cctx.affinity().affinityTopologyVersion()); log.debug("Record [key=" + key + ", val=" + val + @@ -2008,7 +2009,7 @@ public Collection sqlMetadata() throws IgniteCheckedExcept return new IgniteBiPredicate() { @Override public boolean apply(K k, V v) { - return cache.context().affinity().primary(ctx.discovery().localNode(), k, NONE); + return cache.context().affinity().primaryByKey(ctx.discovery().localNode(), k, NONE); } }; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java index ea5551d1c449d..72e9b186f5452 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java @@ -862,7 +862,7 @@ private String taskName() { GridCacheAffinityManager aff = cctx.affinity(); if (initUpdCntrsPerNode != null) { - for (ClusterNode node : aff.nodes(partId, initTopVer)) { + for (ClusterNode node : aff.nodesByPartition(partId, initTopVer)) { Map> map = initUpdCntrsPerNode.get(node.id()); if (map != null) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java index d2828e0e775ad..b5c4dcf14dce1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java @@ -368,7 +368,7 @@ public void onEntryExpired(GridCacheEntryEx e, KeyCacheObject key, CacheObject o if (F.isEmpty(lsnrCol)) return; - boolean primary = cctx.affinity().primary(cctx.localNode(), e.partition(), AffinityTopologyVersion.NONE); + boolean primary = cctx.affinity().primaryByPartition(cctx.localNode(), e.partition(), AffinityTopologyVersion.NONE); if (cctx.isReplicated() || primary) { boolean recordIgniteEvt = cctx.gridEvents().isRecordable(EVT_CACHE_QUERY_OBJECT_READ); 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 287893193d129..ce07eb5b3293c 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 @@ -1288,7 +1288,7 @@ protected void batchStoreCommit(Iterable writeEntries) throws Ign if (!skip && skipNonPrimary) { skip = e.cached().isNear() || e.cached().detached() || - !e.context().affinity().primary(e.cached().partition(), topologyVersion()).isLocal(); + !e.context().affinity().primaryByPartition(e.cached().partition(), topologyVersion()).isLocal(); } if (!skip && !local() && // Update local store at backups only if needed. @@ -1705,7 +1705,7 @@ protected boolean isNearLocallyMapped(IgniteTxEntry e, boolean primaryOnly) { int part = cached != null ? cached.partition() : cacheCtx.affinity().partition(e.key()); - List affNodes = cacheCtx.affinity().nodes(part, topologyVersion()); + List affNodes = cacheCtx.affinity().nodesByPartition(part, topologyVersion()); e.locallyMapped(F.contains(affNodes, cctx.localNode())); 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 9fcae351c01a6..ac218d82f6935 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 @@ -1128,7 +1128,7 @@ assert isWriteToStoreFromDhtValid(stores) : * @return {@code True} if local node is current primary for given entry. */ private boolean primaryLocal(GridCacheEntryEx entry) { - return entry.context().affinity().primary(cctx.localNode(), entry.partition(), AffinityTopologyVersion.NONE); + return entry.context().affinity().primaryByPartition(cctx.localNode(), entry.partition(), AffinityTopologyVersion.NONE); } /** @@ -1409,7 +1409,7 @@ private Collection enlistRead( finally { if (entry != null && readCommitted()) { if (cacheCtx.isNear()) { - if (cacheCtx.affinity().belongs(cacheCtx.localNode(), entry.partition(), topVer)) { + if (cacheCtx.affinity().partitionBelongs(cacheCtx.localNode(), entry.partition(), topVer)) { if (entry.markObsolete(xidVer)) cacheCtx.cache().removeEntry(entry); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetection.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetection.java index 70d938e144ead..67d00ea782923 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetection.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetection.java @@ -401,7 +401,7 @@ private void mapTxKeys(@Nullable Set txKeys, Map dataNodes(AffinityTopologyVersion topVer) throws Collection nodes; if (collocated) { - List nodes0 = ctx.affinity().nodes(hdrPart, topVer); + List nodes0 = ctx.affinity().nodesByPartition(hdrPart, topVer); nodes = !nodes0.isEmpty() ? Collections.singleton(nodes0.contains(ctx.localNode()) ? ctx.localNode() : F.first(nodes0)) : nodes0; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridSetQueryPredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridSetQueryPredicate.java index e8b2cc7f0f4b8..bc6c1827a0774 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridSetQueryPredicate.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridSetQueryPredicate.java @@ -91,7 +91,7 @@ public IgniteUuid setId() { /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public boolean apply(K k, V v) { - return !filter || ctx.affinity().primary(ctx.localNode(), k, ctx.affinity().affinityTopologyVersion()); + return !filter || ctx.affinity().primaryByKey(ctx.localNode(), k, ctx.affinity().affinityTopologyVersion()); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobProcessor.java index c34bcb1f46424..0598e4cedfc42 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobProcessor.java @@ -1568,7 +1568,7 @@ public PartitionsReservation(int[] cacheIds, int partId, } } finally { - if (checkPartMapping && !cctx.affinity().primary(partId, topVer).id().equals(ctx.localNodeId())) + if (checkPartMapping && !cctx.affinity().primaryByPartition(partId, topVer).id().equals(ctx.localNodeId())) throw new IgniteException("Failed partition reservation. " + "Partition is not primary on the node. [partition=" + partId + ", cacheName=" + cctx.name() + ", nodeId=" + ctx.localNodeId() + ", topology=" + topVer + ']'); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java index ab04e7eecc4b0..9587b046cd71d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java @@ -1668,7 +1668,7 @@ private class TopologyListener implements GridLocalEventListener { while (it.hasNext()) { Cache.Entry e = it.next(); - if (cache.context().affinity().primary(ctx.grid().localNode(), e.getKey(), topVer)) { + if (cache.context().affinity().primaryByKey(ctx.grid().localNode(), e.getKey(), topVer)) { String name = ((GridServiceAssignmentsKey)e.getKey()).name(); try { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheAffinityCallSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheAffinityCallSelfTest.java index 92e2b9b2ba21d..b0337d62967e0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheAffinityCallSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheAffinityCallSelfTest.java @@ -214,12 +214,12 @@ public CheckCallable(Object key, AffinityTopologyVersion topVer) { ClusterNode loc = ignite.cluster().localNode(); - if (loc.equals(aff.primary(key, topVer))) + if (loc.equals(aff.primaryByKey(key, topVer))) return true; AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer.topologyVersion() + 1, 0); - assertEquals(loc, aff.primary(key, topVer0)); + assertEquals(loc, aff.primaryByKey(key, topVer0)); } return null; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java index 2bf109c4c1e9f..33937af610bb7 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java @@ -1059,9 +1059,9 @@ private T2 offheapKeysCount(int nodeIdx, int part) throws Igni //And then find out whether they are primary or backup ones. int primaryCnt = 0; int backupCnt = 0; - if (affinity.primary(ctx.localNode(), part, topVer)) + if (affinity.primaryByPartition(ctx.localNode(), part, topVer)) primaryCnt = cnt; - else if (affinity.backup(ctx.localNode(), part, topVer)) + else if (affinity.backupByPartition(ctx.localNode(), part, topVer)) backupCnt = cnt; return new T2<>(primaryCnt, backupCnt); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractQueueFailoverDataConsistencySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractQueueFailoverDataConsistencySelfTest.java index 4f02fa284997b..c0d7745ab3577 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractQueueFailoverDataConsistencySelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractQueueFailoverDataConsistencySelfTest.java @@ -370,7 +370,7 @@ private int primaryQueueNode(IgniteQueue queue) throws Exception { for (Cache.Entry e : grid(i).context().cache().internalCache(cctx.name()).localEntries(modes)) { Object key = e.getKey(); - if (aff.primary(grid(i).localNode(), key, AffinityTopologyVersion.NONE) + if (aff.primaryByKey(grid(i).localNode(), key, AffinityTopologyVersion.NONE) && key instanceof GridCacheQueueHeaderKey) return i; } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheClientNodeChangingTopologyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheClientNodeChangingTopologyTest.java index 05bbf1d052bf1..9c39ad7231411 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheClientNodeChangingTopologyTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheClientNodeChangingTopologyTest.java @@ -853,13 +853,13 @@ public void testPessimisticTx2() throws Exception { GridCacheAffinityManager aff = ignite0.context().cache().internalCache(null).context().affinity(); - List nodes1 = aff.nodes(key1, topVer1); - List nodes2 = aff.nodes(key1, topVer2); + List nodes1 = aff.nodesByKey(key1, topVer1); + List nodes2 = aff.nodesByKey(key1, topVer2); assertEquals(nodes1, nodes2); - nodes1 = aff.nodes(key2, topVer1); - nodes2 = aff.nodes(key2, topVer2); + nodes1 = aff.nodesByKey(key2, topVer1); + nodes2 = aff.nodesByKey(key2, topVer2); assertFalse(nodes1.get(0).equals(nodes2.get(0))); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxOptimisticDeadlockDetectionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxOptimisticDeadlockDetectionTest.java index f6a06c29a9fbe..66cfc4ee7338c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxOptimisticDeadlockDetectionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxOptimisticDeadlockDetectionTest.java @@ -289,7 +289,7 @@ private void doTestDeadlock( key = keys.get(1); ClusterNode primaryNode = - ((IgniteCacheProxy)cache).context().affinity().primary(key, NONE); + ((IgniteCacheProxy)cache).context().affinity().primaryByKey(key, NONE); List primaryKeys = primaryKeys(grid(primaryNode).cache(CACHE_NAME), 5, key + (100 * threadNum)); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java index 83eb908d21978..ced8b61166876 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java @@ -293,7 +293,7 @@ private void doTestDeadlock( key = keys.get(1); ClusterNode primaryNode = - ((IgniteCacheProxy)cache).context().affinity().primary(key, NONE); + ((IgniteCacheProxy)cache).context().affinity().primaryByKey(key, NONE); List primaryKeys = primaryKeys(grid(primaryNode).cache(CACHE_NAME), 5, key + (100 * threadNum)); diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index 98b5b7fd8d92a..a2160ffcce70e 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -2132,7 +2132,7 @@ private void createSqlFunctions(String schema, Class[] clss) throws IgniteChe return new IgniteBiPredicate() { @Override public boolean apply(K k, V v) { - return aff.primary(locNode, k, topVer0); + return aff.primaryByKey(locNode, k, topVer0); } }; } diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java index 4ef015b3f591f..80b0ea3dd0c0a 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java @@ -610,7 +610,7 @@ private ClusterNode rangeNode(GridCacheContext cctx, GridH2QueryContext qct node = cctx.discovery().node(nodeId); } else // Get primary node for current topology version. - node = cctx.affinity().primary(affKeyObj, qctx.topologyVersion()); + node = cctx.affinity().primaryByKey(affKeyObj, qctx.topologyVersion()); if (node == null) // Node was not found, probably topology changed and we need to retry the whole query. throw new GridH2RetryException("Failed to find node."); From 4b3fdc42fe88a525957a2ad416dd9ab39a2d4e64 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Thu, 2 Feb 2017 19:54:30 +0300 Subject: [PATCH 039/311] GG-11878 - Snapshots ignore node filter --- .../StartFullSnapshotAckDiscoveryMessage.java | 18 +++- .../StartFullSnapshotDiscoveryMessage.java | 16 +++- .../processors/cache/GridCacheEntryEx.java | 7 ++ .../processors/cache/GridCacheMapEntry.java | 11 ++- .../cache/IgniteCacheOffheapManager.java | 20 ++++- .../cache/IgniteCacheOffheapManagerImpl.java | 37 ++++++-- .../IgniteCacheDatabaseSharedManager.java | 3 +- .../processors/query/GridQueryIndexing.java | 10 +-- .../processors/query/GridQueryProcessor.java | 64 ++++++++------ .../ignite/internal/util/IgniteUtils.java | 2 +- .../internal/util/future/CountDownFuture.java | 74 ++++++++++++++++ .../cache/GridCacheTestEntryEx.java | 5 ++ .../processors/query/h2/IgniteH2Indexing.java | 86 +++++++------------ .../query/h2/database/H2TreeIndex.java | 2 +- 14 files changed, 245 insertions(+), 110 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java index 0d926b9d1b692..8ce2bd76be64d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java @@ -22,6 +22,8 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; @@ -61,10 +63,15 @@ public class StartFullSnapshotAckDiscoveryMessage implements DiscoveryCustomMess * @param err Error. * @param cacheNames Cache names. */ - public StartFullSnapshotAckDiscoveryMessage(long globalSnapshotId, boolean fullSnapshot, + public StartFullSnapshotAckDiscoveryMessage( + long globalSnapshotId, + boolean fullSnapshot, Map lastFullSnapshotIdForCache, - Collection cacheNames, Exception err, - UUID initiatorNodeId, String msg) { + Collection cacheNames, + Exception err, + UUID initiatorNodeId, + String msg + ) { this.globalSnapshotId = globalSnapshotId; this.fullSnapshot = fullSnapshot; this.lastFullSnapshotIdForCache = lastFullSnapshotIdForCache; @@ -144,4 +151,9 @@ public String message() { @Override public boolean isMutable() { return false; } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(StartFullSnapshotAckDiscoveryMessage.class, this); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java index 8d18131d74324..b85fe82c68871 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java @@ -23,6 +23,8 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; @@ -143,7 +145,14 @@ public void lastFullSnapshotId(int cacheId, long id) { /** {@inheritDoc} */ @Nullable @Override public DiscoveryCustomMessage ackMessage() { - return new StartFullSnapshotAckDiscoveryMessage(globalSnapshotId, fullSnapshot, lastFullSnapshotIdForCache, cacheNames, err, initiatorId, msg); + return new StartFullSnapshotAckDiscoveryMessage( + globalSnapshotId, + fullSnapshot, + lastFullSnapshotIdForCache, + cacheNames, + err, + initiatorId, + msg); } /** {@inheritDoc} */ @@ -157,4 +166,9 @@ public void lastFullSnapshotId(int cacheId, long id) { public void fullSnapshot(boolean full) { fullSnapshot = full; } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(StartFullSnapshotDiscoveryMessage.class, this); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java index 26e4ed3e60905..4e74594bb1b31 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java @@ -912,6 +912,13 @@ public Collection localCandidates(@Nullable GridCacheVer */ public void updateTtl(@Nullable GridCacheVersion ver, long ttl) throws GridCacheEntryRemovedException; + /** + * Ensures that the value stored in the entry is also inserted in the indexing. + * + * @throws GridCacheEntryRemovedException If entry was removed. + */ + public void ensureIndexed() throws GridCacheEntryRemovedException, IgniteCheckedException; + /** * @return Value. * @throws IgniteCheckedException If failed to read from swap storage. 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 e3dd3042f17b3..4b73c8bd2ec12 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 @@ -3516,6 +3516,15 @@ private IgniteTxLocalAdapter currentTx() { } } + /** {@inheritDoc} */ + @Override public void ensureIndexed() throws GridCacheEntryRemovedException, IgniteCheckedException { + synchronized (this) { + checkObsolete(); + + cctx.offheap().updateIndexes(key, localPartition()); + } + } + /** {@inheritDoc} */ @Override public synchronized CacheObject valueBytes() throws GridCacheEntryRemovedException { checkObsolete(); @@ -3552,7 +3561,7 @@ protected void storeValue(@Nullable CacheObject val, assert Thread.holdsLock(this); assert val != null : "null values in update for key: " + key; - cctx.offheap().update(key, val, ver, expireTime, partition(), localPartition()); + cctx.offheap().update(key, val, ver, expireTime, localPartition()); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java index f01f0ffeeaafc..a93338fb4e357 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java @@ -111,7 +111,6 @@ public interface IgniteCacheOffheapManager extends GridCacheManager { * @param val Value. * @param ver Version. * @param expireTime Expire time. - * @param partId Partition number. * @param part Partition. * @throws IgniteCheckedException If failed. */ @@ -120,7 +119,16 @@ public void update( CacheObject val, GridCacheVersion ver, long expireTime, - int partId, + GridDhtLocalPartition part + ) throws IgniteCheckedException; + + /** + * @param key Key. + * @param part Partition. + * @throws IgniteCheckedException If failed. + */ + public void updateIndexes( + KeyCacheObject key, GridDhtLocalPartition part ) throws IgniteCheckedException; @@ -295,18 +303,22 @@ interface CacheDataStore { /** * @param key Key. - * @param part Partition. * @param val Value. * @param ver Version. * @param expireTime Expire time. * @throws IgniteCheckedException If failed. */ void update(KeyCacheObject key, - int part, CacheObject val, GridCacheVersion ver, long expireTime) throws IgniteCheckedException; + /** + * @param key Key. + * @throws IgniteCheckedException If failed. + */ + void updateIndexes(KeyCacheObject key) throws IgniteCheckedException; + /** * @param key Key. * @param partId Partition number. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index 06986316883a3..c0e7da9ea8553 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -23,7 +23,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; import javax.cache.Cache; import org.apache.ignite.IgniteCheckedException; @@ -320,12 +319,16 @@ private Iterator cacheData(boolean primary, boolean backup, Affi CacheObject val, GridCacheVersion ver, long expireTime, - int partId, GridDhtLocalPartition part ) throws IgniteCheckedException { assert expireTime >= 0; - dataStore(part).update(key, partId, val, ver, expireTime); + dataStore(part).update(key, val, ver, expireTime); + } + + /** {@inheritDoc} */ + @Override public void updateIndexes(KeyCacheObject key, GridDhtLocalPartition part) throws IgniteCheckedException { + dataStore(part).updateIndexes(key); } /** {@inheritDoc} */ @@ -876,11 +879,10 @@ public CacheDataStoreImpl( /** {@inheritDoc} */ @Override public void update(KeyCacheObject key, - int p, CacheObject val, GridCacheVersion ver, long expireTime) throws IgniteCheckedException { - DataRow dataRow = new DataRow(key.hashCode(), key, val, ver, p, expireTime); + DataRow dataRow = new DataRow(key.hashCode(), key, val, ver, partId, expireTime); // Make sure value bytes initialized. key.valueBytes(cctx.cacheObjectContext()); @@ -905,9 +907,9 @@ public CacheDataStoreImpl( assert qryMgr.enabled(); if (old != null) - qryMgr.store(key, p, old.value(), old.version(), val, ver, expireTime, dataRow.link()); + qryMgr.store(key, partId, old.value(), old.version(), val, ver, expireTime, dataRow.link()); else - qryMgr.store(key, p, null, null, val, ver, expireTime, dataRow.link()); + qryMgr.store(key, partId, null, null, val, ver, expireTime, dataRow.link()); } if (old != null) { @@ -929,6 +931,27 @@ public CacheDataStoreImpl( } } + /** {@inheritDoc} */ + @Override public void updateIndexes(KeyCacheObject key) throws IgniteCheckedException { + if (indexingEnabled) { + DataRow row = dataTree.findOne(new KeySearchRow(key.hashCode(), key, 0)); + + GridCacheQueryManager qryMgr = cctx.queries(); + + if (row != null) { + qryMgr.store( + key, + partId, + null, + null, + row.value(), + row.version(), + row.expireTime(), + row.link()); + } + } + } + /** {@inheritDoc} */ @Override public void remove(KeyCacheObject key, int partId) throws IgniteCheckedException { if (!busyLock.enterBusy()) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 18b3a1f0ed3a9..02e376329a114 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -174,8 +174,7 @@ public void waitForCheckpoint(String reason) throws IgniteCheckedException { /** * */ - @Nullable public IgniteInternalFuture wakeupForSnapshot(long snapshotId, UUID snapshotNodeId, - Collection cacheNames) { + @Nullable public IgniteInternalFuture wakeupForSnapshot(long snapshotId) { return null; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java index 9fda64d851942..ef344261e853d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java @@ -32,8 +32,6 @@ import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.GridSpinBusyLock; import org.apache.ignite.internal.util.lang.GridCloseableIterator; @@ -232,20 +230,16 @@ public void remove(@Nullable String spaceName, * Rebuilds all indexes of given type from hash index. * * @param spaceName Space name. - * @param type Type descriptor. * @throws IgniteCheckedException If failed. */ - public void rebuildIndexesFromHash(@Nullable String spaceName, - GridQueryTypeDescriptor type) throws IgniteCheckedException; + public void rebuildIndexesFromHash(@Nullable String spaceName) throws IgniteCheckedException; /** * Marks all indexes of given type for rebuild from hash index, making them unusable until rebuild finishes. * * @param spaceName Space name. - * @param type Type descriptor. - * @throws IgniteCheckedException If failed. */ - public void markForRebuildFromHash(@Nullable String spaceName, GridQueryTypeDescriptor type); + public void markForRebuildFromHash(@Nullable String spaceName); /** * Returns backup filter. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 42be691cdcad9..ff501816ef04e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -17,12 +17,11 @@ package org.apache.ignite.internal.processors.query; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.concurrent.TimeUnit; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.math.BigDecimal; +import java.sql.PreparedStatement; +import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; import java.util.ArrayList; @@ -40,6 +39,7 @@ import java.util.UUID; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; import javax.cache.Cache; import javax.cache.CacheException; import org.apache.ignite.IgniteCheckedException; @@ -70,9 +70,8 @@ import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper; -import org.apache.ignite.internal.processors.cache.IgniteCacheProxy; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.QueryCursorImpl; import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture; @@ -91,7 +90,6 @@ import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.A; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.util.worker.GridWorker; @@ -598,7 +596,7 @@ public IgniteInternalFuture rebuildIndexes(@Nullable final String space, Stri throw new IllegalStateException("Failed to rebuild indexes (grid is stopping)."); try { - return rebuildIndexes(space, typesByName.get(new TypeName(space, valTypeName)), false); + return rebuildIndexes(space, typesByName.get(new TypeName(space, valTypeName))); } finally { busyLock.leaveBusy(); @@ -610,8 +608,7 @@ public IgniteInternalFuture rebuildIndexes(@Nullable final String space, Stri * @param desc Type descriptor. * @return Future that will be completed when rebuilding of all indexes is finished. */ - private IgniteInternalFuture rebuildIndexes(@Nullable final String space, @Nullable final TypeDescriptor desc, - final boolean fromHash) { + private IgniteInternalFuture rebuildIndexes(@Nullable final String space, @Nullable final TypeDescriptor desc) { if (idx == null) return new GridFinishedFuture<>(new IgniteCheckedException("Indexing is disabled.")); @@ -620,16 +617,10 @@ private IgniteInternalFuture rebuildIndexes(@Nullable final String space, @Nu final GridWorkerFuture fut = new GridWorkerFuture(); - if (fromHash) - idx.markForRebuildFromHash(space, desc); - GridWorker w = new GridWorker(ctx.gridName(), "index-rebuild-worker", log) { @Override protected void body() { try { - if (fromHash) - idx.rebuildIndexesFromHash(space, desc); - else - idx.rebuildIndexes(space, desc); + idx.rebuildIndexes(space, desc); fut.onDone(); } @@ -637,7 +628,8 @@ private IgniteInternalFuture rebuildIndexes(@Nullable final String space, @Nu fut.onDone(e); } catch (Throwable e) { - log.error("Failed to rebuild indexes for type: " + desc.name(), e); + U.error(log, "Failed to rebuild indexes for type [space=" + space + + ", name=" + desc.name() + ']', e); fut.onDone(e); @@ -668,7 +660,7 @@ public IgniteInternalFuture rebuildAllIndexes() { GridCompoundFuture fut = new GridCompoundFuture(); for (Map.Entry e : types.entrySet()) - fut.add((IgniteInternalFuture)rebuildIndexes(e.getKey().space, e.getValue(), false)); + fut.add((IgniteInternalFuture)rebuildIndexes(e.getKey().space, e.getValue())); fut.markInitialized(); @@ -682,22 +674,42 @@ public IgniteInternalFuture rebuildAllIndexes() { /** * Rebuilds indexes for provided caches from corresponding hash indexes. * - * @param cacheIds Cache IDs. + * @param cacheName Cache name. * @return Future that will be completed when rebuilding is finished. */ - public IgniteInternalFuture rebuildIndexesFromHash(Collection cacheIds) { + public IgniteInternalFuture rebuildIndexesFromHash(final String cacheName) { if (!busyLock.enterBusy()) throw new IllegalStateException("Failed to get space size (grid is stopping)."); try { - GridCompoundFuture fut = new GridCompoundFuture(); + final GridWorkerFuture fut = new GridWorkerFuture(); - for (Map.Entry e : types.entrySet()) { - if (cacheIds.contains(CU.cacheId(e.getKey().space))) - fut.add((IgniteInternalFuture)rebuildIndexes(e.getKey().space, e.getValue(), true)); - } + idx.markForRebuildFromHash(cacheName); - fut.markInitialized(); + GridWorker w = new GridWorker(ctx.gridName(), "index-rebuild-worker", log) { + @Override protected void body() { + try { + idx.rebuildIndexesFromHash(cacheName); + + fut.onDone(); + } + catch (Exception e) { + fut.onDone(e); + } + catch (Throwable e) { + U.error(log, "Failed to rebuild indexes for type [cache=" + cacheName + ']'); + + fut.onDone(e); + + if (e instanceof Error) + throw e; + } + } + }; + + fut.setWorker(w); + + execSvc.execute(w); return fut; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index b077666d722ac..a586ade5dc840 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -1109,7 +1109,7 @@ public static void dumpStack() { */ @Deprecated public static void dumpStack(String msg) { - new Exception(debugPrefix() + msg).printStackTrace(System.out); + new Exception(debugPrefix() + msg).printStackTrace(System.err); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java new file mode 100644 index 0000000000000..57ab38431e008 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) GridGain Systems. All Rights Reserved. + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.internal.util.future; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.util.future.GridFutureAdapter; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class CountDownFuture extends GridFutureAdapter { + /** */ + private AtomicInteger remaining; + + /** */ + private AtomicReference errCollector; + + /** + * @param cnt Number of completing parties. + */ + public CountDownFuture(int cnt) { + remaining = new AtomicInteger(cnt); + errCollector = new AtomicReference<>(); + } + + /** {@inheritDoc} */ + @Override public boolean onDone(@Nullable Void res, @Nullable Throwable err) { + if (err != null) + addError(err); + + int left = remaining.decrementAndGet(); + + boolean done = left == 0 && super.onDone(res, errCollector.get()); + + if (done) + afterDone(); + + return done; + } + + /** + * + */ + protected void afterDone() { + // No-op, to be overridden in subclasses. + } + + /** + * @param err Error. + */ + private void addError(Throwable err) { + Exception ex = errCollector.get(); + + if (ex == null) { + Exception compound = new IgniteCheckedException("Compound exception for CountDownFuture."); + + ex = errCollector.compareAndSet(null, compound) ? compound : errCollector.get(); + } + + assert ex != null; + + ex.addSuppressed(err); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java index be3933f52306e..b232617208eb0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java @@ -818,6 +818,11 @@ GridCacheMvccCandidate anyOwner() { throw new UnsupportedOperationException(); } + /** {@inheritDoc} */ + @Override public void ensureIndexed() throws GridCacheEntryRemovedException, IgniteCheckedException { + // No-op. + } + /** {@inheritDoc} */ @Override public CacheObject unswap() throws IgniteCheckedException { return null; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index a2160ffcce70e..e1aef1a48b1f3 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -78,15 +78,16 @@ import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.QueryCursorImpl; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable; import org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery; import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode; -import org.apache.ignite.internal.processors.query.GridQueryCancel; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.processors.query.GridQueryCancel; import org.apache.ignite.internal.processors.query.GridQueryFieldMetadata; import org.apache.ignite.internal.processors.query.GridQueryFieldsResult; import org.apache.ignite.internal.processors.query.GridQueryFieldsResultAdapter; @@ -96,11 +97,11 @@ import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor; import org.apache.ignite.internal.processors.query.IgniteSQLException; import org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex; -import org.apache.ignite.internal.processors.query.h2.opt.GridH2DefaultTableEngine; import org.apache.ignite.internal.processors.query.h2.database.H2RowFactory; import org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex; import org.apache.ignite.internal.processors.query.h2.database.io.H2InnerIO; import org.apache.ignite.internal.processors.query.h2.database.io.H2LeafIO; +import org.apache.ignite.internal.processors.query.h2.opt.GridH2DefaultTableEngine; import org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOffheap; import org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap; import org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryContext; @@ -146,7 +147,6 @@ import org.h2.command.Prepared; import org.h2.engine.Session; import org.h2.engine.SysProperties; -import org.h2.index.Cursor; import org.h2.index.Index; import org.h2.index.SpatialIndex; import org.h2.jdbc.JdbcConnection; @@ -1667,77 +1667,51 @@ public String space(String schemaName) { * Rebuild indexes from hash index. * * @param spaceName Space name. - * @param type Type descriptor. * @throws IgniteCheckedException If failed. */ - @Override public void rebuildIndexesFromHash(@Nullable String spaceName, - GridQueryTypeDescriptor type) throws IgniteCheckedException { - TableDescriptor tbl = tableDescriptor(spaceName, type); - - if (tbl == null) - return; - - assert tbl.tbl != null; - - assert tbl.tbl.rebuildFromHashInProgress(); - - H2PkHashIndex hashIdx = tbl.pkHashIdx; - - Cursor cursor = hashIdx.find((Session)null, null, null); - - int cacheId = CU.cacheId(tbl.schema.ccfg.getName()); + @Override public void rebuildIndexesFromHash(@Nullable String spaceName) throws IgniteCheckedException { + int cacheId = CU.cacheId(spaceName); GridCacheContext cctx = ctx.cache().context().cacheContext(cacheId); - while (cursor.next()) { - CacheDataRow dataRow = (CacheDataRow)cursor.get(); - - boolean done = false; + IgniteCacheOffheapManager offheapMgr = cctx.isNear() ? cctx.near().dht().context().offheap() : cctx.offheap(); - while (!done) { - GridCacheEntryEx entry = cctx.cache().entryEx(dataRow.key()); + for (int p = 0; p < cctx.affinity().partitions(); p++) { + try (GridCloseableIterator keyIter = offheapMgr.keysIterator(p)) { + while (keyIter.hasNext()) { + KeyCacheObject key = keyIter.next(); - try { - synchronized (entry) { - // TODO : How to correctly get current value and link here? - - GridH2Row row = tbl.tbl.rowDescriptor().createRow(entry.key(), entry.partition(), - dataRow.value(), entry.version(), entry.expireTime()); - - row.link(dataRow.link()); - - List indexes = tbl.tbl.getAllIndexes(); + while (true) { + try { + GridCacheEntryEx entry = cctx.isNear() ? + cctx.near().dht().entryEx(key) : cctx.cache().entryEx(key); - for (int i = 2; i < indexes.size(); i++) { - Index idx = indexes.get(i); + entry.ensureIndexed(); - if (idx instanceof H2TreeIndex) - ((H2TreeIndex)idx).put(row); + break; + } + catch (GridCacheEntryRemovedException ignore) { + // Retry. + } + catch (GridDhtInvalidPartitionException ignore) { + break; } - - done = true; } } - catch (GridCacheEntryRemovedException e) { - // No-op - } } - } - tbl.tbl.markRebuildFromHashInProgress(false); + for (TableDescriptor tblDesc : tables(spaceName)) + tblDesc.tbl.markRebuildFromHashInProgress(false); } /** {@inheritDoc} */ - @Override public void markForRebuildFromHash(@Nullable String spaceName, GridQueryTypeDescriptor type) { - TableDescriptor tbl = tableDescriptor(spaceName, type); + @Override public void markForRebuildFromHash(@Nullable String spaceName) { + for (TableDescriptor tblDesc : tables(spaceName)) { + assert tblDesc.tbl != null; - if (tbl == null) - return; - - assert tbl.tbl != null; - - tbl.tbl.markRebuildFromHashInProgress(true); + tblDesc.tbl.markRebuildFromHashInProgress(true); + } } /** diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java index 19cbbf92cbb1b..64d649016c6a8 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java @@ -199,7 +199,7 @@ public H2Tree tree() { /** {@inheritDoc} */ @Override public void destroy() { try { - if (!cctx.kernalContext().clientNode()) { + if (!cctx.kernalContext().clientNode() && cctx.affinityNode()) { tree.destroy(); cctx.offheap().dropRootPageForIndex(tree.getName()); From 66557c8b6d6dbfa09bb559b6ab281ce84ee78d3c Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 3 Feb 2017 12:22:24 +0300 Subject: [PATCH 040/311] GG-11940 - Do not evict non-user cache entries --- .../internal/processors/cache/CacheOffheapEvictionManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOffheapEvictionManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOffheapEvictionManager.java index 12c1e800f328f..a03bc5dfb7db0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOffheapEvictionManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOffheapEvictionManager.java @@ -50,7 +50,7 @@ public class CacheOffheapEvictionManager extends GridCacheManagerAdapter impleme return; } - boolean evicted = e.evictInternal(cctx.versions().next(), null); + boolean evicted = cctx.userCache() && e.evictInternal(cctx.versions().next(), null); if (evicted) cctx.cache().removeEntry(e); From 5c33c292f1ed4c9c8298512a0f3e26daf2308d2e Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 3 Feb 2017 14:03:57 +0300 Subject: [PATCH 041/311] Fixing compilation after merge. --- .../internal/processors/cache/IgniteCacheOffheapManager.java | 3 +-- .../processors/cache/IgniteCacheOffheapManagerImpl.java | 4 ++-- .../internal/processors/cache/database/tree/BPlusTree.java | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java index baf8eedcae055..4b85abee1dab4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java @@ -131,8 +131,7 @@ public void update( */ public void updateIndexes( KeyCacheObject key, - GridDhtLocalPartition part, - @Nullable CacheDataRow oldRow + GridDhtLocalPartition part ) throws IgniteCheckedException; /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index c9b1cf0b3b055..a34d35f60cf49 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -928,7 +928,7 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) throw new NodeStoppingException("Operation has been cancelled (node is stopping)."); try { - DataRow dataRow = new DataRow(key, val, ver, p, expireTime); + DataRow dataRow = new DataRow(key, val, ver, partId, expireTime); CacheObjectContext coCtx = cctx.cacheObjectContext(); @@ -998,7 +998,7 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) /** {@inheritDoc} */ @Override public void updateIndexes(KeyCacheObject key) throws IgniteCheckedException { if (indexingEnabled) { - DataRow row = dataTree.findOne(new KeySearchRow(key.hashCode(), key, 0)); + CacheDataRow row = dataTree.findOne(new SearchRow(key)); GridCacheQueryManager qryMgr = cctx.queries(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java index c74715a26f645..0f0a2459e4811 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java @@ -1690,7 +1690,7 @@ public final long destroy() throws IgniteCheckedException { try (Page meta = page(metaPageId)) { long metaPageAddr = writeLock(meta); // No checks, we must be out of use. - assert metaBuf != null; + assert metaPageAddr != 0L; try { for (long pageId : getFirstPageIds(metaPageAddr)) { From 5967c6d08b4dc978c543df3295b08790440542a6 Mon Sep 17 00:00:00 2001 From: Aleksei Scherbakov Date: Mon, 6 Feb 2017 18:00:47 +0300 Subject: [PATCH 042/311] GG-11946 Fixed. --- .../dht/preloader/GridDhtPartitionsExchangeFuture.java | 1 + 1 file changed, 1 insertion(+) 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 75fd3e261904e..2ccb29bc0d000 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 @@ -1319,6 +1319,7 @@ public void cleanUp() { topSnapshot.set(null); singleMsgs.clear(); fullMsgs.clear(); + msgs.clear(); changeGlobalStateExceptions.clear(); crd = null; partReleaseFut = null; From b1fb8ff108c49ef5f809bad8dc7cd54c7e088be1 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Mon, 6 Feb 2017 20:25:47 +0300 Subject: [PATCH 043/311] GG-11575 'bin' folder contains a service folders from 'database' system --- .../ignite/internal/processors/cache/GridCacheProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5b37ed4c41b20..5f799854f7e96 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 @@ -1142,7 +1142,7 @@ private void startCache(GridCacheAdapter cache) throws IgniteCheckedExcept ctx.continuous().onCacheStart(cacheCtx); - if (sharedCtx.pageStore() != null) + if (sharedCtx.pageStore() != null && !ctx.clientNode()) sharedCtx.pageStore().initializeForCache(cacheCtx.config()); CacheConfiguration cfg = cacheCtx.config(); From 993f1f62695822bb4b71c5f86f42c5de866b21ce Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Mon, 6 Feb 2017 20:39:28 +0300 Subject: [PATCH 044/311] GG-11947 Incorrect checkpoint lock usage --- .../GridDistributedTxRemoteAdapter.java | 5 +- .../dht/GridDhtPartitionTopologyImpl.java | 110 +++++++++--------- 2 files changed, 55 insertions(+), 60 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java index 35477282cb372..78df48ee47079 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java @@ -753,11 +753,10 @@ else if (op == READ) { throw new IgniteCheckedException("Failed to log transaction record " + "(transaction will be rolled back): " + this, e); } - finally { - cctx.database().checkpointReadUnlock(); - } } finally { + cctx.database().checkpointReadUnlock(); + if (wrapper != null) wrapper.initialize(ret); } 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 4c8b8148a2ea7..6c5739e8d248b 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 @@ -505,85 +505,81 @@ else if (localNode(p, aff)) cctx.shared().database().checkpointReadLock(); - synchronized (cctx.shared().exchange().interruptLock()) { - if (Thread.currentThread().isInterrupted()) - throw new IgniteInterruptedCheckedException("Thread is interrupted: " + Thread.currentThread()); + try { + synchronized (cctx.shared().exchange().interruptLock()) { + if (Thread.currentThread().isInterrupted()) + throw new IgniteInterruptedCheckedException("Thread is interrupted: " + Thread.currentThread()); - try { U.writeLock(lock); - } - catch (IgniteInterruptedCheckedException e) { - cctx.shared().database().checkpointReadUnlock(); - throw e; - } + try { + GridDhtPartitionExchangeId exchId = exchFut.exchangeId(); - try { - GridDhtPartitionExchangeId exchId = exchFut.exchangeId(); + if (stopping) + return; - if (stopping) - return; + assert topVer.equals(exchId.topologyVersion()) : "Invalid topology version [topVer=" + + topVer + ", exchId=" + exchId + ']'; - assert topVer.equals(exchId.topologyVersion()) : "Invalid topology version [topVer=" + - topVer + ", exchId=" + exchId + ']'; + if (exchId.isLeft()) + removeNode(exchId.nodeId()); - if (exchId.isLeft()) - removeNode(exchId.nodeId()); + ClusterNode oldest = currentCoordinator(); - ClusterNode oldest = currentCoordinator(); + if (log.isDebugEnabled()) + log.debug("Partition map beforeExchange [exchId=" + exchId + ", fullMap=" + fullMapString() + ']'); - if (log.isDebugEnabled()) - log.debug("Partition map beforeExchange [exchId=" + exchId + ", fullMap=" + fullMapString() + ']'); + long updateSeq = this.updateSeq.incrementAndGet(); - long updateSeq = this.updateSeq.incrementAndGet(); + cntrMap.clear(); - cntrMap.clear(); + // If this is the oldest node. + if (oldest != null && (loc.equals(oldest) || exchFut.isCacheAdded(cctx.cacheId(), exchId.topologyVersion()))) { + if (node2part == null) { + node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq); - // If this is the oldest node. - if (oldest != null && (loc.equals(oldest) || exchFut.isCacheAdded(cctx.cacheId(), exchId.topologyVersion()))) { - if (node2part == null) { - node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq); + if (log.isDebugEnabled()) + log.debug("Created brand new full topology map on oldest node [exchId=" + + exchId + ", fullMap=" + fullMapString() + ']'); + } + else if (!node2part.valid()) { + node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq, node2part, false); - if (log.isDebugEnabled()) - log.debug("Created brand new full topology map on oldest node [exchId=" + - exchId + ", fullMap=" + fullMapString() + ']'); - } - else if (!node2part.valid()) { - node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq, node2part, false); + if (log.isDebugEnabled()) + log.debug("Created new full topology map on oldest node [exchId=" + exchId + ", fullMap=" + + node2part + ']'); + } + else if (!node2part.nodeId().equals(loc.id())) { + node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq, node2part, false); - if (log.isDebugEnabled()) - log.debug("Created new full topology map on oldest node [exchId=" + exchId + ", fullMap=" + - node2part + ']'); + if (log.isDebugEnabled()) + log.debug("Copied old map into new map on oldest node (previous oldest node left) [exchId=" + + exchId + ", fullMap=" + fullMapString() + ']'); + } } - else if (!node2part.nodeId().equals(loc.id())) { - node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq, node2part, false); - if (log.isDebugEnabled()) - log.debug("Copied old map into new map on oldest node (previous oldest node left) [exchId=" + - exchId + ", fullMap=" + fullMapString() + ']'); + if (affReady) + initPartitions0(exchFut, updateSeq); + else { + List> aff = cctx.affinity().idealAssignment(); + + createPartitions(aff, updateSeq); } - } - if (affReady) - initPartitions0(exchFut, updateSeq); - else { - List> aff = cctx.affinity().idealAssignment(); + consistencyCheck(); - createPartitions(aff, updateSeq); + if (log.isDebugEnabled()) + log.debug("Partition map after beforeExchange [exchId=" + exchId + ", fullMap=" + + fullMapString() + ']'); + } + finally { + lock.writeLock().unlock(); } - - consistencyCheck(); - - if (log.isDebugEnabled()) - log.debug("Partition map after beforeExchange [exchId=" + exchId + ", fullMap=" + - fullMapString() + ']'); - } - finally { - lock.writeLock().unlock(); - - cctx.shared().database().checkpointReadUnlock(); } } + finally { + cctx.shared().database().checkpointReadUnlock(); + } // Wait for evictions. waitForRent(); From 159d5f4683a3e131f6d3599b4ecc3bba5639213d Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Mon, 6 Feb 2017 21:07:21 +0300 Subject: [PATCH 045/311] GG-11948 All page updates should be done under checkpoint lock --- .../processors/cache/GridCacheProcessor.java | 9 ++- .../cache/IgniteCacheOffheapManagerImpl.java | 64 +++++++++++-------- .../database/CheckpointLockStateChecker.java | 28 ++++++++ .../IgniteCacheDatabaseSharedManager.java | 8 ++- 4 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CheckpointLockStateChecker.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 5f799854f7e96..e4d979e3c3841 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 @@ -1947,7 +1947,14 @@ public void onExchangeDone( if (req.stop()) { stopGateway(req); - prepareCacheStop(req); + sharedCtx.database().checkpointReadLock(); + + try { + prepareCacheStop(req); + } + finally { + sharedCtx.database().checkpointReadUnlock(); + } } else if (req.close() && req.initiatingNodeId().equals(ctx.localNodeId())) { IgniteCacheProxy proxy = jCacheProxies.remove(masked); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index 06986316883a3..e2a49684d3ecc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -387,21 +387,28 @@ private Iterator cacheData(boolean primary, boolean backup, Affi GridIterator it = rowsIterator(true, true, null); while (it.hasNext()) { - KeyCacheObject key = it.next().key(); + cctx.shared().database().checkpointReadLock(); try { - if (obsoleteVer == null) - obsoleteVer = cctx.versions().next(); + KeyCacheObject key = it.next().key(); + + try { + if (obsoleteVer == null) + obsoleteVer = cctx.versions().next(); - GridCacheEntryEx entry = cctx.cache().entryEx(key); + GridCacheEntryEx entry = cctx.cache().entryEx(key); - entry.clear(obsoleteVer, readers); - } - catch (GridDhtInvalidPartitionException ignore) { - // Ignore. + entry.clear(obsoleteVer, readers); + } + catch (GridDhtInvalidPartitionException ignore) { + // Ignore. + } + catch (IgniteCheckedException e) { + U.error(log, "Failed to clear cache entry: " + key, e); + } } - catch (IgniteCheckedException e) { - U.error(log, "Failed to clear cache entry: " + key, e); + finally { + cctx.shared().database().checkpointReadUnlock(); } } } @@ -762,30 +769,37 @@ protected final String treeName(int p) { int amount ) throws IgniteCheckedException { if (pendingEntries != null) { - GridCacheVersion obsoleteVer = null; + cctx.shared().database().checkpointReadLock(); - long now = U.currentTimeMillis(); + try { + GridCacheVersion obsoleteVer = null; - GridCursor cur = pendingEntries.find(START_PENDING_ROW, new PendingRow(now, 0)); + long now = U.currentTimeMillis(); - int cleared = 0; + GridCursor cur = pendingEntries.find(START_PENDING_ROW, new PendingRow(now, 0)); - while (cur.next()) { - PendingRow row = cur.get(); + int cleared = 0; - if (amount != -1 && cleared > amount) - return true; + while (cur.next()) { + PendingRow row = cur.get(); - assert row.key != null && row.link != 0 && row.expireTime != 0 : row; + if (amount != -1 && cleared > amount) + return true; - if (pendingEntries.remove(row) != null) { - if (obsoleteVer == null) - obsoleteVer = cctx.versions().next(); + assert row.key != null && row.link != 0 && row.expireTime != 0 : row; - c.apply(cctx.cache().entryEx(row.key), obsoleteVer); - } + if (pendingEntries.remove(row) != null) { + if (obsoleteVer == null) + obsoleteVer = cctx.versions().next(); - cleared++; + c.apply(cctx.cache().entryEx(row.key), obsoleteVer); + } + + cleared++; + } + } + finally { + cctx.shared().database().checkpointReadUnlock(); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CheckpointLockStateChecker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CheckpointLockStateChecker.java new file mode 100644 index 0000000000000..df90f332c7060 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CheckpointLockStateChecker.java @@ -0,0 +1,28 @@ +/* + * 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.database; + +/** + * Interface for perform checking that checkpoint lock is held by current track + */ +public interface CheckpointLockStateChecker { + /** + * @return true if checkpoint lock is held by current thread + */ + public boolean checkpointLockIsHeldByThread(); +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 18b3a1f0ed3a9..77631c9efdd58 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -44,7 +44,8 @@ /** * */ -public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdapter implements IgniteChangeGlobalStateSupport { +public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdapter + implements IgniteChangeGlobalStateSupport, CheckpointLockStateChecker { /** */ protected PageMemory pageMem; @@ -120,6 +121,11 @@ public boolean persistenceEnabled() { return false; } + /** {@inheritDoc} */ + @Override public boolean checkpointLockIsHeldByThread() { + return false; + } + /** * @return Page memory instance. */ From 5544978df00a131bae5f52d6c5e335c43a9ffb74 Mon Sep 17 00:00:00 2001 From: sboikov Date: Tue, 7 Feb 2017 14:19:16 +0300 Subject: [PATCH 046/311] ignite-4552 Use for rmvQueue ConcurrentLinkedDeque instead of GridCircularBuffer to reduce memory usage. This closes #1465. (cherry picked from commit e6ea938) --- .../apache/ignite/IgniteSystemProperties.java | 3 + .../processors/cache/GridCacheProcessor.java | 85 +++++++++++ .../distributed/dht/GridDhtCacheAdapter.java | 10 +- .../dht/GridDhtLocalPartition.java | 120 ++++++++++++---- .../cache/CacheDeferredDeleteQueueTest.java | 134 ++++++++++++++++++ .../testsuites/IgniteCacheTestSuite.java | 2 + 6 files changed, 322 insertions(+), 32 deletions(-) create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDeferredDeleteQueueTest.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 1e8adb2fb69b7..1f003a9d7b6be 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -277,6 +277,9 @@ public final class IgniteSystemProperties { /** Maximum size for atomic cache queue delete history (default is 200 000 entries per partition). */ public static final String IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE = "IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE"; + /** Ttl of removed cache entries (ms). */ + public static final String IGNITE_CACHE_REMOVED_ENTRIES_TTL = "IGNITE_CACHE_REMOVED_ENTRIES_TTL"; + /** Maximum amount of concurrent updates per system thread in atomic caches in case of PRIMARY_SYNC or FULL_ASYNC * write synchronization mode. If this limit is exceeded then update will be performed with FULL_SYNC * synchronization mode. If value is {@code 0} then limit is unbounded. 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 e4d979e3c3841..80ca9291e2f4e 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 @@ -83,6 +83,8 @@ import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCache; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache; import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache; @@ -102,6 +104,7 @@ import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor; import org.apache.ignite.internal.processors.plugin.CachePluginManager; import org.apache.ignite.internal.processors.query.GridQueryProcessor; +import org.apache.ignite.internal.processors.timeout.GridTimeoutObject; import org.apache.ignite.internal.util.F0; import org.apache.ignite.internal.util.future.GridCompoundFuture; import org.apache.ignite.internal.util.future.GridFinishedFuture; @@ -123,6 +126,7 @@ import org.apache.ignite.spi.IgniteNodeValidationResult; import org.jetbrains.annotations.Nullable; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_REMOVED_ENTRIES_TTL; import static org.apache.ignite.IgniteSystemProperties.IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK; import static org.apache.ignite.IgniteSystemProperties.getBoolean; import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; @@ -881,6 +885,17 @@ private void initializeInternalCacheNames() { assert caches.containsKey(CU.MARSH_CACHE_NAME) : "Marshaller cache should be started"; assert ctx.config().isDaemon() || caches.containsKey(CU.UTILITY_CACHE_NAME) : "Utility cache should be started"; + + if (!ctx.clientNode() && !ctx.isDaemon()) + addRemovedItemsCleanupTask(Long.getLong(IGNITE_CACHE_REMOVED_ENTRIES_TTL, 10_000)); + + } + + /** + * @param timeout Cleanup timeout. + */ + private void addRemovedItemsCleanupTask(long timeout) { + ctx.timeout().addTimeoutObject(new RemovedItemsCleanupTask(timeout)); } /** @@ -4149,4 +4164,74 @@ private static class LocalAffinityFunction implements AffinityFunction { // No-op. } } + + /** + * + */ + private class RemovedItemsCleanupTask implements GridTimeoutObject { + /** */ + private final IgniteUuid id = IgniteUuid.randomUuid(); + + /** */ + private final long endTime; + + /** */ + private final long timeout; + + /** + * @param timeout Timeout. + */ + RemovedItemsCleanupTask(long timeout) { + this.timeout = timeout; + this.endTime = U.currentTimeMillis() + timeout; + } + + /** {@inheritDoc} */ + @Override public IgniteUuid timeoutId() { + return id; + } + + /** {@inheritDoc} */ + @Override public long endTime() { + return endTime; + } + + /** {@inheritDoc} */ + @Override public void onTimeout() { + ctx.closure().runLocalSafe(new Runnable() { + @Override public void run() { + try { + for (GridCacheContext cacheCtx : sharedCtx.cacheContexts()) { + if (!cacheCtx.isLocal() && cacheCtx.affinityNode()) { + GridDhtPartitionTopology top = null; + + try { + top = cacheCtx.topology(); + } + catch (IllegalStateException ignore) { + // Cache stopped. + } + + if (top != null) { + for (GridDhtLocalPartition part : top.currentLocalPartitions()) + part.cleanupRemoveQueue(); + } + + if (ctx.isStopping()) + return; + } + } + } + catch (Exception e) { + U.error(log, "Failed to cleanup removed cache items: " + e, e); + } + + if (ctx.isStopping()) + return; + + addRemovedItemsCleanupTask(timeout); + } + }, true); + } + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java index 13524396b679d..566882173dfbc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java @@ -1182,14 +1182,8 @@ private PartitionEntrySet(int partId) { GridDhtLocalPartition part = topology().localPartition(entry.partition(), AffinityTopologyVersion.NONE, false); - if (part != null) { - try { - part.onDeferredDelete(entry.key(), ver); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to enqueue deleted entry [key=" + entry.key() + ", ver=" + ver + ']', e); - } - } + if (part != null) + part.onDeferredDelete(entry.key(), ver); } /** 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 4a4f834b7dbd8..40d7d3bf160e5 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 @@ -32,7 +32,6 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.NodeStoppingException; import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; @@ -49,20 +48,19 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader; import org.apache.ignite.internal.processors.cache.extras.GridCacheObsoleteEntryExtras; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; -import org.apache.ignite.internal.util.GridCircularBuffer; import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.lang.GridIterator; import org.apache.ignite.internal.util.tostring.GridToStringExclude; -import org.apache.ignite.internal.util.typedef.CI1; -import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jsr166.ConcurrentLinkedDeque8; import static org.apache.ignite.IgniteSystemProperties.IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_REMOVED_ENTRIES_TTL; import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_OBJECT_UNLOADED; import static org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager.CacheDataStore; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; @@ -76,8 +74,13 @@ */ public class GridDhtLocalPartition implements Comparable, GridReservable, GridCacheConcurrentMap { /** Maximum size for delete queue. */ - public static final int MAX_DELETE_QUEUE_SIZE = Integer.getInteger(IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE, - 200_000); + public static final int MAX_DELETE_QUEUE_SIZE = Integer.getInteger(IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE, 200_000); + + /** Maximum size for {@link #rmvQueue}. */ + private final int rmvQueueMaxSize; + + /** Removed items TTL. */ + private final long rmvdEntryTtl; /** Static logger to avoid re-creation. */ private static final AtomicReference logRef = new AtomicReference<>(); @@ -117,7 +120,7 @@ public class GridDhtLocalPartition implements Comparable, private final ReentrantLock lock = new ReentrantLock(); /** Remove queue. */ - private final GridCircularBuffer> rmvQueue; + private final ConcurrentLinkedDeque8 rmvQueue = new ConcurrentLinkedDeque8<>(); /** Group reservations. */ private final CopyOnWriteArrayList reservations = new CopyOnWriteArrayList<>(); @@ -160,7 +163,9 @@ public class GridDhtLocalPartition implements Comparable, int delQueueSize = CU.isSystemCache(cctx.name()) ? 100 : Math.max(MAX_DELETE_QUEUE_SIZE / cctx.affinity().partitions(), 20); - rmvQueue = new GridCircularBuffer<>(U.ceilPow2(delQueueSize)); + rmvQueueMaxSize = U.ceilPow2(delQueueSize); + + rmvdEntryTtl = Long.getLong(IGNITE_CACHE_REMOVED_ENTRIES_TTL, 10_000); try { store = cctx.offheap().createCacheDataStore(id); @@ -387,24 +392,42 @@ void onRemoved(GridDhtCacheEntry entry) { } /** - * @param key Removed key. - * @param ver Removed version. - * @throws IgniteCheckedException If failed. + * */ - public void onDeferredDelete(KeyCacheObject key, GridCacheVersion ver) throws IgniteCheckedException { - try { - T2 evicted = rmvQueue.add(new T2<>(key, ver)); + public void cleanupRemoveQueue() { + while (rmvQueue.sizex() >= rmvQueueMaxSize) { + RemovedEntryHolder item = rmvQueue.pollFirst(); - if (evicted != null) - cctx.dht().removeVersionedEntry(evicted.get1(), evicted.get2()); + if (item != null) + cctx.dht().removeVersionedEntry(item.key(), item.version()); } - catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new IgniteInterruptedCheckedException(e); + if (!cctx.isDrEnabled()) { + RemovedEntryHolder item = rmvQueue.peekFirst(); + + while (item != null && item.expireTime() < U.currentTimeMillis()) { + item = rmvQueue.pollFirst(); + + if (item == null) + break; + + cctx.dht().removeVersionedEntry(item.key(), item.version()); + + item = rmvQueue.peekFirst(); + } } } + /** + * @param key Removed key. + * @param ver Removed version. + */ + public void onDeferredDelete(KeyCacheObject key, GridCacheVersion ver) { + cleanupRemoveQueue(); + + rmvQueue.add(new RemovedEntryHolder(key, ver, rmvdEntryTtl)); + } + /** * Locks partition. */ @@ -985,11 +1008,8 @@ public void clearAll() throws NodeStoppingException { * */ private void clearDeferredDeletes() { - rmvQueue.forEach(new CI1>() { - @Override public void apply(T2 t) { - cctx.dht().removeVersionedEntry(t.get1(), t.get2()); - } - }); + for (RemovedEntryHolder e : rmvQueue) + cctx.dht().removeVersionedEntry(e.key(), e.version()); } /** {@inheritDoc} */ @@ -1019,4 +1039,56 @@ private void clearDeferredDeletes() { "empty", isEmpty(), "createTime", U.format(createTime)); } + + /** + * Removed entry holder. + */ + private static class RemovedEntryHolder { + /** Cache key */ + private final KeyCacheObject key; + + /** Entry version */ + private final GridCacheVersion ver; + + /** Entry expire time. */ + private final long expireTime; + + /** + * @param key Key. + * @param ver Entry version. + * @param ttl TTL. + */ + private RemovedEntryHolder(KeyCacheObject key, GridCacheVersion ver, long ttl) { + this.key = key; + this.ver = ver; + + expireTime = U.currentTimeMillis() + ttl; + } + + /** + * @return Key. + */ + KeyCacheObject key() { + return key; + } + + /** + * @return Version. + */ + GridCacheVersion version() { + return ver; + } + + /** + * @return item expired time + */ + long expireTime() { + return expireTime; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(RemovedEntryHolder.class, this); + } + } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDeferredDeleteQueueTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDeferredDeleteQueueTest.java new file mode 100644 index 0000000000000..b764d5b3d7852 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDeferredDeleteQueueTest.java @@ -0,0 +1,134 @@ +/* + * 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 java.util.Collection; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.NearCacheConfiguration; +import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; +import org.apache.ignite.internal.util.lang.GridAbsPredicate; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +import static org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_REMOVED_ENTRIES_TTL; +import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheMode.PARTITIONED; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; + +/** + * + */ +public class CacheDeferredDeleteQueueTest extends GridCommonAbstractTest { + /** */ + private static String ttlProp; + + /** */ + private static int NODES = 2; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + ttlProp = System.getProperty(IGNITE_CACHE_REMOVED_ENTRIES_TTL); + + System.setProperty(IGNITE_CACHE_REMOVED_ENTRIES_TTL, "1000"); + + startGridsMultiThreaded(NODES); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + if (ttlProp != null) + System.setProperty(IGNITE_CACHE_REMOVED_ENTRIES_TTL, ttlProp); + else + System.clearProperty(IGNITE_CACHE_REMOVED_ENTRIES_TTL); + + stopAllGrids(); + + super.afterTestsStopped(); + } + + /** + * @throws Exception If failed. + */ + public void testDeferredDeleteQueue() throws Exception { + testQueue(ATOMIC, false); + + testQueue(TRANSACTIONAL, false); + + testQueue(ATOMIC, true); + + testQueue(TRANSACTIONAL, true); + } + + /** + * @param atomicityMode Cache atomicity mode. + * @param nearCache {@code True} if need create near cache. + * + * @throws Exception If failed. + */ + private void testQueue(CacheAtomicityMode atomicityMode, boolean nearCache) throws Exception { + CacheConfiguration ccfg = new CacheConfiguration<>(); + + ccfg.setCacheMode(PARTITIONED); + ccfg.setAtomicityMode(atomicityMode); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setBackups(1); + + if (nearCache) + ccfg.setNearConfiguration(new NearCacheConfiguration()); + + IgniteCache cache = ignite(0).createCache(ccfg); + + try { + final int KEYS = cache.getConfiguration(CacheConfiguration.class).getAffinity().partitions() * 3; + + for (int i = 0; i < KEYS; i++) + cache.put(i, i); + + for (int i = 0; i < KEYS; i++) + cache.remove(i); + + boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + for (int i = 0; i < NODES; i++) { + final GridDhtPartitionTopology top = + ((IgniteKernal)ignite(i)).context().cache().cache(null).context().topology(); + + for (GridDhtLocalPartition p : top.currentLocalPartitions()) { + Collection rmvQueue = GridTestUtils.getFieldValue(p, "rmvQueue"); + + if (!rmvQueue.isEmpty() || p.size() != 0) + return false; + } + } + + return true; + } + }, 5000); + + assertTrue("Failed to wait for rmvQueue cleanup.", wait); + } + finally { + ignite(0).destroyCache(ccfg.getName()); + } + } +} 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 6ec04f0f7683b..49aa533b3342e 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 @@ -45,6 +45,7 @@ import org.apache.ignite.internal.managers.communication.IgniteVariousConnectionNumberTest; import org.apache.ignite.cache.store.jdbc.JdbcTypesDefaultTransformerTest; import org.apache.ignite.internal.processors.cache.CacheAffinityCallSelfTest; +import org.apache.ignite.internal.processors.cache.CacheDeferredDeleteQueueTest; import org.apache.ignite.internal.processors.cache.CacheDeferredDeleteSanitySelfTest; import org.apache.ignite.internal.processors.cache.CacheEntryProcessorCopySelfTest; import org.apache.ignite.internal.processors.cache.CacheFutureExceptionSelfTest; @@ -320,6 +321,7 @@ public static TestSuite suite(Set ignoredTests) throws Exception { suite.addTestSuite(GridCacheTxPartitionedLocalStoreSelfTest.class); suite.addTestSuite(IgniteCacheSystemTransactionsSelfTest.class); suite.addTestSuite(CacheDeferredDeleteSanitySelfTest.class); + suite.addTestSuite(CacheDeferredDeleteQueueTest.class); suite.addTest(IgniteCacheTcpClientDiscoveryTestSuite.suite()); From 754bd7b8a37f7afd3312fc9e9d4d4c7d726387c0 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Tue, 7 Feb 2017 19:19:10 +0300 Subject: [PATCH 047/311] GG-11937 - Fixed checkpoint read lock release on exception --- .../processors/cache/GridCacheProcessor.java | 41 ++++++++++++------- .../IgniteCacheDatabaseSharedManager.java | 5 ++- .../dht/atomic/GridDhtAtomicCache.java | 11 ++--- .../GridDhtPartitionsExchangeFuture.java | 15 ------- .../service/GridServiceProcessor.java | 3 +- 5 files changed, 38 insertions(+), 37 deletions(-) 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 ab306240b1c82..a26e09ab246da 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 @@ -112,6 +112,7 @@ import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiTuple; import org.apache.ignite.lang.IgniteClosure; import org.apache.ignite.lang.IgniteFuture; import org.apache.ignite.lang.IgnitePredicate; @@ -888,7 +889,7 @@ private void initializeInternalCacheNames() { private void checkConsistency() throws IgniteCheckedException { if (!ctx.config().isDaemon() && !getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) { for (ClusterNode n : ctx.discovery().remoteNodes()) { - if (n.attribute(ATTR_CONSISTENCY_CHECK_SKIPPED)) + if (Boolean.TRUE.equals(n.attribute(ATTR_CONSISTENCY_CHECK_SKIPPED))) continue; checkTransactionConfiguration(n); @@ -1248,16 +1249,6 @@ private void stopCache(GridCacheAdapter cache, boolean cancel, boolean des if (log.isInfoEnabled()) log.info("Stopped cache: " + cache.name()); - if (sharedCtx.pageStore() != null) { - try { - sharedCtx.pageStore().shutdownForCache(ctx, destroy); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to gracefully clean page store resources for destroyed cache " + - "[cache=" + ctx.name() + "]", e); - } - } - cleanup(ctx); } @@ -1893,8 +1884,9 @@ private void stopGateway(DynamicCacheChangeRequest req) { /** * @param req Stop request. + * @return Stopped cache context. */ - private void prepareCacheStop(DynamicCacheChangeRequest req) { + private GridCacheContext prepareCacheStop(DynamicCacheChangeRequest req) { assert req.stop() || req.close() : req; GridCacheAdapter cache = caches.remove(maskNull(req.cacheName())); @@ -1910,7 +1902,11 @@ private void prepareCacheStop(DynamicCacheChangeRequest req) { onKernalStop(cache, req.destroy()); stopCache(cache, true, req.destroy()); + + return ctx; } + + return null; } /** @@ -1940,13 +1936,19 @@ public void onExchangeDone( } if (!F.isEmpty(reqs) && err == null) { + Collection> stopped = null; + for (DynamicCacheChangeRequest req : reqs) { String masked = maskNull(req.cacheName()); + GridCacheContext stopCtx = null; + boolean destroy = false; + if (req.stop()) { stopGateway(req); - prepareCacheStop(req); + stopCtx = prepareCacheStop(req); + destroy = req.destroy(); } else if (req.close() && req.initiatingNodeId().equals(ctx.localNodeId())) { IgniteCacheProxy proxy = jCacheProxies.remove(masked); @@ -1964,11 +1966,22 @@ else if (req.close() && req.initiatingNodeId().equals(ctx.localNodeId())) { proxy.context().gate().onStopped(); - prepareCacheStop(req); + stopCtx = prepareCacheStop(req); + destroy = req.destroy(); } } } + + if (stopCtx != null) { + if (stopped == null) + stopped = new ArrayList<>(); + + stopped.add(F.t(stopCtx, destroy)); + } } + + if (stopped != null) + sharedCtx.database().onCachesStopped(stopped); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index a34e918e03573..7600fb680060e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -39,6 +39,7 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport; +import org.apache.ignite.lang.IgniteBiTuple; import org.jetbrains.annotations.Nullable; /** @@ -186,9 +187,9 @@ public void beforeExchange(GridDhtPartitionsExchangeFuture discoEvt) throws Igni } /** - * @throws IgniteCheckedException If failed. + * @param stoppedCtxs A collection of tuples (cache context, destroy flag). */ - public void beforeCachesStop() throws IgniteCheckedException { + public void onCachesStopped(Collection> stoppedCtxs) { // No-op. } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index bee7842e241aa..1c7abd4aec9d7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -122,7 +122,7 @@ /** * Non-transactional partitioned cache. */ -@SuppressWarnings("unchecked") +@SuppressWarnings({"unchecked", "TooBroadScope"}) @GridToStringExclude public class GridDhtAtomicCache extends GridDhtCacheAdapter { /** */ @@ -1806,6 +1806,8 @@ private void updateAllAsyncInternal0( IgniteCacheExpiryPolicy expiry = null; + ctx.shared().database().checkpointReadLock(); + try { // If batch store update is enabled, we need to lock all entries. // First, need to acquire locks on cache entries, then check filter. @@ -1979,6 +1981,9 @@ private void updateAllAsyncInternal0( return; } + finally { + ctx.shared().database().checkpointReadUnlock(); + } if (remap) { assert dhtFut == null; @@ -2924,8 +2929,6 @@ else if (readers.contains(node.id())) // Reader became primary or backup. @SuppressWarnings("ForLoopReplaceableByForEach") private List lockEntries(GridNearAtomicAbstractUpdateRequest req, AffinityTopologyVersion topVer) throws GridDhtInvalidPartitionException { - ctx.shared().database().checkpointReadLock(); - if (req.size() == 1) { KeyCacheObject key = req.key(0); @@ -3041,8 +3044,6 @@ private void unlockEntries(Collection locked, AffinityTopolog entry.onUnlock(); } - ctx.shared().database().checkpointReadUnlock(); - if (skip != null && skip.size() == locked.size()) // Optimization. return; 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 af0085d0dd39e..1420fd4d36fbd 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 @@ -535,21 +535,6 @@ else if (msg instanceof StartFullSnapshotAckDiscoveryMessage) updateTopologies(crdNode); - if (!F.isEmpty(reqs)) { - boolean hasStop = false; - - for (DynamicCacheChangeRequest req : reqs) { - if (req.stop()) { - hasStop = true; - - break; - } - } - - if (hasStop) - cctx.cache().context().database().beforeCachesStop(); - } - switch (exchange) { case ALL: { distributedExchange(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java index 8d0d1284edfa7..f1be37232e869 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java @@ -354,7 +354,8 @@ CU.UTILITY_CACHE_NAME, new ServiceEntriesListener(), null, null cancelFutures(depFuts, err); cancelFutures(undepFuts, err); - }finally { + } + finally { busyLock.unblock(); } From a65d4a70743685fcacb482ebffe0adb026332a75 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Wed, 8 Feb 2017 12:36:39 +0300 Subject: [PATCH 048/311] IGNITE-3477 - Code formatting. --- .../apache/ignite/internal/util/IgniteUtils.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index b077666d722ac..321c7400393df 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -3441,22 +3441,25 @@ public static boolean delete(@Nullable File file) { if (file.isDirectory()) { File[] files = file.listFiles(); - if (files != null && files.length > 0) - for (File file1 : files) + if (files != null && files.length > 0) { + for (File file1 : files) { if (file1.isDirectory()) res &= delete(file1); - else if (file1.getName().endsWith("jar")) + else if (file1.getName().endsWith("jar")) { try { // Why do we do this? new JarFile(file1, false).close(); - - res &= file1.delete(); } catch (IOException ignore) { // Ignore it here... } + + res &= file1.delete(); + } else res &= file1.delete(); + } + } res &= file.delete(); } From 9a8746e1ae9e599e6b7fa3d376d7f8fc1a4e8b92 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Thu, 2 Feb 2017 19:54:30 +0300 Subject: [PATCH 049/311] GG-11878 - Snapshots ignore node filter --- .../StartFullSnapshotAckDiscoveryMessage.java | 18 +++- .../StartFullSnapshotDiscoveryMessage.java | 16 +++- .../processors/cache/GridCacheEntryEx.java | 7 ++ .../processors/cache/GridCacheMapEntry.java | 11 ++- .../cache/IgniteCacheOffheapManager.java | 20 ++++- .../cache/IgniteCacheOffheapManagerImpl.java | 37 ++++++-- .../IgniteCacheDatabaseSharedManager.java | 3 +- .../processors/query/GridQueryIndexing.java | 10 +-- .../processors/query/GridQueryProcessor.java | 64 ++++++++------ .../ignite/internal/util/IgniteUtils.java | 2 +- .../internal/util/future/CountDownFuture.java | 74 ++++++++++++++++ .../cache/GridCacheTestEntryEx.java | 5 ++ .../processors/query/h2/IgniteH2Indexing.java | 86 +++++++------------ .../query/h2/database/H2TreeIndex.java | 2 +- 14 files changed, 245 insertions(+), 110 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java index 0d926b9d1b692..8ce2bd76be64d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java @@ -22,6 +22,8 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; @@ -61,10 +63,15 @@ public class StartFullSnapshotAckDiscoveryMessage implements DiscoveryCustomMess * @param err Error. * @param cacheNames Cache names. */ - public StartFullSnapshotAckDiscoveryMessage(long globalSnapshotId, boolean fullSnapshot, + public StartFullSnapshotAckDiscoveryMessage( + long globalSnapshotId, + boolean fullSnapshot, Map lastFullSnapshotIdForCache, - Collection cacheNames, Exception err, - UUID initiatorNodeId, String msg) { + Collection cacheNames, + Exception err, + UUID initiatorNodeId, + String msg + ) { this.globalSnapshotId = globalSnapshotId; this.fullSnapshot = fullSnapshot; this.lastFullSnapshotIdForCache = lastFullSnapshotIdForCache; @@ -144,4 +151,9 @@ public String message() { @Override public boolean isMutable() { return false; } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(StartFullSnapshotAckDiscoveryMessage.class, this); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java index 8d18131d74324..b85fe82c68871 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java @@ -23,6 +23,8 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; @@ -143,7 +145,14 @@ public void lastFullSnapshotId(int cacheId, long id) { /** {@inheritDoc} */ @Nullable @Override public DiscoveryCustomMessage ackMessage() { - return new StartFullSnapshotAckDiscoveryMessage(globalSnapshotId, fullSnapshot, lastFullSnapshotIdForCache, cacheNames, err, initiatorId, msg); + return new StartFullSnapshotAckDiscoveryMessage( + globalSnapshotId, + fullSnapshot, + lastFullSnapshotIdForCache, + cacheNames, + err, + initiatorId, + msg); } /** {@inheritDoc} */ @@ -157,4 +166,9 @@ public void lastFullSnapshotId(int cacheId, long id) { public void fullSnapshot(boolean full) { fullSnapshot = full; } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(StartFullSnapshotDiscoveryMessage.class, this); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java index 26e4ed3e60905..4e74594bb1b31 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java @@ -912,6 +912,13 @@ public Collection localCandidates(@Nullable GridCacheVer */ public void updateTtl(@Nullable GridCacheVersion ver, long ttl) throws GridCacheEntryRemovedException; + /** + * Ensures that the value stored in the entry is also inserted in the indexing. + * + * @throws GridCacheEntryRemovedException If entry was removed. + */ + public void ensureIndexed() throws GridCacheEntryRemovedException, IgniteCheckedException; + /** * @return Value. * @throws IgniteCheckedException If failed to read from swap storage. 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 e3dd3042f17b3..4b73c8bd2ec12 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 @@ -3516,6 +3516,15 @@ private IgniteTxLocalAdapter currentTx() { } } + /** {@inheritDoc} */ + @Override public void ensureIndexed() throws GridCacheEntryRemovedException, IgniteCheckedException { + synchronized (this) { + checkObsolete(); + + cctx.offheap().updateIndexes(key, localPartition()); + } + } + /** {@inheritDoc} */ @Override public synchronized CacheObject valueBytes() throws GridCacheEntryRemovedException { checkObsolete(); @@ -3552,7 +3561,7 @@ protected void storeValue(@Nullable CacheObject val, assert Thread.holdsLock(this); assert val != null : "null values in update for key: " + key; - cctx.offheap().update(key, val, ver, expireTime, partition(), localPartition()); + cctx.offheap().update(key, val, ver, expireTime, localPartition()); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java index f01f0ffeeaafc..a93338fb4e357 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java @@ -111,7 +111,6 @@ public interface IgniteCacheOffheapManager extends GridCacheManager { * @param val Value. * @param ver Version. * @param expireTime Expire time. - * @param partId Partition number. * @param part Partition. * @throws IgniteCheckedException If failed. */ @@ -120,7 +119,16 @@ public void update( CacheObject val, GridCacheVersion ver, long expireTime, - int partId, + GridDhtLocalPartition part + ) throws IgniteCheckedException; + + /** + * @param key Key. + * @param part Partition. + * @throws IgniteCheckedException If failed. + */ + public void updateIndexes( + KeyCacheObject key, GridDhtLocalPartition part ) throws IgniteCheckedException; @@ -295,18 +303,22 @@ interface CacheDataStore { /** * @param key Key. - * @param part Partition. * @param val Value. * @param ver Version. * @param expireTime Expire time. * @throws IgniteCheckedException If failed. */ void update(KeyCacheObject key, - int part, CacheObject val, GridCacheVersion ver, long expireTime) throws IgniteCheckedException; + /** + * @param key Key. + * @throws IgniteCheckedException If failed. + */ + void updateIndexes(KeyCacheObject key) throws IgniteCheckedException; + /** * @param key Key. * @param partId Partition number. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index e2a49684d3ecc..cf93f1a2883d5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -23,7 +23,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; import javax.cache.Cache; import org.apache.ignite.IgniteCheckedException; @@ -320,12 +319,16 @@ private Iterator cacheData(boolean primary, boolean backup, Affi CacheObject val, GridCacheVersion ver, long expireTime, - int partId, GridDhtLocalPartition part ) throws IgniteCheckedException { assert expireTime >= 0; - dataStore(part).update(key, partId, val, ver, expireTime); + dataStore(part).update(key, val, ver, expireTime); + } + + /** {@inheritDoc} */ + @Override public void updateIndexes(KeyCacheObject key, GridDhtLocalPartition part) throws IgniteCheckedException { + dataStore(part).updateIndexes(key); } /** {@inheritDoc} */ @@ -890,11 +893,10 @@ public CacheDataStoreImpl( /** {@inheritDoc} */ @Override public void update(KeyCacheObject key, - int p, CacheObject val, GridCacheVersion ver, long expireTime) throws IgniteCheckedException { - DataRow dataRow = new DataRow(key.hashCode(), key, val, ver, p, expireTime); + DataRow dataRow = new DataRow(key.hashCode(), key, val, ver, partId, expireTime); // Make sure value bytes initialized. key.valueBytes(cctx.cacheObjectContext()); @@ -919,9 +921,9 @@ public CacheDataStoreImpl( assert qryMgr.enabled(); if (old != null) - qryMgr.store(key, p, old.value(), old.version(), val, ver, expireTime, dataRow.link()); + qryMgr.store(key, partId, old.value(), old.version(), val, ver, expireTime, dataRow.link()); else - qryMgr.store(key, p, null, null, val, ver, expireTime, dataRow.link()); + qryMgr.store(key, partId, null, null, val, ver, expireTime, dataRow.link()); } if (old != null) { @@ -943,6 +945,27 @@ public CacheDataStoreImpl( } } + /** {@inheritDoc} */ + @Override public void updateIndexes(KeyCacheObject key) throws IgniteCheckedException { + if (indexingEnabled) { + DataRow row = dataTree.findOne(new KeySearchRow(key.hashCode(), key, 0)); + + GridCacheQueryManager qryMgr = cctx.queries(); + + if (row != null) { + qryMgr.store( + key, + partId, + null, + null, + row.value(), + row.version(), + row.expireTime(), + row.link()); + } + } + } + /** {@inheritDoc} */ @Override public void remove(KeyCacheObject key, int partId) throws IgniteCheckedException { if (!busyLock.enterBusy()) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 77631c9efdd58..f2ab94039371f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -180,8 +180,7 @@ public void waitForCheckpoint(String reason) throws IgniteCheckedException { /** * */ - @Nullable public IgniteInternalFuture wakeupForSnapshot(long snapshotId, UUID snapshotNodeId, - Collection cacheNames) { + @Nullable public IgniteInternalFuture wakeupForSnapshot(long snapshotId) { return null; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java index 9fda64d851942..ef344261e853d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java @@ -32,8 +32,6 @@ import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.GridSpinBusyLock; import org.apache.ignite.internal.util.lang.GridCloseableIterator; @@ -232,20 +230,16 @@ public void remove(@Nullable String spaceName, * Rebuilds all indexes of given type from hash index. * * @param spaceName Space name. - * @param type Type descriptor. * @throws IgniteCheckedException If failed. */ - public void rebuildIndexesFromHash(@Nullable String spaceName, - GridQueryTypeDescriptor type) throws IgniteCheckedException; + public void rebuildIndexesFromHash(@Nullable String spaceName) throws IgniteCheckedException; /** * Marks all indexes of given type for rebuild from hash index, making them unusable until rebuild finishes. * * @param spaceName Space name. - * @param type Type descriptor. - * @throws IgniteCheckedException If failed. */ - public void markForRebuildFromHash(@Nullable String spaceName, GridQueryTypeDescriptor type); + public void markForRebuildFromHash(@Nullable String spaceName); /** * Returns backup filter. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 42be691cdcad9..ff501816ef04e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -17,12 +17,11 @@ package org.apache.ignite.internal.processors.query; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.concurrent.TimeUnit; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.math.BigDecimal; +import java.sql.PreparedStatement; +import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; import java.util.ArrayList; @@ -40,6 +39,7 @@ import java.util.UUID; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; import javax.cache.Cache; import javax.cache.CacheException; import org.apache.ignite.IgniteCheckedException; @@ -70,9 +70,8 @@ import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper; -import org.apache.ignite.internal.processors.cache.IgniteCacheProxy; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.QueryCursorImpl; import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture; @@ -91,7 +90,6 @@ import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.A; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.util.worker.GridWorker; @@ -598,7 +596,7 @@ public IgniteInternalFuture rebuildIndexes(@Nullable final String space, Stri throw new IllegalStateException("Failed to rebuild indexes (grid is stopping)."); try { - return rebuildIndexes(space, typesByName.get(new TypeName(space, valTypeName)), false); + return rebuildIndexes(space, typesByName.get(new TypeName(space, valTypeName))); } finally { busyLock.leaveBusy(); @@ -610,8 +608,7 @@ public IgniteInternalFuture rebuildIndexes(@Nullable final String space, Stri * @param desc Type descriptor. * @return Future that will be completed when rebuilding of all indexes is finished. */ - private IgniteInternalFuture rebuildIndexes(@Nullable final String space, @Nullable final TypeDescriptor desc, - final boolean fromHash) { + private IgniteInternalFuture rebuildIndexes(@Nullable final String space, @Nullable final TypeDescriptor desc) { if (idx == null) return new GridFinishedFuture<>(new IgniteCheckedException("Indexing is disabled.")); @@ -620,16 +617,10 @@ private IgniteInternalFuture rebuildIndexes(@Nullable final String space, @Nu final GridWorkerFuture fut = new GridWorkerFuture(); - if (fromHash) - idx.markForRebuildFromHash(space, desc); - GridWorker w = new GridWorker(ctx.gridName(), "index-rebuild-worker", log) { @Override protected void body() { try { - if (fromHash) - idx.rebuildIndexesFromHash(space, desc); - else - idx.rebuildIndexes(space, desc); + idx.rebuildIndexes(space, desc); fut.onDone(); } @@ -637,7 +628,8 @@ private IgniteInternalFuture rebuildIndexes(@Nullable final String space, @Nu fut.onDone(e); } catch (Throwable e) { - log.error("Failed to rebuild indexes for type: " + desc.name(), e); + U.error(log, "Failed to rebuild indexes for type [space=" + space + + ", name=" + desc.name() + ']', e); fut.onDone(e); @@ -668,7 +660,7 @@ public IgniteInternalFuture rebuildAllIndexes() { GridCompoundFuture fut = new GridCompoundFuture(); for (Map.Entry e : types.entrySet()) - fut.add((IgniteInternalFuture)rebuildIndexes(e.getKey().space, e.getValue(), false)); + fut.add((IgniteInternalFuture)rebuildIndexes(e.getKey().space, e.getValue())); fut.markInitialized(); @@ -682,22 +674,42 @@ public IgniteInternalFuture rebuildAllIndexes() { /** * Rebuilds indexes for provided caches from corresponding hash indexes. * - * @param cacheIds Cache IDs. + * @param cacheName Cache name. * @return Future that will be completed when rebuilding is finished. */ - public IgniteInternalFuture rebuildIndexesFromHash(Collection cacheIds) { + public IgniteInternalFuture rebuildIndexesFromHash(final String cacheName) { if (!busyLock.enterBusy()) throw new IllegalStateException("Failed to get space size (grid is stopping)."); try { - GridCompoundFuture fut = new GridCompoundFuture(); + final GridWorkerFuture fut = new GridWorkerFuture(); - for (Map.Entry e : types.entrySet()) { - if (cacheIds.contains(CU.cacheId(e.getKey().space))) - fut.add((IgniteInternalFuture)rebuildIndexes(e.getKey().space, e.getValue(), true)); - } + idx.markForRebuildFromHash(cacheName); - fut.markInitialized(); + GridWorker w = new GridWorker(ctx.gridName(), "index-rebuild-worker", log) { + @Override protected void body() { + try { + idx.rebuildIndexesFromHash(cacheName); + + fut.onDone(); + } + catch (Exception e) { + fut.onDone(e); + } + catch (Throwable e) { + U.error(log, "Failed to rebuild indexes for type [cache=" + cacheName + ']'); + + fut.onDone(e); + + if (e instanceof Error) + throw e; + } + } + }; + + fut.setWorker(w); + + execSvc.execute(w); return fut; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 321c7400393df..29c9386eaa33f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -1109,7 +1109,7 @@ public static void dumpStack() { */ @Deprecated public static void dumpStack(String msg) { - new Exception(debugPrefix() + msg).printStackTrace(System.out); + new Exception(debugPrefix() + msg).printStackTrace(System.err); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java new file mode 100644 index 0000000000000..57ab38431e008 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) GridGain Systems. All Rights Reserved. + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.internal.util.future; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.util.future.GridFutureAdapter; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class CountDownFuture extends GridFutureAdapter { + /** */ + private AtomicInteger remaining; + + /** */ + private AtomicReference errCollector; + + /** + * @param cnt Number of completing parties. + */ + public CountDownFuture(int cnt) { + remaining = new AtomicInteger(cnt); + errCollector = new AtomicReference<>(); + } + + /** {@inheritDoc} */ + @Override public boolean onDone(@Nullable Void res, @Nullable Throwable err) { + if (err != null) + addError(err); + + int left = remaining.decrementAndGet(); + + boolean done = left == 0 && super.onDone(res, errCollector.get()); + + if (done) + afterDone(); + + return done; + } + + /** + * + */ + protected void afterDone() { + // No-op, to be overridden in subclasses. + } + + /** + * @param err Error. + */ + private void addError(Throwable err) { + Exception ex = errCollector.get(); + + if (ex == null) { + Exception compound = new IgniteCheckedException("Compound exception for CountDownFuture."); + + ex = errCollector.compareAndSet(null, compound) ? compound : errCollector.get(); + } + + assert ex != null; + + ex.addSuppressed(err); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java index be3933f52306e..b232617208eb0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java @@ -818,6 +818,11 @@ GridCacheMvccCandidate anyOwner() { throw new UnsupportedOperationException(); } + /** {@inheritDoc} */ + @Override public void ensureIndexed() throws GridCacheEntryRemovedException, IgniteCheckedException { + // No-op. + } + /** {@inheritDoc} */ @Override public CacheObject unswap() throws IgniteCheckedException { return null; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index a2160ffcce70e..e1aef1a48b1f3 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -78,15 +78,16 @@ import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.QueryCursorImpl; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable; import org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery; import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode; -import org.apache.ignite.internal.processors.query.GridQueryCancel; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.processors.query.GridQueryCancel; import org.apache.ignite.internal.processors.query.GridQueryFieldMetadata; import org.apache.ignite.internal.processors.query.GridQueryFieldsResult; import org.apache.ignite.internal.processors.query.GridQueryFieldsResultAdapter; @@ -96,11 +97,11 @@ import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor; import org.apache.ignite.internal.processors.query.IgniteSQLException; import org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex; -import org.apache.ignite.internal.processors.query.h2.opt.GridH2DefaultTableEngine; import org.apache.ignite.internal.processors.query.h2.database.H2RowFactory; import org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex; import org.apache.ignite.internal.processors.query.h2.database.io.H2InnerIO; import org.apache.ignite.internal.processors.query.h2.database.io.H2LeafIO; +import org.apache.ignite.internal.processors.query.h2.opt.GridH2DefaultTableEngine; import org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOffheap; import org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap; import org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryContext; @@ -146,7 +147,6 @@ import org.h2.command.Prepared; import org.h2.engine.Session; import org.h2.engine.SysProperties; -import org.h2.index.Cursor; import org.h2.index.Index; import org.h2.index.SpatialIndex; import org.h2.jdbc.JdbcConnection; @@ -1667,77 +1667,51 @@ public String space(String schemaName) { * Rebuild indexes from hash index. * * @param spaceName Space name. - * @param type Type descriptor. * @throws IgniteCheckedException If failed. */ - @Override public void rebuildIndexesFromHash(@Nullable String spaceName, - GridQueryTypeDescriptor type) throws IgniteCheckedException { - TableDescriptor tbl = tableDescriptor(spaceName, type); - - if (tbl == null) - return; - - assert tbl.tbl != null; - - assert tbl.tbl.rebuildFromHashInProgress(); - - H2PkHashIndex hashIdx = tbl.pkHashIdx; - - Cursor cursor = hashIdx.find((Session)null, null, null); - - int cacheId = CU.cacheId(tbl.schema.ccfg.getName()); + @Override public void rebuildIndexesFromHash(@Nullable String spaceName) throws IgniteCheckedException { + int cacheId = CU.cacheId(spaceName); GridCacheContext cctx = ctx.cache().context().cacheContext(cacheId); - while (cursor.next()) { - CacheDataRow dataRow = (CacheDataRow)cursor.get(); - - boolean done = false; + IgniteCacheOffheapManager offheapMgr = cctx.isNear() ? cctx.near().dht().context().offheap() : cctx.offheap(); - while (!done) { - GridCacheEntryEx entry = cctx.cache().entryEx(dataRow.key()); + for (int p = 0; p < cctx.affinity().partitions(); p++) { + try (GridCloseableIterator keyIter = offheapMgr.keysIterator(p)) { + while (keyIter.hasNext()) { + KeyCacheObject key = keyIter.next(); - try { - synchronized (entry) { - // TODO : How to correctly get current value and link here? - - GridH2Row row = tbl.tbl.rowDescriptor().createRow(entry.key(), entry.partition(), - dataRow.value(), entry.version(), entry.expireTime()); - - row.link(dataRow.link()); - - List indexes = tbl.tbl.getAllIndexes(); + while (true) { + try { + GridCacheEntryEx entry = cctx.isNear() ? + cctx.near().dht().entryEx(key) : cctx.cache().entryEx(key); - for (int i = 2; i < indexes.size(); i++) { - Index idx = indexes.get(i); + entry.ensureIndexed(); - if (idx instanceof H2TreeIndex) - ((H2TreeIndex)idx).put(row); + break; + } + catch (GridCacheEntryRemovedException ignore) { + // Retry. + } + catch (GridDhtInvalidPartitionException ignore) { + break; } - - done = true; } } - catch (GridCacheEntryRemovedException e) { - // No-op - } } - } - tbl.tbl.markRebuildFromHashInProgress(false); + for (TableDescriptor tblDesc : tables(spaceName)) + tblDesc.tbl.markRebuildFromHashInProgress(false); } /** {@inheritDoc} */ - @Override public void markForRebuildFromHash(@Nullable String spaceName, GridQueryTypeDescriptor type) { - TableDescriptor tbl = tableDescriptor(spaceName, type); + @Override public void markForRebuildFromHash(@Nullable String spaceName) { + for (TableDescriptor tblDesc : tables(spaceName)) { + assert tblDesc.tbl != null; - if (tbl == null) - return; - - assert tbl.tbl != null; - - tbl.tbl.markRebuildFromHashInProgress(true); + tblDesc.tbl.markRebuildFromHashInProgress(true); + } } /** diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java index 19cbbf92cbb1b..64d649016c6a8 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java @@ -199,7 +199,7 @@ public H2Tree tree() { /** {@inheritDoc} */ @Override public void destroy() { try { - if (!cctx.kernalContext().clientNode()) { + if (!cctx.kernalContext().clientNode() && cctx.affinityNode()) { tree.destroy(); cctx.offheap().dropRootPageForIndex(tree.getName()); From 7122256c87ce74e7942fa083138dd3a4d5e0f976 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Tue, 7 Feb 2017 19:19:10 +0300 Subject: [PATCH 050/311] GG-11937 - Fixed checkpoint read lock release on exception --- .../processors/cache/GridCacheProcessor.java | 41 ++++++++++++------- .../IgniteCacheDatabaseSharedManager.java | 5 ++- .../dht/atomic/GridDhtAtomicCache.java | 11 ++--- .../GridDhtPartitionsExchangeFuture.java | 15 ------- .../service/GridServiceProcessor.java | 3 +- 5 files changed, 38 insertions(+), 37 deletions(-) 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 80ca9291e2f4e..c6a0b7c7be114 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 @@ -116,6 +116,7 @@ import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiTuple; import org.apache.ignite.lang.IgniteClosure; import org.apache.ignite.lang.IgniteFuture; import org.apache.ignite.lang.IgnitePredicate; @@ -904,7 +905,7 @@ private void addRemovedItemsCleanupTask(long timeout) { private void checkConsistency() throws IgniteCheckedException { if (!ctx.config().isDaemon() && !getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) { for (ClusterNode n : ctx.discovery().remoteNodes()) { - if (n.attribute(ATTR_CONSISTENCY_CHECK_SKIPPED)) + if (Boolean.TRUE.equals(n.attribute(ATTR_CONSISTENCY_CHECK_SKIPPED))) continue; checkTransactionConfiguration(n); @@ -1264,16 +1265,6 @@ private void stopCache(GridCacheAdapter cache, boolean cancel, boolean des if (log.isInfoEnabled()) log.info("Stopped cache: " + cache.name()); - if (sharedCtx.pageStore() != null) { - try { - sharedCtx.pageStore().shutdownForCache(ctx, destroy); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to gracefully clean page store resources for destroyed cache " + - "[cache=" + ctx.name() + "]", e); - } - } - cleanup(ctx); } @@ -1909,8 +1900,9 @@ private void stopGateway(DynamicCacheChangeRequest req) { /** * @param req Stop request. + * @return Stopped cache context. */ - private void prepareCacheStop(DynamicCacheChangeRequest req) { + private GridCacheContext prepareCacheStop(DynamicCacheChangeRequest req) { assert req.stop() || req.close() : req; GridCacheAdapter cache = caches.remove(maskNull(req.cacheName())); @@ -1926,7 +1918,11 @@ private void prepareCacheStop(DynamicCacheChangeRequest req) { onKernalStop(cache, req.destroy()); stopCache(cache, true, req.destroy()); + + return ctx; } + + return null; } /** @@ -1956,16 +1952,22 @@ public void onExchangeDone( } if (!F.isEmpty(reqs) && err == null) { + Collection> stopped = null; + for (DynamicCacheChangeRequest req : reqs) { String masked = maskNull(req.cacheName()); + GridCacheContext stopCtx = null; + boolean destroy = false; + if (req.stop()) { stopGateway(req); sharedCtx.database().checkpointReadLock(); try { - prepareCacheStop(req); + stopCtx = prepareCacheStop(req); + destroy = req.destroy(); } finally { sharedCtx.database().checkpointReadUnlock(); @@ -1987,11 +1989,22 @@ else if (req.close() && req.initiatingNodeId().equals(ctx.localNodeId())) { proxy.context().gate().onStopped(); - prepareCacheStop(req); + stopCtx = prepareCacheStop(req); + destroy = req.destroy(); } } } + + if (stopCtx != null) { + if (stopped == null) + stopped = new ArrayList<>(); + + stopped.add(F.t(stopCtx, destroy)); + } } + + if (stopped != null) + sharedCtx.database().onCachesStopped(stopped); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index f2ab94039371f..33dc7b47672a9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -39,6 +39,7 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport; +import org.apache.ignite.lang.IgniteBiTuple; import org.jetbrains.annotations.Nullable; /** @@ -192,9 +193,9 @@ public void beforeExchange(GridDhtPartitionsExchangeFuture discoEvt) throws Igni } /** - * @throws IgniteCheckedException If failed. + * @param stoppedCtxs A collection of tuples (cache context, destroy flag). */ - public void beforeCachesStop() throws IgniteCheckedException { + public void onCachesStopped(Collection> stoppedCtxs) { // No-op. } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index ac5fda260d34b..a9bca20b8209c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -122,7 +122,7 @@ /** * Non-transactional partitioned cache. */ -@SuppressWarnings("unchecked") +@SuppressWarnings({"unchecked", "TooBroadScope"}) @GridToStringExclude public class GridDhtAtomicCache extends GridDhtCacheAdapter { /** */ @@ -1806,6 +1806,8 @@ private void updateAllAsyncInternal0( IgniteCacheExpiryPolicy expiry = null; + ctx.shared().database().checkpointReadLock(); + try { // If batch store update is enabled, we need to lock all entries. // First, need to acquire locks on cache entries, then check filter. @@ -1978,6 +1980,9 @@ private void updateAllAsyncInternal0( return; } + finally { + ctx.shared().database().checkpointReadUnlock(); + } if (remap) { assert dhtFut == null; @@ -2923,8 +2928,6 @@ else if (readers.contains(node.id())) // Reader became primary or backup. @SuppressWarnings("ForLoopReplaceableByForEach") private List lockEntries(GridNearAtomicAbstractUpdateRequest req, AffinityTopologyVersion topVer) throws GridDhtInvalidPartitionException { - ctx.shared().database().checkpointReadLock(); - if (req.size() == 1) { KeyCacheObject key = req.key(0); @@ -3040,8 +3043,6 @@ private void unlockEntries(Collection locked, AffinityTopolog entry.onUnlock(); } - ctx.shared().database().checkpointReadUnlock(); - if (skip != null && skip.size() == locked.size()) // Optimization. return; 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 2ccb29bc0d000..f34eccadcaea8 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 @@ -535,21 +535,6 @@ else if (msg instanceof StartFullSnapshotAckDiscoveryMessage) updateTopologies(crdNode); - if (!F.isEmpty(reqs)) { - boolean hasStop = false; - - for (DynamicCacheChangeRequest req : reqs) { - if (req.stop()) { - hasStop = true; - - break; - } - } - - if (hasStop) - cctx.cache().context().database().beforeCachesStop(); - } - switch (exchange) { case ALL: { distributedExchange(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java index 9587b046cd71d..7cf77661bdb96 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java @@ -354,7 +354,8 @@ CU.UTILITY_CACHE_NAME, new ServiceEntriesListener(), null, null cancelFutures(depFuts, err); cancelFutures(undepFuts, err); - }finally { + } + finally { busyLock.unblock(); } From fe63e0ea349cdaab02e919d40f8f3df6a5e5cf00 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Wed, 8 Feb 2017 18:15:17 +0300 Subject: [PATCH 051/311] GG-11954 - Fixing tests --- .../processors/cache/GridCacheProcessor.java | 2 +- .../IgniteCacheDatabaseSharedManager.java | 5 +-- .../GridDhtPartitionsExchangeFuture.java | 6 +--- .../processors/query/h2/IgniteH2Indexing.java | 33 +++++++++++-------- 4 files changed, 23 insertions(+), 23 deletions(-) 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 c6a0b7c7be114..f21911e6a6169 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 @@ -2003,7 +2003,7 @@ else if (req.close() && req.initiatingNodeId().equals(ctx.localNodeId())) { } } - if (stopped != null) + if (stopped != null && !sharedCtx.kernalContext().clientNode()) sharedCtx.database().onCachesStopped(stopped); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 33dc7b47672a9..fa2a96024eae9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -208,13 +208,10 @@ public void onCacheStop(GridCacheContext cctx) { /** * @param snapshotMsg Snapshot message. - * @param initiator Initiator node. - * @param msg message to log * @return Snapshot creation init future or {@code null} if snapshot is not available. * @throws IgniteCheckedException If failed. */ - @Nullable public IgniteInternalFuture startLocalSnapshotCreation(StartFullSnapshotAckDiscoveryMessage snapshotMsg, - ClusterNode initiator, String msg) + @Nullable public IgniteInternalFuture startLocalSnapshotCreation(StartFullSnapshotAckDiscoveryMessage snapshotMsg) throws IgniteCheckedException { return null; } 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 f34eccadcaea8..851fc731d431c 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 @@ -814,11 +814,7 @@ private void distributedExchange() throws IgniteCheckedException { StartFullSnapshotAckDiscoveryMessage backupMsg = (StartFullSnapshotAckDiscoveryMessage)customMessage; if (!cctx.localNode().isClient() && !cctx.localNode().isDaemon()) { - ClusterNode node = cctx.discovery().node(backupMsg.initiatorNodeId()); - - assert node != null; - - IgniteInternalFuture fut = cctx.database().startLocalSnapshotCreation(backupMsg, node, backupMsg.message()); + IgniteInternalFuture fut = cctx.database().startLocalSnapshotCreation(backupMsg); if (fut != null) fut.get(); diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index e1aef1a48b1f3..eba345d7d1bff 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -1679,24 +1679,31 @@ public String space(String schemaName) { for (int p = 0; p < cctx.affinity().partitions(); p++) { try (GridCloseableIterator keyIter = offheapMgr.keysIterator(p)) { while (keyIter.hasNext()) { - KeyCacheObject key = keyIter.next(); + cctx.shared().database().checkpointReadLock(); - while (true) { - try { - GridCacheEntryEx entry = cctx.isNear() ? - cctx.near().dht().entryEx(key) : cctx.cache().entryEx(key); + try { + KeyCacheObject key = keyIter.next(); - entry.ensureIndexed(); + while (true) { + try { + GridCacheEntryEx entry = cctx.isNear() ? + cctx.near().dht().entryEx(key) : cctx.cache().entryEx(key); - break; - } - catch (GridCacheEntryRemovedException ignore) { - // Retry. - } - catch (GridDhtInvalidPartitionException ignore) { - break; + entry.ensureIndexed(); + + break; + } + catch (GridCacheEntryRemovedException ignore) { + // Retry. + } + catch (GridDhtInvalidPartitionException ignore) { + break; + } } } + finally { + cctx.shared().database().checkpointReadUnlock(); + } } } } From f092fbf2a0b8d727827a080078f9892d24e2b4ae Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 8 Feb 2017 18:51:53 +0300 Subject: [PATCH 052/311] ignite-gg-11952 fix issue. --- .../snapshot/StartFullSnapshotDiscoveryMessage.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java index b85fe82c68871..c4a80cd367f57 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java @@ -63,8 +63,13 @@ public class StartFullSnapshotDiscoveryMessage implements DiscoveryCustomMessage * @param cacheNames Cache names. * @param msg message to log */ - public StartFullSnapshotDiscoveryMessage(long globalSnapshotId, Collection cacheNames, UUID initiatorId, - boolean fullSnapshot, String msg) { + public StartFullSnapshotDiscoveryMessage( + long globalSnapshotId, + Collection cacheNames, + UUID initiatorId, + boolean fullSnapshot, + String msg + ) { this.globalSnapshotId = globalSnapshotId; this.cacheNames = cacheNames; this.initiatorId = initiatorId; From fe0cff39445f1d8e3eea1241c51750c888114121 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Thu, 9 Feb 2017 13:47:55 +0300 Subject: [PATCH 053/311] ignite-gg-8.0.2.ea4 licence header fix. --- .../internal/util/future/CountDownFuture.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java index 57ab38431e008..f01f7bcf11aba 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/future/CountDownFuture.java @@ -1,10 +1,18 @@ /* - * Copyright (C) GridGain Systems. All Rights Reserved. - * _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + * 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.util.future; @@ -12,7 +20,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.jetbrains.annotations.Nullable; /** From 839c598988ba7710c168d6c9e48378d912177010 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Thu, 9 Feb 2017 16:44:41 +0700 Subject: [PATCH 054/311] IGNITE-4676 Fixed hang if closure executed nested internal task with continuation. Added test. (cherry picked from commit e7a5307) --- .../processors/job/GridJobWorker.java | 4 + .../internal/GridContinuousTaskSelfTest.java | 79 +++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobWorker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobWorker.java index 9bee8490fca4f..a1e7dbdee5182 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobWorker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobWorker.java @@ -614,6 +614,10 @@ else if (X.hasCause(e, GridServiceNotFoundException.class) || // Finish here only if not held by this thread. if (!HOLD.get()) finishJob(res, ex, sndRes); + else + // Make sure flag is not set for current thread. + // This may happen in case of nested internal task call with continuation. + HOLD.set(false); ctx.job().currentTaskSession(null); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridContinuousTaskSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridContinuousTaskSelfTest.java index 98e3c5afc8e2d..cec288714c100 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/GridContinuousTaskSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/GridContinuousTaskSelfTest.java @@ -21,10 +21,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.Callable; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCompute; import org.apache.ignite.IgniteException; @@ -43,7 +45,9 @@ import org.apache.ignite.compute.ComputeTaskSessionAttributeListener; import org.apache.ignite.compute.ComputeTaskSessionFullSupport; import org.apache.ignite.compute.ComputeTaskSplitAdapter; +import org.apache.ignite.internal.processors.task.GridInternal; import org.apache.ignite.lang.IgniteClosure; +import org.apache.ignite.resources.IgniteInstanceResource; import org.apache.ignite.resources.JobContextResource; import org.apache.ignite.resources.LoggerResource; import org.apache.ignite.resources.TaskContinuousMapperResource; @@ -51,6 +55,7 @@ import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.apache.ignite.testframework.junits.common.GridCommonTest; +import org.jetbrains.annotations.Nullable; /** * Continuous task test. @@ -195,6 +200,80 @@ public void testMultipleHoldccCalls() throws Exception { } } + /** + * @throws Exception If test failed. + */ + public void testClosureWithNestedInternalTask() throws Exception { + try { + IgniteEx ignite = startGrid(0); + + ComputeTaskInternalFuture fut = ignite.context().closure().callAsync(GridClosureCallMode.BALANCE, new Callable() { + /** */ + @IgniteInstanceResource + private IgniteEx g; + + @Override public String call() throws Exception { + return g.compute(g.cluster()).execute(NestedHoldccTask.class, null); + } + }, ignite.cluster().nodes()); + + assertEquals("DONE", fut.get(3000)); + } + finally { + stopGrid(0, true); + } + } + + /** Test task with continuation. */ + @GridInternal + public static class NestedHoldccTask extends ComputeTaskAdapter { + /** {@inheritDoc} */ + @Nullable @Override public Map map(List subgrid, + @Nullable String arg) throws IgniteException { + Map map = new HashMap<>(); + + for (ClusterNode node : subgrid) + map.put(new NestedHoldccJob(), node); + + return map; + + } + + /** {@inheritDoc} */ + @Nullable @Override public String reduce(List results) throws IgniteException { + return results.get(0).getData(); + } + } + + /** Test job. */ + public static class NestedHoldccJob extends ComputeJobAdapter { + /** */ + @JobContextResource + private ComputeJobContext jobCtx; + + /** */ + private int cnt = 0; + + /** {@inheritDoc} */ + @Override public Object execute() throws IgniteException { + if (cnt < 1) { + cnt++; + + jobCtx.holdcc(); + + new Timer().schedule(new TimerTask() { + @Override public void run() { + jobCtx.callcc(); + } + }, 500); + + return "NOT DONE"; + } + + return "DONE"; + } + } + /** */ @SuppressWarnings({"PublicInnerClass"}) public static class TestMultipleHoldccCallsClosure implements IgniteClosure { From c286f9625287d99f107edbb0ad13e31c9f7de4f4 Mon Sep 17 00:00:00 2001 From: Eduard Shangareev Date: Sun, 12 Feb 2017 18:36:54 +0300 Subject: [PATCH 055/311] Fixing deletion tests --- .../StartFullSnapshotAckDiscoveryMessage.java | 21 +++++++++++++++++++ .../StartFullSnapshotDiscoveryMessage.java | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java index 8ce2bd76be64d..08082de4ce253 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; +import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; @@ -58,6 +59,9 @@ public class StartFullSnapshotAckDiscoveryMessage implements DiscoveryCustomMess /** Last full snapshot id for cache. */ private Map lastFullSnapshotIdForCache; + /** Last snapshot id for cache. */ + private Map lastSnapshotIdForCache; + /** * @param globalSnapshotId Snapshot ID. * @param err Error. @@ -67,6 +71,7 @@ public StartFullSnapshotAckDiscoveryMessage( long globalSnapshotId, boolean fullSnapshot, Map lastFullSnapshotIdForCache, + Map lastSnapshotIdForCache, Collection cacheNames, Exception err, UUID initiatorNodeId, @@ -75,10 +80,19 @@ public StartFullSnapshotAckDiscoveryMessage( this.globalSnapshotId = globalSnapshotId; this.fullSnapshot = fullSnapshot; this.lastFullSnapshotIdForCache = lastFullSnapshotIdForCache; + this.lastSnapshotIdForCache = lastSnapshotIdForCache; this.err = err; this.cacheNames = cacheNames; this.initiatorNodeId = initiatorNodeId; this.msg = msg; + + for (String cacheName : cacheNames) { + int i = CU.cacheId(cacheName); + + if (lastFullSnapshotIdForCache.get(i) == null || lastSnapshotIdForCache.get(i) == null) { + throw new AssertionError(); + } + } } /** @@ -142,6 +156,13 @@ public String message() { return lastFullSnapshotIdForCache.get(cacheId); } + /** + * @param cacheId Cache id. + */ + @Nullable public Long lastSnapshotId(int cacheId) { + return lastSnapshotIdForCache.get(cacheId); + } + /** {@inheritDoc} */ @Nullable @Override public DiscoveryCustomMessage ackMessage() { return null; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java index c4a80cd367f57..bd6d97f5f3330 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java @@ -59,6 +59,9 @@ public class StartFullSnapshotDiscoveryMessage implements DiscoveryCustomMessage /** Last full snapshot id for cache. */ private Map lastFullSnapshotIdForCache = new HashMap<>(); + /** Last snapshot id for cache. */ + private Map lastSnapshotIdForCache = new HashMap<>(); + /** * @param cacheNames Cache names. * @param msg message to log @@ -148,12 +151,28 @@ public void lastFullSnapshotId(int cacheId, long id) { lastFullSnapshotIdForCache.put(cacheId, id); } + /** + * @param cacheId Cache id. + */ + public Long lastSnapshotId(int cacheId) { + return lastSnapshotIdForCache.get(cacheId); + } + + /** + * @param cacheId Cache id. + * @param id Id. + */ + public void lastSnapshotId(int cacheId, long id) { + lastSnapshotIdForCache.put(cacheId, id); + } + /** {@inheritDoc} */ @Nullable @Override public DiscoveryCustomMessage ackMessage() { return new StartFullSnapshotAckDiscoveryMessage( globalSnapshotId, fullSnapshot, lastFullSnapshotIdForCache, + lastSnapshotIdForCache, cacheNames, err, initiatorId, From adf223eb280d4ce5320d9e8923be5a8e5802a268 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Mon, 13 Feb 2017 14:10:39 +0300 Subject: [PATCH 056/311] Use maskNull for stopAllCaches request --- .../ignite/internal/processors/cache/GridCacheProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 69bba787f2e49..24fc7b15f1c5d 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 @@ -2713,7 +2713,7 @@ public Collection stopAllCachesRequests(){ DynamicCacheChangeRequest req = new DynamicCacheChangeRequest( UUID.randomUUID(), cacheName, ctx.localNodeId()); - DynamicCacheDescriptor desc = registeredCaches.get(cacheName); + DynamicCacheDescriptor desc = registeredCaches.get(maskNull(cacheName)); req.deploymentId(desc.deploymentId()); req.stop(true); From e4e58df698950c699170f1bd17c57e67026eda20 Mon Sep 17 00:00:00 2001 From: Aleksei Scherbakov Date: Mon, 13 Feb 2017 14:19:27 +0300 Subject: [PATCH 057/311] IGNITE-4664 - Added lifecycle and injection support for TopologyValidator. Fixes #1514 --- .../processors/cache/GridCacheProcessor.java | 5 + .../GridCacheLifecycleAwareSelfTest.java | 33 ++ ...teTopologyValidatorGridSplitCacheTest.java | 334 ++++++++++++++++++ .../IgniteTopologyValidatorTestSuit.java | 1 + 4 files changed, 373 insertions(+) create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorGridSplitCacheTest.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 f21911e6a6169..6ba6a85bbbf3d 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 @@ -494,6 +494,7 @@ private void prepare(CacheConfiguration cfg, Collection objs) throws Ign prepare(cfg, cfg.getAffinityMapper(), false); prepare(cfg, cfg.getEvictionFilter(), false); prepare(cfg, cfg.getInterceptor(), false); + prepare(cfg, cfg.getTopologyValidator(), false); NearCacheConfiguration nearCfg = cfg.getNearConfiguration(); @@ -529,6 +530,9 @@ private void cleanup(GridCacheContext cctx) { cleanup(cfg, cfg.getEvictionPolicy(), false); cleanup(cfg, cfg.getAffinity(), false); cleanup(cfg, cfg.getAffinityMapper(), false); + cleanup(cfg, cfg.getEvictionFilter(), false); + cleanup(cfg, cfg.getInterceptor(), false); + cleanup(cfg, cfg.getTopologyValidator(), false); cleanup(cfg, cctx.store().configuredStore(), false); if (!CU.isUtilityCache(cfg.getName()) && !CU.isSystemCache(cfg.getName())) { @@ -3819,6 +3823,7 @@ private Iterable lifecycleAwares(CacheConfiguration ccfg, Object... objs ret.add(ccfg.getEvictionFilter()); ret.add(ccfg.getEvictionPolicy()); ret.add(ccfg.getInterceptor()); + ret.add(ccfg.getTopologyValidator()); NearCacheConfiguration nearCfg = ccfg.getNearConfiguration(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLifecycleAwareSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLifecycleAwareSelfTest.java index 81a6433732ec8..aa31ff9bb52f0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLifecycleAwareSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLifecycleAwareSelfTest.java @@ -26,6 +26,7 @@ import java.util.UUID; import javax.cache.Cache; import javax.cache.integration.CacheLoaderException; +import org.apache.ignite.Ignite; import org.apache.ignite.cache.CacheInterceptor; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.cache.affinity.AffinityFunction; @@ -39,10 +40,12 @@ import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.NearCacheConfiguration; +import org.apache.ignite.configuration.TopologyValidator; import org.apache.ignite.lang.IgniteBiInClosure; import org.apache.ignite.lang.IgniteBiTuple; import org.apache.ignite.lifecycle.LifecycleAware; import org.apache.ignite.resources.CacheNameResource; +import org.apache.ignite.resources.IgniteInstanceResource; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.apache.ignite.testframework.junits.common.GridAbstractLifecycleAwareSelfTest; import org.jetbrains.annotations.Nullable; @@ -256,6 +259,30 @@ private TestInterceptor() { } } + /** + */ + private static class TestTopologyValidator extends TestLifecycleAware implements TopologyValidator { + @IgniteInstanceResource + private Ignite ignite; + + /** + */ + public TestTopologyValidator() { + super(CACHE_NAME); + } + + /** {@inheritDoc} */ + @Override public boolean validate(Collection nodes) { + return false; + } + + @Override public void start() { + super.start(); + + assertNotNull(ignite); + } + } + /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected final IgniteConfiguration getConfiguration(String gridName) throws Exception { @@ -324,6 +351,12 @@ private TestInterceptor() { ccfg.setInterceptor(interceptor); + TestTopologyValidator topValidator = new TestTopologyValidator(); + + lifecycleAwares.add(topValidator); + + ccfg.setTopologyValidator(topValidator); + cfg.setCacheConfiguration(ccfg); return cfg; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorGridSplitCacheTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorGridSplitCacheTest.java new file mode 100644 index 0000000000000..3593ad663e6b0 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorGridSplitCacheTest.java @@ -0,0 +1,334 @@ +/* + * 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 java.util.Collection; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.TopologyValidator; +import org.apache.ignite.events.DiscoveryEvent; +import org.apache.ignite.events.Event; +import org.apache.ignite.events.EventType; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.lifecycle.LifecycleAware; +import org.apache.ignite.resources.CacheNameResource; +import org.apache.ignite.resources.IgniteInstanceResource; +import org.apache.ignite.resources.LoggerResource; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +import static org.apache.ignite.cache.CacheMode.PARTITIONED; + +/** + * Tests complex scenario with topology validator. + * Grid is split between to data centers, defined by attribute {@link #DC_NODE_ATTR}. + * If only nodes from single DC are left in topology, grid is moved into inoperative state until special + * activator node'll enter a topology, enabling grid operations. + */ +public class IgniteTopologyValidatorGridSplitCacheTest extends GridCommonAbstractTest { + /** */ + private static final String DC_NODE_ATTR = "dc"; + + /** */ + private static final String ACTIVATOR_NODE_ATTR = "split.resolved"; + + /** */ + private static final int GRID_CNT = 4; + + /** */ + private static final int CACHES_CNT = 10; + + /** */ + private static final int RESOLVER_GRID_IDX = GRID_CNT; + + /** */ + private static final int CONFIGLESS_GRID_IDX = GRID_CNT + 1; + + /** */ + private static CountDownLatch initLatch = new CountDownLatch(GRID_CNT); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + int idx = getTestGridIndex(gridName); + + cfg.setUserAttributes(F.asMap(DC_NODE_ATTR, idx % 2)); + + if (idx != CONFIGLESS_GRID_IDX) { + if (idx == RESOLVER_GRID_IDX) { + cfg.setClientMode(true); + + cfg.setUserAttributes(F.asMap(ACTIVATOR_NODE_ATTR, "true")); + } + else { + CacheConfiguration[] ccfgs = new CacheConfiguration[CACHES_CNT]; + + for (int cnt = 0; cnt < CACHES_CNT; cnt++) { + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setName(testCacheName(cnt)); + ccfg.setCacheMode(PARTITIONED); + ccfg.setBackups(0); + ccfg.setTopologyValidator(new SplitAwareTopologyValidator()); + + ccfgs[cnt] = ccfg; + } + + cfg.setCacheConfiguration(ccfgs); + } + } + + return cfg; + } + + /** + * @param idx Index. + */ + private String testCacheName(int idx) { + return "test" + idx; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + startGridsMultiThreaded(GRID_CNT); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + + stopAllGrids(); + } + + /** + * Tests topology split scenario. + * @throws Exception + */ + public void testTopologyValidator() throws Exception { + assertTrue(initLatch.await(10, TimeUnit.SECONDS)); + + // Tests what each node is able to do puts. + tryPut(0, 1, 2, 3); + + clearAll(); + + stopGrid(1); + + stopGrid(3); + + awaitPartitionMapExchange(); + + try { + tryPut(0, 2); + + fail(); + } + catch (Exception e) { + // No-op. + } + + resolveSplit(); + + tryPut(0, 2); + + clearAll(); + + startGrid(CONFIGLESS_GRID_IDX); + + awaitPartitionMapExchange(); + + tryPut(CONFIGLESS_GRID_IDX); + + stopGrid(CONFIGLESS_GRID_IDX); + + awaitPartitionMapExchange(); + + try { + tryPut(0, 2); + + fail(); + } + catch (Exception e) { + // No-op. + } + + resolveSplit(); + + tryPut(0, 2); + + clearAll(); + + startGrid(1); + + awaitPartitionMapExchange(); + + tryPut(0, 1, 2); + } + + /** */ + private void clearAll() { + for (int i = 0; i < CACHES_CNT; i++) + grid(0).cache(testCacheName(i)).clear(); + } + + /** + * Resolves split by client node join. + */ + private void resolveSplit() throws Exception { + startGrid(RESOLVER_GRID_IDX); + + stopGrid(RESOLVER_GRID_IDX); + } + + /** + * @param grids Grids to test. + */ + private void tryPut(int... grids) { + for (int i = 0; i < grids.length; i++) { + IgniteEx g = grid(grids[i]); + + for (int cnt = 0; cnt < CACHES_CNT; cnt++) { + String cacheName = testCacheName(cnt); + + for (int k = 0; k < 100; k++) { + if (g.affinity(cacheName).isPrimary(g.localNode(), k)) { + log().info("Put " + k + " to node " + g.localNode().id().toString()); + + IgniteCache cache = g.cache(cacheName); + + cache.put(k, k); + + assertEquals(1, cache.localSize()); + + break; + } + } + } + } + } + + /** + * Prevents cache from performing any operation if only nodes from single data center are left in topology. + */ + private static class SplitAwareTopologyValidator implements TopologyValidator, LifecycleAware { + /** */ + private static final long serialVersionUID = 0L; + + @CacheNameResource + private String cacheName; + + @IgniteInstanceResource + private Ignite ignite; + + @LoggerResource + private IgniteLogger log; + + /** */ + private transient volatile long activatorTopVer; + + /** {@inheritDoc} */ + @Override public boolean validate(Collection nodes) { + if (!F.view(nodes, new IgnitePredicate() { + @Override public boolean apply(ClusterNode node) { + return !node.isClient() && node.attribute(DC_NODE_ATTR) == null; + } + }).isEmpty()) + return false; + + IgniteKernal kernal = (IgniteKernal)ignite.cache(cacheName).unwrap(Ignite.class); + + GridDhtCacheAdapter dht = kernal.context().cache().internalCache(cacheName).context().dht(); + + long cacheTopVer = dht.topology().topologyVersionFuture().topologyVersion().topologyVersion(); + + if (hasSplit(nodes)) { + boolean resolved = activatorTopVer != 0 && cacheTopVer >= activatorTopVer; + + if (!resolved) + log.info("Grid segmentation is detected, switching to inoperative state."); + + return resolved; + } + else + activatorTopVer = 0; + + return true; + } + + /** */ + private boolean hasSplit(Collection nodes) { + ClusterNode prev = null; + + for (ClusterNode node : nodes) { + if (node.isClient()) + continue; + + if (prev != null && + !prev.attribute(DC_NODE_ATTR).equals(node.attribute(DC_NODE_ATTR))) + return false; + + prev = node; + } + + return true; + } + + @Override public void start() throws IgniteException { + if (ignite.cluster().localNode().isClient()) + return; + + initLatch.countDown(); + + ignite.events().localListen(new IgnitePredicate() { + @Override public boolean apply(Event evt) { + DiscoveryEvent discoEvt = (DiscoveryEvent)evt; + + ClusterNode node = discoEvt.eventNode(); + + if (isMarkerNode(node)) + activatorTopVer = discoEvt.topologyVersion(); + + return true; + } + }, EventType.EVT_NODE_LEFT); + } + + /** + * @param node Node. + */ + private boolean isMarkerNode(ClusterNode node) { + return node.isClient() && node.attribute(ACTIVATOR_NODE_ATTR) != null; + } + + @Override public void stop() throws IgniteException { + } + } +} \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteTopologyValidatorTestSuit.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteTopologyValidatorTestSuit.java index b100127c79ae9..8c4cd1139452a 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteTopologyValidatorTestSuit.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteTopologyValidatorTestSuit.java @@ -37,6 +37,7 @@ public static TestSuite suite() throws Exception { suite.addTest(new TestSuite(IgniteTopologyValidatorPartitionedTxCacheTest.class)); suite.addTest(new TestSuite(IgniteTopologyValidatorReplicatedAtomicCacheTest.class)); suite.addTest(new TestSuite(IgniteTopologyValidatorReplicatedTxCacheTest.class)); + suite.addTest(new TestSuite(IgniteTopologyValidatorGridSplitCacheTest.class)); return suite; } From 811a2f9199a20c810c6072ba4888cf5712445d9d Mon Sep 17 00:00:00 2001 From: Eduard Shangareev Date: Mon, 13 Feb 2017 22:30:09 +0300 Subject: [PATCH 058/311] GG-11948 All page updates should be done under checkpoint lock (cherry picked from commit fbee63a400b37dce58bb8e3ff681deb23e5ffac4) --- .../processors/cache/database/RowStore.java | 17 +++++++++++++++-- .../dht/preloader/GridDhtForceKeysFuture.java | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java index 8d54542e9173a..0acaa6b018660 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java @@ -70,8 +70,14 @@ protected final Page page(long pageId) throws IgniteCheckedException { */ public void removeRow(long link) throws IgniteCheckedException { assert link != 0; + cctx.shared().database().checkpointReadLock(); - freeList.removeDataRowByLink(link); + try { + freeList.removeDataRowByLink(link); + } + finally { + cctx.shared().database().checkpointReadUnlock(); + } } /** @@ -79,7 +85,14 @@ public void removeRow(long link) throws IgniteCheckedException { * @throws IgniteCheckedException If failed. */ public void addRow(CacheDataRow row) throws IgniteCheckedException { - freeList.insertDataRow(row); + cctx.shared().database().checkpointReadLock(); + + try { + freeList.insertDataRow(row); + } + finally { + cctx.shared().database().checkpointReadUnlock(); + } } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java index 2f58ca98c508a..53cd360e611de 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java @@ -542,6 +542,8 @@ void onResult(GridDhtForceKeysResponse res) { if (locPart != null && (!cctx.rebalanceEnabled() || locPart.state() == MOVING) && locPart.reserve()) { GridCacheEntryEx entry = cctx.dht().entryEx(info.key()); + cctx.shared().database().checkpointReadLock(); + try { if (entry.initialValue( info.value(), @@ -570,6 +572,8 @@ void onResult(GridDhtForceKeysResponse res) { cctx.namex() + ", entry=" + entry + ']'); } finally { + cctx.shared().database().checkpointReadUnlock(); + locPart.release(); } } From 10f6cbbce328da9059a7a57e1ba12f77b088bfbe Mon Sep 17 00:00:00 2001 From: vdpyatkov Date: Fri, 10 Feb 2017 15:08:45 +0300 Subject: [PATCH 059/311] ignite-3994 GridContinuousHandler cleanup on client disconnect. This closes #1496. (cherry picked from commit 2f4bdbb) --- .../internal/GridEventConsumeHandler.java | 5 + .../internal/GridMessageListenHandler.java | 5 + .../CacheContinuousQueryHandler.java | 16 ++ .../continuous/GridContinuousHandler.java | 5 + .../continuous/GridContinuousProcessor.java | 3 + .../ClientReconnectContinuousQueryTest.java | 201 ++++++++++++++++++ .../IgniteCacheQuerySelfTestSuite3.java | 2 + 7 files changed, 237 insertions(+) create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/ClientReconnectContinuousQueryTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java index 7b8408fb9143e..54e3d7fcc3bad 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java @@ -392,6 +392,11 @@ public GridEventConsumeHandler() { return new GridContinuousBatchAdapter(); } + /** {@inheritDoc} */ + @Override public void onClientDisconnected() { + // No-op. + } + /** {@inheritDoc} */ @Override public void onBatchAcknowledged(UUID routineId, GridContinuousBatch batch, GridKernalContext ctx) { // No-op. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridMessageListenHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/GridMessageListenHandler.java index 88b809367c0bf..c146eca255aba 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridMessageListenHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridMessageListenHandler.java @@ -199,6 +199,11 @@ public GridMessageListenHandler(GridMessageListenHandler orig) { return new GridContinuousBatchAdapter(); } + /** {@inheritDoc} */ + @Override public void onClientDisconnected() { + // No-op. + } + /** {@inheritDoc} */ @Override public void onBatchAcknowledged(UUID routineId, GridContinuousBatch batch, GridKernalContext ctx) { // No-op. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java index 5e2e30751af8d..283017c8b10e4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java @@ -845,6 +845,15 @@ private String taskName() { return ctx.security().enabled() ? ctx.task().resolveTaskName(taskHash) : null; } + /** {@inheritDoc} */ + @Override public void onClientDisconnected() { + if (internal) + return; + + for (PartitionRecovery rec : rcvs.values()) + rec.resetTopologyCache(); + } + /** * @param ctx Context. * @param partId Partition id. @@ -962,6 +971,13 @@ private static class PartitionRecovery { } } + /** + * Resets cached topology. + */ + void resetTopologyCache() { + curTop = AffinityTopologyVersion.NONE; + } + /** * Add continuous entry. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousHandler.java index 48fcd8b3d2763..9801746b14d67 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousHandler.java @@ -99,6 +99,11 @@ public enum RegisterStatus { */ public GridContinuousBatch createBatch(); + /** + * Client node disconnected callback. + */ + public void onClientDisconnected(); + /** * Called when ack for a batch is received from client. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java index c0c3989e2bc78..eaa07bd48e1b2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java @@ -913,6 +913,9 @@ public void addNotification(UUID nodeId, unregisterRemote(e.getKey()); } + for (LocalRoutineInfo routine : locInfos.values()) + routine.hnd.onClientDisconnected(); + rmtInfos.clear(); clientInfos.clear(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/ClientReconnectContinuousQueryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/ClientReconnectContinuousQueryTest.java new file mode 100644 index 0000000000000..feded1462d8f8 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/ClientReconnectContinuousQueryTest.java @@ -0,0 +1,201 @@ +/* + * 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.query.continuous; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import javax.cache.event.CacheEntryListenerException; +import javax.cache.event.CacheEntryUpdatedListener; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.query.ContinuousQuery; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.events.Event; +import org.apache.ignite.events.EventType; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.managers.communication.GridIoManager; +import org.apache.ignite.internal.util.nio.GridNioServer; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class ClientReconnectContinuousQueryTest extends GridCommonAbstractTest { + /** Client index. */ + private static final int CLIENT_IDX = 1; + + /** Puts before reconnect. */ + private static final int PUTS_BEFORE_RECONNECT = 50; + + /** Puts after reconnect. */ + private static final int PUTS_AFTER_RECONNECT = 50; + + /** Recon latch. */ + private static final CountDownLatch reconLatch = new CountDownLatch(1); + + /** Discon latch. */ + private static final CountDownLatch disconLatch = new CountDownLatch(1); + + /** Updater received. */ + private static final CountDownLatch updaterReceived = new CountDownLatch(PUTS_BEFORE_RECONNECT); + + /** Receiver after reconnect. */ + private static final CountDownLatch receiverAfterReconnect = new CountDownLatch(PUTS_AFTER_RECONNECT); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + TcpCommunicationSpi commSpi = (TcpCommunicationSpi)cfg.getCommunicationSpi(); + + commSpi.setSlowClientQueueLimit(50); + commSpi.setIdleConnectionTimeout(300_000); + + if (getTestGridName(CLIENT_IDX).equals(gridName)) + cfg.setClientMode(true); + else { + CacheConfiguration ccfg = defaultCacheConfiguration(); + + cfg.setCacheConfiguration(ccfg); + } + + return cfg; + } + + /** + * Test client reconnect to alive grid. + * + * @throws Exception If failed. + */ + public void testClientReconnect() throws Exception { + try { + startGrids(2); + + IgniteEx client = grid(CLIENT_IDX); + + client.events().localListen(new DisconnectListener(), EventType.EVT_CLIENT_NODE_DISCONNECTED); + + client.events().localListen(new ReconnectListener(), EventType.EVT_CLIENT_NODE_RECONNECTED); + + IgniteCache cache = client.cache(null); + + ContinuousQuery qry = new ContinuousQuery(); + + qry.setLocalListener(new CQListener()); + + cache.query(qry); + + putSomeKeys(PUTS_BEFORE_RECONNECT); + + info("updaterReceived Count: " + updaterReceived.getCount()); + + assertTrue(updaterReceived.await(10_000, TimeUnit.MILLISECONDS)); + + skipRead(client, true); + + putSomeKeys(1_000); + + assertTrue(disconLatch.await(10_000, TimeUnit.MILLISECONDS)); + + skipRead(client, false); + + assertTrue(reconLatch.await(10_000, TimeUnit.MILLISECONDS)); + + putSomeKeys(PUTS_AFTER_RECONNECT); + + info("receiverAfterReconnect Count: " + receiverAfterReconnect.getCount()); + + assertTrue(receiverAfterReconnect.await(10_000, TimeUnit.MILLISECONDS)); + } + finally { + stopAllGrids(); + } + + } + + /** + * + */ + private static class ReconnectListener implements IgnitePredicate { + /** {@inheritDoc} */ + @Override public boolean apply(Event evt) { + reconLatch.countDown(); + + return false; + } + } + + /** + * + */ + private static class DisconnectListener implements IgnitePredicate { + /** {@inheritDoc} */ + @Override public boolean apply(Event evt) { + disconLatch.countDown(); + + return false; + } + } + + /** + * + */ + private static class CQListener implements CacheEntryUpdatedListener { + /** {@inheritDoc} */ + @Override public void onUpdated(Iterable iterable) throws CacheEntryListenerException { + if (reconLatch.getCount() != 0) { + for (Object o : iterable) + updaterReceived.countDown(); + } + else { + for (Object o : iterable) + receiverAfterReconnect.countDown(); + } + } + } + + /** + * @param cnt Number of keys. + */ + private void putSomeKeys(int cnt) { + IgniteEx ignite = grid(0); + + IgniteCache srvCache = ignite.cache(null); + + for (int i = 0; i < cnt; i++) + srvCache.put(0, i); + } + + /** + * @param igniteClient Ignite client. + * @param skip Skip. + */ + private void skipRead(IgniteEx igniteClient, boolean skip) { + GridIoManager ioMgr = igniteClient.context().io(); + + TcpCommunicationSpi commSpi = (TcpCommunicationSpi)((Object[])U.field(ioMgr, "spis"))[0]; + + GridNioServer nioSrvr = U.field(commSpi, "nioSrvr"); + + GridTestUtils.setFieldValue(nioSrvr, "skipRead", skip); + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java index 4eaaab892c028..3c1f9716e2c01 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java @@ -33,6 +33,7 @@ import org.apache.ignite.internal.processors.cache.query.continuous.CacheKeepBinaryIterationNearEnabledTest; import org.apache.ignite.internal.processors.cache.query.continuous.CacheKeepBinaryIterationTest; import org.apache.ignite.internal.processors.cache.query.continuous.CacheKeepBinaryIterationStoreEnabledTest; +import org.apache.ignite.internal.processors.cache.query.continuous.ClientReconnectContinuousQueryTest; import org.apache.ignite.internal.processors.cache.query.continuous.ContinuousQueryRemoteFilterMissingInClassPathSelfTest; import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicNearEnabledSelfTest; import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicOffheapTieredTest; @@ -121,6 +122,7 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(CacheKeepBinaryIterationNearEnabledTest.class); suite.addTestSuite(IgniteCacheContinuousQueryBackupQueueTest.class); suite.addTestSuite(IgniteCacheContinuousQueryNoUnsubscribeTest.class); + suite.addTestSuite(ClientReconnectContinuousQueryTest.class); suite.addTest(IgniteDistributedJoinTestSuite.suite()); From 63e6a2189814fb0b3c6b808f02fe2de81c19a5b0 Mon Sep 17 00:00:00 2001 From: Vasiliy Sisko Date: Wed, 15 Feb 2017 11:08:23 +0700 Subject: [PATCH 060/311] Minor fix: missing toString() method. (cherry picked from commit 571586c) --- .../ignite/internal/visor/cache/VisorCacheTypeMetadata.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheTypeMetadata.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheTypeMetadata.java index f17e5889663fc..c87ad05d824e6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheTypeMetadata.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheTypeMetadata.java @@ -32,6 +32,7 @@ import org.apache.ignite.cache.store.jdbc.JdbcTypeField; import org.apache.ignite.internal.LessNamingBean; import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiTuple; @@ -372,4 +373,9 @@ public Collection txtFlds() { public Map>> grps() { return grps; } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(VisorCacheTypeMetadata.class, this); + } } From 92821167ad884266728a2fae83799d1dfa17e07d Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Wed, 15 Feb 2017 21:11:30 +0300 Subject: [PATCH 061/311] GG-11860 Implement snapshot status on platform level -refactoring: extracting snapshot operation --- .../pagemem/snapshot/SnapshotOperation.java | 100 ++++++++++++++++++ .../snapshot/SnapshotOperationType.java | 30 ++++++ .../StartFullSnapshotAckDiscoveryMessage.java | 64 ++--------- .../StartFullSnapshotDiscoveryMessage.java | 70 ++++-------- 4 files changed, 157 insertions(+), 107 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java new file mode 100644 index 0000000000000..81630494ba709 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -0,0 +1,100 @@ +/* + * 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.pagemem.snapshot; + +import java.io.Serializable; +import java.util.Set; + +/** + * Description and parameters of snapshot operation + */ +public class SnapshotOperation implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final SnapshotOperationType type; + + /** + * Snapshot ID (the timestamp of snapshot creation). + */ + private final long snapshotId; + + /** */ + private final Set cacheNames; + + /** Message. */ + private final String msg; + + /** Additional parameter. */ + private final Object extraParam; + + /** + * @param type Type. + * @param snapshotId Snapshot id. + * @param cacheNames Cache names. + * @param msg + * @param extraParam Additional parameter. + */ + public SnapshotOperation(SnapshotOperationType type, long snapshotId, Set cacheNames, String msg, Object extraParam) { + this.type = type; + this.snapshotId = snapshotId; + this.cacheNames = cacheNames; + this.msg = msg; + this.extraParam = extraParam; + } + + /** + * + */ + public SnapshotOperationType type() { + return type; + } + + /** + * Snapshot ID (the timestamp of snapshot creation). + * + * @return Snapshot ID. + */ + public long id() { + return snapshotId; + } + + /** + * Cache names included to this snapshot. + * + * @return Cache names. + */ + public Set cacheNames() { + return cacheNames; + } + + /** + * Additional info which was provided by client + */ + public String message() { + return msg; + } + + /** + * + */ + public Object extraParameter() { + return extraParam; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java new file mode 100644 index 0000000000000..8866bdbf57519 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java @@ -0,0 +1,30 @@ +/* + * 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.pagemem.snapshot; + +/** */ +public enum SnapshotOperationType { + /** Create. */ + CREATE, + /** Restore. */ + RESTORE, + /** Move. */ + MOVE, + /** Delete. */ + DELETE +} \ No newline at end of file diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java index 08082de4ce253..32a3dae4ad3f8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java @@ -35,27 +35,18 @@ public class StartFullSnapshotAckDiscoveryMessage implements DiscoveryCustomMess /** */ private static final long serialVersionUID = 0L; - /** Message. */ - private final String msg; + + private SnapshotOperation snapshotOperation; /** Custom message ID. */ private IgniteUuid id = IgniteUuid.randomUuid(); - /** */ - private long globalSnapshotId; - /** */ private Exception err; - /** */ - private Collection cacheNames; - /** */ private UUID initiatorNodeId; - /** Full snapshot. */ - private boolean fullSnapshot; - /** Last full snapshot id for cache. */ private Map lastFullSnapshotIdForCache; @@ -63,43 +54,21 @@ public class StartFullSnapshotAckDiscoveryMessage implements DiscoveryCustomMess private Map lastSnapshotIdForCache; /** - * @param globalSnapshotId Snapshot ID. + * @param snapshotOperation Snapshot Operation. * @param err Error. - * @param cacheNames Cache names. */ public StartFullSnapshotAckDiscoveryMessage( - long globalSnapshotId, - boolean fullSnapshot, + SnapshotOperation snapshotOperation, Map lastFullSnapshotIdForCache, Map lastSnapshotIdForCache, - Collection cacheNames, Exception err, - UUID initiatorNodeId, - String msg + UUID initiatorNodeId ) { - this.globalSnapshotId = globalSnapshotId; - this.fullSnapshot = fullSnapshot; + this.snapshotOperation = snapshotOperation; this.lastFullSnapshotIdForCache = lastFullSnapshotIdForCache; this.lastSnapshotIdForCache = lastSnapshotIdForCache; this.err = err; - this.cacheNames = cacheNames; this.initiatorNodeId = initiatorNodeId; - this.msg = msg; - - for (String cacheName : cacheNames) { - int i = CU.cacheId(cacheName); - - if (lastFullSnapshotIdForCache.get(i) == null || lastSnapshotIdForCache.get(i) == null) { - throw new AssertionError(); - } - } - } - - /** - * @return Cache names. - */ - public Collection cacheNames() { - return cacheNames; } /** {@inheritDoc} */ @@ -128,25 +97,8 @@ public boolean hasError() { return err != null; } - /** - * @return Snapshot ID. - */ - public long globalSnapshotId() { - return globalSnapshotId; - } - - /** - * - */ - public boolean fullSnapshot() { - return fullSnapshot; - } - - /** - * - */ - public String message() { - return msg; + public SnapshotOperation snapshotOperation() { + return snapshotOperation; } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java index bd6d97f5f3330..2a977f4f1eccf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java @@ -35,17 +35,11 @@ public class StartFullSnapshotDiscoveryMessage implements DiscoveryCustomMessage /** */ private static final long serialVersionUID = 0L; - /** Message. */ - private final String msg; - /** Custom message ID. */ private IgniteUuid id = IgniteUuid.randomUuid(); - /** Snapshot ID. */ - private long globalSnapshotId; - - /** */ - private Collection cacheNames; + /** Snapshot operation. */ + private SnapshotOperation snapshotOperation; /** */ private UUID initiatorId; @@ -53,9 +47,6 @@ public class StartFullSnapshotDiscoveryMessage implements DiscoveryCustomMessage /** Error. */ private Exception err; - /** Full snapshot. */ - private boolean fullSnapshot; - /** Last full snapshot id for cache. */ private Map lastFullSnapshotIdForCache = new HashMap<>(); @@ -63,21 +54,22 @@ public class StartFullSnapshotDiscoveryMessage implements DiscoveryCustomMessage private Map lastSnapshotIdForCache = new HashMap<>(); /** - * @param cacheNames Cache names. - * @param msg message to log + * @param snapshotOperation Snapshot operation + * @param initiatorId initiator node id */ public StartFullSnapshotDiscoveryMessage( - long globalSnapshotId, - Collection cacheNames, - UUID initiatorId, - boolean fullSnapshot, - String msg + SnapshotOperation snapshotOperation, + UUID initiatorId ) { - this.globalSnapshotId = globalSnapshotId; - this.cacheNames = cacheNames; + this.snapshotOperation = snapshotOperation; this.initiatorId = initiatorId; - this.fullSnapshot = fullSnapshot; - this.msg = msg; + } + + /** + * + */ + public SnapshotOperation snapshotOperation() { + return snapshotOperation; } /** @@ -115,27 +107,6 @@ public UUID initiatorId() { return id; } - /** - * @return Backup ID. - */ - public long globalSnapshotId() { - return globalSnapshotId; - } - - /** - * @return Cache names. - */ - public Collection cacheNames() { - return cacheNames; - } - - /** - * - */ - public boolean fullSnapshot() { - return fullSnapshot; - } - /** * @param cacheId Cache id. */ @@ -169,14 +140,11 @@ public void lastSnapshotId(int cacheId, long id) { /** {@inheritDoc} */ @Nullable @Override public DiscoveryCustomMessage ackMessage() { return new StartFullSnapshotAckDiscoveryMessage( - globalSnapshotId, - fullSnapshot, + snapshotOperation, lastFullSnapshotIdForCache, lastSnapshotIdForCache, - cacheNames, err, - initiatorId, - msg); + initiatorId); } /** {@inheritDoc} */ @@ -185,10 +153,10 @@ public void lastSnapshotId(int cacheId, long id) { } /** - * @param full full snapshot. + * @param snapshotOperation new snapshot operation */ - public void fullSnapshot(boolean full) { - fullSnapshot = full; + public void snapshotOperation(SnapshotOperation snapshotOperation) { + this.snapshotOperation = snapshotOperation; } /** {@inheritDoc} */ From e14cab15f647acc20f45f97ec98c2c27a8c56b2e Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Thu, 16 Feb 2017 21:04:36 +0300 Subject: [PATCH 062/311] GG-11860 Implement snapshot status on platform level -refactoring deleteSnapshot operation --- .../snapshot/SnapshotFinishedMessage.java | 32 ++++++++++++++++--- .../pagemem/snapshot/SnapshotOperation.java | 31 ++++++++++++++++++ .../StartFullSnapshotDiscoveryMessage.java | 4 +-- ...SnapshotOperationAckDiscoveryMessage.java} | 9 ++---- .../GridCachePartitionExchangeManager.java | 10 ++---- .../processors/cache/GridCacheProcessor.java | 6 ++-- .../IgniteCacheDatabaseSharedManager.java | 13 ++------ .../GridDhtPartitionsExchangeFuture.java | 12 +++---- .../resources/META-INF/classnames.properties | 2 +- 9 files changed, 77 insertions(+), 42 deletions(-) rename modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/{StartFullSnapshotAckDiscoveryMessage.java => StartSnapshotOperationAckDiscoveryMessage.java} (90%) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotFinishedMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotFinishedMessage.java index a62d3394c8a5b..8ccef4234f742 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotFinishedMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotFinishedMessage.java @@ -33,20 +33,22 @@ public class SnapshotFinishedMessage implements Message { /** */ private long snapshotId; + /** Operation type. */ + private int operationType; + /** */ private boolean success; - /** - * - */ + /** */ public SnapshotFinishedMessage() { } /** * @param snapshotId Snapshot ID. */ - public SnapshotFinishedMessage(long snapshotId, boolean success) { + public SnapshotFinishedMessage(long snapshotId, SnapshotOperationType type, boolean success) { this.snapshotId = snapshotId; + this.operationType = type.ordinal(); this.success = success; } @@ -57,6 +59,12 @@ public long snapshotId() { return snapshotId; } + /** */ + public SnapshotOperationType operationType() { + return SnapshotOperationType.values()[operationType]; + } + + /** */ public boolean success() { return success; } @@ -80,6 +88,12 @@ public boolean success() { writer.incrementState(); case 1: + if (!writer.writeInt("operationType", operationType)) + return false; + + writer.incrementState(); + + case 2: if (!writer.writeBoolean("success", success)) return false; @@ -107,6 +121,14 @@ public boolean success() { reader.incrementState(); case 1: + operationType = reader.readInt("operationType"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 2: success = reader.readBoolean("success"); if (!reader.isLastRead()) @@ -126,7 +148,7 @@ public boolean success() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 2; + return 3; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index 81630494ba709..221d0ce55782c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -97,4 +97,35 @@ public String message() { public Object extraParameter() { return extraParam; } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + SnapshotOperation operation = (SnapshotOperation)o; + + if (snapshotId != operation.snapshotId) + return false; + if (type != operation.type) + return false; + if (cacheNames != null ? !cacheNames.equals(operation.cacheNames) : operation.cacheNames != null) + return false; + if (msg != null ? !msg.equals(operation.msg) : operation.msg != null) + return false; + return extraParam != null ? extraParam.equals(operation.extraParam) : operation.extraParam == null; + + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int result = type != null ? type.hashCode() : 0; + result = 31 * result + (int)(snapshotId ^ (snapshotId >>> 32)); + result = 31 * result + (cacheNames != null ? cacheNames.hashCode() : 0); + result = 31 * result + (msg != null ? msg.hashCode() : 0); + result = 31 * result + (extraParam != null ? extraParam.hashCode() : 0); + return result; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java index 2a977f4f1eccf..3a67e493d0f80 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java @@ -18,13 +18,11 @@ package org.apache.ignite.internal.pagemem.snapshot; -import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.UUID; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; @@ -139,7 +137,7 @@ public void lastSnapshotId(int cacheId, long id) { /** {@inheritDoc} */ @Nullable @Override public DiscoveryCustomMessage ackMessage() { - return new StartFullSnapshotAckDiscoveryMessage( + return new StartSnapshotOperationAckDiscoveryMessage( snapshotOperation, lastFullSnapshotIdForCache, lastSnapshotIdForCache, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationAckDiscoveryMessage.java similarity index 90% rename from modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java rename to modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationAckDiscoveryMessage.java index 32a3dae4ad3f8..e84b2e807340d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotAckDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationAckDiscoveryMessage.java @@ -18,20 +18,17 @@ package org.apache.ignite.internal.pagemem.snapshot; -import java.util.Collection; import java.util.Map; import java.util.UUID; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; /** * Message indicating that a snapshot has been started. */ -public class StartFullSnapshotAckDiscoveryMessage implements DiscoveryCustomMessage { +public class StartSnapshotOperationAckDiscoveryMessage implements DiscoveryCustomMessage { /** */ private static final long serialVersionUID = 0L; @@ -57,7 +54,7 @@ public class StartFullSnapshotAckDiscoveryMessage implements DiscoveryCustomMess * @param snapshotOperation Snapshot Operation. * @param err Error. */ - public StartFullSnapshotAckDiscoveryMessage( + public StartSnapshotOperationAckDiscoveryMessage( SnapshotOperation snapshotOperation, Map lastFullSnapshotIdForCache, Map lastSnapshotIdForCache, @@ -127,6 +124,6 @@ public SnapshotOperation snapshotOperation() { /** {@inheritDoc} */ @Override public String toString() { - return S.toString(StartFullSnapshotAckDiscoveryMessage.class, this); + return S.toString(StartSnapshotOperationAckDiscoveryMessage.class, this); } } 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 46a20abe55358..232dc83a7d58e 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 @@ -30,11 +30,9 @@ import java.util.List; import java.util.Map; import java.util.NavigableMap; -import java.util.Queue; import java.util.TreeMap; import java.util.UUID; import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.LinkedBlockingDeque; @@ -58,7 +56,7 @@ import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.events.DiscoveryCustomEvent; import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener; -import org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage; +import org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; import org.apache.ignite.internal.processors.cache.distributed.dht.GridClientPartitionTopology; @@ -70,7 +68,6 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap2; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessageV2; -import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage; 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.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage; @@ -100,7 +97,6 @@ import org.apache.ignite.thread.IgniteThread; import org.jetbrains.annotations.Nullable; import org.jsr166.ConcurrentHashMap8; -import org.jsr166.ConcurrentLinkedDeque8; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.apache.ignite.IgniteSystemProperties.IGNITE_PRELOAD_RESEND_TIMEOUT; @@ -280,8 +276,8 @@ else if (customEvt.customMessage() instanceof CacheAffinityChangeMessage) { else exchangeFuture(msg.exchangeId(), null, null, null).onAffinityChangeMessage(customEvt.eventNode(), msg); } - else if (customEvt.customMessage() instanceof StartFullSnapshotAckDiscoveryMessage - && !((StartFullSnapshotAckDiscoveryMessage)customEvt.customMessage()).hasError()) { + else if (customEvt.customMessage() instanceof StartSnapshotOperationAckDiscoveryMessage + && !((StartSnapshotOperationAckDiscoveryMessage)customEvt.customMessage()).hasError()) { exchId = exchangeId(n.id(), affinityTopologyVersion(e), e.type()); exchFut = exchangeFuture(exchId, e, null, null); 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 74b6782f3d2cd..2bb1e42943649 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 @@ -72,7 +72,7 @@ import org.apache.ignite.internal.binary.BinaryMarshaller; import org.apache.ignite.internal.binary.GridBinaryMarshaller; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; -import org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage; +import org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage; import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; import org.apache.ignite.internal.processors.GridProcessorAdapter; @@ -2893,8 +2893,8 @@ public boolean onCustomEvent( if (msg instanceof CacheAffinityChangeMessage) return sharedCtx.affinity().onCustomEvent(((CacheAffinityChangeMessage)msg)); - if (msg instanceof StartFullSnapshotAckDiscoveryMessage && - ((StartFullSnapshotAckDiscoveryMessage)msg).error() == null) + if (msg instanceof StartSnapshotOperationAckDiscoveryMessage && + ((StartSnapshotOperationAckDiscoveryMessage)msg).error() == null) return true; if (msg instanceof DynamicCacheChangeBatch) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 7a082cb0c8b77..a5fdeefb7b5b3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -19,9 +19,7 @@ import java.io.File; import java.util.Collection; -import java.util.UUID; import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteInternalFuture; @@ -29,7 +27,7 @@ import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider; import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage; +import org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage; import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; @@ -178,13 +176,6 @@ public void waitForCheckpoint(String reason) throws IgniteCheckedException { // No-op } - /** - * - */ - @Nullable public IgniteInternalFuture wakeupForSnapshot(long snapshotId) { - return null; - } - /** * @param discoEvt Before exchange for the given discovery event. */ @@ -211,7 +202,7 @@ public void onCacheStop(GridCacheContext cctx) { * @return Snapshot creation init future or {@code null} if snapshot is not available. * @throws IgniteCheckedException If failed. */ - @Nullable public IgniteInternalFuture startLocalSnapshotCreation(StartFullSnapshotAckDiscoveryMessage snapshotMsg) + @Nullable public IgniteInternalFuture startLocalSnapshotOperation(StartSnapshotOperationAckDiscoveryMessage snapshotMsg) throws IgniteCheckedException { return null; } 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 2f9fc46630597..987ba5453f909 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 @@ -48,7 +48,7 @@ import org.apache.ignite.internal.events.DiscoveryCustomEvent; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; import org.apache.ignite.internal.managers.discovery.GridDiscoveryTopologySnapshot; -import org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage; +import org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; import org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage; @@ -510,7 +510,7 @@ public void init() throws IgniteInterruptedCheckedException { exchange = onCacheChangeRequest(crdNode); } - else if (msg instanceof StartFullSnapshotAckDiscoveryMessage) + else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) exchange = CU.clientNode(discoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode); @@ -808,13 +808,13 @@ private void distributedExchange() throws IgniteCheckedException { // If a backup request, synchronously wait for backup start. if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) { - DiscoveryCustomMessage customMessage = ((DiscoveryCustomEvent)discoEvt).customMessage(); + DiscoveryCustomMessage customMsg = ((DiscoveryCustomEvent)discoEvt).customMessage(); - if (customMessage instanceof StartFullSnapshotAckDiscoveryMessage) { - StartFullSnapshotAckDiscoveryMessage backupMsg = (StartFullSnapshotAckDiscoveryMessage)customMessage; + if (customMsg instanceof StartSnapshotOperationAckDiscoveryMessage) { + StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg = (StartSnapshotOperationAckDiscoveryMessage)customMsg; if (!cctx.localNode().isClient() && !cctx.localNode().isDaemon()) { - IgniteInternalFuture fut = cctx.database().startLocalSnapshotCreation(backupMsg); + IgniteInternalFuture fut = cctx.database().startLocalSnapshotOperation(snapshotOperationMsg); if (fut != null) fut.get(); diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index 98d0da9c5c0b0..a0838b19e1e50 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -328,7 +328,7 @@ org.apache.ignite.internal.mem.OutOfMemoryException org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl$Segment org.apache.ignite.internal.pagemem.snapshot.SnapshotFinishedMessage org.apache.ignite.internal.pagemem.snapshot.SnapshotProgressMessage -org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage +org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotDiscoveryMessage org.apache.ignite.internal.pagemem.wal.StorageException org.apache.ignite.internal.pagemem.wal.WALIterator From 5ad1933b018583ee7749677aaa39dc5718ae1e36 Mon Sep 17 00:00:00 2001 From: sboikov Date: Thu, 16 Feb 2017 18:34:02 +0300 Subject: [PATCH 063/311] ignite-4710 More information in IgniteTxOptimisticCheckedException message. (cherry picked from commit 7f74458) --- .../dht/GridDhtTxPrepareFuture.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java index d11e3da9ad6b2..a17b782af2674 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java @@ -1142,11 +1142,40 @@ private IgniteInternalFuture forceRebalanceKeys(Map"); + } + + try { + GridCacheEntryEx entryEx = entry.cached(); + + CacheObject cacheVal = entryEx != null ? entryEx.rawGet() : null; + + Object val = cacheVal != null ? cctx.unwrapBinaryIfNeeded(cacheVal, entry.keepBinary(), false) : null; + + if (val != null) + msg.append(", val=").append(val.toString()).append(", valCls=").append(val.getClass().getName()); + else + msg.append(", val=null"); + } + catch (Exception e) { + msg.append(", val="); + } + + msg.append(", cache=").append(cctx.name()).append(", thread=").append(Thread.currentThread()).append("]"); + + return new IgniteTxOptimisticCheckedException(msg.toString()); } /** From 4f859170d7eebaec47470fb3ff4286936e4dac9a Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Fri, 17 Feb 2017 18:39:32 +0300 Subject: [PATCH 064/311] GG-11860 Implement snapshot status on platform level -refactoring moveSnapshot operation --- .../communication/GridIoMessageFactory.java | 4 +-- ... => SnapshotOperationFinishedMessage.java} | 33 ++++++++++++++++--- .../resources/META-INF/classnames.properties | 2 +- 3 files changed, 31 insertions(+), 8 deletions(-) rename modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/{SnapshotFinishedMessage.java => SnapshotOperationFinishedMessage.java} (81%) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java index 979e8db9d9443..15749090c8895 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java @@ -33,7 +33,7 @@ import org.apache.ignite.internal.managers.deployment.GridDeploymentRequest; import org.apache.ignite.internal.managers.deployment.GridDeploymentResponse; import org.apache.ignite.internal.managers.eventstorage.GridEventStorageMessage; -import org.apache.ignite.internal.pagemem.snapshot.SnapshotFinishedMessage; +import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationFinishedMessage; import org.apache.ignite.internal.pagemem.snapshot.SnapshotProgressMessage; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse; @@ -186,7 +186,7 @@ public GridIoMessageFactory(MessageFactory[] ext) { break; case -45: - msg = new SnapshotFinishedMessage(); + msg = new SnapshotOperationFinishedMessage(); break; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotFinishedMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationFinishedMessage.java similarity index 81% rename from modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotFinishedMessage.java rename to modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationFinishedMessage.java index 8ccef4234f742..8986e5cdc457c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotFinishedMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationFinishedMessage.java @@ -26,7 +26,7 @@ /** * Message indicating that snapshot has been finished on a single node. */ -public class SnapshotFinishedMessage implements Message { +public class SnapshotOperationFinishedMessage implements Message { /** */ private static final long serialVersionUID = 0L; @@ -39,17 +39,22 @@ public class SnapshotFinishedMessage implements Message { /** */ private boolean success; + /** Error message. */ + private String errorMsg; + /** */ - public SnapshotFinishedMessage() { + public SnapshotOperationFinishedMessage() { } /** * @param snapshotId Snapshot ID. + * @param errorMsg */ - public SnapshotFinishedMessage(long snapshotId, SnapshotOperationType type, boolean success) { + public SnapshotOperationFinishedMessage(long snapshotId, SnapshotOperationType type, boolean success, String errorMsg) { this.snapshotId = snapshotId; this.operationType = type.ordinal(); this.success = success; + this.errorMsg = errorMsg; } /** @@ -69,6 +74,11 @@ public boolean success() { return success; } + /** */ + public String errorMessage() { + return errorMsg; + } + /** {@inheritDoc} */ @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) { writer.setBuffer(buf); @@ -99,6 +109,12 @@ public boolean success() { writer.incrementState(); + case 3: + if (!writer.writeString("errorMsg", errorMsg)) + return false; + + writer.incrementState(); + } return true; @@ -136,9 +152,16 @@ public boolean success() { reader.incrementState(); + case 3: + errorMsg = reader.readString("errorMsg"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); } - return reader.afterMessageRead(SnapshotFinishedMessage.class); + return reader.afterMessageRead(SnapshotOperationFinishedMessage.class); } /** {@inheritDoc} */ @@ -148,7 +171,7 @@ public boolean success() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 3; + return 4; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index a0838b19e1e50..13a3bcef10916 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -326,7 +326,7 @@ org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerAdapter org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerManager$1 org.apache.ignite.internal.mem.OutOfMemoryException org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl$Segment -org.apache.ignite.internal.pagemem.snapshot.SnapshotFinishedMessage +org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationFinishedMessage org.apache.ignite.internal.pagemem.snapshot.SnapshotProgressMessage org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotDiscoveryMessage From 0384b66252d331f8a0406eecbaeec5ba6f12ed2c Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Fri, 17 Feb 2017 20:10:50 +0300 Subject: [PATCH 065/311] GG-11860 Implement snapshot status on platform level -fix tests with node filters --- .../internal/pagemem/snapshot/SnapshotOperation.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index 221d0ce55782c..3e13f95ed16df 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -98,7 +98,6 @@ public Object extraParameter() { return extraParam; } - /** {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -111,19 +110,15 @@ public Object extraParameter() { return false; if (type != operation.type) return false; - if (cacheNames != null ? !cacheNames.equals(operation.cacheNames) : operation.cacheNames != null) - return false; if (msg != null ? !msg.equals(operation.msg) : operation.msg != null) return false; return extraParam != null ? extraParam.equals(operation.extraParam) : operation.extraParam == null; } - /** {@inheritDoc} */ @Override public int hashCode() { - int result = type != null ? type.hashCode() : 0; + int result = type.hashCode(); result = 31 * result + (int)(snapshotId ^ (snapshotId >>> 32)); - result = 31 * result + (cacheNames != null ? cacheNames.hashCode() : 0); result = 31 * result + (msg != null ? msg.hashCode() : 0); result = 31 * result + (extraParam != null ? extraParam.hashCode() : 0); return result; From 4c97f43be8b608f20f2a5a3d40280233cffd46e8 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Tue, 21 Feb 2017 16:03:05 +0300 Subject: [PATCH 066/311] GG-11860 Implement snapshot status on platform level -refactoring (moving messages, new mechanism of registration, etc.) --- .../communication/GridIoMessageFactory.java | 15 +- .../pagemem/snapshot/SnapshotOperation.java | 30 +++ .../SnapshotOperationFinishedMessage.java | 181 ------------------ .../snapshot/SnapshotOperationType.java | 4 +- .../snapshot/SnapshotProgressMessage.java | 135 ------------- .../GridChangeGlobalStateMessageResponse.java | 2 +- 6 files changed, 36 insertions(+), 331 deletions(-) delete mode 100644 modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationFinishedMessage.java delete mode 100644 modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotProgressMessage.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java index 15749090c8895..6f73682067e74 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java @@ -33,8 +33,6 @@ import org.apache.ignite.internal.managers.deployment.GridDeploymentRequest; import org.apache.ignite.internal.managers.deployment.GridDeploymentResponse; import org.apache.ignite.internal.managers.eventstorage.GridEventStorageMessage; -import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationFinishedMessage; -import org.apache.ignite.internal.pagemem.snapshot.SnapshotProgressMessage; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse; import org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection; @@ -174,19 +172,9 @@ public GridIoMessageFactory(MessageFactory[] ext) { Message msg = null; switch (type) { - case -47: - msg = new SnapshotProgressMessage(); - - break; - - - case -46: - msg = new GridChangeGlobalStateMessageResponse(); - - break; case -45: - msg = new SnapshotOperationFinishedMessage(); + msg = new GridChangeGlobalStateMessageResponse(); break; @@ -848,6 +836,7 @@ public GridIoMessageFactory(MessageFactory[] ext) { // [-3..119] [124..127] [-23..-27] [-36..-47]- this // [120..123] - DR // [-4..-22, -30..-35] - SQL + // [-46..-50] - Snapshots default: if (ext != null) { for (MessageFactory factory : ext) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index 3e13f95ed16df..3f84b97539dcd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -17,7 +17,9 @@ */ package org.apache.ignite.internal.pagemem.snapshot; +import java.io.File; import java.io.Serializable; +import java.util.Collection; import java.util.Set; /** @@ -98,6 +100,34 @@ public Object extraParameter() { return extraParam; } + + /** + * @param op Op. + */ + public static Collection getOptionalPathsParameter(SnapshotOperation op) { + assert op.type() == SnapshotOperationType.CHECK || op.extraParameter() instanceof Collection; + + return (Collection)op.extraParameter(); + } + + /** + * @param op Op. + */ + public static Boolean getFullSnapshotParameter(SnapshotOperation op) { + assert op.type() == SnapshotOperationType.CREATE && op.extraParameter() instanceof Boolean; + + return (Boolean)op.extraParameter(); + } + + /** + * @param op Op. + */ + public static File getMovingPathParameter(SnapshotOperation op) { + assert op.type() == SnapshotOperationType.MOVE && op.extraParameter() instanceof File; + + return (File)op.extraParameter(); + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationFinishedMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationFinishedMessage.java deleted file mode 100644 index 8986e5cdc457c..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationFinishedMessage.java +++ /dev/null @@ -1,181 +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.pagemem.snapshot; - -import java.nio.ByteBuffer; -import org.apache.ignite.plugin.extensions.communication.Message; -import org.apache.ignite.plugin.extensions.communication.MessageReader; -import org.apache.ignite.plugin.extensions.communication.MessageWriter; - -/** - * Message indicating that snapshot has been finished on a single node. - */ -public class SnapshotOperationFinishedMessage implements Message { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private long snapshotId; - - /** Operation type. */ - private int operationType; - - /** */ - private boolean success; - - /** Error message. */ - private String errorMsg; - - /** */ - public SnapshotOperationFinishedMessage() { - } - - /** - * @param snapshotId Snapshot ID. - * @param errorMsg - */ - public SnapshotOperationFinishedMessage(long snapshotId, SnapshotOperationType type, boolean success, String errorMsg) { - this.snapshotId = snapshotId; - this.operationType = type.ordinal(); - this.success = success; - this.errorMsg = errorMsg; - } - - /** - * @return Snapshot ID. - */ - public long snapshotId() { - return snapshotId; - } - - /** */ - public SnapshotOperationType operationType() { - return SnapshotOperationType.values()[operationType]; - } - - /** */ - public boolean success() { - return success; - } - - /** */ - public String errorMessage() { - return errorMsg; - } - - /** {@inheritDoc} */ - @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) { - writer.setBuffer(buf); - - if (!writer.isHeaderWritten()) { - if (!writer.writeHeader(directType(), fieldsCount())) - return false; - - writer.onHeaderWritten(); - } - - switch (writer.state()) { - case 0: - if (!writer.writeLong("snapshotId", snapshotId)) - return false; - - writer.incrementState(); - - case 1: - if (!writer.writeInt("operationType", operationType)) - return false; - - writer.incrementState(); - - case 2: - if (!writer.writeBoolean("success", success)) - return false; - - writer.incrementState(); - - case 3: - if (!writer.writeString("errorMsg", errorMsg)) - return false; - - writer.incrementState(); - - } - - return true; - } - - /** {@inheritDoc} */ - @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) { - reader.setBuffer(buf); - - if (!reader.beforeMessageRead()) - return false; - - switch (reader.state()) { - case 0: - snapshotId = reader.readLong("snapshotId"); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - case 1: - operationType = reader.readInt("operationType"); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - case 2: - success = reader.readBoolean("success"); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - case 3: - errorMsg = reader.readString("errorMsg"); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - } - - return reader.afterMessageRead(SnapshotOperationFinishedMessage.class); - } - - /** {@inheritDoc} */ - @Override public byte directType() { - return -45; - } - - /** {@inheritDoc} */ - @Override public byte fieldsCount() { - return 4; - } - - /** {@inheritDoc} */ - @Override public void onAckReceived() { - // No-op - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java index 8866bdbf57519..3fa6d2a0e32a1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java @@ -26,5 +26,7 @@ public enum SnapshotOperationType { /** Move. */ MOVE, /** Delete. */ - DELETE + DELETE, + /** Check. */ + CHECK } \ No newline at end of file diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotProgressMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotProgressMessage.java deleted file mode 100644 index 70ea6a9ac3285..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotProgressMessage.java +++ /dev/null @@ -1,135 +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.pagemem.snapshot; - -import java.nio.ByteBuffer; -import org.apache.ignite.plugin.extensions.communication.Message; -import org.apache.ignite.plugin.extensions.communication.MessageReader; -import org.apache.ignite.plugin.extensions.communication.MessageWriter; - -/** - * Message for exchange of snapshot creation/restoration progress between nodes. - */ -public class SnapshotProgressMessage implements Message { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private long snapshotId; - - /** */ - private double progress; - - /** */ - public SnapshotProgressMessage() { - } - - /** */ - public SnapshotProgressMessage(long snapshotId, double progress) { - this.snapshotId = snapshotId; - this.progress = progress; - } - - /** - * @return Snapshot ID. - */ - public long snapshotId() { - return snapshotId; - } - - /** - * @return Snapshot creation/restoration progress. - */ - public double progress() { - return progress; - } - - /** {@inheritDoc} */ - @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) { - writer.setBuffer(buf); - - if (!writer.isHeaderWritten()) { - if (!writer.writeHeader(directType(), fieldsCount())) - return false; - - writer.onHeaderWritten(); - } - - switch (writer.state()) { - case 0: - if (!writer.writeDouble("progress", progress)) - return false; - - writer.incrementState(); - - case 1: - if (!writer.writeLong("snapshotId", snapshotId)) - return false; - - writer.incrementState(); - - } - - return true; - } - - /** {@inheritDoc} */ - @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) { - reader.setBuffer(buf); - - if (!reader.beforeMessageRead()) - return false; - - switch (reader.state()) { - case 0: - progress = reader.readDouble("progress"); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - case 1: - snapshotId = reader.readLong("snapshotId"); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - } - - return reader.afterMessageRead(SnapshotProgressMessage.class); - } - - /** {@inheritDoc} */ - @Override public byte directType() { - return -47; - } - - /** {@inheritDoc} */ - @Override public byte fieldsCount() { - return 2; - } - - /** {@inheritDoc} */ - @Override public void onAckReceived() { - // No-op - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java index fafc71f329b17..3ad4ef462080e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java @@ -157,7 +157,7 @@ public Throwable getError() { /** {@inheritDoc} */ @Override public byte directType() { - return -46; + return -45; } /** {@inheritDoc} */ From 9e6b8ccea36ba2665cbe4e91c59a35a26590f9ae Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Fri, 17 Feb 2017 18:45:17 +0700 Subject: [PATCH 067/311] Fixed NPE in IgniteProcessProxy.kill() (cherry picked from commit 11bc058) --- .../testframework/junits/multijvm/IgniteProcessProxy.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java index 2ef9c59a1ea8b..4f204c4ebfe9e 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java @@ -241,9 +241,12 @@ public static void stop(String gridName, boolean cancel) { * @param gridName Grid name. */ public static void kill(String gridName) { + A.notNull(gridName, "gridName"); + IgniteProcessProxy proxy = gridProxies.get(gridName); - A.notNull(gridName, "gridName"); + if (proxy == null) + return; try { proxy.getProcess().kill(); From d13520e9a05bd9e9b987529472d6317951b72f96 Mon Sep 17 00:00:00 2001 From: sboikov Date: Wed, 22 Feb 2017 11:47:38 +0300 Subject: [PATCH 068/311] ignite-4484 Call commit for read-only transactions (reverted changes introduced in ignite-3601). (cherry picked from commit d77fe815395dcd2871d7) --- .../distributed/near/GridNearTxLocal.java | 2 +- .../cache/CacheGetEntryAbstractTest.java | 16 +- .../CacheSerializableTransactionsTest.java | 173 ++++++++++++++++-- .../cache/CacheTxFastFinishTest.java | 2 +- 4 files changed, 170 insertions(+), 23 deletions(-) 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 ba48e7a7cbbc5..66a3a95d184cf 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 @@ -958,7 +958,7 @@ void readyNearLock(IgniteTxEntry txEntry, * @return {@code True} if 'fast finish' path can be used for transaction completion. */ private boolean fastFinish() { - return writeMap().isEmpty() && (optimistic() || readMap().isEmpty()); + return writeMap().isEmpty() && ((optimistic() && !serializable()) || readMap().isEmpty()); } /** diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryAbstractTest.java index 8a2a86e147fed..320d06b05415d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryAbstractTest.java @@ -267,25 +267,27 @@ private void test(CacheConfiguration cfg, final boolean oneEntry) throws Excepti */ private void testConcurrentOptimisticTxGet(final IgniteCache cache, final TransactionIsolation txIsolation) throws Exception { + final int key1 = 42; + final int key2 = 43; + + cache.put(key1, new TestValue(key1)); + GridTestUtils.runMultiThreaded(new Runnable() { @Override public void run() { - final int key = 42; - IgniteTransactions txs = grid(0).transactions(); - cache.put(key, new TestValue(key)); + cache.put(key2, new TestValue(key2)); long stopTime = System.currentTimeMillis() + 3000; while (System.currentTimeMillis() < stopTime) { try (Transaction tx = txs.txStart(OPTIMISTIC, txIsolation)) { - cache.get(key); + cache.get(key1); tx.commit(); } - catch (TransactionOptimisticException e) { - assertTrue("Should not throw optimistic exception in only read TX. Tx isolation: " - + txIsolation, false); + catch (Exception ignored) { + fail("Unexpected exception: " + ignored); } } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java index ce2e75db8307f..f78db628f62db 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java @@ -33,6 +33,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import javax.cache.Cache; @@ -748,6 +749,11 @@ private void txConflictRead(boolean noVal, boolean needVer) throws Exception { updateKey(cache, key, 1); tx.commit(); + + fail(); + } + catch (TransactionOptimisticException e) { + log.info("Expected exception: " + e); } checkValue(key, 1, cache.getName()); @@ -2914,7 +2920,8 @@ public void testReadWriteAccountTx() throws Exception { sum += account.value(); } - cache.put(putKey, new Account(sum)); + if (ThreadLocalRandom.current().nextBoolean()) + cache.put(putKey, new Account(sum)); tx.commit(); } @@ -3204,14 +3211,21 @@ private void rollbackNearCacheRead(boolean near) throws Exception { cache0.put(key2, -1); cache0.put(key3, -1); - try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { - cache.get(key1); - cache.get(key2); - cache.get(key3); + try { + try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { + cache.get(key1); + cache.get(key2); + cache.get(key3); - updateKey(near ? cache : cache0, key2, -2); + updateKey(near ? cache : cache0, key2, -2); - tx.commit(); + tx.commit(); + } + + fail(); + } + catch (TransactionOptimisticException e) { + log.info("Expected exception: " + e); } checkValue(key1, -1, cacheName); @@ -3462,16 +3476,23 @@ public void testCrossCacheTx() throws Exception { checkValue(key1, newVal, CACHE1); checkValue(key2, newVal, CACHE2); - try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { - Object val1 = cache1.get(key1); - Object val2 = cache2.get(key2); + try { + try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { + Object val1 = cache1.get(key1); + Object val2 = cache2.get(key2); - assertEquals(newVal, val1); - assertEquals(newVal, val2); + assertEquals(newVal, val1); + assertEquals(newVal, val2); - updateKey(cache2, key2, newVal); + updateKey(cache2, key2, newVal); - tx.commit(); + tx.commit(); + } + + fail(); + } + catch (TransactionOptimisticException e) { + log.info("Expected exception: " + e); } try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { @@ -4479,6 +4500,130 @@ public void testConflictResolution() throws Exception { } } + /** + * Multithreaded transactional reads. + * + * @throws Exception If failed. + */ + public void testMultipleOptimisticRead() throws Exception { + final Ignite ignite = ignite(0); + final Integer key = 1; + final Integer val = 1; + final int THREADS_CNT = 50; + + final String cacheName = + ignite.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false)).getName(); + + try { + final IgniteCache cache = ignite.cache(cacheName); + + try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) { + cache.put(key, val); + + tx.commit(); + } + + assertTrue(cache.get(key).equals(val)); + + for (int i = 0; i < 10; i++) { + GridTestUtils.runMultiThreadedAsync(new Callable() { + @Override public Void call() throws Exception { + IgniteTransactions txs = cache.unwrap(Ignite.class).transactions(); + + try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { + assertTrue(cache.get(key).equals(val)); + + tx.commit(); + + } + return null; + } + }, THREADS_CNT, "multiple-reads-thread").get(); + } + } + finally { + destroyCache(cacheName); + } + } + + /** + * Transactional read in parallel with changing the same data. + * + * @throws Exception If failed. + */ + public void testTxReadInParallerTxWrite() throws Exception { + final Ignite ignite = ignite(0); + final Integer key = 1; + final Integer val = 1; + + final CountDownLatch readLatch = new CountDownLatch(1); + final CountDownLatch writeLatch = new CountDownLatch(1); + + final Exception[] err = {null}; + + final String cacheName = + ignite.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false)).getName(); + + final IgniteCache cache = ignite.cache(cacheName); + + try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) { + cache.put(key, val); + + tx.commit(); + } + + try { + IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable() { + @Override public Void call() throws Exception { + IgniteTransactions txs = cache.unwrap(Ignite.class).transactions(); + + try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { + assertTrue(cache.get(key).equals(val)); + + readLatch.countDown(); + + writeLatch.await(10, TimeUnit.SECONDS); + + try { + tx.commit(); + } + catch (TransactionOptimisticException e) { + log.info("Expected exception: " + e); + + err[0] = e; + } + } + return null; + } + }, "read-thread"); + + GridTestUtils.runAsync(new Callable() { + @Override public Void call() throws Exception { + IgniteTransactions txs = cache.unwrap(Ignite.class).transactions(); + + readLatch.await(10, TimeUnit.SECONDS); + + try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { + cache.put(key, val); + + tx.commit(); + } + + writeLatch.countDown(); + + return null; + } + }, "write-thread").get(); + + fut.get(); + + assertNotNull("Expected exception was not thrown", err[0]); + } + finally { + destroyCache(cacheName); + } + } + /** * @throws Exception If failed. */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheTxFastFinishTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheTxFastFinishTest.java index f9c66834d088e..35b14055066d4 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheTxFastFinishTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheTxFastFinishTest.java @@ -173,7 +173,7 @@ private void fastFinishTx(Ignite ignite) { try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { cache.get(i); - checkFastTxFinish(tx, commit); + checkNormalTxFinish(tx, commit); } try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) { From 5424b706163c2539c7e54a4cdf7e007766e17088 Mon Sep 17 00:00:00 2001 From: Alexandr Kuramshin Date: Thu, 16 Feb 2017 16:09:22 +0700 Subject: [PATCH 069/311] IGNITE-4538: Improved messages for BinaryMarshaller field read errors. This closes #1470. (cherry picked from commit f52ba0f) --- .../apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java index 3496dbf381ac8..1a348e0def568 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java @@ -33,6 +33,7 @@ import org.apache.ignite.internal.binary.BinaryObjectBuilderAdditionalSelfTest; import org.apache.ignite.internal.binary.BinaryObjectBuilderDefaultMappersSelfTest; import org.apache.ignite.internal.binary.BinaryObjectBuilderSimpleNameLowerCaseMappersSelfTest; +import org.apache.ignite.internal.binary.BinaryObjectExceptionSelfTest; import org.apache.ignite.internal.binary.BinaryObjectToStringSelfTest; import org.apache.ignite.internal.binary.BinarySerialiedFieldComparatorSelfTest; import org.apache.ignite.internal.binary.BinarySimpleNameTestPropertySelfTest; @@ -93,6 +94,7 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(BinaryTreeSelfTest.class); suite.addTestSuite(BinaryMarshallerSelfTest.class); + suite.addTestSuite(BinaryObjectExceptionSelfTest.class); suite.addTestSuite(BinarySerialiedFieldComparatorSelfTest.class); suite.addTestSuite(BinaryArrayIdentityResolverSelfTest.class); From 1118c72837096f29ff58065137f82763831c2c85 Mon Sep 17 00:00:00 2001 From: Alexandr Kuramshin Date: Thu, 16 Feb 2017 16:09:22 +0700 Subject: [PATCH 070/311] IGNITE-4538: Improved messages for BinaryMarshaller field read errors. This closes #1470. (cherry picked from commit f52ba0f) --- .../binary/BinaryClassDescriptor.java | 81 ++--- .../internal/binary/BinaryFieldAccessor.java | 56 ++-- .../internal/binary/BinaryReaderExImpl.java | 284 +++++++++++++++--- .../ignite/internal/binary/BinaryUtils.java | 11 +- .../binary/BinaryObjectExceptionSelfTest.java | 209 +++++++++++++ 5 files changed, 542 insertions(+), 99 deletions(-) create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java index 3a72a31db58aa..5616c691b6c87 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java @@ -44,6 +44,7 @@ import org.apache.ignite.internal.util.GridUnsafe; import org.apache.ignite.internal.util.IgniteUtils; import org.apache.ignite.internal.util.tostring.GridToStringExclude; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.marshaller.MarshallerExclusions; @@ -806,58 +807,66 @@ void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException { * @throws BinaryObjectException If failed. */ Object read(BinaryReaderExImpl reader) throws BinaryObjectException { - assert reader != null; - assert mode != BinaryWriteMode.OPTIMIZED : "OptimizedMarshaller should not be used here: " + cls.getName(); + try { + assert reader != null; + assert mode != BinaryWriteMode.OPTIMIZED : "OptimizedMarshaller should not be used here: " + cls.getName(); - Object res; + Object res; - switch (mode) { - case BINARY: - res = newInstance(); + switch (mode) { + case BINARY: + res = newInstance(); - reader.setHandle(res); + reader.setHandle(res); - if (serializer != null) - serializer.readBinary(res, reader); - else - ((Binarylizable)res).readBinary(reader); + if (serializer != null) + serializer.readBinary(res, reader); + else + ((Binarylizable)res).readBinary(reader); - break; + break; - case OBJECT: - res = newInstance(); + case OBJECT: + res = newInstance(); - reader.setHandle(res); + reader.setHandle(res); - for (BinaryFieldAccessor info : fields) - info.read(res, reader); + for (BinaryFieldAccessor info : fields) + info.read(res, reader); - break; + break; - default: - assert false : "Invalid mode: " + mode; + default: + assert false : "Invalid mode: " + mode; - return null; - } + return null; + } - if (readResolveMtd != null) { - try { - res = readResolveMtd.invoke(res); + if (readResolveMtd != null) { + try { + res = readResolveMtd.invoke(res); - reader.setHandle(res); - } - catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - catch (InvocationTargetException e) { - if (e.getTargetException() instanceof BinaryObjectException) - throw (BinaryObjectException)e.getTargetException(); + reader.setHandle(res); + } + catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + catch (InvocationTargetException e) { + if (e.getTargetException() instanceof BinaryObjectException) + throw (BinaryObjectException)e.getTargetException(); - throw new BinaryObjectException("Failed to execute readResolve() method on " + res, e); + throw new BinaryObjectException("Failed to execute readResolve() method on " + res, e); + } } - } - return res; + return res; + } + catch (Exception e) { + if (S.INCLUDE_SENSITIVE && !F.isEmpty(typeName)) + throw new BinaryObjectException("Failed to deserialize object [typeName=" + typeName + ']', e); + else + throw new BinaryObjectException("Failed to deserialize object [typeId=" + typeId + ']', e); + } } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java index af33b63f9ef55..db683db5b1972 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java @@ -26,6 +26,8 @@ import java.util.UUID; import org.apache.ignite.binary.BinaryObjectException; import org.apache.ignite.internal.util.GridUnsafe; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; /** @@ -35,6 +37,9 @@ public abstract class BinaryFieldAccessor { /** Field ID. */ protected final int id; + /** Field name */ + protected final String name; + /** Mode. */ protected final BinaryWriteMode mode; @@ -116,10 +121,12 @@ public static BinaryFieldAccessor create(Field field, int id) { * @param id Field ID. * @param mode Mode; */ - protected BinaryFieldAccessor(int id, BinaryWriteMode mode) { + protected BinaryFieldAccessor(Field field, int id, BinaryWriteMode mode) { + assert field != null; assert id != 0; assert mode != null; + this.name = field.getName(); this.id = id; this.mode = mode; } @@ -149,7 +156,26 @@ public BinaryWriteMode mode() { * @param reader Reader. * @throws BinaryObjectException If failed. */ - public abstract void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException; + public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { + try { + read0(obj, reader); + } + catch (Exception ex) { + if (S.INCLUDE_SENSITIVE && !F.isEmpty(name)) + throw new BinaryObjectException("Failed to read field [name=" + name + ']', ex); + else + throw new BinaryObjectException("Failed to read field [id=" + id + ']', ex); + } + } + + /** + * Read field. + * + * @param obj Object. + * @param reader Reader. + * @throws BinaryObjectException If failed. + */ + protected abstract void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException; /** * Base primitive field accessor. @@ -166,9 +192,7 @@ private static abstract class AbstractPrimitiveAccessor extends BinaryFieldAcces * @param mode Mode. */ protected AbstractPrimitiveAccessor(Field field, int id, BinaryWriteMode mode) { - super(id, mode); - - assert field != null; + super(field, id, mode); offset = GridUnsafe.objectFieldOffset(field); } @@ -197,7 +221,7 @@ public BytePrimitiveAccessor(Field field, int id) { } /** {@inheritDoc} */ - @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { + @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { byte val = reader.readByte(id); GridUnsafe.putByteField(obj, offset, val); @@ -227,7 +251,7 @@ public BooleanPrimitiveAccessor(Field field, int id) { } /** {@inheritDoc} */ - @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { + @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { boolean val = reader.readBoolean(id); GridUnsafe.putBooleanField(obj, offset, val); @@ -257,7 +281,7 @@ public ShortPrimitiveAccessor(Field field, int id) { } /** {@inheritDoc} */ - @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { + @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { short val = reader.readShort(id); GridUnsafe.putShortField(obj, offset, val); @@ -287,7 +311,7 @@ public CharPrimitiveAccessor(Field field, int id) { } /** {@inheritDoc} */ - @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { + @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { char val = reader.readChar(id); GridUnsafe.putCharField(obj, offset, val); @@ -317,7 +341,7 @@ public IntPrimitiveAccessor(Field field, int id) { } /** {@inheritDoc} */ - @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { + @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { int val = reader.readInt(id); GridUnsafe.putIntField(obj, offset, val); @@ -347,7 +371,7 @@ public LongPrimitiveAccessor(Field field, int id) { } /** {@inheritDoc} */ - @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { + @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { long val = reader.readLong(id); GridUnsafe.putLongField(obj, offset, val); @@ -377,7 +401,7 @@ public FloatPrimitiveAccessor(Field field, int id) { } /** {@inheritDoc} */ - @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { + @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { float val = reader.readFloat(id); GridUnsafe.putFloatField(obj, offset, val); @@ -407,7 +431,7 @@ public DoublePrimitiveAccessor(Field field, int id) { } /** {@inheritDoc} */ - @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { + @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { double val = reader.readDouble(id); GridUnsafe.putDoubleField(obj, offset, val); @@ -432,9 +456,7 @@ private static class DefaultFinalClassAccessor extends BinaryFieldAccessor { * @param mode Mode. */ DefaultFinalClassAccessor(Field field, int id, BinaryWriteMode mode, boolean dynamic) { - super(id, mode); - - assert field != null; + super(field, id, mode); this.field = field; this.dynamic = dynamic; @@ -635,7 +657,7 @@ private static class DefaultFinalClassAccessor extends BinaryFieldAccessor { } /** {@inheritDoc} */ - @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { + @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException { Object val = dynamic ? reader.readField(id) : readFixedType(reader); try { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java index 775f237787cfc..a0aac3f7106d4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java @@ -35,6 +35,7 @@ import org.apache.ignite.binary.BinaryReader; import org.apache.ignite.internal.binary.streams.BinaryInputStream; import org.apache.ignite.internal.util.IgniteUtils; +import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.SB; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -329,7 +330,12 @@ public Object unmarshal(int offset) throws BinaryObjectException { * @throws BinaryObjectException In case of error. */ @Nullable Object unmarshalField(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? BinaryUtils.unmarshal(in, ctx, ldr, this) : null; + try { + return findFieldByName(fieldName) ? BinaryUtils.unmarshal(in, ctx, ldr, this) : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -421,9 +427,29 @@ private T readHandleField() { return (T)obj; } + + /** + * Wraps an exception by adding the fieldName + * + * @param fieldName the name of the field, causes failure + * @param e the cause of the deserialization failure + * @return wrapping exception + */ + private BinaryObjectException wrapFieldException(String fieldName, Exception e) { + if (S.INCLUDE_SENSITIVE) + return new BinaryObjectException("Failed to read field: " + fieldName, e); + else + return new BinaryObjectException("Failed to read field.", e); + } + /** {@inheritDoc} */ @Override public byte readByte(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) && checkFlagNoHandles(BYTE) == Flag.NORMAL ? in.readByte() : 0; + try { + return findFieldByName(fieldName) && checkFlagNoHandles(BYTE) == Flag.NORMAL ? in.readByte() : 0; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -451,7 +477,12 @@ byte readByte(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public byte[] readByteArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readByteArray() : null; + try { + return findFieldByName(fieldName) ? this.readByteArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -479,7 +510,12 @@ byte readByte(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override public boolean readBoolean(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) && checkFlagNoHandles(BOOLEAN) == Flag.NORMAL && in.readBoolean(); + try { + return findFieldByName(fieldName) && checkFlagNoHandles(BOOLEAN) == Flag.NORMAL && in.readBoolean(); + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -507,7 +543,12 @@ boolean readBoolean(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public boolean[] readBooleanArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readBooleanArray() : null; + try { + return findFieldByName(fieldName) ? this.readBooleanArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -535,7 +576,12 @@ boolean readBoolean(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override public short readShort(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) && checkFlagNoHandles(SHORT) == Flag.NORMAL ? in.readShort() : 0; + try { + return findFieldByName(fieldName) && checkFlagNoHandles(SHORT) == Flag.NORMAL ? in.readShort() : 0; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -563,7 +609,12 @@ short readShort(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public short[] readShortArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readShortArray() : null; + try { + return findFieldByName(fieldName) ? this.readShortArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -591,7 +642,12 @@ short readShort(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override public char readChar(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) && checkFlagNoHandles(CHAR) == Flag.NORMAL ? in.readChar() : 0; + try { + return findFieldByName(fieldName) && checkFlagNoHandles(CHAR) == Flag.NORMAL ? in.readChar() : 0; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -619,7 +675,12 @@ char readChar(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public char[] readCharArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readCharArray() : null; + try { + return findFieldByName(fieldName) ? this.readCharArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -647,7 +708,12 @@ char readChar(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override public int readInt(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) && checkFlagNoHandles(INT) == Flag.NORMAL ? in.readInt() : 0; + try { + return findFieldByName(fieldName) && checkFlagNoHandles(INT) == Flag.NORMAL ? in.readInt() : 0; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -675,7 +741,12 @@ int readInt(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public int[] readIntArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readIntArray() : null; + try { + return findFieldByName(fieldName) ? this.readIntArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -703,7 +774,12 @@ int readInt(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override public long readLong(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) && checkFlagNoHandles(LONG) == Flag.NORMAL ? in.readLong() : 0; + try { + return findFieldByName(fieldName) && checkFlagNoHandles(LONG) == Flag.NORMAL ? in.readLong() : 0; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -731,7 +807,12 @@ long readLong(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public long[] readLongArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readLongArray() : null; + try { + return findFieldByName(fieldName) ? this.readLongArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -759,7 +840,12 @@ long readLong(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override public float readFloat(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) && checkFlagNoHandles(FLOAT) == Flag.NORMAL ? in.readFloat() : 0; + try { + return findFieldByName(fieldName) && checkFlagNoHandles(FLOAT) == Flag.NORMAL ? in.readFloat() : 0; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -787,7 +873,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public float[] readFloatArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readFloatArray() : null; + try { + return findFieldByName(fieldName) ? this.readFloatArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -815,7 +906,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override public double readDouble(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) && checkFlagNoHandles(DOUBLE) == Flag.NORMAL ? in.readDouble() : 0; + try { + return findFieldByName(fieldName) && checkFlagNoHandles(DOUBLE) == Flag.NORMAL ? in.readDouble() : 0; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -843,7 +939,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public double[] readDoubleArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readDoubleArray() : null; + try { + return findFieldByName(fieldName) ? this.readDoubleArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -871,7 +972,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override @Nullable public BigDecimal readDecimal(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readDecimal() : null; + try { + return findFieldByName(fieldName) ? this.readDecimal() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -890,7 +996,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override @Nullable public BigDecimal[] readDecimalArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readDecimalArray() : null; + try { + return findFieldByName(fieldName) ? this.readDecimalArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -918,7 +1029,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override @Nullable public String readString(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readString() : null; + try { + return findFieldByName(fieldName) ? this.readString() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -937,7 +1053,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override @Nullable public String[] readStringArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readStringArray() : null; + try { + return findFieldByName(fieldName) ? this.readStringArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -965,7 +1086,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override @Nullable public UUID readUuid(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readUuid() : null; + try { + return findFieldByName(fieldName) ? this.readUuid() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -984,7 +1110,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override @Nullable public UUID[] readUuidArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readUuidArray() : null; + try { + return findFieldByName(fieldName) ? this.readUuidArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -1012,7 +1143,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override @Nullable public Date readDate(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readDate() : null; + try { + return findFieldByName(fieldName) ? this.readDate() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -1031,7 +1167,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override @Nullable public Date[] readDateArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readDateArray() : null; + try { + return findFieldByName(fieldName) ? this.readDateArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -1059,7 +1200,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override @Nullable public Timestamp readTimestamp(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readTimestamp() : null; + try { + return findFieldByName(fieldName) ? this.readTimestamp() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -1078,7 +1224,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Override @Nullable public Timestamp[] readTimestampArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readTimestampArray() : null; + try { + return findFieldByName(fieldName) ? this.readTimestampArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -1107,7 +1258,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Nullable @Override public T readObject(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? (T)BinaryUtils.doReadObject(in, ctx, ldr, this) : null; + try { + return findFieldByName(fieldName) ? (T)BinaryUtils.doReadObject(in, ctx, ldr, this) : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -1131,7 +1287,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public Object[] readObjectArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? this.readObjectArray() : null; + try { + return findFieldByName(fieldName) ? this.readObjectArray() : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -1159,7 +1320,12 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public > T readEnum(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? (T)readEnum0(null) : null; + try { + return findFieldByName(fieldName) ? (T)readEnum0(null) : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -1201,7 +1367,13 @@ private Enum readEnum0(@Nullable Class cls) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public > T[] readEnumArray(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? (T[])readEnumArray0(null) : null; + + try { + return findFieldByName(fieldName) ? (T[])readEnumArray0(null) : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -1247,13 +1419,24 @@ private Object[] readEnumArray0(@Nullable Class cls) throws BinaryObjectExcep /** {@inheritDoc} */ @Nullable @Override public Collection readCollection(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? (Collection)readCollection0(null) : null; + try { + return findFieldByName(fieldName) ? (Collection)readCollection0(null) : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** {@inheritDoc} */ @Nullable @Override public Collection readCollection(String fieldName, BinaryCollectionFactory factory) throws BinaryObjectException { - return findFieldByName(fieldName) ? readCollection0(factory) : null; + + try { + return findFieldByName(fieldName) ? readCollection0(factory) : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -1316,13 +1499,24 @@ private Collection readCollection0(@Nullable BinaryCollectionFactory factory) /** {@inheritDoc} */ @Nullable @Override public Map readMap(String fieldName) throws BinaryObjectException { - return findFieldByName(fieldName) ? (Map)readMap0(null) : null; + try { + return findFieldByName(fieldName) ? (Map)readMap0(null) : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** {@inheritDoc} */ @Nullable @Override public Map readMap(String fieldName, BinaryMapFactory factory) throws BinaryObjectException { - return findFieldByName(fieldName) ? readMap0(factory) : null; + + try { + return findFieldByName(fieldName) ? readMap0(factory) : null; + } + catch (Exception ex) { + throw wrapFieldException(fieldName, ex); + } } /** @@ -1400,8 +1594,8 @@ else if (flag == HANDLE) int pos = BinaryUtils.positionForHandle(in); - throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected=" + expFlag + - ", actual=" + flag + ']'); + throw new BinaryObjectException("Unexpected field type [pos=" + pos + ", expected=" + fieldFlagName(expFlag) + + ", actual=" + fieldFlagName(flag) + ']'); } /** @@ -1421,8 +1615,20 @@ else if (flag == NULL) int pos = BinaryUtils.positionForHandle(in); - throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected=" + expFlag + - ", actual=" + flag + ']'); + throw new BinaryObjectException("Unexpected field type [pos=" + pos + ", expected=" + fieldFlagName(expFlag) + + ", actual=" + fieldFlagName(flag) + ']'); + } + + /** + * Gets a flag name + * + * @param flag a flag value + * @return string representation of the flag (type name, handle, else number) + */ + private String fieldFlagName(byte flag) { + String typeName = BinaryUtils.fieldTypeName(flag); + + return typeName == null ? String.valueOf(flag) : typeName; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java index 1153d155c0400..1d06417669d20 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java @@ -347,16 +347,13 @@ public static int updateSchemaId(int schemaId, int fieldId) { /** * @param typeId Field type ID. - * @return Field type name. + * @return Field type name or {@code null} if unknown. */ public static String fieldTypeName(int typeId) { - assert typeId >= 0 && typeId < FIELD_TYPE_NAMES.length : typeId; - - String typeName = FIELD_TYPE_NAMES[typeId]; - - assert typeName != null : typeId; + if(typeId < 0 || typeId >= FIELD_TYPE_NAMES.length) + return null; - return typeName; + return FIELD_TYPE_NAMES[typeId]; } /** diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java new file mode 100644 index 0000000000000..e4be8244bf4e6 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java @@ -0,0 +1,209 @@ +/* + * 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.binary; + +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Date; +import java.util.Iterator; +import java.util.UUID; +import javax.cache.Cache; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.binary.BinaryBasicNameMapper; +import org.apache.ignite.binary.BinaryObjectException; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +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.junits.common.GridCommonAbstractTest; + +/** + * BinaryObjectExceptionSelfTest + */ +public class BinaryObjectExceptionSelfTest extends GridCommonAbstractTest { + /** */ + private static final String TEST_KEY = "test_key"; + + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setMarshaller(new BinaryMarshaller()); + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER)); + + cfg.setCacheConfiguration(new CacheConfiguration().setCopyOnRead(true)); + + BinaryConfiguration bcfg = new BinaryConfiguration(); + + bcfg.setNameMapper(new BinaryBasicNameMapper(false)); + + cfg.setBinaryConfiguration(bcfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + startGrids(2); + + awaitPartitionMapExchange(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** + * Test unexpected field type. + * + * @throws Exception If failed. + */ + @SuppressWarnings("WhileLoopReplaceableByForEach") + public void testUnexpectedFieldType() throws Exception { + IgniteEx grid = grid(0); + + IgniteCache cache = grid.cache(null); + + cache.put(TEST_KEY, new Value()); + + BinaryObjectImpl b = (BinaryObjectImpl)cache.withKeepBinary().get(TEST_KEY); + + b.deserialize(); // deserialize working + + byte[] a = b.array(); + + int unexpectedCnt = 0; + + Field[] fields = Value.class.getDeclaredFields(); + + StringBuilder sb = new StringBuilder(4 << 10); + + for (int i = b.dataStartOffset(), j = b.footerStartOffset(); i < j; ++i) { + byte old = a[i]; + + a[i] = -1; + + try { + Iterator> it = cache.iterator(); + + while (it.hasNext()) + it.next(); + } + catch (Exception ex) { + Throwable root = ex; + + sb.setLength(0); + + sb.append(root.getMessage()); + + while (root.getCause() != null) { + root = root.getCause(); + + sb.append(". ").append(root.getMessage()); + } + if (root instanceof BinaryObjectException && root.getMessage().startsWith("Unexpected field type")) { + log().info(sb.toString()); + + Field f = fields[unexpectedCnt]; + + Throwable t = ex; + + assertTrue(t.getMessage(), t.getMessage().contains( + "object [typeName=org.apache.ignite.internal.binary.BinaryObjectExceptionSelfTest$Value")); + + t = t.getCause(); + + assertTrue(t.getMessage(), t.getMessage().contains("field [name=" + f.getName())); + + ++unexpectedCnt; + } + else + log().info("Ignored exception: " + sb); + } + + a[i] = old; + } + + assertEquals("Fields count must match \"Unexpected field type\" exception count", fields.length, unexpectedCnt); + } + + /** */ + private enum EnumValues { + /** */ + val1, + + /** */ + val2, + + /** */ + val3; + } + + /** */ + @SuppressWarnings("unused") + private static class Value { + /** */ + public byte byteVal = 1; + + /** */ + public boolean booleanVal = true; + + /** */ + public short shortVal = 2; + + /** */ + public char charVal = 'Q'; + + /** */ + public int intVal = 3; + + /** */ + public long longVal = 4; + + /** */ + public float floatVal = 5; + + /** */ + public double doubleVal = 6; + + /** */ + public BigDecimal bigDecimal = new BigDecimal(7); + + /** */ + public String string = "QWERTY"; + + /** */ + public UUID uuid = UUID.randomUUID(); + + /** */ + public Date date = new Date(); + + /** */ + public Timestamp timestamp = new Timestamp(date.getTime() + 1000L); + + /** */ + public EnumValues enumVal = EnumValues.val2; + } +} From ef35f4f42bde09ad890e586ecfd61933e7399378 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Wed, 1 Mar 2017 23:25:21 +0700 Subject: [PATCH 071/311] GG-11992 Add EnforceJoinOrder option. --- .../internal/visor/query/VisorQueryArg.java | 16 +++++++++++++++- .../internal/visor/query/VisorQueryJob.java | 1 + .../commands/cache/VisorCacheScanCommand.scala | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryArg.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryArg.java index a5eb3eb75a638..74f5b97ff6a54 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryArg.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryArg.java @@ -35,6 +35,9 @@ public class VisorQueryArg implements Serializable { /** Distributed joins enabled flag. */ private final boolean distributedJoins; + /** Enforce join order flag. */ + private final boolean enforceJoinOrder; + /** Flag whether to execute query locally. */ private final boolean loc; @@ -44,13 +47,17 @@ public class VisorQueryArg implements Serializable { /** * @param cacheName Cache name for query. * @param qryTxt Query text. + * @param distributedJoins If {@code true} then distributed joins enabled. + * @param enforceJoinOrder If {@code true} then enforce join order. * @param loc Flag whether to execute query locally. * @param pageSize Result batch size. */ - public VisorQueryArg(String cacheName, String qryTxt, boolean distributedJoins, boolean loc, int pageSize) { + public VisorQueryArg(String cacheName, String qryTxt, + boolean distributedJoins, boolean enforceJoinOrder, boolean loc, int pageSize) { this.cacheName = cacheName; this.qryTxt = qryTxt; this.distributedJoins = distributedJoins; + this.enforceJoinOrder = enforceJoinOrder; this.loc = loc; this.pageSize = pageSize; } @@ -76,6 +83,13 @@ public boolean distributedJoins() { return distributedJoins; } + /** + * @return Enforce join order flag. + */ + public boolean enforceJoinOrder() { + return enforceJoinOrder; + } + /** * @return {@code true} if query should be executed locally. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java index cc1c678550c65..95ac39b75f31b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java @@ -162,6 +162,7 @@ private QueryCursor> near(IgniteCache error(x.get1()) From a62cc454466f921e2edd26bb0a6e0646bdb3a7f1 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Thu, 2 Mar 2017 16:33:58 +0300 Subject: [PATCH 072/311] GG-11860 Implement snapshot status on platform level -refactoring RESTORE --- .../pagemem/snapshot/SnapshotOperation.java | 3 +- .../GridDhtPartitionsExchangeFuture.java | 119 ++++++++++++++++-- 2 files changed, 109 insertions(+), 13 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index 3f84b97539dcd..f3b5eeee0886a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -105,7 +105,8 @@ public Object extraParameter() { * @param op Op. */ public static Collection getOptionalPathsParameter(SnapshotOperation op) { - assert op.type() == SnapshotOperationType.CHECK || op.extraParameter() instanceof Collection; + assert (op.type() == SnapshotOperationType.CHECK || op.type() == SnapshotOperationType.RESTORE) + && (op.extraParameter() == null || op.extraParameter() instanceof Collection); return (Collection)op.extraParameter(); } 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 987ba5453f909..4c179e660b4af 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 @@ -48,6 +48,8 @@ import org.apache.ignite.internal.events.DiscoveryCustomEvent; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; import org.apache.ignite.internal.managers.discovery.GridDiscoveryTopologySnapshot; +import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; +import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationType; import org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; @@ -59,6 +61,7 @@ import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; 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.distributed.dht.GridClientPartitionTopology; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; @@ -81,6 +84,7 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.lang.IgniteRunnable; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jsr166.ConcurrentHashMap8; @@ -510,10 +514,36 @@ public void init() throws IgniteInterruptedCheckedException { exchange = onCacheChangeRequest(crdNode); } - else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) + else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) { exchange = CU.clientNode(discoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode); + + StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg = (StartSnapshotOperationAckDiscoveryMessage)msg; + + if (!cctx.localNode().isDaemon()) { + SnapshotOperation op = snapshotOperationMsg.snapshotOperation(); + + if (op.type() == SnapshotOperationType.RESTORE) { + if (reqs != null) + reqs = new ArrayList<>(reqs); + else + reqs = new ArrayList<>(); + + List destroyRequests = getStopCacheRequests( + cctx.cache(), op.cacheNames(), cctx.localNodeId()); + + reqs.addAll(destroyRequests); + + if (!reqs.isEmpty()) { //Emulate destroy cache request + if (op.type() == SnapshotOperationType.RESTORE) + cctx.cache().onCustomEvent(new DynamicCacheChangeBatch(reqs), topVer); + + onCacheChangeRequest(crdNode); + } + } + } + } else { assert affChangeMsg != null : this; @@ -577,6 +607,36 @@ else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) } } + /** + * @param cache Cache. + * @param cacheNames Cache names. + * @param locNodeId Local node id. + */ + @NotNull public static List getStopCacheRequests(GridCacheProcessor cache, + Set cacheNames, UUID locNodeId) { + List destroyRequests = new ArrayList<>(); + + for (String cacheName : cacheNames) { + DynamicCacheDescriptor desc = cache.cacheDescriptor(CU.cacheId(cacheName)); + + if (desc == null) + continue; + + DynamicCacheChangeRequest t = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, locNodeId); + + t.stop(true); + t.destroy(true); + + t.deploymentId(desc.deploymentId()); + + t.restart(true); + + destroyRequests.add(t); + } + + return destroyRequests; + } + /** * @throws IgniteCheckedException If failed. */ @@ -806,19 +866,15 @@ private void distributedExchange() throws IgniteCheckedException { cctx.database().beforeExchange(this); - // If a backup request, synchronously wait for backup start. - if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) { - DiscoveryCustomMessage customMsg = ((DiscoveryCustomEvent)discoEvt).customMessage(); - - if (customMsg instanceof StartSnapshotOperationAckDiscoveryMessage) { - StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg = (StartSnapshotOperationAckDiscoveryMessage)customMsg; + StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg = getSnapshotOperationMessage(); - if (!cctx.localNode().isClient() && !cctx.localNode().isDaemon()) { - IgniteInternalFuture fut = cctx.database().startLocalSnapshotOperation(snapshotOperationMsg); + // If it's a snapshot operation request, synchronously wait for backup start. + if (snapshotOperationMsg != null) { + if (!cctx.localNode().isClient() && !cctx.localNode().isDaemon()) { + SnapshotOperation op = snapshotOperationMsg.snapshotOperation(); - if (fut != null) - fut.get(); - } + if (op.type() != SnapshotOperationType.RESTORE) + startLocalSnasphotOperation(snapshotOperationMsg); } } @@ -832,6 +888,17 @@ private void distributedExchange() throws IgniteCheckedException { initDone(); } + /** + * @param snapshotOperationMsg Snapshot operation message. + */ + private void startLocalSnasphotOperation(StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg + ) throws IgniteCheckedException { + IgniteInternalFuture fut = cctx.database().startLocalSnapshotOperation(snapshotOperationMsg); + + if (fut != null) + fut.get(); + } + /** * @throws IgniteCheckedException If failed. */ @@ -1168,6 +1235,20 @@ private void sendPartitions(ClusterNode oldestNode) { cctx.cache().completeStartFuture(req); } + StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg = getSnapshotOperationMessage(); + + if (snapshotOperationMsg != null && !cctx.localNode().isClient() && !cctx.localNode().isDaemon()) { + SnapshotOperation op = snapshotOperationMsg.snapshotOperation(); + + if (op.type() == SnapshotOperationType.RESTORE) + try { + startLocalSnasphotOperation(snapshotOperationMsg); + } + catch (IgniteCheckedException e) { + log.error("Error while starting snapshot operation", e); + } + } + if (exchangeOnChangeGlobalState && err == null) cctx.kernalContext().state().onExchangeDone(); @@ -1196,6 +1277,20 @@ private void sendPartitions(ClusterNode oldestNode) { return dummy; } + /** + * + */ + private StartSnapshotOperationAckDiscoveryMessage getSnapshotOperationMessage() { + // If it's a snapshot operation request, synchronously wait for backup start. + if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) { + DiscoveryCustomMessage customMsg = ((DiscoveryCustomEvent)discoEvt).customMessage(); + + if (customMsg instanceof StartSnapshotOperationAckDiscoveryMessage) + return (StartSnapshotOperationAckDiscoveryMessage)customMsg; + } + return null; + } + /** {@inheritDoc} */ @Nullable @Override public Throwable validateCache( GridCacheContext cctx, From b51a2f8006a13a24e7115c44bcb7124ee20be255 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Thu, 2 Mar 2017 22:20:08 +0300 Subject: [PATCH 073/311] GG-11860 Implement snapshot status on platform level -fixing race with operation finish message --- .../StartSnapshotOperationAckDiscoveryMessage.java | 12 ++++++++++++ ...a => StartSnapshotOperationDiscoveryMessage.java} | 11 +++++++---- .../main/resources/META-INF/classnames.properties | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) rename modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/{StartFullSnapshotDiscoveryMessage.java => StartSnapshotOperationDiscoveryMessage.java} (93%) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationAckDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationAckDiscoveryMessage.java index e84b2e807340d..72defd4b392a9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationAckDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationAckDiscoveryMessage.java @@ -38,6 +38,9 @@ public class StartSnapshotOperationAckDiscoveryMessage implements DiscoveryCusto /** Custom message ID. */ private IgniteUuid id = IgniteUuid.randomUuid(); + /** Operation id. */ + private IgniteUuid opId; + /** */ private Exception err; @@ -55,12 +58,14 @@ public class StartSnapshotOperationAckDiscoveryMessage implements DiscoveryCusto * @param err Error. */ public StartSnapshotOperationAckDiscoveryMessage( + IgniteUuid id, SnapshotOperation snapshotOperation, Map lastFullSnapshotIdForCache, Map lastSnapshotIdForCache, Exception err, UUID initiatorNodeId ) { + this.opId = id; this.snapshotOperation = snapshotOperation; this.lastFullSnapshotIdForCache = lastFullSnapshotIdForCache; this.lastSnapshotIdForCache = lastSnapshotIdForCache; @@ -73,6 +78,13 @@ public StartSnapshotOperationAckDiscoveryMessage( return id; } + /** + * + */ + public IgniteUuid operationId() { + return opId; + } + /** * @return Initiator node id. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java similarity index 93% rename from modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java rename to modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java index 3a67e493d0f80..2373a9b6db6cc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartFullSnapshotDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java @@ -29,12 +29,12 @@ /** * Message indicating that a snapshot has been started. */ -public class StartFullSnapshotDiscoveryMessage implements DiscoveryCustomMessage { +public class StartSnapshotOperationDiscoveryMessage implements DiscoveryCustomMessage { /** */ private static final long serialVersionUID = 0L; /** Custom message ID. */ - private IgniteUuid id = IgniteUuid.randomUuid(); + private IgniteUuid id; /** Snapshot operation. */ private SnapshotOperation snapshotOperation; @@ -55,10 +55,12 @@ public class StartFullSnapshotDiscoveryMessage implements DiscoveryCustomMessage * @param snapshotOperation Snapshot operation * @param initiatorId initiator node id */ - public StartFullSnapshotDiscoveryMessage( + public StartSnapshotOperationDiscoveryMessage( + IgniteUuid id, SnapshotOperation snapshotOperation, UUID initiatorId ) { + this.id = id; this.snapshotOperation = snapshotOperation; this.initiatorId = initiatorId; } @@ -138,6 +140,7 @@ public void lastSnapshotId(int cacheId, long id) { /** {@inheritDoc} */ @Nullable @Override public DiscoveryCustomMessage ackMessage() { return new StartSnapshotOperationAckDiscoveryMessage( + id, snapshotOperation, lastFullSnapshotIdForCache, lastSnapshotIdForCache, @@ -159,6 +162,6 @@ public void snapshotOperation(SnapshotOperation snapshotOperation) { /** {@inheritDoc} */ @Override public String toString() { - return S.toString(StartFullSnapshotDiscoveryMessage.class, this); + return S.toString(StartSnapshotOperationDiscoveryMessage.class, this); } } diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index 13a3bcef10916..1750276480a33 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -329,7 +329,7 @@ org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl$Segment org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationFinishedMessage org.apache.ignite.internal.pagemem.snapshot.SnapshotProgressMessage org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage -org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotDiscoveryMessage +org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationDiscoveryMessage org.apache.ignite.internal.pagemem.wal.StorageException org.apache.ignite.internal.pagemem.wal.WALIterator org.apache.ignite.internal.pagemem.wal.record.StoreOperationRecord$StoreOperationType From e4b05d53d52ce3500e409d7275942d92e23db01b Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Tue, 7 Mar 2017 18:01:31 +0300 Subject: [PATCH 074/311] IGNITE-3477 - Log partition destroy to WAL --- .../pagemem/wal/record/WALRecord.java | 5 +- .../MetaPageUpdatePartitionDataRecord.java | 17 +++- .../record/delta/PartitionDestroyRecord.java | 73 +++++++++++++++++ .../delta/PartitionMetaStateRecord.java | 2 +- .../preloader/GridDhtPartitionDemander.java | 81 ++++++++++--------- 5 files changed, 135 insertions(+), 43 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PartitionDestroyRecord.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/WALRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/WALRecord.java index 9c2c88aaf9c48..142f0ee188152 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/WALRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/WALRecord.java @@ -160,7 +160,10 @@ public enum RecordType { DATA_PAGE_UPDATE_RECORD, /** init */ - BTREE_META_PAGE_INIT_ROOT2 + BTREE_META_PAGE_INIT_ROOT2, + + /** Partition destroy. */ + PARTITION_DESTROY ; /** */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java index 66efc6ff248ab..ef57c46f56a99 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java @@ -20,6 +20,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionMetaIO; +import org.apache.ignite.internal.util.typedef.internal.S; /** * @@ -45,8 +46,15 @@ public class MetaPageUpdatePartitionDataRecord extends PageDeltaRecord { * @param pageId Page ID. * @param allocatedIdxCandidate Page Allocated index candidate */ - public MetaPageUpdatePartitionDataRecord(int cacheId, long pageId, long updateCntr, long globalRmvId, int partSize, - byte state, int allocatedIdxCandidate) { + public MetaPageUpdatePartitionDataRecord( + int cacheId, + long pageId, + long updateCntr, + long globalRmvId, + int partSize, + byte state, + int allocatedIdxCandidate + ) { super(cacheId, pageId); this.updateCntr = updateCntr; @@ -104,4 +112,9 @@ public int allocatedIndexCandidate() { @Override public RecordType type() { return RecordType.PARTITION_META_PAGE_UPDATE_COUNTERS; } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(MetaPageUpdatePartitionDataRecord.class, this); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PartitionDestroyRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PartitionDestroyRecord.java new file mode 100644 index 0000000000000..c3b82009f29b2 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PartitionDestroyRecord.java @@ -0,0 +1,73 @@ +/* + * 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.pagemem.wal.record.delta; + +import org.apache.ignite.internal.pagemem.wal.record.WALRecord; + +/** + * + */ +public class PartitionDestroyRecord extends WALRecord { + /** */ + private int cacheId; + + /** */ + private int partId; + + /** + * @param cacheId Cache ID. + * @param partId Partition ID. + */ + public PartitionDestroyRecord(int cacheId, int partId) { + this.cacheId = cacheId; + this.partId = partId; + } + + /** {@inheritDoc} */ + @Override public RecordType type() { + return RecordType.PARTITION_DESTROY; + } + + /** + * @return Cache ID. + */ + public int cacheId() { + return cacheId; + } + + /** + * @param cacheId Cache ID. + */ + public void cacheId(int cacheId) { + this.cacheId = cacheId; + } + + /** + * @return Partition ID. + */ + public int partitionId() { + return partId; + } + + /** + * @param partId Partition ID. + */ + public void partitionId(int partId) { + this.partId = partId; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PartitionMetaStateRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PartitionMetaStateRecord.java index fd8b2fd9a7b14..95e1a561d28f3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PartitionMetaStateRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PartitionMetaStateRecord.java @@ -69,7 +69,7 @@ public int cacheId() { /** * */ - public int partId() { + public int partitionId() { return partId; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java index ce43ec42f8f48..4f8d13b7f9a9f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java @@ -778,8 +778,6 @@ private boolean preloadEntry( GridCacheEntryInfo entry, AffinityTopologyVersion topVer ) throws IgniteCheckedException { - cctx.shared().database().checkpointReadLock(); - try { GridCacheEntryEx cached = null; @@ -800,34 +798,41 @@ private boolean preloadEntry( return true; } - if (preloadPred == null || preloadPred.apply(entry)) { - if (cached.initialValue( - entry.value(), - entry.version(), - entry.ttl(), - entry.expireTime(), - true, - topVer, - cctx.isDrEnabled() ? DR_PRELOAD : DR_NONE, - false - )) { - cctx.evicts().touch(cached, topVer); // Start tracking. - - if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_OBJECT_LOADED) && !cached.isInternal()) - cctx.events().addEvent(cached.partition(), cached.key(), cctx.localNodeId(), - (IgniteUuid)null, null, EVT_CACHE_REBALANCE_OBJECT_LOADED, entry.value(), true, null, - false, null, null, null, true); - } - else { - cctx.evicts().touch(cached, topVer); // Start tracking. + cctx.shared().database().checkpointReadLock(); - if (log.isDebugEnabled()) - log.debug("Rebalancing entry is already in cache (will ignore) [key=" + cached.key() + - ", part=" + p + ']'); + try { + if (preloadPred == null || preloadPred.apply(entry)) { + if (cached.initialValue( + entry.value(), + entry.version(), + entry.ttl(), + entry.expireTime(), + true, + topVer, + cctx.isDrEnabled() ? DR_PRELOAD : DR_NONE, + false + )) { + cctx.evicts().touch(cached, topVer); // Start tracking. + + if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_OBJECT_LOADED) && !cached.isInternal()) + cctx.events().addEvent(cached.partition(), cached.key(), cctx.localNodeId(), + (IgniteUuid)null, null, EVT_CACHE_REBALANCE_OBJECT_LOADED, entry.value(), true, null, + false, null, null, null, true); + } + else { + cctx.evicts().touch(cached, topVer); // Start tracking. + + if (log.isDebugEnabled()) + log.debug("Rebalancing entry is already in cache (will ignore) [key=" + cached.key() + + ", part=" + p + ']'); + } } + else if (log.isDebugEnabled()) + log.debug("Rebalance predicate evaluated to false for entry (will ignore): " + entry); + } + finally { + cctx.shared().database().checkpointReadUnlock(); } - else if (log.isDebugEnabled()) - log.debug("Rebalance predicate evaluated to false for entry (will ignore): " + entry); } catch (GridCacheEntryRemovedException ignored) { if (log.isDebugEnabled()) @@ -848,9 +853,6 @@ else if (log.isDebugEnabled()) throw new IgniteCheckedException("Failed to cache rebalanced entry (will stop rebalancing) [local=" + cctx.nodeId() + ", node=" + pick.id() + ", key=" + entry.key() + ", part=" + p + ']', e); } - finally { - cctx.shared().database().checkpointReadUnlock(); - } return true; } @@ -911,8 +913,9 @@ public static class RebalanceFuture extends GridFutureAdapter { long updateSeq) { assert assigns != null; - this.exchFut = assigns.exchangeFuture(); - this.topVer = assigns.topologyVersion(); + exchFut = assigns.exchangeFuture(); + topVer = assigns.topologyVersion(); + this.cctx = cctx; this.log = log; this.startedEvtSent = startedEvtSent; @@ -924,13 +927,13 @@ public static class RebalanceFuture extends GridFutureAdapter { * Dummy future. Will be done by real one. */ public RebalanceFuture() { - this.exchFut = null; - this.topVer = null; - this.cctx = null; - this.log = null; - this.startedEvtSent = null; - this.stoppedEvtSent = null; - this.updateSeq = -1; + exchFut = null; + topVer = null; + cctx = null; + log = null; + startedEvtSent = null; + stoppedEvtSent = null; + updateSeq = -1; } /** From 7e956ed07c70c6d4de0ccb60a222529ecef3ea9b Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Thu, 9 Mar 2017 15:09:42 +0300 Subject: [PATCH 075/311] IGNITE-3477 - Remove waitForRent() in exchange future --- .../wal/IgniteWriteAheadLogManager.java | 27 ++- .../GridCachePartitionExchangeManager.java | 27 ++- .../cache/IgniteCacheOffheapManager.java | 3 +- .../cache/IgniteCacheOffheapManagerImpl.java | 57 +++-- .../IgniteCacheDatabaseSharedManager.java | 44 +++- .../dht/GridClientPartitionTopology.java | 33 ++- .../distributed/dht/GridDhtCacheEntry.java | 2 +- .../dht/GridDhtLocalPartition.java | 60 ++--- .../distributed/dht/GridDhtLockFuture.java | 29 ++- .../dht/GridDhtPartitionTopology.java | 22 +- .../dht/GridDhtPartitionTopologyImpl.java | 215 ++++++++---------- .../dht/GridDhtTxLocalAdapter.java | 2 +- .../GridDhtPartitionDemandMessage.java | 73 ++++-- .../preloader/GridDhtPartitionSupplier.java | 10 +- .../GridDhtPartitionSupplyMessageV2.java | 1 - .../GridDhtPartitionsExchangeFuture.java | 153 +++++++++++-- .../GridDhtPartitionsFullMessage.java | 120 ++++++++-- .../GridDhtPartitionsSingleMessage.java | 77 ++++++- .../dht/preloader/GridDhtPreloader.java | 106 ++++++--- .../IgniteDhtPartitionCountersMap.java | 64 ++++++ ...IgniteDhtPartitionHistorySuppliersMap.java | 107 +++++++++ .../IgniteDhtPartitionsToReloadMap.java | 88 +++++++ 22 files changed, 1043 insertions(+), 277 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersMap.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionHistorySuppliersMap.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionsToReloadMap.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/IgniteWriteAheadLogManager.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/IgniteWriteAheadLogManager.java index fb7a39b14a3be..ac785b6b024f8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/IgniteWriteAheadLogManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/IgniteWriteAheadLogManager.java @@ -59,8 +59,9 @@ public interface IgniteWriteAheadLogManager extends GridCacheSharedManager, Igni * the underlying storage. * * @param ptr Optional pointer to sync. If {@code null}, will sync up to the latest record. - * @throws IgniteCheckedException If - * @throws StorageException + * @throws IgniteCheckedException If failed to fsync. + * @throws StorageException If IO exception occurred during the write. If an exception is thrown from this + * method, the WAL will be invalidated and the node will be stopped. */ public void fsync(WALPointer ptr) throws IgniteCheckedException, StorageException; @@ -74,6 +75,22 @@ public interface IgniteWriteAheadLogManager extends GridCacheSharedManager, Igni */ public WALIterator replay(WALPointer start) throws IgniteCheckedException, StorageException; + /** + * Invoke this method to reserve WAL history since provided pointer and prevent it's deletion. + * + * @param start WAL pointer. + * @throws IgniteException If failed to reserve. + */ + public boolean reserve(WALPointer start) throws IgniteCheckedException; + + /** + * Invoke this method to release WAL history since provided pointer that was previously reserved. + * + * @param start WAL pointer. + * @throws IgniteException If failed to release. + */ + public void release(WALPointer start) throws IgniteCheckedException; + /** * Gives a hint to WAL manager to clear entries logged before the given pointer. Some entries before the * the given pointer will be kept because there is a configurable WAL history size. Those entries may be used @@ -83,4 +100,10 @@ public interface IgniteWriteAheadLogManager extends GridCacheSharedManager, Igni * @return Number of deleted WAL segments. */ public int truncate(WALPointer ptr); + + /** + * @param ptr Pointer. + * @return True if given pointer is located in reserved segment. + */ + public boolean reserved(WALPointer ptr); } 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 232dc83a7d58e..695872ffe9dcf 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 @@ -73,6 +73,8 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleRequest; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloaderAssignments; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionHistorySuppliersMap; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionsToReloadMap; import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx; import org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; @@ -822,7 +824,7 @@ private void refreshPartitions() { * @return {@code True} if message was sent, {@code false} if node left grid. */ private boolean sendAllPartitions(Collection nodes) { - GridDhtPartitionsFullMessage m = createPartitionsFullMessage(nodes, null, null, true); + GridDhtPartitionsFullMessage m = createPartitionsFullMessage(nodes, null, null, null, null, true); if (log.isDebugEnabled()) log.debug("Sending all partitions [nodeIds=" + U.nodeIds(nodes) + ", msg=" + m + ']'); @@ -854,12 +856,17 @@ private boolean sendAllPartitions(Collection nodes) { * @return Message. */ public GridDhtPartitionsFullMessage createPartitionsFullMessage(Collection nodes, - final @Nullable GridDhtPartitionExchangeId exchId, + @Nullable final GridDhtPartitionExchangeId exchId, @Nullable GridCacheVersion lastVer, + @Nullable IgniteDhtPartitionHistorySuppliersMap partHistSuppliers, + @Nullable IgniteDhtPartitionsToReloadMap partsToReload, final boolean compress) { final GridDhtPartitionsFullMessage m = new GridDhtPartitionsFullMessage(exchId, lastVer, - exchId != null ? exchId.topologyVersion() : AffinityTopologyVersion.NONE); + exchId != null ? exchId.topologyVersion() : AffinityTopologyVersion.NONE, + partHistSuppliers, + partsToReload + ); m.compress(compress); @@ -1239,11 +1246,23 @@ else if (!cacheCtx.isLocal()) top = cacheCtx.topology(); if (top != null) - updated |= top.update(null, entry.getValue(), null) != null; + updated |= top.update(null, entry.getValue(), null, msg.partsToReload(cctx.localNodeId(), cacheId)) != null; } if (!cctx.kernalContext().clientNode() && updated) refreshPartitions(); + + boolean hasMovingParts = false; + + for (GridCacheContext cacheCtx : cctx.cacheContexts()) { + if (!cacheCtx.isLocal() && cacheCtx.started() && cacheCtx.topology().hasMovingPartitions()) { + hasMovingParts = true; + break; + } + } + + if (!hasMovingParts) + cctx.database().releaseHistoryForPreloading(); } else exchangeFuture(msg.exchangeId(), null, null, null).onReceive(node, msg); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java index 4b85abee1dab4..d1ab78718ea0d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java @@ -82,10 +82,9 @@ public interface IgniteCacheOffheapManager extends GridCacheManager { public Iterable cacheDataStores(); /** - * @param p Partition ID. * @param store Data store. */ - public void destroyCacheDataStore(int p, CacheDataStore store) throws IgniteCheckedException; + public void destroyCacheDataStore(CacheDataStore store) throws IgniteCheckedException; /** * TODO: GG-10884, used on only from initialValue. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index 05eaf0ad29903..5d1f7b9122aab 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -59,6 +59,7 @@ import org.apache.ignite.internal.util.GridCloseableIteratorAdapter; import org.apache.ignite.internal.util.GridEmptyCloseableIterator; import org.apache.ignite.internal.util.GridSpinBusyLock; +import org.apache.ignite.internal.util.GridStripedLock; import org.apache.ignite.internal.util.GridUnsafe; import org.apache.ignite.internal.util.lang.GridCloseableIterator; import org.apache.ignite.internal.util.lang.GridCursor; @@ -91,9 +92,6 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple /** */ protected final ConcurrentMap partDataStores = new ConcurrentHashMap<>(); - /** */ - protected final CacheDataStore rmvdStore = new CacheDataStoreImpl(-1, null, null, null); - /** */ protected PendingEntriesTree pendingEntries; @@ -112,6 +110,9 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple /** */ private int updateValSizeThreshold; + /** */ + private GridStripedLock partStoreLock = new GridStripedLock(Runtime.getRuntime().availableProcessors()); + /** {@inheritDoc} */ @Override public GridAtomicLong globalRemoveId() { return globalRmvId; @@ -172,7 +173,7 @@ protected void initDataStructures() throws IgniteCheckedException { super.stop0(cancel, destroy); if (destroy && cctx.affinityNode()) - destroyCacheDataStructures(destroy); + destroyCacheDataStructures(); } /** {@inheritDoc} */ @@ -185,7 +186,7 @@ protected void initDataStructures() throws IgniteCheckedException { /** * */ - protected void destroyCacheDataStructures(boolean destroy) { + protected void destroyCacheDataStructures() { assert cctx.affinityNode(); try { @@ -196,7 +197,7 @@ protected void destroyCacheDataStructures(boolean destroy) { pendingEntries.destroy(); for (CacheDataStore store : partDataStores.values()) - store.destroy(); + destroyCacheDataStore(store); } catch (IgniteCheckedException e) { throw new IgniteException(e.getMessage(), e); @@ -238,7 +239,7 @@ private CacheDataStore dataStore(GridDhtLocalPartition part) { if (cctx.isLocal()) return locCacheDataStore; else { - GridDhtLocalPartition part = cctx.topology().localPartition(p, AffinityTopologyVersion.NONE, false); + GridDhtLocalPartition part = cctx.topology().localPartition(p, AffinityTopologyVersion.NONE, false, true); return part != null ? part.dataStore() : null; } @@ -278,7 +279,7 @@ private CacheDataStore dataStore(GridDhtLocalPartition part) { /** {@inheritDoc} */ @Override public long entriesCount(int part) { - if (cctx.isLocal()){ + if (cctx.isLocal()) { assert part == 0; return locCacheDataStore.size(); @@ -709,15 +710,20 @@ private long allocateForTree() throws IgniteCheckedException { /** {@inheritDoc} */ @Override public final CacheDataStore createCacheDataStore(int p) throws IgniteCheckedException { - CacheDataStore dataStore = null; - CacheDataStore oldStore = null; + CacheDataStore dataStore; + + partStoreLock.lock(p); + + try { + assert !partDataStores.containsKey(p); - do { dataStore = createCacheDataStore0(p); - oldStore = partDataStores.putIfAbsent(p, dataStore); + partDataStores.put(p, dataStore); + } + finally { + partStoreLock.unlock(p); } - while (oldStore != null); return dataStore; } @@ -763,15 +769,32 @@ protected CacheDataStore createCacheDataStore0(int p) } /** {@inheritDoc} */ - @Override public void destroyCacheDataStore(int p, CacheDataStore store) throws IgniteCheckedException { + @Override public final void destroyCacheDataStore(CacheDataStore store) throws IgniteCheckedException { + int p = store.partId(); + + partStoreLock.lock(p); + try { - partDataStores.remove(p, store); + boolean removed = partDataStores.remove(p, store); + + assert removed; - store.destroy(); + destroyCacheDataStore0(store); } catch (IgniteCheckedException e) { throw new IgniteException(e); } + finally { + partStoreLock.unlock(p); + } + } + + /** + * @param store Cache data store. + * @throws IgniteCheckedException If failed. + */ + protected void destroyCacheDataStore0(CacheDataStore store) throws IgniteCheckedException { + store.destroy(); } /** @@ -1155,7 +1178,7 @@ private void updateIgfsMetrics( KeyCacheObject key, CacheObject oldVal, CacheObject newVal - ) throws IgniteCheckedException { + ) { // In case we deal with IGFS cache, count updated data if (cctx.cache().isIgfsDataCache() && !cctx.isNear() && diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 95ed3aeb7f670..743cd77f1fa9f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -19,9 +19,10 @@ import java.io.File; import java.util.Collection; +import java.util.Collections; +import java.util.Map; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; -import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteInternalFuture; @@ -95,7 +96,7 @@ protected void initDataStructures() throws IgniteCheckedException { /** * @throws IgniteCheckedException If failed. */ - public void initDataBase() throws IgniteCheckedException{ + public void initDataBase() throws IgniteCheckedException { // No-op. } @@ -152,7 +153,7 @@ public void lock() throws IgniteCheckedException { /** * */ - public void unLock(){ + public void unLock() { } @@ -212,7 +213,8 @@ public void onCacheStop(GridCacheContext cctx) { * @return Snapshot creation init future or {@code null} if snapshot is not available. * @throws IgniteCheckedException If failed. */ - @Nullable public IgniteInternalFuture startLocalSnapshotOperation(StartSnapshotOperationAckDiscoveryMessage snapshotMsg) + @Nullable public IgniteInternalFuture startLocalSnapshotOperation( + StartSnapshotOperationAckDiscoveryMessage snapshotMsg) throws IgniteCheckedException { return null; } @@ -224,6 +226,40 @@ public void onCacheStop(GridCacheContext cctx) { return null; } + /** + * Reserve update history for exchange. + * + * @return Reserved update counters per cache and partition. + */ + public Map> reserveHistoryForExchange() { + return Collections.emptyMap(); + } + + /** + * Release reserved update history. + */ + public void releaseHistoryForExchange() { + // No-op + } + + /** + * Reserve update history for preloading. + * @param cacheId Cache ID. + * @param partId Partition Id. + * @param cntr Update counter. + * @return True if successfully reserved. + */ + public boolean reserveHistoryForPreloading(int cacheId, int partId, long cntr) { + return false; + } + + /** + * Release reserved update history. + */ + public void releaseHistoryForPreloading() { + // No-op + } + /** * @param dbCfg Database configuration. * @return Page memory instance. 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 ca71f511e685b..e63379abd5d57 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 @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -51,6 +52,7 @@ import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.MOVING; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.OWNING; +import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.RENTING; /** * Partition topology for node which does not have any local partitions. @@ -352,6 +354,12 @@ else if (!node2part.nodeId().equals(loc.id())) { "[part=" + p + ", topVer=" + topVer + ", this.topVer=" + this.topVer + ']'); } + /** {@inheritDoc} */ + @Nullable @Override public GridDhtLocalPartition localPartition(int p, AffinityTopologyVersion topVer, + boolean create, boolean showRenting) throws GridDhtInvalidPartitionException { + return localPartition(p, topVer, create); + } + /** {@inheritDoc} */ @Override public GridDhtLocalPartition localPartition(Object key, boolean create) { return localPartition(1, AffinityTopologyVersion.NONE, create); @@ -550,9 +558,11 @@ public long lastUpdateSequence() { /** {@inheritDoc} */ @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"}) - @Nullable @Override public GridDhtPartitionMap2 update(@Nullable GridDhtPartitionExchangeId exchId, - GridDhtPartitionFullMap partMap, - Map> cntrMap) { + @Nullable @Override public GridDhtPartitionMap2 update(@Nullable GridDhtPartitionsExchangeFuture exchFut, + GridDhtPartitionFullMap partMap, Map> cntrMap, Set partsToReload) { + + GridDhtPartitionExchangeId exchId = exchFut != null ? exchFut.exchangeId() : null; + if (log.isDebugEnabled()) log.debug("Updating full partition map [exchId=" + exchId + ", parts=" + fullMapString() + ']'); @@ -910,7 +920,9 @@ private void removeNode(UUID nodeId) { } /** {@inheritDoc} */ - @Override public void setOwners(int p, Set owners, boolean updateSeq) { + @Override public Set setOwners(int p, Set owners, boolean haveHistory, boolean updateSeq) { + Set result = haveHistory ? Collections.emptySet() : new HashSet(); + lock.writeLock().lock(); try { @@ -918,8 +930,15 @@ private void removeNode(UUID nodeId) { if (!e.getValue().containsKey(p)) continue; - if (e.getValue().get(p) == OWNING && !owners.contains(e.getKey())) - e.getValue().put(p, MOVING); + if (e.getValue().get(p) == OWNING && !owners.contains(e.getKey())) { + if (haveHistory) + e.getValue().put(p, MOVING); + else { + e.getValue().put(p, RENTING); + + result.add(e.getKey()); + } + } else if (owners.contains(e.getKey())) e.getValue().put(p, OWNING); } @@ -932,6 +951,8 @@ else if (owners.contains(e.getKey())) finally { lock.writeLock().unlock(); } + + return result; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java index 5b5cc3ba305ea..f1f4376c1bfc6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java @@ -91,7 +91,7 @@ public GridDhtCacheEntry( // Record this entry with partition. int p = cctx.affinity().partition(key); - locPart = ctx.topology().localPartition(p, topVer, true); + locPart = ctx.topology().localPartition(p, topVer, true, true); assert locPart != null : p; } 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 4418f530c4915..aeb40f89f5b77 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 @@ -138,13 +138,16 @@ public class GridDhtLocalPartition implements Comparable, * reservation is released. */ private volatile boolean shouldBeRenting; + /** Set if partition must be re-created and preloaded after eviction. */ + private boolean reload; + /** * @param cctx Context. * @param id Partition ID. * @param entryFactory Entry factory. */ - @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor") - GridDhtLocalPartition(GridCacheContext cctx, int id, GridCacheMapEntryFactory entryFactory) { + @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor") GridDhtLocalPartition(GridCacheContext cctx, + int id, GridCacheMapEntryFactory entryFactory) { assert cctx != null; this.id = id; @@ -373,12 +376,7 @@ void onRemoved(GridDhtCacheEntry entry) { map.removeEntry(entry); // Attempt to evict. - try { - tryEvict(); - } - catch (NodeStoppingException ignore) { - // No-op. - } + tryEvictAsync(false); } /** @@ -514,12 +512,7 @@ public boolean preloadingPermitted(KeyCacheObject key, GridCacheVersion ver) { if ((reservations & 0xFFFF) == 0 && shouldBeRenting) rent(true); - try { - tryEvict(); - } - catch (NodeStoppingException ignore) { - // No-op. - } + tryEvictAsync(false); break; } @@ -530,7 +523,7 @@ public boolean preloadingPermitted(KeyCacheObject key, GridCacheVersion ver) { * @param stateToRestore State to restore. */ public void restoreState(GridDhtPartitionState stateToRestore) { - state.set(((long)stateToRestore.ordinal()) << 32); + state.set(((long)stateToRestore.ordinal()) << 32); } /** @@ -631,11 +624,25 @@ boolean markLost() { } } + /** + * @return {@code True} if partition should be re-created after it is cleared. + */ + public boolean reload() { + return reload; + } + + /** + * @param value {@code reload} flag value. + */ + public void reload(boolean value) { + reload = value; + } + /** * @param updateSeq Update sequence. * @return Future to signal that this node is no longer an owner or backup. */ - IgniteInternalFuture rent(boolean updateSeq) { + public IgniteInternalFuture rent(boolean updateSeq) { long reservations = state.get(); int ord = (int)(reservations >> 32); @@ -663,8 +670,6 @@ IgniteInternalFuture rent(boolean updateSeq) { * @param updateSeq Update sequence. */ void tryEvictAsync(boolean updateSeq) { - assert cctx.kernalContext().state().active(); - long reservations = state.get(); int ord = (int)(reservations >> 32); @@ -713,7 +718,7 @@ private boolean addEvicting() { * */ private void clearEvicting() { - boolean free; + boolean free; while (true) { int cnt = evictGuard.get(); @@ -804,9 +809,7 @@ public void tryEvict() throws NodeStoppingException { */ private void destroyCacheDataStore() { try { - CacheDataStore store = dataStore(); - - cctx.offheap().destroyCacheDataStore(id, store); + cctx.offheap().destroyCacheDataStore(dataStore()); } catch (IgniteCheckedException e) { log.error("Unable to destroy cache data store on partition eviction [id=" + id + "]", e); @@ -817,12 +820,7 @@ private void destroyCacheDataStore() { * */ void onUnlock() { - try { - tryEvict(); - } - catch (NodeStoppingException ignore) { - // No-op. - } + tryEvictAsync(false); } /** @@ -949,7 +947,11 @@ public void clearAll() throws NodeStoppingException { try { CacheDataRow row = it0.next(); - GridDhtCacheEntry cached = (GridDhtCacheEntry)cctx.cache().entryEx(row.key()); + GridDhtCacheEntry cached = (GridDhtCacheEntry) getEntry(row.key()); + + if (cached == null || cached.obsolete()) + cached = (GridDhtCacheEntry) putEntryIfObsoleteOrAbsent( + cctx.affinity().affinityTopologyVersion(), row.key(), null, true, false); if (cached.clearInternal(clearVer, extras)) { if (rec) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java index b57ca571fd8ba..7b5dee3c8355d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java @@ -1262,17 +1262,24 @@ void onResult(GridDhtLockResponse res) { try { GridCacheEntryEx entry = cache0.entryEx(info.key(), topVer); - if (entry.initialValue(info.value(), - info.version(), - info.ttl(), - info.expireTime(), - true, topVer, - replicate ? DR_PRELOAD : DR_NONE, - false)) { - if (rec && !entry.isInternal()) - cctx.events().addEvent(entry.partition(), entry.key(), cctx.localNodeId(), - (IgniteUuid)null, null, EVT_CACHE_REBALANCE_OBJECT_LOADED, info.value(), true, null, - false, null, null, null, false); + cctx.shared().database().checkpointReadLock(); + + try { + if (entry.initialValue(info.value(), + info.version(), + info.ttl(), + info.expireTime(), + true, topVer, + replicate ? DR_PRELOAD : DR_NONE, + false)) { + if (rec && !entry.isInternal()) + cctx.events().addEvent(entry.partition(), entry.key(), cctx.localNodeId(), + (IgniteUuid)null, null, EVT_CACHE_REBALANCE_OBJECT_LOADED, info.value(), true, null, + false, null, null, null, false); + } + } + finally { + cctx.shared().database().checkpointReadUnlock(); } } catch (IgniteCheckedException e) { 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 ac3e2c8241d98..37c3af9b0fa10 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 @@ -127,6 +127,18 @@ public void beforeExchange(GridDhtPartitionsExchangeFuture exchFut, boolean affR @Nullable public GridDhtLocalPartition localPartition(int p, AffinityTopologyVersion topVer, boolean create) throws GridDhtInvalidPartitionException; + /** + * @param topVer Topology version at the time of creation. + * @param p Partition ID. + * @param create If {@code true}, then partition will be created if it's not there. + * @return Local partition. + * @throws GridDhtInvalidPartitionException If partition is evicted or absent and + * does not belong to this node. + */ + @Nullable public GridDhtLocalPartition localPartition(int p, AffinityTopologyVersion topVer, boolean create, + boolean showRenting) + throws GridDhtInvalidPartitionException; + /** * @param parts Partitions to release (should be reserved before). */ @@ -213,14 +225,15 @@ public void beforeExchange(GridDhtPartitionsExchangeFuture exchFut, boolean affR public void onRemoved(GridDhtCacheEntry e); /** - * @param exchId Exchange ID. + * @param exchFut Exchange future. * @param partMap Update partition map. * @param cntrMap Partition update counters. * @return Local partition map if there were evictions or {@code null} otherwise. */ - public GridDhtPartitionMap2 update(@Nullable GridDhtPartitionExchangeId exchId, + public GridDhtPartitionMap2 update(@Nullable GridDhtPartitionsExchangeFuture exchFut, GridDhtPartitionFullMap partMap, - @Nullable Map> cntrMap); + @Nullable Map> cntrMap, + Set partsToReload); /** * @param exchId Exchange ID. @@ -301,6 +314,7 @@ public GridDhtPartitionMap2 update(@Nullable GridDhtPartitionExchangeId exchId, * @param p Partition ID. * @param updateSeq If should increment sequence when updated. * @param owners Set of new owners. + * @return Set of node IDs that should reload partitions. */ - public void setOwners(int p, Set owners, boolean updateSeq); + public Set setOwners(int p, Set owners, boolean haveHistory, boolean updateSeq); } 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 66e5be348e7c1..553aa2a184179 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 @@ -32,12 +32,10 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; -import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.cache.PartitionLossPolicy; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.events.EventType; -import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException; import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.processors.affinity.AffinityAssignment; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; @@ -59,7 +57,6 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.jetbrains.annotations.Nullable; -import static org.apache.ignite.IgniteSystemProperties.IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT; import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.LOST; @@ -70,8 +67,7 @@ /** * Partition topology. */ -@GridToStringExclude -class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology { +@GridToStringExclude class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology { /** If true, then check consistency. */ private static final boolean CONSISTENCY_CHECK = false; @@ -189,93 +185,6 @@ private String mapString(GridDhtPartitionMap2 map) { return map == null ? "null" : FULL_MAP_DEBUG ? map.toFullString() : map.toString(); } - /** - * Waits for renting partitions. - * - * @return {@code True} if mapping was changed. - * @throws IgniteCheckedException If failed. - */ - private boolean waitForRent() throws IgniteCheckedException { - final long longOpDumpTimeout = - IgniteSystemProperties.getLong(IgniteSystemProperties.IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, 60_000); - - int dumpCnt = 0; - - GridDhtLocalPartition part; - - for (int i = 0; i < locParts.length(); i++) { - part = locParts.get(i); - - if (part == null) - continue; - - GridDhtPartitionState state = part.state(); - - if (state == RENTING || state == EVICTED) { - if (log.isDebugEnabled()) - log.debug("Waiting for renting partition: " + part); - - part.tryEvictAsync(false); - - // Wait for partition to empty out. - if (longOpDumpTimeout > 0) { - while (true) { - try { - part.rent(true).get(longOpDumpTimeout); - - break; - } - catch (IgniteFutureTimeoutCheckedException e) { - if (dumpCnt++ < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) { - U.warn(log, "Failed to wait for partition eviction [" + - "topVer=" + topVer + - ", cache=" + cctx.name() + - ", part=" + part.id() + - ", partState=" + part.state() + - ", size=" + part.size() + - ", reservations=" + part.reservations() + - ", grpReservations=" + part.groupReserved() + - ", node=" + cctx.localNodeId() + "]"); - - if (IgniteSystemProperties.getBoolean(IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT, false)) - U.dumpThreads(log); - } - } - } - } - else - part.rent(true).get(); - - if (log.isDebugEnabled()) - log.debug("Finished waiting for renting partition: " + part); - } - } - - // Remove evicted partition. - lock.writeLock().lock(); - - try { - boolean changed = false; - - for (int i = 0; i < locParts.length(); i++) { - part = locParts.get(i); - - if (part == null) - continue; - - if (part.state() == EVICTED) { - locParts.set(i, null); - changed = true; - } - } - - return changed; - } - finally { - lock.writeLock().unlock(); - } - } - /** {@inheritDoc} */ @SuppressWarnings({"LockAcquiredButNotSafelyReleased"}) @Override public void readLock() { @@ -422,7 +331,7 @@ private void initPartitions0(GridDhtPartitionsExchangeFuture exchFut, long updat // If preloader is disabled, then we simply clear out // the partitions this node is not responsible for. for (int p = 0; p < num; p++) { - GridDhtLocalPartition locPart = localPartition(p, topVer, false, false); + GridDhtLocalPartition locPart = localPartition0(p, topVer, false, true, false); boolean belongs = localNode(p, aff); @@ -498,9 +407,6 @@ else if (localNode(p, aff)) && !cctx.kernalContext().clientNode() ); - // Wait for rent outside of checkpoint lock. - waitForRent(); - ClusterNode loc = cctx.localNode(); cctx.shared().database().checkpointReadLock(); @@ -580,16 +486,13 @@ else if (!node2part.nodeId().equals(loc.id())) { finally { cctx.shared().database().checkpointReadUnlock(); } - - // Wait for evictions. - waitForRent(); } /** {@inheritDoc} */ @Override public boolean afterExchange(GridDhtPartitionsExchangeFuture exchFut) throws IgniteCheckedException { treatAllPartAsLoc = false; - boolean changed = waitForRent(); + boolean changed = false; int num = cctx.affinity().partitions(); @@ -616,7 +519,7 @@ else if (!node2part.nodeId().equals(loc.id())) { long updateSeq = this.updateSeq.incrementAndGet(); for (int p = 0; p < num; p++) { - GridDhtLocalPartition locPart = localPartition(p, topVer, false, false); + GridDhtLocalPartition locPart = localPartition0(p, topVer, false, false, false); if (cctx.affinity().partitionLocalNode(p, topVer)) { // This partition will be created during next topology event, @@ -697,7 +600,13 @@ else if (log.isDebugEnabled()) @Nullable @Override public GridDhtLocalPartition localPartition(int p, AffinityTopologyVersion topVer, boolean create) throws GridDhtInvalidPartitionException { - return localPartition(p, topVer, create, true); + return localPartition0(p, topVer, create, false, true); + } + + /** {@inheritDoc} */ + @Nullable @Override public GridDhtLocalPartition localPartition(int p, AffinityTopologyVersion topVer, + boolean create, boolean showRenting) throws GridDhtInvalidPartitionException { + return localPartition0(p, topVer, create, showRenting, true); } /** @@ -734,9 +643,10 @@ private GridDhtLocalPartition createPartition(int p) { * @return Local partition. */ @SuppressWarnings("TooBroadScope") - private GridDhtLocalPartition localPartition(int p, + private GridDhtLocalPartition localPartition0(int p, AffinityTopologyVersion topVer, boolean create, + boolean showRenting, boolean updateSeq) { GridDhtLocalPartition loc; @@ -744,7 +654,7 @@ private GridDhtLocalPartition localPartition(int p, GridDhtPartitionState state = loc != null ? loc.state() : null; - if (loc != null && state != EVICTED && (state != RENTING || !cctx.allowFastEviction())) + if (loc != null && state != EVICTED && (state != RENTING || showRenting)) return loc; if (!create) @@ -769,8 +679,9 @@ private GridDhtLocalPartition localPartition(int p, "(often may be caused by inconsistent 'key.hashCode()' implementation) " + "[part=" + p + ", topVer=" + topVer + ", this.topVer=" + this.topVer + ']'); } - else if (loc != null && state == RENTING && cctx.allowFastEviction()) - throw new GridDhtInvalidPartitionException(p, "Adding entry to partition that is concurrently evicted."); + else if (loc != null && state == RENTING && !showRenting) + throw new GridDhtInvalidPartitionException(p, "Adding entry to partition that is concurrently evicted " + + "[part=" + p + ", shouldBeMoving=" + loc.reload() + "]"); if (loc == null) { if (!treatAllPartAsLoc && !belongs) @@ -1062,10 +973,13 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) /** {@inheritDoc} */ @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"}) @Nullable @Override public GridDhtPartitionMap2 update( - @Nullable GridDhtPartitionExchangeId exchId, + @Nullable GridDhtPartitionsExchangeFuture exchFut, GridDhtPartitionFullMap partMap, - @Nullable Map> cntrMap + @Nullable Map> cntrMap, + Set partsToReload ) { + GridDhtPartitionExchangeId exchId = exchFut != null ? exchFut.exchangeId() : null; + if (log.isDebugEnabled()) log.debug("Updating full partition map [exchId=" + exchId + ", parts=" + fullMapString() + ']'); @@ -1117,8 +1031,6 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) return null; } - long updateSeq = this.updateSeq.incrementAndGet(); - if (exchId != null) lastExchangeId = exchId; @@ -1186,11 +1098,32 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) int p = e.getKey(); GridDhtPartitionState state = e.getValue(); - if (state == MOVING) { + if (state == OWNING) { GridDhtLocalPartition locPart = locParts.get(p); assert locPart != null; + if (cntrMap != null) { + T2 cntr = cntrMap.get(p); + + if (cntr != null && cntr.get2() > locPart.updateCounter()) + locPart.updateCounter(cntr.get2()); + } + + if (locPart.state() == MOVING) { + boolean success = locPart.own(); + + assert success : locPart; + + changed |= success; + } + } + else if (state == MOVING) { + GridDhtLocalPartition locPart = locParts.get(p); + + if (locPart == null || locPart.state() == EVICTED) + locPart = createPartition(p); + if (locPart.state() == OWNING) { locPart.moving(); @@ -1204,9 +1137,30 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) locPart.updateCounter(cntr.get2()); } } + else if (state == RENTING && partsToReload.contains(p)) { + GridDhtLocalPartition locPart = locParts.get(p); + + if (locPart == null || locPart.state() == EVICTED) { + createPartition(p); + + changed = true; + } + else if (locPart.state() == OWNING || locPart.state() == MOVING) { + locPart.reload(true); + + locPart.rent(false); + + changed = true; + } + else { + locPart.reload(true); + } + } } } + long updateSeq = this.updateSeq.incrementAndGet(); + if (!affVer.equals(AffinityTopologyVersion.NONE) && affVer.compareTo(topVer) >= 0) { List> aff = cctx.affinity().assignments(topVer); @@ -1536,24 +1490,42 @@ else if (plc != PartitionLossPolicy.IGNORE) { } /** {@inheritDoc} */ - @Override public void setOwners(int p, Set owners, boolean updateSeq) { + @Override public Set setOwners(int p, Set owners, boolean haveHistory, boolean updateSeq) { + Set result = haveHistory ? Collections.emptySet() : new HashSet(); + lock.writeLock().lock(); try { - GridDhtLocalPartition locPart = locParts.get(p); if (locPart != null) { - if (locPart.state() == OWNING && !owners.contains(cctx.localNodeId())) - locPart.moving(); + if (locPart.state() == OWNING && !owners.contains(cctx.localNodeId())) { + if (haveHistory) + locPart.moving(); + else { + locPart.rent(false); + + locPart.reload(true); + + result.add(cctx.localNodeId()); + } + + } } for (Map.Entry e : node2part.entrySet()) { if (!e.getValue().containsKey(p)) continue; - if (e.getValue().get(p) == OWNING && !owners.contains(e.getKey())) - e.getValue().put(p, MOVING); + if (e.getValue().get(p) == OWNING && !owners.contains(e.getKey())) { + if (haveHistory) + e.getValue().put(p, MOVING); + else { + e.getValue().put(p, RENTING); + + result.add(e.getKey()); + } + } } if (updateSeq) @@ -1562,6 +1534,8 @@ else if (plc != PartitionLossPolicy.IGNORE) { finally { lock.writeLock().unlock(); } + + return result; } /** @@ -1629,6 +1603,8 @@ private boolean checkEvictions(long updateSeq, List> aff) { // If all affinity nodes are owners, then evict partition from local node. if (nodeIds.containsAll(F.nodeIds(affNodes))) { + part.reload(false); + part.rent(false); updateSeq = updateLocal(part.id(), part.state(), updateSeq); @@ -1654,6 +1630,8 @@ private boolean checkEvictions(long updateSeq, List> aff) { ClusterNode n = sorted.get(i); if (locId.equals(n.id())) { + part.reload(false); + part.rent(false); updateSeq = updateLocal(part.id(), part.state(), updateSeq); @@ -1833,6 +1811,9 @@ private void removeNode(UUID nodeId) { long seq = updateSeq ? this.updateSeq.incrementAndGet() : this.updateSeq.get(); + if (part.reload()) + part = createPartition(part.id()); + updateLocal(part.id(), part.state(), seq); consistencyCheck(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java index debf8b607372b..5169f2741d351 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java @@ -147,7 +147,7 @@ protected GridDhtTxLocalAdapter( storeEnabled, onePhaseCommit, txSize, - subjId, + subjId, taskNameHash ); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java index c9dcaaf1bccd9..377c274ed7fbe 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java @@ -50,7 +50,11 @@ public class GridDhtPartitionDemandMessage extends GridCacheMessage { @GridDirectCollection(int.class) private Collection parts; - /** Partition. */ + /** Partitions that must be restored from history. */ + @GridDirectCollection(int.class) + private Collection historicalParts; + + /** Partition counters. */ @GridDirectMap(keyType = int.class, valueType = long.class) private Map partsCntrs; @@ -85,7 +89,8 @@ public class GridDhtPartitionDemandMessage extends GridCacheMessage { * @param cp Message to copy from. * @param parts Partitions. */ - GridDhtPartitionDemandMessage(GridDhtPartitionDemandMessage cp, Collection parts, Map partsCntrs) { + GridDhtPartitionDemandMessage(GridDhtPartitionDemandMessage cp, Collection parts, + Map partsCntrs) { cacheId = cp.cacheId; updateSeq = cp.updateSeq; topic = cp.topic; @@ -96,6 +101,9 @@ public class GridDhtPartitionDemandMessage extends GridCacheMessage { // Create a copy of passed in collection since it can be modified when this message is being sent. this.parts = new HashSet<>(parts); this.partsCntrs = partsCntrs; + + if (cp.historicalParts != null) + historicalParts = new HashSet<>(cp.historicalParts); } /** @@ -108,13 +116,19 @@ public GridDhtPartitionDemandMessage() { /** * @param p Partition. */ - void addPartition(int p) { + void addPartition(int p, boolean historical) { if (parts == null) parts = new HashSet<>(); parts.add(p); - } + if (historical) { + if (historicalParts == null) + historicalParts = new HashSet<>(); + + historicalParts.add(p); + } + } /** * @return Partition. @@ -123,6 +137,17 @@ Collection partitions() { return parts; } + /** + * @param p Partition to check. + * @return {@code True} if historical. + */ + boolean isHistorical(int p) { + if (historicalParts == null) + return false; + + return historicalParts.contains(p); + } + /** * @param updateSeq Update sequence. */ @@ -232,42 +257,48 @@ Long partitionCounter(int part) { switch (writer.state()) { case 3: - if (!writer.writeCollection("parts", parts, MessageCollectionItemType.INT)) + if (!writer.writeCollection("historicalParts", historicalParts, MessageCollectionItemType.INT)) return false; writer.incrementState(); case 4: - if (!writer.writeMap("partsCntrs", partsCntrs, MessageCollectionItemType.INT, MessageCollectionItemType.LONG)) + if (!writer.writeCollection("parts", parts, MessageCollectionItemType.INT)) return false; writer.incrementState(); case 5: - if (!writer.writeLong("timeout", timeout)) + if (!writer.writeMap("partsCntrs", partsCntrs, MessageCollectionItemType.INT, MessageCollectionItemType.LONG)) return false; writer.incrementState(); case 6: - if (!writer.writeMessage("topVer", topVer)) + if (!writer.writeLong("timeout", timeout)) return false; writer.incrementState(); case 7: - if (!writer.writeByteArray("topicBytes", topicBytes)) + if (!writer.writeMessage("topVer", topVer)) return false; writer.incrementState(); case 8: - if (!writer.writeLong("updateSeq", updateSeq)) + if (!writer.writeByteArray("topicBytes", topicBytes)) return false; writer.incrementState(); case 9: + if (!writer.writeLong("updateSeq", updateSeq)) + return false; + + writer.incrementState(); + + case 10: if (!writer.writeInt("workerId", workerId)) return false; @@ -290,7 +321,7 @@ Long partitionCounter(int part) { switch (reader.state()) { case 3: - parts = reader.readCollection("parts", MessageCollectionItemType.INT); + historicalParts = reader.readCollection("historicalParts", MessageCollectionItemType.INT); if (!reader.isLastRead()) return false; @@ -298,7 +329,7 @@ Long partitionCounter(int part) { reader.incrementState(); case 4: - partsCntrs = reader.readMap("partsCntrs", MessageCollectionItemType.INT, MessageCollectionItemType.LONG, false); + parts = reader.readCollection("parts", MessageCollectionItemType.INT); if (!reader.isLastRead()) return false; @@ -306,7 +337,7 @@ Long partitionCounter(int part) { reader.incrementState(); case 5: - timeout = reader.readLong("timeout"); + partsCntrs = reader.readMap("partsCntrs", MessageCollectionItemType.INT, MessageCollectionItemType.LONG, false); if (!reader.isLastRead()) return false; @@ -314,7 +345,7 @@ Long partitionCounter(int part) { reader.incrementState(); case 6: - topVer = reader.readMessage("topVer"); + timeout = reader.readLong("timeout"); if (!reader.isLastRead()) return false; @@ -322,7 +353,7 @@ Long partitionCounter(int part) { reader.incrementState(); case 7: - topicBytes = reader.readByteArray("topicBytes"); + topVer = reader.readMessage("topVer"); if (!reader.isLastRead()) return false; @@ -330,7 +361,7 @@ Long partitionCounter(int part) { reader.incrementState(); case 8: - updateSeq = reader.readLong("updateSeq"); + topicBytes = reader.readByteArray("topicBytes"); if (!reader.isLastRead()) return false; @@ -338,6 +369,14 @@ Long partitionCounter(int part) { reader.incrementState(); case 9: + updateSeq = reader.readLong("updateSeq"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 10: workerId = reader.readInt("workerId"); if (!reader.isLastRead()) @@ -357,7 +396,7 @@ Long partitionCounter(int part) { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 10; + return 11; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java index b80ad04eb09c1..c04a7b5927329 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java @@ -278,10 +278,16 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage IgniteRebalanceIterator iter; if (sctx == null || sctx.entryIt == null) { - iter = cctx.offheap().rebalanceIterator(part, d.topologyVersion(), d.partitionCounter(part)); + iter = cctx.offheap().rebalanceIterator(part, d.topologyVersion(), + d.isHistorical(part) ? d.partitionCounter(part) : null); + + if (!iter.historical()) { + assert !cctx.shared().database().persistenceEnabled() || !d.isHistorical(part); - if (!iter.historical()) s.clean(part); + } + else + assert cctx.shared().database().persistenceEnabled() && d.isHistorical(part); } else iter = (IgniteRebalanceIterator)sctx.entryIt; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessageV2.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessageV2.java index f4c624d5ccd7c..5cfd6e5bb8e09 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessageV2.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessageV2.java @@ -235,7 +235,6 @@ void addEntry(int p, GridCacheEntryInfo info, GridCacheContext ctx) throws Ignit void addEntry0(int p, GridCacheEntryInfo info, GridCacheContext ctx) throws IgniteCheckedException { assert info != null; assert (info.key() != null || info.keyBytes() != null); - assert info.value() != null; // Need to call this method to initialize info properly. marshalInfo(info, ctx); 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 4c179e660b4af..6cba4f4889df1 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 @@ -218,11 +218,20 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter msgs = new ConcurrentHashMap8<>(); + private ConcurrentMap msgs = new ConcurrentHashMap8<>(); + + /** */ + private volatile IgniteDhtPartitionHistorySuppliersMap partHistSuppliers = new IgniteDhtPartitionHistorySuppliersMap(); /** Forced Rebalance future. */ private GridFutureAdapter forcedRebFut; + /** */ + private volatile Map> partHistReserved; + + /** */ + private volatile IgniteDhtPartitionsToReloadMap partsToReload = new IgniteDhtPartitionsToReloadMap(); + /** * Dummy future created to trigger reassignments if partition * topology changed while preloading. @@ -367,6 +376,15 @@ public boolean dummyReassign() { return (dummy() || forcePreload()) && reassign(); } + /** + * @param cacheId Cache ID. + * @param partId Partition ID. + * @return ID of history supplier node or null if it doesn't exist. + */ + @Nullable public UUID partitionHistorySupplier(int cacheId, int partId) { + return partHistSuppliers.getSupplier(cacheId, partId); + } + /** * @param cacheId Cache ID to check. * @param topVer Topology version. @@ -509,7 +527,7 @@ public void init() throws IgniteInterruptedCheckedException { if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) { DiscoveryCustomMessage msg = ((DiscoveryCustomEvent)discoEvt).customMessage(); - if (msg instanceof DynamicCacheChangeBatch){ + if (msg instanceof DynamicCacheChangeBatch) { assert !F.isEmpty(reqs); exchange = onCacheChangeRequest(crdNode); @@ -678,7 +696,7 @@ private void updateTopologies(boolean crd) throws IgniteCheckedException { exchId.topologyVersion().equals(cacheCtx.startTopologyVersion()); if (updateTop && clientTop != null) - cacheCtx.topology().update(exchId, clientTop.partitionMap(true), clientTop.updateCounters(false)); + cacheCtx.topology().update(this, clientTop.partitionMap(true), clientTop.updateCounters(false), Collections.emptySet()); } top.updateTopologyVersion(exchId, this, updSeq, stopping(cacheCtx.cacheId())); @@ -798,9 +816,10 @@ private void clientOnlyExchange() throws IgniteCheckedException { if (updateTop) { for (GridClientPartitionTopology top : cctx.exchange().clientTopologies()) { if (top.cacheId() == cacheCtx.cacheId()) { - cacheCtx.topology().update(exchId, + cacheCtx.topology().update(this, top.partitionMap(true), - top.updateCounters(false)); + top.updateCounters(false), + Collections.emptySet()); break; } @@ -845,11 +864,15 @@ private void distributedExchange() throws IgniteCheckedException { cacheCtx.preloader().onTopologyChanged(this); } + cctx.database().releaseHistoryForPreloading(); + + // To correctly rebalance when persistence is enabled, it is necessary to reserve history within exchange. + partHistReserved = cctx.database().reserveHistoryForExchange(); + waitPartitionRelease(); boolean topChanged = discoEvt.type() != EVT_DISCOVERY_CUSTOM_EVT || affChangeMsg != null; - //todo check for (GridCacheContext cacheCtx : cctx.cacheContexts()) { if (cacheCtx.isLocal() || stopping(cacheCtx.cacheId())) continue; @@ -1107,6 +1130,11 @@ private void sendLocalPartitions(ClusterNode node) throws IgniteCheckedException GridDhtPartitionsSingleMessage m = cctx.exchange().createPartitionsSingleMessage( node, exchangeId(), clientOnlyExchange, true); + Map> partHistReserved0 = partHistReserved; + + if (partHistReserved0 != null) + m.partitionHistoryCounters(partHistReserved0); + if (exchangeOnChangeGlobalState && changeGlobalStateE != null) m.setException(changeGlobalStateE); @@ -1133,6 +1161,8 @@ private GridDhtPartitionsFullMessage createPartitionsMessage(Collection, Long> localReserved = partHistSuppliers.getReservations(cctx.localNodeId()); + + if (localReserved != null) { + for (Map.Entry, Long> e : localReserved.entrySet()) { + boolean success = cctx.database().reserveHistoryForPreloading( + e.getKey().get1(), e.getKey().get2(), e.getValue()); + + if (!success) { + // TODO: how to handle? + err = new IgniteCheckedException("Could not reserve history"); + } + } + } + + cctx.database().releaseHistoryForExchange(); + if (super.onDone(res, err) && realExchange) { if (log.isDebugEnabled()) log.debug("Completed partition exchange [localNode=" + cctx.localNodeId() + ", exchange= " + this + @@ -1523,8 +1569,9 @@ private void onAffinityInitialized(IgniteInternalFuture maxCntrs = new HashMap<>(); + Map minCntrs = new HashMap<>(); - for (Map.Entry e : msgs.entrySet()) { + for (Map.Entry e : msgs.entrySet()) { assert e.getValue().partitionUpdateCounters(top.cacheId()) != null; for (Map.Entry> e0 : e.getValue().partitionUpdateCounters(top.cacheId()).entrySet()) { @@ -1534,12 +1581,20 @@ private void assignPartitionStates(GridDhtPartitionTopology top) { GridDhtPartitionState state = top.partitionState(uuid, p); - if (state != GridDhtPartitionState.OWNING) + if (state != GridDhtPartitionState.OWNING && state != GridDhtPartitionState.MOVING) continue; - Long cntr = e0.getValue().get1(); + Long cntr = state == GridDhtPartitionState.MOVING ? e0.getValue().get1() : e0.getValue().get2(); if (cntr == null) + cntr = 0L; + + Long minCntr = minCntrs.get(p); + + if (minCntr == null || minCntr > cntr) + minCntrs.put(p, cntr); + + if (state != GridDhtPartitionState.OWNING) continue; CounterWithNodes maxCntr = maxCntrs.get(p); @@ -1555,29 +1610,86 @@ else if (cntr == maxCntr.cnt) for (GridDhtLocalPartition part : top.currentLocalPartitions()) { GridDhtPartitionState state = top.partitionState(cctx.localNodeId(), part.id()); + if (state != GridDhtPartitionState.OWNING && state != GridDhtPartitionState.MOVING) + continue; + + long cntr = state == GridDhtPartitionState.MOVING ? part.initialUpdateCounter() : part.updateCounter(); + + Long minCntr = minCntrs.get(part.id()); + + if (minCntr == null || minCntr > cntr) + minCntrs.put(part.id(), cntr); + if (state != GridDhtPartitionState.OWNING) continue; CounterWithNodes maxCntr = maxCntrs.get(part.id()); - if (maxCntr == null || part.initialUpdateCounter() > maxCntr.cnt) - maxCntrs.put(part.id(), new CounterWithNodes(part.updateCounter(), cctx.localNodeId())); - else if (part.initialUpdateCounter() == maxCntr.cnt) + if (maxCntr == null || cntr > maxCntr.cnt) + maxCntrs.put(part.id(), new CounterWithNodes(cntr, cctx.localNodeId())); + else if (cntr == maxCntr.cnt) maxCntr.nodes.add(cctx.localNodeId()); } int entryLeft = maxCntrs.size(); + Map> partHistReserved0 = partHistReserved; + + Map localReserved = partHistReserved0 != null ? partHistReserved0.get(top.cacheId()) : null; + + Set haveHistory = new HashSet<>(); + + for (Map.Entry e : minCntrs.entrySet()) { + int p = e.getKey(); + long minCntr = e.getValue(); + + CounterWithNodes maxCntrObj = maxCntrs.get(p); + + long maxCntr = maxCntrObj != null ? maxCntrObj.cnt : 0; + + // If minimal counter is zero, do clean preloading. + if (minCntr == 0 || minCntr == maxCntr) + continue; + + if (localReserved != null) { + Long localCntr = localReserved.get(p); + + if (localCntr != null && localCntr <= minCntr && + maxCntrObj.nodes.contains(cctx.localNodeId())) { + partHistSuppliers.put(cctx.localNodeId(), top.cacheId(), p, minCntr); + + haveHistory.add(p); + + continue; + } + } + + for (Map.Entry e0 : msgs.entrySet()) { + Long histCntr = e0.getValue().partitionHistoryCounters(top.cacheId()).get(p); + + if (histCntr != null && histCntr <= minCntr && maxCntrObj.nodes.contains(e0.getKey())) { + partHistSuppliers.put(e0.getKey(), top.cacheId(), p, minCntr); + + haveHistory.add(p); + + break; + } + } + } + for (Map.Entry e : maxCntrs.entrySet()) { int p = e.getKey(); long maxCntr = e.getValue().cnt; - entryLeft --; + entryLeft--; if (entryLeft != 0 && maxCntr == 0) continue; - top.setOwners(p, e.getValue().nodes, entryLeft == 0); + Set nodesToReload = top.setOwners(p, e.getValue().nodes, haveHistory.contains(p), entryLeft == 0); + + for (UUID nodeId : nodesToReload) + partsToReload.put(nodeId, top.cacheId(), p); } } @@ -1618,6 +1730,8 @@ private void onAllReceived() { try { assert crd.isLocal(); + assert partHistSuppliers.isEmpty(); + if (!crd.equals(cctx.discovery().serverNodes(topologyVersion()).get(0))) { for (GridCacheContext cacheCtx : cctx.cacheContexts()) { if (!cacheCtx.isLocal()) @@ -1818,6 +1932,10 @@ private void processMessage(ClusterNode node, GridDhtPartitionsFullMessage msg) private void updatePartitionFullMap(GridDhtPartitionsFullMessage msg) { cctx.versions().onExchange(msg.lastVersion().order()); + assert partHistSuppliers.isEmpty(); + + partHistSuppliers.putAll(msg.partitionHistorySuppliers()); + for (Map.Entry entry : msg.partitions().entrySet()) { Integer cacheId = entry.getKey(); @@ -1826,12 +1944,13 @@ private void updatePartitionFullMap(GridDhtPartitionsFullMessage msg) { GridCacheContext cacheCtx = cctx.cacheContext(cacheId); if (cacheCtx != null) - cacheCtx.topology().update(exchId, entry.getValue(), cntrMap); + cacheCtx.topology().update(this, entry.getValue(), cntrMap, + msg.partsToReload(cctx.localNodeId(), cacheId)); else { ClusterNode oldest = cctx.discovery().oldestAliveCacheServerNode(AffinityTopologyVersion.NONE); if (oldest != null && oldest.isLocal()) - cctx.exchange().clientTopology(cacheId, this).update(exchId, entry.getValue(), cntrMap); + cctx.exchange().clientTopology(cacheId, this).update(this, entry.getValue(), cntrMap, Collections.emptySet()); } } } @@ -2014,7 +2133,7 @@ public void onNodeLeft(final ClusterNode node) { } if (crd0.isLocal()) { - if (exchangeOnChangeGlobalState && changeGlobalStateE !=null) + if (exchangeOnChangeGlobalState && changeGlobalStateE != null) changeGlobalStateExceptions.put(crd0.id(), changeGlobalStateE); if (allReceived) { 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 9ef9c8debd498..cd731cf6073bf 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 @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Set; import java.util.UUID; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.GridDirectMap; @@ -62,11 +63,27 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa /** Partitions update counters. */ @GridToStringInclude @GridDirectTransient - private Map>> partCntrs; + private IgniteDhtPartitionCountersMap partCntrs; /** Serialized partitions counters. */ private byte[] partCntrsBytes; + /** Partitions history suppliers. */ + @GridToStringInclude + @GridDirectTransient + private IgniteDhtPartitionHistorySuppliersMap partHistSuppliers; + + /** Serialized partitions history suppliers. */ + private byte[] partHistSuppliersBytes; + + /** Partitions that must be cleared and re-loaded. */ + @GridToStringInclude + @GridDirectTransient + private IgniteDhtPartitionsToReloadMap partsToReload; + + /** Serialized partitions that must be cleared and re-loaded. */ + private byte[] partsToReloadBytes; + /** Topology version. */ private AffinityTopologyVersion topVer; @@ -96,12 +113,16 @@ public GridDhtPartitionsFullMessage() { */ public GridDhtPartitionsFullMessage(@Nullable GridDhtPartitionExchangeId id, @Nullable GridCacheVersion lastVer, - @NotNull AffinityTopologyVersion topVer) { + @NotNull AffinityTopologyVersion topVer, + @Nullable IgniteDhtPartitionHistorySuppliersMap partHistSuppliers, + @Nullable IgniteDhtPartitionsToReloadMap partsToReload) { super(id, lastVer); assert id == null || topVer.equals(id.topologyVersion()); this.topVer = topVer; + this.partHistSuppliers = partHistSuppliers; + this.partsToReload = partsToReload; } /** @@ -159,10 +180,9 @@ public void addFullPartitionsMap(int cacheId, GridDhtPartitionFullMap fullMap, @ */ public void addPartitionUpdateCounters(int cacheId, Map> cntrMap) { if (partCntrs == null) - partCntrs = new HashMap<>(); + partCntrs = new IgniteDhtPartitionCountersMap(); - if (!partCntrs.containsKey(cacheId)) - partCntrs.put(cacheId, cntrMap); + partCntrs.putIfAbsent(cacheId, cntrMap); } /** @@ -171,14 +191,29 @@ public void addPartitionUpdateCounters(int cacheId, Map> */ @Override public Map> partitionUpdateCounters(int cacheId) { if (partCntrs != null) { - Map> res = partCntrs.get(cacheId); - - return res != null ? res : Collections.>emptyMap(); + return partCntrs.get(cacheId); } return Collections.emptyMap(); } + /** + * + */ + public IgniteDhtPartitionHistorySuppliersMap partitionHistorySuppliers() { + if (partHistSuppliers == null) + return IgniteDhtPartitionHistorySuppliersMap.empty(); + + return partHistSuppliers; + } + + public Set partsToReload(UUID nodeId, int cacheId) { + if (partsToReload == null) + return Collections.emptySet(); + + return partsToReload.get(nodeId, cacheId); + } + /** * */ @@ -199,11 +234,15 @@ public void setExceptionsMap(Map exs) { boolean marshal = (parts != null && partsBytes == null) || (partCntrs != null && partCntrsBytes == null) || + (partHistSuppliers != null && partHistSuppliersBytes == null) || + (partsToReload != null && partsToReloadBytes == null) || (exs != null && exsBytes == null); if (marshal) { byte[] partsBytes0 = null; byte[] partCntrsBytes0 = null; + byte[] partHistSuppliersBytes0 = null; + byte[] partsToReloadBytes0 = null; byte[] exsBytes0 = null; if (parts != null && partsBytes == null) @@ -212,6 +251,12 @@ public void setExceptionsMap(Map exs) { if (partCntrs != null && partCntrsBytes == null) partCntrsBytes0 = U.marshal(ctx, partCntrs); + if (partHistSuppliers != null && partHistSuppliersBytes == null) + partHistSuppliersBytes0 = U.marshal(ctx, partHistSuppliers); + + if (partsToReload != null && partsToReloadBytes == null) + partsToReloadBytes0 = U.marshal(ctx, partsToReload); + if (exs != null && exsBytes == null) exsBytes0 = U.marshal(ctx, exs); @@ -221,10 +266,14 @@ public void setExceptionsMap(Map exs) { try { byte[] partsBytesZip = U.zip(partsBytes0); byte[] partCntrsBytesZip = U.zip(partCntrsBytes0); + byte[] partHistSuppliersBytesZip = U.zip(partHistSuppliersBytes0); + byte[] partsToReloadBytesZip = U.zip(partsToReloadBytes0); byte[] exsBytesZip = U.zip(exsBytes0); partsBytes0 = partsBytesZip; partCntrsBytes0 = partCntrsBytesZip; + partHistSuppliersBytes0 = partHistSuppliersBytesZip; + partsToReloadBytes0 = partsToReloadBytesZip; exsBytes0 = exsBytesZip; compressed(true); @@ -236,6 +285,8 @@ public void setExceptionsMap(Map exs) { partsBytes = partsBytes0; partCntrsBytes = partCntrsBytes0; + partHistSuppliersBytes = partHistSuppliersBytes0; + partsToReloadBytes = partsToReloadBytes0; exsBytes = exsBytes0; } } @@ -302,10 +353,24 @@ public void topologyVersion(AffinityTopologyVersion topVer) { partCntrs = U.unmarshal(ctx, partCntrsBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); } + if (partHistSuppliersBytes != null && partHistSuppliers == null) { + if (compressed()) + partHistSuppliers = U.unmarshalZip(ctx.marshaller(), partHistSuppliersBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); + else + partHistSuppliers = U.unmarshal(ctx, partHistSuppliersBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); + } + + if (partsToReloadBytes != null && partsToReload == null) { + if (compressed()) + partsToReload = U.unmarshalZip(ctx.marshaller(), partsToReloadBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); + else + partsToReload = U.unmarshal(ctx, partsToReloadBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); + } + if (partCntrs == null) - partCntrs = new HashMap<>(); + partCntrs = new IgniteDhtPartitionCountersMap(); - if (exsBytes != null && exs == null){ + if (exsBytes != null && exs == null) { if (compressed()) exs = U.unmarshalZip(ctx.marshaller(), exsBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); else @@ -350,12 +415,24 @@ public void topologyVersion(AffinityTopologyVersion topVer) { writer.incrementState(); case 9: - if (!writer.writeByteArray("partsBytes", partsBytes)) + if (!writer.writeByteArray("partHistSuppliersBytes", partHistSuppliersBytes)) return false; writer.incrementState(); case 10: + if (!writer.writeByteArray("partsBytes", partsBytes)) + return false; + + writer.incrementState(); + + case 11: + if (!writer.writeByteArray("partsToReloadBytes", partsToReloadBytes)) + return false; + + writer.incrementState(); + + case 12: if (!writer.writeMessage("topVer", topVer)) return false; @@ -402,7 +479,7 @@ public void topologyVersion(AffinityTopologyVersion topVer) { reader.incrementState(); case 9: - partsBytes = reader.readByteArray("partsBytes"); + partHistSuppliersBytes = reader.readByteArray("partHistSuppliersBytes"); if (!reader.isLastRead()) return false; @@ -410,6 +487,22 @@ public void topologyVersion(AffinityTopologyVersion topVer) { reader.incrementState(); case 10: + partsBytes = reader.readByteArray("partsBytes"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 11: + partsToReloadBytes = reader.readByteArray("partsToReloadBytes"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 12: topVer = reader.readMessage("topVer"); if (!reader.isLastRead()) @@ -428,9 +521,10 @@ public void topologyVersion(AffinityTopologyVersion topVer) { } //todo + /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 11; + return 13; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java index 2f16c8cd54dae..8df74663fc876 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java @@ -65,6 +65,14 @@ public class GridDhtPartitionsSingleMessage extends GridDhtPartitionsAbstractMes /** Serialized partitions counters. */ private byte[] partCntrsBytes; + /** Partitions history reservation counters. */ + @GridToStringInclude + @GridDirectTransient + private Map> partHistCntrs; + + /** Serialized partitions history reservation counters. */ + private byte[] partHistCntrsBytes; + /** Exception. */ @GridToStringInclude @GridDirectTransient @@ -158,6 +166,43 @@ public void partitionUpdateCounters(int cacheId, Map> cn return Collections.emptyMap(); } + /** + * @param cacheId Cache ID. + * @param cntrMap Partition history counters. + */ + public void partitionHistoryCounters(int cacheId, Map cntrMap) { + if (cntrMap.isEmpty()) + return; + + if (partHistCntrs == null) + partHistCntrs = new HashMap<>(); + + partHistCntrs.put(cacheId, cntrMap); + } + + /** + * @param cntrMap Partition history counters. + */ + public void partitionHistoryCounters(Map> cntrMap) { + for (Map.Entry> e : cntrMap.entrySet()) { + partitionHistoryCounters(e.getKey(), e.getValue()); + } + } + + /** + * @param cacheId Cache ID. + * @return Partition history counters. + */ + public Map partitionHistoryCounters(int cacheId) { + if (partHistCntrs != null) { + Map res = partHistCntrs.get(cacheId); + + return res != null ? res : Collections.emptyMap(); + } + + return Collections.emptyMap(); + } + /** * @return Local partitions. */ @@ -189,11 +234,13 @@ public Exception getException() { boolean marshal = (parts != null && partsBytes == null) || (partCntrs != null && partCntrsBytes == null) || + (partHistCntrs != null && partHistCntrsBytes == null) || (ex != null && exBytes == null); if (marshal) { byte[] partsBytes0 = null; byte[] partCntrsBytes0 = null; + byte[] partHistCntrsBytes0 = null; byte[] exBytes0 = null; if (parts != null && partsBytes == null) @@ -202,6 +249,9 @@ public Exception getException() { if (partCntrs != null && partCntrsBytes == null) partCntrsBytes0 = U.marshal(ctx, partCntrs); + if (partHistCntrs != null && partHistCntrsBytes == null) + partHistCntrsBytes0 = U.marshal(ctx, partHistCntrs); + if (ex != null && exBytes == null) exBytes0 = U.marshal(ctx, ex); @@ -211,10 +261,12 @@ public Exception getException() { try { byte[] partsBytesZip = U.zip(partsBytes0); byte[] partCntrsBytesZip = U.zip(partCntrsBytes0); + byte[] partHistCntrsBytesZip = U.zip(partHistCntrsBytes0); byte[] exBytesZip = U.zip(exBytes0); partsBytes0 = partsBytesZip; partCntrsBytes0 = partCntrsBytesZip; + partHistCntrsBytes0 = partHistCntrsBytesZip; exBytes0 = exBytesZip; compressed(true); @@ -226,6 +278,7 @@ public Exception getException() { partsBytes = partsBytes0; partCntrsBytes = partCntrsBytes0; + partHistCntrsBytes = partHistCntrsBytes0; exBytes = exBytes0; } } @@ -248,6 +301,13 @@ public Exception getException() { partCntrs = U.unmarshal(ctx, partCntrsBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); } + if (partHistCntrsBytes != null && partHistCntrs == null) { + if (compressed()) + partHistCntrs = U.unmarshalZip(ctx.marshaller(), partHistCntrsBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); + else + partHistCntrs = U.unmarshal(ctx, partHistCntrsBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); + } + if (exBytes != null && ex == null) { if (compressed()) ex = U.unmarshalZip(ctx.marshaller(), exBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); @@ -316,6 +376,12 @@ public Exception getException() { writer.incrementState(); case 10: + if (!writer.writeByteArray("partHistCntrsBytes", partHistCntrsBytes)) + return false; + + writer.incrementState(); + + case 11: if (!writer.writeByteArray("partsBytes", partsBytes)) return false; @@ -370,6 +436,14 @@ public Exception getException() { reader.incrementState(); case 10: + partHistCntrsBytes = reader.readByteArray("partHistCntrsBytes"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 11: partsBytes = reader.readByteArray("partsBytes"); if (!reader.isLastRead()) @@ -388,9 +462,10 @@ public Exception getException() { } //todo add ex + /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 11; + return 12; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java index 8ada4b3d74605..55f6bcb8ba768 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java @@ -75,6 +75,7 @@ import static org.apache.ignite.internal.managers.communication.GridIoPolicy.AFFINITY_POOL; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.MOVING; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; +import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.RENTING; import static org.apache.ignite.internal.util.GridConcurrentFactory.newMap; /** @@ -235,6 +236,7 @@ public GridDhtPreloader(GridCacheContext cctx) { top = null; } + /** * @return Node stop exception. */ @@ -270,8 +272,8 @@ private IgniteCheckedException stopError() { assert exchFut.forcePreload() || exchFut.dummyReassign() || exchFut.exchangeId().topologyVersion().equals(top.topologyVersion()) : "Topology version mismatch [exchId=" + exchFut.exchangeId() + - ", cache=" + cctx.name() + - ", topVer=" + top.topologyVersion() + ']'; + ", cache=" + cctx.name() + + ", topVer=" + top.topologyVersion() + ']'; GridDhtPreloaderAssignments assigns = new GridDhtPreloaderAssignments(exchFut, top.topologyVersion()); @@ -290,47 +292,95 @@ private IgniteCheckedException stopError() { // If partition belongs to local node. if (cctx.affinity().partitionLocalNode(p, topVer)) { - GridDhtLocalPartition part = top.localPartition(p, topVer, true); + GridDhtLocalPartition part = top.localPartition(p, topVer, true, true); assert part != null; assert part.id() == p; - if (part.state() != MOVING) { - if (log.isDebugEnabled()) - log.debug("Skipping partition assignment (state is not MOVING): " + part); - - continue; // For. - } + ClusterNode histSupplier = null; - Collection picked = pickedOwners(p, topVer); + if (cctx.shared().database().persistenceEnabled()) { + UUID nodeId = exchFut.partitionHistorySupplier(cctx.cacheId(), p); - if (picked.isEmpty()) { - top.own(part); + if (nodeId != null) + histSupplier = cctx.discovery().node(nodeId); + } - if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_PART_DATA_LOST)) { - DiscoveryEvent discoEvt = exchFut.discoveryEvent(); + if (histSupplier != null) { + if (part.state() != MOVING) { + if (log.isDebugEnabled()) + log.debug("Skipping partition assignment (state is not MOVING): " + part); - cctx.events().addPreloadEvent(p, - EVT_CACHE_REBALANCE_PART_DATA_LOST, discoEvt.eventNode(), - discoEvt.type(), discoEvt.timestamp()); + continue; // For. } - if (log.isDebugEnabled()) - log.debug("Owning partition as there are no other owners: " + part); - } - else { - ClusterNode n = F.rand(picked); + assert cctx.shared().database().persistenceEnabled(); + assert remoteOwners(p, topVer).contains(histSupplier) : remoteOwners(p, topVer); - GridDhtPartitionDemandMessage msg = assigns.get(n); + GridDhtPartitionDemandMessage msg = assigns.get(histSupplier); if (msg == null) { - assigns.put(n, msg = new GridDhtPartitionDemandMessage( + assigns.put(histSupplier, msg = new GridDhtPartitionDemandMessage( top.updateSequence(), exchFut.exchangeId().topologyVersion(), cctx.cacheId())); } - msg.addPartition(p); + msg.addPartition(p, true); + } + else { + if (cctx.shared().database().persistenceEnabled()) { + if (part.state() == RENTING || part.state() == EVICTED) { + try { + part.rent(false).get(); + } + catch (IgniteCheckedException e) { + U.error(log, "Error while clearing outdated local partition", e); + } + + part = top.localPartition(p, topVer, true); + + assert part != null; + } + } + + if (part.state() != MOVING) { + if (log.isDebugEnabled()) + log.debug("Skipping partition assignment (state is not MOVING): " + part); + + continue; // For. + } + + Collection picked = pickedOwners(p, topVer); + + if (picked.isEmpty()) { + top.own(part); + + if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_PART_DATA_LOST)) { + DiscoveryEvent discoEvt = exchFut.discoveryEvent(); + + cctx.events().addPreloadEvent(p, + EVT_CACHE_REBALANCE_PART_DATA_LOST, discoEvt.eventNode(), + discoEvt.type(), discoEvt.timestamp()); + } + + if (log.isDebugEnabled()) + log.debug("Owning partition as there are no other owners: " + part); + } + else { + ClusterNode n = F.rand(picked); + + GridDhtPartitionDemandMessage msg = assigns.get(n); + + if (msg == null) { + assigns.put(n, msg = new GridDhtPartitionDemandMessage( + top.updateSequence(), + exchFut.exchangeId().topologyVersion(), + cctx.cacheId())); + } + + msg.addPartition(p, false); + } } } } @@ -379,7 +429,7 @@ private Collection remoteOwners(int p, AffinityTopologyVersion topV } /** {@inheritDoc} */ - public void handleSupplyMessage(int idx, UUID id, final GridDhtPartitionSupplyMessageV2 s) { + @Override public void handleSupplyMessage(int idx, UUID id, final GridDhtPartitionSupplyMessageV2 s) { if (!enterBusy()) return; @@ -399,7 +449,7 @@ public void handleSupplyMessage(int idx, UUID id, final GridDhtPartitionSupplyMe } /** {@inheritDoc} */ - public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage d) { + @Override public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage d) { if (!enterBusy()) return; @@ -789,7 +839,7 @@ void remoteFuture(GridDhtForceKeysFuture fut) { try { part.tryEvict(); - if (part.state() != EVICTED) + if (part.state() == RENTING) partsToEvict.push(part); } catch (Throwable ex) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersMap.java new file mode 100644 index 0000000000000..9db80ae740c96 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersMap.java @@ -0,0 +1,64 @@ +/* + * 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.dht.preloader; + +import java.io.Serializable; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.apache.ignite.internal.util.typedef.T2; + +/** + * Partition counters map. + */ +public class IgniteDhtPartitionCountersMap implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private Map>> map; + + /** + * @param cacheId Cache ID. + * @param cntrMap Counters map. + */ + public synchronized void putIfAbsent(int cacheId, Map> cntrMap) { + if (map == null) + map = new HashMap<>(); + + if (!map.containsKey(cacheId)) + map.put(cacheId, cntrMap); + } + + /** + * @param cacheId Cache ID. + * @return Counters map. + */ + public synchronized Map> get(int cacheId) { + if (map == null) + map = new HashMap<>(); + + Map> cntrMap = map.get(cacheId); + + if (cntrMap == null) + return Collections.emptyMap(); + + return cntrMap; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionHistorySuppliersMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionHistorySuppliersMap.java new file mode 100644 index 0000000000000..333eb9733b063 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionHistorySuppliersMap.java @@ -0,0 +1,107 @@ +/* + * 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.dht.preloader; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import org.apache.ignite.internal.util.typedef.T2; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class IgniteDhtPartitionHistorySuppliersMap implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private static final IgniteDhtPartitionHistorySuppliersMap EMPTY = new IgniteDhtPartitionHistorySuppliersMap(); + + /** */ + private Map, Long>> map; + + /** + * @return Empty map. + */ + public static IgniteDhtPartitionHistorySuppliersMap empty() { + return EMPTY; + } + + /** + * @param cacheId Cache ID. + * @param partId Partition ID. + * @return Supplier UUID. + */ + @Nullable public synchronized UUID getSupplier(int cacheId, int partId) { + if (map == null) + return null; + + for (Map.Entry, Long>> e : map.entrySet()) { + if (e.getValue().containsKey(new T2<>(cacheId, partId))) + return e.getKey(); + } + + return null; + } + + /** + * @param nodeId Node ID to check. + * @return Reservations for the given node. + */ + @Nullable public synchronized Map, Long> getReservations(UUID nodeId) { + if (map == null) + return null; + + return map.get(nodeId); + } + + /** + * @param nodeId Node ID. + * @param cacheId Cache ID. + * @param partId Partition ID. + * @param cntr Partition counter. + */ + public synchronized void put(UUID nodeId, int cacheId, int partId, long cntr) { + Map, Long> nodeMap = map.get(nodeId); + + if (nodeMap == null) { + nodeMap = new HashMap<>(); + + map.put(nodeId, nodeMap); + } + + nodeMap.put(new T2<>(cacheId, partId), cntr); + } + + /** + * @return {@code True} if empty. + */ + public synchronized boolean isEmpty() { + return map == null || map.isEmpty(); + } + + /** + * @param that Other map to put. + */ + public synchronized void putAll(IgniteDhtPartitionHistorySuppliersMap that) { + map = that.map; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionsToReloadMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionsToReloadMap.java new file mode 100644 index 0000000000000..2a72e957b6b6d --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionsToReloadMap.java @@ -0,0 +1,88 @@ +/* + * 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.dht.preloader; + +import java.io.Serializable; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +/** + * Partition reload map. + */ +public class IgniteDhtPartitionsToReloadMap implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private Map>> map; + + /** + * @param nodeId Node ID. + * @param cacheId Cache ID. + * @return Collection of partitions to reload. + */ + public synchronized Set get(UUID nodeId, int cacheId) { + if (map == null) + return Collections.emptySet(); + + Map> nodeMap = map.get(nodeId); + + if (nodeMap == null) + return Collections.emptySet(); + + Set parts = nodeMap.get(cacheId); + + if (parts == null) + return Collections.emptySet(); + + return parts; + } + + /** + * @param nodeId Node ID. + * @param cacheId Cache ID. + * @param partId Partition ID. + */ + public synchronized void put(UUID nodeId, int cacheId, int partId) { + if (map == null) + map = new HashMap<>(); + + Map> nodeMap = map.get(nodeId); + + if (nodeMap == null) { + nodeMap = new HashMap<>(); + + map.put(nodeId, nodeMap); + } + + Set parts = nodeMap.get(cacheId); + + if (parts == null) { + parts = new HashSet<>(); + + nodeMap.put(cacheId, parts); + } + + parts.add(partId); + } +} From 423466736904b55a6d4397aa6268fff5a9ee5ea9 Mon Sep 17 00:00:00 2001 From: Igor Seliverstov Date: Thu, 9 Mar 2017 21:01:41 +0300 Subject: [PATCH 076/311] ignite-4779 Missed discovery data snapshot during exchange processing (do not use discovery manager cache to handle exchange) (cherry picked from commit a61a98ad3908770b77d0ffb071effbc92f4d5c5a) --- .../managers/discovery/DiscoCache.java | 310 ++++++++ .../discovery/GridDiscoveryManager.java | 680 +++++------------- .../eventstorage/DiscoveryEventListener.java | 33 + .../eventstorage/GridEventStorageManager.java | 162 ++++- .../affinity/GridAffinityAssignmentCache.java | 7 +- .../cache/CacheAffinitySharedManager.java | 35 +- .../cache/GridCacheAffinityManager.java | 3 +- .../GridCachePartitionExchangeManager.java | 73 +- .../dht/GridClientPartitionTopology.java | 20 +- .../dht/GridDhtAssignmentFetchFuture.java | 7 +- .../dht/GridDhtPartitionTopologyImpl.java | 40 +- .../GridDhtPartitionsExchangeFuture.java | 30 +- .../service/GridServiceProcessor.java | 21 +- ...ridDiscoveryManagerAliveCacheSelfTest.java | 14 - 14 files changed, 808 insertions(+), 627 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoCache.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/DiscoveryEventListener.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoCache.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoCache.java new file mode 100644 index 0000000000000..5247ac1b28091 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoCache.java @@ -0,0 +1,310 @@ +/* + * 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.managers.discovery; + +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.util.GridConcurrentHashSet; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.P1; +import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class DiscoCache { + /** Local node. */ + private final ClusterNode loc; + + /** Remote nodes. */ + private final List rmtNodes; + + /** All nodes. */ + private final List allNodes; + + /** All server nodes. */ + private final List srvNodes; + + /** Daemon nodes. */ + private final List daemonNodes; + + /** All server nodes. */ + private final List srvNodesWithCaches; + + /** All nodes with at least one cache configured. */ + @GridToStringInclude + private final List allNodesWithCaches; + + /** All remote nodes with at least one cache configured. */ + @GridToStringInclude + private final List rmtNodesWithCaches; + + /** Cache nodes by cache name. */ + @GridToStringInclude + private final Map> allCacheNodes; + + /** Affinity cache nodes by cache name. */ + @GridToStringInclude + private final Map> affCacheNodes; + + /** Node map. */ + private final Map nodeMap; + + /** Caches where at least one node has near cache enabled. */ + @GridToStringInclude + private final Set nearEnabledCaches; + + /** Alive nodes. */ + private final Set alives = new GridConcurrentHashSet<>(); + + /** + * @param loc Local node. + * @param rmtNodes Remote nodes. + * @param allNodes All nodes. + * @param srvNodes Server nodes. + * @param daemonNodes Daemon nodes. + * @param srvNodesWithCaches Server nodes with at least one cache configured. + * @param allNodesWithCaches All nodes with at least one cache configured. + * @param rmtNodesWithCaches Remote nodes with at least one cache configured. + * @param allCacheNodes Cache nodes by cache name. + * @param affCacheNodes Affinity cache nodes by cache name. + * @param nodeMap Node map. + * @param nearEnabledCaches Caches where at least one node has near cache enabled. + * @param alives Alive nodes. + */ + DiscoCache(ClusterNode loc, + List rmtNodes, + List allNodes, + List srvNodes, + List daemonNodes, + List srvNodesWithCaches, + List allNodesWithCaches, + List rmtNodesWithCaches, + Map> allCacheNodes, + Map> affCacheNodes, + Map nodeMap, + Set nearEnabledCaches, + Set alives) { + this.loc = loc; + this.rmtNodes = rmtNodes; + this.allNodes = allNodes; + this.srvNodes = srvNodes; + this.daemonNodes = daemonNodes; + this.srvNodesWithCaches = srvNodesWithCaches; + this.allNodesWithCaches = allNodesWithCaches; + this.rmtNodesWithCaches = rmtNodesWithCaches; + this.allCacheNodes = allCacheNodes; + this.affCacheNodes = affCacheNodes; + this.nodeMap = nodeMap; + this.nearEnabledCaches = nearEnabledCaches; + this.alives.addAll(alives); + } + + /** @return Local node. */ + public ClusterNode localNode() { + return loc; + } + + /** @return Remote nodes. */ + public List remoteNodes() { + return rmtNodes; + } + + /** @return All nodes. */ + public List allNodes() { + return allNodes; + } + + /** @return Server nodes. */ + public List serverNodes() { + return srvNodes; + } + + /** @return Daemon nodes. */ + public List daemonNodes() { + return daemonNodes; + } + + /** @return Server nodes with at least one cache configured. */ + public List serverNodesWithCaches() { + return srvNodesWithCaches; + } + + /** + * Gets all remote nodes that have at least one cache configured. + * + * @return Collection of nodes. + */ + public List remoteNodesWithCaches() { + return rmtNodesWithCaches; + } + + /** + * Gets collection of nodes with at least one cache configured. + * + * @return Collection of nodes. + */ + public List allNodesWithCaches() { + return allNodesWithCaches; + } + + /** + * Gets collection of server nodes with at least one cache configured. + * + * @return Collection of nodes. + */ + public Collection aliveServerNodes() { + return F.view(serverNodes(), new P1() { + @Override public boolean apply(ClusterNode node) { + return alives.contains(node.id()); + } + }); + } + + /** + * Gets collection of server nodes with at least one cache configured. + * + * @return Collection of nodes. + */ + public Collection aliveServerNodesWithCaches() { + return F.view(serverNodesWithCaches(), new P1() { + @Override public boolean apply(ClusterNode node) { + return alives.contains(node.id()); + } + }); + } + + /** + * @return Oldest alive server node. + */ + public @Nullable ClusterNode oldestAliveServerNode(){ + Iterator it = aliveServerNodes().iterator(); + return it.hasNext() ? it.next() : null; + } + + /** + * @return Oldest alive server node with at least one cache configured. + */ + public @Nullable ClusterNode oldestAliveServerNodeWithCache(){ + Iterator it = aliveServerNodesWithCaches().iterator(); + return it.hasNext() ? it.next() : null; + } + + /** + * Gets all nodes that have cache with given name. + * + * @param cacheName Cache name. + * @return Collection of nodes. + */ + public List cacheNodes(@Nullable String cacheName) { + return cacheNodes(CU.cacheId(cacheName)); + } + + /** + * Gets all nodes that have cache with given ID. + * + * @param cacheId Cache ID. + * @return Collection of nodes. + */ + public List cacheNodes(Integer cacheId) { + return emptyIfNull(allCacheNodes.get(cacheId)); + } + + /** + * Gets all nodes that have cache with given ID and should participate in affinity calculation. With + * partitioned cache nodes with near-only cache do not participate in affinity node calculation. + * + * @param cacheName Cache name. + * @return Collection of nodes. + */ + public List cacheAffinityNodes(@Nullable String cacheName) { + return cacheAffinityNodes(CU.cacheId(cacheName)); + } + + /** + * Gets all nodes that have cache with given ID and should participate in affinity calculation. With + * partitioned cache nodes with near-only cache do not participate in affinity node calculation. + * + * @param cacheId Cache ID. + * @return Collection of nodes. + */ + public List cacheAffinityNodes(int cacheId) { + return emptyIfNull(affCacheNodes.get(cacheId)); + } + + /** + * Checks if cache with given ID has at least one node with near cache enabled. + * + * @param cacheId Cache ID. + * @return {@code True} if cache with given name has at least one node with near cache enabled. + */ + public boolean hasNearCache(int cacheId) { + return nearEnabledCaches.contains(cacheId); + } + + /** + * @param id Node ID. + * @return Node. + */ + public @Nullable ClusterNode node(UUID id) { + return nodeMap.get(id); + } + + /** + * Removes left node from alives lists. + * + * @param rmvd Removed node. + */ + public void updateAlives(ClusterNode rmvd) { + alives.remove(rmvd.id()); + } + + /** + * Removes left nodes from cached alives lists. + * + * @param discovery Discovery manager. + */ + public void updateAlives(GridDiscoveryManager discovery) { + for (UUID alive : alives) { + if (!discovery.alive(alive)) + alives.remove(alive); + } + } + + /** + * @param nodes Cluster nodes. + * @return Empty collection if nodes list is {@code null} + */ + private List emptyIfNull(List nodes) { + return nodes == null ? Collections.emptyList() : nodes; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(DiscoCache.class, this); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java index 218aff02db180..960a064251368 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java @@ -35,14 +35,12 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.NavigableMap; import java.util.Set; -import java.util.TreeMap; +import java.util.TreeSet; import java.util.UUID; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; @@ -79,19 +77,17 @@ import org.apache.ignite.internal.processors.security.SecurityContext; import org.apache.ignite.internal.processors.service.GridServiceProcessor; import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor; -import org.apache.ignite.internal.util.F0; import org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap; import org.apache.ignite.internal.util.GridSpinBusyLock; import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.internal.util.future.GridFutureAdapter; -import org.apache.ignite.internal.util.lang.GridTuple5; +import org.apache.ignite.internal.util.lang.GridTuple6; import org.apache.ignite.internal.util.tostring.GridToStringExclude; -import org.apache.ignite.internal.util.tostring.GridToStringInclude; -import org.apache.ignite.internal.util.typedef.C1; import org.apache.ignite.internal.util.typedef.CI1; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.G; import org.apache.ignite.internal.util.typedef.P1; +import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.LT; import org.apache.ignite.internal.util.typedef.internal.S; @@ -100,7 +96,6 @@ import org.apache.ignite.lang.IgniteFuture; import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.lang.IgnitePredicate; -import org.apache.ignite.lang.IgniteProductVersion; import org.apache.ignite.lang.IgniteUuid; import org.apache.ignite.plugin.security.SecurityCredentials; import org.apache.ignite.plugin.segmentation.SegmentationPolicy; @@ -114,6 +109,7 @@ import org.apache.ignite.spi.discovery.DiscoverySpiNodeAuthenticator; import org.apache.ignite.spi.discovery.DiscoverySpiOrderSupport; import org.apache.ignite.thread.IgniteThread; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jsr166.ConcurrentHashMap8; @@ -235,7 +231,7 @@ public class GridDiscoveryManager extends GridManagerAdapter { private long segChkFreq; /** Local node join to topology event. */ - private GridFutureAdapter locJoinEvt = new GridFutureAdapter<>(); + private GridFutureAdapter> locJoin = new GridFutureAdapter<>(); /** GC CPU load. */ private volatile double gcCpuLoad; @@ -560,20 +556,25 @@ customMsg, new AffinityTopologyVersion(topVer, minorTopVer) } } + final DiscoCache discoCache; + // Put topology snapshot into discovery history. // There is no race possible between history maintenance and concurrent discovery // event notifications, since SPI notifies manager about all events from this listener. if (verChanged) { - DiscoCache cache = new DiscoCache(locNode, F.view(topSnapshot, F.remoteNodes(locNode.id()))); + discoCache = createDiscoCache(locNode, topSnapshot); - discoCacheHist.put(nextTopVer, cache); + discoCacheHist.put(nextTopVer, discoCache); - boolean set = updateTopologyVersionIfGreater(nextTopVer, cache); + boolean set = updateTopologyVersionIfGreater(nextTopVer, discoCache); assert set || topVer == 0 : "Topology version has not been updated [this.topVer=" + topSnap + ", topVer=" + topVer + ", node=" + node + ", evt=" + U.gridEventName(type) + ']'; } + else + // Current version. + discoCache = discoCache(); // If this is a local join event, just save it and do not notify listeners. if (type == EVT_NODE_JOINED && node.id().equals(locNode.id())) { @@ -581,7 +582,7 @@ customMsg, new AffinityTopologyVersion(topVer, minorTopVer) gridStartTime = getSpi().getGridStartTime(); updateTopologyVersionIfGreater(new AffinityTopologyVersion(locNode.order()), - new DiscoCache(localNode(), F.view(topSnapshot, F.remoteNodes(locNode.id())))); + discoCache); startLatch.countDown(); @@ -591,14 +592,9 @@ customMsg, new AffinityTopologyVersion(topVer, minorTopVer) discoEvt.eventNode(node); discoEvt.type(EVT_NODE_JOINED); - discoEvt.topologySnapshot(topVer, new ArrayList<>( - F.viewReadOnly(topSnapshot, new C1() { - @Override public ClusterNode apply(ClusterNode e) { - return e; - } - }, FILTER_DAEMON))); + discoEvt.topologySnapshot(topVer, new ArrayList<>(F.view(topSnapshot, FILTER_DAEMON))); - locJoinEvt.onDone(discoEvt); + locJoin.onDone(new T2<>(discoEvt, discoCache)); return; } @@ -613,7 +609,7 @@ else if (type == EVT_CLIENT_NODE_DISCONNECTED) { ((IgniteKernal)ctx.grid()).onDisconnected(); - locJoinEvt = new GridFutureAdapter<>(); + locJoin = new GridFutureAdapter<>(); registeredCaches.clear(); @@ -626,7 +622,7 @@ else if (type == EVT_CLIENT_NODE_DISCONNECTED) { topHist.clear(); topSnap.set(new Snapshot(AffinityTopologyVersion.ZERO, - new DiscoCache(locNode, Collections.emptySet()))); + createDiscoCache(locNode, Collections.emptySet()))); } else if (type == EVT_CLIENT_NODE_RECONNECTED) { assert locNode.isClient() : locNode; @@ -643,7 +639,7 @@ else if (type == EVT_CLIENT_NODE_RECONNECTED) { try { fut.get(); - discoWrk.addEvent(type, nextTopVer, node, topSnapshot, null); + discoWrk.addEvent(type, nextTopVer, node, discoCache, topSnapshot, null); } catch (IgniteException ignore) { // No-op. @@ -655,7 +651,7 @@ else if (type == EVT_CLIENT_NODE_RECONNECTED) { } if (type == EVT_CLIENT_NODE_DISCONNECTED || type == EVT_NODE_SEGMENTED || !ctx.clientDisconnected()) - discoWrk.addEvent(type, nextTopVer, node, topSnapshot, customMsg); + discoWrk.addEvent(type, nextTopVer, node, discoCache, topSnapshot, customMsg); } }); @@ -1372,8 +1368,8 @@ private String topologySnapshotMessage(long topVer, int srvNodesNum, int clientN U.join(segChkThread, log); } - if (!locJoinEvt.isDone()) - locJoinEvt.onDone( + if (!locJoin.isDone()) + locJoin.onDone( new IgniteCheckedException("Failed to wait for local node joined event (grid is stopping).")); } @@ -1567,7 +1563,7 @@ public IgniteInternalFuture topologyFuture(final long awaitVer) { * * @return Discovery collection cache. */ - private DiscoCache discoCache() { + public DiscoCache discoCache() { Snapshot cur = topSnap.get(); assert cur != null; @@ -1619,14 +1615,6 @@ public Collection nodes(AffinityTopologyVersion topVer) { return resolveDiscoCache(null, topVer).allNodes(); } - /** - * @param topVer Topology version. - * @return All server nodes for given topology version. - */ - public List serverNodes(AffinityTopologyVersion topVer) { - return resolveDiscoCache(null, topVer).srvNodes; - } - /** * Gets node from history for given topology version. * @@ -1646,7 +1634,7 @@ public ClusterNode node(AffinityTopologyVersion topVer, UUID id) { * @return Collection of cache nodes. */ public Collection cacheNodes(@Nullable String cacheName, AffinityTopologyVersion topVer) { - return resolveDiscoCache(cacheName, topVer).cacheNodes(cacheName, topVer.topologyVersion()); + return resolveDiscoCache(cacheName, topVer).cacheNodes(cacheName); } /** @@ -1656,7 +1644,7 @@ public Collection cacheNodes(@Nullable String cacheName, AffinityTo * @return Collection of cache nodes. */ public Collection cacheNodes(AffinityTopologyVersion topVer) { - return resolveDiscoCache(null, topVer).allNodesWithCaches(topVer.topologyVersion()); + return resolveDiscoCache(null, topVer).allNodesWithCaches(); } /** @@ -1666,29 +1654,7 @@ public Collection cacheNodes(AffinityTopologyVersion topVer) { * @return Collection of cache nodes. */ public Collection remoteCacheNodes(AffinityTopologyVersion topVer) { - return resolveDiscoCache(null, topVer).remoteCacheNodes(topVer.topologyVersion()); - } - - /** - * Gets cache nodes for cache with given name. - * - * @param cacheName Cache name. - * @param topVer Topology version. - * @return Collection of cache nodes. - */ - Collection aliveCacheNodes(@Nullable String cacheName, AffinityTopologyVersion topVer) { - return resolveDiscoCache(cacheName, topVer).aliveCacheNodes(cacheName, topVer.topologyVersion()); - } - - /** - * Gets cache remote nodes for cache with given name. - * - * @param cacheName Cache name. - * @param topVer Topology version. - * @return Collection of cache nodes. - */ - Collection aliveRemoteCacheNodes(@Nullable String cacheName, AffinityTopologyVersion topVer) { - return resolveDiscoCache(cacheName, topVer).aliveRemoteCacheNodes(cacheName, topVer.topologyVersion()); + return resolveDiscoCache(null, topVer).remoteNodesWithCaches(); } /** @@ -1696,11 +1662,7 @@ Collection aliveRemoteCacheNodes(@Nullable String cacheName, Affini * @return Oldest alive server nodes with at least one cache configured. */ @Nullable public ClusterNode oldestAliveCacheServerNode(AffinityTopologyVersion topVer) { - DiscoCache cache = resolveDiscoCache(null, topVer); - - Map.Entry e = cache.aliveSrvNodesWithCaches.firstEntry(); - - return e != null ? e.getKey() : null; + return resolveDiscoCache(null, topVer).oldestAliveServerNodeWithCache(); } /** @@ -1711,7 +1673,7 @@ Collection aliveRemoteCacheNodes(@Nullable String cacheName, Affini * @return Collection of cache affinity nodes. */ public Collection cacheAffinityNodes(@Nullable String cacheName, AffinityTopologyVersion topVer) { - return resolveDiscoCache(cacheName, topVer).cacheAffinityNodes(cacheName, topVer.topologyVersion()); + return resolveDiscoCache(cacheName, topVer).cacheAffinityNodes(cacheName); } /** @@ -1788,7 +1750,7 @@ public Map nodeCaches(ClusterNode node) { * @return {@code True} if cache with given name has at least one node with near cache enabled. */ public boolean hasNearCache(@Nullable String cacheName, AffinityTopologyVersion topVer) { - return resolveDiscoCache(cacheName, topVer).hasNearCache(cacheName); + return resolveDiscoCache(cacheName, topVer).hasNearCache(CU.cacheId(cacheName)); } /** @@ -1874,7 +1836,19 @@ public AffinityTopologyVersion topologyVersionEx() { /** @return Event that represents a local node joined to topology. */ public DiscoveryEvent localJoinEvent() { try { - return locJoinEvt.get(); + return locJoin.get().get1(); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + } + + /** + * @return Tuple that consists of a local join event and discovery cache at the join time. + */ + public T2 localJoin() { + try { + return locJoin.get(); } catch (IgniteCheckedException e) { throw new IgniteException(e); @@ -1947,6 +1921,114 @@ public void failNode(UUID nodeId, @Nullable String warning) { } } + /** + * @param loc Local node. + * @param topSnapshot Topology snapshot. + * @return Newly created discovery cache. + */ + @NotNull private DiscoCache createDiscoCache(ClusterNode loc, Collection topSnapshot) { + HashSet alives = U.newHashSet(topSnapshot.size()); + HashMap nodeMap = U.newHashMap(topSnapshot.size()); + + ArrayList daemonNodes = new ArrayList<>(topSnapshot.size()); + ArrayList srvNodes = new ArrayList<>(topSnapshot.size()); + ArrayList rmtNodes = new ArrayList<>(topSnapshot.size()); + ArrayList allNodes = new ArrayList<>(topSnapshot.size()); + + for (ClusterNode node : topSnapshot) { + if (alive(node)) + alives.add(node.id()); + + if (node.isDaemon()) + daemonNodes.add(node); + else { + allNodes.add(node); + + if (!node.isLocal()) + rmtNodes.add(node); + + if (!CU.clientNode(node)) + srvNodes.add(node); + } + + nodeMap.put(node.id(), node); + } + + assert !rmtNodes.contains(loc) : "Remote nodes collection shouldn't contain local node" + + " [rmtNodes=" + rmtNodes + ", loc=" + loc + ']'; + + Map> allCacheNodes = U.newHashMap(allNodes.size()); + Map> affCacheNodes = U.newHashMap(allNodes.size()); + + Set allNodesWithCaches = new TreeSet<>(GridNodeOrderComparator.INSTANCE); + Set rmtNodesWithCaches = new TreeSet<>(GridNodeOrderComparator.INSTANCE); + Set srvNodesWithCaches = new TreeSet<>(GridNodeOrderComparator.INSTANCE); + + Set nearEnabledCaches = new HashSet<>(); + + for (ClusterNode node : allNodes) { + assert node.order() != 0 : "Invalid node order [locNode=" + loc + ", node=" + node + ']'; + assert !node.isDaemon(); + + for (Map.Entry entry : registeredCaches.entrySet()) { + String cacheName = entry.getKey(); + CachePredicate filter = entry.getValue(); + + if (filter.cacheNode(node)) { + allNodesWithCaches.add(node); + + if(!CU.clientNode(node)) + srvNodesWithCaches.add(node); + + if (!node.isLocal()) + rmtNodesWithCaches.add(node); + + addToMap(allCacheNodes, cacheName, node); + + if (filter.dataNode(node)) + addToMap(affCacheNodes, cacheName, node); + + if (filter.nearNode(node)) + nearEnabledCaches.add(CU.cacheId(cacheName)); + } + } + } + + return new DiscoCache( + loc, + Collections.unmodifiableList(rmtNodes), + Collections.unmodifiableList(allNodes), + Collections.unmodifiableList(srvNodes), + Collections.unmodifiableList(daemonNodes), + U.sealList(srvNodesWithCaches), + U.sealList(allNodesWithCaches), + U.sealList(rmtNodesWithCaches), + Collections.unmodifiableMap(allCacheNodes), + Collections.unmodifiableMap(affCacheNodes), + Collections.unmodifiableMap(nodeMap), + Collections.unmodifiableSet(nearEnabledCaches), + alives); + } + + /** + * Adds node to map. + * + * @param cacheMap Map to add to. + * @param cacheName Cache name. + * @param rich Node to add + */ + private void addToMap(Map> cacheMap, String cacheName, ClusterNode rich) { + List cacheNodes = cacheMap.get(CU.cacheId(cacheName)); + + if (cacheNodes == null) { + cacheNodes = new ArrayList<>(); + + cacheMap.put(CU.cacheId(cacheName), cacheNodes); + } + + cacheNodes.add(rich); + } + /** * Updates topology version if current version is smaller than updated. * @@ -2048,8 +2130,16 @@ public void scheduleSegmentCheck() { lastChk = now; if (!segValid) { - discoWrk.addEvent(EVT_NODE_SEGMENTED, AffinityTopologyVersion.NONE, getSpi().getLocalNode(), - Collections.emptyList(), null); + List empty = Collections.emptyList(); + + ClusterNode node = getSpi().getLocalNode(); + + discoWrk.addEvent(EVT_NODE_SEGMENTED, + AffinityTopologyVersion.NONE, + node, + createDiscoCache(node, empty), + empty, + null); lastSegChkRes.set(false); } @@ -2069,8 +2159,8 @@ public void scheduleSegmentCheck() { /** Worker for discovery events. */ private class DiscoveryWorker extends GridWorker { /** Event queue. */ - private final BlockingQueue, - DiscoveryCustomMessage>> evts = new LinkedBlockingQueue<>(); + private final BlockingQueue, DiscoveryCustomMessage>> evts = new LinkedBlockingQueue<>(); /** Node segmented event fired flag. */ private boolean nodeSegFired; @@ -2088,10 +2178,11 @@ private DiscoveryWorker() { * @param type Discovery event type. See {@link DiscoveryEvent} for more details. * @param topVer Topology version. * @param node Remote node this event is connected with. + * @param discoCache Discovery cache. * @param topSnapshot Topology snapshot. */ @SuppressWarnings("RedundantTypeArguments") - private void recordEvent(int type, long topVer, ClusterNode node, Collection topSnapshot) { + private void recordEvent(int type, long topVer, ClusterNode node, DiscoCache discoCache, Collection topSnapshot) { assert node != null; if (ctx.event().isRecordable(type)) { @@ -2100,7 +2191,6 @@ private void recordEvent(int type, long topVer, ClusterNode node, CollectionarrayList(topSnapshot, FILTER_DAEMON)); if (type == EVT_NODE_METRICS_UPDATED) @@ -2127,7 +2217,7 @@ else if (type == EVT_CLIENT_NODE_RECONNECTED) else assert false; - ctx.event().record(evt); + ctx.event().record(evt, discoCache); } } @@ -2135,6 +2225,7 @@ else if (type == EVT_CLIENT_NODE_RECONNECTED) * @param type Event type. * @param topVer Topology version. * @param node Node. + * @param discoCache Discovery cache. * @param topSnapshot Topology snapshot. * @param data Custom message. */ @@ -2142,12 +2233,13 @@ void addEvent( int type, AffinityTopologyVersion topVer, ClusterNode node, + DiscoCache discoCache, Collection topSnapshot, @Nullable DiscoveryCustomMessage data ) { assert node != null : data; - evts.add(new GridTuple5<>(type, topVer, node, topSnapshot, data)); + evts.add(new GridTuple6<>(type, topVer, node, discoCache, topSnapshot, data)); } /** @@ -2184,7 +2276,7 @@ private String quietNode(ClusterNode node) { /** @throws InterruptedException If interrupted. */ @SuppressWarnings("DuplicateCondition") private void body0() throws InterruptedException { - GridTuple5, + GridTuple6, DiscoveryCustomMessage> evt = evts.take(); int type = evt.get1(); @@ -2317,11 +2409,11 @@ else if (log.isDebugEnabled()) customEvt.node(ctx.discovery().localNode()); customEvt.eventNode(node); customEvt.type(type); - customEvt.topologySnapshot(topVer.topologyVersion(), evt.get4()); + customEvt.topologySnapshot(topVer.topologyVersion(), evt.get5()); customEvt.affinityTopologyVersion(topVer); - customEvt.customMessage(evt.get5()); + customEvt.customMessage(evt.get6()); - ctx.event().record(customEvt); + ctx.event().record(customEvt, evt.get4()); } return; @@ -2335,7 +2427,7 @@ else if (log.isDebugEnabled()) assert false : "Invalid discovery event: " + type; } - recordEvent(type, topVer.topologyVersion(), node, evt.get4()); + recordEvent(type, topVer.topologyVersion(), node, evt.get4(), evt.get5()); if (segmented) onSegmentation(); @@ -2545,432 +2637,6 @@ private Snapshot(AffinityTopologyVersion topVer, DiscoCache discoCache) { } } - /** Cache for discovery collections. */ - private class DiscoCache { - /** Remote nodes. */ - private final List rmtNodes; - - /** All nodes. */ - private final List allNodes; - - /** All server nodes. */ - private final List srvNodes; - - /** All nodes with at least one cache configured. */ - @GridToStringInclude - private final Collection allNodesWithCaches; - - /** All nodes with at least one cache configured. */ - @GridToStringInclude - private final Collection rmtNodesWithCaches; - - /** Cache nodes by cache name. */ - @GridToStringInclude - private final Map> allCacheNodes; - - /** Remote cache nodes by cache name. */ - @GridToStringInclude - private final Map> rmtCacheNodes; - - /** Cache nodes by cache name. */ - @GridToStringInclude - private final Map> affCacheNodes; - - /** Caches where at least one node has near cache enabled. */ - @GridToStringInclude - private final Set nearEnabledCaches; - - /** Nodes grouped by version. */ - private final NavigableMap> nodesByVer; - - /** Daemon nodes. */ - private final List daemonNodes; - - /** Node map. */ - private final Map nodeMap; - - /** Local node. */ - private final ClusterNode loc; - - /** Highest node order. */ - private final long maxOrder; - - /** - * Cached alive nodes list. As long as this collection doesn't accept {@code null}s use {@link - * #maskNull(String)} before passing raw cache names to it. - */ - private final ConcurrentMap> aliveCacheNodes; - - /** - * Cached alive remote nodes list. As long as this collection doesn't accept {@code null}s use {@link - * #maskNull(String)} before passing raw cache names to it. - */ - private final ConcurrentMap> aliveRmtCacheNodes; - - /** - * Cached alive server remote nodes with caches. - */ - private final ConcurrentSkipListMap aliveSrvNodesWithCaches; - - /** - * @param loc Local node. - * @param rmts Remote nodes. - */ - private DiscoCache(ClusterNode loc, Collection rmts) { - this.loc = loc; - - rmtNodes = Collections.unmodifiableList(new ArrayList<>(F.view(rmts, FILTER_DAEMON))); - - assert !rmtNodes.contains(loc) : "Remote nodes collection shouldn't contain local node" + - " [rmtNodes=" + rmtNodes + ", loc=" + loc + ']'; - - List all = new ArrayList<>(rmtNodes.size() + 1); - - if (!loc.isDaemon()) - all.add(loc); - - all.addAll(rmtNodes); - - Collections.sort(all, GridNodeOrderComparator.INSTANCE); - - allNodes = Collections.unmodifiableList(all); - - Map> cacheMap = new HashMap<>(allNodes.size(), 1.0f); - Map> rmtCacheMap = new HashMap<>(allNodes.size(), 1.0f); - Map> dhtNodesMap = new HashMap<>(allNodes.size(), 1.0f); - Collection nodesWithCaches = new HashSet<>(allNodes.size()); - Collection rmtNodesWithCaches = new HashSet<>(allNodes.size()); - - aliveCacheNodes = new ConcurrentHashMap8<>(allNodes.size(), 1.0f); - aliveRmtCacheNodes = new ConcurrentHashMap8<>(allNodes.size(), 1.0f); - aliveSrvNodesWithCaches = new ConcurrentSkipListMap<>(GridNodeOrderComparator.INSTANCE); - nodesByVer = new TreeMap<>(); - - long maxOrder0 = 0; - - Set nearEnabledSet = new HashSet<>(); - - List srvNodes = new ArrayList<>(); - - for (ClusterNode node : allNodes) { - assert node.order() != 0 : "Invalid node order [locNode=" + loc + ", node=" + node + ']'; - assert !node.isDaemon(); - - if (!CU.clientNode(node)) - srvNodes.add(node); - - if (node.order() > maxOrder0) - maxOrder0 = node.order(); - - boolean hasCaches = false; - - for (Map.Entry entry : registeredCaches.entrySet()) { - String cacheName = entry.getKey(); - - CachePredicate filter = entry.getValue(); - - if (filter.cacheNode(node)) { - nodesWithCaches.add(node); - - if (!loc.id().equals(node.id())) - rmtNodesWithCaches.add(node); - - addToMap(cacheMap, cacheName, node); - - if (alive(node.id())) - addToMap(aliveCacheNodes, maskNull(cacheName), node); - - if (filter.dataNode(node)) - addToMap(dhtNodesMap, cacheName, node); - - if (filter.nearNode(node)) - nearEnabledSet.add(cacheName); - - if (!loc.id().equals(node.id())) { - addToMap(rmtCacheMap, cacheName, node); - - if (alive(node.id())) - addToMap(aliveRmtCacheNodes, maskNull(cacheName), node); - } - - hasCaches = true; - } - } - - if (hasCaches && alive(node.id()) && !CU.clientNode(node)) - aliveSrvNodesWithCaches.put(node, Boolean.TRUE); - - IgniteProductVersion nodeVer = U.productVersion(node); - - // Create collection for this version if it does not exist. - Collection nodes = nodesByVer.get(nodeVer); - - if (nodes == null) { - nodes = new ArrayList<>(allNodes.size()); - - nodesByVer.put(nodeVer, nodes); - } - - nodes.add(node); - } - - Collections.sort(srvNodes, CU.nodeComparator(true)); - - // Need second iteration to add this node to all previous node versions. - for (ClusterNode node : allNodes) { - IgniteProductVersion nodeVer = U.productVersion(node); - - // Get all versions lower or equal node's version. - NavigableMap> updateView = - nodesByVer.headMap(nodeVer, false); - - for (Collection prevVersions : updateView.values()) - prevVersions.add(node); - } - - maxOrder = maxOrder0; - - allCacheNodes = Collections.unmodifiableMap(cacheMap); - rmtCacheNodes = Collections.unmodifiableMap(rmtCacheMap); - affCacheNodes = Collections.unmodifiableMap(dhtNodesMap); - allNodesWithCaches = Collections.unmodifiableCollection(nodesWithCaches); - this.rmtNodesWithCaches = Collections.unmodifiableCollection(rmtNodesWithCaches); - nearEnabledCaches = Collections.unmodifiableSet(nearEnabledSet); - this.srvNodes = Collections.unmodifiableList(srvNodes); - - daemonNodes = Collections.unmodifiableList(new ArrayList<>( - F.view(F.concat(false, loc, rmts), F0.not(FILTER_DAEMON)))); - - Map nodeMap = new HashMap<>(allNodes().size() + daemonNodes.size(), 1.0f); - - for (ClusterNode n : F.concat(false, allNodes(), daemonNodes())) - nodeMap.put(n.id(), n); - - this.nodeMap = nodeMap; - } - - /** - * Adds node to map. - * - * @param cacheMap Map to add to. - * @param cacheName Cache name. - * @param rich Node to add - */ - private void addToMap(Map> cacheMap, String cacheName, ClusterNode rich) { - Collection cacheNodes = cacheMap.get(cacheName); - - if (cacheNodes == null) { - cacheNodes = new ArrayList<>(allNodes.size()); - - cacheMap.put(cacheName, cacheNodes); - } - - cacheNodes.add(rich); - } - - /** @return Local node. */ - ClusterNode localNode() { - return loc; - } - - /** @return Remote nodes. */ - Collection remoteNodes() { - return rmtNodes; - } - - /** @return All nodes. */ - Collection allNodes() { - return allNodes; - } - - /** - * Gets collection of nodes which have version equal or greater than {@code ver}. - * - * @param ver Version to check. - * @return Collection of nodes with version equal or greater than {@code ver}. - */ - Collection elderNodes(IgniteProductVersion ver) { - Map.Entry> entry = nodesByVer.ceilingEntry(ver); - - if (entry == null) - return Collections.emptyList(); - - return entry.getValue(); - } - - /** - * @return Versions map. - */ - NavigableMap> versionsMap() { - return nodesByVer; - } - - /** - * Gets collection of nodes with at least one cache configured. - * - * @param topVer Topology version (maximum allowed node order). - * @return Collection of nodes. - */ - Collection allNodesWithCaches(final long topVer) { - return filter(topVer, allNodesWithCaches); - } - - /** - * Gets all nodes that have cache with given name. - * - * @param cacheName Cache name. - * @param topVer Topology version. - * @return Collection of nodes. - */ - Collection cacheNodes(@Nullable String cacheName, final long topVer) { - return filter(topVer, allCacheNodes.get(cacheName)); - } - - /** - * Gets all remote nodes that have at least one cache configured. - * - * @param topVer Topology version. - * @return Collection of nodes. - */ - Collection remoteCacheNodes(final long topVer) { - return filter(topVer, rmtNodesWithCaches); - } - - /** - * Gets all nodes that have cache with given name and should participate in affinity calculation. With - * partitioned cache nodes with near-only cache do not participate in affinity node calculation. - * - * @param cacheName Cache name. - * @param topVer Topology version. - * @return Collection of nodes. - */ - Collection cacheAffinityNodes(@Nullable String cacheName, final long topVer) { - return filter(topVer, affCacheNodes.get(cacheName)); - } - - /** - * Gets all alive nodes that have cache with given name. - * - * @param cacheName Cache name. - * @param topVer Topology version. - * @return Collection of nodes. - */ - Collection aliveCacheNodes(@Nullable String cacheName, final long topVer) { - return filter(topVer, aliveCacheNodes.get(maskNull(cacheName))); - } - - /** - * Gets all alive remote nodes that have cache with given name. - * - * @param cacheName Cache name. - * @param topVer Topology version. - * @return Collection of nodes. - */ - Collection aliveRemoteCacheNodes(@Nullable String cacheName, final long topVer) { - return filter(topVer, aliveRmtCacheNodes.get(maskNull(cacheName))); - } - - /** - * Checks if cache with given name has at least one node with near cache enabled. - * - * @param cacheName Cache name. - * @return {@code True} if cache with given name has at least one node with near cache enabled. - */ - boolean hasNearCache(@Nullable String cacheName) { - return nearEnabledCaches.contains(cacheName); - } - - /** - * Removes left node from cached alives lists. - * - * @param leftNode Left node. - */ - void updateAlives(ClusterNode leftNode) { - if (leftNode.order() > maxOrder) - return; - - filterNodeMap(aliveCacheNodes, leftNode); - - filterNodeMap(aliveRmtCacheNodes, leftNode); - - aliveSrvNodesWithCaches.remove(leftNode); - } - - /** - * Creates a copy of nodes map without the given node. - * - * @param map Map to copy. - * @param exclNode Node to exclude. - */ - private void filterNodeMap(ConcurrentMap> map, final ClusterNode exclNode) { - for (String cacheName : registeredCaches.keySet()) { - String maskedName = maskNull(cacheName); - - while (true) { - Collection oldNodes = map.get(maskedName); - - if (oldNodes == null || oldNodes.isEmpty()) - break; - - Collection newNodes = new ArrayList<>(oldNodes); - - if (!newNodes.remove(exclNode)) - break; - - if (map.replace(maskedName, oldNodes, newNodes)) - break; - } - } - } - - /** - * Replaces {@code null} with {@code NULL_CACHE_NAME}. - * - * @param cacheName Cache name. - * @return Masked name. - */ - private String maskNull(@Nullable String cacheName) { - return cacheName == null ? NULL_CACHE_NAME : cacheName; - } - - /** - * @param topVer Topology version. - * @param nodes Nodes. - * @return Filtered collection (potentially empty, but never {@code null}). - */ - private Collection filter(final long topVer, @Nullable Collection nodes) { - if (nodes == null) - return Collections.emptyList(); - - // If no filtering needed, return original collection. - return nodes.isEmpty() || topVer < 0 || topVer >= maxOrder ? - nodes : - F.view(nodes, new P1() { - @Override public boolean apply(ClusterNode node) { - return node.order() <= topVer; - } - }); - } - - /** @return Daemon nodes. */ - Collection daemonNodes() { - return daemonNodes; - } - - /** - * @param id Node ID. - * @return Node. - */ - @Nullable ClusterNode node(UUID id) { - return nodeMap.get(id); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(DiscoCache.class, this, "allNodesWithDaemons", U.toShortString(allNodes)); - } - } - /** * Cache predicate. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/DiscoveryEventListener.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/DiscoveryEventListener.java new file mode 100644 index 0000000000000..963d97eefee84 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/DiscoveryEventListener.java @@ -0,0 +1,33 @@ +/* + * 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.managers.eventstorage; + +import java.util.EventListener; +import org.apache.ignite.events.DiscoveryEvent; +import org.apache.ignite.internal.managers.discovery.DiscoCache; + +/** + * Internal listener for discovery events. + */ +public interface DiscoveryEventListener extends EventListener { + /** + * @param evt Discovery event. + * @param discoCache Discovery cache. + */ + public void onEvent(DiscoveryEvent evt, DiscoCache discoCache); +} \ No newline at end of file diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java index 684e326cd5cc3..f8abd30fe4eb6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java @@ -47,6 +47,7 @@ import org.apache.ignite.internal.managers.communication.GridIoManager; import org.apache.ignite.internal.managers.communication.GridMessageListener; import org.apache.ignite.internal.managers.deployment.GridDeployment; +import org.apache.ignite.internal.managers.discovery.DiscoCache; import org.apache.ignite.internal.processors.platform.PlatformEventFilterListener; import org.apache.ignite.internal.util.GridConcurrentLinkedHashSet; import org.apache.ignite.internal.util.future.GridFutureAdapter; @@ -79,6 +80,9 @@ public class GridEventStorageManager extends GridManagerAdapter /** Local event listeners. */ private final ConcurrentMap> lsnrs = new ConcurrentHashMap8<>(); + /** Internal discovery listeners. */ + private final ConcurrentMap> discoLsnrs = new ConcurrentHashMap8<>(); + /** Busy lock to control activity of threads. */ private final ReadWriteLock busyLock = new ReentrantReadWriteLock(); @@ -234,6 +238,7 @@ private void leaveBusy() { msgLsnr = null; lsnrs.clear(); + discoLsnrs.clear(); } /** {@inheritDoc} */ @@ -299,6 +304,30 @@ public void record(Event evt) { } } + /** + * Records discovery events. + * + * @param evt Event to record. + * @param discoCache Discovery cache. + */ + public void record(DiscoveryEvent evt, DiscoCache discoCache) { + assert evt != null; + + if (!enterBusy()) + return; + + try { + // Notify internal discovery listeners first. + notifyDiscoveryListeners(evt, discoCache); + + // Notify all other registered listeners. + record(evt); + } + finally { + leaveBusy(); + } + } + /** * Gets types of enabled user-recordable events. * @@ -570,7 +599,7 @@ public void addLocalEventListener(GridLocalEventListener lsnr, int[] types) { try { for (int t : types) { - getOrCreate(t).add(lsnr); + getOrCreate(lsnrs, t).add(lsnr); if (!isRecordable(t)) U.warn(log, "Added listener for disabled event type: " + U.gridEventName(t)); @@ -595,14 +624,14 @@ public void addLocalEventListener(GridLocalEventListener lsnr, int type, @Nullab return; try { - getOrCreate(type).add(lsnr); + getOrCreate(lsnrs, type).add(lsnr); if (!isRecordable(type)) U.warn(log, "Added listener for disabled event type: " + U.gridEventName(type)); if (types != null) { for (int t : types) { - getOrCreate(t).add(lsnr); + getOrCreate(lsnrs, t).add(lsnr); if (!isRecordable(t)) U.warn(log, "Added listener for disabled event type: " + U.gridEventName(t)); @@ -615,16 +644,70 @@ public void addLocalEventListener(GridLocalEventListener lsnr, int type, @Nullab } /** + * Adds discovery event listener. Note that this method specifically disallow an empty + * array of event type to prevent accidental subscription for all system event that + * may lead to a drastic performance decrease. + * + * @param lsnr Listener to add. + * @param types Event types to subscribe listener for. + */ + public void addDiscoveryEventListener(DiscoveryEventListener lsnr, int[] types) { + assert lsnr != null; + assert types != null; + assert types.length > 0; + + if (!enterBusy()) + return; + + try { + for (int t : types) { + getOrCreate(discoLsnrs, t).add(lsnr); + } + } + finally { + leaveBusy(); + } + } + + /** + * Adds discovery event listener. + * + * @param lsnr Listener to add. + * @param type Event type to subscribe listener for. + * @param types Additional event types to subscribe listener for. + */ + public void addDiscoveryEventListener(DiscoveryEventListener lsnr, int type, @Nullable int... types) { + assert lsnr != null; + + if (!enterBusy()) + return; + + try { + getOrCreate(discoLsnrs, type).add(lsnr); + + if (types != null) { + for (int t : types) { + getOrCreate(discoLsnrs, t).add(lsnr); + } + } + } + finally { + leaveBusy(); + } + } + + /** + * @param lsnrs Listeners map. * @param type Event type. * @return Listeners for given event type. */ - private Collection getOrCreate(Integer type) { - Set set = lsnrs.get(type); + private Collection getOrCreate(ConcurrentMap> lsnrs, Integer type) { + Set set = lsnrs.get(type); if (set == null) { set = new GridConcurrentLinkedHashSet<>(); - Set prev = lsnrs.putIfAbsent(type, set); + Set prev = lsnrs.putIfAbsent(type, set); if (prev != null) set = prev; @@ -687,6 +770,38 @@ public boolean removeLocalEventListener(GridLocalEventListener lsnr, @Nullable i return found; } + /** + * Removes listener for specified events, if any. If no event types provided - it + * remove the listener for all its registered events. + * + * @param lsnr Listener. + * @param types Event types. + * @return Returns {@code true} if removed. + */ + public boolean removeDiscoveryEventListener(DiscoveryEventListener lsnr, @Nullable int... types) { + assert lsnr != null; + + boolean found = false; + + if (F.isEmpty(types)) { + for (Set set : discoLsnrs.values()) + if (set.remove(lsnr)) + found = true; + } + else { + assert types != null; + + for (int type : types) { + Set set = discoLsnrs.get(type); + + if (set != null && set.remove(lsnr)) + found = true; + } + } + + return found; + } + /** * * @param p Optional predicate. @@ -779,6 +894,41 @@ private void notifyListeners(@Nullable Collection set, E } } + /** + * @param evt Discovery event + * @param cache Discovery cache. + */ + private void notifyDiscoveryListeners(DiscoveryEvent evt, DiscoCache cache) { + assert evt != null; + + notifyDiscoveryListeners(discoLsnrs.get(evt.type()), evt, cache); + } + + /** + * @param set Set of listeners. + * @param evt Discovery event. + * @param cache Discovery cache. + */ + private void notifyDiscoveryListeners(@Nullable Collection set, DiscoveryEvent evt, DiscoCache cache) { + assert evt != null; + + if (!F.isEmpty(set)) { + assert set != null; + + for (DiscoveryEventListener lsnr : set) { + try { + lsnr.onEvent(evt, cache); + } + catch (Throwable e) { + U.error(log, "Unexpected exception in listener notification for event: " + evt, e); + + if (e instanceof Error) + throw (Error)e; + } + } + } + } + /** * @param p Grid event predicate. * @return Collection of grid events. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java index a388c7affb65a..50704622017df 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java @@ -39,6 +39,7 @@ import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.GridNodeOrderComparator; import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.managers.discovery.DiscoCache; import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.CU; @@ -252,10 +253,12 @@ public void onReconnected() { * * @param topVer Topology version to calculate affinity cache for. * @param discoEvt Discovery event that caused this topology version change. + * @param discoCache Discovery cache. * @return Affinity assignments. */ @SuppressWarnings("IfMayBeConditional") - public List> calculate(AffinityTopologyVersion topVer, DiscoveryEvent discoEvt) { + public List> calculate(AffinityTopologyVersion topVer, DiscoveryEvent discoEvt, + DiscoCache discoCache) { if (log.isDebugEnabled()) log.debug("Calculating affinity [topVer=" + topVer + ", locNodeId=" + ctx.localNodeId() + ", discoEvt=" + discoEvt + ']'); @@ -266,7 +269,7 @@ public List> calculate(AffinityTopologyVersion topVer, Discove List sorted; if (!locCache) { - sorted = new ArrayList<>(ctx.discovery().cacheAffinityNodes(cacheName, topVer)); + sorted = new ArrayList<>(discoCache.cacheAffinityNodes(cacheId())); Collections.sort(sorted, GridNodeOrderComparator.INSTANCE); } 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 459723c35b682..c1dde1353a928 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 @@ -387,7 +387,7 @@ else if (req.start() && !req.clientStartOnly()) { cctx.cache().prepareCacheStart(req, fut.topologyVersion()); if (fut.isCacheAdded(cacheId, fut.topologyVersion())) { - if (cctx.discovery().cacheAffinityNodes(req.cacheName(), fut.topologyVersion()).isEmpty()) + if (fut.discoCache().cacheAffinityNodes(req.cacheName()).isEmpty()) U.quietAndWarn(log, "No server nodes found for cache client: " + req.cacheName()); } @@ -408,7 +408,7 @@ else if (!req.clientStartOnly()) { assert aff.lastVersion().equals(AffinityTopologyVersion.NONE) : aff.lastVersion(); List> assignment = aff.calculate(fut.topologyVersion(), - fut.discoveryEvent()); + fut.discoveryEvent(), fut.discoCache()); aff.initialize(fut.topologyVersion(), assignment); } @@ -768,7 +768,7 @@ private void initStartedCacheOnCoordinator(GridDhtPartitionsExchangeFuture fut, assert old == null : old; - List> newAff = cache.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent()); + List> newAff = cache.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); cache.affinity().initialize(fut.topologyVersion(), newAff); } @@ -806,7 +806,7 @@ public void initStartedCaches(boolean crd, if (cache.affinity().lastVersion().equals(AffinityTopologyVersion.NONE)) { List> assignment = - cache.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent()); + cache.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); cache.affinity().initialize(fut.topologyVersion(), assignment); } @@ -832,14 +832,15 @@ public void initStartedCaches(boolean crd, private void initAffinity(GridAffinityAssignmentCache aff, GridDhtPartitionsExchangeFuture fut, boolean fetch) throws IgniteCheckedException { if (!fetch && canCalculateAffinity(aff, fut)) { - List> assignment = aff.calculate(fut.topologyVersion(), fut.discoveryEvent()); + List> assignment = aff.calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); aff.initialize(fut.topologyVersion(), assignment); } else { GridDhtAssignmentFetchFuture fetchFut = new GridDhtAssignmentFetchFuture(cctx, aff.cacheName(), - fut.topologyVersion()); + fut.topologyVersion(), + fut.discoCache()); fetchFut.init(); @@ -893,7 +894,7 @@ public void onServerJoin(final GridDhtPartitionsExchangeFuture fut, boolean crd) CacheHolder cache = cache(fut, cacheDesc); - List> newAff = cache.affinity().calculate(topVer, fut.discoveryEvent()); + List> newAff = cache.affinity().calculate(topVer, fut.discoveryEvent(), fut.discoCache()); cache.affinity().initialize(topVer, newAff); } @@ -960,14 +961,15 @@ private void fetchAffinityOnJoin(GridDhtPartitionsExchangeFuture fut) throws Ign if (cctx.localNodeId().equals(cacheDesc.receivedFrom())) { List> assignment = - cacheCtx.affinity().affinityCache().calculate(fut.topologyVersion(), fut.discoveryEvent()); + cacheCtx.affinity().affinityCache().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); cacheCtx.affinity().affinityCache().initialize(fut.topologyVersion(), assignment); } else { GridDhtAssignmentFetchFuture fetchFut = new GridDhtAssignmentFetchFuture(cctx, cacheCtx.name(), - topVer); + topVer, + fut.discoCache()); fetchFut.init(); @@ -1001,7 +1003,7 @@ private void fetchAffinity(GridDhtPartitionsExchangeFuture fut, GridDhtAffinityAssignmentResponse res = fetchFut.get(); if (res == null) { - List> aff = affCache.calculate(topVer, fut.discoveryEvent()); + List> aff = affCache.calculate(topVer, fut.discoveryEvent(), fut.discoCache()); affCache.initialize(topVer, aff); } @@ -1013,7 +1015,7 @@ private void fetchAffinity(GridDhtPartitionsExchangeFuture fut, else { assert !affCache.centralizedAffinityFunction() || !lateAffAssign; - affCache.calculate(topVer, fut.discoveryEvent()); + affCache.calculate(topVer, fut.discoveryEvent(), fut.discoCache()); } List> aff = res.affinityAssignment(cctx.discovery()); @@ -1043,7 +1045,7 @@ public boolean onServerLeft(final GridDhtPartitionsExchangeFuture fut) throws Ig if (cacheCtx.isLocal()) continue; - cacheCtx.affinity().affinityCache().calculate(fut.topologyVersion(), fut.discoveryEvent()); + cacheCtx.affinity().affinityCache().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); } centralizedAff = true; @@ -1093,7 +1095,7 @@ private IgniteInternalFuture initCoordinatorCaches(final GridDhtPartitionsExc if (cache != null) { if (cache.client()) - cache.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent()); + cache.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); return; } @@ -1133,7 +1135,8 @@ private IgniteInternalFuture initCoordinatorCaches(final GridDhtPartitionsExc GridDhtAssignmentFetchFuture fetchFut = new GridDhtAssignmentFetchFuture(cctx, aff.cacheName(), - prev.topologyVersion()); + prev.topologyVersion(), + prev.discoCache()); fetchFut.init(); @@ -1144,7 +1147,7 @@ private IgniteInternalFuture initCoordinatorCaches(final GridDhtPartitionsExc throws IgniteCheckedException { fetchAffinity(prev, aff, (GridDhtAssignmentFetchFuture)fetchFut); - aff.calculate(fut.topologyVersion(), fut.discoveryEvent()); + aff.calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); affFut.onDone(fut.topologyVersion()); } @@ -1283,7 +1286,7 @@ private void initAffinityOnNodeJoin(GridDhtPartitionsExchangeFuture fut, assert aff.idealAssignment() != null : "Previous assignment is not available."; - List> idealAssignment = aff.calculate(topVer, fut.discoveryEvent()); + List> idealAssignment = aff.calculate(topVer, fut.discoveryEvent(), fut.discoCache()); List> newAssignment = null; if (latePrimary) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java index a65d971db155f..24321b281add1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java @@ -28,7 +28,6 @@ import org.apache.ignite.internal.processors.affinity.AffinityAssignment; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; -import org.apache.ignite.internal.util.GridLeanSet; import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.lang.IgniteFuture; @@ -77,7 +76,7 @@ public class GridCacheAffinityManager extends GridCacheManagerAdapter { @Override protected void onKernalStart0() throws IgniteCheckedException { if (cctx.isLocal()) // No discovery event needed for local affinity. - aff.calculate(LOC_CACHE_TOP_VER, null); + aff.calculate(LOC_CACHE_TOP_VER, null, null); } /** {@inheritDoc} */ 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 695872ffe9dcf..ff7feb87e3952 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 @@ -48,7 +48,6 @@ import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.events.DiscoveryEvent; -import org.apache.ignite.events.Event; import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException; import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException; import org.apache.ignite.internal.IgniteInternalFuture; @@ -57,6 +56,8 @@ import org.apache.ignite.internal.events.DiscoveryCustomEvent; import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener; import org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage; +import org.apache.ignite.internal.managers.discovery.DiscoCache; +import org.apache.ignite.internal.managers.eventstorage.DiscoveryEventListener; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; import org.apache.ignite.internal.processors.cache.distributed.dht.GridClientPartitionTopology; @@ -181,35 +182,33 @@ public class GridCachePartitionExchangeManager extends GridCacheSharedMana private DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS"); /** Discovery listener. */ - private final GridLocalEventListener discoLsnr = new GridLocalEventListener() { - @Override public void onEvent(Event evt) { + private final DiscoveryEventListener discoLsnr = new DiscoveryEventListener() { + @Override public void onEvent(DiscoveryEvent evt, DiscoCache cache) { if (!enterBusy()) return; try { - DiscoveryEvent e = (DiscoveryEvent)evt; - ClusterNode loc = cctx.localNode(); - assert e.type() == EVT_NODE_JOINED || e.type() == EVT_NODE_LEFT || e.type() == EVT_NODE_FAILED || - e.type() == EVT_DISCOVERY_CUSTOM_EVT; + assert evt.type() == EVT_NODE_JOINED || evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED || + evt.type() == EVT_DISCOVERY_CUSTOM_EVT; - final ClusterNode n = e.eventNode(); + final ClusterNode n = evt.eventNode(); GridDhtPartitionExchangeId exchId = null; GridDhtPartitionsExchangeFuture exchFut = null; - if (e.type() != EVT_DISCOVERY_CUSTOM_EVT) { + if (evt.type() != EVT_DISCOVERY_CUSTOM_EVT) { assert !loc.id().equals(n.id()); - if (e.type() == EVT_NODE_LEFT || e.type() == EVT_NODE_FAILED) { + if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED) { assert cctx.discovery().node(n.id()) == null; // Avoid race b/w initial future add and discovery event. GridDhtPartitionsExchangeFuture initFut = null; if (readyTopVer.get().equals(AffinityTopologyVersion.NONE)) { - initFut = exchangeFuture(initialExchangeId(), null, null, null); + initFut = exchangeFuture(initialExchangeId(), null, null, null, null); initFut.onNodeLeft(n); } @@ -220,16 +219,18 @@ public class GridCachePartitionExchangeManager extends GridCacheSharedMana } } - assert e.type() != EVT_NODE_JOINED || n.order() > loc.order() : + assert evt.type() != EVT_NODE_JOINED || n.order() > loc.order() : "Node joined with smaller-than-local " + "order [newOrder=" + n.order() + ", locOrder=" + loc.order() + ']'; - exchId = exchangeId(n.id(), affinityTopologyVersion(e), e.type()); + exchId = exchangeId(n.id(), + affinityTopologyVersion(evt), + evt.type()); - exchFut = exchangeFuture(exchId, e, null, null); + exchFut = exchangeFuture(exchId, evt, cache,null, null); } else { - DiscoveryCustomEvent customEvt = (DiscoveryCustomEvent)e; + DiscoveryCustomEvent customEvt = (DiscoveryCustomEvent)evt; if (customEvt.customMessage() instanceof DynamicCacheChangeBatch) { DynamicCacheChangeBatch batch = (DynamicCacheChangeBatch)customEvt.customMessage(); @@ -260,9 +261,9 @@ public class GridCachePartitionExchangeManager extends GridCacheSharedMana //todo think about refactoring if (!F.isEmpty(valid) && !(valid.size() == 1 && valid.iterator().next().globalStateChange())) { - exchId = exchangeId(n.id(), affinityTopologyVersion(e), e.type()); + exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt.type()); - exchFut = exchangeFuture(exchId, e, valid, null); + exchFut = exchangeFuture(exchId, evt, cache, valid, null); } } else if (customEvt.customMessage() instanceof CacheAffinityChangeMessage) { @@ -270,19 +271,19 @@ else if (customEvt.customMessage() instanceof CacheAffinityChangeMessage) { if (msg.exchangeId() == null) { if (msg.exchangeNeeded()) { - exchId = exchangeId(n.id(), affinityTopologyVersion(e), e.type()); + exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt.type()); - exchFut = exchangeFuture(exchId, e, null, msg); + exchFut = exchangeFuture(exchId, evt, cache, null, msg); } } else - exchangeFuture(msg.exchangeId(), null, null, null).onAffinityChangeMessage(customEvt.eventNode(), msg); + exchangeFuture(msg.exchangeId(), null, null, null, null).onAffinityChangeMessage(customEvt.eventNode(), msg); } else if (customEvt.customMessage() instanceof StartSnapshotOperationAckDiscoveryMessage && !((StartSnapshotOperationAckDiscoveryMessage)customEvt.customMessage()).hasError()) { - exchId = exchangeId(n.id(), affinityTopologyVersion(e), e.type()); + exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt.type()); - exchFut = exchangeFuture(exchId, e, null, null); + exchFut = exchangeFuture(exchId, evt, null, null, null); } } @@ -291,7 +292,7 @@ else if (customEvt.customMessage() instanceof StartSnapshotOperationAckDiscovery log.debug("Discovery event (will start exchange): " + exchId); // Event callback - without this callback future will never complete. - exchFut.onEvent(exchId, e); + exchFut.onEvent(exchId, evt, cache); // Start exchange process. addFuture(exchFut); @@ -313,7 +314,7 @@ else if (customEvt.customMessage() instanceof StartSnapshotOperationAckDiscovery exchWorker = new ExchangeWorker(); - cctx.gridEvents().addLocalEventListener(discoLsnr, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED, + cctx.gridEvents().addDiscoveryEventListener(discoLsnr, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED, EVT_DISCOVERY_CUSTOM_EVT); cctx.io().addHandler(0, GridDhtPartitionsSingleMessage.class, @@ -371,11 +372,14 @@ private GridDhtPartitionExchangeId initialExchangeId() { assert startTime > 0; // Generate dummy discovery event for local node joining. - DiscoveryEvent discoEvt = cctx.discovery().localJoinEvent(); + T2 localJoin = cctx.discovery().localJoin(); + + DiscoveryEvent discoEvt = localJoin.get1(); + DiscoCache discoCache = localJoin.get2(); GridDhtPartitionExchangeId exchId = initialExchangeId(); - GridDhtPartitionsExchangeFuture fut = exchangeFuture(exchId, discoEvt, null, null); + GridDhtPartitionsExchangeFuture fut = exchangeFuture(exchId, discoEvt, discoCache, null, null); if (reconnect) reconnectExchangeFut = new GridFutureAdapter<>(); @@ -482,7 +486,7 @@ public static Object rebalanceTopic(int idx) { /** {@inheritDoc} */ @Override protected void onKernalStop0(boolean cancel) { - cctx.gridEvents().removeLocalEventListener(discoLsnr); + cctx.gridEvents().removeDiscoveryEventListener(discoLsnr); cctx.io().removeHandler(0, GridDhtPartitionsSingleMessage.class); cctx.io().removeHandler(0, GridDhtPartitionsFullMessage.class); @@ -1085,12 +1089,14 @@ private GridDhtPartitionExchangeId exchangeId(UUID nodeId, AffinityTopologyVersi /** * @param exchId Exchange ID. * @param discoEvt Discovery event. + * @param cache Discovery data cache. * @param reqs Cache change requests. * @param affChangeMsg Affinity change message. * @return Exchange future. */ private GridDhtPartitionsExchangeFuture exchangeFuture(GridDhtPartitionExchangeId exchId, @Nullable DiscoveryEvent discoEvt, + @Nullable DiscoCache cache, @Nullable Collection reqs, @Nullable CacheAffinityChangeMessage affChangeMsg) { GridDhtPartitionsExchangeFuture fut; @@ -1109,7 +1115,7 @@ private GridDhtPartitionsExchangeFuture exchangeFuture(GridDhtPartitionExchangeI } if (discoEvt != null) - fut.onEvent(exchId, discoEvt); + fut.onEvent(exchId, discoEvt, cache); if (stopErr != null) fut.onDone(stopErr); @@ -1265,7 +1271,7 @@ else if (!cacheCtx.isLocal()) cctx.database().releaseHistoryForPreloading(); } else - exchangeFuture(msg.exchangeId(), null, null, null).onReceive(node, msg); + exchangeFuture(msg.exchangeId(), null, null, null, null).onReceive(node, msg); } finally { leaveBusy(); @@ -1318,8 +1324,11 @@ else if (!cacheCtx.isLocal()) } else { if (msg.client()) { - final GridDhtPartitionsExchangeFuture exchFut = exchangeFuture( - msg.exchangeId(), null, null, null); + final GridDhtPartitionsExchangeFuture exchFut = exchangeFuture(msg.exchangeId(), + null, + null, + null, + null); exchFut.listen(new CI1>() { @Override public void apply(IgniteInternalFuture fut) { @@ -1329,7 +1338,7 @@ else if (!cacheCtx.isLocal()) }); } else - exchangeFuture(msg.exchangeId(), null, null, null).onReceive(node, msg); + exchangeFuture(msg.exchangeId(), null, null, null, null).onReceive(node, msg); } } finally { 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 e63379abd5d57..a96cc43962cf6 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 @@ -33,6 +33,7 @@ import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.managers.discovery.DiscoCache; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId; @@ -45,7 +46,6 @@ import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.X; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; import org.jetbrains.annotations.Nullable; @@ -107,6 +107,9 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology { /** */ private final Object similarAffKey; + /** */ + private volatile DiscoCache discoCache; + /** * @param cctx Context. * @param cacheId Cache ID. @@ -125,6 +128,8 @@ public GridClientPartitionTopology( topVer = exchFut.topologyVersion(); + discoCache = exchFut.discoCache(); + log = cctx.logger(getClass()); lock.writeLock().lock(); @@ -193,6 +198,7 @@ private String mapString(GridDhtPartitionMap2 map) { this.stopping = stopping; topVer = exchId.topologyVersion(); + discoCache = exchFut.discoCache(); updateSeq.setIfGreater(updSeq); @@ -273,7 +279,7 @@ private void beforeExchange0(ClusterNode loc, GridDhtPartitionsExchangeFuture ex removeNode(exchId.nodeId()); // In case if node joins, get topology at the time of joining node. - ClusterNode oldest = cctx.discovery().oldestAliveCacheServerNode(topVer); + ClusterNode oldest = discoCache.oldestAliveServerNodeWithCache(); assert oldest != null; @@ -432,7 +438,7 @@ else if (!node2part.nodeId().equals(loc.id())) { if (!F.isEmpty(nodeIds)) { for (UUID nodeId : nodeIds) { - ClusterNode n = cctx.discovery().node(nodeId); + ClusterNode n = discoCache.node(nodeId); if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) { if (nodes == null) @@ -458,7 +464,7 @@ else if (!node2part.nodeId().equals(loc.id())) { * @return List of nodes for the partition. */ private List nodes(int p, AffinityTopologyVersion topVer, GridDhtPartitionState state, GridDhtPartitionState... states) { - Collection allIds = topVer.topologyVersion() > 0 ? F.nodeIds(CU.allNodes(cctx, topVer)) : null; + Collection allIds = topVer.topologyVersion() > 0 ? F.nodeIds(discoCache.allNodesWithCaches()) : null; lock.readLock().lock(); @@ -481,7 +487,7 @@ private List nodes(int p, AffinityTopologyVersion topVer, GridDhtPa continue; if (hasState(p, id, state, states)) { - ClusterNode n = cctx.discovery().node(id); + ClusterNode n = discoCache.node(id); if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) nodes.add(n); @@ -792,7 +798,7 @@ private void updateLocal(int p, UUID nodeId, GridDhtPartitionState state, long u assert nodeId.equals(cctx.localNodeId()); // In case if node joins, get topology at the time of joining node. - ClusterNode oldest = cctx.discovery().oldestAliveCacheServerNode(topVer); + ClusterNode oldest = discoCache.oldestAliveServerNodeWithCache(); // If this node became the oldest node. if (oldest.id().equals(cctx.localNodeId())) { @@ -842,7 +848,7 @@ private void removeNode(UUID nodeId) { assert nodeId != null; assert lock.writeLock().isHeldByCurrentThread(); - ClusterNode oldest = cctx.discovery().oldestAliveCacheServerNode(topVer); + ClusterNode oldest = discoCache.oldestAliveServerNodeWithCache(); ClusterNode loc = cctx.localNode(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java index ab8e863e90e7d..7dcfcf2598353 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java @@ -29,6 +29,7 @@ import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.internal.GridNodeOrderComparator; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; +import org.apache.ignite.internal.managers.discovery.DiscoCache; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.future.GridFutureAdapter; @@ -72,16 +73,18 @@ public class GridDhtAssignmentFetchFuture extends GridFutureAdapter(CU.cacheId(cacheName), topVer); - Collection availableNodes = ctx.discovery().cacheAffinityNodes(cacheName, topVer); + Collection availableNodes = discoCache.cacheAffinityNodes(cacheName); LinkedList tmp = new LinkedList<>(); 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 553aa2a184179..36c1ae56d5278 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 @@ -37,6 +37,7 @@ import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.events.EventType; import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.managers.discovery.DiscoCache; import org.apache.ignite.internal.processors.affinity.AffinityAssignment; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.ClusterState; @@ -98,6 +99,9 @@ /** */ private volatile AffinityTopologyVersion topVer = AffinityTopologyVersion.NONE; + /** Discovery cache. */ + private volatile DiscoCache discoCache; + /** */ private volatile boolean stopping; @@ -162,6 +166,8 @@ public void onReconnected() { rebalancedTopVer = AffinityTopologyVersion.NONE; topVer = AffinityTopologyVersion.NONE; + + discoCache = cctx.discovery().discoCache(); } finally { lock.writeLock().unlock(); @@ -219,6 +225,8 @@ private String mapString(GridDhtPartitionMap2 map) { rebalancedTopVer = AffinityTopologyVersion.NONE; topVer = exchId.topologyVersion(); + + discoCache = exchFut.discoCache(); } finally { lock.writeLock().unlock(); @@ -281,7 +289,7 @@ private String mapString(GridDhtPartitionMap2 map) { private void initPartitions0(GridDhtPartitionsExchangeFuture exchFut, long updateSeq) { ClusterNode loc = cctx.localNode(); - ClusterNode oldest = currentCoordinator(); + ClusterNode oldest = discoCache.oldestAliveServerNodeWithCache(); GridDhtPartitionExchangeId exchId = exchFut.exchangeId(); @@ -430,7 +438,7 @@ else if (localNode(p, aff)) if (exchId.isLeft()) removeNode(exchId.nodeId()); - ClusterNode oldest = currentCoordinator(); + ClusterNode oldest = discoCache.oldestAliveServerNodeWithCache(); if (log.isDebugEnabled()) log.debug("Partition map beforeExchange [exchId=" + exchId + ", fullMap=" + fullMapString() + ']'); @@ -875,7 +883,7 @@ private List nodes(int p, AffinityTopologyVersion topVer, GridDhtPartitionState state, GridDhtPartitionState... states) { - Collection allIds = topVer.topologyVersion() > 0 ? F.nodeIds(CU.affinityNodes(cctx, topVer)) : null; + Collection allIds = topVer.topologyVersion() > 0 ? F.nodeIds(discoCache.cacheAffinityNodes(cctx.cacheId())) : null; lock.readLock().lock(); @@ -1599,7 +1607,8 @@ private boolean checkEvictions(long updateSeq, List> aff) { List affNodes = aff.get(p); if (!affNodes.contains(cctx.localNode())) { - Collection nodeIds = F.nodeIds(nodes(p, topVer, OWNING)); + List nodes = nodes(p, topVer, OWNING); + Collection nodeIds = F.nodeIds(nodes); // If all affinity nodes are owners, then evict partition from local node. if (nodeIds.containsAll(F.nodeIds(affNodes))) { @@ -1619,15 +1628,13 @@ private boolean checkEvictions(long updateSeq, List> aff) { int affCnt = affNodes.size(); if (ownerCnt > affCnt) { - List sorted = new ArrayList<>(cctx.discovery().nodes(nodeIds)); - // Sort by node orders in ascending order. - Collections.sort(sorted, CU.nodeComparator(true)); + Collections.sort(nodes, CU.nodeComparator(true)); - int diff = sorted.size() - affCnt; + int diff = nodes.size() - affCnt; for (int i = 0; i < diff; i++) { - ClusterNode n = sorted.get(i); + ClusterNode n = nodes.get(i); if (locId.equals(n.id())) { part.reload(false); @@ -1654,17 +1661,6 @@ private boolean checkEvictions(long updateSeq, List> aff) { return changed; } - /** - * @return Current coordinator node. - */ - @Nullable private ClusterNode currentCoordinator() { - ClusterNode oldest = cctx.discovery().oldestAliveCacheServerNode(topVer); - - assert oldest != null || cctx.kernalContext().clientNode(); - - return oldest; - } - /** * Updates value for single partition. * @@ -1675,7 +1671,7 @@ private boolean checkEvictions(long updateSeq, List> aff) { */ @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"}) private long updateLocal(int p, GridDhtPartitionState state, long updateSeq) { - ClusterNode oldest = currentCoordinator(); + ClusterNode oldest = discoCache.oldestAliveServerNodeWithCache(); assert oldest != null || cctx.kernalContext().clientNode(); @@ -1742,7 +1738,7 @@ private long updateLocal(int p, GridDhtPartitionState state, long updateSeq) { private void removeNode(UUID nodeId) { assert nodeId != null; - ClusterNode oldest = CU.oldest(cctx.discovery().serverNodes(topVer)); + ClusterNode oldest = discoCache.oldestAliveServerNode(); assert oldest != null; 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 6cba4f4889df1..b3f3d4f16903f 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 @@ -51,6 +51,7 @@ import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationType; import org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage; +import org.apache.ignite.internal.managers.discovery.DiscoCache; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; import org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage; @@ -121,6 +122,10 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter topSnapshot = new AtomicReference<>(); - /** Last committed cache version before next topology version use. */ private AtomicReference lastVer = new AtomicReference<>(); @@ -385,6 +387,13 @@ public boolean dummyReassign() { return partHistSuppliers.getSupplier(cacheId, partId); } + /** + * @return Discovery cache. + */ + public DiscoCache discoCache() { + return discoCache; + } + /** * @param cacheId Cache ID to check. * @param topVer Topology version. @@ -428,11 +437,13 @@ public boolean onAdded() { * * @param exchId Exchange ID. * @param discoEvt Discovery event. + * @param discoCache Discovery data cache. */ - public void onEvent(GridDhtPartitionExchangeId exchId, DiscoveryEvent discoEvt) { + public void onEvent(GridDhtPartitionExchangeId exchId, DiscoveryEvent discoEvt, DiscoCache discoCache) { assert exchId.equals(this.exchId); this.discoEvt = discoEvt; + this.discoCache = discoCache; evtLatch.countDown(); } @@ -512,7 +523,9 @@ public void init() throws IgniteInterruptedCheckedException { try { AffinityTopologyVersion topVer = topologyVersion(); - srvNodes = new ArrayList<>(cctx.discovery().serverNodes(topVer)); + discoCache.updateAlives(cctx.discovery()); + + srvNodes = new ArrayList<>(discoCache.serverNodes()); remaining.addAll(F.nodeIds(F.view(srvNodes, F.remoteNodes(cctx.localNodeId())))); @@ -1017,7 +1030,7 @@ private void warnNoAffinityNodes() { List cachesWithoutNodes = null; for (String name : cctx.cache().cacheNames()) { - if (cctx.discovery().cacheAffinityNodes(name, topologyVersion()).isEmpty()) { + if (discoCache.cacheAffinityNodes(name).isEmpty()) { if (cachesWithoutNodes == null) cachesWithoutNodes = new ArrayList<>(); @@ -1446,7 +1459,6 @@ private CacheInvalidStateException validatePartitionOperation( * Cleans up resources to avoid excessive memory usage. */ public void cleanUp() { - topSnapshot.set(null); singleMsgs.clear(); fullMsgs.clear(); msgs.clear(); @@ -1732,7 +1744,7 @@ private void onAllReceived() { assert partHistSuppliers.isEmpty(); - if (!crd.equals(cctx.discovery().serverNodes(topologyVersion()).get(0))) { + if (!crd.equals(discoCache.serverNodes().get(0))) { for (GridCacheContext cacheCtx : cctx.cacheContexts()) { if (!cacheCtx.isLocal()) cacheCtx.topology().beforeExchange(this, !centralizedAff); @@ -2090,6 +2102,8 @@ public void onNodeLeft(final ClusterNode node) { ClusterNode crd0; + discoCache.updateAlives(node); + synchronized (mux) { if (!srvNodes.remove(node)) return; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java index f1be37232e869..94cf6e01641f8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java @@ -48,7 +48,6 @@ import org.apache.ignite.configuration.DeploymentMode; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.events.DiscoveryEvent; -import org.apache.ignite.events.Event; import org.apache.ignite.events.EventType; import org.apache.ignite.internal.GridClosureCallMode; import org.apache.ignite.internal.GridKernalContext; @@ -58,8 +57,9 @@ import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.events.DiscoveryCustomEvent; +import org.apache.ignite.internal.managers.discovery.DiscoCache; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; -import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener; +import org.apache.ignite.internal.managers.eventstorage.DiscoveryEventListener; import org.apache.ignite.internal.processors.GridProcessorAdapter; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage; @@ -168,7 +168,7 @@ public class GridServiceProcessor extends GridProcessorAdapter implements Ignite private IgniteInternalCache cache; /** Topology listener. */ - private GridLocalEventListener topLsnr = new TopologyListener(); + private DiscoveryEventListener topLsnr = new TopologyListener(); static { Set versions = new TreeSet<>(new Comparator() { @@ -250,7 +250,7 @@ CU.UTILITY_CACHE_NAME, new ServiceEntriesListener(), null, null cache = ctx.cache().utilityCache(); if (!ctx.clientNode()) - ctx.event().addLocalEventListener(topLsnr, EVTS); + ctx.event().addDiscoveryEventListener(topLsnr, EVTS); try { if (ctx.deploy().enabled()) @@ -312,7 +312,7 @@ CU.UTILITY_CACHE_NAME, new ServiceEntriesListener(), null, null return; if (!ctx.clientNode()) - ctx.event().removeLocalEventListener(topLsnr); + ctx.event().removeDiscoveryEventListener(topLsnr); Collection ctxs = new ArrayList<>(); @@ -1588,9 +1588,9 @@ private void onDeployment(final GridServiceDeployment dep, final AffinityTopolog /** * Topology listener. */ - private class TopologyListener implements GridLocalEventListener { + private class TopologyListener implements DiscoveryEventListener { /** {@inheritDoc} */ - @Override public void onEvent(Event evt) { + @Override public void onEvent(DiscoveryEvent evt, final DiscoCache discoCache) { if (!busyLock.enterBusy()) return; @@ -1612,11 +1612,14 @@ private class TopologyListener implements GridLocalEventListener { } } else - topVer = new AffinityTopologyVersion(((DiscoveryEvent)evt).topologyVersion(), 0); + topVer = new AffinityTopologyVersion((evt).topologyVersion(), 0); depExe.execute(new BusyRunnable() { @Override public void run0() { - ClusterNode oldest = ctx.discovery().oldestAliveCacheServerNode(topVer); + // In case the cache instance isn't tracked by DiscoveryManager anymore. + discoCache.updateAlives(ctx.discovery()); + + ClusterNode oldest = discoCache.oldestAliveServerNodeWithCache(); if (oldest != null && oldest.isLocal()) { final Collection retries = new ConcurrentLinkedQueue<>(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAliveCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAliveCacheSelfTest.java index 31b4bc7ca6682..69573d6f22cea 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAliveCacheSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAliveCacheSelfTest.java @@ -222,20 +222,6 @@ private void validateAlives() { long startVer = discoMgr.localNode().order(); for (long v = currVer; v > currVer - GridDiscoveryManager.DISCOVERY_HISTORY_SIZE && v >= startVer; v--) { - F.forAll(discoMgr.aliveCacheNodes(null, new AffinityTopologyVersion(v)), - new IgnitePredicate() { - @Override public boolean apply(ClusterNode e) { - return currTop.contains(e); - } - }); - - F.forAll(discoMgr.aliveRemoteCacheNodes(null, new AffinityTopologyVersion(v)), - new IgnitePredicate() { - @Override public boolean apply(ClusterNode e) { - return currTop.contains(e) || g.cluster().localNode().equals(e); - } - }); - GridCacheSharedContext ctx = k.context().cache().context(); ClusterNode oldest = From b7c616037ad2fd294f6e4579077718bc2acc1279 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 10 Mar 2017 14:38:59 +0300 Subject: [PATCH 077/311] IGNITE-3477 - More correct way to acquire checkpoint read lock --- .../dht/GridDhtLocalPartition.java | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) 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 aeb40f89f5b77..271739fef403c 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 @@ -942,44 +942,42 @@ public void clearAll() throws NodeStoppingException { GridIterator it0 = cctx.offheap().iterator(id); while (it0.hasNext()) { - cctx.shared().database().checkpointReadLock(); - try { CacheDataRow row = it0.next(); - GridDhtCacheEntry cached = (GridDhtCacheEntry) getEntry(row.key()); - - if (cached == null || cached.obsolete()) - cached = (GridDhtCacheEntry) putEntryIfObsoleteOrAbsent( - cctx.affinity().affinityTopologyVersion(), row.key(), null, true, false); - - if (cached.clearInternal(clearVer, extras)) { - if (rec) { - cctx.events().addEvent(cached.partition(), - cached.key(), - cctx.localNodeId(), - (IgniteUuid)null, - null, - EVT_CACHE_REBALANCE_OBJECT_UNLOADED, - null, - false, - cached.rawGet(), - cached.hasValue(), - null, - null, - null, - false); + GridDhtCacheEntry cached = (GridDhtCacheEntry)cctx.cache().entryEx(row.key()); + + cctx.shared().database().checkpointReadLock(); + + try { + if (cached.clearInternal(clearVer, extras)) { + if (rec) { + cctx.events().addEvent(cached.partition(), + cached.key(), + cctx.localNodeId(), + (IgniteUuid)null, + null, + EVT_CACHE_REBALANCE_OBJECT_UNLOADED, + null, + false, + cached.rawGet(), + cached.hasValue(), + null, + null, + null, + false); + } } } + finally { + cctx.shared().database().checkpointReadUnlock(); + } } catch (GridDhtInvalidPartitionException e) { assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']'; break; // Partition is already concurrently cleared and evicted. } - finally { - cctx.shared().database().checkpointReadUnlock(); - } } } catch (NodeStoppingException e) { From 2be130769e9c913ee7c84d660b813cca76a113eb Mon Sep 17 00:00:00 2001 From: Aleksei Scherbakov Date: Fri, 10 Mar 2017 16:23:50 +0300 Subject: [PATCH 078/311] Reverted default late aff value. --- .../org/apache/ignite/configuration/IgniteConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index cda74ae35a487..235f753f5738d 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -216,7 +216,7 @@ public class IgniteConfiguration { public static final boolean DFLT_CACHE_SANITY_CHECK_ENABLED = true; /** Default value for late affinity assignment flag. */ - public static final boolean DFLT_LATE_AFF_ASSIGNMENT = false; + public static final boolean DFLT_LATE_AFF_ASSIGNMENT = true; /** Default value for active on start flag. */ public static final boolean DFLT_ACTIVE_ON_START = true; From d37d4df928ae2c9a1ba8cb5a236e4c3a7ab1b361 Mon Sep 17 00:00:00 2001 From: Eduard Shangareev Date: Mon, 13 Mar 2017 11:33:55 +0300 Subject: [PATCH 079/311] GG-11860 Implement snapshot status on platform level -introducing SnapshotOperationFuture -adding to API gettingOngoingOperation --- ...hSnapshotOperationAckDiscoveryMessage.java | 74 +++++++++++++++++++ .../pagemem/snapshot/SnapshotOperation.java | 10 +++ ...tartSnapshotOperationDiscoveryMessage.java | 35 +++++++-- .../IgniteCacheDatabaseSharedManager.java | 10 ++- .../GridDhtPartitionsExchangeFuture.java | 7 +- 5 files changed, 123 insertions(+), 13 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/FinishSnapshotOperationAckDiscoveryMessage.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/FinishSnapshotOperationAckDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/FinishSnapshotOperationAckDiscoveryMessage.java new file mode 100644 index 0000000000000..e19ddc4810c4c --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/FinishSnapshotOperationAckDiscoveryMessage.java @@ -0,0 +1,74 @@ +/* + * 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.pagemem.snapshot; + +import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; +import org.apache.ignite.lang.IgniteUuid; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class FinishSnapshotOperationAckDiscoveryMessage implements DiscoveryCustomMessage { + /** Id. */ + private final IgniteUuid id = IgniteUuid.randomUuid(); + + /** Op id. */ + private final IgniteUuid opId; + + /** Success. */ + private final boolean success; + + /** + * @param opId Op id. + * @param success Success. + */ + public FinishSnapshotOperationAckDiscoveryMessage(IgniteUuid opId, boolean success) { + this.opId = opId; + this.success = success; + } + + /** {@inheritDoc} */ + @Override public IgniteUuid id() { + return id; + } + + /** {@inheritDoc} */ + @Nullable @Override public DiscoveryCustomMessage ackMessage() { + return null; + } + + /** {@inheritDoc} */ + @Override public boolean isMutable() { + return false; + } + + /** + * @return Op id. + */ + public IgniteUuid operationId() { + return opId; + } + + /** + * @return Success. + */ + public boolean success() { + return success; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index f3b5eeee0886a..36577a6b489dd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -154,4 +154,14 @@ public static File getMovingPathParameter(SnapshotOperation op) { result = 31 * result + (extraParam != null ? extraParam.hashCode() : 0); return result; } + + @Override public String toString() { + return "SnapshotOperation{" + + "type=" + type + + ", snapshotId=" + snapshotId + + ", cacheNames=" + cacheNames + + ", msg='" + msg + '\'' + + ", extraParam=" + extraParam + + '}'; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java index 2373a9b6db6cc..700f4049abdfb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java @@ -21,6 +21,8 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; + +import org.apache.ignite.IgniteException; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.lang.IgniteUuid; @@ -33,8 +35,11 @@ public class StartSnapshotOperationDiscoveryMessage implements DiscoveryCustomMe /** */ private static final long serialVersionUID = 0L; + /** Id. */ + private IgniteUuid id = IgniteUuid.randomUuid(); + /** Custom message ID. */ - private IgniteUuid id; + private IgniteUuid operationId; /** Snapshot operation. */ private SnapshotOperation snapshotOperation; @@ -42,6 +47,9 @@ public class StartSnapshotOperationDiscoveryMessage implements DiscoveryCustomMe /** */ private UUID initiatorId; + /** Validated by coordinator. */ + private boolean validatedByCoordinator = false; + /** Error. */ private Exception err; @@ -56,11 +64,11 @@ public class StartSnapshotOperationDiscoveryMessage implements DiscoveryCustomMe * @param initiatorId initiator node id */ public StartSnapshotOperationDiscoveryMessage( - IgniteUuid id, + IgniteUuid operationId, SnapshotOperation snapshotOperation, UUID initiatorId ) { - this.id = id; + this.operationId = operationId; this.snapshotOperation = snapshotOperation; this.initiatorId = initiatorId; } @@ -98,7 +106,7 @@ public Exception error() { /** * @return Initiator node id. */ - public UUID initiatorId() { + public UUID initiatorNodeId() { return initiatorId; } @@ -107,6 +115,11 @@ public UUID initiatorId() { return id; } + /** {@inheritDoc} */ + public IgniteUuid operationId() { + return operationId; + } + /** * @param cacheId Cache id. */ @@ -129,6 +142,16 @@ public Long lastSnapshotId(int cacheId) { return lastSnapshotIdForCache.get(cacheId); } + /** @return Validated by coordinator. */ + public boolean validatedByCoordinator() { + return validatedByCoordinator; + } + + /** Validated by coordinator. */ + public void validatedByCoordinator(boolean validatedByCoordinator) { + this.validatedByCoordinator = validatedByCoordinator; + } + /** * @param cacheId Cache id. * @param id Id. @@ -140,11 +163,11 @@ public void lastSnapshotId(int cacheId, long id) { /** {@inheritDoc} */ @Nullable @Override public DiscoveryCustomMessage ackMessage() { return new StartSnapshotOperationAckDiscoveryMessage( - id, + operationId, snapshotOperation, lastFullSnapshotIdForCache, lastSnapshotIdForCache, - err, + err != null ? err : (validatedByCoordinator? null : new IgniteException("Coordinator didn't validate operation!")), initiatorId); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 95ed3aeb7f670..3380e16329e23 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -19,9 +19,9 @@ import java.io.File; import java.util.Collection; +import java.util.UUID; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; -import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteInternalFuture; @@ -29,7 +29,7 @@ import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider; import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage; +import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; @@ -208,11 +208,13 @@ public void onCacheStop(GridCacheContext cctx) { } /** - * @param snapshotMsg Snapshot message. + * @param initiatorNodeId Snapshot message. + * @param snapshotOperation * @return Snapshot creation init future or {@code null} if snapshot is not available. * @throws IgniteCheckedException If failed. */ - @Nullable public IgniteInternalFuture startLocalSnapshotOperation(StartSnapshotOperationAckDiscoveryMessage snapshotMsg) + @Nullable public IgniteInternalFuture startLocalSnapshotOperation(UUID initiatorNodeId, + SnapshotOperation snapshotOperation) throws IgniteCheckedException { return null; } 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 4c179e660b4af..925848b531c8a 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 @@ -889,11 +889,12 @@ private void distributedExchange() throws IgniteCheckedException { } /** - * @param snapshotOperationMsg Snapshot operation message. + * @param snapOpMsg Snapshot operation message. */ - private void startLocalSnasphotOperation(StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg + private void startLocalSnasphotOperation(StartSnapshotOperationAckDiscoveryMessage snapOpMsg ) throws IgniteCheckedException { - IgniteInternalFuture fut = cctx.database().startLocalSnapshotOperation(snapshotOperationMsg); + IgniteInternalFuture fut = cctx.database() + .startLocalSnapshotOperation(snapOpMsg.initiatorNodeId(), snapOpMsg.snapshotOperation()); if (fut != null) fut.get(); From 2491a2a9d28a901223db7c2ceaeac30c06ff4083 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Wed, 15 Mar 2017 11:14:50 +0700 Subject: [PATCH 080/311] Updated classnames. --- .../resources/META-INF/classnames.properties | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index 1750276480a33..d61450c905946 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -16,6 +16,7 @@ # org.apache.ignite.IgniteAuthenticationException +org.apache.ignite.IgniteCacheRestartingException org.apache.ignite.IgniteCheckedException org.apache.ignite.IgniteClientDisconnectedException org.apache.ignite.IgniteDataStreamerTimeoutException @@ -162,6 +163,8 @@ org.apache.ignite.events.IgfsEvent org.apache.ignite.events.JobEvent org.apache.ignite.events.SwapSpaceEvent org.apache.ignite.events.TaskEvent +org.apache.ignite.hadoop.HadoopInputSplit +org.apache.ignite.hadoop.HadoopMapReducePlan org.apache.ignite.igfs.IgfsConcurrentModificationException org.apache.ignite.igfs.IgfsCorruptedFileException org.apache.ignite.igfs.IgfsDirectoryNotEmptyException @@ -326,8 +329,8 @@ org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerAdapter org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerManager$1 org.apache.ignite.internal.mem.OutOfMemoryException org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl$Segment -org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationFinishedMessage -org.apache.ignite.internal.pagemem.snapshot.SnapshotProgressMessage +org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation +org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationType org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationDiscoveryMessage org.apache.ignite.internal.pagemem.wal.StorageException @@ -381,6 +384,7 @@ org.apache.ignite.internal.processors.cache.CacheObjectImpl org.apache.ignite.internal.processors.cache.CacheOperationContext org.apache.ignite.internal.processors.cache.CacheOperationFilter org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException +org.apache.ignite.internal.processors.cache.CacheStoppedException org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException org.apache.ignite.internal.processors.cache.CacheType org.apache.ignite.internal.processors.cache.CacheWeakQueryIteratorsHolder$WeakQueryCloseableIterator @@ -503,6 +507,7 @@ org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$4 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$5 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$6 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$7 +org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$8 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeFutureSet org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$MessageHandler org.apache.ignite.internal.processors.cache.GridCacheProcessor$2 @@ -553,6 +558,7 @@ org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$8 org.apache.ignite.internal.processors.cache.IgniteCacheProxy org.apache.ignite.internal.processors.cache.IgniteCacheProxy$1 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$10 +org.apache.ignite.internal.processors.cache.IgniteCacheProxy$12 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$2 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$2$1 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$3 @@ -571,6 +577,7 @@ org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImp org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetaDataEntryFilter org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetaDataPredicate org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetadataProcessor +org.apache.ignite.internal.processors.cache.database.CacheDataRowAdapter$RowData org.apache.ignite.internal.processors.cache.database.tree.BPlusTree$Bool org.apache.ignite.internal.processors.cache.database.tree.BPlusTree$DestroyBag org.apache.ignite.internal.processors.cache.database.tree.BPlusTree$Result @@ -621,7 +628,6 @@ org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtGetSingleFutu org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtGetSingleFuture$2 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtGetSingleFuture$3 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException -org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition$2 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture$1 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture$2 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture$3 @@ -740,7 +746,6 @@ org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPar org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$1$1 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$2 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$3 -org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$3$1 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$4$1 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$5$1 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$DemandWorker$1 @@ -770,6 +775,9 @@ org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPre org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$8 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$MessageHandler org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloaderAssignments +org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionCountersMap +org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionHistorySuppliersMap +org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionsToReloadMap org.apache.ignite.internal.processors.cache.distributed.near.CacheVersionedValue org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache$1 @@ -1044,7 +1052,6 @@ org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$Buffer$1 org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$Buffer$2 org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$Buffer$3 org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$DataStreamerPda -org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$DefaultIoPolicyResolver org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$IsolatedUpdater org.apache.ignite.internal.processors.datastreamer.DataStreamerRequest org.apache.ignite.internal.processors.datastreamer.DataStreamerResponse @@ -1121,13 +1128,10 @@ org.apache.ignite.internal.processors.dr.GridDrType org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater org.apache.ignite.internal.processors.hadoop.HadoopDefaultJobInfo org.apache.ignite.internal.processors.hadoop.HadoopFileBlock -org.apache.ignite.hadoop.HadoopInputSplit org.apache.ignite.internal.processors.hadoop.HadoopJobId -org.apache.ignite.internal.processors.hadoop.HadoopJobInfo org.apache.ignite.internal.processors.hadoop.HadoopJobPhase org.apache.ignite.internal.processors.hadoop.HadoopJobProperty org.apache.ignite.internal.processors.hadoop.HadoopJobStatus -org.apache.ignite.hadoop.HadoopMapReducePlan org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo org.apache.ignite.internal.processors.hadoop.HadoopTaskType org.apache.ignite.internal.processors.hadoop.message.HadoopMessage @@ -1288,12 +1292,12 @@ org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionL org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionSetAndUnlockProcessor org.apache.ignite.internal.processors.query.GridQueryFieldMetadata org.apache.ignite.internal.processors.query.GridQueryIndexType -org.apache.ignite.internal.processors.query.GridQueryProcessor$3 org.apache.ignite.internal.processors.query.GridQueryProcessor$4 org.apache.ignite.internal.processors.query.GridQueryProcessor$5 org.apache.ignite.internal.processors.query.GridQueryProcessor$6 org.apache.ignite.internal.processors.query.GridQueryProcessor$7 org.apache.ignite.internal.processors.query.GridQueryProcessor$8 +org.apache.ignite.internal.processors.query.GridQueryProcessor$9 org.apache.ignite.internal.processors.query.GridQueryProcessor$IndexType org.apache.ignite.internal.processors.query.IgniteSQLException org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryCancelRequest @@ -1632,6 +1636,7 @@ org.apache.ignite.internal.util.nio.GridNioException org.apache.ignite.internal.util.nio.GridNioMessageTracker org.apache.ignite.internal.util.nio.GridNioServer$NioOperation org.apache.ignite.internal.util.nio.GridNioServer$RandomBalancer +org.apache.ignite.internal.util.nio.GridNioServer$ReadWriteSizeBasedBalancer org.apache.ignite.internal.util.nio.GridNioServer$SizeBasedBalancer org.apache.ignite.internal.util.nio.GridNioSessionMetaKey org.apache.ignite.internal.util.nio.ssl.GridNioSslHandler From 22b6a9a954fd9e56fd96ca94d99165f94bf8ec01 Mon Sep 17 00:00:00 2001 From: Alexandr Kuramshin Date: Wed, 15 Mar 2017 19:18:51 +0700 Subject: [PATCH 081/311] initial CHECK snapshot test w/o modifications --- modules/core/src/test/config/log4j-test.xml | 8 ++++---- .../junits/common/GridCommonAbstractTest.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) mode change 100644 => 100755 modules/core/src/test/config/log4j-test.xml mode change 100644 => 100755 modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java diff --git a/modules/core/src/test/config/log4j-test.xml b/modules/core/src/test/config/log4j-test.xml old mode 100644 new mode 100755 index 276de8ccdbabf..edabff72ae844 --- a/modules/core/src/test/config/log4j-test.xml +++ b/modules/core/src/test/config/log4j-test.xml @@ -102,9 +102,9 @@ --> - - - + + + @@ -113,7 +113,7 @@ - + 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 old mode 100644 new mode 100755 index d82f1ea822a94..3391b7cae0700 --- 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 @@ -1452,8 +1452,8 @@ protected boolean deleteRecursively(File file) { ok = false; } - if (ok) - info("Deleted OK: " + file.getAbsolutePath() + + if (ok && log().isDebugEnabled()) // too much logging on real data + log().debug("Deleted OK: " + file.getAbsolutePath() + (size >= 0 ? "(" + IgniteUtils.readableSize(size, false) + ")" : "")); return ok; From 476e8f1e19dbaae426b1121a48d0d23043e1babb Mon Sep 17 00:00:00 2001 From: Alexandr Kuramshin Date: Thu, 16 Mar 2017 00:34:14 +0700 Subject: [PATCH 082/311] RESTORE snapshot test with modifications using DirectoryStream API --- .../ignite/internal/util/lang/GridFunc.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) mode change 100644 => 100755 modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java old mode 100644 new mode 100755 index 5eb27d31db20c..4ddf615119a13 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java @@ -17,6 +17,10 @@ package org.apache.ignite.internal.util.lang; +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -41,6 +45,7 @@ import java.util.concurrent.atomic.AtomicReference; import javax.cache.Cache; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.compute.ComputeJobResult; import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException; @@ -2312,6 +2317,23 @@ public static boolean isEmpty(@Nullable Map m) { return m == null || m.isEmpty(); } + /** + * Tests if the given path is a directory and is not {@code null} or empty. + * + * @param dir Path to test. + * @return Whether or not the given path is a directory and is not {@code null} or empty. + */ + public static boolean isEmptyDirectory(Path dir) { + if (dir == null || !Files.isDirectory(dir)) + return false; + try (DirectoryStream files = Files.newDirectoryStream(dir)) { + return !files.iterator().hasNext(); + } + catch (IOException e) { + throw new IgniteException(e); + } + } + /** * Converts collection of numbers to primitive {@code int[]} array. * From 0693a9a7eb0f4c7b3fd7109885f1e1150f4da126 Mon Sep 17 00:00:00 2001 From: Alexandr Kuramshin Date: Sun, 19 Mar 2017 00:08:50 +0700 Subject: [PATCH 083/311] create F.isNotEmptyDirectory() as an opposite to F.isEmptyDirectory() (fixing call to !F.isEmptyDirectory()) revert some FileSnapshot.getStream() changes --- .../ignite/internal/util/lang/GridFunc.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java index 4ddf615119a13..fff76cba3c2f4 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java @@ -2318,10 +2318,10 @@ public static boolean isEmpty(@Nullable Map m) { } /** - * Tests if the given path is a directory and is not {@code null} or empty. + * Tests if the given path is not {@code null} and is an empty directory. * * @param dir Path to test. - * @return Whether or not the given path is a directory and is not {@code null} or empty. + * @return Whether or not the given path is not {@code null} and is an empty directory. */ public static boolean isEmptyDirectory(Path dir) { if (dir == null || !Files.isDirectory(dir)) @@ -2334,6 +2334,23 @@ public static boolean isEmptyDirectory(Path dir) { } } + /** + * Tests if the given path is not {@code null} and is a not empty directory. + * + * @param dir Path to test. + * @return Whether or not the given path is not {@code null} and is a not empty directory. + */ + public static boolean isNotEmptyDirectory(Path dir) { + if (dir == null || !Files.isDirectory(dir)) + return false; + try (DirectoryStream files = Files.newDirectoryStream(dir)) { + return files.iterator().hasNext(); + } + catch (IOException e) { + throw new IgniteException(e); + } + } + /** * Converts collection of numbers to primitive {@code int[]} array. * From 2d3d5eb229728ef984ead430b00720e423c50102 Mon Sep 17 00:00:00 2001 From: Alexandr Kuramshin Date: Sun, 19 Mar 2017 19:13:21 +0700 Subject: [PATCH 084/311] implement U.ensureDirectory() for Path --- .../ignite/internal/util/IgniteUtils.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) mode change 100644 => 100755 modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java old mode 100644 new mode 100755 index 4892917afa403..e8cb32b462412 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -9166,6 +9166,32 @@ else if (!dir.isDirectory()) log.info("Resolved " + msg + ": " + dir.getAbsolutePath()); } + /** + * Checks if the given directory exists and attempts to create one if not. + * + * @param dir Directory to check. + * @param msg Directory name for the messages. + * @param log Optional logger to log a message that the directory has been resolved. + * @throws IgniteCheckedException If directory does not exist and failed to create it, or if a file with + * the same name already exists. + */ + public static void ensureDirectory(Path dir, String msg, IgniteLogger log) throws IgniteCheckedException { + if (!Files.exists(dir)) { + try { + Files.createDirectories(dir); + } + catch (IOException e) { + throw new IgniteCheckedException("Failed to create " + msg + ": " + dir.toAbsolutePath(), e); + } + } + else if (!Files.isDirectory(dir)) + throw new IgniteCheckedException("Failed to initialize " + msg + + " (a file with the same name already exists): " + dir.toAbsolutePath()); + + if (log != null && log.isInfoEnabled()) + log.info("Resolved " + msg + ": " + dir.toAbsolutePath()); + } + /** * Creates {@code IgniteCheckedException} with the collection of suppressed exceptions. * From 3b86e29abf6e94cac8eb0208a4a7b81eff628ff2 Mon Sep 17 00:00:00 2001 From: sboikov Date: Thu, 16 Mar 2017 10:37:02 +0300 Subject: [PATCH 085/311] ignite-4712 Memory leaks in PageMemory --- .../cache/database/freelist/PagesList.java | 221 +++++++---- .../ignite/cache/LargeEntryUpdateTest.java | 177 +++++++++ .../database/IgniteDbAbstractTest.java | 369 ++++++++++++++++++ .../IgniteDbMemoryLeakAbstractTest.java | 265 +++++++++++++ .../IgniteDbMemoryLeakLargeObjectsTest.java | 56 +++ .../IgniteDbMemoryLeakLargePagesTest.java | 33 ++ ...gniteDbMemoryLeakNonTransactionalTest.java | 31 ++ .../database/IgniteDbMemoryLeakTest.java | 46 +++ .../IgniteDbMemoryLeakWithExpirationTest.java | 44 +++ .../database/IgniteDbPutGetAbstractTest.java | 328 +--------------- .../IgniteDbMemoryLeakTestSuite.java | 49 +++ .../IgniteDbMemoryLeakIndexedTest.java | 33 ++ .../IgniteDbMemoryLeakSqlQueryTest.java | 76 ++++ ...niteDbMemoryLeakWithIndexingTestSuite.java | 40 ++ 14 files changed, 1369 insertions(+), 399 deletions(-) create mode 100644 modules/core/src/test/java/org/apache/ignite/cache/LargeEntryUpdateTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakLargeObjectsTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakLargePagesTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakNonTransactionalTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakWithExpirationTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/testsuites/IgniteDbMemoryLeakTestSuite.java create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakIndexedTest.java create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakSqlQueryTest.java create mode 100644 modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteDbMemoryLeakWithIndexingTestSuite.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java index e5430cf04065f..5c66b102dcbf1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.internal.pagemem.Page; @@ -51,7 +52,6 @@ import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.jetbrains.annotations.Nullable; -import org.jsr166.LongAdder8; import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; @@ -76,10 +76,7 @@ public abstract class PagesList extends DataStructure { Math.min(8, Runtime.getRuntime().availableProcessors() * 2)); /** */ - private final boolean trackBucketsSize = IgniteSystemProperties.getBoolean("IGNITE_PAGES_LIST_TRACK_SIZE", false); - - /** */ - protected final LongAdder8[] bucketsSize; + protected final AtomicLong[] bucketsSize; /** Page ID to store list metadata. */ private final long metaPageId; @@ -117,7 +114,7 @@ private class CutTail extends PageHandler { return TRUE; } - }; + } /** * @param cacheId Cache ID. @@ -142,10 +139,10 @@ public PagesList( this.buckets = buckets; this.metaPageId = metaPageId; - bucketsSize = new LongAdder8[buckets]; + bucketsSize = new AtomicLong[buckets]; for (int i = 0; i < buckets; i++) - bucketsSize[i] = new LongAdder8(); + bucketsSize[i] = new AtomicLong(); } /** @@ -191,6 +188,7 @@ protected final void init(long metaPageId, boolean initNew) throws IgniteChecked for (Map.Entry e : bucketsData.entrySet()) { int bucket = e.getKey(); + long bucketSize = 0; Stripe[] old = getBucket(bucket); assert old == null; @@ -199,11 +197,43 @@ protected final void init(long metaPageId, boolean initNew) throws IgniteChecked Stripe[] tails = new Stripe[upd.length]; - for (int i = 0; i < upd.length; i++) - tails[i] = new Stripe(upd[i]); + for (int i = 0; i < upd.length; i++) { + long tailId = upd[i]; + + long pageId = tailId; + int cnt = 0; + + while (pageId != 0L) { + try (Page page = page(pageId)) { + long pageAddr = readLock(page); + + assert pageAddr != 0L; + + try { + PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr); + + cnt += io.getCount(pageAddr); + pageId = io.getPreviousId(pageAddr); + + // In reuse bucket the page itself can be used as a free page. + if (isReuseBucket(bucket) && pageId != 0L) + cnt++; + } + finally { + readUnlock(page, pageAddr); + } + } + } + + Stripe stripe = new Stripe(tailId, cnt == 0); + tails[i] = stripe; + bucketSize += cnt; + } boolean ok = casBucket(bucket, null, tails); assert ok; + + bucketsSize[bucket].set(bucketSize); } } } @@ -363,7 +393,7 @@ private Stripe addStripe(int bucket, boolean reuse) throws IgniteCheckedExceptio initPage(pageMem, page, this, PagesListNodeIO.VERSIONS.latest(), wal); } - Stripe stripe = new Stripe(pageId); + Stripe stripe = new Stripe(pageId, true); for (;;) { Stripe[] old = getBucket(bucket); @@ -490,25 +520,32 @@ protected final long storedPagesCount(int bucket) throws IgniteCheckedException for (Stripe tail : tails) { long pageId = tail.tailId; - try (Page page = page(pageId)) { - long pageAddr = readLock(page); // No correctness guaranties. + while (pageId != 0L) { + try (Page page = page(pageId)) { + long pageAddr = readLock(page); - try { - PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr); + assert pageAddr != 0L; - int cnt = io.getCount(pageAddr); + try { + PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr); - assert cnt >= 0; + res += io.getCount(pageAddr); + pageId = io.getPreviousId(pageAddr); - res += cnt; - } - finally { - readUnlock(page, pageAddr); + // In reuse bucket the page itself can be used as a free page. + if (isReuseBucket(bucket) && pageId != 0L) + res++; + } + finally { + readUnlock(page, pageAddr); + } } } } } + assert res == bucketsSize[bucket].get() : "Wrong bucket size counter [exp=" + res + ", cntr=" + bucketsSize[bucket].get() + ']'; + return res; } @@ -600,8 +637,7 @@ private boolean putDataPage( if (idx == -1) handlePageFull(pageId, page, pageAddr, io, dataPage, dataPageAddr, bucket); else { - if (trackBucketsSize) - bucketsSize[bucket].increment(); + bucketsSize[bucket].incrementAndGet(); if (isWalDeltaRecordNeeded(wal, page)) wal.log(new PagesListAddPageRecord(cacheId, pageId, dataPageId)); @@ -660,6 +696,9 @@ private void handlePageFull( dataPageId, pageId, 0L)); + // In reuse bucket the page itself can be used as a free page. + bucketsSize[bucket].incrementAndGet(); + updateTail(bucket, pageId, dataPageId); } else { @@ -695,14 +734,13 @@ private void handlePageFull( assert idx != -1; - if (trackBucketsSize) - bucketsSize[bucket].increment(); - dataIO.setFreeListPageId(dataPageAddr, nextId); if (isWalDeltaRecordNeeded(wal, dataPage)) wal.log(new DataPageSetFreeListPageRecord(cacheId, dataPageId, nextId)); + bucketsSize[bucket].incrementAndGet(); + updateTail(bucket, pageId, nextId); } finally { @@ -778,6 +816,10 @@ private boolean putReuseBag( 0L )); + // In reuse bucket the page itself can be used as a free page. + if (isReuseBucket(bucket)) + bucketsSize[bucket].incrementAndGet(); + // Switch to this new page, which is now a part of our list // to add the rest of the bag to the new page. prevPageAddr = nextPageAddr; @@ -786,12 +828,11 @@ private boolean putReuseBag( } } else { - if (trackBucketsSize) - bucketsSize[bucket].increment(); - // TODO: use single WAL record for bag? if (isWalDeltaRecordNeeded(wal, page)) wal.log(new PagesListAddPageRecord(cacheId, prevId, nextId)); + + bucketsSize[bucket].incrementAndGet(); } } } @@ -816,10 +857,22 @@ private boolean putReuseBag( private Stripe getPageForTake(int bucket) { Stripe[] tails = getBucket(bucket); - if (tails == null) + if (tails == null || bucketsSize[bucket].get() == 0) return null; - return randomTail(tails); + int len = tails.length; + int init = randomInt(len); + int cur = init; + + while (true) { + Stripe stripe = tails[cur]; + + if (!stripe.empty) + return stripe; + + if ((cur = (cur + 1) % len) == init) + return null; + } } /** @@ -873,7 +926,7 @@ protected final long takeEmptyPage(int bucket, @Nullable IOVersions initIoVers) for (int lockAttempt = 0; ;) { Stripe stripe = getPageForTake(bucket); - if (stripe == null || stripe.empty) + if (stripe == null) return 0L; long tailId = stripe.tailId; @@ -888,24 +941,38 @@ protected final long takeEmptyPage(int bucket, @Nullable IOVersions initIoVers) continue; } + if (stripe.empty) { + // Another thread took the last page. + writeUnlock(tail, tailPageAddr, false); + + if (bucketsSize[bucket].get() > 0) { + lockAttempt--; // Ignore current attempt. + + continue; + } + else + return 0L; + } + assert PageIO.getPageId(tailPageAddr) == tailId : "tailId = " + tailId + ", tailPageId = " + PageIO.getPageId(tailPageAddr); assert PageIO.getType(tailPageAddr) == PageIO.T_PAGE_LIST_NODE; boolean dirty = false; - long ret = 0L; + long ret; long recycleId = 0L; try { PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(tailPageAddr); - if (io.getNextId(tailPageAddr) != 0) + if (io.getNextId(tailPageAddr) != 0) { + // It is not a tail anymore, retry. continue; + } long pageId = io.takeAnyPage(tailPageAddr); if (pageId != 0L) { - if (trackBucketsSize) - bucketsSize[bucket].decrement(); + bucketsSize[bucket].decrementAndGet(); if (isWalDeltaRecordNeeded(wal, tail)) wal.log(new PagesListRemovePageRecord(cacheId, tailId, pageId)); @@ -914,59 +981,66 @@ protected final long takeEmptyPage(int bucket, @Nullable IOVersions initIoVers) ret = pageId; - // If we got an empty page in non-reuse bucket, move it back to reuse list - // to prevent empty page leak to data pages. - if (io.isEmpty(tailPageAddr) && !isReuseBucket(bucket)) { + if (io.isEmpty(tailPageAddr)) { long prevId = io.getPreviousId(tailPageAddr); - if (prevId != 0L) { - try (Page prev = page(prevId)) { - // Lock pages from next to previous. - Boolean ok = writePage(pageMem, prev, this, cutTail, null, bucket, FALSE); + // If we got an empty page in non-reuse bucket, move it back to reuse list + // to prevent empty page leak to data pages. + if (!isReuseBucket(bucket)) { + if (prevId != 0L) { + try (Page prev = page(prevId)) { + // Lock pages from next to previous. + Boolean ok = writePage(pageMem, prev, this, cutTail, null, bucket, FALSE); - assert ok == TRUE : ok; - } + assert ok == TRUE : ok; + } - recycleId = recyclePage(tailId, tail, tailPageAddr); + recycleId = recyclePage(tailId, tail, tailPageAddr); + } + else + stripe.empty = true; } + else + stripe.empty = prevId == 0L; } } else { - // The tail page is empty. We can unlink and return it if we have a previous page. - long prevId = io.getPreviousId(tailPageAddr); + // The tail page is empty, but stripe is not. It might + // happen only if we are in reuse bucket and it has + // a previous page, so, the current page can be collected + assert isReuseBucket(bucket); - if (prevId != 0L) { - // This can only happen if we are in the reuse bucket. - assert isReuseBucket(bucket); + long prevId = io.getPreviousId(tailPageAddr); - try (Page prev = page(prevId)) { - // Lock pages from next to previous. - Boolean ok = writePage(pageMem, prev, this, cutTail, null, bucket, FALSE); + assert prevId != 0L; - assert ok == TRUE : ok; - } + try (Page prev = page(prevId)) { + // Lock pages from next to previous. + Boolean ok = writePage(pageMem, prev, this, cutTail, null, bucket, FALSE); - if (initIoVers != null) { - tailId = PageIdUtils.changeType(tailId, FLAG_DATA); + assert ok == TRUE : ok; - PageIO initIo = initIoVers.latest(); + bucketsSize[bucket].decrementAndGet(); + } - initIo.initNewPage(tailPageAddr, tailId, pageSize()); + if (initIoVers != null) { + tailId = PageIdUtils.changeType(tailId, FLAG_DATA); - if (isWalDeltaRecordNeeded(wal, tail)) { - wal.log(new InitNewPageRecord(cacheId, tail.id(), initIo.getType(), - initIo.getVersion(), tailId)); - } - } - else - tailId = recyclePage(tailId, tail, tailPageAddr); + PageIO initIo = initIoVers.latest(); - dirty = true; + initIo.initNewPage(tailPageAddr, tailId, pageSize()); - ret = tailId; + if (isWalDeltaRecordNeeded(wal, tail)) { + wal.log(new InitNewPageRecord(cacheId, tail.id(), initIo.getType(), + initIo.getVersion(), tailId)); + } } else - stripe.empty = true; + tailId = recyclePage(tailId, tail, tailPageAddr); + + dirty = true; + + ret = tailId; } // If we do not have a previous page (we are at head), then we still can return @@ -1026,8 +1100,7 @@ protected final boolean removeDataPage(Page dataPage, long dataPageAddr, DataPag if (!rmvd) return false; - if (trackBucketsSize) - bucketsSize[bucket].decrement(); + bucketsSize[bucket].decrementAndGet(); if (isWalDeltaRecordNeeded(wal, page)) wal.log(new PagesListRemovePageRecord(cacheId, pageId, dataPageId)); @@ -1312,9 +1385,11 @@ public static final class Stripe { /** * @param tailId Tail ID. + * @param empty Empty flag. */ - Stripe(long tailId) { + Stripe(long tailId, boolean empty) { this.tailId = tailId; + this.empty = empty; } } } diff --git a/modules/core/src/test/java/org/apache/ignite/cache/LargeEntryUpdateTest.java b/modules/core/src/test/java/org/apache/ignite/cache/LargeEntryUpdateTest.java new file mode 100644 index 0000000000000..18a165425ee81 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/cache/LargeEntryUpdateTest.java @@ -0,0 +1,177 @@ +/* + * 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.cache; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.cache.processor.MutableEntry; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCompute; +import org.apache.ignite.IgniteException; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.lang.IgniteFuture; +import org.apache.ignite.lang.IgniteRunnable; +import org.apache.ignite.resources.IgniteInstanceResource; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class LargeEntryUpdateTest extends GridCommonAbstractTest { + /** */ + private static final int THREAD_COUNT = 10; + + /** */ + private static final int PAGE_SIZE = 1 << 10; // 1 kB. + + /** */ + private static final int PAGE_CACHE_SIZE = 30 << 20; // 30 MB. + + /** */ + private static final String CACHE_PREFIX = "testCache"; + + /** */ + private static final int CACHE_COUNT = 10; + + /** */ + private static final long WAIT_TIMEOUT = 5 * 60_000L; // 5 min. + + /** */ + private static final long TEST_TIMEOUT = 10 * 60_000L; // 10 min. + + /** */ + private final AtomicBoolean cacheUpdate = new AtomicBoolean(); + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return TEST_TIMEOUT; + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setPublicThreadPoolSize(THREAD_COUNT); + + MemoryConfiguration mem = new MemoryConfiguration(); + + mem.setPageSize(PAGE_SIZE); + mem.setPageCacheSize(PAGE_CACHE_SIZE); + + cfg.setMemoryConfiguration(mem); + + CacheConfiguration[] ccfgs = new CacheConfiguration[CACHE_COUNT]; + + for (int i = 0; i < CACHE_COUNT; ++i) { + CacheConfiguration ccfg = new CacheConfiguration(); + ccfg.setName(CACHE_PREFIX + i); + ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfgs[i] = ccfg; + } + + cfg.setCacheConfiguration(ccfgs); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testEntryUpdate() throws Exception { + try (Ignite ignite = startGrid()) { + for (int i = 0; i < CACHE_COUNT; ++i) { + IgniteCache cache = ignite.cache(CACHE_PREFIX + i); + + cache.put(0L, new byte[PAGE_SIZE * 2]); + } + + IgniteCompute compute = ignite.compute().withAsync(); + + long endTime = System.currentTimeMillis() + WAIT_TIMEOUT; + + int iter = 0; + + while (System.currentTimeMillis() < endTime) { + log.info("Iteration: " + iter++); + + cacheUpdate.set(true); + + try { + List futs = new ArrayList<>(); + + for (int i = 0; i < THREAD_COUNT; ++i) { + compute.run(new CacheUpdater()); + + futs.add(compute.future()); + } + + Thread.sleep(30_000); + + cacheUpdate.set(false); + + for (IgniteFuture fut : futs) + fut.get(); + } + finally { + cacheUpdate.set(false); + } + } + } + } + + /** */ + public static class EntryUpdater implements CacheEntryProcessor { + /** */ + public static final EntryUpdater INSTANCE = new EntryUpdater(); + + /** {@inheritDoc} */ + @Override public Void process(MutableEntry entry, Object... args) { + entry.setValue(new byte[PAGE_SIZE]); + + return null; + } + } + + /** */ + public class CacheUpdater implements IgniteRunnable { + /** */ + @IgniteInstanceResource + public transient Ignite ignite; + + /** {@inheritDoc} */ + @Override public void run() { + try { + while (cacheUpdate.get()) { + for (int i = 0; i < CACHE_COUNT; ++i) { + IgniteCache cache = ignite.cache(CACHE_PREFIX + i); + + cache.invoke(0L, EntryUpdater.INSTANCE); + } + } + } + catch (Throwable ex) { + throw new IgniteException(ex); + } + } + } + +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java new file mode 100644 index 0000000000000..cf26187cb9e8b --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java @@ -0,0 +1,369 @@ +/* + * 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.database; + +import java.io.Serializable; +import java.util.Arrays; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; +import org.apache.ignite.internal.util.typedef.internal.S; +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.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +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.CacheRebalanceMode.SYNC; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; + +/** + * + */ +public abstract class IgniteDbAbstractTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** + * @return Node count. + */ + protected abstract int gridCount(); + + /** + * @return {@code True} if indexing is enabled. + */ + protected abstract boolean indexingEnabled(); + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); + + if (isLargePage()) + dbCfg.setPageSize(16 * 1024); + else + dbCfg.setPageSize(1024); + + dbCfg.setPageCacheSize(200 * 1024 * 1024); + + configure(dbCfg); + + cfg.setMemoryConfiguration(dbCfg); + + CacheConfiguration ccfg = new CacheConfiguration(); + + if (indexingEnabled()) + ccfg.setIndexedTypes(Integer.class, DbValue.class); + + ccfg.setAtomicityMode(TRANSACTIONAL); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setRebalanceMode(SYNC); + ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + + CacheConfiguration ccfg2 = new CacheConfiguration("non-primitive"); + + if (indexingEnabled()) + ccfg2.setIndexedTypes(DbKey.class, DbValue.class); + + ccfg2.setAtomicityMode(TRANSACTIONAL); + ccfg2.setWriteSynchronizationMode(FULL_SYNC); + ccfg2.setRebalanceMode(SYNC); + ccfg2.setAffinity(new RendezvousAffinityFunction(false, 32)); + + CacheConfiguration ccfg3 = new CacheConfiguration("large"); + + if (indexingEnabled()) + ccfg3.setIndexedTypes(Integer.class, LargeDbValue.class); + + ccfg3.setAtomicityMode(TRANSACTIONAL); + ccfg3.setWriteSynchronizationMode(FULL_SYNC); + ccfg3.setRebalanceMode(SYNC); + ccfg3.setAffinity(new RendezvousAffinityFunction(false, 32)); + + CacheConfiguration ccfg4 = new CacheConfiguration("tiny"); + + ccfg4.setAtomicityMode(TRANSACTIONAL); + ccfg4.setWriteSynchronizationMode(FULL_SYNC); + ccfg4.setRebalanceMode(SYNC); + ccfg4.setAffinity(new RendezvousAffinityFunction(1, null)); + + CacheConfiguration ccfg5 = new CacheConfiguration("atomic"); + + if (indexingEnabled()) + ccfg5.setIndexedTypes(DbKey.class, DbValue.class); + + ccfg5.setAtomicityMode(ATOMIC); + ccfg5.setWriteSynchronizationMode(FULL_SYNC); + ccfg5.setRebalanceMode(SYNC); + ccfg5.setAffinity(new RendezvousAffinityFunction(false, 32)); + + cfg.setCacheConfiguration(ccfg, ccfg2, ccfg3, ccfg4, ccfg5); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(discoSpi); + cfg.setMarshaller(null); + + configure(cfg); + + return cfg; + } + + /** + * @param cfg IgniteConfiguration. + */ + protected void configure(IgniteConfiguration cfg){ + // No-op. + } + + /** + * @param mCfg MemoryConfiguration. + */ + protected void configure(MemoryConfiguration mCfg){ + // No-op. + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + +// long seed = System.currentTimeMillis(); +// +// info("Seed: " + seed + "L"); +// +// BPlusTree.rnd = new Random(seed); + + startGrids(gridCount()); + + awaitPartitionMapExchange(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + BPlusTree.rnd = null; + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @return {@code True} if use large page. + */ + protected boolean isLargePage() { + return false; + } + + /** + * + */ + static class DbKey implements Serializable { + /** */ + int val; + + /** + * @param val Value. + */ + DbKey(int val) { + this.val = val; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || !(o instanceof DbKey)) + return false; + + DbKey key = (DbKey)o; + + return val == key.val; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return val; + } + } + + /** + * + */ + static class LargeDbKey implements Serializable { + /** */ + int val; + + /** */ + byte[] data; + + /** + * @param val Value. + * @param size Key payload size. + */ + LargeDbKey(int val, int size) { + this.val = val; + + data = new byte[size]; + + Arrays.fill(data, (byte)val); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || !(o instanceof LargeDbKey)) + return false; + + LargeDbKey key = (LargeDbKey)o; + + return val == key.val && Arrays.equals(data, key.data); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return val + Arrays.hashCode(data); + } + } + + /** + * + */ + static class DbValue implements Serializable { + /** */ + @QuerySqlField(index = true) + int iVal; + + /** */ + @QuerySqlField(index = true) + String sVal; + + /** */ + @QuerySqlField + long lVal; + + /** + * @param iVal Integer value. + * @param sVal String value. + * @param lVal Long value. + */ + DbValue(int iVal, String sVal, long lVal) { + this.iVal = iVal; + this.sVal = sVal; + this.lVal = lVal; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + DbValue dbVal = (DbValue)o; + + return iVal == dbVal.iVal && lVal == dbVal.lVal && + !(sVal != null ? !sVal.equals(dbVal.sVal) : dbVal.sVal != null); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int res = iVal; + + res = 31 * res + (sVal != null ? sVal.hashCode() : 0); + res = 31 * res + (int)(lVal ^ (lVal >>> 32)); + + return res; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(DbValue.class, this); + } + } + + /** + * + */ + static class LargeDbValue { + /** */ + @QuerySqlField(index = true) + String str1; + + /** */ + @QuerySqlField(index = true) + String str2; + + /** */ + int[] arr; + + /** + * @param str1 String 1. + * @param str2 String 2. + * @param arr Big array. + */ + LargeDbValue(final String str1, final String str2, final int[] arr) { + this.str1 = str1; + this.str2 = str2; + this.arr = arr; + } + + /** {@inheritDoc} */ + @Override public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + final LargeDbValue that = (LargeDbValue) o; + + if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + + return Arrays.equals(arr, that.arr); + + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int res = str1 != null ? str1.hashCode() : 0; + + res = 31 * res + (str2 != null ? str2.hashCode() : 0); + res = 31 * res + Arrays.hashCode(arr); + + return res; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(LargeDbValue.class, this); + } + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java new file mode 100644 index 0000000000000..2e9d3f90be401 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java @@ -0,0 +1,265 @@ +/* + * 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.database; + +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.database.DataStructure; + +import static org.apache.ignite.IgniteSystemProperties.getInteger; + +/** + * Base class for memory leaks tests. + */ +public abstract class IgniteDbMemoryLeakAbstractTest extends IgniteDbAbstractTest { + /** */ + private static final int CONCURRENCY_LEVEL = 8; + + /** */ + private static final int MIN_PAGE_CACHE_SIZE = 1048576 * CONCURRENCY_LEVEL; + + /** */ + private volatile Exception ex; + + /** */ + private long warmUpEndTime; + + /** */ + private long endTime; + + /** */ + private long loadedPages; + + /** */ + private long delta; + + /** */ + private long probeCnt; + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + DataStructure.rnd = null; + + long startTime = System.nanoTime(); + + warmUpEndTime = startTime + TimeUnit.SECONDS.toNanos(warmUp()); + + endTime = warmUpEndTime + TimeUnit.SECONDS.toNanos(duration()); + } + + /** {@inheritDoc} */ + @Override protected void configure(IgniteConfiguration cfg) { + cfg.setMetricsLogFrequency(5000); + } + + /** {@inheritDoc} */ + @Override protected void configure(MemoryConfiguration mCfg) { + mCfg.setConcurrencyLevel(CONCURRENCY_LEVEL); + + long size = (1024 * (isLargePage() ? 16 : 1) + 24) * pagesMax(); + + mCfg.setPageCacheSize(Math.max(size, MIN_PAGE_CACHE_SIZE)); + } + + /** + * @return Test duration in seconds. + */ + protected int duration() { + return getInteger("IGNITE_MEMORY_LEAKS_TEST_DURATION", 300); + } + + /** + * @return Warm up duration in seconds. + */ + @SuppressWarnings("WeakerAccess") + protected int warmUp() { + return getInteger("IGNITE_MEMORY_LEAKS_TEST_WARM_UP", 450); + } + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 1; + } + + /** {@inheritDoc} */ + @Override protected boolean indexingEnabled() { + return false; + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return (warmUp() + duration() + 10) * 1000; // Extra seconds to stop all threads. + } + + /** + * @param ig Ignite instance. + * @return IgniteCache. + */ + protected abstract IgniteCache cache(IgniteEx ig); + + /** + * @return Cache key to perform an operation. + */ + protected abstract Object key(); + + /** + * @param key Cache key to perform an operation. + * @return Cache value to perform an operation. + */ + protected abstract Object value(Object key); + + /** + * @param cache IgniteCache. + */ + protected void operation(IgniteCache cache) { + Object key = key(); + Object val = value(key); + + switch (nextInt(3)) { + case 0: + cache.getAndPut(key, val); + + break; + + case 1: + cache.get(key); + + break; + + case 2: + cache.getAndRemove(key); + } + } + + /** + * @param bound Upper bound (exclusive). Must be positive. + * @return Random int value. + */ + protected static int nextInt(int bound) { + return ThreadLocalRandom.current().nextInt(bound); + } + + /** + * @return Random int value. + */ + protected static int nextInt() { + return ThreadLocalRandom.current().nextInt(); + } + + /** + * @throws Exception If failed. + */ + public void testMemoryLeak() throws Exception { + final IgniteEx ignite = grid(0); + + final IgniteCache cache = cache(ignite); + + Runnable target = new Runnable() { + @Override public void run() { + while (ex == null && System.nanoTime() < endTime) { + try { + operation(cache); + } + catch (Exception e) { + ex = e; + + break; + } + } + } + }; + + Thread[] threads = new Thread[CONCURRENCY_LEVEL]; + + info("Warming up is started."); + + for (int i = 0; i < threads.length; i++) { + threads[i] = new Thread(target); + threads[i].start(); + } + + while (ex == null && System.nanoTime() < warmUpEndTime) + Thread.sleep(100); + + if (ex != null) + throw ex; + + info("Warming up is ended."); + + while (ex == null && System.nanoTime() < endTime) { + try { + check(ignite); + } + catch (Exception e) { + ex = e; + + break; + } + + Thread.sleep(TimeUnit.SECONDS.toMillis(5)); + } + + if (ex != null) + throw ex; + } + + /** + * Callback to check the current state. + * + * @param ig Ignite instance. + * @throws Exception If failed. + */ + protected void check(IgniteEx ig) throws Exception { + long pagesActual = ig.context().cache().context().database().pageMemory().loadedPages(); + + if (loadedPages > 0) { + delta += pagesActual - loadedPages; + + int allowedDelta = pagesDelta(); + + if (probeCnt++ > 12) { // We need some statistic first. Minimal statistic is taken for a minute. + long actualDelta = delta / probeCnt; + + assertTrue( + "Average growth pages in the number is more than expected [allowed=" + allowedDelta + ", actual=" + actualDelta + "]", + actualDelta <= allowedDelta); + } + } + + loadedPages = pagesActual; + } + + /** + * @return Maximal allowed pages number. + */ + protected abstract long pagesMax(); + + /** + * @return Expected average number of pages, on which their total number can grow per 5 seconds. + */ + @SuppressWarnings("WeakerAccess") + protected int pagesDelta() { + return 3; + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakLargeObjectsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakLargeObjectsTest.java new file mode 100644 index 0000000000000..077a1e19d9cd6 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakLargeObjectsTest.java @@ -0,0 +1,56 @@ +/* + * 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.database; + +import org.apache.ignite.IgniteCache; +import org.apache.ignite.internal.IgniteEx; + +/** + * + */ +public class IgniteDbMemoryLeakLargeObjectsTest extends IgniteDbMemoryLeakAbstractTest { + /** */ + private final static int[] ARRAY; + + static { + ARRAY = new int[1024]; + + for (int i = 0; i < ARRAY.length; i++) + ARRAY[i] = nextInt(); + } + + /** {@inheritDoc} */ + @Override protected IgniteCache cache(IgniteEx ig) { + return ig.cache("large"); + } + + /** {@inheritDoc} */ + @Override protected Object key() { + return new LargeDbKey(nextInt(10_000), 1024); + } + + /** {@inheritDoc} */ + @Override protected Object value(Object key) { + return new LargeDbValue("test-value-1-" + nextInt(200), "test-value-2-" + nextInt(200), ARRAY); + } + + /** {@inheritDoc} */ + @Override protected long pagesMax() { + return 35_000; + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakLargePagesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakLargePagesTest.java new file mode 100644 index 0000000000000..540681db4ecb5 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakLargePagesTest.java @@ -0,0 +1,33 @@ +/* + * 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.database; + +/** + * + */ +public class IgniteDbMemoryLeakLargePagesTest extends IgniteDbMemoryLeakTest { + /** {@inheritDoc} */ + @Override protected boolean isLargePage() { + return true; + } + + /** {@inheritDoc} */ + @Override protected long pagesMax() { + return 4000; + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakNonTransactionalTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakNonTransactionalTest.java new file mode 100644 index 0000000000000..2a6293d12af57 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakNonTransactionalTest.java @@ -0,0 +1,31 @@ +/* + * 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.database; + +import org.apache.ignite.IgniteCache; +import org.apache.ignite.internal.IgniteEx; + +/** + * + */ +public class IgniteDbMemoryLeakNonTransactionalTest extends IgniteDbMemoryLeakTest { + /** {@inheritDoc} */ + @Override protected IgniteCache cache(IgniteEx ig) { + return ig.cache("atomic"); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakTest.java new file mode 100644 index 0000000000000..b8ac8f097ee90 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakTest.java @@ -0,0 +1,46 @@ +/* + * 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.database; + +import org.apache.ignite.IgniteCache; +import org.apache.ignite.internal.IgniteEx; + +/** + * + */ +public class IgniteDbMemoryLeakTest extends IgniteDbMemoryLeakAbstractTest { + /** {@inheritDoc} */ + @Override protected IgniteCache cache(IgniteEx ig) { + return ig.cache("non-primitive"); + } + + /** {@inheritDoc} */ + @Override protected Object key() { + return new DbKey(nextInt(200_000)); + } + + /** {@inheritDoc} */ + @Override protected Object value(Object key) { + return new DbValue(((DbKey)key).val, "test-value-" + nextInt(200), nextInt(500)); + } + + /** {@inheritDoc} */ + @Override protected long pagesMax() { + return 20_000; + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakWithExpirationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakWithExpirationTest.java new file mode 100644 index 0000000000000..6e0abaf25e2b1 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakWithExpirationTest.java @@ -0,0 +1,44 @@ +/* + * 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.database; + +import javax.cache.expiry.CreatedExpiryPolicy; +import javax.cache.expiry.Duration; +import javax.cache.expiry.ExpiryPolicy; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.internal.IgniteEx; + +import static java.util.concurrent.TimeUnit.MILLISECONDS; + +/** + * + */ +public class IgniteDbMemoryLeakWithExpirationTest extends IgniteDbMemoryLeakTest { + /** */ + private static final ExpiryPolicy EXPIRY = new CreatedExpiryPolicy(new Duration(MILLISECONDS, 10L)); + + /** {@inheritDoc} */ + @Override protected IgniteCache cache(IgniteEx ig) { + return ig.cache("non-primitive").withExpiryPolicy(EXPIRY); + } + + /** {@inheritDoc} */ + @Override protected long pagesMax() { + return 7000; + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java index 2c37d8a55930a..86f1237a486a6 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java @@ -17,8 +17,6 @@ package org.apache.ignite.internal.processors.database; -import java.io.Serializable; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -32,13 +30,8 @@ import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteDataStreamer; -import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CachePeekMode; -import org.apache.ignite.cache.CacheRebalanceMode; -import org.apache.ignite.cache.CacheWriteSynchronizationMode; import org.apache.ignite.cache.affinity.Affinity; -import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; -import org.apache.ignite.cache.affinity.AffinityFunction; import org.apache.ignite.cache.query.QueryCursor; import org.apache.ignite.cache.query.ScanQuery; import org.apache.ignite.cache.query.SqlFieldsQuery; @@ -55,22 +48,13 @@ import org.apache.ignite.internal.util.GridRandom; import org.apache.ignite.internal.util.typedef.PA; import org.apache.ignite.internal.util.typedef.X; -import org.apache.ignite.internal.util.typedef.internal.S; -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.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 org.junit.Assert; /** * */ -public abstract class IgniteDbPutGetAbstractTest extends GridCommonAbstractTest { - /** */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - +public abstract class IgniteDbPutGetAbstractTest extends IgniteDbAbstractTest { /** */ private static final int KEYS_COUNT = 20_000; @@ -91,121 +75,6 @@ protected boolean withClientNearCache() { return false; } - /** */ - private boolean client = false; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - MemoryConfiguration dbCfg = new MemoryConfiguration(); - - if (client) - cfg.setClientMode(true); - - if (isLargePage()) { - dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); - - dbCfg.setPageSize(16 * 1024); - - dbCfg.setPageCacheSize(200 * 1024 * 1024); - } - else { - dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); - - dbCfg.setPageSize(1024); - - dbCfg.setPageCacheSize(200 * 1024 * 1024); - } - - cfg.setMemoryConfiguration(dbCfg); - - CacheConfiguration ccfg = new CacheConfiguration(); - - if (indexingEnabled()) - ccfg.setIndexedTypes(Integer.class, DbValue.class); - - ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); - ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); - ccfg.setRebalanceMode(CacheRebalanceMode.SYNC); - ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); - - CacheConfiguration ccfg2 = new CacheConfiguration("non-primitive"); - - if (indexingEnabled()) - ccfg2.setIndexedTypes(DbKey.class, DbValue.class); - - ccfg2.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); - ccfg2.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); - ccfg2.setRebalanceMode(CacheRebalanceMode.SYNC); - ccfg2.setAffinity(new RendezvousAffinityFunction(false, 32)); - - CacheConfiguration ccfg3 = new CacheConfiguration("large"); - - if (indexingEnabled()) - ccfg3.setIndexedTypes(Integer.class, LargeDbValue.class); - - ccfg3.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); - ccfg3.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); - ccfg3.setRebalanceMode(CacheRebalanceMode.SYNC); - ccfg3.setAffinity(new RendezvousAffinityFunction(false, 32)); - - CacheConfiguration ccfg4 = new CacheConfiguration("tiny"); - - ccfg4.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); - ccfg4.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); - ccfg4.setRebalanceMode(CacheRebalanceMode.SYNC); - ccfg4.setAffinity(new RendezvousAffinityFunction(false, 32)); - - final AffinityFunction aff = new RendezvousAffinityFunction(1, null); - - ccfg4.setAffinity(aff); - - if (!client) - cfg.setCacheConfiguration(ccfg, ccfg2, ccfg3, ccfg4); - - TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); - - discoSpi.setIpFinder(IP_FINDER); - - cfg.setDiscoverySpi(discoSpi); - cfg.setMarshaller(null); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - - long seed = System.currentTimeMillis(); - - info("Seed: " + seed + "L"); - - BPlusTree.rnd = new Random(seed); - - startGrids(gridCount()); - - if (withClientNearCache()) { - client = true; - - startGrid(gridCount()); - - client = false; - } - - awaitPartitionMapExchange(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - BPlusTree.rnd = null; - - stopAllGrids(); - - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - } - /** * @return Ignite instance for testing. */ @@ -243,9 +112,7 @@ public void testGradualRandomPutAllRemoveAll() throws Exception { final int cnt = KEYS_COUNT; - Random rnd = BPlusTree.rnd; - - assert rnd != null; + Random rnd = new Random(); Map map = new HashMap<>(); @@ -1369,195 +1236,4 @@ private void checkEmpty(final GridCacheAdapter internalCache, final Object key) assertNull(internalCache.peekEx(key)); } - - /** - * - */ - private static class DbKey implements Serializable { - /** */ - private int val; - - /** - * @param val Value. - */ - private DbKey(int val) { - this.val = val; - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - if (this == o) - return true; - - if (o == null || !(o instanceof DbKey)) - return false; - - DbKey key = (DbKey)o; - - return val == key.val; - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return val; - } - } - - /** - * - */ - private static class LargeDbKey implements Serializable { - /** */ - private int val; - - /** */ - private byte[] data; - - /** - * @param val Value. - * @param size Key payload size. - */ - private LargeDbKey(int val, int size) { - this.val = val; - - data = new byte[size]; - - Arrays.fill(data, (byte)val); - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - if (this == o) - return true; - - if (o == null || !(o instanceof LargeDbKey)) - return false; - - LargeDbKey key = (LargeDbKey)o; - - return val == key.val && Arrays.equals(data, key.data); - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return val + Arrays.hashCode(data); - } - } - - /** - * - */ - private static class DbValue implements Serializable { - /** */ - @QuerySqlField(index = true) - private int iVal; - - /** */ - @QuerySqlField(index = true) - private String sVal; - - /** */ - @QuerySqlField - private long lVal; - - /** - * @param iVal Integer value. - * @param sVal String value. - * @param lVal Long value. - */ - public DbValue(int iVal, String sVal, long lVal) { - this.iVal = iVal; - this.sVal = sVal; - this.lVal = lVal; - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - if (this == o) - return true; - - if (o == null || getClass() != o.getClass()) - return false; - - DbValue dbVal = (DbValue)o; - - return iVal == dbVal.iVal && lVal == dbVal.lVal && - !(sVal != null ? !sVal.equals(dbVal.sVal) : dbVal.sVal != null); - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - int res = iVal; - - res = 31 * res + (sVal != null ? sVal.hashCode() : 0); - res = 31 * res + (int)(lVal ^ (lVal >>> 32)); - - return res; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(DbValue.class, this); - } - } - - /** - * - */ - private static class LargeDbValue { - /** */ - @QuerySqlField(index = true) - private String str1; - - /** */ - @QuerySqlField(index = true) - private String str2; - - /** */ - private int[] arr; - - /** - * @param str1 String 1. - * @param str2 String 2. - * @param arr Big array. - */ - public LargeDbValue(final String str1, final String str2, final int[] arr) { - this.str1 = str1; - this.str2 = str2; - this.arr = arr; - } - - /** {@inheritDoc} */ - @Override public boolean equals(final Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - - final LargeDbValue that = (LargeDbValue)o; - - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) - return false; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) - return false; - - return Arrays.equals(arr, that.arr); - - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - int res = str1 != null ? str1.hashCode() : 0; - - res = 31 * res + (str2 != null ? str2.hashCode() : 0); - res = 31 * res + Arrays.hashCode(arr); - - return res; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(LargeDbValue.class, this); - } - } } diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteDbMemoryLeakTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteDbMemoryLeakTestSuite.java new file mode 100644 index 0000000000000..f271bd88c4b7d --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteDbMemoryLeakTestSuite.java @@ -0,0 +1,49 @@ +/* + * 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.testsuites; + +import junit.framework.TestSuite; +import org.apache.ignite.cache.LargeEntryUpdateTest; +import org.apache.ignite.internal.processors.database.IgniteDbMemoryLeakLargeObjectsTest; +import org.apache.ignite.internal.processors.database.IgniteDbMemoryLeakLargePagesTest; +import org.apache.ignite.internal.processors.database.IgniteDbMemoryLeakNonTransactionalTest; +import org.apache.ignite.internal.processors.database.IgniteDbMemoryLeakTest; +import org.apache.ignite.internal.processors.database.IgniteDbMemoryLeakWithExpirationTest; + +/** + * Page memory leaks tests. + */ +public class IgniteDbMemoryLeakTestSuite extends TestSuite { + /** + * @return Test suite. + * @throws Exception Thrown in case of the failure. + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("Ignite Db Memory Leaks Test Suite"); + + suite.addTestSuite(IgniteDbMemoryLeakTest.class); + suite.addTestSuite(IgniteDbMemoryLeakWithExpirationTest.class); + suite.addTestSuite(IgniteDbMemoryLeakLargePagesTest.class); + suite.addTestSuite(IgniteDbMemoryLeakLargeObjectsTest.class); + suite.addTestSuite(IgniteDbMemoryLeakNonTransactionalTest.class); + + suite.addTestSuite(LargeEntryUpdateTest.class); + + return suite; + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakIndexedTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakIndexedTest.java new file mode 100644 index 0000000000000..f6a06c95f43ef --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakIndexedTest.java @@ -0,0 +1,33 @@ +/* + * 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.database; + +/** + * + */ +public class IgniteDbMemoryLeakIndexedTest extends IgniteDbMemoryLeakTest { + /** {@inheritDoc} */ + @Override protected boolean indexingEnabled() { + return true; + } + + /** {@inheritDoc} */ + @Override protected long pagesMax() { + return 24_000; + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakSqlQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakSqlQueryTest.java new file mode 100644 index 0000000000000..57f9fb575cabd --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakSqlQueryTest.java @@ -0,0 +1,76 @@ +/* + * 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.database; + +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.jetbrains.annotations.NotNull; + +/** + * + */ +public class IgniteDbMemoryLeakSqlQueryTest extends IgniteDbMemoryLeakTest { + /** {@inheritDoc} */ + @Override protected boolean indexingEnabled() { + return true; + } + + /** {@inheritDoc} */ + @Override protected long pagesMax() { + return 24_000; + } + + /** {@inheritDoc} */ + @Override protected void operation(IgniteCache cache) { + Object key = key(); + Object val = value(key); + + switch (nextInt(4)) { + case 0: + cache.getAndPut(key, val); + + break; + + case 1: + cache.get(key); + + break; + + case 2: + cache.getAndRemove(key); + + break; + + case 3: + cache.query(sqlQuery(cache)).getAll(); + } + } + + /** + * @param cache IgniteCache. + * @return SqlFieldsQuery. + */ + @NotNull private SqlFieldsQuery sqlQuery(IgniteCache cache) { + String qry = String.format("select _key from \"%s\".DbValue where iVal=?", cache.getName()); + + SqlFieldsQuery sqlQry = new SqlFieldsQuery(qry); + sqlQry.setArgs(nextInt(200_000)); + + return sqlQry; + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteDbMemoryLeakWithIndexingTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteDbMemoryLeakWithIndexingTestSuite.java new file mode 100644 index 0000000000000..36cd10130da1d --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteDbMemoryLeakWithIndexingTestSuite.java @@ -0,0 +1,40 @@ +/* + * 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.testsuites; + +import junit.framework.TestSuite; +import org.apache.ignite.internal.processors.database.IgniteDbMemoryLeakIndexedTest; +import org.apache.ignite.internal.processors.database.IgniteDbMemoryLeakSqlQueryTest; + +/** + * Page memory leaks tests using indexing. + */ +public class IgniteDbMemoryLeakWithIndexingTestSuite extends TestSuite { + /** + * @return Test suite. + * @throws Exception Thrown in case of the failure. + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("Ignite Db Memory Leaks With Indexing Test Suite"); + + suite.addTestSuite(IgniteDbMemoryLeakSqlQueryTest.class); + suite.addTestSuite(IgniteDbMemoryLeakIndexedTest.class); + + return suite; + } +} From 937a1414df54a67be55633cf1a19066708f3c816 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Tue, 21 Mar 2017 20:00:12 +0300 Subject: [PATCH 086/311] ignite-4712 Memory leaks in PageMemory --- .../database/IgniteDbAbstractTest.java | 24 ++++++++++++++- .../database/IgniteDbPutGetAbstractTest.java | 29 ------------------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java index cf26187cb9e8b..95ec17896ea8b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java @@ -54,6 +54,9 @@ public abstract class IgniteDbAbstractTest extends GridCommonAbstractTest { */ protected abstract boolean indexingEnabled(); + /** */ + protected boolean client; + /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { @@ -61,6 +64,9 @@ public abstract class IgniteDbAbstractTest extends GridCommonAbstractTest { MemoryConfiguration dbCfg = new MemoryConfiguration(); + if (client) + cfg.setClientMode(true); + dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); if (isLargePage()) @@ -121,7 +127,8 @@ public abstract class IgniteDbAbstractTest extends GridCommonAbstractTest { ccfg5.setRebalanceMode(SYNC); ccfg5.setAffinity(new RendezvousAffinityFunction(false, 32)); - cfg.setCacheConfiguration(ccfg, ccfg2, ccfg3, ccfg4, ccfg5); + if (!client) + cfg.setCacheConfiguration(ccfg, ccfg2, ccfg3, ccfg4, ccfg5); TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); @@ -149,6 +156,13 @@ protected void configure(MemoryConfiguration mCfg){ // No-op. } + /** + * @return {@code True} if cache operations should be called from client node with near cache. + */ + protected boolean withClientNearCache() { + return false; + } + /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); @@ -161,6 +175,14 @@ protected void configure(MemoryConfiguration mCfg){ startGrids(gridCount()); + if (withClientNearCache()) { + client = true; + + startGrid(gridCount()); + + client = false; + } + awaitPartitionMapExchange(); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java index 86f1237a486a6..cfb9b087268ab 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java @@ -36,14 +36,9 @@ import org.apache.ignite.cache.query.ScanQuery; import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.cache.query.SqlQuery; -import org.apache.ignite.cache.query.annotations.QuerySqlField; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.MemoryConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.NearCacheConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter; import org.apache.ignite.internal.util.GridRandom; import org.apache.ignite.internal.util.typedef.PA; @@ -58,23 +53,6 @@ public abstract class IgniteDbPutGetAbstractTest extends IgniteDbAbstractTest { /** */ private static final int KEYS_COUNT = 20_000; - /** - * @return Node count. - */ - protected abstract int gridCount(); - - /** - * @return {@code True} if indexing is enabled. - */ - protected abstract boolean indexingEnabled(); - - /** - * @return {@code True} if cache operations should be called from client node with near cache. - */ - protected boolean withClientNearCache() { - return false; - } - /** * @return Ignite instance for testing. */ @@ -97,13 +75,6 @@ private IgniteCache cache(String name) throws Exception { return ig().cache(name); } - /** - * @return {@code True} if use large page. - */ - protected boolean isLargePage() { - return false; - } - /** * */ From 719fb5a914bdcfa42e0db4aa208fa7fd57cca9fc Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Thu, 23 Mar 2017 16:07:33 +0300 Subject: [PATCH 087/311] IGNITE-3477 - Rebuilt classnames.properties --- .../resources/META-INF/classnames.properties | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index 1750276480a33..7dd19292bdbb5 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -16,6 +16,7 @@ # org.apache.ignite.IgniteAuthenticationException +org.apache.ignite.IgniteCacheRestartingException org.apache.ignite.IgniteCheckedException org.apache.ignite.IgniteClientDisconnectedException org.apache.ignite.IgniteDataStreamerTimeoutException @@ -162,6 +163,8 @@ org.apache.ignite.events.IgfsEvent org.apache.ignite.events.JobEvent org.apache.ignite.events.SwapSpaceEvent org.apache.ignite.events.TaskEvent +org.apache.ignite.hadoop.HadoopInputSplit +org.apache.ignite.hadoop.HadoopMapReducePlan org.apache.ignite.igfs.IgfsConcurrentModificationException org.apache.ignite.igfs.IgfsCorruptedFileException org.apache.ignite.igfs.IgfsDirectoryNotEmptyException @@ -312,13 +315,13 @@ org.apache.ignite.internal.managers.deployment.GridDeploymentPerVersionStore$2 org.apache.ignite.internal.managers.deployment.GridDeploymentRequest org.apache.ignite.internal.managers.deployment.GridDeploymentResponse org.apache.ignite.internal.managers.discovery.CustomMessageWrapper +org.apache.ignite.internal.managers.discovery.DiscoCache$1 +org.apache.ignite.internal.managers.discovery.DiscoCache$2 org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage org.apache.ignite.internal.managers.discovery.GridDiscoveryManager$1 org.apache.ignite.internal.managers.discovery.GridDiscoveryManager$2 org.apache.ignite.internal.managers.discovery.GridDiscoveryManager$4$1 -org.apache.ignite.internal.managers.discovery.GridDiscoveryManager$4$2 org.apache.ignite.internal.managers.discovery.GridDiscoveryManager$6 -org.apache.ignite.internal.managers.discovery.GridDiscoveryManager$DiscoCache$1 org.apache.ignite.internal.managers.discovery.GridLocalMetrics org.apache.ignite.internal.managers.eventstorage.GridEventStorageMessage org.apache.ignite.internal.managers.indexing.GridIndexingManager$1 @@ -326,8 +329,8 @@ org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerAdapter org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerManager$1 org.apache.ignite.internal.mem.OutOfMemoryException org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl$Segment -org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationFinishedMessage -org.apache.ignite.internal.pagemem.snapshot.SnapshotProgressMessage +org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation +org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationType org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationDiscoveryMessage org.apache.ignite.internal.pagemem.wal.StorageException @@ -381,6 +384,7 @@ org.apache.ignite.internal.processors.cache.CacheObjectImpl org.apache.ignite.internal.processors.cache.CacheOperationContext org.apache.ignite.internal.processors.cache.CacheOperationFilter org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException +org.apache.ignite.internal.processors.cache.CacheStoppedException org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException org.apache.ignite.internal.processors.cache.CacheType org.apache.ignite.internal.processors.cache.CacheWeakQueryIteratorsHolder$WeakQueryCloseableIterator @@ -503,6 +507,7 @@ org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$4 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$5 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$6 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$7 +org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$8 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeFutureSet org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$MessageHandler org.apache.ignite.internal.processors.cache.GridCacheProcessor$2 @@ -553,6 +558,7 @@ org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$8 org.apache.ignite.internal.processors.cache.IgniteCacheProxy org.apache.ignite.internal.processors.cache.IgniteCacheProxy$1 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$10 +org.apache.ignite.internal.processors.cache.IgniteCacheProxy$12 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$2 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$2$1 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$3 @@ -571,6 +577,7 @@ org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImp org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetaDataEntryFilter org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetaDataPredicate org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetadataProcessor +org.apache.ignite.internal.processors.cache.database.CacheDataRowAdapter$RowData org.apache.ignite.internal.processors.cache.database.tree.BPlusTree$Bool org.apache.ignite.internal.processors.cache.database.tree.BPlusTree$DestroyBag org.apache.ignite.internal.processors.cache.database.tree.BPlusTree$Result @@ -621,7 +628,6 @@ org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtGetSingleFutu org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtGetSingleFuture$2 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtGetSingleFuture$3 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException -org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition$2 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture$1 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture$2 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture$3 @@ -740,7 +746,6 @@ org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPar org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$1$1 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$2 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$3 -org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$3$1 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$4$1 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$5$1 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$DemandWorker$1 @@ -770,6 +775,9 @@ org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPre org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$8 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$MessageHandler org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloaderAssignments +org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionCountersMap +org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionHistorySuppliersMap +org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionsToReloadMap org.apache.ignite.internal.processors.cache.distributed.near.CacheVersionedValue org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache$1 @@ -1044,7 +1052,6 @@ org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$Buffer$1 org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$Buffer$2 org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$Buffer$3 org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$DataStreamerPda -org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$DefaultIoPolicyResolver org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl$IsolatedUpdater org.apache.ignite.internal.processors.datastreamer.DataStreamerRequest org.apache.ignite.internal.processors.datastreamer.DataStreamerResponse @@ -1121,13 +1128,10 @@ org.apache.ignite.internal.processors.dr.GridDrType org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater org.apache.ignite.internal.processors.hadoop.HadoopDefaultJobInfo org.apache.ignite.internal.processors.hadoop.HadoopFileBlock -org.apache.ignite.hadoop.HadoopInputSplit org.apache.ignite.internal.processors.hadoop.HadoopJobId -org.apache.ignite.internal.processors.hadoop.HadoopJobInfo org.apache.ignite.internal.processors.hadoop.HadoopJobPhase org.apache.ignite.internal.processors.hadoop.HadoopJobProperty org.apache.ignite.internal.processors.hadoop.HadoopJobStatus -org.apache.ignite.hadoop.HadoopMapReducePlan org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo org.apache.ignite.internal.processors.hadoop.HadoopTaskType org.apache.ignite.internal.processors.hadoop.message.HadoopMessage @@ -1288,12 +1292,12 @@ org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionL org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionSetAndUnlockProcessor org.apache.ignite.internal.processors.query.GridQueryFieldMetadata org.apache.ignite.internal.processors.query.GridQueryIndexType -org.apache.ignite.internal.processors.query.GridQueryProcessor$3 org.apache.ignite.internal.processors.query.GridQueryProcessor$4 org.apache.ignite.internal.processors.query.GridQueryProcessor$5 org.apache.ignite.internal.processors.query.GridQueryProcessor$6 org.apache.ignite.internal.processors.query.GridQueryProcessor$7 org.apache.ignite.internal.processors.query.GridQueryProcessor$8 +org.apache.ignite.internal.processors.query.GridQueryProcessor$9 org.apache.ignite.internal.processors.query.GridQueryProcessor$IndexType org.apache.ignite.internal.processors.query.IgniteSQLException org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryCancelRequest @@ -1632,6 +1636,7 @@ org.apache.ignite.internal.util.nio.GridNioException org.apache.ignite.internal.util.nio.GridNioMessageTracker org.apache.ignite.internal.util.nio.GridNioServer$NioOperation org.apache.ignite.internal.util.nio.GridNioServer$RandomBalancer +org.apache.ignite.internal.util.nio.GridNioServer$ReadWriteSizeBasedBalancer org.apache.ignite.internal.util.nio.GridNioServer$SizeBasedBalancer org.apache.ignite.internal.util.nio.GridNioSessionMetaKey org.apache.ignite.internal.util.nio.ssl.GridNioSslHandler From 6eec695f5d1223c73f336f05641e2de7004fc5fa Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Thu, 23 Mar 2017 22:25:00 +0300 Subject: [PATCH 088/311] GG-12061 Corrupted snapshot causes CHECK to quietly fail with assertion --- .../MetaPageUpdateLastAllocatedIndex.java | 2 +- .../cache/database/tree/io/PageMetaIO.java | 34 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastAllocatedIndex.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastAllocatedIndex.java index bd9b1000fdb5c..d916be26e92b7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastAllocatedIndex.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastAllocatedIndex.java @@ -44,7 +44,7 @@ public MetaPageUpdateLastAllocatedIndex(int cacheId, long pageId, int lastAlloca PageMetaIO io = PageMetaIO.VERSIONS.forVersion(PageIO.getVersion(pageAddr)); - io.setLastAllocatedIndex(pageAddr, lastAllocatedIdx); + io.setLastPageCount(pageAddr, lastAllocatedIdx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java index e768f47ed7425..7a5535c27022f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java @@ -44,13 +44,13 @@ public class PageMetaIO extends PageIO { private static final int LAST_SUCCESSFUL_FULL_SNAPSHOT_TAG_OFF = NEXT_SNAPSHOT_TAG_OFF + 8; /** Last allocated index offset. */ - private static final int LAST_ALLOCATED_INDEX_OFF = LAST_SUCCESSFUL_FULL_SNAPSHOT_TAG_OFF + 8; + private static final int LAST_PAGE_COUNT_OFF = LAST_SUCCESSFUL_FULL_SNAPSHOT_TAG_OFF + 8; /** Candidate allocated index offset. */ - private static final int CANDIDATE_ALLOCATED_INDEX_OFF = LAST_ALLOCATED_INDEX_OFF + 4; + private static final int CANDIDATE_PAGE_COUNT_OFF = LAST_PAGE_COUNT_OFF + 4; /** End of page meta. */ - static final int END_OF_PAGE_META = CANDIDATE_ALLOCATED_INDEX_OFF + 4; + static final int END_OF_PAGE_META = CANDIDATE_PAGE_COUNT_OFF + 4; /** */ public static final IOVersions VERSIONS = new IOVersions<>( @@ -82,8 +82,8 @@ protected PageMetaIO(int type, int ver) { setLastSuccessfulSnapshotId(pageAddr, 0); setNextSnapshotTag(pageAddr, 1); setLastSuccessfulSnapshotTag(pageAddr, 0); - setLastAllocatedIndex(pageAddr, 0); - setCandidateAllocatedIndex(pageAddr, 0); + setLastPageCount(pageAddr, 0); + setCandidatePageCount(pageAddr, 0); } /** @@ -180,38 +180,38 @@ public long getNextSnapshotTag(long pageAddr) { /** * @param pageAddr Page address. - * @param lastAllocatedIdx Last allocated index. + * @param pageCnt Last allocated index. */ - public void setLastAllocatedIndex(long pageAddr, int lastAllocatedIdx) { - PageUtils.putInt(pageAddr, LAST_ALLOCATED_INDEX_OFF, lastAllocatedIdx); + public void setLastPageCount(long pageAddr, int pageCnt) { + PageUtils.putInt(pageAddr, LAST_PAGE_COUNT_OFF, pageCnt); } /** * @param buf Buffer. */ - public int getLastAllocatedIndex(@NotNull ByteBuffer buf) { - return buf.getInt(LAST_ALLOCATED_INDEX_OFF); + public int getLastPageCount(@NotNull ByteBuffer buf) { + return buf.getInt(LAST_PAGE_COUNT_OFF); } /** * @param pageAddr Page address. */ - public int getLastAllocatedIndex(long pageAddr) { - return PageUtils.getInt(pageAddr, LAST_ALLOCATED_INDEX_OFF); + public int getLastPageCount(long pageAddr) { + return PageUtils.getInt(pageAddr, LAST_PAGE_COUNT_OFF); } /** * @param pageAddr Page address. - * @param previousAllocatedIdx Last allocated index. + * @param pageCnt Last page count. */ - public void setCandidateAllocatedIndex(long pageAddr, int previousAllocatedIdx) { - PageUtils.putInt(pageAddr, CANDIDATE_ALLOCATED_INDEX_OFF, previousAllocatedIdx); + public void setCandidatePageCount(long pageAddr, int pageCnt) { + PageUtils.putInt(pageAddr, CANDIDATE_PAGE_COUNT_OFF, pageCnt); } /** * @param pageAddr Page address. */ - public int getCandidateAllocatedIndex(long pageAddr) { - return PageUtils.getInt(pageAddr, CANDIDATE_ALLOCATED_INDEX_OFF); + public int getCandidatePageCount(long pageAddr) { + return PageUtils.getInt(pageAddr, CANDIDATE_PAGE_COUNT_OFF); } } From ef4238fce54dfea5f9a95113a57819b8b08b1b7d Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Mon, 27 Mar 2017 20:40:58 +0300 Subject: [PATCH 089/311] GG-12074 Creating checkpoint during writing snapshots to disc results in "Failed to create checkpoint" AND failed incremental SHAPSHOT command due to crc validation failure --- .../internal/pagemem/snapshot/SnapshotOperation.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index f3b5eeee0886a..93054ec9199da 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -154,4 +154,14 @@ public static File getMovingPathParameter(SnapshotOperation op) { result = 31 * result + (extraParam != null ? extraParam.hashCode() : 0); return result; } + + @Override public String toString() { + return "SnapshotOperation{" + + "type=" + type + + ", snapshotId=" + snapshotId + + ", cacheNames=" + cacheNames + + ", msg='" + msg + '\'' + + ", extraParam=" + extraParam + + '}'; + } } From 3a68d8550bfc34be48fd4298f537c4326de3feec Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Tue, 28 Mar 2017 17:19:56 +0300 Subject: [PATCH 090/311] GG-11894: Found one more place where CacheRestartingException is not thrown in case cache is restarting. --- .../distributed/dht/atomic/GridNearAtomicUpdateResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java index b5b11db32ece9..4b62f6b976bfd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java @@ -370,7 +370,7 @@ public synchronized void addFailedKeys(Collection keys, Throwabl } if (err == null) - err = new IgniteCheckedException("Failed to update keys on primary node."); + err = new IgniteCheckedException("Failed to update keys on primary node.", e); err.addSuppressed(e); } From 3a7e80164dc6a15f99979063ff214153a637a2f4 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Wed, 29 Mar 2017 20:41:50 +0300 Subject: [PATCH 091/311] GG-12081 ConcurrentModificationException in GridDhtPartitionsExchangeFuture --- .../processors/cache/transactions/IgniteTxStateImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java index 42aba77800944..3f3544dc4e7d8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java @@ -56,7 +56,7 @@ public class IgniteTxStateImpl extends IgniteTxLocalStateAdapter { private GridLongList activeCacheIds = new GridLongList(); /** Per-transaction read map. */ - @GridToStringInclude + @GridToStringExclude protected Map txMap; /** Read view on transaction map. */ @@ -475,6 +475,6 @@ public synchronized Collection allEntriesCopy() { /** {@inheritDoc} */ public String toString() { - return S.toString(IgniteTxStateImpl.class, this); + return S.toString(IgniteTxStateImpl.class, this, "txMap", allEntriesCopy()); } } From 9d71e3159ca4cc95e6943e637d7fa74cabf22d77 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Fri, 31 Mar 2017 17:21:02 +0300 Subject: [PATCH 092/311] GG-11894 - Fixed IgniteDbSnapshotSelfTest.testReuseCacheProxyAfterRestore --- .../internal/processors/cache/GridCacheAdapter.java | 9 +++++++-- .../internal/processors/cache/GridCacheGateway.java | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) 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 1470a971b3f7e..288eafc381e4d 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 @@ -58,6 +58,7 @@ import org.apache.ignite.cache.CachePeekMode; import org.apache.ignite.cache.affinity.Affinity; import org.apache.ignite.cluster.ClusterGroup; +import org.apache.ignite.cluster.ClusterGroupEmptyException; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.cluster.ClusterTopologyException; import org.apache.ignite.compute.ComputeJob; @@ -3802,8 +3803,12 @@ IgniteInternalFuture globalLoadCacheAsync(@Nullable IgniteBiPredicate p ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes); - return ctx.kernalContext().task().execute( - new SizeTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), peekModes), null); + try { + return ctx.kernalContext().task().execute( + new SizeTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), peekModes), null); + } catch (ClusterGroupEmptyException e) { + return new GridFinishedFuture<>(0); + } } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java index 1562d701a92bd..43142112c82d7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java @@ -82,7 +82,7 @@ private boolean checkState(boolean lock, boolean stopErr) { if (state == State.STOPPED) { if (stopErr) - throw new IllegalStateException("Cache has been stopped: " + ctx.name()); + throw new IllegalStateException(new CacheStoppedException(ctx.name())); else return false; } @@ -157,7 +157,7 @@ public void leave() { GridCachePreloader preldr = cache != null ? cache.preloader() : null; if (preldr == null) - throw new IllegalStateException("Cache has been closed or destroyed: " + ctx.name()); + throw new IllegalStateException(new CacheStoppedException(ctx.name())); preldr.startFuture().get(); } From 1229d2f1eaa8cf0fbdbc9b2409e089af4ce00fd9 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Mon, 3 Apr 2017 13:59:05 +0300 Subject: [PATCH 093/311] GG-11860 Implement snapshot status on platform level -fixing tests --- .../snapshot/FinishSnapshotOperationAckDiscoveryMessage.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/FinishSnapshotOperationAckDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/FinishSnapshotOperationAckDiscoveryMessage.java index e19ddc4810c4c..1e5ed4256314e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/FinishSnapshotOperationAckDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/FinishSnapshotOperationAckDiscoveryMessage.java @@ -25,6 +25,9 @@ * */ public class FinishSnapshotOperationAckDiscoveryMessage implements DiscoveryCustomMessage { + /** */ + private static final long serialVersionUID = 0L; + /** Id. */ private final IgniteUuid id = IgniteUuid.randomUuid(); From f2c9d6cd0f22974aa4e1db99cd519a954b18dd4c Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Mon, 10 Apr 2017 19:00:02 +0300 Subject: [PATCH 094/311] Moved updatePartitionSingleMap(...) outside of synchronized block. --- .../dht/preloader/GridDhtPartitionsExchangeFuture.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 28ecacbc311d1..b0d776f496c9a 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 @@ -1532,13 +1532,14 @@ public void onReceive(final ClusterNode node, final GridDhtPartitionsSingleMessa */ private void processMessage(ClusterNode node, GridDhtPartitionsSingleMessage msg) { boolean allReceived = false; + boolean updateSingleMap = false; synchronized (mux) { assert crd != null; if (crd.isLocal()) { if (remaining.remove(node.id())) { - updatePartitionSingleMap(node, msg); + updateSingleMap = true; if (exchangeOnChangeGlobalState && msg.getException() != null) changeGlobalStateExceptions.put(node.id(), msg.getException()); @@ -1550,6 +1551,9 @@ private void processMessage(ClusterNode node, GridDhtPartitionsSingleMessage msg singleMsgs.put(node, msg); } + if (updateSingleMap) + updatePartitionSingleMap(node, msg); + if (allReceived) onAllReceived(); } From ead06b06f4b164998bfc5853dfa28cac4b618d8d Mon Sep 17 00:00:00 2001 From: Aleksei Scherbakov Date: Mon, 10 Apr 2017 19:46:18 +0300 Subject: [PATCH 095/311] IGNITE-4920 Fixed. --- .../deployment/local/LocalDeploymentSpi.java | 12 +- .../p2p/GridP2PLocalDeploymentSelfTest.java | 109 ++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java index 68ef178ed74aa..87fa452aa5035 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java @@ -25,6 +25,7 @@ import java.util.Map.Entry; import java.util.concurrent.ConcurrentMap; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.compute.ComputeTask; import org.apache.ignite.compute.ComputeTaskName; import org.apache.ignite.internal.util.GridAnnotationsCache; @@ -67,6 +68,13 @@ @IgniteSpiConsistencyChecked(optional = false) @IgnoreIfPeerClassLoadingDisabled public class LocalDeploymentSpi extends IgniteSpiAdapter implements DeploymentSpi, LocalDeploymentSpiMBean { + /** */ + public static final String IGNITE_DEPLOYMENT_ADDITIONAL_CHECK = "ignite.deployment.additional.check"; + + /** */ + private static final boolean ENABLE_IGNITE_DEPLOYMENT_ADDITIONAL_CHECK = + IgniteSystemProperties.getBoolean(IGNITE_DEPLOYMENT_ADDITIONAL_CHECK); + /** */ @SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"}) @LoggerResource @@ -333,7 +341,9 @@ private boolean removeResources(@Nullable ClassLoader clsLdrToIgnore, Map fut = multithreadedAsync(new Callable() { + @Override public Void call() throws Exception { + while (!stop.get()) { + final Class clazz = root.loadClass("org.apache.ignite.p2p.GridP2PLocalDeploymentSelfTest$TestClosure"); + + ignite.compute(). + call((IgniteCallable) clazz.getDeclaredConstructor(ClassLoader.class).newInstance(root)); + } + + return null; + } + }, 1); + + ignite.scheduler().runLocal(new Runnable() { + @Override public void run() { + stop.set(true); + } + }, 10, TimeUnit.SECONDS); + + fut.get(); + } finally { + stopAllGrids(); + + System.clearProperty(IGNITE_CACHE_REMOVED_ENTRIES_TTL); + System.clearProperty(IGNITE_DEPLOYMENT_ADDITIONAL_CHECK); + } + } + + /** */ + private static class TestClosure implements IgniteCallable, GridPeerDeployAware { + /** */ + transient ClassLoader clsLdr; + + /** + * @param cls Class. + */ + public TestClosure(ClassLoader cls) { + this.clsLdr = cls; + } + + /** {@inheritDoc} */ + public Object call() throws Exception { + return null; + } + + /** {@inheritDoc} */ + public Class deployClass() { + return this.getClass(); + } + + /** {@inheritDoc} */ + public ClassLoader classLoader() { + return clsLdr; + } + } + + /** */ + private static class DelegateClassLoader extends ClassLoader { + /** Delegate class loader. */ + private ClassLoader delegateClsLdr; + + /** + * @param parent Parent. + * @param delegateClsLdr Delegate class loader. + */ + public DelegateClassLoader(ClassLoader parent, ClassLoader delegateClsLdr) { + super(parent); // Parent doesn't matter. + this.delegateClsLdr = delegateClsLdr; + } + + /** {@inheritDoc} */ + @Override public URL getResource(String name) { + return delegateClsLdr.getResource(name); + } + + /** {@inheritDoc} */ + @Override public Class loadClass(String name) throws ClassNotFoundException { + return delegateClsLdr.loadClass(name); + } + } + /** * Simple resource. */ From 9ad0883c66120940740bc1944bd1e17814f9d540 Mon Sep 17 00:00:00 2001 From: Aleksei Scherbakov Date: Mon, 10 Apr 2017 19:58:09 +0300 Subject: [PATCH 096/311] IGNITE-4920 Fixed. --- .../ignite/spi/deployment/local/LocalDeploymentSpi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java index 87fa452aa5035..66f0326684c10 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java @@ -68,10 +68,10 @@ @IgniteSpiConsistencyChecked(optional = false) @IgnoreIfPeerClassLoadingDisabled public class LocalDeploymentSpi extends IgniteSpiAdapter implements DeploymentSpi, LocalDeploymentSpiMBean { - /** */ + /** Enables additional check for resource name on resources removal. */ public static final String IGNITE_DEPLOYMENT_ADDITIONAL_CHECK = "ignite.deployment.additional.check"; - /** */ + /** Value for additional check on resources removal. */ private static final boolean ENABLE_IGNITE_DEPLOYMENT_ADDITIONAL_CHECK = IgniteSystemProperties.getBoolean(IGNITE_DEPLOYMENT_ADDITIONAL_CHECK); From a3ad6e04c163718306044573be7b30fe636ad193 Mon Sep 17 00:00:00 2001 From: Aleksei Scherbakov Date: Wed, 12 Apr 2017 16:07:33 +0300 Subject: [PATCH 097/311] IGNITE-4920 Uppercase system prop. --- .../apache/ignite/spi/deployment/local/LocalDeploymentSpi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java index 66f0326684c10..741335b201887 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/deployment/local/LocalDeploymentSpi.java @@ -69,7 +69,7 @@ @IgnoreIfPeerClassLoadingDisabled public class LocalDeploymentSpi extends IgniteSpiAdapter implements DeploymentSpi, LocalDeploymentSpiMBean { /** Enables additional check for resource name on resources removal. */ - public static final String IGNITE_DEPLOYMENT_ADDITIONAL_CHECK = "ignite.deployment.additional.check"; + public static final String IGNITE_DEPLOYMENT_ADDITIONAL_CHECK = "IGNITE.DEPLOYMENT.ADDITIONAL.CHECK"; /** Value for additional check on resources removal. */ private static final boolean ENABLE_IGNITE_DEPLOYMENT_ADDITIONAL_CHECK = From ea02f6a025994a7f0567ac1959ff03cf1cb9d982 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Thu, 13 Apr 2017 17:59:56 +0300 Subject: [PATCH 098/311] GG-12064 Need to have an ability to cancel snapshot operations -fixing issues with client nodes --- .../GridDhtPartitionsExchangeFuture.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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 28ecacbc311d1..248412406aa00 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 @@ -622,6 +622,14 @@ else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) { default: assert false; } + + if (cctx.localNode().isClient()) { + StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg = getSnapshotOperationMessage(); + + // If it's a snapshot operation request, synchronously wait for backup start. + if (snapshotOperationMsg != null) + startLocalSnasphotOperation(snapshotOperationMsg); + } } catch (IgniteInterruptedCheckedException e) { onDone(e); @@ -906,12 +914,10 @@ private void distributedExchange() throws IgniteCheckedException { // If it's a snapshot operation request, synchronously wait for backup start. if (snapshotOperationMsg != null) { - if (!cctx.localNode().isClient() && !cctx.localNode().isDaemon()) { - SnapshotOperation op = snapshotOperationMsg.snapshotOperation(); + SnapshotOperation op = snapshotOperationMsg.snapshotOperation(); - if (op.type() != SnapshotOperationType.RESTORE) - startLocalSnasphotOperation(snapshotOperationMsg); - } + if (op.type() != SnapshotOperationType.RESTORE) + startLocalSnasphotOperation(snapshotOperationMsg); } if (crd.isLocal()) { @@ -1281,7 +1287,7 @@ private void sendPartitions(ClusterNode oldestNode) { StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg = getSnapshotOperationMessage(); - if (snapshotOperationMsg != null && !cctx.localNode().isClient() && !cctx.localNode().isDaemon()) { + if (snapshotOperationMsg != null) { SnapshotOperation op = snapshotOperationMsg.snapshotOperation(); if (op.type() == SnapshotOperationType.RESTORE) From 4b8dc799fcd0173576e7e3439d5c7e88531fd1b7 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Fri, 14 Apr 2017 13:26:34 +0300 Subject: [PATCH 099/311] GG-12064 Need to have an ability to cancel snapshot operations -fixing issues with multiple exchange future completion --- .../dht/preloader/GridDhtPartitionsExchangeFuture.java | 5 +++++ 1 file changed, 5 insertions(+) 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 248412406aa00..ee5bed9912884 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 @@ -234,6 +234,8 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter Date: Mon, 17 Apr 2017 14:31:59 +0300 Subject: [PATCH 100/311] Fixing compilation after merge --- .../apache/ignite/IgniteSystemProperties.java | 3 - .../communication/GridIoMessageFactory.java | 6 - .../eventstorage/GridEventStorageManager.java | 56 -------- .../ignite/internal/pagemem/PageSupport.java | 2 +- .../GridCachePartitionExchangeManager.java | 4 +- .../cache/IgniteCacheOffheapManagerImpl.java | 5 +- .../IgniteCacheDatabaseSharedManager.java | 17 +-- .../dht/GridDhtLocalPartition.java | 27 ---- .../dht/preloader/GridDhtPreloader.java | 1 + .../processors/query/GridQueryProcessor.java | 9 +- .../CacheSerializableTransactionsTest.java | 124 ------------------ .../IgniteDbMemoryLeakAbstractTest.java | 3 +- 12 files changed, 12 insertions(+), 245 deletions(-) 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 9c81be276bd30..e53cca9310647 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -301,9 +301,6 @@ public final class IgniteSystemProperties { public static final String IGNITE_ATOMIC_CACHE_MAX_CONCURRENT_DHT_UPDATES = "IGNITE_ATOMIC_CACHE_MAX_CONCURRENT_DHT_UPDATES"; - /** Ttl of removed cache entries (ms). */ - public static final String IGNITE_CACHE_REMOVED_ENTRIES_TTL = "IGNITE_CACHE_REMOVED_ENTRIES_TTL"; - /** * Comma separated list of addresses in format "10.100.22.100:45000,10.100.22.101:45000". * Makes sense only for {@link org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder}. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java index e6ac63f868059..1d9ae5355ff8f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java @@ -33,7 +33,6 @@ import org.apache.ignite.internal.managers.deployment.GridDeploymentRequest; import org.apache.ignite.internal.managers.deployment.GridDeploymentResponse; import org.apache.ignite.internal.managers.eventstorage.GridEventStorageMessage; -import org.apache.ignite.internal.pagemem.snapshot.SnapshotProgressMessage; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse; import org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection; @@ -195,11 +194,6 @@ public GridIoMessageFactory(MessageFactory[] ext) { break; - case -47: - msg = new SnapshotProgressMessage(); - - break; - case -45: msg = new GridChangeGlobalStateMessageResponse(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java index 6e6d06114f904..04fb5b9a9a6bf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java @@ -347,30 +347,6 @@ private void record0(Event evt, Object... params) { } } - /** - * Records discovery events. - * - * @param evt Event to record. - * @param discoCache Discovery cache. - */ - public void record(DiscoveryEvent evt, DiscoCache discoCache) { - assert evt != null; - - if (!enterBusy()) - return; - - try { - // Notify internal discovery listeners first. - notifyDiscoveryListeners(evt, discoCache); - - // Notify all other registered listeners. - record(evt); - } - finally { - leaveBusy(); - } - } - /** * Gets types of enabled user-recordable events. * @@ -844,38 +820,6 @@ private boolean removeEventListener(EventListener lsnr, @Nullable int[] types) { return found; } - /** - * Removes listener for specified events, if any. If no event types provided - it - * remove the listener for all its registered events. - * - * @param lsnr Listener. - * @param types Event types. - * @return Returns {@code true} if removed. - */ - public boolean removeDiscoveryEventListener(DiscoveryEventListener lsnr, @Nullable int... types) { - assert lsnr != null; - - boolean found = false; - - if (F.isEmpty(types)) { - for (Set set : discoLsnrs.values()) - if (set.remove(lsnr)) - found = true; - } - else { - assert types != null; - - for (int type : types) { - Set set = discoLsnrs.get(type); - - if (set != null && set.remove(lsnr)) - found = true; - } - } - - return found; - } - /** * * @param p Optional predicate. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageSupport.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageSupport.java index 0f39058a820df..f4b2d96d4901e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageSupport.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageSupport.java @@ -98,7 +98,7 @@ public interface PageSupport { * @param pageId Page ID. * @param page Page pointer. * @param walPlc {@code True} if page should be recorded to WAL, {@code false} if the page must not -* be recorded and {@code null} for the default behavior. + * be recorded and {@code null} for the default behavior. * @param dirtyFlag Determines whether the page was modified since the last checkpoint. */ public void writeUnlock(int cacheId, long pageId, long page, Boolean walPlc, 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 598dfc97ebe82..57bbba36b1efe 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 @@ -59,8 +59,6 @@ import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; import org.apache.ignite.internal.managers.eventstorage.DiscoveryEventListener; import org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage; -import org.apache.ignite.internal.managers.discovery.DiscoCache; -import org.apache.ignite.internal.managers.eventstorage.DiscoveryEventListener; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; import org.apache.ignite.internal.processors.cache.distributed.dht.GridClientPartitionTopology; @@ -279,7 +277,7 @@ else if (customMsg instanceof CacheAffinityChangeMessage) { } } else { - exchangeFuture(msg.exchangeId(), null, null, null, null, null) + exchangeFuture(msg.exchangeId(), null, null, null, null) .onAffinityChangeMessage(evt.eventNode(), msg); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index 270c24353eb7e..f23eccb4d2266 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -31,7 +31,6 @@ import org.apache.ignite.configuration.DataPageEvictionMode; import org.apache.ignite.internal.NodeStoppingException; import org.apache.ignite.internal.pagemem.FullPageId; -import org.apache.ignite.internal.pagemem.PageIdUtils; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; @@ -54,7 +53,6 @@ import org.apache.ignite.internal.processors.cache.local.GridLocalCache; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; -import org.apache.ignite.internal.processors.query.GridQueryProcessor; import org.apache.ignite.internal.processors.query.QueryUtils; import org.apache.ignite.internal.util.GridAtomicLong; import org.apache.ignite.internal.util.GridCloseableIteratorAdapter; @@ -85,7 +83,6 @@ @SuppressWarnings("PublicInnerClass") public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter implements IgniteCacheOffheapManager { /** */ - // TODO GG-11208 need restore size after restart. private CacheDataStore locCacheDataStore; /** */ @@ -124,7 +121,7 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple @Override protected void start0() throws IgniteCheckedException { super.start0(); - indexingEnabled = GridQueryProcessor.isEnabled(cctx.config()); + indexingEnabled = QueryUtils.isEnabled(cctx.config()); updateValSizeThreshold = cctx.shared().database().pageSize() / 2; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index df6fb07684448..027a2fb32ac0e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -19,19 +19,17 @@ import java.io.File; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.Collections; -import java.util.Map; import javax.management.JMException; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.MemoryMetrics; -import org.apache.ignite.cluster.ClusterNode; -import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.DataPageEvictionMode; +import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.GridKernalContext; @@ -40,8 +38,8 @@ import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider; import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl; +import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; @@ -54,8 +52,8 @@ import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl; import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; -import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiTuple; import org.apache.ignite.mxbean.MemoryMetricsMXBean; import org.jetbrains.annotations.Nullable; @@ -466,13 +464,6 @@ public boolean persistenceEnabled() { return false; } - /** - * @return Page memory instance. - */ - public PageMemory pageMemory() { - return pageMem; - } - /** * */ 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 249848c6d5b8e..99515c0855ffe 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 @@ -331,33 +331,6 @@ public void cleanupRemoveQueue() { } } - /** - * - */ - public void cleanupRemoveQueue() { - while (rmvQueue.sizex() >= rmvQueueMaxSize) { - RemovedEntryHolder item = rmvQueue.pollFirst(); - - if (item != null) - cctx.dht().removeVersionedEntry(item.key(), item.version()); - } - - if (!cctx.isDrEnabled()) { - RemovedEntryHolder item = rmvQueue.peekFirst(); - - while (item != null && item.expireTime() < U.currentTimeMillis()) { - item = rmvQueue.pollFirst(); - - if (item == null) - break; - - cctx.dht().removeVersionedEntry(item.key(), item.version()); - - item = rmvQueue.peekFirst(); - } - } - } - /** * @param key Removed key. * @param ver Removed version. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java index eb4b4c81b9dc6..5f4136ada548f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java @@ -72,6 +72,7 @@ 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.managers.communication.GridIoPolicy.AFFINITY_POOL; +import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.MOVING; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.OWNING; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.RENTING; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 8a9d6bfb10e2e..207b1cd30f63e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -46,8 +46,6 @@ import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper; -import org.apache.ignite.internal.processors.cache.IgniteCacheProxy; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.QueryCursorImpl; import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture; @@ -63,9 +61,6 @@ import org.apache.ignite.internal.util.lang.GridClosureException; import org.apache.ignite.internal.util.lang.IgniteOutClosureX; import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.T2; -import org.apache.ignite.internal.util.typedef.internal.A; -import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.util.worker.GridWorker; @@ -373,12 +368,12 @@ private IgniteInternalFuture rebuildIndexesFromHash(@Nullable final Stri final GridWorkerFuture fut = new GridWorkerFuture<>(); - idx.markForRebuildFromHash(space, desc); + idx.markForRebuildFromHash(space); GridWorker w = new GridWorker(ctx.igniteInstanceName(), "index-rebuild-worker", log) { @Override protected void body() { try { - idx.rebuildIndexesFromHash(space, desc); + idx.rebuildIndexesFromHash(space); fut.onDone(); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java index 1785025cef876..bfd7806d81708 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java @@ -4494,130 +4494,6 @@ public void testConflictResolution() throws Exception { } } - /** - * Multithreaded transactional reads. - * - * @throws Exception If failed. - */ - public void testMultipleOptimisticRead() throws Exception { - final Ignite ignite = ignite(0); - final Integer key = 1; - final Integer val = 1; - final int THREADS_CNT = 50; - - final String cacheName = - ignite.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false)).getName(); - - try { - final IgniteCache cache = ignite.cache(cacheName); - - try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) { - cache.put(key, val); - - tx.commit(); - } - - assertTrue(cache.get(key).equals(val)); - - for (int i = 0; i < 10; i++) { - GridTestUtils.runMultiThreadedAsync(new Callable() { - @Override public Void call() throws Exception { - IgniteTransactions txs = cache.unwrap(Ignite.class).transactions(); - - try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { - assertTrue(cache.get(key).equals(val)); - - tx.commit(); - - } - return null; - } - }, THREADS_CNT, "multiple-reads-thread").get(); - } - } - finally { - destroyCache(cacheName); - } - } - - /** - * Transactional read in parallel with changing the same data. - * - * @throws Exception If failed. - */ - public void testTxReadInParallerTxWrite() throws Exception { - final Ignite ignite = ignite(0); - final Integer key = 1; - final Integer val = 1; - - final CountDownLatch readLatch = new CountDownLatch(1); - final CountDownLatch writeLatch = new CountDownLatch(1); - - final Exception[] err = {null}; - - final String cacheName = - ignite.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false)).getName(); - - final IgniteCache cache = ignite.cache(cacheName); - - try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) { - cache.put(key, val); - - tx.commit(); - } - - try { - IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable() { - @Override public Void call() throws Exception { - IgniteTransactions txs = cache.unwrap(Ignite.class).transactions(); - - try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { - assertTrue(cache.get(key).equals(val)); - - readLatch.countDown(); - - writeLatch.await(10, TimeUnit.SECONDS); - - try { - tx.commit(); - } - catch (TransactionOptimisticException e) { - log.info("Expected exception: " + e); - - err[0] = e; - } - } - return null; - } - }, "read-thread"); - - GridTestUtils.runAsync(new Callable() { - @Override public Void call() throws Exception { - IgniteTransactions txs = cache.unwrap(Ignite.class).transactions(); - - readLatch.await(10, TimeUnit.SECONDS); - - try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { - cache.put(key, val); - - tx.commit(); - } - - writeLatch.countDown(); - - return null; - } - }, "write-thread").get(); - - fut.get(); - - assertNotNull("Expected exception was not thrown", err[0]); - } - finally { - destroyCache(cacheName); - } - } - /** * Multithreaded transactional reads. * diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java index d5d0437f647ea..5fa1051ce492e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java @@ -80,7 +80,8 @@ public abstract class IgniteDbMemoryLeakAbstractTest extends IgniteDbAbstractTes long size = (1024 * (isLargePage() ? 16 : 1) + 24) * pagesMax(); - mCfg.setPageCacheSize(Math.max(size, MIN_PAGE_CACHE_SIZE)); + mCfg.setDefaultMemoryPolicyName("default").setMemoryPolicies( + new MemoryPolicyConfiguration().setSize(Math.max(size, MIN_PAGE_CACHE_SIZE)).setName("default")); } /** From 346373a75387ea0e1c07bb7a5824c7910faf78e6 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Mon, 17 Apr 2017 18:32:21 +0300 Subject: [PATCH 101/311] GG-12064 Need to have an ability to cancel snapshot operations -cancel for RESTORE --- .../processors/cache/IgniteCacheOffheapManagerImpl.java | 2 +- .../dht/preloader/GridDhtPartitionsExchangeFuture.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index 5d1f7b9122aab..68965c0d25291 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -172,7 +172,7 @@ protected void initDataStructures() throws IgniteCheckedException { @Override protected void stop0(final boolean cancel, final boolean destroy) { super.stop0(cancel, destroy); - if (destroy && cctx.affinityNode()) + if (cctx.affinityNode()) destroyCacheDataStructures(); } 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 ee5bed9912884..11343968b8e8c 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 @@ -666,7 +666,7 @@ else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) { DynamicCacheChangeRequest t = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, locNodeId); t.stop(true); - t.destroy(true); + t.destroy(false); t.deploymentId(desc.deploymentId()); From 633db6f1b011450f5e926375c24d1ac2fa5e1dd7 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Tue, 18 Apr 2017 17:30:59 +0300 Subject: [PATCH 102/311] GG-12064 Need to have an ability to cancel snapshot operations -added handling start on broken restore --- .../ignite/internal/processors/cache/GridCacheContext.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java index c7bf4e9e7b5ab..401d4bfdcca7b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java @@ -1937,7 +1937,10 @@ public boolean allowFastLocalRead(int part, List affNodes, Affinity // When persistence is enabled, only reading from partitions with OWNING state is allowed. assert !result || !ctx.cache().context().database().persistenceEnabled() || - topology().partitionState(localNodeId(), part) == OWNING; + topology().partitionState(localNodeId(), part) == OWNING : + "result = " + result + ", persistenceEnabled = " + ctx.cache().context().database().persistenceEnabled() + + ", partitionState = " + topology().partitionState(localNodeId(), part); + ; return result; } From eff4201ab5ccfa4cfe874d300a975e6a53f94ba1 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Tue, 18 Apr 2017 18:49:11 +0300 Subject: [PATCH 103/311] Fixing compilation after merge --- .../processors/database/IgniteDbMemoryLeakAbstractTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java index 1d58968bfac29..dbe2bec67585b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java @@ -22,6 +22,7 @@ import org.apache.ignite.IgniteCache; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.IgniteCacheProxy; import org.apache.ignite.internal.processors.cache.database.DataStructure; From 7808492b7dee12bdd0c3922e1760ffa364183bc2 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Tue, 18 Apr 2017 23:52:30 +0700 Subject: [PATCH 104/311] 8.0.4.ea1 Fixed snapshot utility tests. --- .../main/java/org/apache/ignite/internal/util/IgniteUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 7655e3d5ff29a..ccf3a1da5db5d 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -8062,7 +8062,7 @@ public static T invoke(@Nullable Class cls, @Nullable Object obj, String * @param paramTypes Parameter types. * @param params Parameters. * @return Field value. - * @throws IgniteCheckedException If static field with given name cannot be retreived. + * @throws IgniteCheckedException If static field with given name cannot be retrieved. */ public static T invoke(@Nullable Class cls, @Nullable Object obj, String mtdName, Class[] paramTypes, Object... params) throws IgniteCheckedException { From c812cc843e3fdfbc17a99920247320af997b3aa4 Mon Sep 17 00:00:00 2001 From: Eduard Shangareev Date: Wed, 19 Apr 2017 13:30:15 +0300 Subject: [PATCH 105/311] GG-12118 Stabilize tests in 8.0.4.ea1 after master merge -fixing NPE in exchange future --- .../ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java | 3 ++- .../dht/preloader/GridDhtPartitionsExchangeFuture.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java index 7134cff0ce46a..ac789001c64aa 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java @@ -36,6 +36,7 @@ import org.apache.ignite.internal.util.GridUnsafe; import org.apache.ignite.internal.util.OffheapReadWriteLock; import org.apache.ignite.internal.util.offheap.GridOffHeapOutOfMemoryException; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lifecycle.LifecycleAware; import static org.apache.ignite.internal.util.GridUnsafe.wrapPointer; @@ -254,7 +255,7 @@ public PageMemoryNoStoreImpl( if (relPtr == INVALID_REL_PTR) throw new OutOfMemoryException(); - assert (relPtr & ~PageIdUtils.PAGE_IDX_MASK) == 0; + assert (relPtr & ~PageIdUtils.PAGE_IDX_MASK) == 0 : U.hexLong(relPtr & ~PageIdUtils.PAGE_IDX_MASK); // Assign page ID according to flags and partition ID. long pageId = PageIdUtils.pageId(partId, flags, (int)relPtr); 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 0680403b1b5f7..5bd12d021754a 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 @@ -1357,7 +1357,7 @@ private void sendPartitions(ClusterNode oldestNode) { */ private StartSnapshotOperationAckDiscoveryMessage getSnapshotOperationMessage() { // If it's a snapshot operation request, synchronously wait for backup start. - if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) { + if (discoEvt != null && discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) { DiscoveryCustomMessage customMsg = ((DiscoveryCustomEvent)discoEvt).customMessage(); if (customMsg instanceof StartSnapshotOperationAckDiscoveryMessage) From 553288b11d9d6ed2f8cd9c612399944533d64988 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Wed, 19 Apr 2017 13:36:42 +0300 Subject: [PATCH 106/311] GG-12118: Page counter increment fix --- .../internal/processors/cache/database/freelist/PagesList.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java index 98f2073e0e2a4..98a55bda4124a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java @@ -779,8 +779,6 @@ private void handlePageFull( bucketsSize[bucket].incrementAndGet(); - bucketsSize[bucket].incrementAndGet(); - updateTail(bucket, pageId, nextId); } finally { From be8b260bd90e951c84ccbbb733e89fcd6c758279 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Wed, 19 Apr 2017 19:00:17 +0300 Subject: [PATCH 107/311] IGNITE-4861: Export rebalance metrics and state as MBeans --- .../apache/ignite/IgniteSystemProperties.java | 5 + .../org/apache/ignite/cache/CacheMetrics.java | 25 +++ .../cache/CacheClusterMetricsMXBeanImpl.java | 25 +++ .../cache/CacheLocalMetricsMXBeanImpl.java | 25 +++ .../processors/cache/CacheMetricsImpl.java | 107 +++++++++++ .../cache/CacheMetricsSnapshot.java | 64 +++++++ .../preloader/GridDhtPartitionDemander.java | 24 +++ .../preloader/GridDhtPartitionSupplier.java | 15 ++ .../GridDhtPartitionSupplyMessage.java | 49 ++++- .../cache/ratemetrics/HitRateMetrics.java | 179 ++++++++++++++++++ .../ratemetrics/HitRateMetricsSandbox.java | 90 +++++++++ .../PlatformCacheWriteMetricsTask.java | 25 +++ 12 files changed, 630 insertions(+), 3 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetrics.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.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 6d589a5213944..264d55df6096a 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -575,6 +575,11 @@ public final class IgniteSystemProperties { */ public static final String IGNITE_MAX_INDEX_PAYLOAD_SIZE = "IGNITE_MAX_INDEX_PAYLOAD_SIZE"; + /** + * Time interval for calculating rebalance rate statistics, in milliseconds. Defaults to 60000. + */ + public static final String IGNITE_REBALANCE_STATISTICS_TIME_INTERVAL = "IGNITE_REBALANCE_STATISTICS_TIME_INTERVAL"; + /** * Indexing discovery history size. Protects from duplicate messages maintaining the list of IDs of recently * arrived discovery messages. 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 c0eb98eb499eb..d926c0b0a5950 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 @@ -480,6 +480,31 @@ public interface CacheMetrics { */ public boolean isStoreByValue(); + /** + * @return Total number of partitions on current node. + */ + public int getTotalPartitionsCount(); + + /** + * @return Number of currently rebalancing partitions on current node. + */ + public int getRebalancingPartitionsCount(); + + /** + * @return Estimated number of keys to be rebalanced on current node. + */ + public long getKeysToRebalanceLeft(); + + /** + * @return Estimated rebalancing speed in keys. + */ + public long getRebalancingKeysRate(); + + /** + * @return Estimated rebalancing speed in bytes. + */ + public long getRebalancingBytesRate(); + /** * Checks whether statistics collection is enabled in this cache. *

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClusterMetricsMXBeanImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClusterMetricsMXBeanImpl.java index c633fde121749..fbb7f290446ff 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClusterMetricsMXBeanImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClusterMetricsMXBeanImpl.java @@ -357,4 +357,29 @@ class CacheClusterMetricsMXBeanImpl implements CacheMetricsMXBean { @Override public boolean isWriteThrough() { return cache.clusterMetrics().isWriteThrough(); } + + /** {@inheritDoc} */ + @Override public int getTotalPartitionsCount() { + return cache.clusterMetrics().getTotalPartitionsCount(); + } + + /** {@inheritDoc} */ + @Override public int getRebalancingPartitionsCount() { + return cache.clusterMetrics().getRebalancingPartitionsCount(); + } + + /** {@inheritDoc} */ + @Override public long getKeysToRebalanceLeft() { + return cache.clusterMetrics().getKeysToRebalanceLeft(); + } + + /** {@inheritDoc} */ + @Override public long getRebalancingKeysRate() { + return cache.clusterMetrics().getRebalancingKeysRate(); + } + + /** {@inheritDoc} */ + @Override public long getRebalancingBytesRate() { + return cache.clusterMetrics().getRebalancingBytesRate(); + } } \ No newline at end of file diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLocalMetricsMXBeanImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLocalMetricsMXBeanImpl.java index cdab58a8757e9..337f41aaee3ad 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLocalMetricsMXBeanImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLocalMetricsMXBeanImpl.java @@ -357,4 +357,29 @@ class CacheLocalMetricsMXBeanImpl implements CacheMetricsMXBean { @Override public boolean isWriteThrough() { return cache.metrics0().isWriteThrough(); } + + /** {@inheritDoc} */ + @Override public int getTotalPartitionsCount() { + return cache.metrics0().getTotalPartitionsCount(); + } + + /** {@inheritDoc} */ + @Override public int getRebalancingPartitionsCount() { + return cache.metrics0().getRebalancingPartitionsCount(); + } + + /** {@inheritDoc} */ + @Override public long getKeysToRebalanceLeft() { + return cache.metrics0().getKeysToRebalanceLeft(); + } + + /** {@inheritDoc} */ + @Override public long getRebalancingKeysRate() { + return cache.metrics0().getRebalancingKeysRate(); + } + + /** {@inheritDoc} */ + @Override public long getRebalancingBytesRate() { + return cache.metrics0().getRebalancingBytesRate(); + } } \ No newline at end of file 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 aceef978d93e9..9aaea84ebcb56 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 @@ -17,10 +17,14 @@ package org.apache.ignite.internal.processors.cache; +import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.cache.CacheMetrics; import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; +import org.apache.ignite.internal.processors.cache.ratemetrics.HitRateMetrics; import org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.internal.S; @@ -29,6 +33,10 @@ * Adapter for cache metrics. */ public class CacheMetricsImpl implements CacheMetrics { + /** Rebalance rate interval. */ + private static final int REBALANCE_RATE_INTERVAL = IgniteSystemProperties.getInteger( + IgniteSystemProperties.IGNITE_REBALANCE_STATISTICS_TIME_INTERVAL, 60000); + /** */ private static final long NANOS_IN_MICROSECOND = 1000L; @@ -104,6 +112,21 @@ public class CacheMetricsImpl implements CacheMetrics { /** Number of swap misses. */ private AtomicLong swapMisses = new AtomicLong(); + /** Rebalanced keys count. */ + private AtomicLong rebalancedKeys = new AtomicLong(); + + /** Total rebalanced bytes count. */ + private AtomicLong totalRebalancedBytes = new AtomicLong(); + + /** Estimated rebalancing keys count. */ + private AtomicLong estimatedRebalancingKeys = new AtomicLong(); + + /** Rebalancing rate in keys. */ + private HitRateMetrics rebalancingKeysRate = new HitRateMetrics(REBALANCE_RATE_INTERVAL, 20); + + /** Rebalancing rate in bytes. */ + private HitRateMetrics rebalancingBytesRate = new HitRateMetrics(REBALANCE_RATE_INTERVAL, 20); + /** Cache metrics. */ @GridToStringExclude private transient CacheMetricsImpl delegate; @@ -441,6 +464,8 @@ public void clear() { swapHits.set(0); swapMisses.set(0); + clearRebalanceCounters(); + if (delegate != null) delegate.clear(); } @@ -713,6 +738,88 @@ public void addPutAndGetTimeNanos(long duration) { return ccfg != null && ccfg.isManagementEnabled(); } + /** {@inheritDoc} */ + public int getTotalPartitionsCount() { + int res = 0; + + for (Map.Entry e : cctx.topology().localPartitionMap().entrySet()) { + if (e.getValue() == GridDhtPartitionState.OWNING || e.getValue() == GridDhtPartitionState.MOVING) + res++; + } + + return res; + } + + /** {@inheritDoc} */ + public int getRebalancingPartitionsCount() { + int res = 0; + + for (Map.Entry e : cctx.topology().localPartitionMap().entrySet()) { + if (e.getValue() == GridDhtPartitionState.MOVING) + res++; + } + + return res; + } + + /** {@inheritDoc} */ + public long getKeysToRebalanceLeft() { + return Math.max(0, estimatedRebalancingKeys.get() - rebalancedKeys.get()); + } + + /** {@inheritDoc} */ + public long getRebalancingKeysRate() { + return rebalancingKeysRate.getRate(); + } + + /** {@inheritDoc} */ + public long getRebalancingBytesRate() { + return rebalancingBytesRate.getRate(); + } + + /** + * Clear rebalance counters. + */ + public void clearRebalanceCounters() { + estimatedRebalancingKeys.set(0); + + rebalancedKeys.set(0); + + totalRebalancedBytes.set(0); + + rebalancingBytesRate.clear(); + + rebalancingKeysRate.clear(); + } + + /** + * First rebalance supply message callback. + * @param keysCnt Estimated number of keys. + */ + public void onRebalancingKeysCountEstimateReceived(long keysCnt) { + estimatedRebalancingKeys.addAndGet(keysCnt); + } + + /** + * Rebalance entry store callback. + */ + public void onRebalanceKeyReceived() { + rebalancedKeys.incrementAndGet(); + + rebalancingKeysRate.onHit(); + } + + /** + * Rebalance supply message callback. + * + * @param batchSize Batch size in bytes. + */ + public void onRebalanceBatchReceived(long batchSize) { + totalRebalancedBytes.addAndGet(batchSize); + + rebalancingBytesRate.onHits(batchSize); + } + public long getTotalAllocatedPages() { return 0; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java index a8d769304cb51..d21e48a163bce 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java @@ -188,6 +188,21 @@ public class CacheMetricsSnapshot implements CacheMetrics, Externalizable { /** Total count of entries in cache store internal buffer. */ private int writeBehindBufSize; + /** Total partitions count. */ + private int totalPartitionsCnt; + + /** Rebalancing partitions count. */ + private int rebalancingPartitionsCnt; + + /** Keys to rebalance left. */ + private long keysToRebalanceLeft; + + /** Rebalancing keys rate. */ + private long rebalancingKeysRate; + + /** Get rebalancing bytes rate. */ + private long rebalancingBytesRate; + /** */ private String keyType; @@ -286,6 +301,12 @@ public CacheMetricsSnapshot(CacheMetrics m) { isManagementEnabled = m.isManagementEnabled(); isReadThrough = m.isReadThrough(); isWriteThrough = m.isWriteThrough(); + + totalPartitionsCnt = m.getTotalPartitionsCount(); + rebalancingPartitionsCnt = m.getRebalancingPartitionsCount(); + keysToRebalanceLeft = m.getKeysToRebalanceLeft(); + rebalancingBytesRate = m.getRebalancingBytesRate(); + rebalancingKeysRate = m.getRebalancingKeysRate(); } /** @@ -405,6 +426,12 @@ public CacheMetricsSnapshot(CacheMetrics loc, Collection metrics) writeBehindErrorRetryCnt += e.getWriteBehindErrorRetryCount(); else writeBehindErrorRetryCnt = -1; + + totalPartitionsCnt += e.getTotalPartitionsCount(); + rebalancingPartitionsCnt += e.getRebalancingPartitionsCount(); + keysToRebalanceLeft += e.getKeysToRebalanceLeft(); + rebalancingBytesRate += e.getRebalancingBytesRate(); + rebalancingKeysRate += e.getRebalancingKeysRate(); } int size = metrics.size(); @@ -664,6 +691,31 @@ public CacheMetricsSnapshot(CacheMetrics loc, Collection metrics) return txDhtRolledbackVersionsSize; } + /** {@inheritDoc} */ + @Override public int getTotalPartitionsCount() { + return totalPartitionsCnt; + } + + /** {@inheritDoc} */ + @Override public int getRebalancingPartitionsCount() { + return rebalancingPartitionsCnt; + } + + /** {@inheritDoc} */ + @Override public long getKeysToRebalanceLeft() { + return keysToRebalanceLeft; + } + + /** {@inheritDoc} */ + @Override public long getRebalancingKeysRate() { + return rebalancingKeysRate; + } + + /** {@inheritDoc} */ + @Override public long getRebalancingBytesRate() { + return rebalancingBytesRate; + } + /** {@inheritDoc} */ @Override public boolean isWriteBehindEnabled() { return isWriteBehindEnabled; @@ -796,6 +848,12 @@ public CacheMetricsSnapshot(CacheMetrics loc, Collection metrics) out.writeInt(writeBehindTotalCriticalOverflowCnt); out.writeInt(writeBehindCriticalOverflowCnt); out.writeInt(writeBehindErrorRetryCnt); + + out.writeInt(totalPartitionsCnt); + out.writeInt(rebalancingPartitionsCnt); + out.writeLong(keysToRebalanceLeft); + out.writeLong(rebalancingBytesRate); + out.writeLong(rebalancingKeysRate); } /** {@inheritDoc} */ @@ -845,5 +903,11 @@ public CacheMetricsSnapshot(CacheMetrics loc, Collection metrics) writeBehindTotalCriticalOverflowCnt = in.readInt(); writeBehindCriticalOverflowCnt = in.readInt(); writeBehindErrorRetryCnt = in.readInt(); + + totalPartitionsCnt = in.readInt(); + rebalancingPartitionsCnt = in.readInt(); + keysToRebalanceLeft = in.readLong(); + rebalancingBytesRate = in.readLong(); + rebalancingKeysRate = in.readLong(); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java index 5cde3d206d1d2..5ebcb351d76f3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java @@ -314,6 +314,18 @@ Runnable addAssignments(final GridDhtPreloaderAssignments assigns, fut.sendRebalanceStartedEvent(); + final boolean statsEnabled = cctx.config().isStatisticsEnabled(); + + if (statsEnabled) { + cctx.cache().metrics0().clearRebalanceCounters(); + + rebalanceFut.listen(new IgniteInClosure>() { + @Override public void apply(IgniteInternalFuture fut) { + cctx.cache().metrics0().clearRebalanceCounters(); + } + }); + } + if (assigns.cancelled()) { // Pending exchange. if (log.isDebugEnabled()) log.debug("Rebalancing skipped due to cancelled assignments."); @@ -612,6 +624,15 @@ public void handleSupplyMessage( final GridDhtPartitionTopology top = cctx.dht().topology(); + final boolean statsEnabled = cctx.config().isStatisticsEnabled(); + + if (statsEnabled) { + if (supply.estimatedKeysCount() != -1) + cctx.cache().metrics0().onRebalancingKeysCountEstimateReceived(supply.estimatedKeysCount()); + + cctx.cache().metrics0().onRebalanceBatchReceived(supply.messageSize()); + } + try { // Preload. for (Map.Entry e : supply.infos().entrySet()) { @@ -651,6 +672,9 @@ public void handleSupplyMessage( break; } + + if (statsEnabled) + cctx.cache().metrics0().onRebalanceKeyReceived(); } // If message was last for this partition, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java index 75dbd291c4ccb..0207017583da3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java @@ -242,6 +242,21 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage Iterator partIt = sctx != null ? sctx.partIt : d.partitions().iterator(); + if (sctx == null) { + long keysCnt = 0; + + for (Integer part : d.partitions()) { + GridDhtLocalPartition loc = top.localPartition(part, d.topologyVersion(), false); + + if (loc == null || loc.state() != OWNING || !loc.reserve()) + continue; + + keysCnt += cctx.offheap().entriesCount(part); + } + + s.estimatedKeysCount(keysCnt); + } + while ((sctx != null && newReq) || partIt.hasNext()) { int part = sctx != null && newReq ? sctx.part : partIt.next(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java index ee461ab81f198..56b22dd796dda 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java @@ -74,9 +74,11 @@ public class GridDhtPartitionSupplyMessage extends GridCacheMessage implements G private Map infos; /** Message size. */ - @GridDirectTransient private int msgSize; + /** Estimated keys count. */ + private long estimatedKeysCnt = -1; + /** * @param updateSeq Update sequence for this node. * @param cacheId Cache ID. @@ -90,7 +92,8 @@ public class GridDhtPartitionSupplyMessage extends GridCacheMessage implements G this.cacheId = cacheId; this.updateSeq = updateSeq; this.topVer = topVer; - this.addDepInfo = addDepInfo; } + this.addDepInfo = addDepInfo; + } /** * Empty constructor required for {@link Externalizable}. @@ -333,6 +336,17 @@ public int size() { writer.incrementState(); + case 9: + if (!writer.writeLong("estimatedKeysCnt", estimatedKeysCnt)) + return false; + + writer.incrementState(); + + case 10: + if (!writer.writeInt("msgSize", msgSize)) + return false; + + writer.incrementState(); } return true; @@ -397,6 +411,21 @@ public int size() { reader.incrementState(); + case 9: + estimatedKeysCnt = reader.readLong("estimatedKeysCnt"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 10: + msgSize = reader.readInt("msgSize"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); } return reader.afterMessageRead(GridDhtPartitionSupplyMessage.class); @@ -409,7 +438,21 @@ public int size() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 9; + return 11; + } + + /** + * @return Estimated keys count. + */ + public long estimatedKeysCount() { + return estimatedKeysCnt; + } + + /** + * @param estimatedKeysCnt New estimated keys count. + */ + public void estimatedKeysCount(long estimatedKeysCnt) { + this.estimatedKeysCnt = estimatedKeysCnt; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetrics.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetrics.java new file mode 100644 index 0000000000000..824bc7a9f50bf --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetrics.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.ratemetrics; + +import java.util.concurrent.atomic.AtomicLongArray; +import org.apache.ignite.internal.util.typedef.internal.A; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** + * Accumulates approximate hit rate statistics. + * Calculates number of hits in last {@link #rateTimeInterval} milliseconds. + * Algorithm is based on circular array of {@link #size} hit counters, each is responsible for last corresponding time + * interval of {@link #rateTimeInterval}/{@link #size} milliseconds. Resulting number of hits is sum of all counters. + * + *

Implementation is nonblocking and protected from hits loss. + * Maximum relative error is 1/{@link #size}. + * 2^56 - 1 hits per interval can be accumulated without numeric overflow. + */ +public class HitRateMetrics { + /** Bits that store actual hit count. */ + private static final int TAG_OFFSET = 56; + + /** Useful part mask. */ + private static final long NO_TAG_MASK = ~(-1L << TAG_OFFSET); + + /** Time interval when hits are counted to calculate rate, in milliseconds. */ + private final int rateTimeInterval; + + /** Counters array size. */ + private final int size; + + /** Tagged counters. */ + private volatile AtomicLongArray taggedCounters; + + /** Last hit times. */ + private volatile AtomicLongArray lastHitTimes; + + /** + * @param rateTimeInterval Rate time interval. + * @param size Number of counters. + */ + public HitRateMetrics(int rateTimeInterval, int size) { + A.ensure(rateTimeInterval > 0, "should be positive"); + + A.ensure(size > 1, "minimum is 2"); + + this.rateTimeInterval = rateTimeInterval; + + this.size = size; + + taggedCounters = new AtomicLongArray(size); + + lastHitTimes = new AtomicLongArray(size); + } + + /** + * Mark one hit. + */ + public void onHit() { + onHits(1); + } + + /** + * Mark multiple hits. + * + * @param hits Number of hits. + */ + public void onHits(long hits) { + long curTs = U.currentTimeMillis(); + + int curPos = position(curTs); + + clearIfObsolete(curTs, curPos); + + lastHitTimes.set(curPos, curTs); + + // Order is important. Hit won't be cleared by concurrent #clearIfObsolete. + taggedCounters.addAndGet(curPos, hits); + } + + /** + * @return Total number of hits in last {@link #rateTimeInterval} milliseconds. + */ + public long getRate() { + long curTs = U.currentTimeMillis(); + + long sum = 0; + + for (int i = 0; i < size; i++) { + clearIfObsolete(curTs, i); + + sum += untag(taggedCounters.get(i)); + } + + return sum; + } + + /** + * Clear metrics. + */ + public void clear() { + taggedCounters = new AtomicLongArray(size); + + lastHitTimes = new AtomicLongArray(size); + } + + /** + * @param curTs Current timestamp. + * @param i Index. + */ + private void clearIfObsolete(long curTs, int i) { + long cur = taggedCounters.get(i); + + byte curTag = getTag(cur); + + long lastTs = lastHitTimes.get(i); + + if (isObsolete(curTs, lastTs)) { + if (taggedCounters.compareAndSet(i, cur, taggedLongZero(++curTag))) // ABA problem prevention. + lastHitTimes.set(i, curTs); + // If CAS failed, counter is reset by another thread. + } + } + + /** + * @param curTs Current timestamp. + * @param lastHitTime Last hit timestamp. + * @return True, is last hit time was too long ago. + */ + private boolean isObsolete(long curTs, long lastHitTime) { + return curTs - lastHitTime > rateTimeInterval * (size - 1) / size; + } + + /** + * @param time Timestamp. + * @return Index of counter for given timestamp. + */ + private int position(long time) { + return (int)(time % rateTimeInterval * size) / rateTimeInterval; + } + + /** + * @param tag Tag byte. + * @return 0L with given tag byte. + */ + private static long taggedLongZero(byte tag) { + return ((long)tag << TAG_OFFSET); + } + + /** + * @param l Tagged long. + * @return Long without tag byte. + */ + private static long untag(long l) { + return l & NO_TAG_MASK; + } + + /** + * @param taggedLong Tagged long. + * @return Tag byte. + */ + private static byte getTag(long taggedLong) { + return (byte)(taggedLong >> TAG_OFFSET); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.java new file mode 100644 index 0000000000000..ec1c2f585c723 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.java @@ -0,0 +1,90 @@ +/* +* 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.ratemetrics; + +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.Timer; +import org.apache.ignite.internal.util.IgniteUtils; + +/** + * Visualization of {@link HitRateMetrics}. + */ +public class HitRateMetricsSandbox extends JFrame { + /** */ + private final JLabel rateLb = new JLabel("0.0"); + + /** */ + private final HitRateMetrics metrics = new HitRateMetrics(5_000, 20); + + /** + * Default constructor. + */ + private HitRateMetricsSandbox() { + IgniteUtils.onGridStart(); + + JButton hitBtn = new JButton("Hit"); + hitBtn.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { + metrics.onHit(); + } + }); + + new Timer(100, new ActionListener() { + public void actionPerformed(ActionEvent evt) { + rateLb.setText(Double.toString(metrics.getRate())); + } + }).start(); + + setContentPane(createPanel(new JLabel("Hits in 5 seconds:"), rateLb, hitBtn)); + + setMinimumSize(new Dimension(300, 120)); + } + + /** + * @param components Components. + * @return Panel. + */ + private JPanel createPanel(JComponent... components) { + JPanel panel = new JPanel(); + + panel.setLayout(new FlowLayout()); + + for (JComponent component : components) + panel.add(component); + + return panel; + } + + /** + * @param args Args. + */ + public static void main(String[] args) { + EventQueue.invokeLater(() -> { + HitRateMetricsSandbox s = new HitRateMetricsSandbox(); + s.setVisible(true); + }); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheWriteMetricsTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheWriteMetricsTask.java index da013bd1ac6ad..b2697e14139bb 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheWriteMetricsTask.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheWriteMetricsTask.java @@ -408,6 +408,31 @@ private static class TestCacheMetrics implements CacheMetrics { @Override public boolean isWriteThrough() { return true; } + + /** {@inheritDoc} */ + @Override public int getTotalPartitionsCount() { + return 54; + } + + /** {@inheritDoc} */ + @Override public int getRebalancingPartitionsCount() { + return 55; + } + + /** {@inheritDoc} */ + @Override public long getKeysToRebalanceLeft() { + return 56; + } + + /** {@inheritDoc} */ + @Override public long getRebalancingKeysRate() { + return 57; + } + + /** {@inheritDoc} */ + @Override public long getRebalancingBytesRate() { + return 58; + } } } From 58995f668a172f3acdb2bd6386dc5390f0dca9a2 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Wed, 19 Apr 2017 23:27:27 +0700 Subject: [PATCH 108/311] 8.0.4.ea1 Fixed compilation. --- .../cache/ratemetrics/HitRateMetricsSandbox.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.java index ec1c2f585c723..864a8a13fd2bb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.java @@ -82,9 +82,11 @@ private JPanel createPanel(JComponent... components) { * @param args Args. */ public static void main(String[] args) { - EventQueue.invokeLater(() -> { - HitRateMetricsSandbox s = new HitRateMetricsSandbox(); - s.setVisible(true); + EventQueue.invokeLater(new Runnable() { + @Override public void run() { + HitRateMetricsSandbox s = new HitRateMetricsSandbox(); + s.setVisible(true); + } }); } } From d8c6ffafa0923544dbb9814c2ea0cbbddde7a5d0 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Wed, 19 Apr 2017 19:24:36 +0300 Subject: [PATCH 109/311] GG-12118 Stabilize tests in 8.0.4.ea1 after master merge -fixing issued with message ids --- .../internal/managers/communication/GridIoMessageFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java index 8183f43b6161d..33dd941cb4846 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java @@ -864,7 +864,7 @@ public GridIoMessageFactory(MessageFactory[] ext) { // [-3..119] [124..127] [-23..-27] [-36..-47]- this // [120..123] - DR // [-4..-22, -30..-35] - SQL - // [-46..-50] - Snapshots + // [-54..-60] - Snapshots default: if (ext != null) { for (MessageFactory factory : ext) { From 097b4f67e48e31b61ffa5c1220d7ada8b51f4516 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Thu, 20 Apr 2017 11:53:14 +0300 Subject: [PATCH 110/311] GG-12118: Build fix --- .../processors/cache/ratemetrics/HitRateMetricsSandbox.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.java index 864a8a13fd2bb..3a542e857a8b6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ratemetrics/HitRateMetricsSandbox.java @@ -33,6 +33,9 @@ * Visualization of {@link HitRateMetrics}. */ public class HitRateMetricsSandbox extends JFrame { + /** Serial version uid. */ + private static final long serialVersionUID = 0L; + /** */ private final JLabel rateLb = new JLabel("0.0"); From 22826bc93dc2f186ef6e129d687a28b1c1f384b0 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Thu, 20 Apr 2017 14:44:08 +0300 Subject: [PATCH 111/311] IGNITE-4861: Counting expected amount of keys for rebalance metrics hangs exchange, fix TBD --- .../preloader/GridDhtPartitionSupplier.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java index 0207017583da3..7d861fff12e81 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java @@ -242,20 +242,20 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage Iterator partIt = sctx != null ? sctx.partIt : d.partitions().iterator(); - if (sctx == null) { - long keysCnt = 0; - - for (Integer part : d.partitions()) { - GridDhtLocalPartition loc = top.localPartition(part, d.topologyVersion(), false); - - if (loc == null || loc.state() != OWNING || !loc.reserve()) - continue; - - keysCnt += cctx.offheap().entriesCount(part); - } - - s.estimatedKeysCount(keysCnt); - } +// if (sctx == null) { +// long keysCnt = 0; +// +// for (Integer part : d.partitions()) { +// GridDhtLocalPartition loc = top.localPartition(part, d.topologyVersion(), false); +// +// if (loc == null || loc.state() != OWNING || !loc.reserve()) +// continue; +// +// keysCnt += cctx.offheap().entriesCount(part); +// } +// +// s.estimatedKeysCount(keysCnt); +// } while ((sctx != null && newReq) || partIt.hasNext()) { int part = sctx != null && newReq ? sctx.part : partIt.next(); From 75c760aa0f16aee7c1a77c9d1a87114f141659ab Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Thu, 20 Apr 2017 16:47:45 +0300 Subject: [PATCH 112/311] IGNITE-4861: Metrics fix --- .../preloader/GridDhtPartitionSupplier.java | 28 +++++++++---------- .../cache/GridCacheStopSelfTest.java | 6 ++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java index 7d861fff12e81..0ff03f73590ca 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java @@ -242,20 +242,20 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage Iterator partIt = sctx != null ? sctx.partIt : d.partitions().iterator(); -// if (sctx == null) { -// long keysCnt = 0; -// -// for (Integer part : d.partitions()) { -// GridDhtLocalPartition loc = top.localPartition(part, d.topologyVersion(), false); -// -// if (loc == null || loc.state() != OWNING || !loc.reserve()) -// continue; -// -// keysCnt += cctx.offheap().entriesCount(part); -// } -// -// s.estimatedKeysCount(keysCnt); -// } + if (sctx == null) { + long keysCnt = 0; + + for (Integer part : d.partitions()) { + GridDhtLocalPartition loc = top.localPartition(part, d.topologyVersion(), false); + + if (loc == null || loc.state() != OWNING) + continue; + + keysCnt += cctx.offheap().entriesCount(part); + } + + s.estimatedKeysCount(keysCnt); + } while ((sctx != null && newReq) || partIt.hasNext()) { int part = sctx != null && newReq ? sctx.part : partIt.next(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStopSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStopSelfTest.java index 890e005f1d171..c354aa37c2f59 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStopSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStopSelfTest.java @@ -31,6 +31,7 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.util.typedef.X; 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; @@ -313,10 +314,11 @@ private void testStop(final boolean startTx) throws Exception { cache.put(1, 1); } catch (IllegalStateException e) { - if (!e.getMessage().startsWith(EXPECTED_MSG)) + if (!X.hasCause(e, CacheStoppedException.class)) { e.printStackTrace(); - assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().startsWith(EXPECTED_MSG)); + fail("Unexpected exception: " + e); + } } } } From a527e4123aad5233995d643d1a9bc1dc330a9949 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Thu, 20 Apr 2017 17:06:00 +0300 Subject: [PATCH 113/311] gg-12095 : part2node usage optimization --- .../dht/GridDhtPartitionTopologyImpl.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) 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 731be1a1c39bf..55b20022c151e 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 @@ -91,7 +91,7 @@ private GridDhtPartitionFullMap node2part; /** Partition to node map. */ - private Map> part2node = new HashMap<>(); + private final Map> part2node; /** */ private GridDhtPartitionExchangeId lastExchangeId; @@ -139,6 +139,8 @@ log = cctx.logger(getClass()); locParts = new AtomicReferenceArray<>(cctx.config().getAffinity().partitions()); + + part2node = new HashMap<>(cctx.config().getAffinity().partitions(), 1.0f); } /** {@inheritDoc} */ @@ -155,7 +157,7 @@ public void onReconnected() { try { node2part = null; - part2node = new HashMap<>(); + part2node.clear(); lastExchangeId = null; @@ -1093,23 +1095,26 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) node2part = partMap; - Map> p2n = new HashMap<>(cctx.affinity().partitions(), 1.0f); + part2node.clear(); for (Map.Entry e : partMap.entrySet()) { - for (Integer p : e.getValue().keySet()) { - Set ids = p2n.get(p); + for (Map.Entry e0 : e.getValue().entrySet()) { + if (e0.getValue() != MOVING && e0.getValue() != OWNING) + continue; + + int p = e0.getKey(); + + Set ids = part2node.get(p); if (ids == null) // Initialize HashSet to size 3 in anticipation that there won't be // more than 3 nodes per partitions. - p2n.put(p, ids = U.newHashSet(3)); + part2node.put(p, ids = U.newHashSet(3)); ids.add(e.getKey()); } } - part2node = p2n; - boolean changed = false; AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); @@ -1288,18 +1293,24 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { node2part.put(parts.nodeId(), parts); - part2node = new HashMap<>(part2node); - // Add new mappings. - for (Integer p : parts.keySet()) { + for (Map.Entry e : parts.entrySet()) { + int p = e.getKey(); + Set ids = part2node.get(p); - if (ids == null) - // Initialize HashSet to size 3 in anticipation that there won't be - // more than 3 nodes per partition. - part2node.put(p, ids = U.newHashSet(3)); + if (e.getValue() == MOVING || e.getValue() == OWNING) { + if (ids == null) + // Initialize HashSet to size 3 in anticipation that there won't be + // more than 3 nodes per partition. + part2node.put(p, ids = U.newHashSet(3)); - changed |= ids.add(parts.nodeId()); + changed |= ids.add(parts.nodeId()); + } + else { + if (ids != null) + changed |= ids.remove(parts.nodeId()); + } } // Remove obsolete mappings. From 1be7d4a8cba88ffdca35d9d2936d2f92a51f02db Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Thu, 20 Apr 2017 17:16:41 +0300 Subject: [PATCH 114/311] gg-12095 : part2node usage optimization for client topology. --- .../dht/GridClientPartitionTopology.java | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) 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 ea477b77c2c33..772084d3ec2eb 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 @@ -82,7 +82,7 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology { private GridDhtPartitionFullMap node2part; /** Partition to node map. */ - private Map> part2node = new HashMap<>(); + private final Map> part2node = new HashMap<>(); /** */ private GridDhtPartitionExchangeId lastExchangeId; @@ -628,25 +628,26 @@ public long lastUpdateSequence() { } } - node2part = partMap; - - Map> p2n = new HashMap<>(); + part2node.clear(); for (Map.Entry e : partMap.entrySet()) { - for (Integer p : e.getValue().keySet()) { - Set ids = p2n.get(p); + for (Map.Entry e0 : e.getValue().entrySet()) { + if (e0.getValue() != MOVING && e0.getValue() != OWNING) + continue; + + int p = e0.getKey(); + + Set ids = part2node.get(p); if (ids == null) // Initialize HashSet to size 3 in anticipation that there won't be // more than 3 nodes per partitions. - p2n.put(p, ids = U.newHashSet(3)); + part2node.put(p, ids = U.newHashSet(3)); ids.add(e.getKey()); } } - part2node = p2n; - if (cntrMap != null) this.cntrMap = new HashMap<>(cntrMap); @@ -722,18 +723,24 @@ public long lastUpdateSequence() { node2part.put(parts.nodeId(), parts); - part2node = new HashMap<>(part2node); - // Add new mappings. - for (Integer p : parts.keySet()) { + for (Map.Entry e : parts.entrySet()) { + int p = e.getKey(); + Set ids = part2node.get(p); - if (ids == null) - // Initialize HashSet to size 3 in anticipation that there won't be - // more than 3 nodes per partition. - part2node.put(p, ids = U.newHashSet(3)); + if (e.getValue() == MOVING || e.getValue() == OWNING) { + if (ids == null) + // Initialize HashSet to size 3 in anticipation that there won't be + // more than 3 nodes per partition. + part2node.put(p, ids = U.newHashSet(3)); - changed |= ids.add(parts.nodeId()); + changed |= ids.add(parts.nodeId()); + } + else { + if (ids != null) + changed |= ids.remove(parts.nodeId()); + } } // Remove obsolete mappings. @@ -868,8 +875,6 @@ private void removeNode(UUID nodeId) { else node2part = new GridDhtPartitionFullMap(node2part, node2part.updateSequence()); - part2node = new HashMap<>(part2node); - GridDhtPartitionMap parts = node2part.remove(nodeId); if (parts != null) { From 6e93d04d0117ff4977ad5f2ffe2a4c990c5ab0cb Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Thu, 20 Apr 2017 23:17:48 +0700 Subject: [PATCH 115/311] GG-12050 Snapshots catalog beta. --- .../apache/ignite/IgniteSystemProperties.java | 7 ++ .../visor/cache/VisorCachePartitionsTask.java | 2 +- .../visor/file/VisorFileBlockTaskResult.java | 87 +++++++++++++++++++ .../visor/igfs/VisorIgfsFormatTask.java | 2 +- .../resources/META-INF/classnames.properties | 39 ++++++--- .../resources/META-INF/classnames.properties | 1 + .../frontend/app/core/utils/maskNull.js | 21 +++++ .../app/modules/agent/AgentManager.service.js | 3 +- .../frontend/app/primitives/btn/index.scss | 36 ++++---- .../ignite/console/agent/AgentLauncher.java | 10 +-- 10 files changed, 170 insertions(+), 38 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/visor/file/VisorFileBlockTaskResult.java create mode 100644 modules/web-console/frontend/app/core/utils/maskNull.js 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 264d55df6096a..21d0e1b58ce31 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -597,6 +597,13 @@ public final class IgniteSystemProperties { } }; + /** + * Ignite cluster name. + *

+ * Defaults to utility cache deployment ID.. + */ + public static final String IGNITE_CLUSTER_NAME = "IGNITE_CLUSTER_NAME"; + /** * Enforces singleton. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java index c9339b7c81d75..69188c5938f1f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java @@ -124,7 +124,7 @@ else if (ca instanceof GridDhtCacheAdapter) for (GridDhtLocalPartition part : locParts) { int p = part.id(); - long sz = part.publicSize(); + long sz = part.dataStore().size(); // Pass NONE as topology version in order not to wait for topology version. if (part.primary(AffinityTopologyVersion.NONE)) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/file/VisorFileBlockTaskResult.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/file/VisorFileBlockTaskResult.java new file mode 100644 index 0000000000000..b888f6d17bbe6 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/file/VisorFileBlockTaskResult.java @@ -0,0 +1,87 @@ +/* + * 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.visor.file; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.visor.VisorDataTransferObject; + +/** + * Result for file block operation. + */ +public class VisorFileBlockTaskResult extends VisorDataTransferObject { + /** */ + private static final long serialVersionUID = 0L; + + /** Exception on reading of block. */ + private IOException ex; + + /** Read file block. */ + private VisorFileBlock block; + + /** + * Default constructor. + */ + public VisorFileBlockTaskResult() { + // No-op. + } + + /** + * Create log search result with given parameters. + * + * @param ex Exception on reading of block. + * @param block Read file block. + */ + public VisorFileBlockTaskResult(IOException ex, VisorFileBlock block) { + this.ex = ex; + this.block = block; + } + + /** + * @return Exception on reading of block. + */ + public IOException getException() { + return ex; + } + + /** + * @return Read file block. + */ + public VisorFileBlock getBlock() { + return block; + } + + /** {@inheritDoc} */ + @Override protected void writeExternalData(ObjectOutput out) throws IOException { + out.writeObject(ex); + out.writeObject(block); + } + + /** {@inheritDoc} */ + @Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException { + ex = (IOException)in.readObject(); + block = (VisorFileBlock)in.readObject(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(VisorFileBlockTaskResult.class, this); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/igfs/VisorIgfsFormatTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/igfs/VisorIgfsFormatTask.java index 3a9f68312a730..d72841559eb4b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/igfs/VisorIgfsFormatTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/igfs/VisorIgfsFormatTask.java @@ -68,4 +68,4 @@ private VisorIgfsFormatJob(String arg, boolean debug) { return S.toString(VisorIgfsFormatJob.class, this); } } -} \ No newline at end of file +} diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index c4101755908cb..90b83a4cde24e 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -324,8 +324,9 @@ org.apache.ignite.internal.managers.indexing.GridIndexingManager$1 org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerAdapter org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerManager$1 org.apache.ignite.internal.marshaller.optimized.OptimizedFieldType -org.apache.ignite.internal.mem.OutOfMemoryException +org.apache.ignite.internal.mem.IgniteOutOfMemoryException org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl$Segment +org.apache.ignite.internal.pagemem.snapshot.FinishSnapshotOperationAckDiscoveryMessage org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationType org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage @@ -542,9 +543,8 @@ org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$8 org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$CacheDataStoreImpl$1 org.apache.ignite.internal.processors.cache.IgniteCacheProxy org.apache.ignite.internal.processors.cache.IgniteCacheProxy$1 -org.apache.ignite.internal.processors.cache.IgniteCacheProxy$10 -org.apache.ignite.internal.processors.cache.IgniteCacheProxy$12 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$1$1 +org.apache.ignite.internal.processors.cache.IgniteCacheProxy$10 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$2 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$3 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$4 @@ -559,10 +559,6 @@ org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityProxy org.apache.ignite.internal.processors.cache.binary.BinaryMetadataHolder org.apache.ignite.internal.processors.cache.binary.BinaryMetadataKey org.apache.ignite.internal.processors.cache.binary.CacheDefaultBinaryAffinityKeyMapper -org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$4 -org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetaDataEntryFilter -org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetaDataPredicate -org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetadataProcessor org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$3 org.apache.ignite.internal.processors.cache.binary.MetadataRequestMessage org.apache.ignite.internal.processors.cache.binary.MetadataResponseMessage @@ -745,8 +741,9 @@ org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPar org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$1$1 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$2 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$3 -org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$4$1 +org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$4 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$5$1 +org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander$6$1 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap @@ -924,9 +921,11 @@ org.apache.ignite.internal.processors.cache.query.jdbc.GridCacheQueryJdbcTask$Jd org.apache.ignite.internal.processors.cache.query.jdbc.GridCacheQueryJdbcTask$JdbcDriverJob$1 org.apache.ignite.internal.processors.cache.query.jdbc.GridCacheQueryJdbcValidationTask org.apache.ignite.internal.processors.cache.query.jdbc.GridCacheQueryJdbcValidationTask$1 +org.apache.ignite.internal.processors.cache.ratemetrics.HitRateMetricsSandbox org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter$1 org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter$2 org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter$3 +org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore$BatchingResult org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore$StatefulValue org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore$StoreOperation org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore$ValueStatus @@ -1164,6 +1163,7 @@ org.apache.ignite.internal.processors.igfs.IgfsListingEntry org.apache.ignite.internal.processors.igfs.IgfsMetaManager$2 org.apache.ignite.internal.processors.igfs.IgfsMetaManager$3 org.apache.ignite.internal.processors.igfs.IgfsMetricsAdapter +org.apache.ignite.internal.processors.igfs.IgfsModeResolver org.apache.ignite.internal.processors.igfs.IgfsNodePredicate org.apache.ignite.internal.processors.igfs.IgfsProcessor$1 org.apache.ignite.internal.processors.igfs.IgfsSamplingKey @@ -1287,20 +1287,31 @@ org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils$Interna org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionLockProcessor org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionSetAndUnlockProcessor org.apache.ignite.internal.processors.query.GridQueryFieldMetadata -org.apache.ignite.internal.processors.query.GridQueryIndexType -org.apache.ignite.internal.processors.query.GridQueryProcessor$3 org.apache.ignite.internal.processors.query.GridQueryProcessor$4 org.apache.ignite.internal.processors.query.GridQueryProcessor$5 org.apache.ignite.internal.processors.query.GridQueryProcessor$6 org.apache.ignite.internal.processors.query.GridQueryProcessor$7 org.apache.ignite.internal.processors.query.GridQueryProcessor$8 org.apache.ignite.internal.processors.query.GridQueryProcessor$9 -org.apache.ignite.internal.processors.query.GridQueryProcessor$IndexType +org.apache.ignite.internal.processors.query.GridQueryProcessor$SchemaOperation$1 org.apache.ignite.internal.processors.query.IgniteSQLException +org.apache.ignite.internal.processors.query.QueryIndexKey +org.apache.ignite.internal.processors.query.QuerySchema org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryCancelRequest org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryFailResponse org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageRequest org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageResponse +org.apache.ignite.internal.processors.query.schema.SchemaOperationException +org.apache.ignite.internal.processors.query.schema.SchemaOperationManager$1 +org.apache.ignite.internal.processors.query.schema.SchemaOperationWorker$1 +org.apache.ignite.internal.processors.query.schema.message.SchemaAbstractDiscoveryMessage +org.apache.ignite.internal.processors.query.schema.message.SchemaFinishDiscoveryMessage +org.apache.ignite.internal.processors.query.schema.message.SchemaOperationStatusMessage +org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage +org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation +org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexAbstractOperation +org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexCreateOperation +org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexDropOperation org.apache.ignite.internal.processors.resource.GridResourceIoc$AnnotationSet org.apache.ignite.internal.processors.resource.GridResourceIoc$ResourceAnnotation org.apache.ignite.internal.processors.rest.GridRestCommand @@ -1711,6 +1722,7 @@ org.apache.ignite.internal.visor.cache.VisorCacheResetMetricsTask org.apache.ignite.internal.visor.cache.VisorCacheResetMetricsTask$VisorCacheResetMetricsJob org.apache.ignite.internal.visor.cache.VisorCacheSqlIndexMetadata org.apache.ignite.internal.visor.cache.VisorCacheSqlMetadata +org.apache.ignite.internal.visor.cache.VisorCacheStartArg org.apache.ignite.internal.visor.cache.VisorCacheStartTask org.apache.ignite.internal.visor.cache.VisorCacheStartTask$VisorCacheStartJob org.apache.ignite.internal.visor.cache.VisorCacheStartTaskArg @@ -1741,9 +1753,11 @@ org.apache.ignite.internal.visor.event.VisorGridEventsLost org.apache.ignite.internal.visor.event.VisorGridJobEvent org.apache.ignite.internal.visor.event.VisorGridTaskEvent org.apache.ignite.internal.visor.file.VisorFileBlock +org.apache.ignite.internal.visor.file.VisorFileBlockArg org.apache.ignite.internal.visor.file.VisorFileBlockTask org.apache.ignite.internal.visor.file.VisorFileBlockTask$VisorFileBlockJob org.apache.ignite.internal.visor.file.VisorFileBlockTaskArg +org.apache.ignite.internal.visor.file.VisorFileBlockTaskResult org.apache.ignite.internal.visor.file.VisorLatestTextFilesTask org.apache.ignite.internal.visor.file.VisorLatestTextFilesTask$VisorLatestTextFilesJob org.apache.ignite.internal.visor.file.VisorLatestTextFilesTaskArg @@ -1765,6 +1779,7 @@ org.apache.ignite.internal.visor.igfs.VisorIgfsSamplingStateTask org.apache.ignite.internal.visor.igfs.VisorIgfsSamplingStateTask$VisorIgfsSamplingStateJob org.apache.ignite.internal.visor.igfs.VisorIgfsSamplingStateTaskArg org.apache.ignite.internal.visor.log.VisorLogFile +org.apache.ignite.internal.visor.log.VisorLogSearchArg org.apache.ignite.internal.visor.log.VisorLogSearchResult org.apache.ignite.internal.visor.log.VisorLogSearchTask org.apache.ignite.internal.visor.log.VisorLogSearchTask$VisorLogSearchJob @@ -1820,6 +1835,7 @@ org.apache.ignite.internal.visor.node.VisorSpiDescription org.apache.ignite.internal.visor.node.VisorSpisConfiguration org.apache.ignite.internal.visor.node.VisorSuppressedError org.apache.ignite.internal.visor.node.VisorTransactionConfiguration +org.apache.ignite.internal.visor.query.VisorQueryArg org.apache.ignite.internal.visor.query.VisorQueryCancelTask org.apache.ignite.internal.visor.query.VisorQueryCancelTask$VisorCancelQueriesJob org.apache.ignite.internal.visor.query.VisorQueryCleanupTask @@ -1848,6 +1864,7 @@ org.apache.ignite.internal.visor.query.VisorQueryTaskArg org.apache.ignite.internal.visor.query.VisorRunningQueriesCollectorTask org.apache.ignite.internal.visor.query.VisorRunningQueriesCollectorTask$VisorCollectRunningQueriesJob org.apache.ignite.internal.visor.query.VisorRunningQuery +org.apache.ignite.internal.visor.query.VisorScanQueryArg org.apache.ignite.internal.visor.query.VisorScanQueryTask org.apache.ignite.internal.visor.query.VisorScanQueryTask$VisorScanQueryJob org.apache.ignite.internal.visor.query.VisorScanQueryTaskArg diff --git a/modules/hadoop/src/main/resources/META-INF/classnames.properties b/modules/hadoop/src/main/resources/META-INF/classnames.properties index 051094d06169b..a83b9ffe45e85 100644 --- a/modules/hadoop/src/main/resources/META-INF/classnames.properties +++ b/modules/hadoop/src/main/resources/META-INF/classnames.properties @@ -43,6 +43,7 @@ org.apache.ignite.internal.processors.hadoop.impl.igfs.HadoopIgfsInProc$13 org.apache.ignite.internal.processors.hadoop.impl.igfs.HadoopIgfsInProc$14 org.apache.ignite.internal.processors.hadoop.impl.igfs.HadoopIgfsInProc$15 org.apache.ignite.internal.processors.hadoop.impl.igfs.HadoopIgfsInProc$16 +org.apache.ignite.internal.processors.hadoop.impl.igfs.HadoopIgfsInProc$17 org.apache.ignite.internal.processors.hadoop.impl.igfs.HadoopIgfsInProc$2 org.apache.ignite.internal.processors.hadoop.impl.igfs.HadoopIgfsInProc$3 org.apache.ignite.internal.processors.hadoop.impl.igfs.HadoopIgfsInProc$4 diff --git a/modules/web-console/frontend/app/core/utils/maskNull.js b/modules/web-console/frontend/app/core/utils/maskNull.js new file mode 100644 index 0000000000000..604b69082ae01 --- /dev/null +++ b/modules/web-console/frontend/app/core/utils/maskNull.js @@ -0,0 +1,21 @@ +/* + * 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. + */ + +// Filter that will check value and return `null` if needed. +export default function(val) { + return _.isNil(val) ? 'null' : val; +} diff --git a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js index 3b39463e3b033..d3f911fc800de 100644 --- a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js +++ b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js @@ -16,8 +16,7 @@ */ import io from 'socket.io-client'; // eslint-disable-line no-unused-vars - -const maskNull = (val) => _.isNil(val) ? 'null' : val; +import maskNull from 'app/core/utils/maskNull'; const State = { INIT: 'INIT', diff --git a/modules/web-console/frontend/app/primitives/btn/index.scss b/modules/web-console/frontend/app/primitives/btn/index.scss index 1eb027f25e754..ef6a19a20c3a7 100644 --- a/modules/web-console/frontend/app/primitives/btn/index.scss +++ b/modules/web-console/frontend/app/primitives/btn/index.scss @@ -16,26 +16,26 @@ */ .btn.btn--stroke { - min-width: 36px; - height: 36px; + min-width: 36px; + height: 36px; - line-height: 36px; - text-align: center; + line-height: 36px; + text-align: center; - color: #ee2b27; - border: 1px solid #ee2b27; - background: initial; + color: #ee2b27; + border: 1px solid #ee2b27; + background: initial; - &:hover, &:focus { - color: #a8110f; - border-color: #a8110f; - } + &:hover, &:focus { + color: #a8110f; + border-color: #a8110f; + } - &:focus { - outline: none; - } + &:focus { + outline: none; + } - i { - margin: 0; - } -} \ No newline at end of file + i { + margin: 0; + } +} diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/AgentLauncher.java b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/AgentLauncher.java index 65b8192b5f868..4db26bacc05b6 100644 --- a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/AgentLauncher.java +++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/AgentLauncher.java @@ -33,9 +33,9 @@ import java.net.URL; import java.net.UnknownHostException; import java.util.Arrays; -import java.util.Scanner; import java.util.Collection; import java.util.List; +import java.util.Scanner; import java.util.concurrent.CountDownLatch; import java.util.jar.Attributes; import java.util.jar.Manifest; @@ -65,7 +65,7 @@ import static org.apache.ignite.console.agent.AgentUtils.toJSON; /** - * Control Center Agent launcher. + * Ignite Web Agent launcher. */ public class AgentLauncher { /** */ @@ -235,7 +235,7 @@ private static TrustManager[] getTrustManagers() { * @param fmt Format string. * @param args Arguments. */ - private static String readLine(String fmt, Object ... args) { + private static String readLine(String fmt, Object... args) { if (System.console() != null) return System.console().readLine(fmt, args); @@ -248,7 +248,7 @@ private static String readLine(String fmt, Object ... args) { * @param fmt Format string. * @param args Arguments. */ - private static char[] readPassword(String fmt, Object ... args) { + private static char[] readPassword(String fmt, Object... args) { if (System.console() != null) return System.console().readPassword(fmt, args); @@ -339,7 +339,7 @@ public static void main(String[] args) throws Exception { case "http": case "https": final String username = System.getProperty(uri.getScheme() + ".proxyUsername"); - final char[] pwd = System.getProperty(uri.getScheme() + ".proxyPassword", "").toCharArray(); + final char[] pwd = System.getProperty(uri.getScheme() + ".proxyPassword", "").toCharArray(); Authenticator.setDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { From 907b13ebcaa07c7471588de1f831e5ad827eeb71 Mon Sep 17 00:00:00 2001 From: vsisko Date: Fri, 21 Apr 2017 09:42:15 +0700 Subject: [PATCH 116/311] ignite-2.0 Fixed IGNITE_MODULES search path. (cherry picked from commit 8ad5a94) --- modules/web-console/backend/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/web-console/backend/index.js b/modules/web-console/backend/index.js index 7416f51f25134..7db51c89f8179 100644 --- a/modules/web-console/backend/index.js +++ b/modules/web-console/backend/index.js @@ -22,12 +22,13 @@ const path = require('path'); const http = require('http'); const https = require('https'); -const igniteModules = process.env.IGNITE_MODULES || './ignite_modules'; +const igniteModules = process.env.IGNITE_MODULES ? + path.join(path.normalize(process.env.IGNITE_MODULES), 'backend') : './ignite_modules'; let injector; try { - const igniteModulesInjector = path.resolve(path.join(igniteModules, 'backend', 'injector.js')); + const igniteModulesInjector = path.resolve(path.join(igniteModules, 'injector.js')); fs.accessSync(igniteModulesInjector, fs.F_OK); From d43a63c5e878460c1a9d6e2569e315aada788a76 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Fri, 21 Apr 2017 16:34:01 +0700 Subject: [PATCH 117/311] GG-12050 Fixed dependencies. --- modules/web-console/web-agent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/web-console/web-agent/pom.xml b/modules/web-console/web-agent/pom.xml index 697e58f32e012..49e0ef0e841eb 100644 --- a/modules/web-console/web-agent/pom.xml +++ b/modules/web-console/web-agent/pom.xml @@ -61,7 +61,7 @@ com.squareup.okhttp3 okhttp - 3.6.0 + 3.7.0 From 1aeaf2070a56f1dd6a867108e0d54038f7985446 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Thu, 20 Apr 2017 19:22:16 +0300 Subject: [PATCH 118/311] GG-12118: Metrics test fix --- .../ignite/internal/processors/cache/CacheMetricsImpl.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 9aaea84ebcb56..48e1d2fc002c5 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 @@ -742,6 +742,9 @@ public void addPutAndGetTimeNanos(long duration) { public int getTotalPartitionsCount() { int res = 0; + if (cctx.isLocal()) + return res; + for (Map.Entry e : cctx.topology().localPartitionMap().entrySet()) { if (e.getValue() == GridDhtPartitionState.OWNING || e.getValue() == GridDhtPartitionState.MOVING) res++; @@ -754,6 +757,9 @@ public int getTotalPartitionsCount() { public int getRebalancingPartitionsCount() { int res = 0; + if (cctx.isLocal()) + return res; + for (Map.Entry e : cctx.topology().localPartitionMap().entrySet()) { if (e.getValue() == GridDhtPartitionState.MOVING) res++; From 39abe5ee8c918c0866627ad30813f361f6ab8145 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 21 Apr 2017 14:26:23 +0300 Subject: [PATCH 119/311] IGNITE-3477 - Properly handle GridDhtInvalidPartitionException --- .../cache/distributed/dht/GridDhtGetFuture.java | 13 ++++++++++--- .../dht/GridDhtPartitionTopologyImpl.java | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java index 0f650556e9efd..b951a16befceb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java @@ -291,9 +291,16 @@ else if (mappedKeys != null) * @return {@code True} if mapped. */ private boolean map(KeyCacheObject key) { - GridDhtLocalPartition part = topVer.topologyVersion() > 0 ? - cache().topology().localPartition(cctx.affinity().partition(key), topVer, true) : - cache().topology().localPartition(key, false); + GridDhtLocalPartition part; + + try { + part = topVer.topologyVersion() > 0 ? + cache().topology().localPartition(cctx.affinity().partition(key), topVer, true) : + cache().topology().localPartition(key, false); + } + catch (GridDhtInvalidPartitionException e) { + return false; + } if (part == null) return false; 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 731be1a1c39bf..dbf2f80547d08 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 @@ -864,7 +864,7 @@ else if (loc != null && state == RENTING && !showRenting) for (UUID nodeId : nodeIds) { HashSet affIds = affAssignment.getIds(p); - if (!affIds.contains(nodeId) && hasState(p, nodeId, OWNING, MOVING, RENTING)) { + if (!affIds.contains(nodeId) && hasState(p, nodeId, OWNING, MOVING)) { ClusterNode n = cctx.discovery().node(nodeId); if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) { From 0292ce00b20a1cdf7852f213e17190d80d42f2b3 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Fri, 21 Apr 2017 19:42:25 +0300 Subject: [PATCH 120/311] gg-12120 : Throw exception instead of AssertionError when partition is in invalid state. --- .../cache/distributed/dht/GridDhtTxLocalAdapter.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java index 8b51cb577c51a..a9c383dfc8005 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java @@ -520,9 +520,7 @@ private void addMapping( return addReader(msgId, dhtCache.entryExx(existing.key()), existing, topologyVersion()); } catch (GridDhtInvalidPartitionException ex) { - addInvalidPartition(cacheCtx, ex.partition()); - - return new GridFinishedFuture<>(true); + throw new IgniteCheckedException(ex); } } From 6e571f8ed17849b88aa51f942dab091f251d6fd5 Mon Sep 17 00:00:00 2001 From: devozerov Date: Mon, 24 Apr 2017 12:31:51 +0300 Subject: [PATCH 121/311] IGNITE-5058: Fixed QueryIndex validation when QueryEntity.valueType is not set yet. This closes #1861. --- .../org/apache/ignite/cache/QueryEntity.java | 43 ++--- .../processors/cache/GridCacheProcessor.java | 4 + .../processors/query/QuerySchema.java | 4 +- .../internal/processors/query/QueryUtils.java | 79 ++++++++- .../h2/H2IndexingAbstractGeoSelfTest.java | 2 +- .../DynamicIndexAbstractBasicSelfTest.java | 16 +- .../index/QueryEntityValidationSelfTest.java | 162 ++++++++++++++++++ .../IgniteCacheQuerySelfTestSuite.java | 5 + 8 files changed, 280 insertions(+), 35 deletions(-) create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/QueryEntityValidationSelfTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java index 31fe26439da87..806cd7d69af37 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java @@ -18,16 +18,18 @@ package org.apache.ignite.cache; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; -import org.apache.ignite.internal.processors.query.QueryUtils; -import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.A; +import org.apache.ignite.internal.util.typedef.internal.S; /** * Query entity is a description of {@link org.apache.ignite.IgniteCache cache} entry (composed of key and value) @@ -44,16 +46,20 @@ public class QueryEntity implements Serializable { private String valType; /** Fields available for query. A map from field name to type name. */ + @GridToStringInclude private LinkedHashMap fields = new LinkedHashMap<>(); /** Set of field names that belong to the key. */ + @GridToStringInclude private Set keyFields; /** Aliases. */ + @GridToStringInclude private Map aliases = new HashMap<>(); /** Collection of query indexes. */ - private Map idxs = new HashMap<>(); + @GridToStringInclude + private Collection idxs; /** Table name. */ private String tableName; @@ -78,7 +84,7 @@ public QueryEntity(QueryEntity other) { keyFields = other.keyFields != null ? new HashSet<>(other.keyFields) : null; aliases = new HashMap<>(other.aliases); - idxs = new HashMap<>(other.idxs); + idxs = other.idxs != null ? new ArrayList<>(other.idxs) : null; tableName = other.tableName; } @@ -190,7 +196,7 @@ public QueryEntity setKeyFields(Set keyFields) { * @return Collection of index entities. */ public Collection getIndexes() { - return idxs.values(); + return idxs == null ? Collections.emptyList() : idxs; } /** @@ -222,31 +228,11 @@ public QueryEntity setAliases(Map aliases) { * @return {@code this} for chaining. */ public QueryEntity setIndexes(Collection idxs) { - for (QueryIndex idx : idxs) { - if (!F.isEmpty(idx.getFields())) { - if (idx.getName() == null) - idx.setName(QueryUtils.indexName(this, idx)); - - if (idx.getIndexType() == null) - throw new IllegalArgumentException("Index type is not set " + idx.getName()); - - if (!this.idxs.containsKey(idx.getName())) - this.idxs.put(idx.getName(), idx); - else - throw new IllegalArgumentException("Duplicate index name: " + idx.getName()); - } - } + this.idxs = idxs; return this; } - /** - * Clear indexes. - */ - public void clearIndexes() { - this.idxs.clear(); - } - /** * Gets table name for this query entity. * @@ -282,4 +268,9 @@ public QueryEntity addQueryField(String fullName, String type, String alias) { return this; } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(QueryEntity.class, this); + } } 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 df42b6f18d64b..e104b14b85041 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 @@ -514,6 +514,8 @@ else if (cc.getRebalanceMode() == SYNC) { if (cc.getEvictionPolicy() != null && !cc.isOnheapCacheEnabled()) throw new IgniteCheckedException("Onheap cache must be enabled if eviction policy is configured [cacheName=" + U.maskName(cc.getName()) + "]"); + + QueryUtils.validateCacheConfiguration(cc); } /** @@ -1441,6 +1443,8 @@ private GridCacheContext createCache(CacheConfiguration cfg, CacheStore cfgStore = cfg.getCacheStoreFactory() != null ? cfg.getCacheStoreFactory().create() : null; + QueryUtils.prepareCacheConfiguration(cfg); + validate(ctx.config(), cfg, cacheType, cfgStore); if (pluginMgr == null) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java index 395f077c4e9df..b380131a701e3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java @@ -111,7 +111,6 @@ public void finish(SchemaFinishDiscoveryMessage msg) { idxs.add(op0.index()); - entity.clearIndexes(); entity.setIndexes(idxs); } @@ -142,8 +141,7 @@ public void finish(SchemaFinishDiscoveryMessage msg) { newIdxs.remove(victim); - entity.clearIndexes(); - entity.setIndexes(idxs); + entity.setIndexes(newIdxs); break; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java index 3a7437b58a5fa..e56f39fc9775e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java @@ -45,6 +45,7 @@ import java.math.BigDecimal; import java.sql.Time; import java.sql.Timestamp; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -162,9 +163,6 @@ public static String indexName(String tblName, QueryIndex idx) { */ public static QueryTypeCandidate typeForQueryEntity(String space, GridCacheContext cctx, QueryEntity qryEntity, List> mustDeserializeClss) throws IgniteCheckedException { - if (F.isEmpty(qryEntity.getValueType())) - throw new IgniteCheckedException("Value type is not set: " + qryEntity); - GridKernalContext ctx = cctx.kernalContext(); CacheConfiguration ccfg = cctx.config(); @@ -796,6 +794,81 @@ public static int discoveryHistorySize() { return new SchemaOperationException("Unexpected exception.", e); } + /** + * Prepare cache configuration. + * + * @param ccfg Cache configuration. + */ + @SuppressWarnings("unchecked") + public static void prepareCacheConfiguration(CacheConfiguration ccfg) { + assert ccfg != null; + + Collection entities = ccfg.getQueryEntities(); + + if (!F.isEmpty(entities)) { + for (QueryEntity entity : entities) { + if (F.isEmpty(entity.getValueType())) + continue; + + Collection idxs = entity.getIndexes(); + + if (!F.isEmpty(idxs)) { + for (QueryIndex idx : idxs) { + if (idx.getName() == null) { + String idxName = indexName(entity, idx); + + idx.setName(idxName); + } + } + } + } + } + } + + /** + * Prepare cache configuration. + * + * @param ccfg Cache configuration. + * @throws IgniteCheckedException If failed. + */ + @SuppressWarnings("unchecked") + public static void validateCacheConfiguration(CacheConfiguration ccfg) throws IgniteCheckedException { + assert ccfg != null; + + Collection entities = ccfg.getQueryEntities(); + + if (!F.isEmpty(entities)) { + for (QueryEntity entity : entities) { + if (F.isEmpty(entity.getValueType())) + throw new IgniteCheckedException("Value type cannot be null or empty [cacheName=" + + ccfg.getName() + ", queryEntity=" + entity + ']'); + + Collection idxs = entity.getIndexes(); + + if (!F.isEmpty(idxs)) { + Set idxNames = new HashSet<>(); + + for (QueryIndex idx : idxs) { + String idxName = idx.getName(); + + if (idxName == null) + idxName = indexName(entity, idx); + + assert !F.isEmpty(idxName); + + if (!idxNames.add(idxName)) + throw new IgniteCheckedException("Duplicate index name [cacheName=" + ccfg.getName() + + ", queryEntity=" + entity + ", queryIdx=" + idx + ']'); + + if (idx.getIndexType() == null) + throw new IgniteCheckedException("Index type is not set [cacheName=" + ccfg.getName() + + ", queryEntity=" + entity + ", queryIdx=" + idx + ']'); + } + } + } + } + } + /** * Private constructor. */ diff --git a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java index 914bb62b3a23c..c5c2b4738b140 100644 --- a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java +++ b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java @@ -151,7 +151,7 @@ protected IgniteCache createCache(String name, boolean partitioned, Collection idxs = new ArrayList<>(entity.getIndexes()); - entity.clearIndexes(); + entity.setIndexes(null); IgniteCache cache = grid(0).getOrCreateCache(ccfg); diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java index 6bc1576021c08..b923fd8fad27b 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java @@ -657,23 +657,35 @@ public void testDropReplicatedTransactional() throws Exception { public void checkDrop(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception { initialize(mode, atomicityMode, near); - QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1)); + // Create target index. + QueryIndex idx1 = index(IDX_NAME_1, field(FIELD_NAME_1)); - queryProcessor(node()).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false).get(); + queryProcessor(node()).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx1, false).get(); assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1)); assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1); assertSimpleIndexOperations(SQL_SIMPLE_FIELD_1); + // Create another index which must stay intact afterwards. + QueryIndex idx2 = index(IDX_NAME_2, field(alias(FIELD_NAME_2))); + + queryProcessor(node()).dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx2, false).get(); + assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(alias(FIELD_NAME_2))); + + // Load some data. loadInitialData(); + // Drop index. queryProcessor(node()).dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, false).get(); assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1); assertSimpleIndexOperations(SQL_SIMPLE_FIELD_1); assertIndexNotUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1); + + // Make sure the second index is still there. + assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(alias(FIELD_NAME_2))); } /** diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/QueryEntityValidationSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/QueryEntityValidationSelfTest.java new file mode 100644 index 0000000000000..97c9aa1df3e50 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/QueryEntityValidationSelfTest.java @@ -0,0 +1,162 @@ +/* + * 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.index; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.QueryIndex; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.concurrent.Callable; + +/** + * Tests for query entity validation. + */ +@SuppressWarnings("ThrowableResultOfMethodCallIgnored") +public class QueryEntityValidationSelfTest extends GridCommonAbstractTest { + /** Cache name. */ + private static final String CACHE_NAME = "cache"; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGrid(0); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** + * Test null value type. + * + * @throws Exception If failed. + */ + public void testValueTypeNull() throws Exception { + final CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME); + + QueryEntity entity = new QueryEntity(); + + entity.setKeyType("Key"); + + ccfg.setQueryEntities(Collections.singleton(entity)); + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + grid(0).createCache(ccfg); + + return null; + } + }, IgniteCheckedException.class, "Value type cannot be null or empty"); + } + + /** + * Test failure if index type is null. + * + * @throws Exception If failed. + */ + public void testIndexTypeNull() throws Exception { + final CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME); + + QueryEntity entity = new QueryEntity(); + + entity.setKeyType("Key"); + entity.setValueType("Value"); + + LinkedHashMap fields = new LinkedHashMap<>(); + + fields.put("a", Integer.class.getName()); + + entity.setFields(fields); + + LinkedHashMap idxFields = new LinkedHashMap<>(); + + idxFields.put("a", true); + + QueryIndex idx = new QueryIndex().setName("idx").setFields(idxFields).setIndexType(null); + + List idxs = new ArrayList<>(); + + idxs.add(idx); + + entity.setIndexes(idxs); + + ccfg.setQueryEntities(Collections.singleton(entity)); + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + grid(0).createCache(ccfg); + + return null; + } + }, IgniteCheckedException.class, "Index type is not set"); + } + + /** + * Test duplicated index name. + * + * @throws Exception If failed. + */ + public void testIndexNameDuplicate() throws Exception { + final CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME); + + QueryEntity entity = new QueryEntity(); + + entity.setKeyType("Key"); + entity.setValueType("Value"); + + LinkedHashMap fields = new LinkedHashMap<>(); + + fields.put("a", Integer.class.getName()); + fields.put("b", Integer.class.getName()); + + entity.setFields(fields); + + LinkedHashMap idx1Fields = new LinkedHashMap<>(); + LinkedHashMap idx2Fields = new LinkedHashMap<>(); + + idx1Fields.put("a", true); + idx1Fields.put("b", true); + + QueryIndex idx1 = new QueryIndex().setName("idx").setFields(idx1Fields); + QueryIndex idx2 = new QueryIndex().setName("idx").setFields(idx2Fields); + + List idxs = new ArrayList<>(); + + idxs.add(idx1); + idxs.add(idx2); + + entity.setIndexes(idxs); + + ccfg.setQueryEntities(Collections.singleton(entity)); + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + grid(0).createCache(ccfg); + + return null; + } + }, IgniteCheckedException.class, "Duplicate index name"); + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java index b61affe2b8739..9acf7618743a9 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java @@ -92,6 +92,7 @@ import org.apache.ignite.internal.processors.cache.index.DynamicIndexServerNodeFIlterBasicSelfTest; import org.apache.ignite.internal.processors.cache.index.DynamicIndexServerNodeFilterCoordinatorBasicSelfTest; import org.apache.ignite.internal.processors.cache.index.DynamicIndexServerBasicSelfTest; +import org.apache.ignite.internal.processors.cache.index.QueryEntityValidationSelfTest; import org.apache.ignite.internal.processors.cache.index.SchemaExchangeSelfTest; import org.apache.ignite.internal.processors.cache.local.IgniteCacheLocalAtomicQuerySelfTest; import org.apache.ignite.internal.processors.cache.local.IgniteCacheLocalFieldsQuerySelfTest; @@ -128,6 +129,10 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite { public static TestSuite suite() throws Exception { IgniteTestSuite suite = new IgniteTestSuite("Ignite Cache Queries Test Suite"); + // Misc tests. + // TODO: Enable when IGNITE-1094 is fixed. + // suite.addTest(new TestSuite(QueryEntityValidationSelfTest.class)); + // Dynamic index create/drop tests. suite.addTest(new TestSuite(SchemaExchangeSelfTest.class)); From ed5c09653afea5a6f76a1042e162c9288af90802 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Mon, 24 Apr 2017 17:31:30 +0300 Subject: [PATCH 122/311] ignite-5068 : Replaced part2node with diffFromAffinity. --- .../dht/GridDhtPartitionTopologyImpl.java | 355 ++++++++---------- 1 file changed, 164 insertions(+), 191 deletions(-) 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 38cbb8c46931f..23c7caa317312 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 @@ -71,8 +71,7 @@ /** * Partition topology. */ -@GridToStringExclude -class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology { +@GridToStringExclude class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology { /** If true, then check consistency. */ private static final boolean CONSISTENCY_CHECK = false; @@ -97,6 +96,8 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology { /** Partition to node map. */ private Map> part2node = new HashMap<>(); + private final Map> diffFromAffinity = new HashMap<>(); + /** */ private GridDhtPartitionExchangeId lastExchangeId; @@ -159,7 +160,7 @@ public void onReconnected() { try { node2part = null; - part2node = new HashMap<>(); + diffFromAffinity.clear(); lastExchangeId = null; @@ -951,18 +952,20 @@ else if (loc != null && state == RENTING && cctx.allowFastEviction()) List nodes = null; - Collection nodeIds = part2node.get(p); + Collection diffIds = diffFromAffinity.get(p); + + if (!F.isEmpty(diffIds)) { + HashSet affIds = affAssignment.getIds(p); - if (!F.isEmpty(nodeIds)) { - for (UUID nodeId : nodeIds) { - HashSet affIds = affAssignment.getIds(p); + for (UUID nodeId : diffIds) { +// assert !affIds.contains(nodeId); if (!affIds.contains(nodeId) && hasState(p, nodeId, OWNING, MOVING, RENTING)) { ClusterNode n = cctx.discovery().node(nodeId); if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) { if (nodes == null) { - nodes = new ArrayList<>(affNodes.size() + 2); + nodes = new ArrayList<>(affNodes.size() + diffIds.size()); nodes.addAll(affNodes); } @@ -991,7 +994,7 @@ private List nodes(int p, AffinityTopologyVersion topVer, GridDhtPartitionState state, GridDhtPartitionState... states) { - Collection allIds = topVer.topologyVersion() > 0 ? F.nodeIds(discoCache.cacheAffinityNodes(cctx.cacheId())) : null; + Collection allIds = F.nodeIds(discoCache.cacheAffinityNodes(cctx.cacheId())); lock.readLock().lock(); @@ -1001,20 +1004,10 @@ private List nodes(int p, ", node2part=" + node2part + ", cache=" + cctx.name() + ']'; - Collection nodeIds = part2node.get(p); - // Node IDs can be null if both, primary and backup, nodes disappear. - int size = nodeIds == null ? 0 : nodeIds.size(); - - if (size == 0) - return Collections.emptyList(); - - List nodes = new ArrayList<>(size); - - for (UUID id : nodeIds) { - if (topVer.topologyVersion() > 0 && !F.contains(allIds, id)) - continue; + List nodes = new ArrayList<>(); + for (UUID id : allIds) { if (hasState(p, id, state, states)) { ClusterNode n = cctx.discovery().node(id); @@ -1185,27 +1178,38 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) node2part = partMap; - Map> p2n = new HashMap<>(cctx.affinity().partitions(), 1.0f); + diffFromAffinity.clear(); + + int diffFromAffinitySize = 0; + + AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); + + AffinityAssignment affAssignment = cctx.affinity().assignment(affVer); for (Map.Entry e : partMap.entrySet()) { - for (Integer p : e.getValue().keySet()) { - Set ids = p2n.get(p); + for (Map.Entry e0 : e.getValue().entrySet()) { + if (e0.getValue() != MOVING && e0.getValue() != OWNING && e0.getValue() != RENTING) + continue; + + int p = e0.getKey(); + + if (!affAssignment.getIds(p).contains(partMap.nodeId())) { + Set diffIds = diffFromAffinity.get(p); - if (ids == null) - // Initialize HashSet to size 3 in anticipation that there won't be - // more than 3 nodes per partitions. - p2n.put(p, ids = U.newHashSet(3)); + if (diffIds == null) + diffFromAffinity.put(p, diffIds = U.newHashSet(3)); - ids.add(e.getKey()); + if (diffIds.add(partMap.nodeId())) + diffFromAffinitySize++; + } } } - part2node = p2n; + if (diffFromAffinitySize > 0) + U.error(log, "??? S diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); boolean changed = false; - AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); - GridDhtPartitionMap nodeMap = partMap.get(cctx.localNodeId()); if (nodeMap != null && cctx.shared().database().persistenceEnabled()) { @@ -1213,7 +1217,7 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) int p = e.getKey(); GridDhtPartitionState state = e.getValue(); - if (state == MOVING) { + if (state == MOVING) { GridDhtLocalPartition locPart = locParts.get(p); assert locPart != null; @@ -1338,31 +1342,62 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) node2part.put(parts.nodeId(), parts); - part2node = new HashMap<>(part2node); + diffFromAffinity.clear(); + + AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); + + AffinityAssignment affAssignment = cctx.affinity().assignment(affVer); + + int diffFromAffinitySize = 0; // Add new mappings. - for (Integer p : parts.keySet()) { - Set ids = part2node.get(p); + for (Map.Entry e : parts.entrySet()) { + int p = e.getKey(); + + Set diffIds = diffFromAffinity.get(p); + + if ((e.getValue() == MOVING || e.getValue() == OWNING || e.getValue() == RENTING) + && !affAssignment.getIds(p).contains(parts.nodeId())) { + if (diffIds == null) + diffFromAffinity.put(p, diffIds = U.newHashSet(3)); + + if (diffIds.add(parts.nodeId())) { + changed = true; + + diffFromAffinitySize++; + } + } + else { + if (diffIds != null && diffIds.remove(parts.nodeId())) { + changed = true; - if (ids == null) - // Initialize HashSet to size 3 in anticipation that there won't be - // more than 3 nodes per partition. - part2node.put(p, ids = U.newHashSet(3)); + diffFromAffinitySize--; - changed |= ids.add(parts.nodeId()); + if (diffIds.isEmpty()) + diffFromAffinity.remove(p); + } + + } } // Remove obsolete mappings. if (cur != null) { for (Integer p : F.view(cur.keySet(), F0.notIn(parts.keySet()))) { - Set ids = part2node.get(p); + Set ids = diffFromAffinity.get(p); - if (ids != null) - changed |= ids.remove(parts.nodeId()); + if (ids != null && ids.remove(parts.nodeId())) { + changed = true; + + diffFromAffinitySize--; + + if (ids.isEmpty()) + diffFromAffinity.remove(p); + } } } - AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); + if (diffFromAffinitySize > 0) + U.error(log, "??? diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); if (!affVer.equals(AffinityTopologyVersion.NONE) && affVer.compareTo(topVer) >= 0) { List> aff = cctx.affinity().assignments(topVer); @@ -1394,38 +1429,21 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) try { int parts = cctx.affinity().partitions(); - Collection lost = null; - - for (int p = 0; p < parts; p++) { - boolean foundOwner = false; - - Set nodeIds = part2node.get(p); + Set lost = new HashSet<>(parts); - if (nodeIds != null) { - for (UUID nodeId : nodeIds) { - GridDhtPartitionMap partMap = node2part.get(nodeId); + for (int p = 0; p < parts; p++) + lost.add(p); - GridDhtPartitionState state = partMap.get(p); - - if (state == OWNING) { - foundOwner = true; - - break; - } - } - } - - if (!foundOwner) { - if (lost == null) - lost = new HashSet<>(parts - p, 1.0f); - - lost.add(p); + for (GridDhtPartitionMap partMap : node2part.values()) { + for (Map.Entry e : partMap.entrySet()) { + if (e.getValue() == OWNING) + lost.remove(e.getKey()); } } boolean changed = false; - if (lost != null) { + if (!lost.isEmpty()) { PartitionLossPolicy plc = cctx.config().getPartitionLossPolicy(); assert plc != null; @@ -1446,16 +1464,17 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) } // Update map for remote node. else if (plc != PartitionLossPolicy.IGNORE) { - Set nodeIds = part2node.get(part); - - if (nodeIds != null) { - for (UUID nodeId : nodeIds) { - GridDhtPartitionMap nodeMap = node2part.get(nodeId); - - if (nodeMap.get(part) != EVICTED) - nodeMap.put(part, LOST); - } - } + // TODO +// Set nodeIds = part2node.get(part); +// +// if (nodeIds != null) { +// for (UUID nodeId : nodeIds) { +// GridDhtPartitionMap nodeMap = node2part.get(nodeId); +// +// if (nodeMap.get(part) != EVICTED) +// nodeMap.put(part, LOST); +// } +// } } if (cctx.events().isRecordable(EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST)) @@ -1476,86 +1495,83 @@ else if (plc != PartitionLossPolicy.IGNORE) { /** {@inheritDoc} */ @Override public void resetLostPartitions() { - lock.writeLock().lock(); - - try { - int parts = cctx.affinity().partitions(); - long updSeq = updateSeq.incrementAndGet(); - - for (int part = 0; part < parts; part++) { - Set nodeIds = part2node.get(part); - - if (nodeIds != null) { - boolean lost = false; - - for (UUID node : nodeIds) { - GridDhtPartitionMap map = node2part.get(node); - - if (map.get(part) == LOST) { - lost = true; - - break; - } - } - - if (lost) { - GridDhtLocalPartition locPart = localPartition(part, topVer, false); - - if (locPart != null) { - boolean marked = locPart.own(); - - if (marked) - updateLocal(locPart.id(), locPart.state(), updSeq); - } - - for (UUID nodeId : nodeIds) { - GridDhtPartitionMap nodeMap = node2part.get(nodeId); - - if (nodeMap.get(part) == LOST) - nodeMap.put(part, OWNING); - } - } - } - } - - checkEvictions(updSeq, cctx.affinity().assignments(topVer)); - - cctx.needsRecovery(false); - } - finally { - lock.writeLock().unlock(); - } + // TODO + +// lock.writeLock().lock(); +// +// try { +// int parts = cctx.affinity().partitions(); +// long updSeq = updateSeq.incrementAndGet(); +// +// for (int part = 0; part < parts; part++) { +// Set nodeIds = part2node.get(part); +// +// if (nodeIds != null) { +// boolean lost = false; +// +// for (UUID node : nodeIds) { +// GridDhtPartitionMap map = node2part.get(node); +// +// if (map.get(part) == LOST) { +// lost = true; +// +// break; +// } +// } +// +// if (lost) { +// GridDhtLocalPartition locPart = localPartition(part, topVer, false); +// +// if (locPart != null) { +// boolean marked = locPart.own(); +// +// if (marked) +// updateLocal(locPart.id(), locPart.state(), updSeq); +// } +// +// for (UUID nodeId : nodeIds) { +// GridDhtPartitionMap nodeMap = node2part.get(nodeId); +// +// if (nodeMap.get(part) == LOST) +// nodeMap.put(part, OWNING); +// } +// } +// } +// } +// +// checkEvictions(updSeq, cctx.affinity().assignments(topVer)); +// +// cctx.needsRecovery(false); +// } +// finally { +// lock.writeLock().unlock(); +// } } /** {@inheritDoc} */ @Override public Collection lostPartitions() { + if (cctx.config().getPartitionLossPolicy() == PartitionLossPolicy.IGNORE) + return Collections.emptySet(); + lock.readLock().lock(); try { - Collection res = null; + Set res = null; int parts = cctx.affinity().partitions(); - for (int part = 0; part < parts; part++) { - Set nodeIds = part2node.get(part); - - if (nodeIds != null) { - for (UUID node : nodeIds) { - GridDhtPartitionMap map = node2part.get(node); - - if (map.get(part) == LOST) { - if (res == null) - res = new ArrayList<>(parts - part); - - res.add(part); + for (GridDhtPartitionMap partMap : node2part.values()) { + for (Map.Entry e : partMap.entrySet()) { + if (e.getValue() == LOST) { + if (res == null) + res = new HashSet<>(parts); - break; - } + res.add(e.getKey()); } } } - return res == null ? Collections.emptyList() : res; + return res == null ? Collections.emptySet() : res; } finally { lock.readLock().unlock(); @@ -1746,7 +1762,7 @@ private long updateLocal(int p, GridDhtPartitionState state, long updateSeq) { if (node2part != null) { UUID locNodeId = cctx.localNodeId(); - GridDhtPartitionMap map = node2part.get(locNodeId); + GridDhtPartitionMap map = node2part.get(locNodeId); if (map == null) { map = new GridDhtPartitionMap(locNodeId, @@ -1761,13 +1777,6 @@ private long updateLocal(int p, GridDhtPartitionState state, long updateSeq) { map.updateSequence(updateSeq, topVer); map.put(p, state); - - Set ids = part2node.get(p); - - if (ids == null) - part2node.put(p, ids = U.newHashSet(3)); - - ids.add(locNodeId); } return updateSeq; @@ -1795,20 +1804,7 @@ private void removeNode(UUID nodeId) { else node2part = new GridDhtPartitionFullMap(node2part, node2part.updateSequence()); - GridDhtPartitionMap parts = node2part.remove(nodeId); - - if (parts != null) { - for (Integer p : parts.keySet()) { - Set nodeIds = part2node.get(p); - - if (nodeIds != null) { - nodeIds.remove(nodeId); - - if (nodeIds.isEmpty()) - part2node.remove(p); - } - } - } + node2part.remove(nodeId); consistencyCheck(); } @@ -2044,30 +2040,7 @@ private boolean hasState(final int p, @Nullable UUID nodeId, final GridDhtPartit * Checks consistency after all operations. */ private void consistencyCheck() { - if (CONSISTENCY_CHECK) { - if (node2part == null) - return; - - for (Map.Entry e : node2part.entrySet()) { - for (Integer p : e.getValue().keySet()) { - Set nodeIds = part2node.get(p); - - assert nodeIds != null : "Failed consistency check [part=" + p + ", nodeId=" + e.getKey() + ']'; - assert nodeIds.contains(e.getKey()) : "Failed consistency check [part=" + p + ", nodeId=" + - e.getKey() + ", nodeIds=" + nodeIds + ']'; - } - } - - for (Map.Entry> e : part2node.entrySet()) { - for (UUID nodeId : e.getValue()) { - GridDhtPartitionMap map = node2part.get(nodeId); - - assert map != null : "Failed consistency check [part=" + e.getKey() + ", nodeId=" + nodeId + ']'; - assert map.containsKey(e.getKey()) : "Failed consistency check [part=" + e.getKey() + - ", nodeId=" + nodeId + ']'; - } - } - } + // no-op } /** From c094ac5a95e546f03713ec1def9157fe273bb032 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Mon, 24 Apr 2017 18:55:34 +0300 Subject: [PATCH 123/311] ignite-5068 : Fixed diffFromAffinity consistency when affinity initialization is deferred (node left) --- .../dht/GridClientPartitionTopology.java | 5 + .../dht/GridDhtPartitionTopology.java | 2 + .../dht/GridDhtPartitionTopologyImpl.java | 170 ++++++++++++------ .../GridDhtPartitionsExchangeFuture.java | 4 + 4 files changed, 122 insertions(+), 59 deletions(-) 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 f3c3a1bb14972..e026feac102b5 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 @@ -754,6 +754,11 @@ public long lastUpdateSequence() { } } + /** {@inheritDoc} */ + @Override public void onAffinityInitialized(Map> assignment) { + // TODO + } + /** {@inheritDoc} */ @Override public boolean detectLostPartitions(DiscoveryEvent discoEvt) { assert false : "detectLostPartitions should never be called on client topology"; 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 f9fd85270e483..b47321e9aee06 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 @@ -312,4 +312,6 @@ public GridDhtPartitionMap update(@Nullable GridDhtPartitionExchangeId exchId, * @param owners Set of new owners. */ public void setOwners(int p, Set owners, boolean updateSeq); + + public void onAffinityInitialized(Map> assignment); } 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 23c7caa317312..fcc934f619b91 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 @@ -62,6 +62,8 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT; import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST; +import static org.apache.ignite.events.EventType.EVT_NODE_FAILED; +import static org.apache.ignite.events.EventType.EVT_NODE_LEFT; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.LOST; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.MOVING; @@ -93,11 +95,12 @@ /** Node to partition map. */ private GridDhtPartitionFullMap node2part; - /** Partition to node map. */ - private Map> part2node = new HashMap<>(); - + /** */ private final Map> diffFromAffinity = new HashMap<>(); + /** */ + private volatile AffinityTopologyVersion diffFromAffinityVer = AffinityTopologyVersion.NONE; + /** */ private GridDhtPartitionExchangeId lastExchangeId; @@ -168,6 +171,8 @@ public void onReconnected() { topReadyFut = null; + diffFromAffinityVer = AffinityTopologyVersion.NONE; + rebalancedTopVer = AffinityTopologyVersion.NONE; topVer = AffinityTopologyVersion.NONE; @@ -1178,35 +1183,43 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) node2part = partMap; - diffFromAffinity.clear(); - int diffFromAffinitySize = 0; AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); - AffinityAssignment affAssignment = cctx.affinity().assignment(affVer); + if (diffFromAffinityVer.compareTo(affVer) <= 0) { + AffinityAssignment affAssignment = cctx.affinity().assignment(affVer); - for (Map.Entry e : partMap.entrySet()) { - for (Map.Entry e0 : e.getValue().entrySet()) { - if (e0.getValue() != MOVING && e0.getValue() != OWNING && e0.getValue() != RENTING) - continue; + for (Map.Entry e : partMap.entrySet()) { + for (Map.Entry e0 : e.getValue().entrySet()) { + int p = e0.getKey(); - int p = e0.getKey(); - - if (!affAssignment.getIds(p).contains(partMap.nodeId())) { Set diffIds = diffFromAffinity.get(p); - if (diffIds == null) - diffFromAffinity.put(p, diffIds = U.newHashSet(3)); + if (e0.getValue() != MOVING && e0.getValue() != OWNING && e0.getValue() != RENTING && + !affAssignment.getIds(p).contains(partMap.nodeId())) { + if (diffIds == null) + diffFromAffinity.put(p, diffIds = U.newHashSet(3)); - if (diffIds.add(partMap.nodeId())) - diffFromAffinitySize++; + if (diffIds.add(partMap.nodeId())) + diffFromAffinitySize++; + } + else { + if (diffIds != null && diffIds.remove(partMap.nodeId())) { + diffFromAffinitySize--; + + if (diffIds.isEmpty()) + diffFromAffinity.remove(p); + } + } } } - } - if (diffFromAffinitySize > 0) - U.error(log, "??? S diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); + diffFromAffinityVer = affVer; + + if (diffFromAffinitySize > 0) + U.error(log, "??? S diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); + } boolean changed = false; @@ -1342,62 +1355,64 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) node2part.put(parts.nodeId(), parts); - diffFromAffinity.clear(); - AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); - AffinityAssignment affAssignment = cctx.affinity().assignment(affVer); + if (diffFromAffinityVer.compareTo(affVer) <= 0) { + AffinityAssignment affAssignment = cctx.affinity().assignment(affVer); - int diffFromAffinitySize = 0; + int diffFromAffinitySize = 0; - // Add new mappings. - for (Map.Entry e : parts.entrySet()) { - int p = e.getKey(); + // Add new mappings. + for (Map.Entry e : parts.entrySet()) { + int p = e.getKey(); - Set diffIds = diffFromAffinity.get(p); + Set diffIds = diffFromAffinity.get(p); - if ((e.getValue() == MOVING || e.getValue() == OWNING || e.getValue() == RENTING) - && !affAssignment.getIds(p).contains(parts.nodeId())) { - if (diffIds == null) - diffFromAffinity.put(p, diffIds = U.newHashSet(3)); + if ((e.getValue() == MOVING || e.getValue() == OWNING || e.getValue() == RENTING) + && !affAssignment.getIds(p).contains(parts.nodeId())) { + if (diffIds == null) + diffFromAffinity.put(p, diffIds = U.newHashSet(3)); - if (diffIds.add(parts.nodeId())) { - changed = true; + if (diffIds.add(parts.nodeId())) { + changed = true; - diffFromAffinitySize++; + diffFromAffinitySize++; + } } - } - else { - if (diffIds != null && diffIds.remove(parts.nodeId())) { - changed = true; + else { + if (diffIds != null && diffIds.remove(parts.nodeId())) { + changed = true; - diffFromAffinitySize--; + diffFromAffinitySize--; - if (diffIds.isEmpty()) - diffFromAffinity.remove(p); - } + if (diffIds.isEmpty()) + diffFromAffinity.remove(p); + } + } } - } - // Remove obsolete mappings. - if (cur != null) { - for (Integer p : F.view(cur.keySet(), F0.notIn(parts.keySet()))) { - Set ids = diffFromAffinity.get(p); + // Remove obsolete mappings. + if (cur != null) { + for (Integer p : F.view(cur.keySet(), F0.notIn(parts.keySet()))) { + Set ids = diffFromAffinity.get(p); - if (ids != null && ids.remove(parts.nodeId())) { - changed = true; + if (ids != null && ids.remove(parts.nodeId())) { + changed = true; - diffFromAffinitySize--; + diffFromAffinitySize--; - if (ids.isEmpty()) - diffFromAffinity.remove(p); + if (ids.isEmpty()) + diffFromAffinity.remove(p); + } } } - } - if (diffFromAffinitySize > 0) - U.error(log, "??? diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); + diffFromAffinityVer = affVer; + + if (diffFromAffinitySize > 0) + U.error(log, "??? diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); + } if (!affVer.equals(AffinityTopologyVersion.NONE) && affVer.compareTo(topVer) >= 0) { List> aff = cctx.affinity().assignments(topVer); @@ -1422,6 +1437,45 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) } } + /** {@inheritDoc} */ + @Override public void onAffinityInitialized(Map> assignment) { + lock.writeLock().lock(); + + try { + AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); + + if (diffFromAffinityVer.compareTo(affVer) >= 0) + return; + + for (Map.Entry e : node2part.entrySet()) { + UUID nodeId = e.getKey(); + + for (Map.Entry e0 : e.getValue().entrySet()) { + int p = e0.getKey(); + GridDhtPartitionState state = e0.getValue(); + + Set ids = diffFromAffinity.get(p); + + if ((state == MOVING || state == OWNING || state == RENTING) && !assignment.get(p).contains(nodeId)) { + if (ids == null) + diffFromAffinity.put(p, ids = U.newHashSet(3)); + + ids.add(nodeId); + } + else { + if (ids != null) + ids.remove(nodeId); + } + } + } + + diffFromAffinityVer = affVer; + } + finally { + lock.writeLock().unlock(); + } + } + /** {@inheritDoc} */ @Override public boolean detectLostPartitions(DiscoveryEvent discoEvt) { lock.writeLock().lock(); @@ -1991,9 +2045,7 @@ private void updateRebalanceVersion(List> aff) { if (affNodes.isEmpty()) continue; - List owners = owners(i); - - if (affNodes.size() != owners.size() || !owners.containsAll(affNodes)) + if (!F.isEmpty(diffFromAffinity.get(i))) return; } 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 f6827ab9e90d1..119ceeec3df24 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 @@ -1486,6 +1486,10 @@ private void onAffinityInitialized(IgniteInternalFuture>> assignmentChange = fut.get(); + for (Map.Entry>> e : assignmentChange.entrySet()) { + cctx.cacheContext(e.getKey()).topology().onAffinityInitialized(e.getValue()); + } + GridDhtPartitionsFullMessage m = createPartitionsMessage(null, false); CacheAffinityChangeMessage msg = new CacheAffinityChangeMessage(exchId, m, assignmentChange); From 8702da9558570043c9e458a903c78d8015d919e8 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Tue, 25 Apr 2017 14:02:26 +0700 Subject: [PATCH 124/311] GG-12132 Added magic header to protect from unexpected input. (cherry picked from commit e4a926b) --- .../marshaller/optimized/OptimizedMarshaller.java | 3 ++- .../internal/visor/VisorDataTransferObject.java | 15 +++++++++++++-- .../visor/binary/VisorBinaryMetadata.java | 3 +-- .../visor/cache/VisorCacheConfiguration.java | 3 +-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java index 3f40d6302339c..575c9a4a0e17e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java @@ -232,7 +232,8 @@ public OptimizedMarshaller setPoolSize(int poolSize) { "[clsLdr=" + clsLdr + ", cls=" + e.getMessage() + "]", e); } catch (Exception e) { - throw new IgniteCheckedException("Failed to deserialize object with given class loader: " + clsLdr, e); + throw new IgniteCheckedException("Failed to deserialize object with given class loader: " + + "[clsLdr=" + clsLdr + ", err=" + e.getMessage() + "]", e); } finally { OptimizedObjectStreamRegistry.closeIn(objIn); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java index d8dcf4e35c93c..bdf01e72406a3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java @@ -30,6 +30,9 @@ * Base class for data transfer objects. */ public abstract class VisorDataTransferObject implements Externalizable { + /** Magic number to detect correct transfer objects. */ + private static final int MAGIC = 0x42BEEF00; + /** * @param col Source collection. * @param Collection type. @@ -59,7 +62,9 @@ public byte getProtocolVersion() { /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { - out.writeByte(getProtocolVersion()); + int hdr = MAGIC + getProtocolVersion(); + + out.writeInt(hdr); try (VisorDataTransferObjectOutput dtout = new VisorDataTransferObjectOutput(out)) { writeExternalData(dtout); @@ -78,7 +83,13 @@ public byte getProtocolVersion() { /** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - byte ver = in.readByte(); + int hdr = in.readInt(); + + if ((hdr & MAGIC) != MAGIC) + throw new IOException("Unexpected VisorDataTransferObject header " + + "[actual=" + Integer.toHexString(hdr) + ", expected=" + Integer.toHexString(MAGIC) + "]"); + + byte ver = (byte)(hdr & 0xFF); try (VisorDataTransferObjectInput dtin = new VisorDataTransferObjectInput(in)) { readExternalData(ver, dtin); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/binary/VisorBinaryMetadata.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/binary/VisorBinaryMetadata.java index 5e948c616fd51..285bff90f1ba3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/binary/VisorBinaryMetadata.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/binary/VisorBinaryMetadata.java @@ -124,8 +124,7 @@ public Collection getFields() { } /** {@inheritDoc} */ - @Override protected void readExternalData(byte protoVer, - ObjectInput in) throws IOException, ClassNotFoundException { + @Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException { typeName = U.readString(in); typeId = (Integer)in.readObject(); affinityKeyFieldName = U.readString(in); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java index 391b120f8d66c..5b5d3a8af2fae 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java @@ -418,8 +418,7 @@ public int getQueryParallelism() { } /** {@inheritDoc} */ - @Override protected void readExternalData(byte protoVer, - ObjectInput in) throws IOException, ClassNotFoundException { + @Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException { name = U.readString(in); mode = CacheMode.fromOrdinal(in.readByte()); atomicityMode = CacheAtomicityMode.fromOrdinal(in.readByte()); From d465f6c69dcfddc944a2974c364eabe51f8d98aa Mon Sep 17 00:00:00 2001 From: devozerov Date: Wed, 19 Apr 2017 19:44:30 +0300 Subject: [PATCH 125/311] IGNITE-5027: Fixed issue with duplicate names on quto-generated indexes. This closes #1831. --- .../configuration/CacheConfiguration.java | 17 ++-- .../processors/query/GridQueryProcessor.java | 10 +- .../h2/H2IndexingAbstractGeoSelfTest.java | 8 +- ...gniteCacheAbstractFieldsQuerySelfTest.java | 10 +- .../DuplicateKeyValueClassesSelfTest.java | 94 +++++++++++++++++++ .../IgniteCacheQuerySelfTestSuite.java | 4 +- 6 files changed, 124 insertions(+), 19 deletions(-) create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DuplicateKeyValueClassesSelfTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java index a2f7cc800e9cd..d37834336e8a0 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java @@ -2145,7 +2145,7 @@ private static void processAnnotationsInClass(boolean key, Class cls, TypeDes // properties override will happen properly (first parent, then children). type.addProperty(prop, key, true); - processAnnotation(key, sqlAnn, txtAnn, field.getType(), prop, type); + processAnnotation(key, sqlAnn, txtAnn, cls, c, field.getType(), prop, type); } } @@ -2171,7 +2171,7 @@ private static void processAnnotationsInClass(boolean key, Class cls, TypeDes // properties override will happen properly (first parent, then children). type.addProperty(prop, key, true); - processAnnotation(key, sqlAnn, txtAnn, mtd.getReturnType(), prop, type); + processAnnotation(key, sqlAnn, txtAnn, cls, c, mtd.getReturnType(), prop, type); } } } @@ -2183,20 +2183,25 @@ private static void processAnnotationsInClass(boolean key, Class cls, TypeDes * @param key If given class relates to key. * @param sqlAnn SQL annotation, can be {@code null}. * @param txtAnn H2 text annotation, can be {@code null}. - * @param cls Class of field or return type for method. + * @param cls Entity class. + * @param curCls Current entity class. + * @param fldCls Class of field or return type for method. * @param prop Current property. * @param desc Class description. */ private static void processAnnotation(boolean key, QuerySqlField sqlAnn, QueryTextField txtAnn, - Class cls, ClassProperty prop, TypeDescriptor desc) { + Class cls, Class curCls, Class fldCls, ClassProperty prop, TypeDescriptor desc) { if (sqlAnn != null) { - processAnnotationsInClass(key, cls, desc, prop); + processAnnotationsInClass(key, fldCls, desc, prop); if (!sqlAnn.name().isEmpty()) prop.alias(sqlAnn.name()); if (sqlAnn.index()) { - String idxName = prop.alias() + "_idx"; + String idxName = curCls.getSimpleName() + "_" + prop.alias() + "_idx"; + + if (cls != curCls) + idxName = cls.getSimpleName() + "_" + idxName; desc.addIndex(idxName, QueryUtils.isGeometryClass(prop.type()) ? QueryIndexType.GEOSPATIAL : QueryIndexType.SORTED); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 98230adf5716a..87b559a96f1f4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -684,15 +684,15 @@ private void initializeCache(GridCacheContext cctx, QuerySchema schema) th QueryTypeDescriptorImpl oldDesc = tblTypMap.put(desc.tableName(), desc); if (oldDesc != null) - throw new IgniteException("Duplicate table name [tblName=" + desc.tableName() + - ", type1=" + desc.name() + ", type2=" + oldDesc.name() + ']'); + throw new IgniteException("Duplicate table name [cache=" + space + + ", tblName=" + desc.tableName() + ", type1=" + desc.name() + ", type2=" + oldDesc.name() + ']'); for (String idxName : desc.indexes().keySet()) { oldDesc = idxTypMap.put(idxName, desc); if (oldDesc != null) - throw new IgniteException("Duplicate index name [idxName=" + idxName + - ", type1=" + desc.name() + ", type2=" + oldDesc.name() + ']'); + throw new IgniteException("Duplicate index name [cache=" + space + + ", idxName=" + idxName + ", type1=" + desc.name() + ", type2=" + oldDesc.name() + ']'); } } @@ -1289,7 +1289,7 @@ private void registerCache0(String space, GridCacheContext cctx, Collectio QueryIndexDescriptorImpl oldIdx = idxs.putIfAbsent(idxKey, idx); if (oldIdx != null) { - throw new IgniteException("Duplicate index name [space=" + space + + throw new IgniteException("Duplicate index name [cache=" + space + ", idxName=" + idx.name() + ", existingTable=" + oldIdx.typeDescriptor().tableName() + ", table=" + desc.tableName() + ']'); } diff --git a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java index c5c2b4738b140..f57d573b44848 100644 --- a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java +++ b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java @@ -179,7 +179,7 @@ private void createDynamicIndex(IgniteCache cache, QueryEntity entity, QueryInde GridStringBuilder sb = new SB("CREATE ") .a(spatial ? "SPATIAL " : "") .a("INDEX ") - .a(idx.getName()) + .a("\"" + idx.getName() + "\"") .a(" ON ") .a(QueryUtils.tableName(entity)) .a(" ("); @@ -333,7 +333,7 @@ private void checkGeo(boolean dynamic) throws Exception { assertTrue("__ explain: " + plan, plan.contains("coords_idx")); if (dynamic) - cache.query(new SqlFieldsQuery("DROP INDEX coords_idx")).getAll(); + cache.query(new SqlFieldsQuery("DROP INDEX \"EnemyCamp_coords_idx\"")).getAll(); } finally { cache.destroy(); @@ -582,8 +582,8 @@ private void checkDistributedQuery() throws ParseException { } } - final SqlFieldsQuery query = new SqlFieldsQuery("select e._val, c._val from \"enemy\".Enemy e, \"camp\".EnemyCamp c " + - "where e.campId = c._key and c.coords && ?").setArgs(lethalArea); + final SqlFieldsQuery query = new SqlFieldsQuery("select e._val, c._val from \"enemy\".Enemy e, " + + "\"camp\".EnemyCamp c where e.campId = c._key and c.coords && ?").setArgs(lethalArea); List> result = c1.query(query.setDistributedJoins(true)).getAll(); diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java index b40dd78551411..8c8828d1313f5 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java @@ -26,6 +26,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import java.util.concurrent.Callable; import javax.cache.CacheException; @@ -270,6 +271,8 @@ public void testCacheMetaData() throws Exception { assertNotNull("Indexes should be defined", indexes); assertEquals(2, indexes.size()); + Set idxFields = new HashSet<>(); + Iterator it = indexes.iterator(); Collection indFlds = it.next().fields(); @@ -279,7 +282,7 @@ public void testCacheMetaData() throws Exception { Iterator indFldIt = indFlds.iterator(); - assertEquals(indFldIt.next(), "AGE"); + idxFields.add(indFldIt.next()); indFlds = it.next().fields(); @@ -288,7 +291,10 @@ public void testCacheMetaData() throws Exception { indFldIt = indFlds.iterator(); - assertEquals(indFldIt.next(), "ORGID"); + idxFields.add(indFldIt.next()); + + assertTrue(idxFields.contains("AGE")); + assertTrue(idxFields.contains("ORGID")); } else if (orgCache.getName().equals(meta.cacheName())) { assertEquals("Invalid types size", 1, types.size()); diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DuplicateKeyValueClassesSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DuplicateKeyValueClassesSelfTest.java new file mode 100644 index 0000000000000..4ee884f6028aa --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DuplicateKeyValueClassesSelfTest.java @@ -0,0 +1,94 @@ +/* + * 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.index; + +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +import java.util.UUID; + +/** + * Make sure that cache can start with multiple key-value classes of the same type. + */ +@SuppressWarnings("unchecked") +public class DuplicateKeyValueClassesSelfTest extends GridCommonAbstractTest { + /** Cache name. */ + private static final String CACHE_NAME = "cache"; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + startGrid(0); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + grid(0).destroyCache(CACHE_NAME); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** + * Test duplicate key class. + * + * @throws Exception If failed. + */ + public void testDuplicateKeyClass() throws Exception { + CacheConfiguration ccfg = new CacheConfiguration() + .setName(CACHE_NAME) + .setIndexedTypes(UUID.class, Clazz1.class, UUID.class, Clazz2.class); + + grid(0).createCache(ccfg); + } + + /** + * Test duplicate value class. + * + * @throws Exception If failed. + */ + public void testDuplicateValueClass() throws Exception { + CacheConfiguration ccfg = new CacheConfiguration() + .setName(CACHE_NAME) + .setIndexedTypes(UUID.class, Clazz1.class, String.class, Clazz1.class); + + grid(0).createCache(ccfg); + } + + /** + * Class 1. + */ + private static class Clazz1 { + /** ID. */ + @QuerySqlField(index = true) + int id; + } + + /** + * Class 2. + */ + private static class Clazz2 { + /** ID. */ + @QuerySqlField(index = true) + int id; + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java index 9acf7618743a9..28b2d339dd693 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java @@ -81,6 +81,7 @@ import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedFieldsQuerySelfTest; import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQueryP2PDisabledSelfTest; import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQuerySelfTest; +import org.apache.ignite.internal.processors.cache.index.DuplicateKeyValueClassesSelfTest; import org.apache.ignite.internal.processors.cache.index.H2DynamicIndexAtomicPartitionedNearSelfTest; import org.apache.ignite.internal.processors.cache.index.H2DynamicIndexAtomicPartitionedSelfTest; import org.apache.ignite.internal.processors.cache.index.H2DynamicIndexAtomicReplicatedSelfTest; @@ -130,8 +131,7 @@ public static TestSuite suite() throws Exception { IgniteTestSuite suite = new IgniteTestSuite("Ignite Cache Queries Test Suite"); // Misc tests. - // TODO: Enable when IGNITE-1094 is fixed. - // suite.addTest(new TestSuite(QueryEntityValidationSelfTest.class)); + suite.addTest(new TestSuite(DuplicateKeyValueClassesSelfTest.class)); // Dynamic index create/drop tests. suite.addTest(new TestSuite(SchemaExchangeSelfTest.class)); From 81d9dcb60d077c829af828a10a3250ed066c8ab1 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Tue, 25 Apr 2017 17:08:11 +0300 Subject: [PATCH 126/311] ignite-5068 : Fixed possible NPE in detectLostPartitions(...) --- .../cache/distributed/dht/GridDhtPartitionTopologyImpl.java | 3 +++ 1 file changed, 3 insertions(+) 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 fcc934f619b91..19c5f3acd7fac 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 @@ -1481,6 +1481,9 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) lock.writeLock().lock(); try { + if (node2part == null) + return false; + int parts = cctx.affinity().partitions(); Set lost = new HashSet<>(parts); From 30ba7698dfcf2e9eb4376afb704e0ab615ffde5e Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Tue, 25 Apr 2017 18:48:07 +0300 Subject: [PATCH 127/311] fixing isFirstJvm method --- .../apache/ignite/testframework/junits/GridAbstractTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java index af623daaaf295..f2fa36908844d 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java @@ -1665,7 +1665,8 @@ protected boolean isMultiJvm() { * @return {@code True} if the name of the grid indicates that it was the first started (on this JVM). */ protected boolean isFirstGrid(String igniteInstanceName) { - return "0".equals(igniteInstanceName.substring(getTestIgniteInstanceName().length())); + return igniteInstanceName != null && igniteInstanceName.startsWith(getTestIgniteInstanceName()) && + "0".equals(igniteInstanceName.substring(getTestIgniteInstanceName().length())); } /** From 401b7a0b76e8372841e4170b14de75da7f45fa76 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Tue, 25 Apr 2017 19:30:03 +0300 Subject: [PATCH 128/311] ignite-5068 : Fixed diff calculation, added workaround when requested affVer != diffFromAffinityVer. --- .../dht/GridDhtPartitionTopologyImpl.java | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) 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 19c5f3acd7fac..80b83faf34745 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 @@ -55,6 +55,8 @@ import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.T2; +import org.apache.ignite.internal.util.typedef.T3; +import org.apache.ignite.internal.util.typedef.T4; import org.apache.ignite.internal.util.typedef.X; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; @@ -957,6 +959,28 @@ else if (loc != null && state == RENTING && cctx.allowFastEviction()) List nodes = null; + if (!topVer.equals(diffFromAffinityVer)) { + System.out.println("??? node2part"); + + nodes = new ArrayList<>(); + + nodes.addAll(affNodes); + + for (Map.Entry entry : node2part.entrySet()) { + GridDhtPartitionState state = entry.getValue().get(p); + + ClusterNode n = cctx.discovery().node(entry.getKey()); + + if (n != null && state != null && (state == MOVING || state == OWNING || state == RENTING) && !nodes.contains(n) + && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) { + nodes.add(n); + } + + } + + return nodes; + } + Collection diffIds = diffFromAffinity.get(p); if (!F.isEmpty(diffIds)) { @@ -1012,7 +1036,10 @@ private List nodes(int p, // Node IDs can be null if both, primary and backup, nodes disappear. List nodes = new ArrayList<>(); - for (UUID id : allIds) { + for (UUID id : node2part.keySet()) { + if (topVer.topologyVersion() > 0 && !allIds.contains(id)) + continue; + if (hasState(p, id, state, states)) { ClusterNode n = cctx.discovery().node(id); @@ -1196,16 +1223,18 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) Set diffIds = diffFromAffinity.get(p); - if (e0.getValue() != MOVING && e0.getValue() != OWNING && e0.getValue() != RENTING && - !affAssignment.getIds(p).contains(partMap.nodeId())) { + if ((e0.getValue() == MOVING || e0.getValue() == OWNING || e0.getValue() == RENTING) && + !affAssignment.getIds(p).contains(e.getKey())) { + if (diffIds == null) diffFromAffinity.put(p, diffIds = U.newHashSet(3)); - if (diffIds.add(partMap.nodeId())) + if (diffIds.add(e.getKey())) { diffFromAffinitySize++; + } } else { - if (diffIds != null && diffIds.remove(partMap.nodeId())) { + if (diffIds != null && diffIds.remove(e.getKey())) { diffFromAffinitySize--; if (diffIds.isEmpty()) @@ -1834,6 +1863,19 @@ private long updateLocal(int p, GridDhtPartitionState state, long updateSeq) { map.updateSequence(updateSeq, topVer); map.put(p, state); + + if (state == MOVING || state == OWNING || state == RENTING) { + AffinityAssignment assignment = cctx.affinity().assignment(diffFromAffinityVer); + + if (!assignment.getIds(p).contains(cctx.localNodeId())) { + Set diffIds = diffFromAffinity.get(p); + + if (diffIds == null) + diffFromAffinity.put(p, diffIds = U.newHashSet(3)); + + diffIds.add(cctx.localNodeId()); + } + } } return updateSeq; From a011f575e7fa974f33d6adbf18a3a4fa32c197d0 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Thu, 27 Apr 2017 16:50:00 +0300 Subject: [PATCH 129/311] ignite-5068 : WIP. --- .../affinity/GridAffinityAssignmentCache.java | 2 + .../dht/GridClientPartitionTopology.java | 2 +- .../dht/GridDhtPartitionTopology.java | 2 +- .../dht/GridDhtPartitionTopologyImpl.java | 86 ++++++++++++------- .../GridDhtPartitionsExchangeFuture.java | 4 - 5 files changed, 57 insertions(+), 39 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java index 2399493b12788..9570e620d8e23 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java @@ -199,6 +199,8 @@ public void initialize(AffinityTopologyVersion topVer, List> a } } + ctx.cache().context().cacheContext(cacheId).topology().onAffinityInitialized(assignment); + onHistoryAdded(assignment); } 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 e026feac102b5..4dc6b5fda68d9 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 @@ -755,7 +755,7 @@ public long lastUpdateSequence() { } /** {@inheritDoc} */ - @Override public void onAffinityInitialized(Map> assignment) { + @Override public void onAffinityInitialized(AffinityAssignment assignment) { // TODO } 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 b47321e9aee06..c1933c6b7b5e2 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 @@ -313,5 +313,5 @@ public GridDhtPartitionMap update(@Nullable GridDhtPartitionExchangeId exchId, */ public void setOwners(int p, Set owners, boolean updateSeq); - public void onAffinityInitialized(Map> assignment); + public void onAffinityInitialized(AffinityAssignment assignment); } 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 80b83faf34745..11f4e8316a515 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 @@ -959,8 +959,8 @@ else if (loc != null && state == RENTING && cctx.allowFastEviction()) List nodes = null; - if (!topVer.equals(diffFromAffinityVer)) { - System.out.println("??? node2part"); + if (topVer.compareTo(diffFromAffinityVer) != 0) { + System.out.println("??? node2part [topVer=" + topVer + ", diffVer=" + diffFromAffinityVer + "]"); nodes = new ArrayList<>(); @@ -1012,6 +1012,53 @@ else if (loc != null && state == RENTING && cctx.allowFastEviction()) } } + private void rebuildDiff(AffinityAssignment affAssignment) { + assert lock.isWriteLockedByCurrentThread(); + + if (node2part == null) + return; + + for (Map.Entry e : node2part.entrySet()) { + UUID nodeId = e.getKey(); + + for (Map.Entry e0 : e.getValue().entrySet()) { + int p0 = e0.getKey(); + + GridDhtPartitionState state = e0.getValue(); + + Set ids = diffFromAffinity.get(p0); + + if ((state == MOVING || state == OWNING || state == RENTING) && !affAssignment.getIds(p0).contains(nodeId)) { + if (ids == null) + diffFromAffinity.put(p0, ids = U.newHashSet(3)); + + ids.add(nodeId); + } + else { + if (ids != null) + ids.remove(nodeId); + } + } + } + +// Collection affNodes = F.nodeIds(cctx.discovery().cacheAffinityNodes(cctx.cacheId(), affAssignment.topologyVersion())); +// +// for (Map.Entry> e : diffFromAffinity.entrySet()) { +// int p = e.getKey(); +// +// Iterator iter = e.getValue().iterator(); +// +// while (iter.hasNext()) { +// UUID nodeId = iter.next(); +// +// if (!affNodes.contains(nodeId) || affAssignment.getIds(p).contains(nodeId)) +// iter.remove(); +// } +// } + + diffFromAffinityVer = affAssignment.topologyVersion(); + } + /** * @param p Partition. * @param topVer Topology version ({@code -1} for all nodes). @@ -1247,7 +1294,7 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) diffFromAffinityVer = affVer; if (diffFromAffinitySize > 0) - U.error(log, "??? S diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); + U.error(log, "??? F diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); } boolean changed = false; @@ -1440,7 +1487,7 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) diffFromAffinityVer = affVer; if (diffFromAffinitySize > 0) - U.error(log, "??? diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); + U.error(log, "??? S diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); } if (!affVer.equals(AffinityTopologyVersion.NONE) && affVer.compareTo(topVer) >= 0) { @@ -1467,38 +1514,11 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) } /** {@inheritDoc} */ - @Override public void onAffinityInitialized(Map> assignment) { + @Override public void onAffinityInitialized(AffinityAssignment assignment) { lock.writeLock().lock(); try { - AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); - - if (diffFromAffinityVer.compareTo(affVer) >= 0) - return; - - for (Map.Entry e : node2part.entrySet()) { - UUID nodeId = e.getKey(); - - for (Map.Entry e0 : e.getValue().entrySet()) { - int p = e0.getKey(); - GridDhtPartitionState state = e0.getValue(); - - Set ids = diffFromAffinity.get(p); - - if ((state == MOVING || state == OWNING || state == RENTING) && !assignment.get(p).contains(nodeId)) { - if (ids == null) - diffFromAffinity.put(p, ids = U.newHashSet(3)); - - ids.add(nodeId); - } - else { - if (ids != null) - ids.remove(nodeId); - } - } - } - - diffFromAffinityVer = affVer; + rebuildDiff(assignment); } finally { lock.writeLock().unlock(); 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 119ceeec3df24..f6827ab9e90d1 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 @@ -1486,10 +1486,6 @@ private void onAffinityInitialized(IgniteInternalFuture>> assignmentChange = fut.get(); - for (Map.Entry>> e : assignmentChange.entrySet()) { - cctx.cacheContext(e.getKey()).topology().onAffinityInitialized(e.getValue()); - } - GridDhtPartitionsFullMessage m = createPartitionsMessage(null, false); CacheAffinityChangeMessage msg = new CacheAffinityChangeMessage(exchId, m, assignmentChange); From c67dc6f81c3c69fd58c3440fd8ab524edbd18d8d Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Fri, 28 Apr 2017 14:06:01 +0300 Subject: [PATCH 130/311] ignite-5068 : WIP. --- .../affinity/GridAffinityAssignmentCache.java | 2 - .../dht/GridDhtPartitionTopologyImpl.java | 67 ++++++++++--------- .../GridDhtPartitionsExchangeFuture.java | 16 +++++ 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java index 9570e620d8e23..2399493b12788 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java @@ -199,8 +199,6 @@ public void initialize(AffinityTopologyVersion topVer, List> a } } - ctx.cache().context().cacheContext(cacheId).topology().onAffinityInitialized(assignment); - onHistoryAdded(assignment); } 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 11f4e8316a515..898cb559468a0 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 @@ -959,7 +959,7 @@ else if (loc != null && state == RENTING && cctx.allowFastEviction()) List nodes = null; - if (topVer.compareTo(diffFromAffinityVer) != 0) { + if (!topVer.equals(diffFromAffinityVer)) { System.out.println("??? node2part [topVer=" + topVer + ", diffVer=" + diffFromAffinityVer + "]"); nodes = new ArrayList<>(); @@ -1018,44 +1018,44 @@ private void rebuildDiff(AffinityAssignment affAssignment) { if (node2part == null) return; - for (Map.Entry e : node2part.entrySet()) { - UUID nodeId = e.getKey(); +// for (Map.Entry e : node2part.entrySet()) { +// UUID nodeId = e.getKey(); +// +// for (Map.Entry e0 : e.getValue().entrySet()) { +// int p0 = e0.getKey(); +// +// GridDhtPartitionState state = e0.getValue(); +// +// Set ids = diffFromAffinity.get(p0); +// +// if ((state == MOVING || state == OWNING || state == RENTING) && !affAssignment.getIds(p0).contains(nodeId)) { +// if (ids == null) +// diffFromAffinity.put(p0, ids = U.newHashSet(3)); +// +// ids.add(nodeId); +// } +// else { +// if (ids != null) +// ids.remove(nodeId); +// } +// } +// } - for (Map.Entry e0 : e.getValue().entrySet()) { - int p0 = e0.getKey(); + Collection affNodes = F.nodeIds(cctx.discovery().cacheAffinityNodes(cctx.cacheId(), affAssignment.topologyVersion())); - GridDhtPartitionState state = e0.getValue(); + for (Map.Entry> e : diffFromAffinity.entrySet()) { + int p = e.getKey(); - Set ids = diffFromAffinity.get(p0); + Iterator iter = e.getValue().iterator(); - if ((state == MOVING || state == OWNING || state == RENTING) && !affAssignment.getIds(p0).contains(nodeId)) { - if (ids == null) - diffFromAffinity.put(p0, ids = U.newHashSet(3)); + while (iter.hasNext()) { + UUID nodeId = iter.next(); - ids.add(nodeId); - } - else { - if (ids != null) - ids.remove(nodeId); - } + if (!affNodes.contains(nodeId) || affAssignment.getIds(p).contains(nodeId)) + iter.remove(); } } -// Collection affNodes = F.nodeIds(cctx.discovery().cacheAffinityNodes(cctx.cacheId(), affAssignment.topologyVersion())); -// -// for (Map.Entry> e : diffFromAffinity.entrySet()) { -// int p = e.getKey(); -// -// Iterator iter = e.getValue().iterator(); -// -// while (iter.hasNext()) { -// UUID nodeId = iter.next(); -// -// if (!affNodes.contains(nodeId) || affAssignment.getIds(p).contains(nodeId)) -// iter.remove(); -// } -// } - diffFromAffinityVer = affAssignment.topologyVersion(); } @@ -1433,7 +1433,7 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); - if (diffFromAffinityVer.compareTo(affVer) <= 0) { + if (diffFromAffinityVer.compareTo(affVer) <= 0 && false) { AffinityAssignment affAssignment = cctx.affinity().assignment(affVer); int diffFromAffinitySize = 0; @@ -1518,7 +1518,8 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) lock.writeLock().lock(); try { - rebuildDiff(assignment); + if (assignment.topologyVersion().compareTo(diffFromAffinityVer) >= 0) + rebuildDiff(assignment); } finally { lock.writeLock().unlock(); 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 f6827ab9e90d1..328f73061bbbb 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 @@ -1215,6 +1215,22 @@ private void sendPartitions(ClusterNode oldestNode) { if (exchangeOnChangeGlobalState && err == null) cctx.kernalContext().state().onExchangeDone(); + if (err == null && realExchange) { +// if (discoEvt.type() == EVT_NODE_JOINED || discoEvt.type() == EVT_NODE_LEFT || discoEvt.type() == EVT_NODE_FAILED || (discoEvt instanceof DiscoveryCustomEvent && ((DiscoveryCustomEvent)discoEvt).customMessage() instanceof CacheAffinityChangeMessage)) { + for (GridCacheContext cacheCtx : cctx.cacheContexts()) { + if (cacheCtx.isLocal()) + continue; + + try { + cacheCtx.topology().onAffinityInitialized(cacheCtx.affinity().assignment(topologyVersion())); + } + catch (Exception e) { + System.out.println("???"); + } + } +// } + } + if (super.onDone(res, err) && realExchange) { if (log.isDebugEnabled()) log.debug("Completed partition exchange [localNode=" + cctx.localNodeId() + ", exchange= " + this + From cc528344169ab89453ad376a3ee8ff2b56a7513f Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Fri, 28 Apr 2017 15:48:30 +0300 Subject: [PATCH 131/311] ignite-5068 : WIP. --- .../dht/GridDhtPartitionTopologyImpl.java | 68 +++++++++---------- .../GridDhtPartitionsExchangeFuture.java | 13 ++-- 2 files changed, 38 insertions(+), 43 deletions(-) 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 898cb559468a0..6d776d2fabcd8 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 @@ -987,7 +987,7 @@ else if (loc != null && state == RENTING && cctx.allowFastEviction()) HashSet affIds = affAssignment.getIds(p); for (UUID nodeId : diffIds) { -// assert !affIds.contains(nodeId); + assert !affIds.contains(nodeId); if (!affIds.contains(nodeId) && hasState(p, nodeId, OWNING, MOVING, RENTING)) { ClusterNode n = cctx.discovery().node(nodeId); @@ -1018,44 +1018,46 @@ private void rebuildDiff(AffinityAssignment affAssignment) { if (node2part == null) return; -// for (Map.Entry e : node2part.entrySet()) { -// UUID nodeId = e.getKey(); -// -// for (Map.Entry e0 : e.getValue().entrySet()) { -// int p0 = e0.getKey(); -// -// GridDhtPartitionState state = e0.getValue(); -// -// Set ids = diffFromAffinity.get(p0); -// -// if ((state == MOVING || state == OWNING || state == RENTING) && !affAssignment.getIds(p0).contains(nodeId)) { -// if (ids == null) -// diffFromAffinity.put(p0, ids = U.newHashSet(3)); -// -// ids.add(nodeId); -// } -// else { -// if (ids != null) -// ids.remove(nodeId); -// } -// } -// } + diffFromAffinity.clear(); - Collection affNodes = F.nodeIds(cctx.discovery().cacheAffinityNodes(cctx.cacheId(), affAssignment.topologyVersion())); + for (Map.Entry e : node2part.entrySet()) { + UUID nodeId = e.getKey(); - for (Map.Entry> e : diffFromAffinity.entrySet()) { - int p = e.getKey(); + for (Map.Entry e0 : e.getValue().entrySet()) { + int p0 = e0.getKey(); - Iterator iter = e.getValue().iterator(); + GridDhtPartitionState state = e0.getValue(); - while (iter.hasNext()) { - UUID nodeId = iter.next(); + Set ids = diffFromAffinity.get(p0); - if (!affNodes.contains(nodeId) || affAssignment.getIds(p).contains(nodeId)) - iter.remove(); + if ((state == MOVING || state == OWNING || state == RENTING) && !affAssignment.getIds(p0).contains(nodeId)) { + if (ids == null) + diffFromAffinity.put(p0, ids = U.newHashSet(3)); + + ids.add(nodeId); + } + else { + if (ids != null) + ids.remove(nodeId); + } } } +// Collection affNodes = F.nodeIds(cctx.discovery().cacheAffinityNodes(cctx.cacheId(), affAssignment.topologyVersion())); +// +// for (Map.Entry> e : diffFromAffinity.entrySet()) { +// int p = e.getKey(); +// +// Iterator iter = e.getValue().iterator(); +// +// while (iter.hasNext()) { +// UUID nodeId = iter.next(); +// +// if (!affNodes.contains(nodeId) || affAssignment.getIds(p).contains(nodeId)) +// iter.remove(); +// } +// } + diffFromAffinityVer = affAssignment.topologyVersion(); } @@ -1433,7 +1435,7 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); - if (diffFromAffinityVer.compareTo(affVer) <= 0 && false) { + if (exchId == null) { AffinityAssignment affAssignment = cctx.affinity().assignment(affVer); int diffFromAffinitySize = 0; @@ -1484,8 +1486,6 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) } } - diffFromAffinityVer = affVer; - if (diffFromAffinitySize > 0) U.error(log, "??? S diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); } 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 328f73061bbbb..9eb7e5096b86c 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 @@ -1216,18 +1216,13 @@ private void sendPartitions(ClusterNode oldestNode) { cctx.kernalContext().state().onExchangeDone(); if (err == null && realExchange) { -// if (discoEvt.type() == EVT_NODE_JOINED || discoEvt.type() == EVT_NODE_LEFT || discoEvt.type() == EVT_NODE_FAILED || (discoEvt instanceof DiscoveryCustomEvent && ((DiscoveryCustomEvent)discoEvt).customMessage() instanceof CacheAffinityChangeMessage)) { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) - continue; +// if (discoEvt.type() == EVT_NODE_LEFT || discoEvt.type() == EVT_NODE_FAILED || (discoEvt instanceof DiscoveryCustomEvent && ((DiscoveryCustomEvent)discoEvt).customMessage() instanceof CacheAffinityChangeMessage)) { + for (GridCacheContext cacheCtx : cctx.cacheContexts()) { + if (cacheCtx.isLocal()) + continue; - try { cacheCtx.topology().onAffinityInitialized(cacheCtx.affinity().assignment(topologyVersion())); } - catch (Exception e) { - System.out.println("???"); - } - } // } } From 03586bc7c75e4b18aba9bdb875e5a7d7a77de062 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Fri, 28 Apr 2017 16:01:12 +0300 Subject: [PATCH 132/311] ignite-5068 : WIP. --- .../dht/GridDhtPartitionTopologyImpl.java | 77 +++++++++++-------- 1 file changed, 46 insertions(+), 31 deletions(-) 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 6d776d2fabcd8..e0fe50e308f2b 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 @@ -82,6 +82,9 @@ /** Flag to control amount of output for full map. */ private static final boolean FULL_MAP_DEBUG = false; + /** */ + private static final boolean FAST_DIFF_REBUILD = false; + /** */ private static final Long ZERO = 0L; @@ -989,7 +992,7 @@ else if (loc != null && state == RENTING && cctx.allowFastEviction()) for (UUID nodeId : diffIds) { assert !affIds.contains(nodeId); - if (!affIds.contains(nodeId) && hasState(p, nodeId, OWNING, MOVING, RENTING)) { + if (hasState(p, nodeId, OWNING, MOVING, RENTING)) { ClusterNode n = cctx.discovery().node(nodeId); if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) { @@ -1020,43 +1023,46 @@ private void rebuildDiff(AffinityAssignment affAssignment) { diffFromAffinity.clear(); - for (Map.Entry e : node2part.entrySet()) { - UUID nodeId = e.getKey(); + if (FAST_DIFF_REBUILD) { + Collection affNodes = F.nodeIds(cctx.discovery().cacheAffinityNodes(cctx.cacheId(), affAssignment.topologyVersion())); - for (Map.Entry e0 : e.getValue().entrySet()) { - int p0 = e0.getKey(); + for (Map.Entry> e : diffFromAffinity.entrySet()) { + int p = e.getKey(); - GridDhtPartitionState state = e0.getValue(); + Iterator iter = e.getValue().iterator(); - Set ids = diffFromAffinity.get(p0); + while (iter.hasNext()) { + UUID nodeId = iter.next(); - if ((state == MOVING || state == OWNING || state == RENTING) && !affAssignment.getIds(p0).contains(nodeId)) { - if (ids == null) - diffFromAffinity.put(p0, ids = U.newHashSet(3)); - - ids.add(nodeId); - } - else { - if (ids != null) - ids.remove(nodeId); + if (!affNodes.contains(nodeId) || affAssignment.getIds(p).contains(nodeId)) + iter.remove(); } } } + else { + for (Map.Entry e : node2part.entrySet()) { + UUID nodeId = e.getKey(); -// Collection affNodes = F.nodeIds(cctx.discovery().cacheAffinityNodes(cctx.cacheId(), affAssignment.topologyVersion())); -// -// for (Map.Entry> e : diffFromAffinity.entrySet()) { -// int p = e.getKey(); -// -// Iterator iter = e.getValue().iterator(); -// -// while (iter.hasNext()) { -// UUID nodeId = iter.next(); -// -// if (!affNodes.contains(nodeId) || affAssignment.getIds(p).contains(nodeId)) -// iter.remove(); -// } -// } + for (Map.Entry e0 : e.getValue().entrySet()) { + int p0 = e0.getKey(); + + GridDhtPartitionState state = e0.getValue(); + + Set ids = diffFromAffinity.get(p0); + + if ((state == MOVING || state == OWNING || state == RENTING) && !affAssignment.getIds(p0).contains(nodeId)) { + if (ids == null) + diffFromAffinity.put(p0, ids = U.newHashSet(3)); + + ids.add(nodeId); + } + else { + if (ids != null) + ids.remove(nodeId); + } + } + } + } diffFromAffinityVer = affAssignment.topologyVersion(); } @@ -1924,7 +1930,16 @@ private void removeNode(UUID nodeId) { else node2part = new GridDhtPartitionFullMap(node2part, node2part.updateSequence()); - node2part.remove(nodeId); + GridDhtPartitionMap partMap = node2part.remove(nodeId); + + if (partMap != null) { + for (Integer p : partMap.keySet()) { + Set diffIds = diffFromAffinity.get(p); + + if (diffIds != null) + diffIds.remove(nodeId); + } + } consistencyCheck(); } From 8374f6c919c3ba46a8138af7638a000e4c22778b Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Fri, 28 Apr 2017 17:02:03 +0300 Subject: [PATCH 133/311] ignite-5068 : First stable solution. --- .../dht/GridDhtPartitionTopologyImpl.java | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) 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 e0fe50e308f2b..baf52a6ea8722 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 @@ -55,8 +55,6 @@ import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.T2; -import org.apache.ignite.internal.util.typedef.T3; -import org.apache.ignite.internal.util.typedef.T4; import org.apache.ignite.internal.util.typedef.X; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; @@ -64,8 +62,6 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT; import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST; -import static org.apache.ignite.events.EventType.EVT_NODE_FAILED; -import static org.apache.ignite.events.EventType.EVT_NODE_LEFT; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.LOST; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.MOVING; @@ -83,7 +79,7 @@ private static final boolean FULL_MAP_DEBUG = false; /** */ - private static final boolean FAST_DIFF_REBUILD = false; + private static final boolean FAST_DIFF_REBUILD = true; /** */ private static final Long ZERO = 0L; @@ -1021,8 +1017,6 @@ private void rebuildDiff(AffinityAssignment affAssignment) { if (node2part == null) return; - diffFromAffinity.clear(); - if (FAST_DIFF_REBUILD) { Collection affNodes = F.nodeIds(cctx.discovery().cacheAffinityNodes(cctx.cacheId(), affAssignment.topologyVersion())); @@ -1441,7 +1435,7 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); - if (exchId == null) { + if (affVer.compareTo(diffFromAffinityVer) >= 0) { AffinityAssignment affAssignment = cctx.affinity().assignment(affVer); int diffFromAffinitySize = 0; @@ -1492,6 +1486,8 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) } } + diffFromAffinityVer = affVer; + if (diffFromAffinitySize > 0) U.error(log, "??? S diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); } @@ -2126,7 +2122,27 @@ private void updateRebalanceVersion(List> aff) { if (affNodes.isEmpty()) continue; - if (!F.isEmpty(diffFromAffinity.get(i))) + Set owners = U.newHashSet(affNodes.size()); + + for (ClusterNode node : affNodes) { + if (hasState(i, node.id(), OWNING)) + owners.add(node); + } + + Set diff = diffFromAffinity.get(i); + + if (diff != null) { + for (UUID nodeId : diff) { + if (hasState(i, nodeId, OWNING)) { + ClusterNode node = cctx.discovery().node(nodeId); + + if (node != null) + owners.add(node); + } + } + } + + if (affNodes.size() != owners.size() || !owners.containsAll(affNodes)) return; } From 3a10973e3555ea1bd23f59da84b936db1b656755 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Fri, 28 Apr 2017 17:34:31 +0300 Subject: [PATCH 134/311] ignite-5068 : Optimized loop. --- .../cache/distributed/dht/GridDhtPartitionTopologyImpl.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 baf52a6ea8722..b5a8bef8326bf 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 @@ -1085,10 +1085,7 @@ private List nodes(int p, // Node IDs can be null if both, primary and backup, nodes disappear. List nodes = new ArrayList<>(); - for (UUID id : node2part.keySet()) { - if (topVer.topologyVersion() > 0 && !allIds.contains(id)) - continue; - + for (UUID id : allIds) { if (hasState(p, id, state, states)) { ClusterNode n = cctx.discovery().node(id); From 0955308b8832200aa8ac86c84e967c1d50ebefb1 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Fri, 28 Apr 2017 18:19:50 +0300 Subject: [PATCH 135/311] ignite-5068 : Cosmetic changes. --- .../dht/GridClientPartitionTopology.java | 2 +- .../dht/GridDhtPartitionTopology.java | 6 +- .../dht/GridDhtPartitionTopologyImpl.java | 105 +++++++++--------- .../GridDhtPartitionsExchangeFuture.java | 12 +- 4 files changed, 65 insertions(+), 60 deletions(-) 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 4dc6b5fda68d9..d55dda733e6a8 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 @@ -755,7 +755,7 @@ public long lastUpdateSequence() { } /** {@inheritDoc} */ - @Override public void onAffinityInitialized(AffinityAssignment assignment) { + @Override public void onExchangeDone(AffinityAssignment assignment) { // TODO } 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 c1933c6b7b5e2..d2f1822da2163 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 @@ -313,5 +313,9 @@ public GridDhtPartitionMap update(@Nullable GridDhtPartitionExchangeId exchId, */ public void setOwners(int p, Set owners, boolean updateSeq); - public void onAffinityInitialized(AffinityAssignment assignment); + /** + * Callback on exchange done. + * @param assignment New affinity assignment. + */ + public void onExchangeDone(AffinityAssignment assignment); } 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 b5a8bef8326bf..69cd7344b5a5f 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 @@ -1011,56 +1011,6 @@ else if (loc != null && state == RENTING && cctx.allowFastEviction()) } } - private void rebuildDiff(AffinityAssignment affAssignment) { - assert lock.isWriteLockedByCurrentThread(); - - if (node2part == null) - return; - - if (FAST_DIFF_REBUILD) { - Collection affNodes = F.nodeIds(cctx.discovery().cacheAffinityNodes(cctx.cacheId(), affAssignment.topologyVersion())); - - for (Map.Entry> e : diffFromAffinity.entrySet()) { - int p = e.getKey(); - - Iterator iter = e.getValue().iterator(); - - while (iter.hasNext()) { - UUID nodeId = iter.next(); - - if (!affNodes.contains(nodeId) || affAssignment.getIds(p).contains(nodeId)) - iter.remove(); - } - } - } - else { - for (Map.Entry e : node2part.entrySet()) { - UUID nodeId = e.getKey(); - - for (Map.Entry e0 : e.getValue().entrySet()) { - int p0 = e0.getKey(); - - GridDhtPartitionState state = e0.getValue(); - - Set ids = diffFromAffinity.get(p0); - - if ((state == MOVING || state == OWNING || state == RENTING) && !affAssignment.getIds(p0).contains(nodeId)) { - if (ids == null) - diffFromAffinity.put(p0, ids = U.newHashSet(3)); - - ids.add(nodeId); - } - else { - if (ids != null) - ids.remove(nodeId); - } - } - } - } - - diffFromAffinityVer = affAssignment.topologyVersion(); - } - /** * @param p Partition. * @param topVer Topology version ({@code -1} for all nodes). @@ -1513,7 +1463,7 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) } /** {@inheritDoc} */ - @Override public void onAffinityInitialized(AffinityAssignment assignment) { + @Override public void onExchangeDone(AffinityAssignment assignment) { lock.writeLock().lock(); try { @@ -1525,6 +1475,59 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) } } + /** + * @param affAssignment New affinity assignment. + */ + private void rebuildDiff(AffinityAssignment affAssignment) { + assert lock.isWriteLockedByCurrentThread(); + + if (node2part == null) + return; + + if (FAST_DIFF_REBUILD) { + Collection affNodes = F.nodeIds(cctx.discovery().cacheAffinityNodes(cctx.cacheId(), affAssignment.topologyVersion())); + + for (Map.Entry> e : diffFromAffinity.entrySet()) { + int p = e.getKey(); + + Iterator iter = e.getValue().iterator(); + + while (iter.hasNext()) { + UUID nodeId = iter.next(); + + if (!affNodes.contains(nodeId) || affAssignment.getIds(p).contains(nodeId)) + iter.remove(); + } + } + } + else { + for (Map.Entry e : node2part.entrySet()) { + UUID nodeId = e.getKey(); + + for (Map.Entry e0 : e.getValue().entrySet()) { + int p0 = e0.getKey(); + + GridDhtPartitionState state = e0.getValue(); + + Set ids = diffFromAffinity.get(p0); + + if ((state == MOVING || state == OWNING || state == RENTING) && !affAssignment.getIds(p0).contains(nodeId)) { + if (ids == null) + diffFromAffinity.put(p0, ids = U.newHashSet(3)); + + ids.add(nodeId); + } + else { + if (ids != null) + ids.remove(nodeId); + } + } + } + } + + diffFromAffinityVer = affAssignment.topologyVersion(); + } + /** {@inheritDoc} */ @Override public boolean detectLostPartitions(DiscoveryEvent discoEvt) { lock.writeLock().lock(); 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 ec67db479e734..5b027a9e3c25b 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 @@ -1216,14 +1216,12 @@ private void sendPartitions(ClusterNode oldestNode) { cctx.kernalContext().state().onExchangeDone(); if (err == null && realExchange) { -// if (discoEvt.type() == EVT_NODE_LEFT || discoEvt.type() == EVT_NODE_FAILED || (discoEvt instanceof DiscoveryCustomEvent && ((DiscoveryCustomEvent)discoEvt).customMessage() instanceof CacheAffinityChangeMessage)) { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) - continue; + for (GridCacheContext cacheCtx : cctx.cacheContexts()) { + if (cacheCtx.isLocal()) + continue; - cacheCtx.topology().onAffinityInitialized(cacheCtx.affinity().assignment(topologyVersion())); - } -// } + cacheCtx.topology().onExchangeDone(cacheCtx.affinity().assignment(topologyVersion())); + } } if (super.onDone(res, err) && realExchange) { From 0fd7ca27ebd3e144f64f11417558f691eb4d62f2 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 2 May 2017 18:55:34 +0300 Subject: [PATCH 136/311] ignite-gg-12163 dirty replace snapshot and and grid shared manager --- .../database/IgniteCacheDatabaseSharedManager.java | 14 +++++++++++--- .../preloader/GridDhtPartitionsExchangeFuture.java | 9 ++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 2ed392ac86f97..1fde564613e0e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -165,6 +165,13 @@ private void startMemoryPolicies() { } } + /** + * + */ + public Object getSnapshotMgr() { + return null; + } + /** * @param dbCfg Database config. */ @@ -535,9 +542,10 @@ public void onCacheStop(GridCacheContext cctx) { * @return Snapshot creation init future or {@code null} if snapshot is not available. * @throws IgniteCheckedException If failed. */ - @Nullable public IgniteInternalFuture startLocalSnapshotOperation(UUID initiatorNodeId, - SnapshotOperation snapshotOperation) - throws IgniteCheckedException { + @Nullable public IgniteInternalFuture startLocalSnapshotOperation( + UUID initiatorNodeId, + SnapshotOperation snapshotOperation + ) throws IgniteCheckedException { return null; } 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 a06e7156d21b4..3155cbaf32f1c 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 @@ -950,10 +950,13 @@ private void distributedExchange() throws IgniteCheckedException { /** * @param snapOpMsg Snapshot operation message. */ - private void startLocalSnasphotOperation(StartSnapshotOperationAckDiscoveryMessage snapOpMsg + private void startLocalSnasphotOperation( + StartSnapshotOperationAckDiscoveryMessage snapOpMsg ) throws IgniteCheckedException { - IgniteInternalFuture fut = cctx.database() - .startLocalSnapshotOperation(snapOpMsg.initiatorNodeId(), snapOpMsg.snapshotOperation()); + IgniteInternalFuture fut = cctx.database().startLocalSnapshotOperation( + snapOpMsg.initiatorNodeId(), + snapOpMsg.snapshotOperation() + ); if (fut != null) fut.get(); From 6d22a91e412943d80c440e89b52d808ac0d5fdb1 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 3 May 2017 11:59:27 +0300 Subject: [PATCH 137/311] ignite-gg-12163 code style refactoring --- .../internal/pagemem/snapshot/SnapshotOperation.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index 93054ec9199da..f6b1c89f0bd5f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -53,7 +53,13 @@ public class SnapshotOperation implements Serializable { * @param msg * @param extraParam Additional parameter. */ - public SnapshotOperation(SnapshotOperationType type, long snapshotId, Set cacheNames, String msg, Object extraParam) { + public SnapshotOperation( + SnapshotOperationType type, + long snapshotId, + Set cacheNames, + String msg, + Object extraParam + ) { this.type = type; this.snapshotId = snapshotId; this.cacheNames = cacheNames; From 28edd6171f273eb3e039d42135cae2fb89a4e3df Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Wed, 3 May 2017 15:04:10 +0300 Subject: [PATCH 138/311] GG-12118: Tests affected by DDL implementation --- .../processors/database/IgniteDbPutGetAbstractTest.java | 4 ++-- .../database/IgniteDbSingleNodeWithIndexingPutGetTest.java | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java index cfb9b087268ab..16349ab0c4a37 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java @@ -444,7 +444,7 @@ public void testPutGetMultipleObjects() throws Exception { String plan = cache.query(new SqlFieldsQuery( "explain select lval from dbvalue where ival >= 5000 and ival < 7000")).getAll().get(0).get(0).toString(); - assertTrue(plan, plan.contains("iVal_idx")); + assertTrue(plan, plan.contains("IVAL_IDX")); } assertTrue(cache.localSize(CachePeekMode.BACKUP) >= 0); @@ -604,7 +604,7 @@ public void testMultithreadedPut() throws Exception { String plan = cache.query(new SqlFieldsQuery( "explain select lval from dbvalue where ival >= 5000 and ival < 7000")).getAll().get(0).get(0).toString(); - assertTrue(plan, plan.contains("iVal_idx")); + assertTrue(plan, plan.contains("IVAL_IDX")); } } diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodeWithIndexingPutGetTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodeWithIndexingPutGetTest.java index 75a424ada2272..46a24a034e375 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodeWithIndexingPutGetTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodeWithIndexingPutGetTest.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.Random; import java.util.TreeMap; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicLong; import org.apache.ignite.IgniteCache; import org.apache.ignite.cache.CacheAtomicityMode; @@ -85,9 +86,7 @@ public void testGroupIndexes2() { Map bs = new TreeMap<>(); Map cs = new TreeMap<>(); - Random rnd = BPlusTree.rnd; - - assertNotNull(rnd); + Random rnd = ThreadLocalRandom.current(); for (int i = 0; i < cnt; i++) { Abc abc = new Abc(rnd.nextInt(2000), rnd.nextInt(100), rnd.nextInt(5)); From c0da061f90dcd56f345c3c70a49bd82f0f5e6111 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 3 May 2017 15:29:21 +0300 Subject: [PATCH 139/311] ignite-gg-12163 refactoring updates, move copy page to snapshot manager --- .../pagemem/snapshot/SnapshotOperation.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index f6b1c89f0bd5f..39a76dd59d6bd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -135,6 +135,7 @@ public static File getMovingPathParameter(SnapshotOperation op) { return (File)op.extraParameter(); } + /** {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -149,18 +150,21 @@ public static File getMovingPathParameter(SnapshotOperation op) { return false; if (msg != null ? !msg.equals(operation.msg) : operation.msg != null) return false; + return extraParam != null ? extraParam.equals(operation.extraParam) : operation.extraParam == null; } + /** {@inheritDoc} */ @Override public int hashCode() { - int result = type.hashCode(); - result = 31 * result + (int)(snapshotId ^ (snapshotId >>> 32)); - result = 31 * result + (msg != null ? msg.hashCode() : 0); - result = 31 * result + (extraParam != null ? extraParam.hashCode() : 0); - return result; + int res = type.hashCode(); + res = 31 * res + (int)(snapshotId ^ (snapshotId >>> 32)); + res = 31 * res + (msg != null ? msg.hashCode() : 0); + res = 31 * res + (extraParam != null ? extraParam.hashCode() : 0); + return res; } + /** {@inheritDoc} */ @Override public String toString() { return "SnapshotOperation{" + "type=" + type + From c4deff8f59ba39802502284acb3a40c745e13844 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Wed, 3 May 2017 19:32:51 +0300 Subject: [PATCH 140/311] fixing issue with message id --- .../processors/cache/GridChangeGlobalStateMessageResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java index 62b67b17640d5..0d04ccb8fd11a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java @@ -157,7 +157,7 @@ public Throwable getError() { /** {@inheritDoc} */ @Override public short directType() { - return -46; + return -45; } /** {@inheritDoc} */ From 0a1939b97fcb4197d3fbbeafc9d69ad62c2e83e7 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Thu, 4 May 2017 15:15:36 +0300 Subject: [PATCH 141/311] first compilable version of PDS code --- .../apache/ignite/IgniteSystemProperties.java | 16 + .../configuration/IgniteConfiguration.java | 24 + .../PersistenceConfiguration.java | 289 ++ .../processors/cache/GridCacheProcessor.java | 9 + .../cache/GridCacheSharedContext.java | 17 +- .../database/IgniteCacheSnapshotManager.java | 119 + .../hashmap/GridCacheTestContext.java | 2 + modules/pds/pom.xml | 140 + .../cache/database/DbCheckpointListener.java | 21 + .../cache/database/FullPageIdIterable.java | 248 ++ .../GridCacheDatabaseSharedManager.java | 3266 +++++++++++++++++ .../cache/database/PageIdIterable.java | 24 + .../cache/database/file/FilePageStore.java | 520 +++ .../database/file/FilePageStoreManager.java | 568 +++ .../database/pagemem/EvictCandidate.java | 60 + .../database/pagemem/FullPageIdTable.java | 534 +++ .../cache/database/pagemem/PageMemoryEx.java | 131 + .../database/pagemem/PageMemoryImpl.java | 2301 ++++++++++++ .../wal/ByteBufferBackedDataInput.java | 23 + .../wal/ByteBufferBackedDataInputImpl.java | 156 + .../cache/database/wal/FileInput.java | 432 +++ .../cache/database/wal/FileWALPointer.java | 93 + .../wal/FileWriteAheadLogManager.java | 2310 ++++++++++++ .../cache/database/wal/RecordSerializer.java | 34 + .../database/wal/SegmentEofException.java | 20 + ...IgniteDataIntegrityViolationException.java | 24 + .../cache/database/wal/crc/PureJavaCrc32.java | 638 ++++ .../database/wal/record/HeaderRecord.java | 33 + .../wal/serializer/RecordV1Serializer.java | 1624 ++++++++ pom.xml | 1 + 30 files changed, 13676 insertions(+), 1 deletion(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/configuration/PersistenceConfiguration.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java create mode 100644 modules/pds/pom.xml create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/DbCheckpointListener.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterable.java create mode 100755 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PageIdIterable.java create mode 100755 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java create mode 100755 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/EvictCandidate.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java create mode 100755 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInput.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInputImpl.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/SegmentEofException.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/IgniteDataIntegrityViolationException.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/PureJavaCrc32.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.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 21d0e1b58ce31..8e52785d59c37 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -588,6 +588,22 @@ public final class IgniteSystemProperties { */ public static final String IGNITE_INDEXING_DISCOVERY_HISTORY_SIZE = "IGNITE_INDEXING_DISCOVERY_HISTORY_SIZE"; + /** + * Skip CRC calculation flag. + */ + public static final String IGNITE_PDS_SKIP_CRC = "IGNITE_PDS_SKIP_CRC"; + + /** + * WAL rebalance threshold. + */ + public static final String IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY = + "IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY"; + + /** + * WAL rebalance threshold. + */ + public static final String IGNITE_WAL_REBALANCE_THRESHOLD = "IGNITE_WAL_REBALANCE_THRESHOLD"; + /** Returns true for system properties only avoiding sending sensitive information. */ private static final IgnitePredicate> PROPS_FILTER = new IgnitePredicate>() { @Override public boolean apply(final Map.Entry entry) { diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index fe08ddf2d1d43..97fe3121d16af 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -443,6 +443,9 @@ public class IgniteConfiguration { /** Page memory configuration. */ private MemoryConfiguration memCfg; + /** Persistence store configuration. */ + private PersistenceConfiguration pstCfg; + /** Active on start flag. */ private boolean activeOnStart = DFLT_ACTIVE_ON_START; @@ -2111,6 +2114,27 @@ public IgniteConfiguration setMemoryConfiguration(MemoryConfiguration memCfg) { return this; } + /** + * Gets persistence configuration. + * + * @return Persistence configuration. + */ + public PersistenceConfiguration getPersistenceConfiguration() { + return pstCfg; + } + + /** + * Sets persistence configuration. + * + * @param pstCfg Persistence configuration. + * @return {@code this} for chaining. + */ + public IgniteConfiguration setPersistenceConfiguration(PersistenceConfiguration pstCfg) { + this.pstCfg = pstCfg; + + return this; + } + /** * Gets flag indicating whether the cluster will be active on start. If cluster is not active on start, * there will be no cache partition map exchanges performed until the cluster is activated. This should diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/PersistenceConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/PersistenceConfiguration.java new file mode 100644 index 0000000000000..2918d92aeaf02 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/configuration/PersistenceConfiguration.java @@ -0,0 +1,289 @@ +/* + * 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.configuration; + +import java.io.Serializable; + +/** + * Configures persistence module of Ignite node. + */ +public class PersistenceConfiguration implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + public static final int DFLT_CHECKPOINT_FREQ = 180000; + + /** Lock default wait time, 10 sec. */ + public static final int DFLT_LOCK_WAIT_TIME = 10 * 1000; + + /** */ + @SuppressWarnings("UnnecessaryBoxing") + public static final Long DFLT_CHECKPOINT_PAGE_BUFFER_SIZE = new Long(256L * 1024 * 1024); + + /** Default number of checkpoint threads. */ + public static final int DFLT_CHECKPOINT_THREADS = 1; + + /** */ + private static final int DFLT_WAL_HISTORY_SIZE = 20; + + /** */ + public static final int DFLT_WAL_SEGMENTS = 10; + + /** */ + private static final int DFLT_WAL_SEGMENT_SIZE = 64 * 1024 * 1024; + + /** */ + private String persistenceStorePath; + + /** Checkpoint frequency. */ + private long checkpointFreq = DFLT_CHECKPOINT_FREQ; + + /** Lock wait time. */ + private int lockWaitTime = DFLT_LOCK_WAIT_TIME; + + /** */ + private Long checkpointPageBufSize = DFLT_CHECKPOINT_PAGE_BUFFER_SIZE; + + /** */ + private int checkpointThreads = DFLT_CHECKPOINT_THREADS; + + /** */ + private int walHistSize = DFLT_WAL_HISTORY_SIZE; + + /** Number of work WAL segments. */ + private int walSegments = DFLT_WAL_SEGMENTS; + + /** Number of WAL segments to keep. */ + private int walSegmentSize = DFLT_WAL_SEGMENT_SIZE; + + /** Write-ahead log persistence path. */ + private String walStorePath; + + /** Write-ahead log archive path. */ + private String walArchivePath; + + /** + * + */ + public String getPersistenceStorePath() { + return persistenceStorePath; + } + + /** + * @param persistenceStorePath Persistence store path. + */ + public PersistenceConfiguration setPersistenceStorePath(String persistenceStorePath) { + this.persistenceStorePath = persistenceStorePath; + + return this; + } + + /** + * Gets checkpoint frequency. + * + * @return Checkpoint frequency in milliseconds. + */ + public long getCheckpointFrequency() { + return checkpointFreq <= 0 ? DFLT_CHECKPOINT_FREQ : checkpointFreq; + } + + /** + * Sets checkpoint frequency. This is a minimal interval at which memory state will be written to a disk + * storage. If update rate is high, checkpoints can happen more frequently. + * + * @param checkpointFreq Checkpoint frequency in milliseconds. + * @return {@code this} for chaining. + */ + public PersistenceConfiguration setCheckpointFrequency(long checkpointFreq) { + this.checkpointFreq = checkpointFreq; + + return this; + } + + /** + * Time out in second, while wait and try get file lock for start persist manager. + * + * @return Time for wait. + */ + public int getLockWaitTime() { + return lockWaitTime; + } + + /** + * Time out in milliseconds, while wait and try get file lock for start persist manager. + * + * @param lockWaitTime Lock wait time. + * @return {@code this} for chaining. + */ + public PersistenceConfiguration setLockWaitTime(int lockWaitTime) { + this.lockWaitTime = lockWaitTime; + + return this; + } + + + + /** + * Gets amount of memory allocated for checkpoint temporary buffer. This buffer is used to create temporary + * copies of pages when checkpoint is in progress. + * + * @return Checkpoint page buffer size. + */ + public Long getCheckpointPageBufferSize() { + return checkpointPageBufSize; + } + + /** + * Sets amount of memory allocated for checkpoint temporary buffer. This buffer is used to create temporary + * copies of pages when checkpoint is in progress. + * + * @param checkpointPageBufSize Checkpoint page buffer size. + * @return {@code this} for chaining. + */ + public PersistenceConfiguration setCheckpointPageBufferSize(long checkpointPageBufSize) { + this.checkpointPageBufSize = checkpointPageBufSize; + + return this; + } + + + + /** + * Gets number of checkpoint threads to run. + * + * @return Number of checkpoint threads. + */ + public int getCheckpointThreads() { + return checkpointThreads; + } + + /** + * Sets number of checkpoint threads. + * + * @param checkpointThreads Number of checkpoint threads. + * @return {@code this} for chaining. + */ + public PersistenceConfiguration setCheckpointThreads(int checkpointThreads) { + this.checkpointThreads = checkpointThreads; + + return this; + } + + /** + * Gets the number checkpoints to keep in WAL history. + * + * @return Number of WAL segments to keep after the checkpoint is finished. + */ + public int getWalHistorySize() { + return walHistSize <= 0 ? DFLT_WAL_HISTORY_SIZE : walHistSize; + } + + /** + * Sets the number of checkpoints to keep in WAL history. + * + * @param walHistSize Number of WAL segments to keep after the checkpoint is finished. + * @return {@code this} for chaining. + */ + public PersistenceConfiguration setWalHistorySize(int walHistSize) { + this.walHistSize = walHistSize; + + return this; + } + + /** + * Gets the number of Write Ahead Log segments to work with. Write-ahead log is written over a fixed number + * of preallocated file segments of fixed size. This parameter sets the number of these segments. + * + * @return Number of work WAL segments. + */ + public int getWalSegments() { + return walSegments <= 0 ? DFLT_WAL_SEGMENTS : walSegments; + } + + /** + * Sets then number of work Write Ahead Log segments. + * + * @param walSegments Number of work WAL segments. + * @return {@code this} for chaining. + */ + public PersistenceConfiguration setWalSegments(int walSegments) { + this.walSegments = walSegments; + + return this; + } + + /** + * @return WAL segment size. + */ + public int getWalSegmentSize() { + return walSegmentSize <= 0 ? DFLT_WAL_SEGMENT_SIZE : walSegmentSize; + } + + /** + * @param walSegmentSize WAL segment size. + * @return {@code this} for chaining. + */ + public PersistenceConfiguration setWalSegmentSize(int walSegmentSize) { + this.walSegmentSize = walSegmentSize; + + return this; + } + + /** + * Gets write-ahead log persistence path. If this path is relative, it will be resolved relative to + * Ignite work directory. + * + * @return Write-ahead log persistence path, absolute or relative to Ignite work directory. + */ + public String getWalStorePath() { + return walStorePath; + } + + /** + * Sets write-ahead log persistence path. + * + * @param walStorePath Write-ahead log persistence path, absolute or relative to Ignite work directory. + * @return {@code this} for chaining. + */ + public PersistenceConfiguration setWalStorePath(String walStorePath) { + this.walStorePath = walStorePath; + + return this; + } + + /** + * Gets write-ahead log archive path. Full WAL segments will be copied to this directory before reuse. + * + * @return WAL archive directory. + */ + public String getWalArchivePath() { + return walArchivePath; + } + + /** + * Sets write-ahead log archive path. Full WAL segments will be copied to this directory before reuse. + * + * @param walArchivePath WAL archive directory. + * @return {@code this} for chaining. + */ + public PersistenceConfiguration setWalArchivePath(String walArchivePath) { + this.walArchivePath = walArchivePath; + + return this; + } +} 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 e104b14b85041..1bdada24867bf 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 @@ -60,6 +60,7 @@ import org.apache.ignite.configuration.TransactionConfiguration; import org.apache.ignite.events.EventType; import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager; import org.apache.ignite.internal.processors.query.QuerySchema; import org.apache.ignite.internal.processors.query.QueryUtils; import org.apache.ignite.internal.processors.query.schema.message.SchemaAbstractDiscoveryMessage; @@ -1325,6 +1326,8 @@ private void stopCache(GridCacheAdapter cache, boolean cancel, boolean des ctx.kernalContext().cache().context().database().onCacheStop(ctx); + ctx.kernalContext().cache().context().snapshot().onCacheStop(ctx); + U.stopLifecycleAware(log, lifecycleAwares(cache.configuration(), ctx.store().configuredStore())); if (log.isInfoEnabled()) @@ -2127,6 +2130,11 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, if (dbMgr == null) dbMgr = new IgniteCacheDatabaseSharedManager(); + IgniteCacheSnapshotManager snpMgr = ctx.plugins().createComponent(IgniteCacheSnapshotManager.class); + + if (snpMgr == null) + snpMgr = new IgniteCacheSnapshotManager(); + IgnitePageStoreManager pageStoreMgr = ctx.plugins().createComponent(IgnitePageStoreManager.class); IgniteWriteAheadLogManager walMgr = ctx.plugins().createComponent(IgniteWriteAheadLogManager.class); @@ -2144,6 +2152,7 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, pageStoreMgr, walMgr, dbMgr, + snpMgr, depMgr, exchMgr, topMgr, 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 34bb321f83590..e1348bce656b0 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 @@ -43,6 +43,7 @@ import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal; import org.apache.ignite.internal.processors.cache.jta.CacheJtaManagerAdapter; import org.apache.ignite.internal.processors.cache.store.CacheStoreManager; @@ -105,6 +106,9 @@ public class GridCacheSharedContext { /** Database manager. */ private IgniteCacheDatabaseSharedManager dbMgr; + /** Snp manager. */ + private IgniteCacheSnapshotManager snpMgr; + /** Page store manager. */ private IgnitePageStoreManager pageStoreMgr; @@ -171,6 +175,7 @@ public GridCacheSharedContext( IgnitePageStoreManager pageStoreMgr, IgniteWriteAheadLogManager walMgr, IgniteCacheDatabaseSharedManager dbMgr, + IgniteCacheSnapshotManager snpMgr, GridCacheDeploymentManager depMgr, GridCachePartitionExchangeManager exchMgr, CacheAffinitySharedManager affMgr, @@ -181,7 +186,7 @@ public GridCacheSharedContext( ) { this.kernalCtx = kernalCtx; - setManagers(mgrs, txMgr, jtaMgr, verMgr, mvccMgr, pageStoreMgr, walMgr, dbMgr, depMgr, exchMgr, affMgr, ioMgr, ttlMgr); + setManagers(mgrs, txMgr, jtaMgr, verMgr, mvccMgr, pageStoreMgr, walMgr, dbMgr, snpMgr, depMgr, exchMgr, affMgr, ioMgr, ttlMgr); this.storeSesLsnrs = storeSesLsnrs; @@ -280,6 +285,7 @@ void onReconnected() throws IgniteCheckedException { pageStoreMgr, walMgr, dbMgr, + snpMgr, new GridCacheDeploymentManager(), new GridCachePartitionExchangeManager(), affMgr, @@ -327,6 +333,7 @@ private void setManagers(List> mgrs, IgnitePageStoreManager pageStoreMgr, IgniteWriteAheadLogManager walMgr, IgniteCacheDatabaseSharedManager dbMgr, + IgniteCacheSnapshotManager snpMgr, GridCacheDeploymentManager depMgr, GridCachePartitionExchangeManager exchMgr, CacheAffinitySharedManager affMgr, @@ -338,6 +345,7 @@ private void setManagers(List> mgrs, this.pageStoreMgr = add(mgrs, pageStoreMgr); this.walMgr = add(mgrs, walMgr); this.dbMgr = add(mgrs, dbMgr); + this.snpMgr = add(mgrs, snpMgr); this.jtaMgr = add(mgrs, jtaMgr); this.depMgr = add(mgrs, depMgr); this.exchMgr = add(mgrs, exchMgr); @@ -556,6 +564,13 @@ public IgniteCacheDatabaseSharedManager database() { return dbMgr; } + /** + * @return Snapshot manager. + */ + public IgniteCacheSnapshotManager snapshot() { + return snpMgr; + } + /** * @return Page store manager. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java new file mode 100644 index 0000000000000..0721d10418484 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java @@ -0,0 +1,119 @@ +package org.apache.ignite.internal.processors.cache.database; + +import java.nio.ByteBuffer; +import java.util.NavigableMap; +import java.util.UUID; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; +import org.apache.ignite.internal.util.typedef.T2; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class IgniteCacheSnapshotManager extends GridCacheSharedManagerAdapter { + /** Snapshot started lock filename. */ + public static final String SNAPSHOT_RESTORE_STARTED_LOCK_FILENAME = "snapshot-started.loc"; + + /** + * @param initiatorNodeId Initiator node id. + * @param snapshotOperation Snapshot operation. + */ + @Nullable public IgniteInternalFuture startLocalSnapshotOperation( + UUID initiatorNodeId, + SnapshotOperation snapshotOperation + ) throws IgniteCheckedException { + return null; + } + + /** + * @param cacheId Cache id. + * @param pageMem Page Memory. + */ + public long getLastSuccessfulSnapshotTagForCache(int cacheId, PageMemory pageMem) { + return 0; + } + + /** + * @param cacheId Cache ID. + * @param pageMem Page Memory. + * @return Next snapshot ID for given cache. + */ + public long getNextSnapshotTagForCache(int cacheId, PageMemory pageMem) { + return 0; + } + + /** + * + */ + public void restoreState() throws IgniteCheckedException { + + } + + /** + * @param fullId Full id. + */ + public void onPageEvict(FullPageId fullId) throws IgniteCheckedException { + + } + + + /** + * @param snapOp current snapshot operation. + * + * @return {@code true} if next operation must be snapshot, {@code false} if checkpoint must be executed. + */ + public boolean onMarkCheckPointBegin( + SnapshotOperation snapOp, + NavigableMap, T2> map + ){ + return false; + } + + /** + * + */ + public void onCheckPointBegin() { + + } + + /** + * + */ + public void beforeCheckpointPageWritten() { + + } + + /** + * + */ + public void afterCheckpointPageWritten() { + + } + + /** + * @param fullId Full id. + */ + public void checkPointCopyPage(FullPageId fullId) { + + } + + /** + * @param fullId Full id. + */ + public void checkPointBufferCopyPage(FullPageId fullId, ByteBuffer tmpWriteBuf) { + + } + + /** + * @param cctx Cctx. + */ + public void onCacheStop(GridCacheContext cctx) { + + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java index 0f4aa870dd9d1..cf698ce2cf2b1 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java @@ -35,6 +35,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheTtlManager; import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; import org.apache.ignite.internal.processors.cache.GridCacheSharedTtlCleanupManager; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager; import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager; import org.apache.ignite.internal.processors.cache.dr.GridOsCacheDrManager; import org.apache.ignite.internal.processors.cache.jta.CacheNoopJtaManager; @@ -68,6 +69,7 @@ public GridCacheTestContext(GridTestKernalContext ctx) throws Exception { null, null, new IgniteCacheDatabaseSharedManager(), + new IgniteCacheSnapshotManager(), new GridCacheDeploymentManager(), new GridCachePartitionExchangeManager(), new CacheAffinitySharedManager(), diff --git a/modules/pds/pom.xml b/modules/pds/pom.xml new file mode 100644 index 0000000000000..c3bcec6d0fb21 --- /dev/null +++ b/modules/pds/pom.xml @@ -0,0 +1,140 @@ + + + + + + + 4.0.0 + + + org.apache.ignite + ignite-parent + 1 + ../../parent + + + ignite-pds + 2.0.0-SNAPSHOT + + + 2.4 + 1.4.8 + 14.0.1 + 3.20.0-GA + + + + + org.apache.ignite + ignite-core + ${project.version} + + + + commons-io + commons-io + ${common.io.version} + test + + + + org.apache.ignite + ignite-spring + ${project.version} + test + + + + log4j + log4j + test + + + + com.thoughtworks.xstream + xstream + ${xstream.version} + test + + + + org.apache.ignite + ignite-indexing + ${project.version} + test + + + + org.apache.ignite + ignite-indexing + ${project.version} + test-jar + test + + + + org.apache.ignite + ignite-core + ${project.version} + test-jar + test + + + + com.google.guava + guava + ${guava.version} + test + + + + org.javassist + javassist + ${javassist.version} + test + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + test-jar + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + false + + + + + diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/DbCheckpointListener.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/DbCheckpointListener.java new file mode 100644 index 0000000000000..b23743b062de0 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/DbCheckpointListener.java @@ -0,0 +1,21 @@ +package org.apache.ignite.internal.processors.cache.database; + +import java.util.Map; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.util.typedef.T2; + +/** + * + */ +public interface DbCheckpointListener { + public interface Context { + public boolean nextSnapshot(); + + public Map, T2> partitionStatMap(); + } + + /** + * @throws IgniteCheckedException If failed. + */ + public void onCheckpointBegin(Context context) throws IgniteCheckedException; +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterable.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterable.java new file mode 100644 index 0000000000000..f20acfa66573f --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterable.java @@ -0,0 +1,248 @@ +package org.apache.ignite.internal.processors.cache.database; + +import java.io.Serializable; +import java.util.Comparator; +import java.util.Iterator; +import java.util.Map; +import java.util.NavigableMap; +import java.util.NoSuchElementException; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.util.typedef.T2; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +class FullPageIdIterable implements PageIdIterable { + /** (cacheId, partId) -> (lastAllocatedIndex, count) */ + private final NavigableMap, T2> pageCounts; + + /** */ + private final int totalPageCount; + + /** + * @param pageCounts Page counts map. + */ + FullPageIdIterable(NavigableMap, T2> pageCounts) { + this.pageCounts = pageCounts; + + int sum = 0; + + for (T2 t2 : pageCounts.values()) + sum += t2.get2(); + + totalPageCount = sum; + } + + /** + * @return Total page count. + */ + public int size() { + return totalPageCount; + } + + /** + * @param fullId Full page ID. + * @return Total page count below the given page ID. + */ + public int sizeBelow(FullPageId fullId) { + if (fullId == null) + return 0; + + T2 key = new T2<>(fullId.cacheId(), PageIdUtils.partId(fullId.pageId())); + + int sum = 0; + + for (T2 t2 : pageCounts.headMap(key).values()) + sum += t2.get2(); + + sum += PageIdUtils.pageIndex(fullId.pageId()); + + return sum; + } + + /** {@inheritDoc} */ + @Override public Iterator iterator() { + return new FullPageIdIterator(); + } + + /** + * + * @param fullId Full page ID. + * @return {@code True} if contains given ID. + */ + @Override public boolean contains(FullPageId fullId) { + int cacheId = fullId.cacheId(); + int partId = PageIdUtils.partId(fullId.pageId()); + long idx = PageIdUtils.pageIndex(fullId.pageId()); + + T2 cnt = pageCounts.get(new T2<>(cacheId, partId)); + + return cnt != null && cnt.get2() > idx; + } + + /** + * + * @param fullId Full page ID. + * @return Next element after the provided one. If provided element is the last one, returns null. + * If provided element isn't contained, returns the first element. + */ + @Override @Nullable public FullPageId next(@Nullable FullPageId fullId) { + if (isEmpty()) + return null; + + if (fullId == null) { + T2 firstKey = pageCounts.firstKey(); + + return new FullPageId(PageIdUtils.pageId(firstKey.get2(), (byte)0, 0), firstKey.get1()); + } + + T2 key = new T2<>(fullId.cacheId(), PageIdUtils.partId(fullId.pageId())); + int idx = PageIdUtils.pageIndex(fullId.pageId()); + + T2 cnt = pageCounts.get(key); + + if (cnt == null || idx > cnt.get2() - 1) { + T2 firstKey = pageCounts.firstKey(); + return new FullPageId(PageIdUtils.pageId(firstKey.get2(), (byte)0, 0), firstKey.get1()); + } + else if (idx == cnt.get2() - 1) { + NavigableMap, T2> tailMap = pageCounts.tailMap(key, false); + + if (tailMap.isEmpty()) + return null; + + T2 firstKey = tailMap.firstKey(); + + return new FullPageId(PageIdUtils.pageId(firstKey.get2(), (byte)0, 0), firstKey.get1()); + } + else + return new FullPageId(PageIdUtils.pageId(key.get2(), (byte)0, idx + 1), key.get1()); + } + + /** {@inheritDoc} */ + @Override public double progress(FullPageId current) { + if (pageCounts.isEmpty()) + return 1; + + if (current == null) + return 0; + + T2 key = new T2<>(current.cacheId(), PageIdUtils.partId(current.pageId())); + + return (double) pageCounts.headMap(key).size() / pageCounts.size(); + } + + /** + * + * @return {@code True} if empty. + */ + @Override public boolean isEmpty() { + return pageCounts.isEmpty(); + } + + /** + * + */ + private class FullPageIdIterator implements Iterator { + /** */ + private final Iterator, T2>> mapIter; + + /** */ + private Map.Entry, T2> currEntry; + + /** */ + private int currIdx; + + /** */ + private FullPageId next; + + /** */ + private FullPageIdIterator() { + mapIter = pageCounts.entrySet().iterator(); + + advance(); + } + + /** + * + */ + private void advance() { + if (currEntry == null && !mapIter.hasNext()) + return; + else if (currEntry == null && mapIter.hasNext()) + currEntry = mapIter.next(); + else if (currIdx < currEntry.getValue().get2() - 1) + currIdx++; + else if (mapIter.hasNext()) { + currEntry = mapIter.next(); + + currIdx = 0; + } + else { + next = null; + + return; + } + + int cacheId = currEntry.getKey().get1(); + int partId = currEntry.getKey().get2(); + + long pageId = PageIdUtils.pageId(partId, (byte)0, currIdx); + + next = new FullPageId(pageId, cacheId); + } + + /** {@inheritDoc} */ + @Override public boolean hasNext() { + return next != null; + } + + /** {@inheritDoc} */ + @Override public FullPageId next() { + FullPageId next = this.next; + + if (next == null) + throw new NoSuchElementException(); + + advance(); + + return next; + } + + /** {@inheritDoc} */ + @Override public void remove() { + throw new UnsupportedOperationException("remove"); + } + } +} + +/** + * + */ +class FullPageIdIterableComparator implements Comparator>, Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + static final FullPageIdIterableComparator INSTANCE = new FullPageIdIterableComparator(); + + /** {@inheritDoc} */ + @Override public int compare(T2 o1, T2 o2) { + if (o1.get1() < o2.get1()) + return -1; + + if (o1.get1() > o2.get1()) + return 1; + + if (o1.get2() < o2.get2()) + return -1; + + if (o1.get2() > o2.get2()) + return 1; + + return 0; + } +} + diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java new file mode 100755 index 0000000000000..99fbcff8f5544 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -0,0 +1,3266 @@ +package org.apache.ignite.internal.processors.cache.database; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.nio.channels.OverlappingFileLockException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.NavigableMap; +import java.util.Set; +import java.util.TreeMap; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataPageEvictionMode; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.events.DiscoveryEvent; +import org.apache.ignite.events.EventType; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.mem.DirectMemoryProvider; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdAllocator; +import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.pagemem.PageUtils; +import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; +import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; +import org.apache.ignite.internal.pagemem.store.PageStore; +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.pagemem.wal.StorageException; +import org.apache.ignite.internal.pagemem.wal.WALIterator; +import org.apache.ignite.internal.pagemem.wal.WALPointer; +import org.apache.ignite.internal.pagemem.wal.record.CacheState; +import org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord; +import org.apache.ignite.internal.pagemem.wal.record.DataEntry; +import org.apache.ignite.internal.pagemem.wal.record.DataRecord; +import org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord; +import org.apache.ignite.internal.pagemem.wal.record.PageSnapshot; +import org.apache.ignite.internal.pagemem.wal.record.WALRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateLastAllocatedIndex; +import org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.TrackingPageDeltaRecord; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.ClusterState; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionMetaIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; +import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.database.wal.FileWALPointer; +import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; +import org.apache.ignite.internal.processors.port.GridPortRecord; +import org.apache.ignite.internal.util.GridConcurrentHashSet; +import org.apache.ignite.internal.util.GridMultiCollectionWrapper; +import org.apache.ignite.internal.util.GridUnsafe; +import org.apache.ignite.internal.util.future.CountDownFuture; +import org.apache.ignite.internal.util.future.GridFutureAdapter; +import org.apache.ignite.internal.util.lang.GridInClosure3X; +import org.apache.ignite.internal.util.typedef.CI1; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.P3; +import org.apache.ignite.internal.util.typedef.T2; +import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.SB; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.internal.util.worker.GridWorker; +import org.apache.ignite.lang.IgniteBiTuple; +import org.apache.ignite.lang.IgniteInClosure; +import org.apache.ignite.thread.IgniteThread; +import org.jetbrains.annotations.Nullable; + +import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_WAL_REBALANCE_THRESHOLD; +import static org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler.isWalDeltaRecordNeeded; + +/** + * + */ +@SuppressWarnings({"unchecked", "NonPrivateFieldAccessedInSynchronizedContext"}) +public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedManager { + /** */ + public static final String IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC = "IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC"; + + /** Skip sync. */ + private final boolean skipSync = IgniteSystemProperties.getBoolean(IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC); + + /** */ + private boolean skipCrc = IgniteSystemProperties.getBoolean(IGNITE_PDS_SKIP_CRC, false); + + /** Checkpoint initiation delay after a partition has been scheduled for destroy. */ + private volatile long partDestroyCheckpointDelay = + IgniteSystemProperties.getLong(IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY, 30_000); + + /** */ + private final int ggWalRebalanceThreshold = IgniteSystemProperties.getInteger( + IGNITE_WAL_REBALANCE_THRESHOLD, 500_000); + + /** Checkpoint lock hold count. */ + private static final ThreadLocal CHECKPOINT_LOCK_HOLD_COUNT = new ThreadLocal() { + @Override protected Integer initialValue() { + return 0; + } + }; + + /** Assertion enabled. */ + private static final boolean ASSERTION_ENABLED = GridCacheDatabaseSharedManager.class.desiredAssertionStatus(); + + /** Checkpoint file name pattern. */ + private static final Pattern CP_FILE_NAME_PATTERN = Pattern.compile("(\\d+)-(.*)-(START|END)\\.bin"); + + /** */ + private static final FileFilter CP_FILE_FILTER = new FileFilter() { + @Override public boolean accept(File f) { + return CP_FILE_NAME_PATTERN.matcher(f.getName()).matches(); + } + }; + + /** */ + private static final Comparator CP_TS_COMPARATOR = new Comparator() { + /** {@inheritDoc} */ + @Override public int compare(File o1, File o2) { + Matcher m1 = CP_FILE_NAME_PATTERN.matcher(o1.getName()); + Matcher m2 = CP_FILE_NAME_PATTERN.matcher(o2.getName()); + + boolean s1 = m1.matches(); + boolean s2 = m2.matches(); + + assert s1 : "Failed to match CP file: " + o1.getAbsolutePath(); + assert s2 : "Failed to match CP file: " + o2.getAbsolutePath(); + + long ts1 = Long.parseLong(m1.group(1)); + long ts2 = Long.parseLong(m2.group(1)); + + int res = Long.compare(ts1, ts2); + + if (res == 0) { + CheckpointEntryType type1 = CheckpointEntryType.valueOf(m1.group(3)); + CheckpointEntryType type2 = CheckpointEntryType.valueOf(m2.group(3)); + + assert type1 != type2 : "o1=" + o1.getAbsolutePath() + ", o2=" + o2.getAbsolutePath(); + + res = type1 == CheckpointEntryType.START ? -1 : 1; + } + + return res; + } + }; + + /** Checkpoint thread. Needs to be volatile because it is created in exchange worker. */ + private volatile Checkpointer checkpointer; + + /** For testing only. */ + private volatile boolean checkpointsEnabled = true; + + /** For testing only. */ + private volatile GridFutureAdapter enableChangeApplied; + + /** */ + public ReentrantReadWriteLock checkpointLock = new ReentrantReadWriteLock(); + + /** */ + private long checkpointFreq; + + /** */ + private long checkpointPageBufSize; + + /** */ + private FilePageStoreManager storeMgr; + + /** */ + private File cpDir; + + /** */ + private volatile boolean printCheckpointStats = true; + + /** Database configuration. */ + private final PersistenceConfiguration dbCfg; + + /** */ + private final Collection lsnrs = new CopyOnWriteArrayList<>(); + + /** Checkpoint history. */ + private final CheckpointHistory checkpointHist = new CheckpointHistory(); + + /** */ + private boolean stopping; + + /** Tracking io. */ + private final TrackingPageIO trackingIO = TrackingPageIO.VERSIONS.latest(); + + /** Page meta io. */ + private final PageMetaIO pageMetaIO = PageMetaIO.VERSIONS.latest(); + + /** Meta io. */ + private static final PageMetaIO metaIO = PageMetaIO.VERSIONS.latest(); + + /** Checkpoint runner thread pool. */ + private ExecutorService asyncRunner; + + /** Buffer for the checkpoint threads. */ + private ThreadLocal threadBuf; + + /** */ + private final ConcurrentMap idxRebuildFuts = new ConcurrentHashMap<>(); + + /** Lock holder. */ + private FileLockHolder fileLockHolder; + + /** Lock wait time. */ + private final int lockWaitTime; + + /** */ + private Map>> reservedForExchange; + + /** */ + private final ConcurrentMap, T2> reservedForPreloading = new ConcurrentHashMap<>(); + + /** Snapshot manager. */ + private final IgniteCacheSnapshotManager snapshotMgr; + + /** + * @param cfg Ignite configuration. + */ + public GridCacheDatabaseSharedManager(IgniteConfiguration cfg) { + dbCfg = cfg.getPersistenceConfiguration(); + + assert dbCfg != null : "PageStore should not be created if persistence is disabled."; + + checkpointFreq = dbCfg.getCheckpointFrequency(); + + lockWaitTime = dbCfg.getLockWaitTime(); + + final int pageSize = cfg.getMemoryConfiguration().getPageSize(); + + threadBuf = new ThreadLocal() { + /** {@inheritDoc} */ + @Override protected ByteBuffer initialValue() { + ByteBuffer tmpWriteBuf = ByteBuffer.allocateDirect(pageSize); + + tmpWriteBuf.order(ByteOrder.nativeOrder()); + + return tmpWriteBuf; + } + }; + + snapshotMgr = cctx.snapshot(); + } + + /** + * + */ + public Checkpointer getCheckpointer() { + return checkpointer; + } + + /** + * + */ + @Override public IgniteCacheSnapshotManager getSnapshotMgr() { + return snapshotMgr; + } + + /** + * For test use only. + */ + public IgniteInternalFuture enableCheckpoints(boolean enable) { + GridFutureAdapter fut = new GridFutureAdapter<>(); + + enableChangeApplied = fut; + + checkpointsEnabled = enable; + + wakeupForCheckpoint("enableCheckpoints()"); + + return fut; + } + + /** {@inheritDoc} */ + @Override protected void start0() throws IgniteCheckedException { + initDataBase(); + + if (!cctx.kernalContext().clientNode()) { + IgnitePageStoreManager store = cctx.pageStore(); + + assert store instanceof FilePageStoreManager : "Invalid page store manager was created: " + store; + + storeMgr = (FilePageStoreManager)store; + + cpDir = Paths.get(storeMgr.workDir().getAbsolutePath(), "cp").toFile(); + + if (!U.mkdirs(cpDir)) + throw new IgniteCheckedException("Could not create directory for checkpoint metadata: " + cpDir); + + fileLockHolder = new FileLockHolder(storeMgr.workDir().getPath(), cctx.kernalContext(), log); + } + + snapshotMgr.start(cctx); + } + + /** + * + */ + @Override public void initDataBase() throws IgniteCheckedException { + Long cpBufSize = dbCfg.getCheckpointPageBufferSize(); + + if (dbCfg.getCheckpointThreads() > 1) + asyncRunner = new ThreadPoolExecutor( + dbCfg.getCheckpointThreads(), + dbCfg.getCheckpointThreads(), + 30L, + TimeUnit.SECONDS, + new LinkedBlockingQueue() + ); + + // Intentionally use identity comparison to check if configuration default has changed. + //noinspection NumberEquality + if (cpBufSize == PersistenceConfiguration.DFLT_CHECKPOINT_PAGE_BUFFER_SIZE) { + MemoryConfiguration memCfg = cctx.kernalContext().config().getMemoryConfiguration(); + + // Limit the checkpoint page buffer size by 2GB. + //TODO find max page cache and use it instead of memCfg.getPageCacheSize() (replaced with Long.MAX_VALUE now) + long adjusted = Math.min(Long.MAX_VALUE / 4, 2 * 1024L * 1024L * 1024L); + + if (memCfg != null && cpBufSize < adjusted) { + U.quietAndInfo(log, + "Default checkpoint page buffer size is too small, setting to an adjusted value: " + + U.readableSize(adjusted, false) + ); + + cpBufSize = adjusted; + } + } + + checkpointPageBufSize = cpBufSize; + + super.start0(); + } + + /** {@inheritDoc} */ + @Override protected void initPageMemoryDataStructures(MemoryConfiguration dbCfg) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override protected void onKernalStart0(boolean reconnect) throws IgniteCheckedException { + if (!reconnect && !cctx.kernalContext().clientNode() && cctx.kernalContext().state().active()) { + Collection cacheNames = new HashSet<>(); + + for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) + if (CU.isSystemCache(ccfg.getName())) { + storeMgr.initializeForCache(ccfg); + + cacheNames.add(ccfg.getName()); + } + + for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) + if (!CU.isSystemCache(ccfg.getName())) { + storeMgr.initializeForCache(ccfg); + + cacheNames.add(ccfg.getName()); + } + + for (String name : cctx.pageStore().savedCacheNames()) { + CacheConfiguration ccfg = cctx.pageStore().readConfiguration(name); + + if (ccfg != null && !cacheNames.contains(name)) + storeMgr.initializeForCache(ccfg); + } + + readCheckpointAndRestoreMemory(); + } + + snapshotMgr.onKernalStart(reconnect); + } + + /** {@inheritDoc} */ + @Override public void onActivate(GridKernalContext kctx) throws IgniteCheckedException { + super.onActivate(kctx); + + if (log.isDebugEnabled()) + log.debug("Activate database manager [id=" + cctx.localNodeId() + + " topVer=" + cctx.discovery().topologyVersionEx() + " ]"); + + if (!cctx.kernalContext().clientNode()) { + readCheckpointAndRestoreMemory(); + + if (log.isDebugEnabled()) + log.debug("Restore state after activation [nodeId=" + cctx.localNodeId() + " ]"); + } + } + + /** {@inheritDoc} */ + @Override public void onDeActivate(GridKernalContext kctx) throws IgniteCheckedException { + super.onDeActivate(kctx); + + if (log.isDebugEnabled()) + log.debug("DeActivate database manager [id=" + cctx.localNodeId() + + " topVer=" + cctx.discovery().topologyVersionEx() + " ]"); + + onKernalStop0(true); + + /*must be here, because after deactivate we can invoke activate and file lock must be already configured */ + stopping = false; + + fileLockHolder = new FileLockHolder(storeMgr.workDir().getPath(), cctx.kernalContext(), log); + } + + /** + * + */ + private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { + checkpointReadLock(); + + try { + CheckpointStatus status = readCheckpointStatus(); + + // First, bring memory to the last consistent checkpoint state if needed. + // This method should return a pointer to the last valid record in the WAL. + WALPointer restore = restoreMemory(status); + + cctx.wal().resumeLogging(restore); + + cctx.wal().log(new MemoryRecoveryRecord(U.currentTimeMillis())); + } + catch (StorageException e) { + throw new IgniteCheckedException(e); + } + finally { + checkpointReadUnlock(); + } + } + + /** {@inheritDoc} */ + @Override public void lock() throws IgniteCheckedException { + if (log.isDebugEnabled()) + log.debug("Try to capture file lock [nodeId=" + + cctx.localNodeId() + " path=" + fileLockHolder.lockPath() + "]"); + + fileLockHolder.tryLock(lockWaitTime); + } + + /** {@inheritDoc} */ + @Override public void unLock() { + if (log.isDebugEnabled()) + log.debug("Release file lock [nodeId=" + + cctx.localNodeId() + " path=" + fileLockHolder.lockPath() + "]"); + + fileLockHolder.release(); + } + + /** {@inheritDoc} */ + @Override public void onCacheStop(GridCacheContext cctx) { + snapshotMgr.onCacheStop(cctx); + } + + /** {@inheritDoc} */ + @Override protected void onKernalStop0(boolean cancel) { + checkpointLock.writeLock().lock(); + + try { + stopping = true; + } + finally { + checkpointLock.writeLock().unlock(); + } + + snapshotMgr.onKernalStop(cancel); + + shutdownCheckpointer(cancel); + + lsnrs.clear(); + + super.onKernalStop0(cancel); + + if (!cctx.kernalContext().clientNode()) { + unLock(); + + fileLockHolder.close(); + } + } + + /** {@inheritDoc} */ + @Override protected void stop0(boolean cancel) { + super.stop0(cancel); + + snapshotMgr.stop(cancel); + } + + /** {@inheritDoc} */ + @Override protected long[] calculateFragmentSizes(int concLvl, long cacheSize) { + if (concLvl < 2) + concLvl = Runtime.getRuntime().availableProcessors(); + + long fragmentSize = cacheSize / concLvl; + + if (fragmentSize < 1024 * 1024) + fragmentSize = 1024 * 1024; + + long[] sizes = new long[concLvl + 1]; + + for (int i = 0; i < concLvl; i++) + sizes[i] = fragmentSize; + + sizes[concLvl] = checkpointPageBufSize; + + return sizes; + } + + /** {@inheritDoc} */ + @Override protected PageMemory createPageMemory( + DirectMemoryProvider memProvider, + int pageSize, + MemoryPolicyConfiguration cfg, + MemoryMetricsImpl memMetrics + ) { + return new PageMemoryImpl(memProvider, cctx, pageSize, + new GridInClosure3X() { + @Override public void applyx(FullPageId fullId, ByteBuffer pageBuf, Integer tag) + throws IgniteCheckedException { + flushPageOnEvict(fullId, pageBuf, tag); + } + }, + new GridInClosure3X() { + @Override public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) { + markDirty(fullId.cacheId(), fullId.pageId(), pageMem); + } + }, + this + ); + } + + /** {@inheritDoc} */ + @Override protected void checkPolicyEvictionProperties(MemoryPolicyConfiguration plcCfg, MemoryConfiguration dbCfg) + throws IgniteCheckedException { + if (plcCfg.getPageEvictionMode() != DataPageEvictionMode.DISABLED) + throw new IgniteCheckedException("Page eviction is not compatible with persistence: " + plcCfg.getName()); + } + + /** + * @param initiatorNodeId Snapshot message. + * @param snapshotOperation Snapshot operation. + * @return Snapshot creation init future or {@code null} if snapshot is not available. + * @throws IgniteCheckedException If failed. + */ + @Override @Nullable public IgniteInternalFuture startLocalSnapshotOperation( + UUID initiatorNodeId, + SnapshotOperation snapshotOperation + ) throws IgniteCheckedException { + return snapshotMgr.startLocalSnapshotOperation(initiatorNodeId, snapshotOperation); + } + + /** + * @param pageMem Page memory. + */ + private void markDirty(int cacheId, long pageId, PageMemory pageMem) { + //skip super page + if (PageIdUtils.pageIndex(pageId) == 0) + return; + + long lastSuccessfulSnapshotTag = snapshotMgr.getLastSuccessfulSnapshotTagForCache(cacheId, (PageMemoryEx) pageMem); + + if (lastSuccessfulSnapshotTag < 0) //there is no full snapshot + return; + + long trackingPageId = trackingIO.trackingPageFor(pageId, pageMem.pageSize()); + + //skip tracking page + if (pageId == trackingPageId) + return; + + try { + long trackingPage = pageMem.acquirePage(cacheId, trackingPageId); + try { + long pageAddr = pageMem.writeLock(cacheId, trackingPageId, trackingPage); + + try { + //cooperative initialization + if (PageIO.getType(pageAddr) == 0) { + trackingIO.initNewPage(pageAddr, trackingPageId, pageMem.pageSize()); + + if (isWalDeltaRecordNeeded(pageMem, cacheId, trackingPageId, trackingPage, cctx.wal(), null)) { + cctx.wal().log(new InitNewPageRecord(cacheId, trackingPageId, trackingIO.getType(), + trackingIO.getVersion(), trackingPageId)); + } + } + + long nextSnapshotTag = snapshotMgr.getNextSnapshotTagForCache(cacheId, (PageMemoryEx) pageMem); + + trackingIO.markChanged(pageMem.pageBuffer(pageAddr), + pageId, + nextSnapshotTag, + lastSuccessfulSnapshotTag, + pageMem.pageSize()); + + if (PageHandler.isWalDeltaRecordNeeded(pageMem, cacheId, trackingPageId, trackingPage, cctx.wal(), null)) + cctx.wal().log(new TrackingPageDeltaRecord( + cacheId, trackingPageId, pageId, nextSnapshotTag, lastSuccessfulSnapshotTag)); + } + finally { + pageMem.writeUnlock(cacheId, trackingPageId, trackingPage, null, true); + } + } + finally { + pageMem.releasePage(cacheId, trackingPageId, trackingPage); + } + } + catch (IgniteCheckedException e) { + // TODO we should not allow next incremental snapshot since we've lost an updated page. + U.error(log, "There was an exception while updating tracking page: " + U.hexLong(trackingPageId), e); + } + } + + /** + * @param cancel Cancel flag. + */ + @SuppressWarnings("unused") + private void shutdownCheckpointer(boolean cancel) { + Checkpointer cp = checkpointer; + + if (cp != null) { + if (cancel) + cp.shutdownNow(); + else + cp.cancel(); + + try { + U.join(cp); + + checkpointer = null; + } + catch (IgniteInterruptedCheckedException ignore) { + U.warn(log, "Was interrupted while waiting for checkpointer shutdown, " + + "will not wait for checkpoint to finish."); + + cp.shutdownNow(); + + while (true) { + try { + U.join(cp); + + checkpointer = null; + + break; + } + catch (IgniteInterruptedCheckedException ignored) { + //Ignore + } + } + + Thread.currentThread().interrupt(); + } + } + + if (asyncRunner != null) { + asyncRunner.shutdownNow(); + + try { + asyncRunner.awaitTermination(2, TimeUnit.MINUTES); + } + catch (InterruptedException ignore) { + Thread.currentThread().interrupt(); + } + } + } + + /** {@inheritDoc} */ + @Override public void beforeExchange(GridDhtPartitionsExchangeFuture fut) throws IgniteCheckedException { + DiscoveryEvent discoEvt = fut.discoveryEvent(); + + boolean joinEvt = discoEvt.type() == EventType.EVT_NODE_JOINED; + + boolean locNode = discoEvt.eventNode().isLocal(); + + boolean isSrvNode = !cctx.kernalContext().clientNode(); + + boolean clusterStatusActive = cctx.kernalContext().state().active(); + + boolean clusterInTransitionStateToActive = fut.newClusterState() == ClusterState.ACTIVE; + + // Before local node join event. + if (clusterInTransitionStateToActive || + (joinEvt && locNode && isSrvNode && clusterStatusActive)) + restoreState(); + + if (cctx.kernalContext().query().moduleEnabled()) { + for (GridCacheContext cacheCtx : (Collection)cctx.cacheContexts()) { + if (fut.isCacheAdded(cacheCtx.cacheId(), fut.topologyVersion()) && + !cctx.pageStore().hasIndexStore(cacheCtx.cacheId()) && cacheCtx.affinityNode()) { + final int cacheId = cacheCtx.cacheId(); + + final IgniteInternalFuture rebuildFut = cctx.kernalContext().query() + .rebuildIndexesFromHash(Collections.singletonList(cacheCtx.cacheId())); + + idxRebuildFuts.put(cacheId, rebuildFut); + + rebuildFut.listen(new CI1() { + @Override public void apply(IgniteInternalFuture igniteInternalFut) { + idxRebuildFuts.remove(cacheId, rebuildFut); + } + }); + } + } + } + } + + /** {@inheritDoc} */ + @Nullable @Override public IgniteInternalFuture indexRebuildFuture(int cacheId) { + return idxRebuildFuts.get(cacheId); + } + + /** {@inheritDoc} */ + @Override public boolean persistenceEnabled() { + return true; + } + + /** {@inheritDoc} */ + @Override public void onCachesStopped(Collection> stoppedCtxs) { + try { + waitForCheckpoint("caches stop"); + } + catch (IgniteCheckedException e) { + U.error(log, "Failed to wait for checkpoint finish during cache stop.", e); + } + + Map> destroyed = new HashMap<>(); + + for (IgniteBiTuple tup : stoppedCtxs) { + PageMemoryEx pageMem = (PageMemoryEx)tup.get1().memoryPolicy().pageMemory(); + + Collection cacheIds = destroyed.get(pageMem); + + if (cacheIds == null) { + cacheIds = new HashSet<>(); + + destroyed.put(pageMem, cacheIds); + } + + cacheIds.add(tup.get1().cacheId()); + + pageMem.onCacheDestroyed(tup.get1().cacheId()); + } + + Collection> clearFuts = new ArrayList<>(destroyed.size()); + + for (Map.Entry> entry : destroyed.entrySet()) { + final Collection cacheIds = entry.getValue(); + + clearFuts.add(entry.getKey().clearAsync(new P3() { + @Override public boolean apply(Integer cacheId, Long pageId, Integer tag) { + return cacheIds.contains(cacheId); + } + }, false)); + } + for (IgniteInternalFuture clearFut : clearFuts) { + try { + clearFut.get(); + } + catch (IgniteCheckedException e) { + log.error("Failed to clear page memory", e); + } + } + + if (cctx.pageStore() != null) { + for (IgniteBiTuple tup : stoppedCtxs) { + GridCacheContext cacheCtx = tup.get1(); + + try { + cctx.pageStore().shutdownForCache(cacheCtx, tup.get2()); + } + catch (IgniteCheckedException e) { + U.error(log, "Failed to gracefully clean page store resources for destroyed cache " + + "[cache=" + cacheCtx.name() + "]", e); + } + } + } + } + + /** + * Gets the checkpoint read lock. While this lock is held, checkpoint thread will not acquiSnapshotWorkerre memory state. + */ + @SuppressWarnings("LockAcquiredButNotSafelyReleased") + @Override public void checkpointReadLock() { + if (checkpointLock.writeLock().isHeldByCurrentThread()) + return; + + for (; ; ) { + checkpointLock.readLock().lock(); + + if (stopping) { + checkpointLock.readLock().unlock(); + + throw new RuntimeException("Failed to perform cache update: node is stopping."); + } + + if (safeToUpdatePageMemories() || checkpointLock.getReadHoldCount() > 1) + break; + else { + checkpointLock.readLock().unlock(); + + try { + checkpointer.wakeupForCheckpoint(0, "too many dirty pages").cpBeginFut.get(); + } + catch (IgniteCheckedException e) { + throw new IgniteException("Failed to wait for checkpoint begin.", e); + } + } + } + + if (ASSERTION_ENABLED) + CHECKPOINT_LOCK_HOLD_COUNT.set(CHECKPOINT_LOCK_HOLD_COUNT.get() + 1); + } + + /** {@inheritDoc} */ + @Override public boolean checkpointLockIsHeldByThread() { + return !ASSERTION_ENABLED || + checkpointLock.isWriteLockedByCurrentThread() || + CHECKPOINT_LOCK_HOLD_COUNT.get() > 0; + } + + /** + * @return {@code true} if all PageMemory instances are safe to update. + */ + private boolean safeToUpdatePageMemories() { + Collection memPlcs = context().database().memoryPolicies(); + + if (memPlcs == null) + return true; + + for (MemoryPolicy memPlc : memPlcs) { + PageMemoryEx pageMemEx = (PageMemoryEx) memPlc.pageMemory(); + + if (!pageMemEx.safeToUpdate()) + return false; + } + + return true; + } + + /** + * Releases the checkpoint read lock. + */ + @Override public void checkpointReadUnlock() { + if (checkpointLock.writeLock().isHeldByCurrentThread()) + return; + + checkpointLock.readLock().unlock(); + + if (checkpointer != null) { + Collection cacheCtxs = context().cacheContexts(); + + for (GridCacheContext cacheCtx : cacheCtxs) { + PageMemoryEx mem = (PageMemoryEx) cacheCtx.memoryPolicy().pageMemory(); + + if (mem != null && !mem.safeToUpdate()) { + checkpointer.wakeupForCheckpoint(0, "too many dirty pages"); + + break; + } + } + } + + if (ASSERTION_ENABLED) + CHECKPOINT_LOCK_HOLD_COUNT.set(CHECKPOINT_LOCK_HOLD_COUNT.get() - 1); + } + + /** + * @throws IgniteCheckedException If failed to restore database status from WAL. + */ + public void restoreState() throws IgniteCheckedException { + try { + CheckpointStatus status = readCheckpointStatus(); + + checkpointReadLock(); + + try { + applyLastUpdates(status); + } + finally { + checkpointReadUnlock(); + } + + snapshotMgr.restoreState(); + + checkpointer = new Checkpointer(cctx.igniteInstanceName(), "db-checkpoint-thread", log); + + new IgniteThread(cctx.igniteInstanceName(), "db-checkpoint-thread", checkpointer).start(); + } + catch (StorageException e) { + throw new IgniteCheckedException(e); + } + } + + /** {@inheritDoc} */ + @Override public synchronized Map> reserveHistoryForExchange() { + assert reservedForExchange == null : reservedForExchange; + + reservedForExchange = new HashMap<>(); + + for (GridCacheContext cacheCtx : (Collection)cctx.cacheContexts()) { + if (cacheCtx.isLocal()) + continue; + + for (GridDhtLocalPartition part : cacheCtx.topology().currentLocalPartitions()) { + if (part.state() != GridDhtPartitionState.OWNING || part.size() <= ggWalRebalanceThreshold) + continue; + + for (Long cpTs : checkpointHist.checkpoints()) { + try { + CheckpointEntry entry = checkpointHist.entry(cpTs); + + if (!entry.cacheStates.containsKey(cacheCtx.cacheId()) || + !entry.cacheStates.get(cacheCtx.cacheId()).partitions().containsKey(part.id())) + continue; + + WALPointer ptr = searchPartitionCounter(cacheCtx, part.id(), entry.checkpointTimestamp()); + + if (ptr != null && cctx.wal().reserve(ptr)) { + Map> cacheMap = reservedForExchange.get(cacheCtx.cacheId()); + + if (cacheMap == null) { + cacheMap = new HashMap<>(); + + reservedForExchange.put(cacheCtx.cacheId(), cacheMap); + } + + cacheMap.put(part.id(), new T2<>(entry.partitionCounter(cacheCtx.cacheId(), part.id()), ptr)); + } + } + catch (IgniteCheckedException ex) { + U.error(log, "Error while trying to reserve history", ex); + } + + } + } + } + + Map> resMap = new HashMap<>(); + + for (Map.Entry>> e : reservedForExchange.entrySet()) { + Map cacheMap = new HashMap<>(); + + for (Map.Entry> e0 : e.getValue().entrySet()) + cacheMap.put(e0.getKey(), e0.getValue().get1()); + + resMap.put(e.getKey(), cacheMap); + } + + return resMap; + } + + /** {@inheritDoc} */ + @Override public synchronized void releaseHistoryForExchange() { + if (reservedForExchange == null) + return; + + for (Map.Entry>> e : reservedForExchange.entrySet()) { + for (Map.Entry> e0 : e.getValue().entrySet()) { + try { + cctx.wal().release(e0.getValue().get2()); + } + catch (IgniteCheckedException ex) { + U.error(log, "Could not release history lock", ex); + } + } + } + + reservedForExchange = null; + } + + /** {@inheritDoc} */ + @Override public boolean reserveHistoryForPreloading(int cacheId, int partId, long cntr) { + WALPointer ptr = searchPartitionCounter(cctx.cacheContext(cacheId), partId, cntr); + + if (ptr == null) + return false; + + boolean reserved; + + try { + reserved = cctx.wal().reserve(ptr); + } + catch (IgniteCheckedException e) { + U.error(log, "Error while trying to reserve history", e); + + reserved = false; + } + + if (reserved) + reservedForPreloading.put(new T2<>(cacheId, partId), new T2<>(cntr, ptr)); + + return reserved; + } + + /** {@inheritDoc} */ + @Override public void releaseHistoryForPreloading() { + for (Map.Entry, T2> e : reservedForPreloading.entrySet()) { + try { + cctx.wal().release(e.getValue().get2()); + } + catch (IgniteCheckedException ex) { + U.error(log, "Could not release WAL reservation", ex); + + throw new IgniteException(ex); + } + } + + reservedForPreloading.clear(); + } + + /** + * For debugging only. TODO: remove. + * + */ + public Map, T2> reservedForPreloading() { + return reservedForPreloading; + } + + /** + * + */ + @Nullable @Override public IgniteInternalFuture wakeupForCheckpoint(String reason) { + Checkpointer cp = checkpointer; + + if (cp != null) + return cp.wakeupForCheckpoint(0, reason).cpBeginFut; + + return null; + } + + /** {@inheritDoc} */ + @Override public void waitForCheckpoint(String reason) throws IgniteCheckedException { + Checkpointer cp = checkpointer; + + if (cp == null) + return; + + CheckpointProgressSnapshot progSnapshot = cp.wakeupForCheckpoint(0, reason); + + IgniteInternalFuture fut1 = progSnapshot.cpFinishFut; + + fut1.get(); + + if (!progSnapshot.started) + return; + + IgniteInternalFuture fut2 = cp.wakeupForCheckpoint(0, reason).cpFinishFut; + + assert fut1 != fut2; + + fut2.get(); + } + + /** + * Schedules partition destroy during next checkpoint. This method must be called inside checkpoint read lock. + * + * @param cacheCtx Cache context. + * @param partId Partition ID. + */ + public void schedulePartitionDestroy(GridCacheContext cacheCtx, int partId) { + Checkpointer cp = checkpointer; + + if (cp != null) + cp.schedulePartitionDestroy(cacheCtx, partId); + } + + /** + * Cancels partition destroy if it has not begun yet. Otherwise, will wait for cleanup to finish. + * + * @param cacheCtx Cache context. + * @param partId Partition ID. + */ + public void cancelOrWaitPartitionDestroy(GridCacheContext cacheCtx, int partId) + throws IgniteCheckedException { + Checkpointer cp = checkpointer; + + if (cp != null) + cp.cancelOrWaitPartitionDestroy(cacheCtx, partId); + } + + + + /** + * Tries to search for a WAL pointer for the given partition counter start. + * + * @param cacheCtx Cache context. + * @param part Partition ID. + * @param partCntrSince Partition counter. + * @return WAL pointer or {@code null} if failed to search. + */ + public WALPointer searchPartitionCounter(GridCacheContext cacheCtx, int part, Long partCntrSince) { + boolean hasGap = false; + WALPointer first = null; + + for (Long cpTs : checkpointHist.checkpoints()) { + try { + CheckpointEntry entry = checkpointHist.entry(cpTs); + + Long foundCntr = entry.partitionCounter(cacheCtx.cacheId(), part); + + if (foundCntr != null) { + if (foundCntr <= partCntrSince) { + first = entry.cpMark; + + hasGap = false; + } + else + return hasGap ? null : first; + } + else + hasGap = true; + } + catch (IgniteCheckedException ignore) { + // Treat exception the same way as a gap. + hasGap = true; + } + } + + return hasGap ? null : first; + } + + /** + * @return Checkpoint history. For tests only. + */ + public CheckpointHistory checkpointHistory() { + return checkpointHist; + } + + /** + * @return Checkpoint directory. + */ + public File checkpointDirectory() { + return cpDir; + } + + /** + * @param lsnr Listener. + */ + public void addCheckpointListener(DbCheckpointListener lsnr) { + lsnrs.add(lsnr); + } + + /** + * @param lsnr Listener. + */ + public void removeCheckpointListener(DbCheckpointListener lsnr) { + lsnrs.remove(lsnr); + } + + /** + * @return Read checkpoint status. + * @throws IgniteCheckedException If failed to read checkpoint status page. + */ + @SuppressWarnings("TooBroadScope") + private CheckpointStatus readCheckpointStatus() throws IgniteCheckedException { + long lastStartTs = 0; + long lastEndTs = 0; + + UUID startId = CheckpointStatus.NULL_UUID; + UUID endId = CheckpointStatus.NULL_UUID; + + File startFile = null; + File endFile = null; + + WALPointer startPtr = CheckpointStatus.NULL_PTR; + WALPointer endPtr = CheckpointStatus.NULL_PTR; + + File dir = cpDir; + + if (!dir.exists()) { + // TODO: remove excessive logging after GG-12116 fix. + File[] files = dir.listFiles(); + + if (files != null && files.length > 0) { + log.warning("Read checkpoint status: cpDir.exists() is false, cpDir.listFiles() is: " + + Arrays.toString(files)); + } + + if (Files.exists(dir.toPath())) + log.warning("Read checkpoint status: cpDir.exists() is false, Files.exists(cpDir) is true."); + + log.info("Read checkpoint status: checkpoint directory is not found."); + + return new CheckpointStatus(0, startId, startPtr, endId, endPtr); + } + + File[] files = dir.listFiles(); + + for (File file : files) { + Matcher matcher = CP_FILE_NAME_PATTERN.matcher(file.getName()); + + if (matcher.matches()) { + long ts = Long.parseLong(matcher.group(1)); + UUID id = UUID.fromString(matcher.group(2)); + CheckpointEntryType type = CheckpointEntryType.valueOf(matcher.group(3)); + + if (type == CheckpointEntryType.START && ts > lastStartTs) { + lastStartTs = ts; + startId = id; + startFile = file; + } + else if (type == CheckpointEntryType.END && ts > lastEndTs) { + lastEndTs = ts; + endId = id; + endFile = file; + } + } + } + + ByteBuffer buf = ByteBuffer.allocate(16); + buf.order(ByteOrder.nativeOrder()); + + if (startFile != null) + startPtr = readPointer(startFile, buf); + + if (endFile != null) + endPtr = readPointer(endFile, buf); + + // TODO: remove excessive logging after GG-12116 fix. + log.info("Read checkpoint status: start marker = " + startFile + ", end marker = " + endFile); + + return new CheckpointStatus(lastStartTs, startId, startPtr, endId, endPtr); + } + + /** + * @param cpMarkerFile Checkpoint mark file. + * @return WAL pointer. + * @throws IgniteCheckedException If failed to read mark file. + */ + private WALPointer readPointer(File cpMarkerFile, ByteBuffer buf) throws IgniteCheckedException { + buf.position(0); + + try (FileChannel ch = FileChannel.open(cpMarkerFile.toPath(), StandardOpenOption.READ)) { + ch.read(buf); + + buf.flip(); + + return new FileWALPointer(buf.getInt(), buf.getInt(), buf.getInt()); + } + catch (IOException e) { + throw new IgniteCheckedException("Failed to read checkpoint pointer from marker file: " + + cpMarkerFile.getAbsolutePath(), e); + } + } + + /** + * @param status Checkpoint status. + */ + private WALPointer restoreMemory(CheckpointStatus status) throws IgniteCheckedException { + if (log.isInfoEnabled()) + log.info("Checking memory state [lastValidPos=" + status.endPtr + ", lastMarked=" + + status.startPtr + ", lastCheckpointId=" + status.cpStartId + ']'); + + boolean apply = status.needRestoreMemory(); + + if (apply) { + U.quietAndWarn(log, "Ignite node crashed in the middle of checkpoint. Will restore memory state and " + + "enforce checkpoint on node start."); + + cctx.pageStore().beginRecover(); + } + + long start = U.currentTimeMillis(); + int applied = 0; + WALPointer lastRead = null; + + try (WALIterator it = cctx.wal().replay(status.endPtr)) { + while (it.hasNextX()) { + IgniteBiTuple tup = it.nextX(); + + WALRecord rec = tup.get2(); + + lastRead = tup.get1(); + + switch (rec.type()) { + case CHECKPOINT_RECORD: + CheckpointRecord cpRec = (CheckpointRecord)rec; + + // We roll memory up until we find a checkpoint start record registered in the status. + if (F.eq(cpRec.checkpointId(), status.cpStartId)) { + log.info("Found last checkpoint marker [cpId=" + cpRec.checkpointId() + + ", pos=" + tup.get1() + ']'); + + apply = false; + } + else if (!F.eq(cpRec.checkpointId(), status.cpEndId)) + U.warn(log, "Found unexpected checkpoint marker, skipping [cpId=" + cpRec.checkpointId() + + ", expCpId=" + status.cpStartId + ", pos=" + tup.get1() + ']'); + + break; + + case PAGE_RECORD: + if (apply) { + PageSnapshot pageRec = (PageSnapshot)rec; + + // Here we do not require tag check because we may be applying memory changes after + // several repetitive restarts and the same pages may have changed several times. + int cacheId = pageRec.fullPageId().cacheId(); + long pageId = pageRec.fullPageId().pageId(); + + PageMemoryEx pageMem = getPageMemoryForCacheId(cacheId); + + long page = pageMem.acquirePage(cacheId, pageId, true); + + try { + long pageAddr = pageMem.writeLock(cacheId, pageId, page); + + try { + PageUtils.putBytes(pageAddr, 0, pageRec.pageData()); + } + finally { + pageMem.writeUnlock(cacheId, pageId, page, null, true, true); + } + } + finally { + pageMem.releasePage(cacheId, pageId, page); + } + + applied++; + } + + break; + + case PARTITION_DESTROY: + if (apply) { + PartitionDestroyRecord destroyRec = (PartitionDestroyRecord)rec; + + final int cId = destroyRec.cacheId(); + final int pId = destroyRec.partitionId(); + + PageMemoryEx pageMem = (PageMemoryEx)cctx.cacheContext(cId).memoryPolicy().pageMemory(); + + pageMem.clearAsync(new P3() { + @Override public boolean apply(Integer cacheId, Long pageId, Integer tag) { + return cacheId == cId && PageIdUtils.partId(pageId) == pId; + } + }, true).get(); + } + + break; + + default: + if (apply && rec instanceof PageDeltaRecord) { + PageDeltaRecord r = (PageDeltaRecord)rec; + + int cacheId = r.cacheId(); + long pageId = r.pageId(); + + PageMemoryEx pageMem = getPageMemoryForCacheId(cacheId); + + // Here we do not require tag check because we may be applying memory changes after + // several repetitive restarts and the same pages may have changed several times. + long page = pageMem.acquirePage(cacheId, pageId, true); + + try { + long pageAddr = pageMem.writeLock(cacheId, pageId, page); + + try { + r.applyDelta(pageMem, pageAddr); + } + finally { + pageMem.writeUnlock(cacheId, pageId, page, null, true, true); + } + } + finally { + pageMem.releasePage(cacheId, pageId, page); + } + + applied++; + } + } + } + } + + if (status.needRestoreMemory()) { + assert !apply : "Restoring memory state failed, checkpoint marker [cpId=" + status.cpStartId + + "] was not found in WAL"; + + log.info("Finished applying memory changes [changesApplied=" + applied + + ", time=" + (U.currentTimeMillis() - start) + "ms]"); + + if (applied > 0) + finalizeCheckpointOnRecovery(status.cpStartTs, status.cpStartId, status.startPtr); + } + + checkpointHist.loadHistory(cpDir); + + return lastRead == null ? null : lastRead.next(); + } + + /** + * Obtains PageMemory reference from cache descriptor instead of cache context. + * + * @param cacheId Cache id. + * @return PageMemoryEx instance. + * @throws IgniteCheckedException if no MemoryPolicy is configured for a name obtained from cache descriptor. + */ + private PageMemoryEx getPageMemoryForCacheId(int cacheId) throws IgniteCheckedException { + GridCacheSharedContext sharedCtx = context(); + + String memPlcName = sharedCtx + .cache() + .cacheDescriptor(cacheId) + .cacheConfiguration() + .getMemoryPolicyName(); + + return (PageMemoryEx) sharedCtx.database().memoryPolicy(memPlcName).pageMemory(); + } + + /** + * @param status Last registered checkpoint status. + * @throws IgniteCheckedException If failed to apply updates. + * @throws StorageException If IO exception occurred while reading write-ahead log. + */ + private void applyLastUpdates(CheckpointStatus status) throws IgniteCheckedException { + if (log.isInfoEnabled()) + log.info("Applying lost cache updates since last checkpoint record [lastMarked=" + + status.startPtr + ", lastCheckpointId=" + status.cpStartId + ']'); + + cctx.kernalContext().query().skipFieldLookup(true); + + long start = U.currentTimeMillis(); + int applied = 0; + + try (WALIterator it = cctx.wal().replay(status.startPtr)) { + Map, T2> partStates = new HashMap<>(); + + while (it.hasNextX()) { + IgniteBiTuple next = it.nextX(); + + WALRecord rec = next.get2(); + + switch (rec.type()) { + case DATA_RECORD: + DataRecord dataRec = (DataRecord)rec; + + for (DataEntry dataEntry : dataRec.writeEntries()) { + int cacheId = dataEntry.cacheId(); + + GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + + applyUpdate(cacheCtx, dataEntry); + + applied++; + } + + break; + + case PART_META_UPDATE_STATE: + PartitionMetaStateRecord metaStateRecord = (PartitionMetaStateRecord)rec; + + partStates.put(new T2<>(metaStateRecord.cacheId(), metaStateRecord.partitionId()), + new T2<>((int)metaStateRecord.state(), metaStateRecord.updateCounter())); + + break; + + default: + // Skip other records. + } + } + + restorePartitionState(partStates); + } + finally { + cctx.kernalContext().query().skipFieldLookup(false); + } + + if (log.isInfoEnabled()) + log.info("Finished applying WAL changes [updatesApplied=" + applied + + ", time=" + (U.currentTimeMillis() - start) + "ms]"); + } + + /** + * @param partStates Partition states. + * @throws IgniteCheckedException If failed to restore. + */ + private void restorePartitionState( + Map, T2> partStates) throws IgniteCheckedException { + Collection cacheContexts = cctx.cacheContexts(); + + for (GridCacheContext context : cacheContexts) { + int cacheId = context.cacheId(); + + GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + + PageMemoryEx pageMem = (PageMemoryEx)cacheCtx.memoryPolicy().pageMemory(); + + for (int i = 0; i < context.affinity().partitions(); i++) { + if (storeMgr.exists(cacheId, i)) { + storeMgr.ensure(cacheId, i); + + if (storeMgr.pages(cacheId, i) <= 1) + continue; + + long partMetaId = pageMem.partitionMetaPageId(cacheId, i); + long partMetaPage = pageMem.acquirePage(cacheId, partMetaId); + try { + long pageAddr = pageMem.writeLock(cacheId, partMetaId, partMetaPage); + + boolean changed = false; + + try { + PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.forPage(pageAddr); + + T2 fromWal = partStates.get(new T2<>(cacheId, i)); + + GridDhtLocalPartition part = context.topology() + .localPartition(i, AffinityTopologyVersion.NONE, true); + + assert part != null; + + if (fromWal != null) { + int stateId = fromWal.get1(); + + io.setPartitionState(pageAddr, (byte)stateId); + + changed = updateState(part, stateId); + + if (stateId == GridDhtPartitionState.OWNING.ordinal()) { + cacheCtx.offheap().onPartitionInitialCounterUpdated(i, fromWal.get2()); + + if (part.initialUpdateCounter() < fromWal.get2()) { + part.initialUpdateCounter(fromWal.get2()); + + changed = true; + } + } + } + else + changed = updateState(part, (int)io.getPartitionState(pageAddr)); + } + finally { + pageMem.writeUnlock(cacheId, partMetaId, partMetaPage, null, changed); + } + } + finally { + pageMem.releasePage(cacheId, partMetaId, partMetaPage); + } + } + } + } + } + + /** + * @param part Partition to restore state for. + * @param stateId State enum ordinal. + * @return Updated flag. + */ + private boolean updateState(GridDhtLocalPartition part, int stateId) { + if (stateId != -1) { + GridDhtPartitionState state = GridDhtPartitionState.fromOrdinal(stateId); + + assert state != null; + + part.restoreState(state == GridDhtPartitionState.EVICTED ? GridDhtPartitionState.RENTING : state); + + return true; + } + + return false; + } + + /** + * @param cacheCtx Cache context to apply an update. + * @param dataEntry Data entry to apply. + */ + private void applyUpdate(GridCacheContext cacheCtx, DataEntry dataEntry) throws IgniteCheckedException { + GridDhtLocalPartition locPart = cacheCtx.topology() + .localPartition(dataEntry.partitionId(), AffinityTopologyVersion.NONE, true); + + switch (dataEntry.op()) { + case CREATE: + case UPDATE: + cacheCtx.offheap().update( + dataEntry.key(), + dataEntry.value(), + dataEntry.writeVersion(), + 0L, + locPart, + null); + + if (dataEntry.partitionCounter() != 0) + cacheCtx.offheap().onPartitionInitialCounterUpdated(dataEntry.partitionId(), dataEntry.partitionCounter()); + + break; + + case DELETE: + cacheCtx.offheap().remove(dataEntry.key(), dataEntry.partitionId(), locPart); + + if (dataEntry.partitionCounter() != 0) + cacheCtx.offheap().onPartitionInitialCounterUpdated(dataEntry.partitionId(), dataEntry.partitionCounter()); + + break; + + default: + throw new IgniteCheckedException("Invalid operation for WAL entry update: " + dataEntry.op()); + } + } + + /** + * @param fullId Full page ID. + * @param pageBuf Page buffer. + */ + private void flushPageOnEvict(FullPageId fullId, ByteBuffer pageBuf, int tag) throws IgniteCheckedException { + storeMgr.write(fullId.cacheId(), fullId.pageId(), pageBuf, tag); + + snapshotMgr.onPageEvict(fullId); + } + + /** + * @throws IgniteCheckedException If failed. + */ + private void finalizeCheckpointOnRecovery(long cpTs, UUID cpId, WALPointer walPtr) throws IgniteCheckedException { + assert cpTs != 0; + + ByteBuffer tmpWriteBuf = ByteBuffer.allocateDirect(pageSize()); + + long start = System.currentTimeMillis(); + + Collection memPolicies = context().database().memoryPolicies(); + + List>> cpEntities = new ArrayList<>(memPolicies.size()); + + for (MemoryPolicy memPlc : memPolicies) { + PageMemoryEx pageMem = (PageMemoryEx) memPlc.pageMemory(); + cpEntities.add(new IgniteBiTuple>(pageMem, + (pageMem).beginCheckpoint())); + } + + tmpWriteBuf.order(ByteOrder.nativeOrder()); + + // Identity stores set. + Collection updStores = new HashSet<>(); + + int cpPagesCnt = 0; + + for (IgniteBiTuple> e : cpEntities) { + PageMemoryEx pageMem = (PageMemoryEx) e.get1(); + + Collection cpPages = e.get2(); + + cpPagesCnt += cpPages.size(); + + for (FullPageId fullId : cpPages) { + tmpWriteBuf.rewind(); + + Integer tag = pageMem.getForCheckpoint(fullId, tmpWriteBuf); + + if (tag != null) { + tmpWriteBuf.rewind(); + + PageStore store = storeMgr.writeInternal(fullId.cacheId(), fullId.pageId(), tmpWriteBuf, tag); + + tmpWriteBuf.rewind(); + + updStores.add(store); + } + } + } + + long written = U.currentTimeMillis(); + + for (PageStore updStore : updStores) + updStore.sync(); + + long fsync = U.currentTimeMillis(); + + for (IgniteBiTuple> e : cpEntities) + ((PageMemoryEx)e.get1()).finishCheckpoint(); + + writeCheckpointEntry( + tmpWriteBuf, + cpTs, + cpId, + walPtr, + null, + CheckpointEntryType.END); + + cctx.pageStore().finishRecover(); + + if (log.isInfoEnabled()) + log.info(String.format("Checkpoint finished [cpId=%s, pages=%d, markPos=%s, " + + "pagesWrite=%dms, fsync=%dms, total=%dms]", + cpId, + cpPagesCnt, + walPtr, + written - start, + fsync - written, + fsync - start)); + } + + /** + * @param cpId Checkpoint ID. + * @param ptr Wal pointer of current checkpoint. + */ + private CheckpointEntry writeCheckpointEntry( + ByteBuffer tmpWriteBuf, + long cpTs, + UUID cpId, + WALPointer ptr, + CheckpointRecord rec, + CheckpointEntryType type + ) throws IgniteCheckedException { + assert ptr instanceof FileWALPointer; + + FileWALPointer filePtr = (FileWALPointer)ptr; + + String fileName = checkpointFileName(cpTs, cpId, type); + + try (FileChannel ch = FileChannel.open(Paths.get(cpDir.getAbsolutePath(), fileName), + StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND)) { + + tmpWriteBuf.rewind(); + + tmpWriteBuf.putInt(filePtr.index()); + + tmpWriteBuf.putInt(filePtr.fileOffset()); + + tmpWriteBuf.putInt(filePtr.length()); + + tmpWriteBuf.flip(); + + ch.write(tmpWriteBuf); + + tmpWriteBuf.clear(); + + if (!skipSync) + ch.force(true); + + return type == CheckpointEntryType.START ? + new CheckpointEntry(cpTs, ptr, cpId, rec.cacheStates()) : null; + } + catch (IOException e) { + throw new IgniteCheckedException(e); + } + } + + /** + * @param cpTs Checkpoint timestamp. + * @param cpId Checkpoint ID. + * @param type Checkpoint type. + * @return Checkpoint file name. + */ + private static String checkpointFileName(long cpTs, UUID cpId, CheckpointEntryType type) { + return cpTs + "-" + cpId + "-" + type + ".bin"; + } + + /** + * @param reqs Destroy requests. + */ + @SuppressWarnings("TypeMayBeWeakened") + private void finishDestroyPartitionsAsync(final Collection reqs) { + final Map> filterMap = new HashMap<>(); + + final Set pageMemSet = new HashSet<>(); + + for (PartitionDestroyRequest req : reqs) { + Collection partIds = filterMap.get(req.cacheId); + + if (partIds == null) { + partIds = new HashSet<>(); + + filterMap.put(req.cacheId, partIds); + } + + partIds.add(req.partId); + + pageMemSet.add((PageMemoryEx)cctx.cacheContext(req.cacheId).memoryPolicy().pageMemory()); + } + + for (PageMemoryEx pageMem : pageMemSet) { + IgniteInternalFuture clearFut = pageMem.clearAsync(new P3() { + @Override public boolean apply(Integer cacheId, Long pageId, Integer tag) { + assert cacheId != null; + assert pageId != null; + + int partId = PageIdUtils.partId(pageId); + + Collection parts = filterMap.get(cacheId); + + return parts != null && parts.contains(partId); + } + }, true); + + clearFut.listen(new IgniteInClosure>() { + @Override public void apply(IgniteInternalFuture clearFut) { + for (PartitionDestroyRequest req : reqs) { + try { + assert !req.allowFastEviction; + + // Tag should never grow in this case. + cctx.pageStore().onPartitionDestroyed(req.cacheId, req.partId, 1); + } + catch (IgniteCheckedException e) { + req.onDone(e); + } + finally { + req.onDone(clearFut.error()); + } + } + } + }); + } + } + + /** + * + */ + @SuppressWarnings("NakedNotify") + public class Checkpointer extends GridWorker { + /** Temporary write buffer. */ + private final ByteBuffer tmpWriteBuf; + + /** Next scheduled checkpoint progress. */ + private volatile CheckpointProgress scheduledCp; + + /** Current checkpoint. This field is updated only by checkpoint thread. */ + private volatile CheckpointProgress curCpProgress; + + /** Shutdown now. */ + private volatile boolean shutdownNow; + + /** + * @param gridName Grid name. + * @param name Thread name. + * @param log Logger. + */ + protected Checkpointer(@Nullable String gridName, String name, IgniteLogger log) { + super(gridName, name, log); + + scheduledCp = new CheckpointProgress(U.currentTimeMillis() + checkpointFreq); + + tmpWriteBuf = ByteBuffer.allocateDirect(pageSize()); + + tmpWriteBuf.order(ByteOrder.nativeOrder()); + } + + /** {@inheritDoc} */ + @Override protected void body() throws InterruptedException, IgniteInterruptedCheckedException { + while (!isCancelled()) { + waitCheckpointEvent(); + + GridFutureAdapter enableChangeApplied = GridCacheDatabaseSharedManager.this.enableChangeApplied; + + if (enableChangeApplied != null) { + enableChangeApplied.onDone(); + + GridCacheDatabaseSharedManager.this.enableChangeApplied = null; + } + + if (checkpointsEnabled) + doCheckpoint(); + else { + synchronized (this) { + scheduledCp.nextCpTs = U.currentTimeMillis() + checkpointFreq; + } + } + } + + // Final run after the cancellation. + if (checkpointsEnabled && !shutdownNow) + doCheckpoint(); + } + + /** + * + */ + private CheckpointProgressSnapshot wakeupForCheckpoint(long delayFromNow, String reason) { + CheckpointProgress sched = scheduledCp; + + long next = U.currentTimeMillis() + delayFromNow; + + if (sched.nextCpTs <= next) + return new CheckpointProgressSnapshot(sched); + + CheckpointProgressSnapshot ret; + + synchronized (this) { + sched = scheduledCp; + + if (sched.nextCpTs > next) { + sched.reason = reason; + + sched.nextCpTs = next; + } + + ret = new CheckpointProgressSnapshot(sched); + + notifyAll(); + } + + return ret; + } + + /** + * @param snapshotOperation Snapshot operation. + */ + public IgniteInternalFuture wakeupForSnapshotCreation(SnapshotOperation snapshotOperation) { + GridFutureAdapter ret; + + synchronized (this) { + scheduledCp.nextCpTs = U.currentTimeMillis(); + + scheduledCp.reason = "snapshot"; + + scheduledCp.nextSnapshot = true; + + scheduledCp.snapshotOperation = snapshotOperation; + + ret = scheduledCp.cpBeginFut; + + notifyAll(); + } + + return ret; + } + + /** + * @param cacheCtx Cache context. + * @param partId Partition ID. + */ + private void schedulePartitionDestroy(GridCacheContext cacheCtx, int partId) { + synchronized (this) { + scheduledCp.destroyQueue.addDestroyRequest(cacheCtx, partId); + } + + wakeupForCheckpoint(partDestroyCheckpointDelay, "partition destroy"); + } + + /** + * @param cacheCtx Cache context. + * @param partId Partition ID. + */ + private void cancelOrWaitPartitionDestroy(GridCacheContext cacheCtx, int partId) + throws IgniteCheckedException { + CheckpointProgress cur = curCpProgress; + + PartitionDestroyRequest req; + + if (cur != null) { + req = cur.destroyQueue.cancelDestroy(cacheCtx.cacheId(), partId); + + if (req != null) + req.waitCompleted(); + } + + synchronized (this) { + req = scheduledCp.destroyQueue.cancelDestroy(cacheCtx.cacheId(), partId); + } + + if (req != null) + req.waitCompleted(); + } + + /** + * + */ + private void doCheckpoint() { + try { + long start = U.currentTimeMillis(); + + Checkpoint chp = markCheckpointBegin(); + + snapshotMgr.onCheckPointBegin(); + + long written, fsync, marked = U.currentTimeMillis(); + + int pages = chp.cpPages.size(); + + boolean interrupted = true; + + try { + // Identity stores set. + GridConcurrentHashSet updStores = new GridConcurrentHashSet<>(); + + CountDownFuture doneWriteFut = new CountDownFuture( + asyncRunner == null ? 1 : chp.cpPages.collectionsSize()); + + if (asyncRunner != null) { + for (int i = 0; i < chp.cpPages.collectionsSize(); i++) { + Runnable write = new WriteCheckpointPages( + chp.cpPages.innerCollection(i), + updStores, + doneWriteFut + ); + + try { + asyncRunner.execute(write); + } + catch (RejectedExecutionException ignore) { + // Run the task synchronously. + write.run(); + } + } + } + else { + // Single-threaded checkpoint. + Runnable write = new WriteCheckpointPages(chp.cpPages, updStores, doneWriteFut); + + write.run(); + } + + // Wait and check for errors. + doneWriteFut.get(); + + // Must re-check shutdown flag here because threads may have skipped some pages. + // If so, we should not put finish checkpoint mark. + if (shutdownNow) + return; + + snapshotMgr.afterCheckpointPageWritten(); + + written = U.currentTimeMillis(); + + if (!skipSync) { + for (PageStore updStore : updStores) { + if (shutdownNow) + return; + + updStore.sync(); + } + } + + fsync = U.currentTimeMillis(); + + // Must mark successful checkpoint only if there are no exceptions or interrupts. + interrupted = false; + } + finally { + if (!interrupted) + markCheckpointEnd(chp); + } + + long fsyncEnd = U.currentTimeMillis(); + + // We finished this checkpoint, now it's time to clean up partitions. + PartitionDestroyQueue destroyQueue = chp.progress.destroyQueue; + + Collection reqs = null; + WALPointer lastPtr = null; + + for (T2 destroyId : destroyQueue.pendingReqs.keySet()) { + PartitionDestroyRequest req = destroyQueue.beginDestroy(destroyId); + + if (req != null) { + // Log destroy record before actual partition clear. + lastPtr = cctx.wal().log(new PartitionDestroyRecord(req.cacheId, req.partId)); + + if (reqs == null) + reqs = new ArrayList<>(); + + reqs.add(req); + } + } + + if (reqs != null) { + assert lastPtr != null; + + cctx.wal().fsync(lastPtr); + + finishDestroyPartitionsAsync(reqs); + } + + if (printCheckpointStats) + log.info(String.format("Checkpoint finished [cpId=%s, pages=%d, markPos=%s, " + + "walSegmentsCleared=%d, markBegin=%dms, pagesWrite=%dms, fsync=%dms, markEnd=%dms, " + + "total=%dms]", + chp.cpEntry.checkpointId(), + pages, + chp.cpEntry.checkpointMark(), + chp.walFilesDeleted, + marked - start, + written - marked, + fsync - written, + fsyncEnd - fsync, + fsyncEnd - start)); + } + catch (IgniteCheckedException e) { + // TODO-ignite-db how to handle exception? + U.error(log, "Failed to create checkpoint.", e); + } + } + + /** + * + */ + @SuppressWarnings("WaitNotInLoop") + private void waitCheckpointEvent() { + boolean cancel = false; + + try { + long now = U.currentTimeMillis(); + + synchronized (this) { + long remaining; + + while ((remaining = scheduledCp.nextCpTs - now) > 0 && !isCancelled()) { + wait(remaining); + + now = U.currentTimeMillis(); + } + } + } + catch (InterruptedException ignored) { + Thread.currentThread().interrupt(); + + cancel = true; + } + + if (cancel) + isCancelled = true; + } + + /** + * + */ + @SuppressWarnings("TooBroadScope") + private Checkpoint markCheckpointBegin() throws IgniteCheckedException { + CheckpointRecord cpRec = new CheckpointRecord(null, false); + + WALPointer cpPtr; + + GridMultiCollectionWrapper cpPages; + + long lockAcquired, lockReleased, lockStart = U.currentTimeMillis(); + + final CheckpointProgress curr; + + checkpointLock.writeLock().lock(); + + try { + lockAcquired = U.currentTimeMillis(); + + synchronized (this) { + curr = scheduledCp; + + curr.started = true; + + if (curr.reason == null) + curr.reason = "timeout"; + + // It is important that we assign a new progress object before checkpoint mark in page memory. + scheduledCp = new CheckpointProgress(U.currentTimeMillis() + checkpointFreq); + + curCpProgress = curr; + } + + final NavigableMap, T2> map = + new TreeMap<>(FullPageIdIterableComparator.INSTANCE); + + DbCheckpointListener.Context ctx0 = new DbCheckpointListener.Context() { + @Override public boolean nextSnapshot() { + return curr.nextSnapshot; + } + + @Override public Map, T2> partitionStatMap() { + return map; + } + }; + + // Listeners must be invoked before we write checkpoint record to WAL. + for (DbCheckpointListener lsnr : lsnrs) + lsnr.onCheckpointBegin(ctx0); + + Collection cacheCtxs = ((GridCacheSharedContext)cctx).cacheContexts(); + + for (GridCacheContext cacheCtx : cacheCtxs) { + CacheState state = new CacheState(); + + if (cacheCtx.isLocal()) + continue; + + for (GridDhtLocalPartition part : cacheCtx.topology().currentLocalPartitions()) + state.addPartitionState(part.id(), part.dataStore().size(), part.lastAppliedUpdate()); + + cpRec.addCacheState(cacheCtx.cacheId(), state); + } + + if (curr.nextSnapshot) + snapshotMgr.onMarkCheckPointBegin(curr.snapshotOperation, map); + + // No page updates for this checkpoint are allowed from now on. + cpPtr = cctx.wal().log(cpRec); + + if (cpPtr == null) + cpPtr = CheckpointStatus.NULL_PTR; + + IgniteBiTuple>, Integer> tup = beginAllCheckpoints(); + + // Todo it maybe more optimally + Collection cpPagesList = new ArrayList<>(tup.get2()); + + for (GridMultiCollectionWrapper col : tup.get1()) { + for (int i = 0; i < col.collectionsSize(); i++) + cpPagesList.addAll(col.innerCollection(i)); + } + + cpPages = new GridMultiCollectionWrapper<>(cpPagesList); + } + finally { + checkpointLock.writeLock().unlock(); + + lockReleased = U.currentTimeMillis(); + } + + curr.cpBeginFut.onDone(); + + // Sync log outside the checkpoint write lock. + cctx.wal().fsync(cpPtr); + + long cpTs = System.currentTimeMillis(); + + CheckpointEntry cpEntry = writeCheckpointEntry( + tmpWriteBuf, + cpTs, + cpRec.checkpointId(), + cpPtr, + cpRec, + CheckpointEntryType.START); + + checkpointHist.addCheckpointEntry(cpEntry); + + if (printCheckpointStats) + if (log.isInfoEnabled()) + log.info(String.format("Checkpoint started [checkpointId=%s, startPtr=%s, checkpointLockWait=%dms, " + + "checkpointLockHoldTime=%dms, pages=%d, reason='%s']", + cpRec.checkpointId(), + cpPtr, + lockAcquired - lockStart, + lockReleased - lockAcquired, + cpPages.size(), + curr.reason) + ); + + return new Checkpoint(cpEntry, cpPages, curr); + } + + /** + * @return tuple with collections of FullPageIds obtained from each PageMemory and overall number of dirty pages. + */ + private IgniteBiTuple>, Integer> beginAllCheckpoints() { + Collection> res = new ArrayList(memoryPolicies().size()); + + int pagesNum = 0; + + for (MemoryPolicy memPlc : memoryPolicies()) { + GridMultiCollectionWrapper nextCpPagesCol = ((PageMemoryEx) memPlc.pageMemory()).beginCheckpoint(); + + pagesNum += nextCpPagesCol.size(); + + res.add(nextCpPagesCol); + } + + return new IgniteBiTuple<>(res, pagesNum); + } + + /** + * @param chp Checkpoint snapshot. + */ + private void markCheckpointEnd(Checkpoint chp) throws IgniteCheckedException { + synchronized (this) { + for (MemoryPolicy memPlc : memoryPolicies()) + ((PageMemoryEx)memPlc.pageMemory()).finishCheckpoint(); + + writeCheckpointEntry( + tmpWriteBuf, + chp.cpEntry.checkpointTimestamp(), + chp.cpEntry.checkpointId(), + chp.cpEntry.checkpointMark(), + null, + CheckpointEntryType.END); + } + + chp.walFilesDeleted = checkpointHist.onCheckpointFinished(); + + chp.progress.cpFinishFut.onDone(); + } + + /** {@inheritDoc} */ + @Override public void cancel() { + if (log.isDebugEnabled()) + log.debug("Cancelling grid runnable: " + this); + + // Do not interrupt runner thread. + isCancelled = true; + + synchronized (this) { + notifyAll(); + } + } + + /** + * + */ + public void shutdownNow() { + shutdownNow = true; + + if (!isCancelled) + cancel(); + } + } + + /** + * + */ + private class WriteCheckpointPages implements Runnable { + /** */ + private Collection writePageIds; + + /** */ + private GridConcurrentHashSet updStores; + + /** */ + private CountDownFuture doneFut; + + /** + * @param writePageIds Write page IDs. + */ + private WriteCheckpointPages( + Collection writePageIds, + GridConcurrentHashSet updStores, + CountDownFuture doneFut + ) { + this.writePageIds = writePageIds; + this.updStores = updStores; + this.doneFut = doneFut; + } + + /** {@inheritDoc} */ + @Override public void run() { + ByteBuffer tmpWriteBuf = threadBuf.get(); + + long writeAddr = GridUnsafe.bufferAddress(tmpWriteBuf); + + snapshotMgr.beforeCheckpointPageWritten(); + + try { + for (FullPageId fullId : writePageIds) { + if (checkpointer.shutdownNow) + break; + + tmpWriteBuf.rewind(); + + snapshotMgr.checkPointCopyPage(fullId); + + int cacheId = fullId.cacheId(); + + GridCacheContext cacheCtx = context().cacheContext(cacheId); + + if (cacheCtx == null) + continue; + + PageMemoryEx pageMem = (PageMemoryEx) cacheCtx.memoryPolicy().pageMemory(); + + Integer tag = pageMem.getForCheckpoint(fullId, tmpWriteBuf); + + if (tag != null) { + tmpWriteBuf.rewind(); + + if (!skipCrc) { + PageIO.setCrc(writeAddr, PureJavaCrc32.calcCrc32(tmpWriteBuf, pageSize())); + + tmpWriteBuf.rewind(); + } + + snapshotMgr.checkPointBufferCopyPage(fullId, tmpWriteBuf); + + tmpWriteBuf.rewind(); + + PageIO.setCrc(writeAddr, 0); + + PageStore store = storeMgr.writeInternal(cacheId, fullId.pageId(), tmpWriteBuf, tag); + + updStores.add(store); + } + } + + doneFut.onDone((Void)null); + } + catch (Throwable e) { + doneFut.onDone(e); + } + } + } + + /** + * @param pageMem Page mem. + * @param cacheId Cache id. + * @param part Partition. + */ + static void completeSavingAllocatedIndex( + PageMemoryEx pageMem, IgniteWriteAheadLogManager wal, int cacheId, int part + ) throws IgniteCheckedException { + long pageId = getSuperPageId(pageMem, cacheId, part); + long page = pageMem.acquirePage(cacheId, pageId); + try { + long pageAddr = pageMem.writeLock(cacheId, pageId, page); + + boolean wasChanged = false; + + try { + assert PageIO.getPageId(pageAddr) != 0; + + int lastAllocatedIdx = metaIO.getLastPageCount(pageAddr); + int candidateAllocatedIdx = metaIO.getCandidatePageCount(pageAddr); + + if (lastAllocatedIdx != candidateAllocatedIdx) { + if (isWalDeltaRecordNeeded(pageMem, cacheId, pageId, page, wal, null)) + wal.log(new MetaPageUpdateLastAllocatedIndex(cacheId, pageId, candidateAllocatedIdx)); + + metaIO.setLastPageCount(pageAddr, candidateAllocatedIdx); + + wasChanged = true; + } + } + finally { + pageMem.writeUnlock(cacheId, pageId, page, null, wasChanged); + } + } + finally { + pageMem.releasePage(cacheId, pageId, page); + } + } + + /** + * @param pageMem Page mem. + * @param cacheId Cache id. + * @param part Partition. + */ + private static long getSuperPageId(PageMemoryEx pageMem, int cacheId, int part) throws IgniteCheckedException { + return part == PageIdAllocator.INDEX_PARTITION ? + pageMem.metaPageId(cacheId) : + pageMem.partitionMetaPageId(cacheId, part); + } + + /** + * + */ + private enum CheckpointEntryType { + /** */ + START, + + /** */ + END + } + + /** + * + */ + private static class Checkpoint { + /** Checkpoint entry. */ + private final CheckpointEntry cpEntry; + + /** Checkpoint pages. */ + private final GridMultiCollectionWrapper cpPages; + + /** */ + private final CheckpointProgress progress; + + /** Number of deleted WAL files. */ + private int walFilesDeleted; + + /** + * @param cpEntry Checkpoint entry. + * @param cpPages Pages to write to the page store. + * @param progress Checkpoint progress status. + */ + private Checkpoint( + CheckpointEntry cpEntry, + GridMultiCollectionWrapper cpPages, + CheckpointProgress progress + ) { + assert cpEntry.initGuard != 0; + + this.cpEntry = cpEntry; + this.cpPages = cpPages; + this.progress = progress; + } + } + + /** + * + */ + private static class CheckpointStatus { + /** Null checkpoint UUID. */ + private static final UUID NULL_UUID = new UUID(0L, 0L); + + /** Null WAL pointer. */ + private static final WALPointer NULL_PTR = new FileWALPointer(0, 0, 0); + + /** */ + private long cpStartTs; + + /** */ + private UUID cpStartId; + + /** */ + private WALPointer startPtr; + + /** */ + private UUID cpEndId; + + /** */ + private WALPointer endPtr; + + /** + * @param cpStartId Checkpoint start ID. + * @param startPtr Checkpoint start pointer. + * @param cpEndId Checkpoint end ID. + * @param endPtr Checkpoint end pointer. + */ + private CheckpointStatus(long cpStartTs, UUID cpStartId, WALPointer startPtr, UUID cpEndId, WALPointer endPtr) { + this.cpStartTs = cpStartTs; + this.cpStartId = cpStartId; + this.startPtr = startPtr; + this.cpEndId = cpEndId; + this.endPtr = endPtr; + } + + /** + * @return {@code True} if need to apply page log to restore tree structure. + */ + public boolean needRestoreMemory() { + return !F.eq(cpStartId, cpEndId) && !F.eq(NULL_UUID, cpStartId); + } + } + + /** + * + */ + public static class CheckpointProgress { + /** */ + private volatile long nextCpTs; + + /** */ + private GridFutureAdapter cpBeginFut = new GridFutureAdapter<>(); + + /** */ + private GridFutureAdapter cpFinishFut = new GridFutureAdapter<>(); + + /** */ + public volatile boolean nextSnapshot; + + /** */ + private volatile boolean started; + + /** */ + public volatile SnapshotOperation snapshotOperation; + + /** Wakeup reason. */ + private String reason; + + /** */ + private final PartitionDestroyQueue destroyQueue = new PartitionDestroyQueue(); + + /** + * @param nextCpTs Next checkpoint timestamp. + */ + private CheckpointProgress(long nextCpTs) { + this.nextCpTs = nextCpTs; + } + } + + /** + * + */ + private static class CheckpointProgressSnapshot { + /** */ + private final boolean started; + + /** */ + private final GridFutureAdapter cpBeginFut; + + /** */ + private final GridFutureAdapter cpFinishFut; + + /** */ + CheckpointProgressSnapshot(CheckpointProgress cpProgress) { + started = cpProgress.started; + cpBeginFut = cpProgress.cpBeginFut; + cpFinishFut = cpProgress.cpFinishFut; + } + } + + /** + * Checkpoint history. + */ + @SuppressWarnings("PublicInnerClass") + public class CheckpointHistory { + /** */ + private final NavigableMap histMap = new ConcurrentSkipListMap<>(); + + /** + * Load history form checkpoint directory. + * + * @param dir Checkpoint state dir. + */ + private void loadHistory(File dir) throws IgniteCheckedException { + if (!dir.exists()) + return; + + File[] files = dir.listFiles(CP_FILE_FILTER); + + if (!F.isEmpty(files)) { + Arrays.sort(files, CP_TS_COMPARATOR); + + ByteBuffer buf = ByteBuffer.allocate(16); + buf.order(ByteOrder.nativeOrder()); + + for (File file : files) { + Matcher matcher = CP_FILE_NAME_PATTERN.matcher(file.getName()); + + if (matcher.matches()) { + CheckpointEntryType type = CheckpointEntryType.valueOf(matcher.group(3)); + + if (type == CheckpointEntryType.START) { + long cpTs = Long.parseLong(matcher.group(1)); + WALPointer ptr = readPointer(file, buf); + + if (ptr == null) + continue; + + // Create lazy checkpoint entry. + CheckpointEntry entry = new CheckpointEntry(cpTs, ptr); + + histMap.put(cpTs, entry); + } + } + } + } + } + + /** + * @param cpTs Checkpoint timestamp. + * @return Initialized entry. + * @throws IgniteCheckedException If failed to initialize entry. + */ + private CheckpointEntry entry(Long cpTs) throws IgniteCheckedException { + CheckpointEntry entry = histMap.get(cpTs); + + if (entry == null) + throw new IgniteCheckedException("Checkpoint entry was removed: " + cpTs); + + entry.initIfNeeded(cctx); + + return entry; + } + + /** + * @return Collection of checkpoint timestamps. + */ + public Collection checkpoints() { + return histMap.keySet(); + } + + /** + * Adds checkpoint entry after the corresponding WAL record has been written to WAL. The checkpoint itself + * is not finished yet. + * + * @param entry Entry to ad. + */ + private void addCheckpointEntry(CheckpointEntry entry) { + histMap.put(entry.checkpointTimestamp(), entry); + } + + /** + * Clears checkpoint history. + */ + private int onCheckpointFinished() { + int deleted = 0; + + while (histMap.size() > dbCfg.getWalHistorySize()) { + Map.Entry entry = histMap.firstEntry(); + + CheckpointEntry cpEntry = entry.getValue(); + + if (cctx.wal().reserved(cpEntry.checkpointMark())) + break; + + File startFile = new File(cpDir.getAbsolutePath(), cpEntry.startFile()); + File endFile = new File(cpDir.getAbsolutePath(), cpEntry.endFile()); + + boolean rmvdStart = !startFile.exists() || startFile.delete(); + boolean rmvdEnd = !endFile.exists() || endFile.delete(); + + boolean fail = !rmvdStart || !rmvdEnd; + + if (fail) { + U.warn(log, "Failed to remove stale checkpoint files [startFile=" + startFile.getAbsolutePath() + + ", endFile=" + endFile.getAbsolutePath() + ']'); + + if (histMap.size() > 2 * dbCfg.getWalHistorySize()) { + U.error(log, "Too many stale checkpoint entries in the map, will truncate WAL archive anyway."); + + fail = false; + } + } + + if (!fail) { + deleted += cctx.wal().truncate(cpEntry.checkpointMark()); + + histMap.remove(entry.getKey()); + } + else + break; + } + + return deleted; + } + + /** + * + * @param cacheId Cache ID. + * @param partId Partition ID. + * @return Reserved counter or null if couldn't reserve. + */ + @Nullable private Long reserve(int cacheId, int partId) { + for (CheckpointEntry entry : histMap.values()) { + try { + entry.initIfNeeded(cctx); + + if (entry.cacheStates == null) + continue; + + CacheState cacheState = entry.cacheStates.get(cacheId); + + if (cacheState == null) + continue; + + CacheState.PartitionState partState = cacheState.partitions().get(partId); + + if (partState != null) { + if (cctx.wal().reserve(entry.checkpointMark())) + return partState.partitionCounter(); + } + } + catch (Exception e) { + U.error(log, "Error while trying to reserve history", e); + } + } + + return null; + } + } + + /** + * + */ + private static class CheckpointEntry { + /** */ + private static final AtomicIntegerFieldUpdater initGuardUpdater = + AtomicIntegerFieldUpdater.newUpdater(CheckpointEntry.class, "initGuard"); + + /** Checkpoint timestamp. */ + private long cpTs; + + /** Checkpoint end mark. */ + private WALPointer cpMark; + + /** Initialization latch. */ + private CountDownLatch initLatch; + + /** */ + @SuppressWarnings("unused") + private volatile int initGuard; + + /** Checkpoint ID. Initalized lazily. */ + private UUID cpId; + + /** Cache states. Initialized lazily. */ + private Map cacheStates; + + /** Initialization exception. */ + private IgniteCheckedException initEx; + + /** + * Lazy entry constructor. + * + * @param cpTs Checkpoint timestamp. + * @param cpMark Checkpoint WAL mark. + */ + private CheckpointEntry(long cpTs, WALPointer cpMark) { + assert cpMark != null; + + this.cpTs = cpTs; + this.cpMark = cpMark; + + initLatch = new CountDownLatch(1); + } + + /** + * Creates complete entry. + * + * @param cpTs Checkpoint timestamp. + * @param cpMark Checkpoint mark pointer. + * @param cpId Checkpoint ID. + * @param cacheStates Cache states. + */ + private CheckpointEntry(long cpTs, WALPointer cpMark, UUID cpId, Map cacheStates) { + this.cpTs = cpTs; + this.cpMark = cpMark; + this.cpId = cpId; + this.cacheStates = cacheStates; + + initGuard = 1; + initLatch = new CountDownLatch(0); + } + + /** + * @return Checkpoint timestamp. + */ + private long checkpointTimestamp() { + return cpTs; + } + + /** + * @return Checkpoint ID. + */ + private UUID checkpointId() { + return cpId; + } + + /** + * @return Checkpoint mark. + */ + private WALPointer checkpointMark() { + return cpMark; + } + + /** + * @return Start file name. + */ + private String startFile() { + return checkpointFileName(cpTs, cpId, CheckpointEntryType.START); + } + + /** + * @return End file name. + */ + private String endFile() { + return checkpointFileName(cpTs, cpId, CheckpointEntryType.END); + } + + /** + * @param cacheId Cache ID. + * @param part Partition ID. + * @return Partition counter or {@code null} if not found. + */ + private Long partitionCounter(int cacheId, int part) { + assert initGuard != 0; + + if (initEx != null || cacheStates == null) + return null; + + CacheState state = cacheStates.get(cacheId); + + if (state != null) { + CacheState.PartitionState partState = state.partitions().get(part); + + return partState == null ? null : partState.partitionCounter(); + } + + return null; + } + + /** + * @throws IgniteCheckedException If failed to read WAL entry. + */ + private void initIfNeeded(GridCacheSharedContext cctx) throws IgniteCheckedException { + if (initGuardUpdater.compareAndSet(this, 0, 1)) { + try (WALIterator it = cctx.wal().replay(cpMark)) { + if (it.hasNextX()) { + IgniteBiTuple tup = it.nextX(); + + CheckpointRecord rec = (CheckpointRecord)tup.get2(); + + cpId = rec.checkpointId(); + cacheStates = rec.cacheStates(); + } + else + initEx = new IgniteCheckedException("Failed to find checkpoint record at " + + "the given WAL pointer: " + cpMark); + } + catch (IgniteCheckedException e) { + initEx = e; + } + finally { + initLatch.countDown(); + } + } + else { + U.await(initLatch); + + if (initEx != null) + throw initEx; + } + } + } + + + + /** + * Partition destroy queue. + */ + private static class PartitionDestroyQueue { + /** */ + private final ConcurrentMap, PartitionDestroyRequest> pendingReqs = + new ConcurrentHashMap<>(); + + /** + * @param cacheCtx Cache context. + * @param partId Partition ID to destroy. + */ + private void addDestroyRequest(GridCacheContext cacheCtx, int partId) { + PartitionDestroyRequest req = new PartitionDestroyRequest(cacheCtx, partId); + + PartitionDestroyRequest old = pendingReqs.putIfAbsent(new T2<>(cacheCtx.cacheId(), partId), req); + + assert old == null : "Must wait for old destroy request to finish before adding a new one " + + "[cacheId=" + cacheCtx.cacheId() + ", cacheName=" + cacheCtx.name() + ", partId=" + partId + ']'; + } + + /** + * @param destroyId Destroy ID. + * @return Destroy request to complete if was not concurrently cancelled. + */ + private PartitionDestroyRequest beginDestroy(T2 destroyId) { + PartitionDestroyRequest rmvd = pendingReqs.remove(destroyId); + + return rmvd == null ? null : rmvd.beginDestroy() ? rmvd : null; + } + + /** + * @param cacheId Cache ID. + * @param partId Partition ID. + * @return Destroy request to wait for if destroy has begun. + */ + private PartitionDestroyRequest cancelDestroy(int cacheId, int partId) { + PartitionDestroyRequest rmvd = pendingReqs.remove(new T2<>(cacheId, partId)); + + return rmvd == null ? null : !rmvd.cancel() ? rmvd : null; + } + } + + /** + * Partition destroy request. + */ + private static class PartitionDestroyRequest { + /** */ + private int cacheId; + + /** */ + private String cacheName; + + /** */ + private int partId; + + /** */ + private boolean allowFastEviction; + + /** Destroy cancelled flag. */ + private boolean cancelled; + + /** Destroy future. Not null if partition destroy has begun. */ + private GridFutureAdapter destroyFut; + + /** + * @param cacheCtx Cache context. + * @param partId Partition ID. + */ + private PartitionDestroyRequest(GridCacheContext cacheCtx, int partId) { + cacheId = cacheCtx.cacheId(); + cacheName = cacheCtx.name(); + allowFastEviction = cacheCtx.allowFastEviction(); + + this.partId = partId; + } + + /** + * Cancels partition destroy request. + * + * @return {@code False} if this request needs to be waited for. + */ + private synchronized boolean cancel() { + if (destroyFut != null) { + assert !cancelled; + + return false; + } + + cancelled = true; + + return true; + } + + /** + * Initiates partition destroy. + * + * @return {@code True} if destroy request should be executed, {@code false} otherwise. + */ + private synchronized boolean beginDestroy() { + if (cancelled) { + assert destroyFut == null; + + return false; + } + + if (destroyFut != null) + return false; + + destroyFut = new GridFutureAdapter<>(); + + return true; + } + + /** + * + */ + private synchronized void onDone(Throwable err) { + assert destroyFut != null; + + destroyFut.onDone(err); + } + + /** + * + */ + private void waitCompleted() throws IgniteCheckedException { + GridFutureAdapter fut; + + synchronized (this) { + assert destroyFut != null; + + fut = destroyFut; + } + + fut.get(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "PartitionDestroyRequest [cacheId=" + cacheId + ", cacheName=" + cacheName + + ", partId=" + partId + ']'; + } + } + + /** + * + */ + private static class FileLockHolder { + /** Lock file name. */ + private static final String lockFileName = "lock"; + + /** File. */ + private File file; + + /** Channel. */ + private RandomAccessFile lockFile; + + /** Lock. */ + private FileLock lock; + + /** Id. */ + private GridKernalContext ctx; + + /** Logger. */ + private IgniteLogger log; + + /** + * @param path Path. + */ + private FileLockHolder(String path, GridKernalContext ctx, IgniteLogger log) { + try { + file = Paths.get(path, lockFileName).toFile(); + + lockFile = new RandomAccessFile(file, "rw"); + + this.ctx = ctx; + this.log = log; + } + catch (IOException e) { + throw new IgniteException(e); + } + } + + /** + * @param lockWaitTime During which time thread will try capture file lock. + * @throws IgniteCheckedException If failed to capture file lock. + */ + public void tryLock(int lockWaitTime) throws IgniteCheckedException { + assert lockFile != null; + + FileChannel ch = lockFile.getChannel(); + + SB sb = new SB(); + + //write node id + sb.a("[").a(ctx.localNodeId().toString()).a("]"); + + //write ip addresses + sb.a(ctx.discovery().localNode().addresses()); + + //write ports + sb.a("["); + Iterator it = ctx.ports().records().iterator(); + + while (it.hasNext()) { + GridPortRecord rec = it.next(); + + sb.a(rec.protocol()).a(":").a(rec.port()); + + if (it.hasNext()) + sb.a(", "); + } + + sb.a("]"); + + String failMsg; + + try { + String content = null; + + // Try to get lock, if not available wait 1 sec and re-try. + for (int i = 0; i < lockWaitTime; i += 1000) { + try { + lock = ch.tryLock(0, 1, false); + if (lock != null && lock.isValid()) { + writeContent(sb.toString()); + + return; + } + } + catch (OverlappingFileLockException ignore) { + if (content == null) + content = readContent(); + + log.warning("Failed to acquire file lock (already locked by " + content + + "), will try again in 1s: " + file.getAbsolutePath()); + } + + U.sleep(1000); + } + + if (content == null) + content = readContent(); + + failMsg = "Failed to acquire file lock during " + (lockWaitTime / 1000) + + " sec, (locked by " + content + "): " + file.getAbsolutePath(); + } + catch (Exception e) { + throw new IgniteCheckedException(e); + } + + if (failMsg != null) + throw new IgniteCheckedException(failMsg); + } + + /** + * Write node id (who captured lock) into lock file. + * + * @param content Node id. + * @throws IOException if some fail while write node it. + */ + private void writeContent(String content) throws IOException { + FileChannel ch = lockFile.getChannel(); + + byte[] bytes = content.getBytes(); + + ByteBuffer buf = ByteBuffer.allocate(bytes.length); + buf.put(bytes); + + buf.flip(); + + ch.write(buf, 1); + + ch.force(false); + } + + /** + * + */ + private String readContent() throws IOException { + FileChannel ch = lockFile.getChannel(); + + ByteBuffer buf = ByteBuffer.allocate((int)(ch.size() - 1)); + + ch.read(buf, 1); + + String content = new String(buf.array()); + + buf.clear(); + + return content; + } + + /** + * + */ + private void release() { + U.releaseQuiet(lock); + } + + /** + * + */ + private void close() { + U.closeQuiet(lockFile); + } + + /** + * @return Absolute path to lock file. + */ + private String lockPath() { + return file.getAbsolutePath(); + } + } +} \ No newline at end of file diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PageIdIterable.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PageIdIterable.java new file mode 100644 index 0000000000000..a5891fb931957 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PageIdIterable.java @@ -0,0 +1,24 @@ +package org.apache.ignite.internal.processors.cache.database; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public interface PageIdIterable extends Iterable { + /** */ + public boolean contains(FullPageId fullId) throws IgniteCheckedException; + + /** */ + @Nullable public FullPageId next(@Nullable FullPageId fullId); + + /** */ + public double progress(FullPageId curr); + + /** + * + */ + public boolean isEmpty(); +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java new file mode 100755 index 0000000000000..02fa6b918a1a5 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java @@ -0,0 +1,520 @@ +package org.apache.ignite.internal.processors.cache.database.file; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.FileChannel; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.pagemem.store.PageStore; +import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.database.wal.crc.IgniteDataIntegrityViolationException; +import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; +import org.apache.ignite.internal.util.typedef.internal.U; + +import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC; + +/** + * File page store. + */ +public class FilePageStore implements PageStore { + /** Page store file signature. */ + private static final long SIGNATURE = 0xF19AC4FE60C530B8L; + + /** File version. */ + private static final int VERSION = 1; + + /** Allocated field offset. */ + public static final int HEADER_SIZE = 8/*SIGNATURE*/ + 4/*VERSION*/ + 1/*type*/ + 4/*page size*/; + + /** */ + private final File cfgFile; + + /** */ + private final byte type; + + /** Database configuration. */ + private final MemoryConfiguration dbCfg; + + /** */ + private RandomAccessFile file; + + /** */ + private FileChannel ch; + + /** */ + private final AtomicLong allocated; + + /** */ + private final int pageSize; + + /** */ + private volatile boolean inited; + + /** */ + private volatile boolean recover; + + /** */ + private volatile int tag; + + /** */ + private boolean skipCrc = IgniteSystemProperties.getBoolean(IGNITE_PDS_SKIP_CRC, false); + + /** */ + private final ReadWriteLock lock = new ReentrantReadWriteLock(); + + /** + * @param file File. + */ + public FilePageStore(byte type, File file, MemoryConfiguration cfg) { + this.type = type; + + cfgFile = file; + dbCfg = cfg; + + allocated = new AtomicLong(); + + pageSize = dbCfg.getPageSize(); + } + + /** {@inheritDoc} */ + @Override public boolean exists() { + return cfgFile.exists() && cfgFile.length() > HEADER_SIZE; + } + + /** + * @param type Type. + * @param pageSize Page size. + * @return Byte buffer instance. + */ + public static ByteBuffer header(byte type, int pageSize) { + ByteBuffer hdr = ByteBuffer.allocate(HEADER_SIZE).order(ByteOrder.LITTLE_ENDIAN); + + hdr.putLong(SIGNATURE); + + hdr.putInt(VERSION); + + hdr.put(type); + + hdr.putInt(pageSize); + + hdr.rewind(); + + return hdr; + } + + /** + * + */ + private long initFile() { + try { + ByteBuffer hdr = header(type, dbCfg.getPageSize()); + + while (hdr.remaining() > 0) + ch.write(hdr); + } + catch (IOException e) { + throw new IgniteException("Check file failed.", e); + } + + //there is 'super' page in every file + return HEADER_SIZE + dbCfg.getPageSize(); + } + + /** + * + */ + private long checkFile() throws IgniteCheckedException { + try { + ByteBuffer hdr = ByteBuffer.allocate(HEADER_SIZE).order(ByteOrder.LITTLE_ENDIAN); + + while (hdr.remaining() > 0) + ch.read(hdr); + + hdr.rewind(); + + long signature = hdr.getLong(); + + if (SIGNATURE != signature) + throw new IgniteCheckedException("Failed to verify store file (invalid file signature)" + + " [expectedSignature=" + U.hexLong(SIGNATURE) + + ", actualSignature=" + U.hexLong(signature) + ']'); + + int ver = hdr.getInt(); + + if (VERSION != ver) + throw new IgniteCheckedException("Failed to verify store file (invalid file version)" + + " [expectedVersion=" + VERSION + + ", fileVersion=" + ver + "]"); + + byte type = hdr.get(); + + if (this.type != type) + throw new IgniteCheckedException("Failed to verify store file (invalid file type)" + + " [expectedFileType=" + this.type + + ", actualFileType=" + type + "]"); + + int pageSize = hdr.getInt(); + + if (dbCfg.getPageSize() != pageSize) + throw new IgniteCheckedException("Failed to verify store file (invalid page size)" + + " [expectedPageSize=" + dbCfg.getPageSize() + + ", filePageSize=" + pageSize + "]"); + + long fileSize = file.length(); + + if (fileSize == HEADER_SIZE) // Every file has a special meta page. + fileSize = pageSize + HEADER_SIZE; + + if ((fileSize - HEADER_SIZE) % pageSize != 0) + throw new IgniteCheckedException("Failed to verify store file (invalid file size)" + + " [fileSize=" + U.hexLong(fileSize) + + ", pageSize=" + U.hexLong(pageSize) + ']'); + + return fileSize; + } + catch (IOException e) { + throw new IgniteCheckedException("File check failed", e); + } + } + + /** + * @param cleanFile {@code True} to delete file. + * @throws IgniteCheckedException If failed. + */ + public void stop(boolean cleanFile) throws IgniteCheckedException { + lock.writeLock().lock(); + + try { + if (!inited) + return; + + ch.force(false); + + file.close(); + + if (cleanFile) + cfgFile.delete(); + } + catch (IOException e) { + throw new IgniteCheckedException(e); + } + finally { + lock.writeLock().unlock(); + } + } + + /** + * + */ + public void truncate(int tag) throws IgniteCheckedException { + lock.writeLock().lock(); + + try { + if (!inited) + return; + + this.tag = tag; + + ch.position(0); + + file.setLength(0); + + allocated.set(initFile()); + } + catch (IOException e) { + throw new IgniteCheckedException(e); + } + finally { + lock.writeLock().unlock(); + } + } + + /** + * + */ + public void beginRecover() { + lock.writeLock().lock(); + + try { + recover = true; + } + finally { + lock.writeLock().unlock(); + } + } + + /** + * + */ + public void finishRecover() { + lock.writeLock().lock(); + + try { + if (inited) + allocated.set(ch.size()); + + recover = false; + } + catch (IOException e) { + throw new RuntimeException(e); + } + finally { + lock.writeLock().unlock(); + } + } + + /** {@inheritDoc} */ + @Override public void read(long pageId, ByteBuffer pageBuf, boolean keepCrc) throws IgniteCheckedException { + init(); + + try { + long off = pageOffset(pageId); + + assert pageBuf.capacity() == pageSize; + assert pageBuf.position() == 0; + assert pageBuf.order() == ByteOrder.nativeOrder(); + + int len = pageSize; + + do { + int n = ch.read(pageBuf, off); + + // If page was not written yet, nothing to read. + if (n < 0) { + pageBuf.put(new byte[pageBuf.remaining()]); + + return; + } + + off += n; + + len -= n; + } + while (len > 0); + + int savedCrc32 = PageIO.getCrc(pageBuf); + + PageIO.setCrc(pageBuf, 0); + + pageBuf.position(0); + + if (!skipCrc) { + int curCrc32 = PureJavaCrc32.calcCrc32(pageBuf, pageSize); + + if ((savedCrc32 ^ curCrc32) != 0) + throw new IgniteDataIntegrityViolationException("Failed to read page (CRC validation failed) " + + "[id=" + U.hexLong(pageId) + ", off=" + (off - pageSize) + + ", file=" + cfgFile.getAbsolutePath() + ", fileSize=" + ch.size() + + ", savedCrc=" + U.hexInt(savedCrc32) + ", curCrc=" + U.hexInt(curCrc32) + "]"); + } + + assert PageIO.getCrc(pageBuf) == 0; + + if (keepCrc) + PageIO.setCrc(pageBuf, savedCrc32); + } + catch (IOException e) { + throw new IgniteCheckedException("Read error", e); + } + } + + /** {@inheritDoc} */ + @Override public void readHeader(ByteBuffer buf) throws IgniteCheckedException { + init(); + + try { + assert buf.remaining() == HEADER_SIZE; + + int len = HEADER_SIZE; + + long off = 0; + + do { + int n = ch.read(buf, off); + + // If page was not written yet, nothing to read. + if (n < 0) + return; + + off += n; + + len -= n; + } + while (len > 0); + } + catch (IOException e) { + throw new IgniteCheckedException("Read error", e); + } + } + + /** + * @throws IgniteCheckedException If failed to initialize store file. + */ + private void init() throws IgniteCheckedException { + if (!inited) { + lock.writeLock().lock(); + + try { + if (!inited) { + RandomAccessFile rndFile = null; + + IgniteCheckedException err = null; + + try { + file = rndFile = new RandomAccessFile(cfgFile, "rw"); + + ch = file.getChannel(); + + if (file.length() == 0) + allocated.set(initFile()); + else + allocated.set(checkFile()); + + inited = true; + } + catch (IOException e) { + throw err = new IgniteCheckedException("Can't open file: " + cfgFile.getName(), e); + } + finally { + if (err != null && rndFile != null) + try { + rndFile.close(); + } + catch (IOException e) { + err.addSuppressed(e); + } + } + } + } + finally { + lock.writeLock().unlock(); + } + } + } + + /** {@inheritDoc} */ + @Override public void write(long pageId, ByteBuffer pageBuf, int tag) throws IgniteCheckedException { + init(); + + lock.readLock().lock(); + + try { + if (tag < this.tag) + return; + + long off = pageOffset(pageId); + + assert (off >= 0 && off + pageSize <= allocated.get() + HEADER_SIZE) || recover : + "off=" + U.hexLong(off) + ", allocated=" + U.hexLong(allocated.get()) + ", pageId=" + U.hexLong(pageId); + + assert pageBuf.capacity() == pageSize; + assert pageBuf.position() == 0; + assert pageBuf.order() == ByteOrder.nativeOrder(); + + int len = pageSize; + + assert PageIO.getCrc(pageBuf) == 0 : U.hexLong(pageId); + + int crc32 = skipCrc ? 0 : PureJavaCrc32.calcCrc32(pageBuf, pageSize); + + PageIO.setCrc(pageBuf, crc32); + + pageBuf.position(0); + + do { + int n = ch.write(pageBuf, off); + + off += n; + + len -= n; + } + while (len > 0); + + PageIO.setCrc(pageBuf, 0); + } + catch (IOException e) { + throw new IgniteCheckedException("Failed to write the page to the file store [pageId=" + pageId + + ", file=" + cfgFile.getAbsolutePath() + ']', e); + } + finally { + lock.readLock().unlock(); + } + } + + /** {@inheritDoc} */ + @Override public long pageOffset(long pageId) { + return (long) PageIdUtils.pageIndex(pageId) * pageSize + HEADER_SIZE; + } + + /** {@inheritDoc} */ + @Override public void sync() throws IgniteCheckedException { + lock.writeLock().lock(); + + try { + init(); + + ch.force(false); + } + catch (IOException e) { + throw new IgniteCheckedException("Sync error", e); + } + finally { + lock.writeLock().unlock(); + } + } + + /** {@inheritDoc} */ + @Override public synchronized void ensure() throws IgniteCheckedException { + init(); + } + + /** {@inheritDoc} */ + @Override public long allocatePage() throws IgniteCheckedException { + init(); + + long off = allocPage(); + + return off / pageSize; + } + + /** + * + */ + private long allocPage() { + long off; + + do { + off = allocated.get(); + + if (allocated.compareAndSet(off, off + pageSize)) + break; + } + while (true); + + return off; + } + + /** {@inheritDoc} */ + @Override public int pages() { + if (!inited) + return 0; + + return (int)(allocated.get() / pageSize); + } + + /** + * Visible for testing + */ + FileChannel getCh() { + return ch; + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java new file mode 100755 index 0000000000000..fdfd3e0e07606 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java @@ -0,0 +1,568 @@ +package org.apache.ignite.internal.processors.cache.database.file; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.pagemem.PageIdAllocator; +import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; +import org.apache.ignite.internal.pagemem.store.PageStore; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager; +import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.Marshaller; +import org.apache.ignite.marshaller.jdk.JdkMarshaller; +import org.jetbrains.annotations.Nullable; + +/** + * File page store manager. + */ +public class FilePageStoreManager extends GridCacheSharedManagerAdapter implements IgnitePageStoreManager { + /** File suffix. */ + public static final String FILE_SUFFIX = ".bin"; + + /** Partition file prefix. */ + public static final String PART_FILE_PREFIX = "part-"; + + /** */ + public static final String INDEX_FILE_NAME = "index" + FILE_SUFFIX; + + /** */ + public static final String PART_FILE_TEMPLATE = PART_FILE_PREFIX+ "%d" + FILE_SUFFIX; + + /** */ + public static final String CACHE_DIR_PREFIX = "cache-"; + + /** */ + public static final String CACHE_CONF_FILENAME = "conf.dat"; + + /** Marshaller. */ + private static final Marshaller marshaller = new JdkMarshaller(); + + /** */ + private final Map idxCacheStores = new ConcurrentHashMap<>(); + + /** */ + private final IgniteConfiguration igniteCfg; + + /** */ + private PersistenceConfiguration pstCfg; + + /** Absolute directory for file page store */ + private File storeWorkDir; + + /** */ + private final long metaPageId = PageIdUtils.pageId(-1, PageMemory.FLAG_IDX, 0); + + /** */ + private final Set cachesWithoutIdx = Collections.newSetFromMap(new ConcurrentHashMap()); + + /** + * @param igniteCfg Ignite configuration. + */ + public FilePageStoreManager(IgniteConfiguration igniteCfg) { + PersistenceConfiguration pstCfg = igniteCfg.getPersistenceConfiguration(); + + assert pstCfg != null : "WAL should not be created if persistence is disabled."; + + this.pstCfg = pstCfg; + this.igniteCfg = igniteCfg; + } + + /** {@inheritDoc} */ + @Override public void start0() throws IgniteCheckedException { + if (cctx.kernalContext().clientNode()) + return; + + String consId = U.maskForFileName(cctx.kernalContext().discovery().consistentId().toString()); + + if (pstCfg.getPersistenceStorePath() != null) { + File workDir0 = new File(pstCfg.getPersistenceStorePath()); + if (!workDir0.isAbsolute()) + workDir0 = U.resolveWorkDirectory(igniteCfg.getWorkDirectory(), pstCfg.getPersistenceStorePath(), false); + storeWorkDir = new File(workDir0, consId); + } + else + storeWorkDir = new File(U.resolveWorkDirectory(igniteCfg.getWorkDirectory(), "db", false), consId); + + U.ensureDirectory(storeWorkDir, "page store work directory", log); + } + + /** {@inheritDoc} */ + @Override public void stop0(boolean cancel) { + if (log.isDebugEnabled()) + log.debug("Stopping page store manager."); + + IgniteCheckedException ex = shutdown(false); + + if (ex != null) + U.error(log, "Failed to gracefully stop page store manager", ex); + } + + /** {@inheritDoc} */ + @Override public void onActivate(GridKernalContext kctx) throws IgniteCheckedException { + if (log.isDebugEnabled()) + log.debug("Activate page store manager [id=" + cctx.localNodeId() + + " topVer=" + cctx.discovery().topologyVersionEx() + " ]"); + + start0(); + } + + /** {@inheritDoc} */ + @Override public void onDeActivate(GridKernalContext kctx) throws IgniteCheckedException { + if (log.isDebugEnabled()) + log.debug("DeActivate page store manager [id=" + cctx.localNodeId() + + " topVer=" + cctx.discovery().topologyVersionEx() + " ]"); + + stop0(true); + } + + /** {@inheritDoc} */ + @Override public void beginRecover() { + for (CacheStoreHolder holder : idxCacheStores.values()) { + holder.idxStore.beginRecover(); + + for (FilePageStore partStore : holder.partStores) + partStore.beginRecover(); + } + } + + /** {@inheritDoc} */ + @Override public void finishRecover() { + for (CacheStoreHolder holder : idxCacheStores.values()) { + holder.idxStore.finishRecover(); + + for (FilePageStore partStore : holder.partStores) + partStore.finishRecover(); + } + } + + /** {@inheritDoc} */ + @Override public void initializeForCache(CacheConfiguration ccfg) throws IgniteCheckedException { + int cacheId = CU.cacheId(ccfg.getName()); + + if (!idxCacheStores.containsKey(cacheId)) { + CacheStoreHolder holder = initForCache(ccfg); + + CacheStoreHolder old = idxCacheStores.put(cacheId, holder); + + assert old == null : "Non-null old store holder for cache: " + ccfg.getName(); + } + } + + /** {@inheritDoc} */ + @Override public void shutdownForCache(GridCacheContext cacheCtx, boolean destroy) throws IgniteCheckedException { + cachesWithoutIdx.remove(cacheCtx.cacheId()); + + CacheStoreHolder old = idxCacheStores.remove(cacheCtx.cacheId()); + + assert old != null : "Missing cache store holder [cache=" + cacheCtx.name() + + ", locNodeId=" + cctx.localNodeId() + ", gridName=" + cctx.igniteInstanceName() + ']'; + + IgniteCheckedException ex = shutdown(old, /*clean files if destroy*/destroy, null); + + if (ex != null) + throw ex; + } + + /** {@inheritDoc} */ + @Override public void onPartitionCreated(int cacheId, int partId) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onPartitionDestroyed(int cacheId, int partId, int tag) throws IgniteCheckedException { + assert partId <= PageIdAllocator.MAX_PARTITION_ID; + + PageStore store = getStore(cacheId, partId); + + assert store instanceof FilePageStore; + + ((FilePageStore)store).truncate(tag); + } + + /** {@inheritDoc} */ + @Override public void read(int cacheId, long pageId, ByteBuffer pageBuf) throws IgniteCheckedException { + read(cacheId, pageId, pageBuf, false); + } + + /** + * Will preserve crc in buffer if keepCrc is true. + * + * @param cacheId Cache ID. + * @param pageId Page ID. + * @param pageBuf Page buffer. + * @param keepCrc Keep CRC flag. + * @throws IgniteCheckedException If failed. + */ + public void read(int cacheId, long pageId, ByteBuffer pageBuf, boolean keepCrc) throws IgniteCheckedException { + PageStore store = getStore(cacheId, PageIdUtils.partId(pageId)); + + store.read(pageId, pageBuf, keepCrc); + } + + /** {@inheritDoc} */ + @Override public boolean exists(int cacheId, int partId) throws IgniteCheckedException { + PageStore store = getStore(cacheId, partId); + + return store.exists(); + } + + /** {@inheritDoc} */ + @Override public void readHeader(int cacheId, int partId, ByteBuffer buf) throws IgniteCheckedException { + PageStore store = getStore(cacheId, partId); + + store.readHeader(buf); + } + + /** {@inheritDoc} */ + @Override public void write(int cacheId, long pageId, ByteBuffer pageBuf,int tag) throws IgniteCheckedException { + writeInternal(cacheId, pageId, pageBuf, tag); + } + + /** {@inheritDoc} */ + @Override public long pageOffset(int cacheId, long pageId) throws IgniteCheckedException { + PageStore store = getStore(cacheId, PageIdUtils.partId(pageId)); + + return store.pageOffset(pageId); + } + + /** + * @param cacheId Cache ID to write. + * @param pageId Page ID. + * @param pageBuf Page buffer. + * @return PageStore to which the page has been written. + * @throws IgniteCheckedException If IO error occurred. + */ + public PageStore writeInternal(int cacheId, long pageId, ByteBuffer pageBuf, int tag) throws IgniteCheckedException { + int partId = PageIdUtils.partId(pageId); + + PageStore store = getStore(cacheId, partId); + + store.write(pageId, pageBuf, tag); + + return store; + } + + /** + * @param ccfg Cache configuration. + * @return Cache store holder. + * @throws IgniteCheckedException If failed. + */ + private CacheStoreHolder initForCache(CacheConfiguration ccfg) throws IgniteCheckedException { + File cacheWorkDir = new File(storeWorkDir, CACHE_DIR_PREFIX + ccfg.getName()); + + boolean dirExisted = false; + + if (!cacheWorkDir.exists()) { + boolean res = cacheWorkDir.mkdirs(); + + if (!res) + throw new IgniteCheckedException("Failed to initialize cache working directory " + + "(failed to create, make sure the work folder has correct permissions): " + + cacheWorkDir.getAbsolutePath()); + } + else { + if (cacheWorkDir.isFile()) + throw new IgniteCheckedException("Failed to initialize cache working directory " + + "(a file with the same name already exists): " + cacheWorkDir.getAbsolutePath()); + + File lockF = new File(cacheWorkDir, IgniteCacheSnapshotManager.SNAPSHOT_RESTORE_STARTED_LOCK_FILENAME); + + if (lockF.exists()) { + Path tmp = cacheWorkDir.toPath().getParent().resolve(cacheWorkDir.getName() + ".tmp"); + + boolean deleted = U.delete(cacheWorkDir); + + if (Files.exists(tmp) && Files.isDirectory(tmp)) { + U.warn(log, "Ignite node crashed during the snapshot restore process " + + "(there is a snapshot restore lock file left for cache). But old version of cache was saved. " + + "Trying to restore it. Cache - [" + cacheWorkDir.getAbsolutePath() + ']'); + + try { + Files.move(tmp, cacheWorkDir.toPath()); + } + catch (IOException e) { + throw new IgniteCheckedException(e); + } + } else { + U.warn(log, "Ignite node crashed during the snapshot restore process " + + "(there is a snapshot restore lock file left for cache). Will remove both the lock file and " + + "incomplete cache directory [cacheDir=" + cacheWorkDir.getAbsolutePath() + ']'); + + if (!deleted) + throw new IgniteCheckedException("Failed to remove obsolete cache working directory " + + "(remove the directory manually and make sure the work folder has correct permissions): " + + cacheWorkDir.getAbsolutePath()); + + cacheWorkDir.mkdirs(); + } + + if (!cacheWorkDir.exists()) + throw new IgniteCheckedException("Failed to initialize cache working directory " + + "(failed to create, make sure the work folder has correct permissions): " + + cacheWorkDir.getAbsolutePath()); + } + else + dirExisted = true; + } + + File file = new File(cacheWorkDir, CACHE_CONF_FILENAME); + + if (!file.exists() || file.length() == 0) { + try { + file.createNewFile(); + + try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(file))) { + marshaller.marshal(ccfg, stream); + } + } + catch (IOException ex) { + throw new IgniteCheckedException("Failed to persist cache configuration: " + ccfg.getName(), ex); + } + } + + File idxFile = new File(cacheWorkDir, INDEX_FILE_NAME); + + if (dirExisted && !idxFile.exists()) + cachesWithoutIdx.add(CU.cacheId(ccfg.getName())); + + FilePageStore idxStore = new FilePageStore( + PageMemory.FLAG_IDX, + idxFile, + cctx.kernalContext().config().getMemoryConfiguration()); + + FilePageStore[] partStores = new FilePageStore[ccfg.getAffinity().partitions()]; + + for (int partId = 0; partId < partStores.length; partId++) { + FilePageStore partStore = new FilePageStore( + PageMemory.FLAG_DATA, + new File(cacheWorkDir, String.format(PART_FILE_TEMPLATE, partId)), + cctx.kernalContext().config().getMemoryConfiguration() + ); + + partStores[partId] = partStore; + } + + return new CacheStoreHolder(idxStore, partStores); + } + + /** {@inheritDoc} */ + @Override public void sync(int cacheId, int partId) throws IgniteCheckedException { + getStore(cacheId, partId).sync(); + } + + /** {@inheritDoc} */ + @Override public void ensure(int cacheId, int partId) throws IgniteCheckedException { + getStore(cacheId, partId).ensure(); + } + + /** {@inheritDoc} */ + @Override public long allocatePage(int cacheId, int partId, byte flags) throws IgniteCheckedException { + assert partId <= PageIdAllocator.MAX_PARTITION_ID || partId == PageIdAllocator.INDEX_PARTITION; + + PageStore store = getStore(cacheId, partId); + + long pageIdx = store.allocatePage(); + + return PageIdUtils.pageId(partId, flags, (int)pageIdx); + } + + /** {@inheritDoc} */ + @Override public long metaPageId(final int cacheId) { + return metaPageId; + } + + /** {@inheritDoc} */ + @Override public int pages(int cacheId, int partId) throws IgniteCheckedException { + PageStore store = getStore(cacheId, partId); + + return store.pages(); + } + + /** {@inheritDoc} */ + @Override public Set savedCacheNames() { + if (cctx.kernalContext().clientNode()) + return Collections.emptySet(); + + File[] files = storeWorkDir.listFiles(); + + if (files == null) + return Collections.emptySet(); + + Set cacheNames = new HashSet<>(); + + for (File file : files) { + if (file.isDirectory() && file.getName().startsWith(CACHE_DIR_PREFIX)) { + File conf = new File(file, CACHE_CONF_FILENAME); + if (conf.exists() && conf.length() > 0) { + String name = file.getName().substring(CACHE_DIR_PREFIX.length()); + + // TODO remove when fixed null cache names. + if ("null".equals(name)) + name = null; + + cacheNames.add(name); + } + } + } + + return cacheNames; + } + + /** {@inheritDoc} */ + @Override public CacheConfiguration readConfiguration(String cacheName) { + File file = new File(storeWorkDir, CACHE_DIR_PREFIX + cacheName); + + assert file.exists() && file.isDirectory(); + + try (InputStream stream = new BufferedInputStream(new FileInputStream(new File(file, CACHE_CONF_FILENAME)))) { + return marshaller.unmarshal(stream, U.resolveClassLoader(igniteCfg)); + } + catch (IOException | IgniteCheckedException e) { + throw new IllegalStateException("Failed to read cache configuration from disk for cache: " + cacheName, e); + } + } + + /** {@inheritDoc} */ + @Override public boolean hasIndexStore(int cacheId) { + return !cachesWithoutIdx.contains(cacheId); + } + + /** + * @return Store work dir. + */ + public File workDir() { + return storeWorkDir; + } + + /** + * @param cacheName Cache name. + * @return Store dir for given cache. + */ + public File cacheWorkDir(String cacheName) { + return new File(storeWorkDir, "cache-" + cacheName); + } + + /** + * @param cleanFiles {@code True} if the stores should delete it's files upon close. + */ + private IgniteCheckedException shutdown(boolean cleanFiles) { + IgniteCheckedException ex = null; + + for (CacheStoreHolder holder : idxCacheStores.values()) + ex = shutdown(holder, cleanFiles, ex); + + return ex; + } + + /** + * @param holder Store holder. + * @param cleanFile {@code True} if files should be cleaned. + * @param aggr Aggregating exception. + * @return Aggregating exception, if error occurred. + */ + private IgniteCheckedException shutdown(CacheStoreHolder holder, boolean cleanFile, + @Nullable IgniteCheckedException aggr) { + aggr = shutdown(holder.idxStore, cleanFile, aggr); + + for (FilePageStore store : holder.partStores) { + if (store != null) + aggr = shutdown(store, cleanFile, aggr); + } + + return aggr; + } + + /** + * @param store Store to shutdown. + * @param cleanFile {@code True} if files should be cleaned. + * @param aggr Aggregating exception. + * @return Aggregating exception, if error occurred. + */ + private IgniteCheckedException shutdown(FilePageStore store, boolean cleanFile, IgniteCheckedException aggr) { + try { + if (store != null) + store.stop(cleanFile); + } + catch (IgniteCheckedException e) { + if (aggr == null) + aggr = new IgniteCheckedException("Failed to gracefully shutdown store"); + + aggr.addSuppressed(e); + } + + return aggr; + } + + /** + * @param cacheId Cache ID. + * @param partId Partition ID. + * @return Page store for the corresponding parameters. + * @throws IgniteCheckedException If cache or partition with the given ID was not created. + * + * Note: visible for testing. + */ + public PageStore getStore(int cacheId, int partId) throws IgniteCheckedException { + CacheStoreHolder holder = idxCacheStores.get(cacheId); + + if (holder == null) + throw new IgniteCheckedException("Failed to get page store for the given cache ID " + + "(cache has not been started): " + cacheId); + + if (partId == PageIdAllocator.INDEX_PARTITION) + return holder.idxStore; + + if (partId > PageIdAllocator.MAX_PARTITION_ID) + throw new IgniteCheckedException("Partition ID is reserved: " + partId); + + FilePageStore store = holder.partStores[partId]; + + if (store == null) + throw new IgniteCheckedException("Failed to get page store for the given partition ID " + + "(partition has not been created) [cacheId=" + cacheId + ", partId=" + partId + ']'); + + return store; + } + + /** + * + */ + private static class CacheStoreHolder { + /** Index store. */ + private final FilePageStore idxStore; + + /** Partition stores. */ + private final FilePageStore[] partStores; + + /** + * + */ + public CacheStoreHolder(FilePageStore idxStore, FilePageStore[] partStores) { + this.idxStore = idxStore; + this.partStores = partStores; + } + } + +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/EvictCandidate.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/EvictCandidate.java new file mode 100644 index 0000000000000..96dbdb289704c --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/EvictCandidate.java @@ -0,0 +1,60 @@ +package org.apache.ignite.internal.processors.cache.database.pagemem; + +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.util.tostring.GridToStringExclude; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** + * + */ +public class EvictCandidate { + /** */ + private int tag; + + /** */ + @GridToStringExclude + private long relPtr; + + /** */ + @GridToStringInclude + private FullPageId fullId; + + /** + * @param tag Tag. + * @param relPtr Relative pointer. + * @param fullId Full page ID. + */ + public EvictCandidate(int tag, long relPtr, FullPageId fullId) { + this.tag = tag; + this.relPtr = relPtr; + this.fullId = fullId; + } + + /** + * @return Tag. + */ + public int tag() { + return tag; + } + + /** + * @return Relative pointer. + */ + public long relativePointer() { + return relPtr; + } + + /** + * @return Index. + */ + public FullPageId fullId() { + return fullId; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(EvictCandidate.class, this, "relPtr", U.hexLong(relPtr)); + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java new file mode 100644 index 0000000000000..2c5099843e543 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java @@ -0,0 +1,534 @@ +package org.apache.ignite.internal.processors.cache.database.pagemem; + +import org.apache.ignite.internal.mem.IgniteOutOfMemoryException; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.util.GridUnsafe; +import org.apache.ignite.internal.util.lang.GridPredicate3; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiInClosure; + +import static org.apache.ignite.IgniteSystemProperties.IGNITE_LONG_LONG_HASH_MAP_LOAD_FACTOR; +import static org.apache.ignite.IgniteSystemProperties.getFloat; + +/** + * + */ +public class FullPageIdTable { + /** Load factor. */ + private static final float LOAD_FACTOR = getFloat(IGNITE_LONG_LONG_HASH_MAP_LOAD_FACTOR, 2.5f); + + /** */ + private static final int BYTES_PER_ENTRY = /*cache ID*/4 + /*partition tag*/4 + /*page ID*/8 + /*pointer*/8; + + /** */ + private static final FullPageId EMPTY_FULL_PAGE_ID = new FullPageId(0, 0); + + /** */ + private static final long EMPTY_PAGE_ID = EMPTY_FULL_PAGE_ID.pageId(); + + /** */ + private static final int EMPTY_CACHE_ID = EMPTY_FULL_PAGE_ID.cacheId(); + + /** */ + private static final long REMOVED_PAGE_ID = 0x8000000000000000L; + + /** */ + private static final int REMOVED_CACHE_ID = 0; + + /** */ + private static final int EQUAL = 0; + + /** */ + private static final int EMPTY = 1; + + /** */ + private static final int REMOVED = -1; + + /** */ + private static final int NOT_EQUAL = 2; + + /** */ + private static final int OUTDATED = -3; + + /** Max size, in elements. */ + protected int capacity; + + /** Maximum number of steps to try before failing. */ + protected int maxSteps; + + /** Pointer to the values array. */ + protected long valPtr; + + /** + * @return Estimated memory size required for this map to store the given number of elements. + */ + public static long requiredMemory(long elementCnt) { + assert LOAD_FACTOR != 0; + + return ((long)(elementCnt * LOAD_FACTOR)) * BYTES_PER_ENTRY + 8; + } + + /** + * @param addr Base address. + * @param len Allocated memory length. + * @param clear If {@code true}, then memory is considered dirty and will be cleared. Otherwise, + * map will assume that the given memory region is in valid state. + */ + public FullPageIdTable(long addr, long len, boolean clear) { + valPtr = addr; + capacity = (int)((len - 8) / BYTES_PER_ENTRY); + + maxSteps = capacity; + + if (clear) + clear(); + } + + /** + * @return Current number of entries in the map. + */ + public final int size() { + return GridUnsafe.getInt(valPtr); + } + + /** + * @return Maximum number of entries in the map. This maximum can not be always reached. + */ + public final int capacity() { + return capacity; + } + + /** + * Gets value associated with the given key. + * + * @param cacheId Cache ID. + * @param pageId Page ID. + * @return A value associated with the given key. + */ + public long get(int cacheId, long pageId, int tag, long absent, long outdated) { + assert assertKey(cacheId, pageId); + + int idx = getKey(cacheId, pageId, tag, false); + + if (idx == -1) + return absent; + + if (idx == -2) + return outdated; + + return valueAt(idx); + } + + /** + * Refresh outdated value. + * + * @param cacheId Cache ID. + * @param pageId Page ID. + * @param tag Partition tag. + * @return A value associated with the given key. + */ + public long refresh(int cacheId, long pageId, int tag) { + assert assertKey(cacheId, pageId); + + int idx = getKey(cacheId, pageId, tag, true); + + assert idx >= 0 : "[idx=" + idx + ", tag=" + tag + ", cacheId=" + cacheId + + ", pageId=" + U.hexLong(pageId) + ']'; + + assert tagAt(idx) < tag : "[idx=" + idx + ", tag=" + tag + ", cacheId=" + cacheId + + ", pageId=" + U.hexLong(pageId) + ", tagAtIdx=" + tagAt(idx) + ']'; + + setTagAt(idx, tag); + + return valueAt(idx); + } + + /** + * Associates the given key with the given value. + * @param cacheId Cache ID + * @param pageId Page ID. + * @param value Value to set. + */ + public void put(int cacheId, long pageId, long value, int tag) { + assert assertKey(cacheId, pageId); + + int index = putKey(cacheId, pageId, tag); + + setValueAt(index, value); + } + + /** + * Removes key-value association for the given key. + * + * @param cacheId Cache ID. + * @param pageId Page ID. + */ + public void remove(int cacheId, long pageId, int tag) { + assert assertKey(cacheId, pageId); + + int index = removeKey(cacheId, pageId, tag); + + if (index >= 0) + setValueAt(index, 0); + } + + /** + * Find nearest value from specified position to the right. + * + * @param idx Index to start searching from. + * @param absent Default value that will be returned if no values present. + * @return Closest value to the index and it's partition tag or {@code absent} and -1 if no values found. + */ + public EvictCandidate getNearestAt(final int idx, final long absent) { + for (int i = idx; i < capacity + idx; i++) { + final int idx2 = i >= capacity ? i - capacity : i; + + if (isValuePresentAt(idx2)) { + long base = entryBase(idx2); + + int cacheId = GridUnsafe.getInt(base); + int tag = GridUnsafe.getInt(base + 4); + long pageId = GridUnsafe.getLong(base + 8); + long val = GridUnsafe.getLong(base + 16); + + return new EvictCandidate(tag, val, new FullPageId(pageId, cacheId)); + } + } + + return null; + } + + /** + * @param idx Index to clear value at. + * @param pred Test predicate. + * @param absent Value to return if the cell is empty. + * @return Value at the given index. + */ + public long clearAt(int idx, GridPredicate3 pred, long absent) { + long base = entryBase(idx); + + int cacheId = GridUnsafe.getInt(base); + int tag = GridUnsafe.getInt(base + 4); + long pageId = GridUnsafe.getLong(base + 8); + + if ((pageId == REMOVED_PAGE_ID && cacheId == REMOVED_CACHE_ID) + || (pageId == EMPTY_PAGE_ID && cacheId == EMPTY_CACHE_ID)) + return absent; + + if (pred.apply(cacheId, pageId, tag)) { + long res = valueAt(idx); + + setKeyAt(idx, REMOVED_CACHE_ID, REMOVED_PAGE_ID); + setValueAt(idx, 0); + + return res; + } + else + return absent; + } + + /** + * @param cacheId Cache ID. + * @param pageId Page ID. + * @return Key index. + */ + private int putKey(int cacheId, long pageId, int tag) { + int step = 1; + + int index = U.safeAbs(FullPageId.hashCode(cacheId, pageId)) % capacity; + + int foundIndex = -1; + int res; + + do { + res = testKeyAt(index, cacheId, pageId, tag); + + if (res == EMPTY || res == OUTDATED) { + if (foundIndex == -1) + foundIndex = index; + + break; + } + else if (res == REMOVED) { + // Must continue search to the first empty slot to ensure there are no duplicate mappings. + if (foundIndex == -1) + foundIndex = index; + } + else if (res == EQUAL) + return index; + else + assert res == NOT_EQUAL; + + index++; + + if (index >= capacity) + index -= capacity; + } + while (++step <= maxSteps); + + if (foundIndex != -1) { + setKeyAt(foundIndex, cacheId, pageId); + setTagAt(foundIndex, tag); + + if (res != OUTDATED) + incrementSize(); + + return foundIndex; + } + + throw new IgniteOutOfMemoryException("No room for a new key"); + } + + /** + * @param cacheId Cache ID. + * @param pageId Page ID. + * @return Key index. + */ + private int getKey(int cacheId, long pageId, int tag, boolean refresh) { + int step = 1; + + int index = U.safeAbs(FullPageId.hashCode(cacheId, pageId)) % capacity; + + do { + long res = testKeyAt(index, cacheId, pageId, tag); + + if (res == EQUAL) + return index; + else if (res == EMPTY) + return -1; + else if (res == OUTDATED) + return !refresh ? -2 : index; + else + assert res == REMOVED || res == NOT_EQUAL; + + index++; + + if (index >= capacity) + index -= capacity; + } + while (++step <= maxSteps); + + return -1; + } + + /** + * @param cacheId Cache ID. + * @param pageId Page ID. + * @return Key index. + */ + private int removeKey(int cacheId, long pageId, int tag) { + int step = 1; + + int index = U.safeAbs(FullPageId.hashCode(cacheId, pageId)) % capacity; + + int foundIndex = -1; + + do { + long res = testKeyAt(index, cacheId, pageId, tag); + + if (res == EQUAL || res == OUTDATED) { + foundIndex = index; + + break; + } + else if (res == EMPTY) + return -1; + else + assert res == REMOVED || res == NOT_EQUAL; + + index++; + + if (index >= capacity) + index -= capacity; + } + while (++step <= maxSteps); + + if (foundIndex != -1) { + setKeyAt(foundIndex, REMOVED_CACHE_ID, REMOVED_PAGE_ID); + + decrementSize(); + } + + return foundIndex; + } + + /** + * @param index Entry index. + * @return Key value. + */ + private int testKeyAt(int index, int testCacheId, long testPageId, int testTag) { + long base = entryBase(index); + + int cacheId = GridUnsafe.getInt(base); + int tag = GridUnsafe.getInt(base + 4); + long pageId = GridUnsafe.getLong(base + 8); + + if (pageId == REMOVED_PAGE_ID && cacheId == REMOVED_CACHE_ID) + return REMOVED; + else if (pageId == testPageId && cacheId == testCacheId && tag >= testTag) + return EQUAL; + else if (pageId == testPageId && cacheId == testCacheId && tag < testTag) + return OUTDATED; + else if (pageId == EMPTY_PAGE_ID && cacheId == EMPTY_CACHE_ID) + return EMPTY; + else + return NOT_EQUAL; + } + + /** + * @param idx Index to test. + * @return {@code True} if value set for index. + */ + private boolean isValuePresentAt(final int idx) { + long base = entryBase(idx); + + int cacheId = GridUnsafe.getInt(base); + long pageId = GridUnsafe.getLong(base + 8); + + return !((pageId == REMOVED_PAGE_ID && cacheId == REMOVED_CACHE_ID) + || (pageId == EMPTY_PAGE_ID && cacheId == EMPTY_CACHE_ID)); + } + + /** + * @param cacheId Cache ID. + * @param pageId Page ID. + * @return {@code True} if checks succeeded. + */ + private boolean assertKey(int cacheId, long pageId) { + assert cacheId != EMPTY_CACHE_ID && PageIdUtils.isEffectivePageId(pageId): + "cacheId=" + cacheId + ", pageId=" + U.hexLong(pageId); + + return true; + } + + /** + * @param index Entry index. + * @param cacheId Cache ID to write. + * @param pageId Page ID to write. + */ + private void setKeyAt(int index, int cacheId, long pageId) { + long base = entryBase(index); + + GridUnsafe.putInt(base, cacheId); + GridUnsafe.putLong(base + 8, pageId); + } + + /** + * Gets distance from the ideal key location to the actual location if this entry is present in the table, + * or returns negative distance that needed to be scanned to determine the absence of the mapping. + * + * @param cacheId Cache ID. + * @param pageId Page ID. + * @param tag Tag. + * @return Distance scanned if the entry is found or negative distance scanned, if entry was not found. + */ + int distanceFromIdeal(int cacheId, long pageId, int tag) { + int step = 1; + + int index = U.safeAbs(FullPageId.hashCode(cacheId, pageId)) % capacity; + + int scans = 0; + boolean found = false; + + do { + scans++; + + long res = testKeyAt(index, cacheId, pageId, tag); + + if (res == EQUAL || res == OUTDATED) { + found = true; + + break; + } + else if (res == EMPTY) + break; + else + assert res == REMOVED || res == NOT_EQUAL; + + index++; + + if (index >= capacity) + index -= capacity; + } + while (++step <= maxSteps); + + return found ? scans : -scans; + } + + /** + * Scans all the elements in this table. + * + * @param visitor Visitor. + */ + void visitAll(IgniteBiInClosure visitor) { + for (int i = 0; i < capacity; i++) { + if (isValuePresentAt(i)) { + long base = entryBase(i); + + int cacheId = GridUnsafe.getInt(base); + long pageId = GridUnsafe.getLong(base + 8); + long val = GridUnsafe.getLong(base + 16); + + visitor.apply(new FullPageId(pageId, cacheId), val); + } + } + } + + /** + * @param index Entry index. + * @return Value. + */ + private long valueAt(int index) { + return GridUnsafe.getLong(entryBase(index) + 16); + } + + /** + * @param index Entry index. + * @param value Value. + */ + private void setValueAt(int index, long value) { + GridUnsafe.putLong(entryBase(index) + 16, value); + } + + private long entryBase(int index) { + return valPtr + 8 + (long)index * BYTES_PER_ENTRY; + } + + /** + * @param index Index to get tag for. + * @return Tag at the given index. + */ + private int tagAt(int index) { + return GridUnsafe.getInt(entryBase(index) + 4); + } + + /** + * @param index Index to set tag for. + * @param tag Tag to set at the given index. + */ + private void setTagAt(int index, int tag) { + GridUnsafe.putInt(entryBase(index) + 4, tag); + } + + /** + * + */ + public void clear() { + GridUnsafe.setMemory(valPtr, (long)capacity * BYTES_PER_ENTRY + 8, (byte)0); + } + + /** + * + */ + private void incrementSize() { + GridUnsafe.putInt(valPtr, GridUnsafe.getInt(valPtr) + 1); + } + + /** + * + */ + private void decrementSize() { + GridUnsafe.putInt(valPtr, GridUnsafe.getInt(valPtr) - 1); + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java new file mode 100644 index 0000000000000..94fd95840073a --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java @@ -0,0 +1,131 @@ +package org.apache.ignite.internal.processors.cache.database.pagemem; + +import java.nio.ByteBuffer; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.util.GridMultiCollectionWrapper; +import org.apache.ignite.internal.util.lang.GridPredicate3; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public interface PageMemoryEx extends PageMemory { + /** + * + * @param cacheId Cache ID. + * @param pageId Page ID. + * @param page Page pointer. + * @param restore Determines if the page is locked for restore. + * @return ByteBuffer for modifying the page. + */ + long writeLock(int cacheId, long pageId, long page, boolean restore); + + /** + * + * @param cacheId Cache ID. + * @param pageId Page ID. + * @param page Page pointer. + * @param walPlc {@code True} if page should be recorded to WAL, {@code false} if the page must not + * be recorded and {@code null} for the default behavior. + * @param dirtyFlag Determines whether the page was modified since the last checkpoint. + * @param restore Determines if the page is locked for restore. + */ + void writeUnlock(int cacheId, long pageId, long page, Boolean walPlc, + boolean dirtyFlag, boolean restore); + + /** + * Gets or allocates metadata page for specified cacheId. + * + * @param cacheId Cache ID. + * @return Meta page for cacheId. + * @throws IgniteCheckedException If failed. + */ + public long metaPageId(int cacheId) throws IgniteCheckedException; + + /** + * Gets or allocates partition metadata page for specified cacheId and partId. + * + * @param cacheId Cache ID. + * @param partId Partition ID. + * @return Meta page for cacheId and partId. + * @throws IgniteCheckedException If failed. + */ + public long partitionMetaPageId(int cacheId, int partId) throws IgniteCheckedException; + + /** + * @see #acquirePage(int, long) + * Will not read page from file if it is not present in memory + * + * @param cacheId Cache id. + * @param pageId Page id. + * @param restore Get page for restore + * @throws IgniteCheckedException If failed. + * @return Page. + */ + public long acquirePage(int cacheId, long pageId, boolean restore) throws IgniteCheckedException; + + /** + * Heuristic method which allows a thread to check if it safe to start memory struture modifications + * in regard with checkpointing. + * + * @return {@code False} if there are too many dirty pages and a thread should wait for a + * checkpoint to begin. + */ + public boolean safeToUpdate(); + + /** + * Gets a collection of dirty page IDs since the last checkpoint. If a dirty page is being written after + * the checkpointing operation begun, the modifications will be written to a temporary buffer which will + * be flushed to the main memory after the checkpointing finished. This method must be called when no + * concurrent operations on pages are performed. + * + * @return Collection of dirty page IDs. + * @throws IgniteException If checkpoint has been already started and was not finished. + */ + public GridMultiCollectionWrapper beginCheckpoint() throws IgniteException; + + /** + * Finishes checkpoint operation. + */ + public void finishCheckpoint(); + + /** + * Gets page byte buffer for the checkpoint procedure. + * + * @param pageId Page ID to get byte buffer for. The page ID must be present in the collection returned by + * the {@link #beginCheckpoint()} method call. + * @param tmpBuf Temporary buffer to write changes into. + * @return {@code True} if data were read, {@code false} otherwise (data already saved to storage). + * @throws IgniteException If failed to obtain page data. + */ + @Nullable public Integer getForCheckpoint(FullPageId pageId, ByteBuffer tmpBuf); + + /** + * Marks partition as invalid / outdated. + * + * @param cacheId Cache ID. + * @param partId Partition ID. + * @return New partition tag. + */ + public int invalidate(int cacheId, int partId); + + /** + * Clears internal metadata of destroyed cache. + * + * @param cacheId Cache ID. + */ + public void onCacheDestroyed(int cacheId); + + /** + * Asynchronously clears pages satisfying the given predicate. + * + * @param pred Predicate for cacheId, pageId and partition tag. + * @param cleanDirty Flag indicating that dirty pages collection should be cleaned. + * @return Future that will be completed when all pages are cleared. + */ + public IgniteInternalFuture clearAsync(GridPredicate3 pred, boolean cleanDirty); +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java new file mode 100755 index 0000000000000..70a9677e301ab --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java @@ -0,0 +1,2301 @@ +package org.apache.ignite.internal.processors.cache.database.pagemem; + +import java.io.Closeable; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.Executor; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.mem.DirectMemory; +import org.apache.ignite.internal.mem.DirectMemoryProvider; +import org.apache.ignite.internal.mem.DirectMemoryRegion; +import org.apache.ignite.internal.mem.IgniteOutOfMemoryException; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdAllocator; +import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.pagemem.PageUtils; +import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.pagemem.wal.WALPointer; +import org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord; +import org.apache.ignite.internal.pagemem.wal.record.PageSnapshot; +import org.apache.ignite.internal.pagemem.wal.record.WALRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; +import org.apache.ignite.internal.processors.cache.database.wal.crc.IgniteDataIntegrityViolationException; +import org.apache.ignite.internal.util.GridConcurrentHashSet; +import org.apache.ignite.internal.util.GridLongList; +import org.apache.ignite.internal.util.GridMultiCollectionWrapper; +import org.apache.ignite.internal.util.GridUnsafe; +import org.apache.ignite.internal.util.OffheapReadWriteLock; +import org.apache.ignite.internal.util.future.CountDownFuture; +import org.apache.ignite.internal.util.lang.GridInClosure3X; +import org.apache.ignite.internal.util.lang.GridPredicate3; +import org.apache.ignite.internal.util.offheap.GridOffHeapOutOfMemoryException; +import org.apache.ignite.internal.util.typedef.T2; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiTuple; +import org.apache.ignite.lifecycle.LifecycleAware; +import sun.misc.JavaNioAccess; +import sun.misc.SharedSecrets; +import sun.nio.ch.DirectBuffer; + +import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; + +/** + * Page header structure is described by the following diagram. + * + * When page is not allocated (in a free list): + *
+ * +--------+------------------------------------------------------+
+ * |8 bytes |         PAGE_SIZE + PAGE_OVERHEAD - 8 bytes          |
+ * +--------+------------------------------------------------------+
+ * |Next ptr|                      Page data                       |
+ * +--------+------------------------------------------------------+
+ * 
+ *

+ * When page is allocated and is in use: + *

+ * +------------------+--------+--------+----+----+--------+--------+----------------------+
+ * |     8 bytes      |8 bytes |8 bytes |4 b |4 b |8 bytes |8 bytes |       PAGE_SIZE      |
+ * +------------------+--------+--------+----+----+--------+--------+----------------------+
+ * | Marker/Timestamp |Rel ptr |Page ID |C ID|PIN | LOCK   |TMP BUF |       Page data      |
+ * +------------------+--------+--------+----+----+--------+--------+----------------------+
+ * 
+ * + * Note that first 8 bytes of page header are used either for page marker or for next relative pointer depending + * on whether the page is in use or not. + */ +@SuppressWarnings({"LockAcquiredButNotSafelyReleased", "FieldAccessedSynchronizedAndUnsynchronized"}) +public class PageMemoryImpl implements PageMemoryEx { + /** */ + public static final long PAGE_MARKER = 0x0000000000000001L; + + /** Relative pointer chunk index mask. */ + private static final long SEGMENT_INDEX_MASK = 0xFFFFFF0000000000L; + + /** Full relative pointer mask. */ + private static final long RELATIVE_PTR_MASK = 0xFFFFFFFFFFFFFFL; + + /** Dirty flag. */ + private static final long DIRTY_FLAG = 0x0100000000000000L; + + /** Dirty flag. */ + private static final long TMP_DIRTY_FLAG = 0x0200000000000000L; + + /** Invalid relative pointer value. */ + private static final long INVALID_REL_PTR = RELATIVE_PTR_MASK; + + /** */ + private static final long OUTDATED_REL_PTR = INVALID_REL_PTR + 1; + + /** Address mask to avoid ABA problem. */ + private static final long ADDRESS_MASK = 0xFFFFFFFFFFFFFFL; + + /** Counter mask to avoid ABA problem. */ + private static final long COUNTER_MASK = ~ADDRESS_MASK; + + /** Counter increment to avoid ABA problem. */ + private static final long COUNTER_INC = ADDRESS_MASK + 1; + + /** Page relative pointer. Does not change once a page is allocated. */ + public static final int RELATIVE_PTR_OFFSET = 8; + + /** Page ID offset */ + public static final int PAGE_ID_OFFSET = 16; + + /** Page cache ID offset. */ + public static final int PAGE_CACHE_ID_OFFSET = 24; + + /** Page pin counter offset. */ + public static final int PAGE_PIN_CNT_OFFSET = 28; + + /** Page lock offset. */ + public static final int PAGE_LOCK_OFFSET = 32; + + /** Page lock offset. */ + public static final int PAGE_TMP_BUF_OFFSET = 40; + + /** + * 8b Marker/timestamp + * 8b Relative pointer + * 8b Page ID + * 4b Cache ID + * 4b Pin count + * 8b Lock + * 8b Temporary buffer + */ + public static final int PAGE_OVERHEAD = 48; + + /** Number of random pages that will be picked for eviction. */ + public static final int RANDOM_PAGES_EVICT_NUM = 5; + + /** Tracking io. */ + private static final TrackingPageIO trackingIO = TrackingPageIO.VERSIONS.latest(); + + /** Page size. */ + private final int sysPageSize; + + /** Shared context. */ + private final GridCacheSharedContext sharedCtx; + + /** State checker. */ + private final CheckpointLockStateChecker stateChecker; + + /** */ + private Executor asyncRunner = new ThreadPoolExecutor( + 0, + Runtime.getRuntime().availableProcessors(), + 30L, + TimeUnit.SECONDS, + new ArrayBlockingQueue(Runtime.getRuntime().availableProcessors())); + + /** Page store manager. */ + private IgnitePageStoreManager storeMgr; + + /** */ + private IgniteWriteAheadLogManager walMgr; + + /** Direct byte buffer factory. */ + private JavaNioAccess nioAccess; + + /** */ + private final IgniteLogger log; + + /** Direct memory allocator. */ + private final DirectMemoryProvider directMemoryProvider; + + /** Segments array. */ + private Segment[] segments; + + /** */ + private PagePool checkpointPool; + + /** */ + private OffheapReadWriteLock rwLock; + + /** Flush dirty page closure. When possible, will be called by evictPage(). */ + private final GridInClosure3X flushDirtyPage; + + /** Flush dirty page closure. When possible, will be called by evictPage(). */ + private final GridInClosure3X changeTracker; + + /** */ + private boolean pageEvictWarned; + + /** + * @param directMemoryProvider Memory allocator to use. + * @param sharedCtx Cache shared context. + * @param pageSize Page size. + * @param flushDirtyPage Callback invoked when a dirty page is evicted. + * @param changeTracker Callback invoked to track changes in pages. + */ + public PageMemoryImpl( + DirectMemoryProvider directMemoryProvider, + GridCacheSharedContext sharedCtx, + int pageSize, + GridInClosure3X flushDirtyPage, + GridInClosure3X changeTracker, + CheckpointLockStateChecker stateChecker + ) { + assert sharedCtx != null; + + log = sharedCtx.logger(PageMemoryImpl.class); + this.sharedCtx = sharedCtx; + this.directMemoryProvider = directMemoryProvider; + this.flushDirtyPage = flushDirtyPage; + this.changeTracker = changeTracker; + this.stateChecker = stateChecker; + + storeMgr = sharedCtx.pageStore(); + walMgr = sharedCtx.wal(); + + assert storeMgr != null; + assert walMgr != null; + + sysPageSize = pageSize + PAGE_OVERHEAD; + + rwLock = new OffheapReadWriteLock(128); + } + + /** {@inheritDoc} */ + @Override public void start() throws IgniteException { + if (directMemoryProvider instanceof LifecycleAware) + ((LifecycleAware)directMemoryProvider).start(); + + DirectMemory memory = directMemoryProvider.memory(); + + nioAccess = SharedSecrets.getJavaNioAccess(); + + int regs = memory.regions().size(); + + segments = new Segment[regs - 1]; + + DirectMemoryRegion cpReg = memory.regions().get(regs - 1); + + checkpointPool = new PagePool(regs - 1, cpReg); + + long checkpointBuf = cpReg.size(); + + long totalAllocated = 0; + int pages = 0; + long totalTblSize = 0; + + for (int i = 0; i < regs - 1; i++) { + assert i < segments.length; + + DirectMemoryRegion reg = memory.regions().get(i); + + totalAllocated += reg.size(); + + segments[i] = new Segment(i, memory.regions().get(i), checkpointPool.pages() / segments.length); + + pages += segments[i].pages(); + totalTblSize += segments[i].tableSize(); + } + + if (log.isInfoEnabled()) + log.info("Started page memory [memoryAllocated=" + U.readableSize(totalAllocated, false) + + ", pages=" + pages + + ", tableSize=" + U.readableSize(totalTblSize, false) + + ", checkpointBuffer=" + U.readableSize(checkpointBuf, false) + + ']'); + } + + /** {@inheritDoc} */ + @SuppressWarnings("OverlyStrongTypeCast") + @Override public void stop() throws IgniteException { + if (log.isDebugEnabled()) + log.debug("Stopping page memory."); + + if (directMemoryProvider instanceof LifecycleAware) + ((LifecycleAware)directMemoryProvider).stop(); + + if (directMemoryProvider instanceof Closeable) { + try { + ((Closeable)directMemoryProvider).close(); + } + catch (IOException e) { + throw new IgniteException(e); + } + } + } + + /** {@inheritDoc} */ + @Override public void releasePage(int cacheId, long pageId, long page) { + Segment seg = segment(cacheId, pageId); + + seg.readLock().lock(); + + try { + seg.releasePage(page); + } + finally { + seg.readLock().unlock(); + } + } + + /** {@inheritDoc} */ + @Override public long readLock(int cacheId, long pageId, long page) { + return readLockPage(page, new FullPageId(pageId, cacheId), false); + } + + /** {@inheritDoc} */ + @Override public void readUnlock(int cacheId, long pageId, long page) { + readUnlockPage(page); + } + + /** {@inheritDoc} */ + @Override public long writeLock(int cacheId, long pageId, long page) { + return writeLock(cacheId, pageId, page, false); + } + + /** {@inheritDoc} */ + @Override public long writeLock(int cacheId, long pageId, long page, boolean restore) { + return writeLockPage(page, new FullPageId(pageId, cacheId), !restore); + } + + /** {@inheritDoc} */ + @Override public long tryWriteLock(int cacheId, long pageId, long page) { + return tryWriteLockPage(page, new FullPageId(pageId, cacheId), true); + } + + /** {@inheritDoc} */ + @Override public void writeUnlock(int cacheId, long pageId, long page, Boolean walPlc, + boolean dirtyFlag) { + writeUnlock(cacheId, pageId, page, walPlc, dirtyFlag, false); + } + + /** {@inheritDoc} */ + @Override public void writeUnlock(int cacheId, long pageId, long page, Boolean walPlc, + boolean dirtyFlag, boolean restore) { + writeUnlockPage(page, new FullPageId(pageId, cacheId), walPlc, dirtyFlag, restore); + } + + /** {@inheritDoc} */ + @Override public boolean isDirty(int cacheId, long pageId, long page) { + return isDirtyVisible(page, new FullPageId(pageId, cacheId)); + } + + /** {@inheritDoc} */ + @Override public long allocatePage(int cacheId, int partId, byte flags) throws IgniteCheckedException { + assert flags == PageIdAllocator.FLAG_DATA && partId <= PageIdAllocator.MAX_PARTITION_ID || + flags == PageIdAllocator.FLAG_IDX && partId == PageIdAllocator.INDEX_PARTITION : + "flags = " + flags + ", partId = " + partId; + + long pageId = storeMgr.allocatePage(cacheId, partId, flags); + + assert PageIdUtils.pageIndex(pageId) > 0; //it's crucial for tracking pages (zero page is super one) + + // We need to allocate page in memory for marking it dirty to save it in the next checkpoint. + // Otherwise it is possible that on file will be empty page which will be saved at snapshot and read with error + // because there is no crc inside them. + Segment seg = segment(cacheId, pageId); + + FullPageId fullId = new FullPageId(pageId, cacheId); + + seg.writeLock().lock(); + + boolean isTrackingPage = trackingIO.trackingPageFor(pageId, pageSize()) == pageId; + + try { + long relPtr = seg.borrowOrAllocateFreePage(pageId); + + if (relPtr == INVALID_REL_PTR) + relPtr = seg.evictPage(); + + long absPtr = seg.absolute(relPtr); + + GridUnsafe.setMemory(absPtr + PAGE_OVERHEAD, pageSize(), (byte)0); + + PageHeader.fullPageId(absPtr, fullId); + PageHeader.writeTimestamp(absPtr, U.currentTimeMillis()); + rwLock.init(absPtr + PAGE_LOCK_OFFSET, PageIdUtils.tag(pageId)); + + assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + + assert !PageHeader.isAcquired(absPtr) : + "Pin counter must be 0 for a new page [relPtr=" + U.hexLong(relPtr) + + ", absPtr=" + U.hexLong(absPtr) + ']'; + + setDirty(fullId, absPtr, true, true, false); + + if (isTrackingPage) { + long pageAddr = absPtr + PAGE_OVERHEAD; + + // We are inside segment write lock, so no other thread can pin this tracking page yet. + // We can modify page buffer directly. + if (PageIO.getType(pageAddr) == 0) { + trackingIO.initNewPage(pageAddr, pageId, pageSize()); + + if (!sharedCtx.wal().isAlwaysWriteFullPages()) + sharedCtx.wal().log(new InitNewPageRecord(cacheId, pageId, trackingIO.getType(), + trackingIO.getVersion(), pageId)); + else + sharedCtx.wal().log(new PageSnapshot(fullId, absPtr + PAGE_OVERHEAD, pageSize())); + } + } + + seg.loadedPages.put(cacheId, PageIdUtils.effectivePageId(pageId), relPtr, seg.partTag(cacheId, partId)); + } + finally { + seg.writeLock().unlock(); + } + + //we have allocated 'tracking' page, we need to allocate regular one + return isTrackingPage ? allocatePage(cacheId, partId, flags) : pageId; + } + + /** {@inheritDoc} */ + @Override public ByteBuffer pageBuffer(long pageAddr) { + return wrapPointer(pageAddr, pageSize()); + } + + /** {@inheritDoc} */ + @Override public boolean freePage(int cacheId, long pageId) throws IgniteCheckedException { + assert false : "Free page should be never called directly when persistence is enabled."; + + return false; + } + + /** {@inheritDoc} */ + @Override public long metaPageId(int cacheId) throws IgniteCheckedException { + return storeMgr.metaPageId(cacheId); + } + + /** {@inheritDoc} */ + @Override public long partitionMetaPageId(int cacheId, int partId) throws IgniteCheckedException { + return PageIdUtils.pageId(partId, PageIdAllocator.FLAG_DATA, 0); + } + + /** {@inheritDoc} */ + @Override public long acquirePage(int cacheId, long pageId) throws IgniteCheckedException { + return acquirePage(cacheId, pageId, false); + } + + /** {@inheritDoc} */ + @Override public long acquirePage(int cacheId, long pageId, boolean restore) throws IgniteCheckedException { + FullPageId fullId = new FullPageId(pageId, cacheId); + + int partId = PageIdUtils.partId(pageId); + + Segment seg = segment(cacheId, pageId); + + seg.readLock().lock(); + + try { + long relPtr = seg.loadedPages.get(cacheId, PageIdUtils.effectivePageId(pageId), seg.partTag(cacheId, partId), + INVALID_REL_PTR, INVALID_REL_PTR); + + // The page is loaded to the memory. + if (relPtr != INVALID_REL_PTR) { + long absPtr = seg.absolute(relPtr); + + seg.acquirePage(absPtr); + + return absPtr; + } + } + finally { + seg.readLock().unlock(); + } + + seg.writeLock().lock(); + + try { + // Double-check. + long relPtr = seg.loadedPages.get(cacheId, PageIdUtils.effectivePageId(pageId), seg.partTag(cacheId, partId), + INVALID_REL_PTR, OUTDATED_REL_PTR); + long absPtr; + + if (relPtr == INVALID_REL_PTR) { + relPtr = seg.borrowOrAllocateFreePage(pageId); + + if (relPtr == INVALID_REL_PTR) + relPtr = seg.evictPage(); + + absPtr = seg.absolute(relPtr); + + PageHeader.fullPageId(absPtr, fullId); + PageHeader.writeTimestamp(absPtr, U.currentTimeMillis()); + + assert !PageHeader.isAcquired(absPtr) : + "Pin counter must be 0 for a new page [relPtr=" + U.hexLong(relPtr) + + ", absPtr=" + U.hexLong(absPtr) + ']'; + + // We can clear dirty flag after the page has been allocated. + setDirty(fullId, absPtr, false, false, false); + + seg.loadedPages.put(cacheId, PageIdUtils.effectivePageId(pageId), relPtr, seg.partTag(cacheId, partId)); + + long pageAddr = absPtr + PAGE_OVERHEAD; + + if (!restore) { + try { + ByteBuffer buf = wrapPointer(pageAddr, pageSize()); + + storeMgr.read(cacheId, pageId, buf); + } + catch (IgniteDataIntegrityViolationException ignore) { + U.warn(log, "Failed to read page (data integrity violation encountered, will try to " + + "restore using existing WAL) [fullPageId=" + fullId + ']'); + + tryToRestorePage(fullId, absPtr); + + seg.acquirePage(absPtr); + + return absPtr; + } + } + else { + GridUnsafe.setMemory(absPtr + PAGE_OVERHEAD, pageSize(), (byte)0); + + // Must init page ID in order to ensure RWLock tag consistency. + PageIO.setPageId(pageAddr, pageId); + } + + rwLock.init(absPtr + PAGE_LOCK_OFFSET, PageIdUtils.tag(pageId)); + } + else if (relPtr == OUTDATED_REL_PTR) { + assert PageIdUtils.pageIndex(pageId) == 0 : fullId; + + relPtr = refreshOutdatedPage(seg, cacheId, pageId, false); + + absPtr = seg.absolute(relPtr); + + long pageAddr = absPtr + PAGE_OVERHEAD; + + GridUnsafe.setMemory(absPtr + PAGE_OVERHEAD, pageSize(), (byte)0); + + PageHeader.fullPageId(absPtr, fullId); + PageHeader.writeTimestamp(absPtr, U.currentTimeMillis()); + PageIO.setPageId(pageAddr, pageId); + + assert !PageHeader.isAcquired(absPtr) : + "Pin counter must be 0 for a new page [relPtr=" + U.hexLong(relPtr) + + ", absPtr=" + U.hexLong(absPtr) + ']'; + + rwLock.init(absPtr + PAGE_LOCK_OFFSET, PageIdUtils.tag(pageId)); + } + else + absPtr = seg.absolute(relPtr); + + seg.acquirePage(absPtr); + + return absPtr; + } + finally { + seg.writeLock().unlock(); + } + } + + /** + * @param seg Segment. + * @param cacheId Cache ID. + * @param pageId Page ID. + * @param remove {@code True} if page should be removed. + * @return Relative pointer to refreshed page. + */ + private long refreshOutdatedPage(Segment seg, int cacheId, long pageId, boolean remove) { + assert seg.writeLock().isHeldByCurrentThread(); + + int tag = seg.partTag(cacheId, PageIdUtils.partId(pageId)); + + long relPtr = seg.loadedPages.refresh(cacheId, PageIdUtils.effectivePageId(pageId), tag); + + long absPtr = seg.absolute(relPtr); + + GridUnsafe.setMemory(absPtr + PAGE_OVERHEAD, pageSize(), (byte)0); + + long tmpBufPtr = PageHeader.tempBufferPointer(absPtr); + + if (tmpBufPtr != INVALID_REL_PTR) { + GridUnsafe.setMemory(checkpointPool.absolute(tmpBufPtr) + PAGE_OVERHEAD, pageSize(), (byte)0); + + PageHeader.tempBufferPointer(absPtr, INVALID_REL_PTR); + PageHeader.dirty(absPtr, false); + PageHeader.tempDirty(absPtr, false); + + // We pinned the page when allocated the temp buffer, release it now. + PageHeader.releasePage(absPtr); + + checkpointPool.releaseFreePage(tmpBufPtr); + } + + if (remove) + seg.loadedPages.remove(cacheId, PageIdUtils.effectivePageId(pageId), tag); + + return relPtr; + } + + /** + * @param fullId Full id. + * @param absPtr Absolute pointer. + */ + private void tryToRestorePage(FullPageId fullId, long absPtr) throws IgniteCheckedException { + Long tmpAddr = null; + + try { + ByteBuffer curPage = null; + ByteBuffer lastValidPage = null; + + for (IgniteBiTuple tuple : walMgr.replay(null)) { + switch (tuple.getValue().type()) { + case PAGE_RECORD: + PageSnapshot snapshot = (PageSnapshot)tuple.getValue(); + + if (snapshot.fullPageId().equals(fullId)) { + if (tmpAddr == null) { + assert snapshot.pageData().length <= pageSize() : snapshot.pageData().length; + + tmpAddr = GridUnsafe.allocateMemory(pageSize()); + } + + if (curPage == null) + curPage = wrapPointer(tmpAddr, pageSize()); + + PageUtils.putBytes(tmpAddr, 0, snapshot.pageData()); + } + + break; + + case CHECKPOINT_RECORD: + CheckpointRecord rec = (CheckpointRecord)tuple.getValue(); + + assert !rec.end(); + + if (curPage != null) { + lastValidPage = curPage; + curPage = null; + } + + break; + + case MEMORY_RECOVERY: // It means that previous checkpoint was broken. + curPage = null; + + break; + + default: + if (tuple.getValue() instanceof PageDeltaRecord) { + PageDeltaRecord deltaRecord = (PageDeltaRecord)tuple.getValue(); + + if (curPage != null + && deltaRecord.pageId() == fullId.pageId() + && deltaRecord.cacheId() == fullId.cacheId()) { + assert tmpAddr != null; + + deltaRecord.applyDelta(this, tmpAddr); + } + } + } + } + + ByteBuffer restored = curPage == null ? lastValidPage : curPage; + + if (restored == null) + throw new AssertionError(String.format( + "Page is broken. Can't restore it from WAL. (cacheId = %d, pageId = %X).", + fullId.cacheId(), fullId.pageId() + )); + + long pageAddr = writeLockPage(absPtr, fullId, false); + + try { + pageBuffer(pageAddr).put(restored); + } + finally { + writeUnlockPage(absPtr, fullId, null, true, false); + } + } + finally { + if (tmpAddr != null) + GridUnsafe.freeMemory(tmpAddr); + } + } + + /** {@inheritDoc} */ + @Override public int pageSize() { + return sysPageSize - PAGE_OVERHEAD; + } + + /** {@inheritDoc} */ + @Override public int systemPageSize() { + return sysPageSize; + } + + /** {@inheritDoc} */ + @Override public boolean safeToUpdate() { + for (Segment segment : segments) + if (!segment.safeToUpdate()) + return false; + + return true; + } + + /** {@inheritDoc} */ + @Override public GridMultiCollectionWrapper beginCheckpoint() throws IgniteException { + Collection[] collections = new Collection[segments.length]; + + for (int i = 0; i < segments.length; i++) { + Segment seg = segments[i]; + + if (seg.segCheckpointPages != null) + throw new IgniteException("Failed to begin checkpoint (it is already in progress)."); + + collections[i] = seg.segCheckpointPages = seg.dirtyPages; + + seg.dirtyPages = new GridConcurrentHashSet<>(); + } + + return new GridMultiCollectionWrapper<>(collections); + } + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked", "TooBroadScope"}) + @Override public void finishCheckpoint() { + // Lock segment by segment and flush changes. + for (Segment seg : segments) { + GridLongList activePages = null; + + seg.writeLock().lock(); + + try { + assert seg.segCheckpointPages != null : "Checkpoint has not been started."; + + for (FullPageId fullId : seg.segCheckpointPages) { + int partTag = seg.partTag(fullId.cacheId(), PageIdUtils.partId(fullId.pageId())); + + long relPtr = seg.loadedPages.get(fullId.cacheId(), + PageIdUtils.effectivePageId(fullId.pageId()), partTag, INVALID_REL_PTR, OUTDATED_REL_PTR); + + // Checkpoint page may have been written by evict. + if (relPtr == INVALID_REL_PTR) + continue; + + if (relPtr == OUTDATED_REL_PTR) { + relPtr = refreshOutdatedPage(seg, fullId.cacheId(), + PageIdUtils.effectivePageId(fullId.pageId()), true); + + seg.pool.releaseFreePage(relPtr); + + continue; + } + + long absPtr = seg.absolute(relPtr); + + boolean pinned = PageHeader.isAcquired(absPtr); + + if (pinned) { + // Pin the page one more time. + seg.acquirePage(absPtr); + + if (activePages == null) + activePages = new GridLongList(seg.segCheckpointPages.size() / 2 + 1); + + activePages.add(relPtr); + } + // Page is not pinned and nobody can pin it since we hold the segment write lock. + else { + flushPageTempBuffer(fullId, absPtr); + + assert PageHeader.tempBufferPointer(absPtr) == INVALID_REL_PTR; + assert !PageHeader.tempDirty(absPtr) : "ptr=" + U.hexLong(absPtr) + ", fullId=" + fullId; + } + } + } + finally { + seg.writeLock().unlock(); + } + + // Must release active pages outside of segment write lock. + if (activePages != null) { + for (int p = 0; p < activePages.size(); p++) { + long relPtr = activePages.get(p); + + long absPtr = seg.absolute(relPtr); + + flushCheckpoint(absPtr); + + seg.readLock().lock(); + + try { + seg.releasePage(absPtr); + } + finally { + seg.readLock().unlock(); + } + } + } + + seg.segCheckpointPages = null; + } + } + + /** + * Checks if the page represented by the given full ID and absolute pointer has a temp buffer. If it has, this + * method will flush temp buffer data to the main page buffer as well as temp buffer dirty flag, release the + * temp buffer to segment pool and clear full page ID from checkpoint set. + *

+ * This method must be called wither from segment write lock while page is not pinned (thus, no other thread has + * access to the page's write buffer, or when this page is pinned and locked for write. + * + * @param fullId Full page ID. + * @param absPtr Page absolute pointer. + */ + private void flushPageTempBuffer(FullPageId fullId, long absPtr) { + long tmpRelPtr = PageHeader.tempBufferPointer(absPtr); + + // The page has temp buffer, need to flush it to the main memory. + if (tmpRelPtr != INVALID_REL_PTR) { + long tmpAbsPtr = checkpointPool.absolute(tmpRelPtr); + + boolean tmpDirty = PageHeader.tempDirty(absPtr, false); + + // Page could have a temp write buffer, but be not dirty because + // it was not modified after getForWrite. + if (tmpDirty) + GridUnsafe.copyMemory(tmpAbsPtr + PAGE_OVERHEAD, absPtr + PAGE_OVERHEAD, + sysPageSize - PAGE_OVERHEAD); + + setDirty(fullId, absPtr, tmpDirty, true, false); + + PageHeader.tempBufferPointer(absPtr, INVALID_REL_PTR); + + checkpointPool.releaseFreePage(tmpRelPtr); + + // We pinned the page when allocated the temp buffer, release it now. + int updated = PageHeader.releasePage(absPtr); + + assert updated > 0 : "Checkpoint page should not be released by flushCheckpoint()"; + } + else { + // We can get here in two cases. + // 1) Page was not modified since the checkpoint started. + // 2) Page was dirty and was written to the store by evictPage(). Then it was loaded to memory again + // and may have already modified by a writer. + // In both cases we should just set page header dirty flag based on dirtyPages collection. + PageHeader.dirty(absPtr, segment(fullId.cacheId(), fullId.pageId()).dirtyPages.contains(fullId)); + } + + // It is important to clear checkpoint status before the write lock is released. + clearCheckpoint(fullId); + } + + /** + * If page was concurrently modified during the checkpoint phase, this method will flush all changes from the + * temporary location to main memory. + * This method must be called outside of the segment write lock because we can ask for another pages + * while holding a page read or write lock. + */ + private void flushCheckpoint(long absPtr) { + rwLock.writeLock(absPtr + PAGE_LOCK_OFFSET, OffheapReadWriteLock.TAG_LOCK_ALWAYS); + + try { + assert PageHeader.isAcquired(absPtr); + + FullPageId fullId = PageHeader.fullPageId(absPtr); + + flushPageTempBuffer(fullId, absPtr); + } + finally { + rwLock.writeUnlock(absPtr + PAGE_LOCK_OFFSET, OffheapReadWriteLock.TAG_LOCK_ALWAYS); + } + } + + /** {@inheritDoc} */ + @Override public Integer getForCheckpoint(FullPageId fullId, ByteBuffer tmpBuf) { + assert tmpBuf.remaining() == pageSize(); + + Segment seg = segment(fullId.cacheId(), fullId.pageId()); + + seg.readLock().lock(); + + try { + int tag = seg.partTag(fullId.cacheId(), PageIdUtils.partId(fullId.pageId())); + + long relPtr = seg.loadedPages.get(fullId.cacheId(), + PageIdUtils.effectivePageId(fullId.pageId()), tag, INVALID_REL_PTR, INVALID_REL_PTR); + + // Page may have been cleared during eviction. We have nothing to do in this case. + if (relPtr == INVALID_REL_PTR) + return null; + + long absPtr = seg.absolute(relPtr); + + if (tmpBuf.isDirect()) { + long tmpPtr = ((DirectBuffer)tmpBuf).address(); + + GridUnsafe.copyMemory(absPtr + PAGE_OVERHEAD, tmpPtr, pageSize()); + + assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + assert GridUnsafe.getInt(tmpPtr + 4) == 0; //TODO GG-11480 + } + else { + byte[] arr = tmpBuf.array(); + + assert arr != null; + assert arr.length == pageSize(); + + GridUnsafe.copyMemory(null, absPtr + PAGE_OVERHEAD, arr, GridUnsafe.BYTE_ARR_OFF, pageSize()); + } + + return tag; + } + finally { + seg.readLock().unlock(); + } + } + + /** {@inheritDoc} */ + @Override public int invalidate(int cacheId, int partId) { + int tag = 0; + + for (Segment seg : segments) { + seg.writeLock().lock(); + + try { + int newTag = seg.incrementPartTag(cacheId, partId); + + if (tag == 0) + tag = newTag; + + assert tag == newTag; + } + finally { + seg.writeLock().unlock(); + } + } + + return tag; + } + + /** {@inheritDoc} */ + @Override public void onCacheDestroyed(int cacheId) { + for (Segment seg : segments) { + seg.writeLock().lock(); + + try { + seg.resetPartTags(cacheId); + } + finally { + seg.writeLock().unlock(); + } + } + } + + /** {@inheritDoc} */ + @Override public IgniteInternalFuture clearAsync( + GridPredicate3 predicate, + boolean cleanDirty + ) { + CountDownFuture completeFut = new CountDownFuture(segments.length); + + for (Segment seg : segments) { + Runnable clear = new ClearSegmentRunnable(seg, predicate, cleanDirty, completeFut, pageSize()); + + try { + asyncRunner.execute(clear); + } + catch (RejectedExecutionException ignore) { + clear.run(); + } + } + + return completeFut; + } + + /** {@inheritDoc} */ + @Override public long loadedPages() { + long total = 0; + + for (Segment seg : segments) { + seg.readLock().lock(); + + try { + total += seg.loadedPages.size(); + } + finally { + seg.readLock().unlock(); + } + } + + return total; + } + + /** + * @return Total number of acquired pages. + */ + public long acquiredPages() { + long total = 0; + + for (Segment seg : segments) { + seg.readLock().lock(); + + try { + total += seg.acquiredPages(); + } + finally { + seg.readLock().unlock(); + } + } + + return total; + } + + /** + * @param absPtr Absolute pointer to read lock. + * @param force Force flag. + * @return Pointer to the page read buffer. + */ + private long readLockPage(long absPtr, FullPageId fullId, boolean force) { + int tag = force ? -1 : PageIdUtils.tag(fullId.pageId()); + + boolean locked = rwLock.readLock(absPtr + PAGE_LOCK_OFFSET, tag); + + if (!locked) + return 0; + + PageHeader.writeTimestamp(absPtr, U.currentTimeMillis()); + + long tmpRelPtr = PageHeader.tempBufferPointer(absPtr); + + if (tmpRelPtr == INVALID_REL_PTR) { + assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + + return absPtr + PAGE_OVERHEAD; + } + else { + long tmpAbsPtr = checkpointPool.absolute(tmpRelPtr); + + assert GridUnsafe.getInt(tmpAbsPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + + return tmpAbsPtr + PAGE_OVERHEAD; + } + } + + /** {@inheritDoc} */ + @Override public long readLockForce(int cacheId, long pageId, long page) { + return readLockPage(page, new FullPageId(pageId, cacheId), true); + } + + /** + * @param absPtr Absolute pointer to unlock. + */ + void readUnlockPage(long absPtr) { + rwLock.readUnlock(absPtr + PAGE_LOCK_OFFSET); + } + + /** + * Checks if a page has temp copy buffer. + * + * @param absPtr Absolute pointer. + * @return {@code True} if a page has temp buffer. + */ + public boolean hasTempCopy(long absPtr) { + return PageHeader.tempBufferPointer(absPtr) != INVALID_REL_PTR; + } + + /** + * @param absPtr Absolute pointer. + * @return Pointer to the page write buffer or {@code 0} if page was not locked. + */ + long tryWriteLockPage(long absPtr, FullPageId fullId, boolean checkTag) { + int tag = checkTag ? PageIdUtils.tag(fullId.pageId()) : OffheapReadWriteLock.TAG_LOCK_ALWAYS; + + if (!rwLock.tryWriteLock(absPtr + PAGE_LOCK_OFFSET, tag)) + return 0; + + return doWriteLockPage(absPtr, fullId); + } + + /** + * @param absPtr Absolute pointer. + * @return Pointer to the page write buffer. + */ + private long writeLockPage(long absPtr, FullPageId fullId, boolean checkTag) { + int tag = checkTag ? PageIdUtils.tag(fullId.pageId()) : OffheapReadWriteLock.TAG_LOCK_ALWAYS; + + boolean locked = rwLock.writeLock(absPtr + PAGE_LOCK_OFFSET, tag); + + return locked ? doWriteLockPage(absPtr, fullId) : 0; + } + + /** + * @param absPtr Absolute pointer. + * @return Pointer to the page write buffer. + */ + private long doWriteLockPage(long absPtr, FullPageId fullId) { + PageHeader.writeTimestamp(absPtr, U.currentTimeMillis()); + + // Create a buffer copy if the page is scheduled for a checkpoint. + if (isInCheckpoint(fullId)) { + long tmpRelPtr = PageHeader.tempBufferPointer(absPtr); + + if (tmpRelPtr == INVALID_REL_PTR) { + tmpRelPtr = checkpointPool.borrowOrAllocateFreePage(fullId.pageId()); + + if (tmpRelPtr == INVALID_REL_PTR) { + rwLock.writeUnlock(absPtr + PAGE_LOCK_OFFSET, OffheapReadWriteLock.TAG_LOCK_ALWAYS); + + throw new IgniteException("Failed to allocate temporary buffer for checkpoint " + + "(increase checkpointPageBufferSize configuration property)"); + } + + // Pin the page until checkpoint is not finished. + PageHeader.acquirePage(absPtr); + + long tmpAbsPtr = checkpointPool.absolute(tmpRelPtr); + + GridUnsafe.copyMemory(null, absPtr + PAGE_OVERHEAD, null, tmpAbsPtr + PAGE_OVERHEAD, pageSize()); + + PageHeader.tempDirty(absPtr, false); + PageHeader.tempBufferPointer(absPtr, tmpRelPtr); + + assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + assert GridUnsafe.getInt(tmpAbsPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + + return tmpAbsPtr + PAGE_OVERHEAD; + } + else { + long newAbsPrt = checkpointPool.absolute(tmpRelPtr) + PAGE_OVERHEAD; + + assert GridUnsafe.getInt(newAbsPrt + 4) == 0; //TODO GG-11480 + + return newAbsPrt; + } + } + else { + assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + + return absPtr + PAGE_OVERHEAD; + } + } + + /** + * @param page Page pointer. + * @param walPolicy Full page WAL record policy. + */ + private void writeUnlockPage(long page, FullPageId fullId, Boolean walPolicy, boolean markDirty, boolean restore) { + boolean dirtyVisible = isDirtyVisible(page, fullId); + + //if page is for restore, we shouldn't mark it as changed + if (!restore && markDirty && !dirtyVisible) { + changeTracker.apply(page, fullId, this); + } + + boolean pageWalRec = markDirty && walPolicy != FALSE && (walPolicy == TRUE || !dirtyVisible); + long pageId; + + long tmpRel = PageHeader.tempBufferPointer(page); + + if (tmpRel != INVALID_REL_PTR) { + long tmpAbsPtr = checkpointPool.absolute(tmpRel); + + assert GridUnsafe.getInt(tmpAbsPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + + if (markDirty) + setDirty(fullId, page, markDirty, false, true); + + beforeReleaseWrite(fullId, tmpAbsPtr + PAGE_OVERHEAD, pageWalRec); + + pageId = PageIO.getPageId(tmpAbsPtr + PAGE_OVERHEAD); + } + else { + assert GridUnsafe.getInt(page + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + + if (markDirty) + setDirty(fullId, page, markDirty, false, false); + + beforeReleaseWrite(fullId, page + PAGE_OVERHEAD, pageWalRec); + + pageId = PageIO.getPageId(page + PAGE_OVERHEAD); + } + + rwLock.writeUnlock(page + PAGE_LOCK_OFFSET, PageIdUtils.tag(pageId)); + } + + /** + * @param absPtr Absolute pointer to the page. + * @return {@code True} if write lock acquired for the page. + */ + boolean isPageWriteLocked(long absPtr) { + return rwLock.isWriteLocked(absPtr + PAGE_LOCK_OFFSET); + } + + /** + * @param absPtr Absolute pointer to the page. + * @return {@code True} if read lock acquired for the page. + */ + boolean isPageReadLocked(long absPtr) { + return rwLock.isReadLocked(absPtr + PAGE_LOCK_OFFSET); + } + + /** + * @param ptr Pointer to wrap. + * @param len Memory location length. + * @return Wrapped buffer. + */ + ByteBuffer wrapPointer(long ptr, int len) { + ByteBuffer buf = nioAccess.newDirectByteBuffer(ptr, len, null); + + buf.order(ByteOrder.nativeOrder()); + + return buf; + } + + /** + * @param pageId Page ID to check if it was added to the checkpoint list. + * @return {@code True} if it was added to the checkpoint list. + */ + boolean isInCheckpoint(FullPageId pageId) { + Segment seg = segment(pageId.cacheId(), pageId.pageId()); + + Collection pages0 = seg.segCheckpointPages; + + return pages0 != null && pages0.contains(pageId); + } + + /** + * @param fullPageId Page ID to clear. + */ + void clearCheckpoint(FullPageId fullPageId) { + Segment seg = segment(fullPageId.cacheId(), fullPageId.pageId()); + + Collection pages0 = seg.segCheckpointPages; + + assert pages0 != null; + + pages0.remove(fullPageId); + } + + /** + * @param absPtr Absolute pointer. + * @return {@code True} if page is dirty. + */ + boolean isDirty(long absPtr) { + return PageHeader.dirty(absPtr); + } + + /** + * @param absPtr Absolute pointer. + * @return {@code True} if page is dirty in temporary buffer. + */ + boolean isTempDirty(long absPtr) { + return PageHeader.tempDirty(absPtr); + } + + /** + * @param absPtr Absolute page pointer. + * @param fullId Full page ID. + * @return If page is visible to memory user as dirty. + */ + boolean isDirtyVisible(long absPtr, FullPageId fullId) { + Collection cp = segment(fullId.cacheId(), fullId.pageId()).segCheckpointPages; + + if (cp == null || !cp.contains(fullId)) + return isDirty(absPtr); + else { + long tmpPtr = PageHeader.tempBufferPointer(absPtr); + + return tmpPtr != INVALID_REL_PTR && PageHeader.tempDirty(absPtr); + } + } + + /** + * Gets the number of active pages across all segments. Used for test purposes only. + * + * @return Number of active pages. + */ + public int activePagesCount() { + int total = 0; + + for (Segment seg : segments) + total += seg.acquiredPages(); + + return total; + } + + /** + * This method must be called in synchronized context. + * + * @param absPtr Absolute pointer. + * @param dirty {@code True} dirty flag. + * @param forceAdd If this flag is {@code true}, then the page will be added to the dirty set regardless whether + * the old flag was dirty or not. + */ + void setDirty(FullPageId pageId, long absPtr, boolean dirty, boolean forceAdd, boolean tmp) { + boolean wasDirty = tmp ? PageHeader.tempDirty(absPtr, dirty) : PageHeader.dirty(absPtr, dirty); + + if (dirty) { + if (!wasDirty || forceAdd) + segment(pageId.cacheId(), pageId.pageId()).dirtyPages.add(pageId); + } + else + segment(pageId.cacheId(), pageId.pageId()).dirtyPages.remove(pageId); + } + + /** + * + */ + void beforeReleaseWrite(FullPageId pageId, long ptr, boolean pageWalRec) { + if (walMgr != null && (pageWalRec || walMgr.isAlwaysWriteFullPages())) { + try { + walMgr.log(new PageSnapshot(pageId, ptr, pageSize())); + } + catch (IgniteCheckedException e) { + // TODO ignite-db. + throw new IgniteException(e); + } + } + } + + /** + * @param cacheId Cache ID. + * @param pageId Page ID. + * @return Segment. + */ + private Segment segment(int cacheId, long pageId) { + int idx = segmentIndex(cacheId, pageId, segments.length); + + return segments[idx]; + } + + /** + * @param pageId Page ID. + * @return Segment index. + */ + public static int segmentIndex(int cacheId, long pageId, int segments) { + pageId = PageIdUtils.effectivePageId(pageId); + + // Take a prime number larger than total number of partitions. + int hash = U.hash(pageId * 65537 + cacheId); + + return U.safeAbs(hash) % segments; + } + + /** + * + */ + private class PagePool { + /** Segment index. */ + protected final int idx; + + /** Direct memory region. */ + protected final DirectMemoryRegion region; + + /** */ + protected long lastAllocatedIdxPtr; + + /** Pointer to the address of the free page list. */ + protected long freePageListPtr; + + /** Pages base. */ + protected long pagesBase; + + /** + * @param idx Index. + * @param region Region + */ + protected PagePool(int idx, DirectMemoryRegion region) { + this.idx = idx; + this.region = region; + + long base = (region.address() + 7) & ~0x7; + + freePageListPtr = base; + + base += 8; + + lastAllocatedIdxPtr = base; + + base += 8; + + // Align page start by + pagesBase = base; + + GridUnsafe.putLong(freePageListPtr, INVALID_REL_PTR); + GridUnsafe.putLong(lastAllocatedIdxPtr, 1L); + } + + /** + * Allocates a new free page. + * + * @return Relative pointer to the allocated page. + * @throws GridOffHeapOutOfMemoryException If failed to allocate new free page. + * @param pageId Page ID to to initialize. + */ + private long borrowOrAllocateFreePage(long pageId) throws GridOffHeapOutOfMemoryException { + long relPtr = borrowFreePage(); + + return relPtr != INVALID_REL_PTR ? relPtr : allocateFreePage(pageId); + } + + /** + * @return Relative pointer to a free page that was borrowed from the allocated pool. + */ + private long borrowFreePage() { + while (true) { + long freePageRelPtrMasked = GridUnsafe.getLong(freePageListPtr); + + long freePageRelPtr = freePageRelPtrMasked & ADDRESS_MASK; + + if (freePageRelPtr != INVALID_REL_PTR) { + long freePageAbsPtr = absolute(freePageRelPtr); + + long nextFreePageRelPtr = GridUnsafe.getLong(freePageAbsPtr) & ADDRESS_MASK; + + long cnt = ((freePageRelPtrMasked & COUNTER_MASK) + COUNTER_INC) & COUNTER_MASK; + + if (GridUnsafe.compareAndSwapLong(null, freePageListPtr, freePageRelPtrMasked, nextFreePageRelPtr | cnt)) { + GridUnsafe.putLong(freePageAbsPtr, PAGE_MARKER); + + return freePageRelPtr; + } + } + else + return INVALID_REL_PTR; + } + } + + /** + * @return Relative pointer of the allocated page. + * @throws GridOffHeapOutOfMemoryException If failed to allocate new free page. + * @param pageId Page ID. + */ + private long allocateFreePage(long pageId) throws GridOffHeapOutOfMemoryException { + long limit = region.address() + region.size(); + + while (true) { + long lastIdx = GridUnsafe.getLong(lastAllocatedIdxPtr); + + // Check if we have enough space to allocate a page. + if (pagesBase + (lastIdx + 1) * sysPageSize > limit) + return INVALID_REL_PTR; + + if (GridUnsafe.compareAndSwapLong(null, lastAllocatedIdxPtr, lastIdx, lastIdx + 1)) { + long absPtr = pagesBase + lastIdx * sysPageSize; + + assert (lastIdx & SEGMENT_INDEX_MASK) == 0L; + + long relative = relative(lastIdx); + + assert relative != INVALID_REL_PTR; + + PageHeader.initNew(absPtr, relative); + + rwLock.init(absPtr + PAGE_LOCK_OFFSET, PageIdUtils.tag(pageId)); + + return relative; + } + } + } + + /** + * @param relPtr Relative pointer to free. + */ + private void releaseFreePage(long relPtr) { + long absPtr = absolute(relPtr); + + assert !PageHeader.isAcquired(absPtr) : "Release pinned page: " + PageHeader.fullPageId(absPtr); + + while (true) { + long freePageRelPtrMasked = GridUnsafe.getLong(freePageListPtr); + + long freePageRelPtr = freePageRelPtrMasked & RELATIVE_PTR_MASK; + + GridUnsafe.putLong(absPtr, freePageRelPtr); + + if (GridUnsafe.compareAndSwapLong(null, freePageListPtr, freePageRelPtrMasked, relPtr)) + return; + } + } + + /** + * @param relativePtr Relative pointer. + * @return Absolute pointer. + */ + long absolute(long relativePtr) { + int segIdx = (int)((relativePtr >> 40) & 0xFFFF); + + assert segIdx == idx : "expected=" + idx + ", actual=" + segIdx; + + long pageIdx = relativePtr & ~SEGMENT_INDEX_MASK; + + long off = pageIdx * sysPageSize; + + return pagesBase + off; + } + + /** + * @param pageIdx Page index in the pool. + * @return Relative pointer. + */ + private long relative(long pageIdx) { + return pageIdx | ((long)idx) << 40; + } + + /** + * @return Max number of pages in the pool. + */ + private int pages() { + return (int)((region.size() - (pagesBase - region.address())) / sysPageSize); + } + } + + /** + * + */ + private class Segment extends ReentrantReadWriteLock { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private static final double FULL_SCAN_THRESHOLD = 0.4; + + /** Page ID to relative pointer map. */ + private FullPageIdTable loadedPages; + + /** */ + private long acquiredPagesPtr; + + /** */ + private PagePool pool; + + /** */ + private long memPerTbl; + + /** Pages marked as dirty since the last checkpoint. */ + private Collection dirtyPages = new GridConcurrentHashSet<>(); + + /** */ + private volatile Collection segCheckpointPages; + + /** */ + private final int maxDirtyPages; + + /** */ + private final Map, Integer> partitionTagMap = new HashMap<>(); + + /** + * @param region Memory region. + */ + private Segment(int idx, DirectMemoryRegion region, int cpPoolPages) { + long totalMemory = region.size(); + + int pages = (int)(totalMemory / sysPageSize); + + memPerTbl = requiredSegmentTableMemory(pages); + + acquiredPagesPtr = region.address(); + + GridUnsafe.putIntVolatile(null, acquiredPagesPtr, 0); + + loadedPages = new FullPageIdTable(region.address() + 8, memPerTbl, true); + + DirectMemoryRegion poolRegion = region.slice(memPerTbl + 8); + + pool = new PagePool(idx, poolRegion); + + maxDirtyPages = Math.min(pool.pages() * 2 / 3, cpPoolPages); + } + + /** + * + */ + private boolean safeToUpdate() { + return dirtyPages.size() < maxDirtyPages; + } + + /** + * @return Max number of pages this segment can allocate. + */ + private int pages() { + return pool.pages(); + } + + /** + * @return Memory allocated for pages table. + */ + private long tableSize() { + return memPerTbl; + } + + /** + * @param absPtr Page absolute address to acquire. + */ + private void acquirePage(long absPtr) { + PageHeader.acquirePage(absPtr); + + updateAtomicInt(acquiredPagesPtr, 1); + } + + /** + * @param absPtr Page absolute address to release. + */ + private void releasePage(long absPtr) { + PageHeader.releasePage(absPtr); + + updateAtomicInt(acquiredPagesPtr, -1); + } + + /** + * @return Total number of acquired pages. + */ + private int acquiredPages() { + return GridUnsafe.getInt(acquiredPagesPtr); + } + + /** + * @return Page relative pointer. + * @param pageId Page ID. + */ + private long borrowOrAllocateFreePage(long pageId) { + return pool.borrowOrAllocateFreePage(pageId); + } + + /** + * Prepares a page for eviction, if needed. + * + * @param fullPageId Candidate page full ID. + * @param absPtr Absolute pointer of the page to evict. + * @return {@code True} if it is ok to evict this page, {@code false} if another page should be selected. + * @throws IgniteCheckedException If failed to write page to the underlying store during eviction. + */ + private boolean prepareEvict(FullPageId fullPageId, long absPtr) throws IgniteCheckedException { + assert writeLock().isHeldByCurrentThread(); + + // Do not evict cache meta pages. + if (fullPageId.pageId() == storeMgr.metaPageId(fullPageId.cacheId())) + return false; + + if (PageHeader.isAcquired(absPtr)) + return false; + + Collection cpPages = segCheckpointPages; + + if (isDirty(absPtr)) { + // Can evict a dirty page only if should be written by a checkpoint. + if (cpPages != null && cpPages.contains(fullPageId)) { + assert storeMgr != null; + + flushDirtyPage.applyx(fullPageId, wrapPointer(absPtr + PAGE_OVERHEAD, pageSize()), + partTag(fullPageId.cacheId(), PageIdUtils.partId(fullPageId.pageId()))); + + setDirty(fullPageId, absPtr, false, true, false); + + cpPages.remove(fullPageId); + + return true; + } + + return false; + } + else + // Page was not modified, ok to evict. + return true; + } + + /** + * Evict random oldest page from memory to storage. + * + * @return Relative address for evicted page. + * @throws IgniteCheckedException If failed to evict page. + */ + private long evictPage() throws IgniteCheckedException { + assert getWriteHoldCount() > 0; + + if (!pageEvictWarned) { + pageEvictWarned = true; + + U.warn(log, "Page evictions started, this will affect storage performance (consider increasing " + + "MemoryConfiguration#setPageCacheSize)."); + } + + final ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + final int cap = loadedPages.capacity(); + + if (acquiredPages() >= loadedPages.size()) + throw new IgniteOutOfMemoryException("Failed to evict page from segment (all pages are acquired)."); + + // With big number of random picked pages we may fall into infinite loop, because + // every time the same page may be found. + Set ignored = null; + + long relEvictAddr = INVALID_REL_PTR; + + int iterations = 0; + + while (true) { + long cleanAddr = INVALID_REL_PTR; + long cleanTs = Long.MAX_VALUE; + long dirtyTs = Long.MAX_VALUE; + long dirtyAddr = INVALID_REL_PTR; + + for (int i = 0; i < RANDOM_PAGES_EVICT_NUM; i++) { + ++iterations; + + if (iterations > pool.pages() * FULL_SCAN_THRESHOLD) + break; + + // We need to lookup for pages only in current segment for thread safety, + // so peeking random memory will lead to checking for found page segment. + // It's much faster to check available pages for segment right away. + EvictCandidate nearest = loadedPages.getNearestAt(rnd.nextInt(cap), INVALID_REL_PTR); + + assert nearest != null && nearest.relativePointer() != INVALID_REL_PTR; + + long rndAddr = nearest.relativePointer(); + + int partTag = nearest.tag(); + + final long absPageAddr = absolute(rndAddr); + + FullPageId fullId = PageHeader.fullPageId(absPageAddr); + + // Check page mapping consistency. + assert fullId.equals(nearest.fullId()) : "Invalid page mapping [tableId=" + nearest.fullId() + + ", actual=" + fullId + ", nearest=" + nearest; + + boolean outdated = partTag < partTag(fullId.cacheId(), PageIdUtils.partId(fullId.pageId())); + + if (outdated) + return refreshOutdatedPage(this, fullId.cacheId(), fullId.pageId(), true); + + boolean pinned = PageHeader.isAcquired(absPageAddr); + + boolean skip = ignored != null && ignored.contains(rndAddr); + + if (relEvictAddr == rndAddr || pinned || skip) { + i--; + + continue; + } + + final long pageTs = PageHeader.readTimestamp(absPageAddr); + + final boolean dirty = isDirty(absPageAddr); + + if (pageTs < cleanTs && !dirty) { + cleanAddr = rndAddr; + + cleanTs = pageTs; + } + else if (pageTs < dirtyTs && dirty) { + dirtyAddr = rndAddr; + + dirtyTs = pageTs; + } + + relEvictAddr = cleanAddr == INVALID_REL_PTR ? dirtyAddr : cleanAddr; + } + + assert relEvictAddr != INVALID_REL_PTR; + + final long absEvictAddr = absolute(relEvictAddr); + + final FullPageId fullPageId = PageHeader.fullPageId(absEvictAddr); + + if (!prepareEvict(fullPageId, absEvictAddr)) { + if (iterations > 10) { + if (ignored == null) + ignored = new HashSet<>(); + + ignored.add(relEvictAddr); + } + + if (iterations > pool.pages() * FULL_SCAN_THRESHOLD) + return tryToFindSequentially(cap); + + continue; + } + + loadedPages.remove(fullPageId.cacheId(), PageIdUtils.effectivePageId(fullPageId.pageId()), + partTag(fullPageId.cacheId(), PageIdUtils.partId(fullPageId.pageId()))); + + return relEvictAddr; + } + } + + /** + * Will scan all segment pages to find one to evict it + * @param cap Capacity. + */ + private long tryToFindSequentially(int cap) throws IgniteCheckedException { + assert getWriteHoldCount() > 0; + + long prevAddr = INVALID_REL_PTR; + int pinnedCnt = 0; + int failToPrepare = 0; + + for (int i = 0; i < cap; i++) { + final EvictCandidate nearest = loadedPages.getNearestAt(i, INVALID_REL_PTR); + + assert nearest != null && nearest.relativePointer() != INVALID_REL_PTR; + + final long addr = nearest.relativePointer(); + + int partTag = nearest.tag(); + + final long absPageAddr = absolute(addr); + + FullPageId fullId = PageHeader.fullPageId(absPageAddr); + + if (partTag < partTag(fullId.cacheId(), PageIdUtils.partId(fullId.pageId()))) + return refreshOutdatedPage(this, fullId.cacheId(), fullId.pageId(), true); + + boolean pinned = PageHeader.isAcquired(absPageAddr); + + if (pinned) + pinnedCnt++; + + if (addr == prevAddr || pinned) + continue; + + final long absEvictAddr = absolute(addr); + + final FullPageId fullPageId = PageHeader.fullPageId(absEvictAddr); + + if (prepareEvict(fullPageId, absEvictAddr)) { + loadedPages.remove(fullPageId.cacheId(), PageIdUtils.effectivePageId(fullPageId.pageId()), + partTag(fullPageId.cacheId(), PageIdUtils.partId(fullPageId.pageId()))); + + return addr; + } + else + failToPrepare++; + + prevAddr = addr; + } + + throw new IgniteOutOfMemoryException("Failed to find a page for eviction [segmentCapacity=" + cap + + ", loaded=" + loadedPages.size() + + ", maxDirtyPages=" + maxDirtyPages + + ", dirtyPages=" + dirtyPages.size() + + ", cpPages=" + (segCheckpointPages == null ? 0 : segCheckpointPages.size()) + + ", pinnedInSegment=" + pinnedCnt + + ", failedToPrepare=" + failToPrepare + + ']'); + } + + /** + * Delegate to the corresponding page pool. + * + * @param relPtr Relative pointer. + * @return Absolute pointer. + */ + private long absolute(long relPtr) { + return pool.absolute(relPtr); + } + + /** + * @param cacheId Cache ID. + * @param partId Partition ID. + * @return Partition tag. + */ + private int partTag(int cacheId, int partId) { + assert getReadHoldCount() > 0 || getWriteHoldCount() > 0; + + Integer tag = partitionTagMap.get(new T2<>(cacheId, partId)); + + if (tag == null) + return 1; + + return tag; + } + + /** + * @param cacheId Cache ID. + * @param partId Partition ID. + * @return New partition tag. + */ + private int incrementPartTag(int cacheId, int partId) { + assert getWriteHoldCount() > 0; + + T2 t = new T2<>(cacheId, partId); + + Integer tag = partitionTagMap.get(t); + + if (tag == null) { + partitionTagMap.put(t, 2); + + return 2; + } + else if (tag == Integer.MAX_VALUE) { + U.warn(log, "Partition tag overflow [cacheId=" + cacheId + ", partId=" + partId + "]"); + + partitionTagMap.put(t, 0); + + return 0; + } + else { + partitionTagMap.put(t, tag + 1); + + return tag + 1; + } + } + + private void resetPartTags(int cacheId) { + assert getWriteHoldCount() > 0; + + Iterator> iter = partitionTagMap.keySet().iterator(); + + while (iter.hasNext()) { + T2 t = iter.next(); + + if (t.get1() == cacheId) + iter.remove(); + } + } + } + + /** + * Gets an estimate for the amount of memory required to store the given number of page IDs + * in a segment table. + * + * @param pages Number of pages to store. + * @return Memory size estimate. + */ + private static long requiredSegmentTableMemory(int pages) { + return FullPageIdTable.requiredMemory(pages) + 8; + } + + /** + * @param ptr Pointer to update. + * @param delta Delta. + */ + private static int updateAtomicInt(long ptr, int delta) { + while (true) { + int old = GridUnsafe.getInt(ptr); + + int updated = old + delta; + + if (GridUnsafe.compareAndSwapInt(null, ptr, old, updated)) + return updated; + } + } + + /** + * @param ptr Pointer to update. + * @param delta Delta. + */ + private static long updateAtomicLong(long ptr, long delta) { + while (true) { + long old = GridUnsafe.getLong(ptr); + + long updated = old + delta; + + if (GridUnsafe.compareAndSwapLong(null, ptr, old, updated)) + return updated; + } + } + + /** + * + */ + private static class PageHeader { + /** + * @param absPtr Absolute pointer to initialize. + * @param relative Relative pointer to write. + */ + private static void initNew(long absPtr, long relative) { + relative(absPtr, relative); + + tempBufferPointer(absPtr, INVALID_REL_PTR); + + GridUnsafe.putLong(absPtr, PAGE_MARKER); + GridUnsafe.putInt(absPtr + PAGE_PIN_CNT_OFFSET, 0); + } + + /** + * @param absPtr Absolute pointer. + * @return Dirty flag. + */ + private static boolean dirty(long absPtr) { + return flag(absPtr, DIRTY_FLAG); + } + + /** + * @param absPtr Page absolute pointer. + * @param dirty Dirty flag. + * @return Previous value of dirty flag. + */ + private static boolean dirty(long absPtr, boolean dirty) { + return flag(absPtr, DIRTY_FLAG, dirty); + } + + /** + * @param absPtr Absolute pointer. + * @return Dirty flag. + */ + private static boolean tempDirty(long absPtr) { + return flag(absPtr, TMP_DIRTY_FLAG); + } + + /** + * @param absPtr Absolute pointer. + * @param tmpDirty Temp dirty flag. + * @return Previous value of temp dirty flag. + */ + private static boolean tempDirty(long absPtr, boolean tmpDirty) { + return flag(absPtr, TMP_DIRTY_FLAG, tmpDirty); + } + + /** + * @param absPtr Absolute pointer. + * @param flag Flag mask. + * @return Flag value. + */ + private static boolean flag(long absPtr, long flag) { + assert (flag & 0xFFFFFFFFFFFFFFL) == 0; + assert Long.bitCount(flag) == 1; + + long relPtrWithFlags = GridUnsafe.getLong(absPtr + RELATIVE_PTR_OFFSET); + + return (relPtrWithFlags & flag) != 0; + } + + /** + * Sets flag. + * + * @param absPtr Absolute pointer. + * @param flag Flag mask. + * @param set New flag value. + * @return Previous flag value. + */ + private static boolean flag(long absPtr, long flag, boolean set) { + assert (flag & 0xFFFFFFFFFFFFFFL) == 0; + assert Long.bitCount(flag) == 1; + + long relPtrWithFlags = GridUnsafe.getLong(absPtr + RELATIVE_PTR_OFFSET); + + boolean was = (relPtrWithFlags & flag) != 0; + + if (set) + relPtrWithFlags |= flag; + else + relPtrWithFlags &= ~flag; + + GridUnsafe.putLong(absPtr + RELATIVE_PTR_OFFSET, relPtrWithFlags); + + return was; + } + + /** + * @param absPtr Page pointer. + * @return If page is pinned. + */ + private static boolean isAcquired(long absPtr) { + return GridUnsafe.getInt(absPtr + PAGE_PIN_CNT_OFFSET) > 0; + } + + /** + * @param absPtr Absolute pointer. + */ + private static void acquirePage(long absPtr) { + updateAtomicInt(absPtr + PAGE_PIN_CNT_OFFSET, 1); + } + + /** + * @param absPtr Absolute pointer. + */ + private static int releasePage(long absPtr) { + return updateAtomicInt(absPtr + PAGE_PIN_CNT_OFFSET, -1); + } + + /** + * Reads relative pointer from the page at the given absolute position. + * + * @param absPtr Absolute memory pointer to the page header. + * @return Relative pointer written to the page. + */ + private static long readRelative(long absPtr) { + return GridUnsafe.getLong(absPtr + RELATIVE_PTR_OFFSET) & RELATIVE_PTR_MASK; + } + + /** + * Writes relative pointer to the page at the given absolute position. + * + * @param absPtr Absolute memory pointer to the page header. + * @param relPtr Relative pointer to write. + */ + private static void relative(long absPtr, long relPtr) { + GridUnsafe.putLong(absPtr + RELATIVE_PTR_OFFSET, relPtr & RELATIVE_PTR_MASK); + } + + /** + * Volatile write for current timestamp to page in {@code absAddr} address. + * + * @param absPtr Absolute page address. + */ + private static void writeTimestamp(final long absPtr, long tstamp) { + tstamp >>= 8; + + GridUnsafe.putLongVolatile(null, absPtr, (tstamp << 8) | 0x01); + } + + /** + * Read for timestamp from page in {@code absAddr} address. + * + * @param absPtr Absolute page address. + * @return Timestamp. + */ + private static long readTimestamp(final long absPtr) { + long markerAndTs = GridUnsafe.getLong(absPtr); + + // Clear last byte as it is occupied by page marker. + return markerAndTs & ~0xFF; + } + + /** + * @param absPtr Page absolute pointer. + * @param tmpRelPtr Temp buffer relative pointer. + */ + private static void tempBufferPointer(long absPtr, long tmpRelPtr) { + GridUnsafe.putLong(absPtr + PAGE_TMP_BUF_OFFSET, tmpRelPtr); + } + + /** + * @param absPtr Page absolute pointer. + * @return Temp buffer relative pointer. + */ + private static long tempBufferPointer(long absPtr) { + return GridUnsafe.getLong(absPtr + PAGE_TMP_BUF_OFFSET); + } + + /** + * Reads page ID from the page at the given absolute position. + * + * @param absPtr Absolute memory pointer to the page header. + * @return Page ID written to the page. + */ + private static long readPageId(long absPtr) { + return GridUnsafe.getLong(absPtr + PAGE_ID_OFFSET); + } + + /** + * Writes page ID to the page at the given absolute position. + * + * @param absPtr Absolute memory pointer to the page header. + * @param pageId Page ID to write. + */ + private static void pageId(long absPtr, long pageId) { + GridUnsafe.putLong(absPtr + PAGE_ID_OFFSET, pageId); + } + + /** + * Reads cache ID from the page at the given absolute pointer. + * + * @param absPtr Absolute memory pointer to the page header. + * @return Cache ID written to the page. + */ + private static int readPageCacheId(final long absPtr) { + return GridUnsafe.getInt(absPtr + PAGE_CACHE_ID_OFFSET); + } + + /** + * Writes cache ID from the page at the given absolute pointer. + * + * @param absPtr Absolute memory pointer to the page header. + * @param cacheId Cache ID to write. + */ + private static void pageCacheId(final long absPtr, final int cacheId) { + GridUnsafe.putInt(absPtr + PAGE_CACHE_ID_OFFSET, cacheId); + } + + /** + * Reads page ID and cache ID from the page at the given absolute pointer. + * + * @param absPtr Absolute memory pointer to the page header. + * @return Full page ID written to the page. + */ + private static FullPageId fullPageId(final long absPtr) { + return new FullPageId(readPageId(absPtr), readPageCacheId(absPtr)); + } + + /** + * Writes page ID and cache ID from the page at the given absolute pointer. + * + * @param absPtr Absolute memory pointer to the page header. + * @param fullPageId Full page ID to write. + */ + private static void fullPageId(final long absPtr, final FullPageId fullPageId) { + pageId(absPtr, fullPageId.pageId()); + + pageCacheId(absPtr, fullPageId.cacheId()); + } + } + + /** + * + */ + private static class ClearSegmentRunnable implements Runnable { + /** */ + private Segment seg; + + /** */ + private GridPredicate3 clearPred; + + /** */ + private CountDownFuture doneFut; + + /** */ + private int pageSize; + + /** */ + private boolean rmvDirty; + + /** + * @param seg Segment. + * @param clearPred Clear predicate. + * @param doneFut Completion future. + */ + private ClearSegmentRunnable( + Segment seg, + GridPredicate3 clearPred, + boolean rmvDirty, + CountDownFuture doneFut, + int pageSize + ) { + this.seg = seg; + this.clearPred = clearPred; + this.rmvDirty = rmvDirty; + this.doneFut = doneFut; + this.pageSize = pageSize; + } + + /** {@inheritDoc} */ + @Override public void run() { + int cap = seg.loadedPages.capacity(); + + int chunkSize = 1000; + GridLongList ptrs = new GridLongList(chunkSize); + + try { + for (int base = 0; base < cap; ) { + int boundary = Math.min(cap, base + chunkSize); + + seg.writeLock().lock(); + + try { + while (base < boundary) { + long ptr = seg.loadedPages.clearAt(base, clearPred, INVALID_REL_PTR); + + if (ptr != INVALID_REL_PTR) + ptrs.add(ptr); + + base++; + } + } + finally { + seg.writeLock().unlock(); + } + + for (int i = 0; i < ptrs.size(); i++) { + long relPtr = ptrs.get(i); + + long absPtr = seg.pool.absolute(relPtr); + + if (rmvDirty) { + FullPageId fullId = PageHeader.fullPageId(absPtr); + + seg.dirtyPages.remove(fullId); + } + + GridUnsafe.setMemory(absPtr + PAGE_OVERHEAD, pageSize, (byte)0); + + seg.pool.releaseFreePage(relPtr); + } + + ptrs.clear(); + } + + doneFut.onDone((Void)null); + } + catch (Throwable e) { + doneFut.onDone(e); + } + } + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInput.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInput.java new file mode 100644 index 0000000000000..d8303759d1228 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInput.java @@ -0,0 +1,23 @@ +package org.apache.ignite.internal.processors.cache.database.wal; + + +import java.io.DataInput; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * ByteBuffer backed data input + */ +public interface ByteBufferBackedDataInput extends DataInput { + /** + * @return ByteBuffer hold by data input + */ + public ByteBuffer buffer(); + + /** + * ensure that requested count of byte is available in data input and will try to load data if not + * @param requested Requested number of bytes. + * @throws IOException If failed. + */ + public void ensure(int requested) throws IOException; +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInputImpl.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInputImpl.java new file mode 100644 index 0000000000000..9d3f88388dfa3 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInputImpl.java @@ -0,0 +1,156 @@ +package org.apache.ignite.internal.processors.cache.database.wal; + +import java.io.IOException; +import java.nio.ByteBuffer; +import org.jetbrains.annotations.NotNull; + +/** + * Byte buffer backed data input. + */ +public class ByteBufferBackedDataInputImpl implements ByteBufferBackedDataInput { + /** Buffer. */ + private ByteBuffer buf; + + /** + * @param buf New buffer. + */ + public ByteBufferBackedDataInput buffer(ByteBuffer buf) { + this.buf = buf; + + return this; + } + + /** {@inheritDoc} */ + @Override public ByteBuffer buffer() { + return buf; + } + + /** {@inheritDoc} */ + @Override public void ensure(int requested) throws IOException { + if (buf.remaining() < requested) + throw new IOException("Requested size is greater than buffer: " + requested); + } + + /** {@inheritDoc} */ + @Override public void readFully(@NotNull byte[] b) throws IOException { + ensure(b.length); + + buf.get(b); + } + + /** {@inheritDoc} */ + @Override public void readFully(@NotNull byte[] b, int off, int len) throws IOException { + ensure(b.length); + + buf.get(b, off, len); + } + + /** + * {@inheritDoc} + */ + @Override public int skipBytes(int n) throws IOException { + ensure(n); + + buf.position(buf.position() + n); + + return n; + } + + /** + * {@inheritDoc} + */ + @Override public boolean readBoolean() throws IOException { + return readByte() == 1; + } + + /** + * {@inheritDoc} + */ + @Override public byte readByte() throws IOException { + ensure(1); + + return buf.get(); + } + + /** + * {@inheritDoc} + */ + @Override public int readUnsignedByte() throws IOException { + return readByte() & 0xFF; + } + + /** + * {@inheritDoc} + */ + @Override public short readShort() throws IOException { + ensure(2); + + return buf.getShort(); + } + + /** + * {@inheritDoc} + */ + @Override public int readUnsignedShort() throws IOException { + return readShort() & 0xFFFF; + } + + /** + * {@inheritDoc} + */ + @Override public char readChar() throws IOException { + ensure(2); + + return buf.getChar(); + } + + /** + * {@inheritDoc} + */ + @Override public int readInt() throws IOException { + ensure(4); + + return buf.getInt(); + } + + /** + * {@inheritDoc} + */ + @Override public long readLong() throws IOException { + ensure(8); + + return buf.getLong(); + } + + /** + * {@inheritDoc} + */ + @Override public float readFloat() throws IOException { + ensure(4); + + return buf.getFloat(); + } + + /** + * {@inheritDoc} + */ + @Override public double readDouble() throws IOException { + ensure(8); + + return buf.getDouble(); + } + + /** + * {@inheritDoc} + */ + @Override public String readLine() throws IOException { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + @Override public String readUTF() throws IOException { + throw new UnsupportedOperationException(); + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java new file mode 100644 index 0000000000000..b6c30d17bc4ac --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java @@ -0,0 +1,432 @@ +package org.apache.ignite.internal.processors.cache.database.wal; + +import java.io.EOFException; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import org.apache.ignite.internal.processors.cache.database.wal.crc.IgniteDataIntegrityViolationException; +import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; +import org.jetbrains.annotations.NotNull; + +/** + * File input. + */ +public final class FileInput implements ByteBufferBackedDataInput { + /** */ + private ByteBuffer buf; + + /** */ + private FileChannel ch; + + /** */ + private long pos; + + /** + * @param ch Channel. + * @param buf Buffer. + */ + public FileInput(FileChannel ch, ByteBuffer buf) throws IOException { + assert ch != null; + + this.ch = ch; + this.buf = buf; + + pos = ch.position(); + + clearBuffer(); + } + + /** + * Clear buffer. + */ + private void clearBuffer() { + buf.clear(); + buf.limit(0); + + assert buf.remaining() == 0; // Buffer is empty. + } + + /** + * @param pos Position in bytes from file begin. + */ + public void seek(long pos) throws IOException { + if (pos > ch.size()) + throw new EOFException(); + + ch.position(pos); + + this.pos = pos; + + clearBuffer(); + } + + /** + * @return Underlying buffer. + */ + @Override public ByteBuffer buffer() { + return buf; + } + + + /** {@inheritDoc} */ + @Override public void ensure(int requested) throws IOException { + int available = buf.remaining(); + + if (available >= requested) + return; + + if (buf.capacity() < requested) + throw new IOException("Requested size is greater than buffer: " + requested); + + buf.compact(); + + do { + int read = ch.read(buf); + + if (read == -1) + throw new EOFException(); + + available += read; + + pos += read; + } + while (available < requested); + + buf.flip(); + } + + /** + * @return Position in the stream. + */ + public long position() { + return pos - buf.remaining(); + } + + /** + * {@inheritDoc} + */ + @Override public void readFully(@NotNull byte[] b) throws IOException { + ensure(b.length); + + buf.get(b); + } + + /** + * {@inheritDoc} + */ + @Override public void readFully(@NotNull byte[] b, int off, int len) throws IOException { + ensure(len); + + buf.get(b, off, len); + } + + /** + * {@inheritDoc} + */ + @Override public int skipBytes(int n) throws IOException { + if (buf.remaining() >= n) + buf.position(buf.position() + n); + else + seek(pos + n); + + return n; + } + + /** + * {@inheritDoc} + */ + @Override public boolean readBoolean() throws IOException { + return readByte() == 1; + } + + /** + * {@inheritDoc} + */ + @Override public byte readByte() throws IOException { + ensure(1); + + return buf.get(); + } + + /** + * {@inheritDoc} + */ + @Override public int readUnsignedByte() throws IOException { + return readByte() & 0xFF; + } + + /** + * {@inheritDoc} + */ + @Override public short readShort() throws IOException { + ensure(2); + + return buf.getShort(); + } + + /** + * {@inheritDoc} + */ + @Override public int readUnsignedShort() throws IOException { + return readShort() & 0xFFFF; + } + + /** + * {@inheritDoc} + */ + @Override public char readChar() throws IOException { + ensure(2); + + return buf.getChar(); + } + + /** + * {@inheritDoc} + */ + @Override public int readInt() throws IOException { + ensure(4); + + return buf.getInt(); + } + + /** + * {@inheritDoc} + */ + @Override public long readLong() throws IOException { + ensure(8); + + return buf.getLong(); + } + + /** + * {@inheritDoc} + */ + @Override public float readFloat() throws IOException { + ensure(4); + + return buf.getFloat(); + } + + /** + * {@inheritDoc} + */ + @Override public double readDouble() throws IOException { + ensure(8); + + return buf.getDouble(); + } + + /** + * {@inheritDoc} + */ + @Override public String readLine() throws IOException { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + @Override public String readUTF() throws IOException { + throw new UnsupportedOperationException(); + } + + /** + * @param skipCheck If CRC check should be skipped. + * @return autoclosable fileInput, after its closing crc32 will be calculated and compared with saved one + */ + public Crc32CheckingFileInput startRead(boolean skipCheck) { + return new Crc32CheckingFileInput(buf.position(), skipCheck); + } + + /** + * Checking of CRC32. + */ + public class Crc32CheckingFileInput implements ByteBufferBackedDataInput, AutoCloseable { + /** */ + private final PureJavaCrc32 crc32 = new PureJavaCrc32(); + + /** Last calc position. */ + private int lastCalcPosition; + + /** Skip crc check. */ + private boolean skipCheck; + + /** + * @param position Position. + */ + public Crc32CheckingFileInput(int position, boolean skipCheck) { + this.lastCalcPosition = position; + this.skipCheck = skipCheck; + } + + /** {@inheritDoc} */ + @Override public void ensure(int requested) throws IOException { + int available = buf.remaining(); + + if (available >= requested) + return; + + updateCrc(); + + FileInput.this.ensure(requested); + + lastCalcPosition = 0; + } + + /** {@inheritDoc} */ + @Override public void close() throws Exception { + updateCrc(); + + int val = crc32.getValue(); + + int writtenCrc = this.readInt(); + + if ((val ^ writtenCrc) != 0 && !skipCheck) { + ensure(5); //if it last message we will skip it (EOF will be thrown) + throw new IgniteDataIntegrityViolationException(); + } + } + + /** + * + */ + private void updateCrc() { + if (skipCheck) + return; + + int oldPos = buf.position(); + + buf.position(lastCalcPosition); + + crc32.update(buf, oldPos - lastCalcPosition); + + lastCalcPosition = oldPos; + } + + /** {@inheritDoc} */ + @Override public int skipBytes(int n) throws IOException { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + @Override public void readFully(@NotNull byte[] b) throws IOException { + ensure(b.length); + + buf.get(b); + } + + /** + * {@inheritDoc} + */ + @Override public void readFully(@NotNull byte[] b, int off, int len) throws IOException { + ensure(len); + + buf.get(b, off, len); + } + + /** + * {@inheritDoc} + */ + @Override public boolean readBoolean() throws IOException { + return readByte() == 1; + } + + /** + * {@inheritDoc} + */ + @Override public byte readByte() throws IOException { + ensure(1); + + return buf.get(); + } + + /** + * {@inheritDoc} + */ + @Override public int readUnsignedByte() throws IOException { + return readByte() & 0xFF; + } + + /** + * {@inheritDoc} + */ + @Override public short readShort() throws IOException { + ensure(2); + + return buf.getShort(); + } + + /** + * {@inheritDoc} + */ + @Override public int readUnsignedShort() throws IOException { + return readShort() & 0xFFFF; + } + + /** + * {@inheritDoc} + */ + @Override public char readChar() throws IOException { + ensure(2); + + return buf.getChar(); + } + + /** + * {@inheritDoc} + */ + @Override public int readInt() throws IOException { + ensure(4); + + return buf.getInt(); + } + + /** + * {@inheritDoc} + */ + @Override public long readLong() throws IOException { + ensure(8); + + return buf.getLong(); + } + + /** + * {@inheritDoc} + */ + @Override public float readFloat() throws IOException { + ensure(4); + + return buf.getFloat(); + } + + /** + * {@inheritDoc} + */ + @Override public double readDouble() throws IOException { + ensure(8); + + return buf.getDouble(); + } + + /** + * {@inheritDoc} + */ + @Override public String readLine() throws IOException { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + @Override public String readUTF() throws IOException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public ByteBuffer buffer() { + return FileInput.this.buffer(); + } + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java new file mode 100644 index 0000000000000..329ccda2ba4cc --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java @@ -0,0 +1,93 @@ +package org.apache.ignite.internal.processors.cache.database.wal; + +import org.apache.ignite.internal.pagemem.wal.WALPointer; +import org.apache.ignite.internal.util.typedef.internal.S; + +/** + * File WAL pointer. + */ +public class FileWALPointer implements WALPointer, Comparable { + /** */ + private final int idx; + + /** */ + private final int fileOffset; + + /** Written record length */ + private int len; + + /** + * @param idx File timestamp index. + * @param fileOffset Offset in file, from the beginning. + */ + public FileWALPointer(int idx, int fileOffset, int len) { + this.idx = idx; + this.fileOffset = fileOffset; + this.len = len; + } + + /** + * @return Timestamp index. + */ + public int index() { + return idx; + } + + /** + * @return File offset. + */ + public int fileOffset() { + return fileOffset; + } + + /** + * @return Record length. + */ + public int length() { + return len; + } + + /** {@inheritDoc} */ + @Override public WALPointer next() { + if (len == 0) + throw new IllegalStateException("Failed to calculate next WAL pointer " + + "(this pointer is a terminal): " + this); + + // Return a terminal pointer. + return new FileWALPointer(idx, fileOffset + len, 0); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (!(o instanceof FileWALPointer)) + return false; + + FileWALPointer that = (FileWALPointer)o; + + return idx == that.idx && fileOffset == that.fileOffset; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int result = idx; + + result = 31 * result + fileOffset; + + return result; + } + + /** {@inheritDoc} */ + @Override public int compareTo(FileWALPointer o) { + int res = Integer.compare(idx, o.idx); + + return res == 0 ? Integer.compare(fileOffset, o.fileOffset) : res; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(FileWALPointer.class, this); + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java new file mode 100644 index 0000000000000..e53a92d0d7218 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -0,0 +1,2310 @@ +package org.apache.ignite.internal.processors.cache.database.wal; + +import java.io.EOFException; +import java.io.File; +import java.io.FileFilter; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.FileChannel; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.NavigableMap; +import java.util.TreeMap; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.LockSupport; +import java.util.concurrent.locks.ReentrantLock; +import java.util.regex.Pattern; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.pagemem.wal.StorageException; +import org.apache.ignite.internal.pagemem.wal.WALIterator; +import org.apache.ignite.internal.pagemem.wal.WALPointer; +import org.apache.ignite.internal.pagemem.wal.record.WALRecord; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; +import org.apache.ignite.internal.processors.cache.database.wal.record.HeaderRecord; +import org.apache.ignite.internal.processors.cache.database.wal.serializer.RecordV1Serializer; +import org.apache.ignite.internal.util.GridCloseableIteratorAdapter; +import org.apache.ignite.internal.util.GridUnsafe; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.G; +import org.apache.ignite.internal.util.typedef.internal.A; +import org.apache.ignite.internal.util.typedef.internal.SB; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiTuple; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * File WAL manager. + */ +public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter implements IgniteWriteAheadLogManager { + /** */ + public static final String WAL_SEGMENT_FILE_EXT = ".wal"; + + /** */ + private static final byte[] FILL_BUF = new byte[1024 * 1024]; + + /** */ + private static final Pattern WAL_NAME_PATTERN = Pattern.compile("\\d{16}\\.v\\d+\\.wal"); + + /** */ + private static final Pattern WAL_TEMP_NAME_PATTERN = Pattern.compile("\\d{16}\\.v\\d+\\.wal\\.tmp"); + + /** */ + private static final FileFilter WAL_SEGMENT_FILE_FILTER = new FileFilter() { + @Override public boolean accept(File file) { + return !file.isDirectory() && WAL_NAME_PATTERN.matcher(file.getName()).matches(); + } + }; + + /** */ + private static final FileFilter WAL_SEGMENT_TEMP_FILE_FILTER = new FileFilter() { + @Override public boolean accept(File file) { + return !file.isDirectory() && WAL_TEMP_NAME_PATTERN.matcher(file.getName()).matches(); + } + }; + + /** */ + public static final String IGNITE_PDS_WAL_MODE = "IGNITE_PDS_WAL_MODE"; + + /** */ + public static final String IGNITE_PDS_WAL_TLB_SIZE = "IGNITE_PDS_WAL_TLB_SIZE"; + + /** */ + public static final String IGNITE_PDS_WAL_FLUSH_FREQ = "IGNITE_PDS_WAL_FLUSH_FREQUENCY"; + + /** */ + public static final String IGNITE_PDS_WAL_FSYNC_DELAY = "IGNITE_PDS_WAL_FSYNC_DELAY"; // TODO may be move to config + + /** */ + public static final String IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES = "IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES"; + + /** */ + private static long fsyncDelayNanos = IgniteSystemProperties.getLong(IGNITE_PDS_WAL_FSYNC_DELAY, 1); + + /** */ + public final int tlbSize = IgniteSystemProperties.getInteger(IGNITE_PDS_WAL_TLB_SIZE, 128 * 1024); + + /** WAL flush frequency. Makes sense only for BACKGROUND log mode. */ + public static final int FLUSH_FREQ = IgniteSystemProperties.getInteger(IGNITE_PDS_WAL_FLUSH_FREQ, 2_000); + + /** */ + private final boolean alwaysWriteFullPages = + IgniteSystemProperties.getBoolean(IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES, false); + + /** */ + private long maxWalSegmentSize; + + /** */ + private final PersistenceConfiguration dbCfg; + + /** */ + private IgniteConfiguration igCfg; + + /** */ + private File walWorkDir; + + /** */ + private File walArchiveDir; + + /** */ + private volatile FileWriteHandle currentHnd; + + /** */ + private static final AtomicReferenceFieldUpdater currentHndUpd = + AtomicReferenceFieldUpdater.newUpdater(FileWriteAheadLogManager.class, FileWriteHandle.class, "currentHnd"); + + /** */ + private final ThreadLocal tlb = new ThreadLocal() { + @Override protected ByteBuffer initialValue() { + ByteBuffer buf = ByteBuffer.allocateDirect(tlbSize); + + buf.order(GridUnsafe.NATIVE_BYTE_ORDER); + + return buf; + } + }; + + /** */ + private RecordSerializer serializer; + + /** */ + private volatile FileArchiver archiver; + + /** */ + private final Mode mode; + + /** */ + private QueueFlusher flusher; + + /** */ + private ThreadLocal lastWALPtr = new ThreadLocal<>(); + + /** + * @param igCfg Ignite Configuration. + */ + public FileWriteAheadLogManager(IgniteConfiguration igCfg) { + PersistenceConfiguration dbCfg = igCfg.getPersistenceConfiguration(); + + assert dbCfg != null : "WAL should not be created if persistence is disabled."; + + this.dbCfg = dbCfg; + this.igCfg = igCfg; + + maxWalSegmentSize = dbCfg.getWalSegmentSize(); + + String modeStr = IgniteSystemProperties.getString(IGNITE_PDS_WAL_MODE); + mode = modeStr == null ? Mode.DEFAULT : Mode.valueOf(modeStr.trim().toUpperCase()); + } + + /** {@inheritDoc} */ + @Override public void start0() throws IgniteCheckedException { + String consId = consistentId(); + + if (!cctx.kernalContext().clientNode()) { + A.notNullOrEmpty(consId, "consistentId"); + + consId = U.maskForFileName(consId); + + checkWalConfiguration(); + walWorkDir = initDirectory(dbCfg.getWalStorePath(), "db/wal", consId, "write ahead log work directory"); + walArchiveDir = initDirectory(dbCfg.getWalArchivePath(), "db/wal/archive", consId, + "write ahead log archive directory"); + + serializer = new RecordV1Serializer(cctx); + + checkOrPrepareFiles(); + + archiver = new FileArchiver(); + + if (mode != Mode.DEFAULT) { + if (log.isInfoEnabled()) + log.info("Started write-ahead log manager [mode=" + mode + ']'); + } + } + } + + /** + * @throws IgniteCheckedException if WAL store path is configured and archive path isn't (or vice versa) + */ + private void checkWalConfiguration() throws IgniteCheckedException { + if (dbCfg.getWalStorePath() == null ^ dbCfg.getWalArchivePath() == null) { + throw new IgniteCheckedException("Properties should be either both specified or both null " + + "[walStorePath = " + dbCfg.getWalStorePath() + ", walArchivePath = " + dbCfg.getWalArchivePath() + "]"); + } + } + + /** {@inheritDoc} */ + @Override protected void onKernalStart0(boolean reconnect) throws IgniteCheckedException { + super.onKernalStart0(reconnect); + + if (!cctx.kernalContext().clientNode() && cctx.kernalContext().state().active()) + archiver.start(); + } + + /** + * @return Consistent ID. + */ + protected String consistentId() { + return cctx.discovery().consistentId().toString(); + } + + /** {@inheritDoc} */ + @Override protected void stop0(boolean cancel) { + FileWriteHandle currentHnd = currentHandle(); + + try { + QueueFlusher flusher0 = flusher; + + if (flusher0 != null) { + flusher0.shutdown(); + + if (currentHnd != null) + currentHnd.flush((FileWALPointer)null); + } + + if (currentHnd != null) + currentHnd.close(false); + + if (archiver != null) + archiver.shutdown(); + } + catch (Exception e) { + U.error(log, "Failed to gracefully close WAL segment: " + currentHnd.file, e); + } + } + + /** {@inheritDoc} */ + @Override public void onActivate(GridKernalContext kctx) throws IgniteCheckedException { + if (log.isDebugEnabled()) + log.debug("Activate file write ahead log [nodeId=" + cctx.localNodeId() + + " topVer=" + cctx.discovery().topologyVersionEx() + " ]"); + + start0(); + + if (!cctx.kernalContext().clientNode()) { + archiver = new FileArchiver(); + + archiver.start(); + } + } + + /** {@inheritDoc} */ + @Override public void onDeActivate(GridKernalContext kctx) { + if (log.isDebugEnabled()) + log.debug("DeActivate file write ahead log [nodeId=" + cctx.localNodeId() + + " topVer=" + cctx.discovery().topologyVersionEx() + " ]"); + + stop0(true); + + currentHnd = null; + } + + /** {@inheritDoc} */ + @Override public boolean isAlwaysWriteFullPages() { + return alwaysWriteFullPages; + } + + /** {@inheritDoc} */ + @Override public boolean isFullSync() { + return mode == Mode.DEFAULT; + } + + /** {@inheritDoc} */ + @Override public void resumeLogging(WALPointer lastPtr) throws IgniteCheckedException { + try { + assert currentHnd == null; + assert lastPtr == null || lastPtr instanceof FileWALPointer; + + FileWALPointer filePtr = (FileWALPointer)lastPtr; + + currentHnd = restoreWriteHandle(filePtr); + + if (mode == Mode.BACKGROUND) { + flusher = new QueueFlusher(cctx.igniteInstanceName()); + + flusher.start(); + } + } + catch (StorageException e) { + throw new IgniteCheckedException(e); + } + } + + /** {@inheritDoc} */ + @SuppressWarnings("TooBroadScope") + @Override public WALPointer log(WALRecord record) throws IgniteCheckedException, StorageException { + if (serializer == null || mode == Mode.NONE) + return null; + + FileWriteHandle current = currentHandle(); + + // Logging was not resumed yet. + if (current == null) + return null; + + // Need to calculate record size first. + record.size(serializer.size(record)); + + for (; ; current = rollOver(current)) { + WALPointer ptr = current.addRecord(record); + + if (ptr != null) { + lastWALPtr.set(ptr); + + return ptr; + } + + if (isStopping()) + throw new IgniteCheckedException("Stopping."); + } + } + + /** {@inheritDoc} */ + @Override public void fsync(WALPointer ptr) throws IgniteCheckedException, StorageException { + if (serializer == null || mode == Mode.NONE || mode == Mode.BACKGROUND) + return; + + FileWriteHandle cur = currentHandle(); + + // WAL manager was not started (client node). + if (cur == null) + return; + + FileWALPointer filePtr = (FileWALPointer)(ptr == null ? lastWALPtr.get() : ptr); + + if (mode == Mode.LOG_ONLY) { + cur.flushOrWait(filePtr); + + return; + } + + // No need to sync if was rolled over. + if (filePtr != null && !cur.needFsync(filePtr)) + return; + + cur.fsync(filePtr); + } + + /** {@inheritDoc} */ + @Override public WALIterator replay(WALPointer start) + throws IgniteCheckedException, StorageException { + assert start == null || start instanceof FileWALPointer : "Invalid start pointer: " + start; + + FileWriteHandle hnd = currentHandle(); + + FileWALPointer end = null; + + if (hnd != null) + end = hnd.position(); + + return new RecordsIterator(cctx, walWorkDir, walArchiveDir, (FileWALPointer)start, end, dbCfg, serializer, + archiver, log, tlbSize); + } + + /** {@inheritDoc} */ + @Override public boolean reserve(WALPointer start) throws IgniteCheckedException { + assert start != null && start instanceof FileWALPointer : "Invalid start pointer: " + start; + + if (mode == Mode.NONE) + return false; + + FileArchiver archiver0 = archiver; + + if (archiver0 == null) + throw new IgniteCheckedException("Could not reserve WAL segment: archiver == null"); + + archiver0.reserve(((FileWALPointer)start).index()); + + if (!hasIndex(((FileWALPointer)start).index())) { + archiver0.release(((FileWALPointer)start).index()); + + return false; + } + + return true; + } + + /** {@inheritDoc} */ + @Override public void release(WALPointer start) throws IgniteCheckedException { + assert start != null && start instanceof FileWALPointer : "Invalid start pointer: " + start; + + if (mode == Mode.NONE) + return; + + FileArchiver archiver0 = archiver; + + if (archiver0 == null) + throw new IgniteCheckedException("Could not release WAL segment: archiver == null"); + + archiver0.release(((FileWALPointer)start).index()); + } + + private boolean hasIndex(int absIdx) { + String name = FileDescriptor.fileName(absIdx, serializer.version()); + + boolean inArchive = new File(walArchiveDir, name).exists(); + + if (inArchive) + return true; + + if (absIdx <= archiver.lastArchivedIndex()) + return false; + + FileWriteHandle cur = currentHnd; + + return cur != null && cur.idx >= absIdx; + } + + /** {@inheritDoc} */ + @Override public int truncate(WALPointer ptr) { + if (ptr == null) + return 0; + + assert ptr instanceof FileWALPointer : ptr; + + FileWALPointer fPtr = (FileWALPointer)ptr; + + FileDescriptor[] descs = scan(walArchiveDir.listFiles(WAL_SEGMENT_FILE_FILTER)); + + int deleted = 0; + + FileArchiver archiver0 = archiver; + + for (FileDescriptor desc : descs) { + // Do not delete reserved segment and any segment after it. + if (archiver0 != null && archiver0.reserved(desc.idx)) + return deleted; + + // We need to leave at least one archived segment to correctly determine the archive index. + if (desc.idx + 1 < fPtr.index()) { + if (!desc.file.delete()) + U.warn(log, "Failed to remove obsolete WAL segment (make sure the process has enough rights): " + + desc.file.getAbsolutePath()); + else + deleted++; + } + } + + return deleted; + } + + /** {@inheritDoc} */ + @Override public boolean reserved(WALPointer ptr) { + FileWALPointer fPtr = (FileWALPointer)ptr; + + FileArchiver archiver0 = archiver; + + return archiver0 != null && archiver0.reserved(fPtr.index()); + } + + /** + * Creates a directory specified by the given arguments. + * + * @param cfg Configured directory path, may be {@code null}. + * @param defDir Default directory path, will be used if cfg is {@code null}. + * @param consId Local node consistent ID. + * @param msg File description to print out on successful initialization. + * @return Initialized directory. + * @throws IgniteCheckedException + */ + private File initDirectory(String cfg, String defDir, String consId, String msg) throws IgniteCheckedException { + File dir; + + if (cfg != null) { + File workDir0 = new File(cfg); + + //TODO check path + dir = workDir0.isAbsolute() ? + new File(workDir0, consId) : + new File(U.resolveWorkDirectory(igCfg.getWorkDirectory(), cfg, false), consId); + } + else + dir = new File(U.resolveWorkDirectory(igCfg.getWorkDirectory(), defDir, false), consId); + + U.ensureDirectory(dir, msg, log); + + return dir; + } + + /** + * @return Current log segment handle. + */ + private FileWriteHandle currentHandle() { + return currentHnd; + } + + /** + * @param cur Handle that failed to fit the given entry. + * @return Handle that will fit the entry. + */ + private FileWriteHandle rollOver(FileWriteHandle cur) throws StorageException, IgniteCheckedException { + FileWriteHandle hnd = currentHandle(); + + if (hnd != cur) + return hnd; + + if (hnd.close(true)) { + FileWriteHandle next = initNextWriteHandle(cur.idx); + + boolean swapped = currentHndUpd.compareAndSet(this, hnd, next); + + assert swapped : "Concurrent updates on rollover are not allowed"; + + hnd.signalNextAvailable(); + } + else + hnd.awaitNext(); + + return currentHandle(); + } + + /** + * @param lastReadPtr Last read WAL file pointer. + * @return Initialized file write handle. + * @throws IgniteCheckedException If failed to initialize WAL write handle. + */ + private FileWriteHandle restoreWriteHandle(FileWALPointer lastReadPtr) throws IgniteCheckedException { + int absIdx = lastReadPtr == null ? 0 : lastReadPtr.index(); + + archiver.currentWalIndex(absIdx); + + int segNo = absIdx % dbCfg.getWalSegments(); + + File curFile = new File(walWorkDir, FileDescriptor.fileName(segNo, serializer.version())); + + int offset = lastReadPtr == null ? 0 : lastReadPtr.fileOffset(); + int len = lastReadPtr == null ? 0 : lastReadPtr.length(); + + log.info("Resuming logging in WAL segment [file=" + curFile.getAbsolutePath() + + ", offset=" + offset + ']'); + + try { + RandomAccessFile file = new RandomAccessFile(curFile, "rw"); + + try { + FileWriteHandle hnd = new FileWriteHandle( + file, + absIdx, + cctx.igniteInstanceName(), + offset + len, + maxWalSegmentSize, + serializer); + + if (lastReadPtr == null) { + HeaderRecord header = new HeaderRecord(serializer.version()); + + header.size(serializer.size(header)); + + hnd.addRecord(header); + } + + return hnd; + } + catch (IgniteCheckedException | IOException e) { + file.close(); + + throw e; + } + } + catch (IOException e) { + throw new IgniteCheckedException("Failed to restore WAL write handle: " + curFile.getAbsolutePath(), e); + } + } + + /** + * Fills the file header for a new segment. + * + * @return Initialized file handle. + * @throws StorageException If IO exception occurred. + * @throws IgniteCheckedException If failed. + */ + private FileWriteHandle initNextWriteHandle(int curIdx) throws StorageException, IgniteCheckedException { + try { + File nextFile = pollNextFile(curIdx); + + if (log.isDebugEnabled()) + log.debug("Switching to a new WAL segment: " + nextFile.getAbsolutePath()); + + RandomAccessFile file = new RandomAccessFile(nextFile, "rw"); + + FileWriteHandle hnd = new FileWriteHandle( + file, + curIdx + 1, + cctx.igniteInstanceName(), + 0, + maxWalSegmentSize, + serializer); + + HeaderRecord header = new HeaderRecord(serializer.version()); + + header.size(serializer.size(header)); + + hnd.addRecord(header); + + return hnd; + } + catch (IOException e) { + throw new StorageException(e); + } + } + + /** + * + */ + private void checkOrPrepareFiles() throws IgniteCheckedException { + // Clean temp files. + { + File[] tmpFiles = walWorkDir.listFiles(WAL_SEGMENT_TEMP_FILE_FILTER); + + if (!F.isEmpty(tmpFiles)) { + for (File tmp : tmpFiles) { + boolean deleted = tmp.delete(); + + if (!deleted) + throw new IgniteCheckedException("Failed to delete previously created temp file " + + "(make sure Ignite process has enough rights): " + tmp.getAbsolutePath()); + } + } + } + + File[] allFiles = walWorkDir.listFiles(WAL_SEGMENT_FILE_FILTER); + + if (allFiles.length != 0 && allFiles.length > dbCfg.getWalSegments()) + throw new IgniteCheckedException("Failed to initialize wal (work directory contains " + + "incorrect number of segments) [cur=" + allFiles.length + ", expected=" + dbCfg.getWalSegments() + ']'); + + // Allocate the first segment synchronously. All other segments will be allocated by archiver in background. + if (allFiles.length == 0) { + File first = new File(walWorkDir, FileDescriptor.fileName(0, serializer.version())); + + createFile(first); + } + else + checkFiles(0, false, null); + } + + /** + * Clears the file with zeros. + * + * @param file File to format. + */ + private void formatFile(File file) throws IgniteCheckedException { + if (log.isDebugEnabled()) + log.debug("Formatting file [exists=" + file.exists() + ", file=" + file.getAbsolutePath() + ']'); + + try (RandomAccessFile rnd = new RandomAccessFile(file, "rw")) { + int left = dbCfg.getWalSegmentSize(); + + if (mode == Mode.DEFAULT) { + while (left > 0) { + int toWrite = Math.min(FILL_BUF.length, left); + + rnd.write(FILL_BUF, 0, toWrite); + + left -= toWrite; + } + + rnd.getChannel().force(false); + } + else { + rnd.setLength(0); + } + } + catch (IOException e) { + throw new IgniteCheckedException("Failed to format WAL segment file: " + file.getAbsolutePath(), e); + } + } + + /** + * Creates a file atomically with temp file. + * + * @param file File to create. + * @throws IgniteCheckedException If failed. + */ + private void createFile(File file) throws IgniteCheckedException { + if (log.isDebugEnabled()) + log.debug("Creating new file [exists=" + file.exists() + ", file=" + file.getAbsolutePath() + ']'); + + File tmp = new File(file.getParent(), file.getName() + ".tmp"); + + formatFile(tmp); + + try { + Files.move(tmp.toPath(), file.toPath()); + } + catch (IOException e) { + throw new IgniteCheckedException("Failed to move temp file to a regular WAL segment file: " + + file.getAbsolutePath(), e); + } + + if (log.isDebugEnabled()) + log.debug("Created WAL segment [file=" + file.getAbsolutePath() + ", size=" + file.length() + ']'); + } + + /** + * @param curIdx Current absolute WAL segment index. + * @return File. + * @throws IgniteCheckedException If failed. + */ + private File pollNextFile(int curIdx) throws IgniteCheckedException { + // Signal to archiver that we are done with the segment and it can be archived. + int absNextIdx = archiver.nextAbsoluteSegmentIndex(curIdx); + + int segmentIdx = absNextIdx % dbCfg.getWalSegments(); + + return new File(walWorkDir, FileDescriptor.fileName(segmentIdx, serializer.version())); + } + + /** + * @param ver Serializer version. + * @return Entry serializer. + */ + private static RecordSerializer forVersion(GridCacheSharedContext cctx, int ver) throws IgniteCheckedException { + if (ver <= 0) + throw new IgniteCheckedException("Failed to create a serializer (corrupted WAL file)."); + + switch (ver) { + case 1: + return new RecordV1Serializer(cctx); + + default: + throw new IgniteCheckedException("Failed to create a serializer with the given version " + + "(forward compatibility is not supported): " + ver); + } + } + + /** + * @return Sorted WAL files descriptors. + */ + private static FileDescriptor[] scan(File[] allFiles) { + if (allFiles == null) + return new FileDescriptor[0]; + + FileDescriptor[] descs = new FileDescriptor[allFiles.length]; + + for (int i = 0; i < allFiles.length; i++) { + File f = allFiles[i]; + + descs[i] = new FileDescriptor(f); + } + + Arrays.sort(descs); + + return descs; + } + + /** + * File archiver operates on absolute segment indexes. For any given absolute segment index N we can calculate + * the work WAL segment: S(N) = N % dbCfg.walSegments. + * When a work segment is finished, it is given to the archiver. If the absolute index of last archived segment + * is denoted by A and the absolute index of next segment we want to write is denoted by W, then we can allow + * write to S(W) if W - A <= walSegments. + */ + private class FileArchiver extends Thread { + /** */ + private IgniteCheckedException cleanException; + + /** Absolute current segment index. */ + private int curAbsWalIdx = -1; + + /** */ + private int lastAbsArchivedIdx = -1; + + /** */ + private volatile boolean stopped; + + /** */ + private NavigableMap reserved = new TreeMap<>(); + + /** */ + private Map locked = new HashMap<>(); + + /** + * + */ + private FileArchiver() { + super("wal-file-archiver%" + cctx.igniteInstanceName()); + + lastAbsArchivedIdx = lastArchivedIndex(); + } + + /** + * @throws IgniteInterruptedCheckedException If failed to wait for thread shutdown. + */ + private void shutdown() throws IgniteInterruptedCheckedException { + synchronized (this) { + stopped = true; + + notifyAll(); + } + + U.join(this); + } + + /** + * @param curAbsWalIdx Current absolute WAL segment index. + */ + private void currentWalIndex(int curAbsWalIdx) { + synchronized (this) { + this.curAbsWalIdx = curAbsWalIdx; + + notifyAll(); + } + } + + /** + * @param absIdx Index for reservation. + */ + private synchronized void reserve(int absIdx) { + Integer cur = reserved.get(absIdx); + + if (cur == null) + reserved.put(absIdx, 1); + else + reserved.put(absIdx, cur + 1); + } + + /** + * @param absIdx Index for reservation. + * @return {@code True} if index is reserved. + */ + private synchronized boolean reserved(int absIdx) { + return locked.containsKey(absIdx) || reserved.floorKey(absIdx) != null; + } + + /** + * @param absIdx Reserved index. + */ + private synchronized void release(int absIdx) { + Integer cur = reserved.get(absIdx); + + assert cur != null && cur >= 1 : cur; + + if (cur == 1) + reserved.remove(absIdx); + else + reserved.put(absIdx, cur - 1); + } + + /** {@inheritDoc} */ + @Override public void run() { + try { + allocateRemainingFiles(); + } + catch (IgniteCheckedException e) { + synchronized (this) { + // Stop the thread and report to starter. + cleanException = e; + + notifyAll(); + + return; + } + } + + try { + synchronized (this) { + while (curAbsWalIdx == -1 && !stopped) + wait(); + + if (curAbsWalIdx != 0 && lastAbsArchivedIdx == -1) + lastAbsArchivedIdx = curAbsWalIdx - 1; + } + + while (!Thread.currentThread().isInterrupted() && !stopped) { + int toArchive; + + synchronized (this) { + assert lastAbsArchivedIdx <= curAbsWalIdx : "lastArchived=" + lastAbsArchivedIdx + + ", current=" + curAbsWalIdx; + + while (lastAbsArchivedIdx >= curAbsWalIdx - 1 && !stopped) + wait(); + + toArchive = lastAbsArchivedIdx + 1; + } + + if (stopped) + break; + + try { + File workFile = archiveSegment(toArchive); + + synchronized (this) { + while (locked.containsKey(toArchive) && !stopped) + wait(); + + // Firstly, format working file + if (!stopped) + formatFile(workFile); + + // Then increase counter to allow rollover on clean working file + lastAbsArchivedIdx = toArchive; + + notifyAll(); + } + } + catch (IgniteCheckedException e) { + synchronized (this) { + cleanException = e; + + notifyAll(); + } + } + } + } + catch (InterruptedException ignore) { + Thread.currentThread().interrupt(); + } + } + + /** + * Gets the absolute index of the next WAL segment available to write. + * + * @param curIdx Current index that we want to increment. + * @return Next index (curIdx+1) when it is ready to be written. + * @throws IgniteCheckedException If failed. + */ + private int nextAbsoluteSegmentIndex(int curIdx) throws IgniteCheckedException { + try { + synchronized (this) { + if (cleanException != null) + throw cleanException; + + assert curIdx == curAbsWalIdx; + + curAbsWalIdx++; + + // Notify archiver thread. + notifyAll(); + + while (curAbsWalIdx - lastAbsArchivedIdx > dbCfg.getWalSegments() && cleanException == null) + wait(); + + return curAbsWalIdx; + } + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + + throw new IgniteInterruptedCheckedException(e); + } + } + + /** + * @param absIdx Segment absolute index. + * @return {@code True} if can read, {@code false} if work segment + */ + @SuppressWarnings("NonPrivateFieldAccessedInSynchronizedContext") + private boolean checkCanReadArchiveOrReserveWorkSegment(int absIdx) { + synchronized (this) { + if (lastAbsArchivedIdx >= absIdx) + return true; + + Integer cur = locked.get(absIdx); + + cur = cur == null ? 1 : cur + 1; + + locked.put(absIdx, cur); + + if (log.isDebugEnabled()) + log.debug("Reserved work segment [absIdx=" + absIdx + ", pins=" + cur + ']'); + + return false; + } + } + + /** + * @param absIdx Segment absolute index. + */ + @SuppressWarnings("NonPrivateFieldAccessedInSynchronizedContext") + private void releaseWorkSegment(int absIdx) { + synchronized (this) { + Integer cur = locked.get(absIdx); + + assert cur != null && cur > 0; + + if (cur == 1) { + locked.remove(absIdx); + + if (log.isDebugEnabled()) + log.debug("Fully released work segment (ready to archive) [absIdx=" + absIdx + ']'); + } + else { + locked.put(absIdx, cur - 1); + + if (log.isDebugEnabled()) + log.debug("Partially released work segment [absIdx=" + absIdx + ", pins=" + (cur - 1) + ']'); + } + + notifyAll(); + } + } + + /** + * @param absIdx Absolute index to archive. + */ + private File archiveSegment(int absIdx) throws IgniteCheckedException { + int segIdx = absIdx % dbCfg.getWalSegments(); + + File origFile = new File(walWorkDir, FileDescriptor.fileName(segIdx, serializer.version())); + + String name = FileDescriptor.fileName(absIdx, serializer.version()); + + File dstTmpFile = new File(walArchiveDir, name + ".tmp"); + + File dstFile = new File(walArchiveDir, name); + + if (log.isDebugEnabled()) + log.debug("Starting to copy WAL segment [absIdx=" + absIdx + ", segIdx=" + segIdx + + ", origFile=" + origFile.getAbsolutePath() + ", dstFile=" + dstFile.getAbsolutePath() + ']'); + + try { + Files.deleteIfExists(dstTmpFile.toPath()); + + Files.copy(origFile.toPath(), dstTmpFile.toPath()); + + Files.move(dstTmpFile.toPath(), dstFile.toPath()); + + if (mode == Mode.DEFAULT) { + try (RandomAccessFile f0 = new RandomAccessFile(dstFile, "rw")) { + f0.getChannel().force(false); + } + } + } + catch (IOException e) { + throw new IgniteCheckedException("Failed to archive WAL segment [" + + "srcFile=" + origFile.getAbsolutePath() + + ", dstFile=" + dstTmpFile.getAbsolutePath() + ']', e); + } + + if (log.isDebugEnabled()) + log.debug("Copied file [src=" + origFile.getAbsolutePath() + + ", dst=" + dstFile.getAbsolutePath() + ']'); + + return origFile; + } + + /** + * Lists files in archive directory and returns the index of last archived file. + * + * @return The absolute index of last archived file. + */ + private int lastArchivedIndex() { + int lastIdx = -1; + + for (File file : walArchiveDir.listFiles(WAL_SEGMENT_FILE_FILTER)) { + try { + int idx = Integer.parseInt(file.getName().substring(0, 16)); + + lastIdx = Math.max(lastIdx, idx); + } + catch (NumberFormatException | IndexOutOfBoundsException ignore) { + + } + } + + return lastIdx; + } + + /** + * + */ + private boolean checkStop() { + return stopped; + } + + /** + * + */ + private void allocateRemainingFiles() throws IgniteCheckedException { + checkFiles(1, true, new IgnitePredicate() { + @Override public boolean apply(Integer integer) { + return !checkStop(); + } + }); + } + } + + /** + * Validate files depending on {@link PersistenceConfiguration#getWalSegments()} and create if need. + * Check end when exit condition return false or all files are passed. + * + * @param startWith Start with. + * @param create Flag create file. + * @param p Predicate Exit condition. + * @throws IgniteCheckedException if validation or create file fail. + */ + private void checkFiles(int startWith, boolean create, IgnitePredicate p) throws IgniteCheckedException { + for (int i = startWith; i < dbCfg.getWalSegments() && (p == null || (p != null && p.apply(i))); i++) { + File checkFile = new File(walWorkDir, FileDescriptor.fileName(i, serializer.version())); + + if (checkFile.exists()) { + if (checkFile.isDirectory()) + throw new IgniteCheckedException("Failed to initialize WAL log segment (a directory with " + + "the same name already exists): " + checkFile.getAbsolutePath()); + else if (checkFile.length() != dbCfg.getWalSegmentSize() && mode == Mode.DEFAULT) + throw new IgniteCheckedException("Failed to initialize WAL log segment " + + "(WAL segment size change is not supported):" + checkFile.getAbsolutePath()); + } + else if (create) + createFile(checkFile); + } + } + + /** + * WAL file descriptor. + */ + private static class FileDescriptor implements Comparable { + /** */ + protected final File file; + + /** */ + protected final int idx; + + /** */ + protected final int ver; + + /** + * @param file File. + */ + private FileDescriptor(File file) { + this(file, null); + } + + /** + * @param file File. + * @param idx index + */ + private FileDescriptor(File file, Integer idx) { + this.file = file; + + String fileName = file.getName(); + + assert fileName.endsWith(WAL_SEGMENT_FILE_EXT); + + int v = fileName.lastIndexOf(".v"); + + assert v > 0; + + int begin = v + 2; + int end = fileName.length() - WAL_SEGMENT_FILE_EXT.length(); + + if (idx == null) + this.idx = Integer.parseInt(fileName.substring(0, v)); + else + this.idx = idx; + + ver = Integer.parseInt(fileName.substring(begin, end)); + } + + /** + * @param segment Segment index. + * @param ver Serializer version. + * @return Segment file name. + */ + private static String fileName(long segment, int ver) { + SB b = new SB(); + + String segmentStr = Long.toString(segment); + + for (int i = segmentStr.length(); i < 16; i++) + b.a('0'); + + b.a(segmentStr).a(".v").a(ver).a(WAL_SEGMENT_FILE_EXT); + + return b.toString(); + } + + /** + * @param segment Segment number as integer. + * @return Segment number as aligned string. + */ + private static String segmentNumber(long segment) { + SB b = new SB(); + + String segmentStr = Long.toString(segment); + + for (int i = segmentStr.length(); i < 16; i++) + b.a('0'); + + b.a(segmentStr); + + return b.toString(); + } + + /** {@inheritDoc} */ + @Override public int compareTo(FileDescriptor o) { + return Long.compare(idx, o.idx); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (!(o instanceof FileDescriptor)) + return false; + + FileDescriptor that = (FileDescriptor)o; + + return idx == that.idx; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return idx; + } + } + + /** + * + */ + private abstract static class FileHandle { + /** */ + protected RandomAccessFile file; + + /** */ + protected FileChannel ch; + + /** */ + protected final int idx; + + /** */ + protected String gridName; + + /** + * @param file File. + * @param idx Index. + */ + private FileHandle(RandomAccessFile file, int idx, String gridName) { + this.file = file; + this.idx = idx; + this.gridName = gridName; + + ch = file.getChannel(); + + assert ch != null; + } + } + + private static class ReadFileHandle extends FileHandle { + /** Entry serializer. */ + private RecordSerializer ser; + + /** */ + private FileInput in; + + /** */ + private boolean workDir; + + /** + * @param file File to read. + * @param idx File index. + * @param ser Entry serializer. + * @param in File input. + */ + private ReadFileHandle( + RandomAccessFile file, + int idx, + String gridName, + RecordSerializer ser, + FileInput in + ) { + super(file, idx, gridName); + + this.ser = ser; + this.in = in; + } + + /** + * @throws IgniteCheckedException If failed to close the WAL segment file. + */ + public void close() throws IgniteCheckedException { + try { + file.close(); + } + catch (IOException e) { + throw new IgniteCheckedException(e); + } + } + } + + /** + * File handle for one log segment. + */ + @SuppressWarnings("SignalWithoutCorrespondingAwait") + private class FileWriteHandle extends FileHandle { + /** */ + private final RecordSerializer serializer; + + /** */ + private final long maxSegmentSize; + + /** */ + private final AtomicReference head = new AtomicReference<>(); + + /** */ + private volatile long written; + + /** */ + private volatile long lastFsyncPos; + + /** Environment failure. */ + private volatile Throwable envFailed; + + /** */ + private final AtomicBoolean stop = new AtomicBoolean(false); + + /** */ + private final Lock lock = new ReentrantLock(); + + /** */ + private final Condition writeComplete = lock.newCondition(); + + /** */ + private final Condition fsync = lock.newCondition(); + + /** */ + private final Condition nextSegment = lock.newCondition(); + + /** + * @param file Mapped file to use. + * @param idx Index for easy access. + * @param pos Position. + * @param maxSegmentSize Max segment size. + * @param serializer Serializer. + * @throws IOException If failed. + */ + private FileWriteHandle( + RandomAccessFile file, + int idx, + String gridName, + long pos, + long maxSegmentSize, + RecordSerializer serializer + ) throws IOException { + super(file, idx, gridName); + + assert serializer != null; + + ch.position(pos); + + this.maxSegmentSize = maxSegmentSize; + this.serializer = serializer; + + head.set(new FakeRecord(pos)); + written = pos; + lastFsyncPos = pos; + } + + /** + * @param rec Record. + * @return Pointer. + * @throws StorageException If failed. + * @throws IgniteCheckedException If failed. + */ + private WALPointer addRecord(WALRecord rec) throws StorageException, IgniteCheckedException { + assert rec.size() > 0 || rec.getClass() == FakeRecord.class; + + boolean flushed = false; + + for (; ; ) { + WALRecord h = head.get(); + + long nextPos = nextPosition(h); + + // It is important that we read `stop` after `head` in this loop for correct close, + // because otherwise we will have a race on the last flush in close. + if (nextPos + rec.size() >= maxSegmentSize || stop.get()) { + // Can not write to this segment, need to switch to the next one. + return null; + } + + int newChainSize = h.chainSize() + rec.size(); + + if (newChainSize > tlbSize && !flushed) { + boolean res = h.previous() == null || flush(h); + + if (rec.size() > tlbSize) + flushed = res; + + continue; + } + + rec.chainSize(newChainSize); + rec.previous(h); + rec.position(nextPos); + + if (head.compareAndSet(h, rec)) + return new FileWALPointer(idx, (int)rec.position(), rec.size()); + } + } + + /** + * @param rec Record. + * @return Position for the next record. + */ + private long nextPosition(WALRecord rec) { + return rec.position() + rec.size(); + } + + /** + * Flush or wait for concurrent flush completion. + * + * @param ptr Pointer. + * @throws IgniteCheckedException If failed. + */ + private void flushOrWait(FileWALPointer ptr) throws IgniteCheckedException { + long expWritten; + + if (ptr != null) { + // If requested obsolete file index, it must be already flushed by close. + if (ptr.index() != idx) + return; + + expWritten = ptr.fileOffset(); + } + else // We read head position before the flush because otherwise we can get wrong position. + expWritten = head.get().position(); + + if (flush(ptr)) + return; + + // Spin-wait for a while before acquiring the lock. + for (int i = 0; i < 64; i++) { + if (written >= expWritten) + return; + } + + // If we did not flush ourselves then await for concurrent flush to complete. + lock.lock(); + + try { + while (written < expWritten && envFailed == null) + U.await(writeComplete); + } + finally { + lock.unlock(); + } + } + + /** + * @param ptr Pointer. + * @return {@code true} If the flush really happened. + * @throws IgniteCheckedException If failed. + * @throws StorageException If failed. + */ + private boolean flush(FileWALPointer ptr) throws IgniteCheckedException, StorageException { + if (ptr == null) { // Unconditional flush. + for (; ; ) { + WALRecord expHead = head.get(); + + if (expHead.previous() == null) { + assert expHead instanceof FakeRecord; + + return false; + } + + if (flush(expHead)) + return true; + } + } + + assert ptr.index() == idx; + + for (; ; ) { + WALRecord h = head.get(); + + // If current chain begin position is greater than requested, then someone else flushed our changes. + if (chainBeginPosition(h) > ptr.fileOffset()) + return false; + + if (flush(h)) + return true; // We are lucky. + } + } + + /** + * @param h Head of the chain. + * @return Chain begin position. + */ + private long chainBeginPosition(WALRecord h) { + return h.position() + h.size() - h.chainSize(); + } + + /** + * @param expHead Expected head of chain. + * @throws IgniteCheckedException If failed. + * @throws StorageException If failed. + */ + private boolean flush(WALRecord expHead) throws StorageException, IgniteCheckedException { + if (expHead.previous() == null) { + assert expHead instanceof FakeRecord; + + return false; + } + + // Fail-fast before CAS. + checkEnvironment(); + + if (!head.compareAndSet(expHead, new FakeRecord(nextPosition(expHead)))) + return false; + + // At this point we grabbed the piece of WAL chain. + // Any failure in this code must invalidate the environment. + try { + // We can safely allow other threads to start building next chains while we are doing flush here. + ByteBuffer buf; + + boolean tmpBuf = false; + + if (expHead.chainSize() > tlbSize) { + buf = GridUnsafe.allocateBuffer(expHead.chainSize()); + + tmpBuf = true; // We need to manually release this temporary direct buffer. + } + else + buf = tlb.get(); + + try { + long pos = fillBuffer(buf, expHead); + + writeBuffer(pos, buf); + } + finally { + if (tmpBuf) + GridUnsafe.freeBuffer(buf); + } + + return true; + } + catch (Throwable e) { + invalidateEnvironment(e); + + throw e; + } + } + + /** + * @param buf Buffer. + * @param head Head of the chain to write to the buffer. + * @return Position in file for this buffer. + * @throws IgniteCheckedException If failed. + */ + private long fillBuffer(ByteBuffer buf, WALRecord head) throws IgniteCheckedException { + final int limit = head.chainSize(); + + assert limit <= buf.capacity(); + + buf.rewind(); + buf.limit(limit); + + do { + buf.position(head.chainSize() - head.size()); + buf.limit(head.chainSize()); // Just to make sure that serializer works in bounds. + + try { + serializer.writeRecord(head, buf); + } + catch (RuntimeException e) { + throw new IllegalStateException("Failed to write record: " + head, e); + } + + assert !buf.hasRemaining() : "Reported record size is greater than actual: " + head; + + head = head.previous(); + } + while (head.previous() != null); + + assert head instanceof FakeRecord : head.getClass(); + + buf.rewind(); + buf.limit(limit); + + return head.position(); + } + + /** + * Non-blocking check if this pointer needs to be sync'ed. + * + * @param ptr WAL pointer to check. + * @return {@code False} if this pointer has been already sync'ed. + */ + private boolean needFsync(FileWALPointer ptr) { + // If index has changed, it means that the log was rolled over and already sync'ed. + // If requested position is smaller than last sync'ed, it also means all is good. + // If position is equal, then our record is the last not synced. + return idx == ptr.index() && lastFsyncPos <= ptr.fileOffset(); + } + + /** + * @return Pointer to the end of the last written record (probably not fsync-ed). + */ + private FileWALPointer position() { + lock.lock(); + + try { + return new FileWALPointer(idx, (int)written, 0); + } + finally { + lock.unlock(); + } + } + + /** + * @param ptr Pointer to sync. + * @throws StorageException If failed. + */ + private void fsync(FileWALPointer ptr) throws StorageException, IgniteCheckedException { + lock.lock(); + + try { + if (ptr != null) { + if (!needFsync(ptr)) + return; + + if (fsyncDelayNanos > 0 && !stop.get()) { + // Delay fsync to collect as many updates as possible: trade latency for throughput. + U.await(fsync, fsyncDelayNanos, TimeUnit.NANOSECONDS); + + if (!needFsync(ptr)) + return; + } + } + + flushOrWait(ptr); + + if (lastFsyncPos != written) { + assert lastFsyncPos < written; // Fsync position must be behind. + + try { + ch.force(false); + } + catch (IOException e) { + throw new StorageException(e); + } + + lastFsyncPos = written; + + if (fsyncDelayNanos > 0) + fsync.signalAll(); + } + } + finally { + lock.unlock(); + } + } + + /** + * @return {@code true} If this thread actually closed the segment. + * @throws IgniteCheckedException If failed. + * @throws StorageException If failed. + */ + private boolean close(boolean rollOver) throws IgniteCheckedException, StorageException { + if (stop.compareAndSet(false, true)) { + // Here we can be sure that no other records will be added and this fsync will be the last. + if (mode == Mode.DEFAULT) + fsync(null); + else + flushOrWait(null); + + try { + if (rollOver && written < (maxSegmentSize - 1)) { + ByteBuffer allocate = ByteBuffer.allocate(1); + allocate.put((byte) WALRecord.RecordType.SWITCH_SEGMENT_RECORD.ordinal()); + + ch.write(allocate, written); + + if (mode == Mode.DEFAULT) + ch.force(false); + } + + ch.close(); + } + catch (IOException e) { + throw new IgniteCheckedException(e); + } + + if (log.isDebugEnabled()) + log.debug("Closed WAL write handle [idx=" + idx + "]"); + + return true; + } + + return false; + } + + /** + * + */ + private void signalNextAvailable() { + lock.lock(); + + try { + assert head.get() instanceof FakeRecord: "head"; + assert written == lastFsyncPos || mode != Mode.DEFAULT : + "fsync [written=" + written + ", lastFsync=" + lastFsyncPos + ']'; + + ch = null; + + nextSegment.signalAll(); + } + finally { + lock.unlock(); + } + } + + /** + * @throws IgniteCheckedException If failed. + */ + private void awaitNext() throws IgniteCheckedException { + lock.lock(); + + try { + while (ch != null) + U.await(nextSegment); + } + finally { + lock.unlock(); + } + } + + /** + * @param pos Position in file. + * @param buf Buffer. + * @throws StorageException If failed. + * @throws IgniteCheckedException If failed. + */ + @SuppressWarnings("TooBroadScope") + private void writeBuffer(long pos, ByteBuffer buf) throws StorageException, IgniteCheckedException { + boolean interrupted = false; + + lock.lock(); + + try { + assert ch != null : "Writing to a closed segment."; + + checkEnvironment(); + + long lastLogged = U.currentTimeMillis(); + + long logBackoff = 2_000; + + // If we were too fast, need to wait previous writes to complete. + while (written != pos) { + assert written < pos : "written = " + written + ", pos = " + pos; // No one can write further than we are now. + + long now = U.currentTimeMillis(); + + if (now - lastLogged >= logBackoff) { + if (logBackoff < 60 * 60_000) + logBackoff *= 2; + + U.warn(log, "Still waiting for a concurrent write to complete [written=" + written + + ", pos=" + pos + ", lastFsyncPos=" + lastFsyncPos + ", stop=" + stop.get() + + ", actualPos=" + safePosition() + ']'); + + lastLogged = now; + } + + try { + writeComplete.await(2, TimeUnit.SECONDS); + } + catch (InterruptedException ignore) { + interrupted = true; + } + + checkEnvironment(); + } + + // Do the write. + int size = buf.remaining(); + + assert size > 0 : size; + + try { + assert written == ch.position(); + + do { + ch.write(buf); + } + while (buf.hasRemaining()); + + written += size; + + assert written == ch.position(); + } + catch (IOException e) { + invalidateEnvironmentLocked(e); + + throw new StorageException(e); + } + } + finally { + writeComplete.signalAll(); + + lock.unlock(); + + if (interrupted) + Thread.currentThread().interrupt(); + } + } + + /** + * @param e Exception to set as a cause for all further operations. + */ + private void invalidateEnvironment(Throwable e) { + lock.lock(); + + try { + invalidateEnvironmentLocked(e); + } + finally { + writeComplete.signalAll(); + + lock.unlock(); + } + } + + /** + * @param e Exception to set as a cause for all further operations. + */ + private void invalidateEnvironmentLocked(Throwable e) { + if (envFailed == null) { + envFailed = e; + + U.error(log, "IO error encountered while running WAL flush. All further operations will be failed and " + + "local node will be stopped.", e); + + new Thread() { + @Override public void run() { + G.stop(gridName, true); + } + }.start(); + } + } + + /** + * @throws StorageException If environment is no longer valid and we missed a WAL write. + */ + private void checkEnvironment() throws StorageException { + if (envFailed != null) + throw new StorageException("Failed to flush WAL buffer (environment was invalidated by a " + + "previous error)", envFailed); + } + + /** + * @return Safely reads current position of the file channel as String. Will return "null" if channel is null. + */ + private String safePosition() { + FileChannel ch = this.ch; + + if (ch == null) + return "null"; + + try { + return String.valueOf(ch.position()); + } + catch (IOException e) { + return "{Failed to read channel position: " + e.getMessage() + "}"; + } + } + } + + /** + * Fake record. + */ + private static final class FakeRecord extends WALRecord { + /** + * @param pos Position. + */ + FakeRecord(long pos) { + position(pos); + } + + /** {@inheritDoc} */ + @Override public RecordType type() { + return null; + } + } + + /** + * Iterator over WAL-log. + */ + public static class RecordsIterator extends GridCloseableIteratorAdapter> + implements WALIterator { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final File walWorkDir; + + /** */ + private final File walArchiveDir; + + /** */ + private final FileArchiver archiver; + + /** */ + private final PersistenceConfiguration dbCfg; + + /** */ + private final RecordSerializer serializer; + + /** */ + private final GridCacheSharedContext cctx; + + /** */ + private FileWALPointer start; + + /** */ + private FileWALPointer end; + + /** */ + private IgniteBiTuple curRec; + + /** */ + private int curIdx = -1; + + /** */ + private ReadFileHandle curHandle; + + /** */ + private ByteBuffer buf; + + /** */ + private IgniteLogger log; + + /** + * @param cctx Shared context. + * @param walWorkDir WAL work dir. + * @param walArchiveDir WAL archive dir. + * @param start Optional start pointer. + * @param end Optional end pointer. + * @param dbCfg Database configuration. + * @param serializer Serializer. + * @param archiver Archiver. + * @throws IgniteCheckedException If failed to initialize WAL segment. + */ + public RecordsIterator( + GridCacheSharedContext cctx, + File walWorkDir, + File walArchiveDir, + FileWALPointer start, + FileWALPointer end, + PersistenceConfiguration dbCfg, + RecordSerializer serializer, + FileArchiver archiver, + IgniteLogger log, + int tlbSize + ) throws IgniteCheckedException { + this.cctx = cctx; + this.walWorkDir = walWorkDir; + this.walArchiveDir = walArchiveDir; + this.dbCfg = dbCfg; + this.serializer = serializer; + this.archiver = archiver; + this.start = start; + this.end = end; + this.log = log; + + // Do not allocate direct buffer for iterator. + buf = ByteBuffer.allocate(16 * tlbSize); + buf.order(ByteOrder.nativeOrder()); + + init(); + + advance(); + } + + /** {@inheritDoc} */ + @Override protected IgniteBiTuple onNext() throws IgniteCheckedException { + IgniteBiTuple ret = curRec; + + advance(); + + return ret; + } + + /** {@inheritDoc} */ + @Override protected boolean onHasNext() throws IgniteCheckedException { + return curRec != null; + } + + /** {@inheritDoc} */ + @Override protected void onClose() throws IgniteCheckedException { + curRec = null; + + if (curHandle != null) { + curHandle.close(); + + if (curHandle.workDir) + releaseWorkSegment(curIdx); + + curHandle = null; + } + + curIdx = Integer.MAX_VALUE; + } + + /** + * @throws IgniteCheckedException If failed to initialize first file handle. + */ + private void init() throws IgniteCheckedException { + FileDescriptor[] descs = scan(walArchiveDir.listFiles(WAL_SEGMENT_FILE_FILTER)); + + if (start != null) { + if (!F.isEmpty(descs)) { + if (descs[0].idx > start.index()) + throw new IgniteCheckedException("WAL history is too short " + + "[descs=" + Arrays.asList(descs) + ", start=" + start + ']'); + + for (FileDescriptor desc : descs) { + if (desc.idx == start.index()) { + curIdx = start.index(); + + break; + } + } + + if (curIdx == -1) { + int lastArchived = descs[descs.length - 1].idx; + + if (lastArchived > start.index()) + throw new IgniteCheckedException("WAL history is corrupted (segment is missing): " + start); + + // This pointer may be in work files because archiver did not + // copy the file yet, check that it is not too far forward. + curIdx = start.index(); + } + } + else { + // This means that whole checkpoint history fits in one segment in WAL work directory. + // Will start from this index right away. + curIdx = start.index(); + } + } + else + curIdx = !F.isEmpty(descs) ? descs[0].idx : 0; + + curIdx--; + + if (log.isDebugEnabled()) + log.debug("Initialized WAL cursor [start=" + start + ", end=" + end + ", curIdx=" + curIdx + ']'); + } + + /** + * @throws IgniteCheckedException If failed. + */ + private void advance() throws IgniteCheckedException { + while (true) { + advanceRecord(); + + if (curRec != null) + return; + else { + advanceSegment(); + + if (curHandle == null) + return; + } + } + } + + /** + * @throws IgniteCheckedException If failed. + */ + private void advanceRecord() throws IgniteCheckedException { + try { + ReadFileHandle hnd = curHandle; + + if (hnd != null) { + RecordSerializer ser = hnd.ser; + + int pos = (int)hnd.in.position(); + + WALRecord rec = ser.readRecord(hnd.in); + + WALPointer ptr = new FileWALPointer(hnd.idx, pos, rec.size()); + + curRec = new IgniteBiTuple<>(ptr, rec); + } + } + catch (IOException | IgniteCheckedException e) { + // TODO: verify that wrapped IntegrityException is acceptable in this case. + curRec = null; + } + } + + /** + * @throws IgniteCheckedException If failed. + */ + private void advanceSegment() throws IgniteCheckedException { + ReadFileHandle cur0 = curHandle; + + if (cur0 != null) { + cur0.close(); + + if (cur0.workDir) + releaseWorkSegment(cur0.idx); + + curHandle = null; + } + + // We are past the end marker. + if (end != null && curIdx + 1 > end.index()) + return; + + curIdx++; + + FileDescriptor fd; + + boolean readArchive = canReadArchiveOrReserveWork(curIdx); + + if (readArchive) { + fd = new FileDescriptor(new File(walArchiveDir, + FileDescriptor.fileName(curIdx, serializer.version()))); + } + else { + int workIdx = curIdx % dbCfg.getWalSegments(); + + fd = new FileDescriptor( + new File(walWorkDir, FileDescriptor.fileName(workIdx, serializer.version())), + curIdx); + } + + if (log.isDebugEnabled()) + log.debug("Reading next file [absIdx=" + curIdx + ", file=" + fd.file.getAbsolutePath() + ']'); + + assert fd != null; + + try { + curHandle = initReadHandle(fd, start != null && curIdx == start.index() ? start : null); + } + catch (FileNotFoundException e) { + if (readArchive) + throw new IgniteCheckedException("Missing WAL segment in the archive", e); + else + curHandle = null; + } + + if (curHandle != null) + curHandle.workDir = !readArchive; + else + releaseWorkSegment(curIdx); + + curRec = null; + } + + /** + * @param desc File descriptor. + * @param start Optional start pointer. + * @return Initialized file handle. + * @throws FileNotFoundException If segment file is missing. + * @throws IgniteCheckedException If initialized failed due to another unexpected error. + */ + private ReadFileHandle initReadHandle(FileDescriptor desc, FileWALPointer start) + throws IgniteCheckedException, FileNotFoundException { + try { + RandomAccessFile rf = new RandomAccessFile(desc.file, "r"); + + try { + RecordSerializer ser = forVersion(cctx, desc.ver); + FileInput in = new FileInput(rf.getChannel(), buf); + + WALRecord rec = ser.readRecord(in); + + if (rec == null) + return null; + + if (rec.type() != WALRecord.RecordType.HEADER_RECORD) + throw new IOException("Missing file header record: " + desc.file.getAbsoluteFile()); + + int ver = ((HeaderRecord)rec).version(); + + if (ver != ser.version()) + throw new IOException("Unexpected file format version: " + ver + ", " + + desc.file.getAbsoluteFile()); + + if (start != null && desc.idx == start.index()) + in.seek(start.fileOffset()); + + return new ReadFileHandle(rf, desc.idx, cctx.igniteInstanceName(), ser, in); + } + catch (SegmentEofException | EOFException ignore) { + try { + rf.close(); + } + catch (IOException ce) { + throw new IgniteCheckedException(ce); + } + + return null; + } + catch (IOException | IgniteCheckedException e) { + try { + rf.close(); + } + catch (IOException ce) { + e.addSuppressed(ce); + } + + throw e; + } + } + catch (FileNotFoundException e) { + throw e; + } + catch (IOException e) { + throw new IgniteCheckedException( + "Failed to initialize WAL segment: " + desc.file.getAbsolutePath(), e); + } + } + + /** + * @param absIdx Absolute index to check. + * @return {@code True} if we can safely read the archive, {@code false} if the segment has not been + * archived yet. In this case the corresponding work segment is reserved (will not be deleted until + * release). + */ + private boolean canReadArchiveOrReserveWork(int absIdx) { + return archiver != null && archiver.checkCanReadArchiveOrReserveWorkSegment(absIdx); + } + + /** + * @param absIdx Absolute index to release. + */ + private void releaseWorkSegment(int absIdx) { + if (archiver != null) + archiver.releaseWorkSegment(absIdx); + } + } + + private class QueueFlusher extends Thread { + /** */ + private volatile boolean stopped; + + /** + * @param gridName Grid name. + */ + private QueueFlusher(String gridName) { + super("wal-queue-flusher-#" + gridName); + } + + /** {@inheritDoc} */ + @Override public void run() { + while (!stopped) { + long wakeup = U.currentTimeMillis() + FLUSH_FREQ; + + LockSupport.parkUntil(wakeup); + + FileWriteHandle hnd = currentHandle(); + + try { + hnd.flush(hnd.head.get()); + } + catch (IgniteCheckedException e) { + U.warn(log, "Failed to flush WAL record queue", e); + } + } + } + + private void shutdown() { + stopped = true; + + LockSupport.unpark(this); + + try { + join(); + } + catch (InterruptedException ignore) { + // Got interrupted while waiting for flusher to shutdown. + } + } + } + + /** + * WAL Mode. + */ + private enum Mode { + NONE, LOG_ONLY, BACKGROUND, DEFAULT + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java new file mode 100644 index 0000000000000..8afc1ed41850a --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java @@ -0,0 +1,34 @@ +package org.apache.ignite.internal.processors.cache.database.wal; + +import java.io.IOException; +import java.nio.ByteBuffer; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.pagemem.wal.record.WALRecord; + +/** + * Record serializer. + */ +public interface RecordSerializer { + /** + * @return writer + */ + public int version(); + + /** + * @param record Record. + * @return Size in bytes. + */ + public int size(WALRecord record) throws IgniteCheckedException; + + /** + * @param record Entry to write. + * @param buf Buffer. + */ + public void writeRecord(WALRecord record, ByteBuffer buf) throws IgniteCheckedException; + + /** + * @param in Data input to read data from. + * @return Read entry. + */ + public WALRecord readRecord(FileInput in) throws IOException, IgniteCheckedException; +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/SegmentEofException.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/SegmentEofException.java new file mode 100644 index 0000000000000..75456f7df5274 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/SegmentEofException.java @@ -0,0 +1,20 @@ +package org.apache.ignite.internal.processors.cache.database.wal; + +import org.apache.ignite.IgniteCheckedException; + +/** + * This exception is thrown either when we reach the end of file of WAL segment, or when we encounter + * a record with type equal to {@code 0}. + */ +public class SegmentEofException extends IgniteCheckedException { + /** */ + private static final long serialVersionUID = 0L; + + /** + * @param msg Message. + * @param cause Cause. + */ + public SegmentEofException(String msg, Throwable cause) { + super(msg, cause, false); + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/IgniteDataIntegrityViolationException.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/IgniteDataIntegrityViolationException.java new file mode 100644 index 0000000000000..f0a64222ee1b9 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/IgniteDataIntegrityViolationException.java @@ -0,0 +1,24 @@ +package org.apache.ignite.internal.processors.cache.database.wal.crc; + +import org.apache.ignite.IgniteException; + +/** + * Will be thrown if data integrity violation is found + */ +public class IgniteDataIntegrityViolationException extends IgniteException { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Default constructor. + */ + public IgniteDataIntegrityViolationException() { + } + + /** + * @param msg Message. + */ + public IgniteDataIntegrityViolationException(String msg) { + super(msg); + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/PureJavaCrc32.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/PureJavaCrc32.java new file mode 100644 index 0000000000000..9775a7560f5dd --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/PureJavaCrc32.java @@ -0,0 +1,638 @@ +package org.apache.ignite.internal.processors.cache.database.wal.crc; + + +import java.nio.ByteBuffer; + +/** + * This class was taken from Hadoop org.apache.hadoop.util.PureJavaCrc32 + * + * A pure-java implementation of the CRC32 checksum that uses the same polynomial as the built-in native CRC32. + * + * This is to avoid the JNI overhead for certain uses of Checksumming where many small pieces of data are checksummed in + * succession. + * + * The current version is ~10x to 1.8x as fast as Sun's native java.util.zip.CRC32 in Java 1.6 + */ +public class PureJavaCrc32 { + /** + * the current CRC value + */ + private int crc; + + /** + * Create a new PureJavaCrc32 object. + */ + public PureJavaCrc32() { + reset(); + } + + /** + * return crc32 value + */ + public int getValue() { + return crc; + } + + /** + * preparation for further calculations + */ + public void reset() { + crc = 0xffffffff; + } + + /** + * @param b B. + * @param len Length. + */ + public void update(final ByteBuffer b, final int len) { + crc = calcCrc32(crc, b, len); + } + + /** + * @param b B. + */ + final public void update(int b) { + crc = (crc >>> 8) ^ T[(((crc ^ b) << 24) >>> 24)]; + } + + + /** + * Calculates CRC32 checksum. This method will move buffer's position to {@code len} bytes forward. + * + * @param b B. + * @param len Length. + */ + public static int calcCrc32(ByteBuffer b, final int len) { + return calcCrc32(0xffffffff, b, len); + } + + /** + * @param crc0 Crc 0. + * @param b B. + * @param len Length. + */ + private static int calcCrc32(int crc0, ByteBuffer b, final int len) { + int crc = crc0; + + final int remainder = len & 0x7; + int i = 0; + for (; i < len - remainder; i += 8) { + final int x = crc + ^ ((((b.get() << 24) >>> 24) + ((b.get() << 24) >>> 16)) + + (((b.get() << 24) >>> 8) + (b.get() << 24))); + + crc = ((T[((x << 24) >>> 24) + 0x700] ^ T[((x << 16) >>> 24) + 0x600]) + ^ (T[((x << 8) >>> 24) + 0x500] ^ T[(x >>> 24) + 0x400])) + ^ ((T[((b.get() << 24) >>> 24) + 0x300] ^ T[((b.get() << 24) >>> 24) + 0x200]) + ^ (T[((b.get() << 24) >>> 24) + 0x100] ^ T[((b.get() << 24) >>> 24)])); + } + + /* loop unroll - duff's device style */ + switch (remainder) { + case 7: + crc = (crc >>> 8) ^ T[((crc ^ b.get()) << 24) >>> 24]; + case 6: + crc = (crc >>> 8) ^ T[((crc ^ b.get()) << 24) >>> 24]; + case 5: + crc = (crc >>> 8) ^ T[((crc ^ b.get()) << 24) >>> 24]; + case 4: + crc = (crc >>> 8) ^ T[((crc ^ b.get()) << 24) >>> 24]; + case 3: + crc = (crc >>> 8) ^ T[((crc ^ b.get()) << 24) >>> 24]; + case 2: + crc = (crc >>> 8) ^ T[((crc ^ b.get()) << 24) >>> 24]; + case 1: + crc = (crc >>> 8) ^ T[((crc ^ b.get()) << 24) >>> 24]; + default: + /* nothing */ + } + + return crc; + } + + /** + * CRC-32 lookup tables generated by the polynomial 0xEDB88320. + */ + private static final int[] T = new int[]{ + /* T8_0 */ + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, + 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, + 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, + 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, + 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, + 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, + 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, + 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, + 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, + 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, + 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, + 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, + 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, + 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, + 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, + 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, + 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, + 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, + 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, + 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, + 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, + 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, + 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, + 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, + 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, + 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, + 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, + 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, + 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, + 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, + 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, + 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, + 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, + 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, + 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, + 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, + 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, + 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, + 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, + 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, + 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, + 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, + 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, + /* T8_1 */ + 0x00000000, 0x191B3141, 0x32366282, 0x2B2D53C3, + 0x646CC504, 0x7D77F445, 0x565AA786, 0x4F4196C7, + 0xC8D98A08, 0xD1C2BB49, 0xFAEFE88A, 0xE3F4D9CB, + 0xACB54F0C, 0xB5AE7E4D, 0x9E832D8E, 0x87981CCF, + 0x4AC21251, 0x53D92310, 0x78F470D3, 0x61EF4192, + 0x2EAED755, 0x37B5E614, 0x1C98B5D7, 0x05838496, + 0x821B9859, 0x9B00A918, 0xB02DFADB, 0xA936CB9A, + 0xE6775D5D, 0xFF6C6C1C, 0xD4413FDF, 0xCD5A0E9E, + 0x958424A2, 0x8C9F15E3, 0xA7B24620, 0xBEA97761, + 0xF1E8E1A6, 0xE8F3D0E7, 0xC3DE8324, 0xDAC5B265, + 0x5D5DAEAA, 0x44469FEB, 0x6F6BCC28, 0x7670FD69, + 0x39316BAE, 0x202A5AEF, 0x0B07092C, 0x121C386D, + 0xDF4636F3, 0xC65D07B2, 0xED705471, 0xF46B6530, + 0xBB2AF3F7, 0xA231C2B6, 0x891C9175, 0x9007A034, + 0x179FBCFB, 0x0E848DBA, 0x25A9DE79, 0x3CB2EF38, + 0x73F379FF, 0x6AE848BE, 0x41C51B7D, 0x58DE2A3C, + 0xF0794F05, 0xE9627E44, 0xC24F2D87, 0xDB541CC6, + 0x94158A01, 0x8D0EBB40, 0xA623E883, 0xBF38D9C2, + 0x38A0C50D, 0x21BBF44C, 0x0A96A78F, 0x138D96CE, + 0x5CCC0009, 0x45D73148, 0x6EFA628B, 0x77E153CA, + 0xBABB5D54, 0xA3A06C15, 0x888D3FD6, 0x91960E97, + 0xDED79850, 0xC7CCA911, 0xECE1FAD2, 0xF5FACB93, + 0x7262D75C, 0x6B79E61D, 0x4054B5DE, 0x594F849F, + 0x160E1258, 0x0F152319, 0x243870DA, 0x3D23419B, + 0x65FD6BA7, 0x7CE65AE6, 0x57CB0925, 0x4ED03864, + 0x0191AEA3, 0x188A9FE2, 0x33A7CC21, 0x2ABCFD60, + 0xAD24E1AF, 0xB43FD0EE, 0x9F12832D, 0x8609B26C, + 0xC94824AB, 0xD05315EA, 0xFB7E4629, 0xE2657768, + 0x2F3F79F6, 0x362448B7, 0x1D091B74, 0x04122A35, + 0x4B53BCF2, 0x52488DB3, 0x7965DE70, 0x607EEF31, + 0xE7E6F3FE, 0xFEFDC2BF, 0xD5D0917C, 0xCCCBA03D, + 0x838A36FA, 0x9A9107BB, 0xB1BC5478, 0xA8A76539, + 0x3B83984B, 0x2298A90A, 0x09B5FAC9, 0x10AECB88, + 0x5FEF5D4F, 0x46F46C0E, 0x6DD93FCD, 0x74C20E8C, + 0xF35A1243, 0xEA412302, 0xC16C70C1, 0xD8774180, + 0x9736D747, 0x8E2DE606, 0xA500B5C5, 0xBC1B8484, + 0x71418A1A, 0x685ABB5B, 0x4377E898, 0x5A6CD9D9, + 0x152D4F1E, 0x0C367E5F, 0x271B2D9C, 0x3E001CDD, + 0xB9980012, 0xA0833153, 0x8BAE6290, 0x92B553D1, + 0xDDF4C516, 0xC4EFF457, 0xEFC2A794, 0xF6D996D5, + 0xAE07BCE9, 0xB71C8DA8, 0x9C31DE6B, 0x852AEF2A, + 0xCA6B79ED, 0xD37048AC, 0xF85D1B6F, 0xE1462A2E, + 0x66DE36E1, 0x7FC507A0, 0x54E85463, 0x4DF36522, + 0x02B2F3E5, 0x1BA9C2A4, 0x30849167, 0x299FA026, + 0xE4C5AEB8, 0xFDDE9FF9, 0xD6F3CC3A, 0xCFE8FD7B, + 0x80A96BBC, 0x99B25AFD, 0xB29F093E, 0xAB84387F, + 0x2C1C24B0, 0x350715F1, 0x1E2A4632, 0x07317773, + 0x4870E1B4, 0x516BD0F5, 0x7A468336, 0x635DB277, + 0xCBFAD74E, 0xD2E1E60F, 0xF9CCB5CC, 0xE0D7848D, + 0xAF96124A, 0xB68D230B, 0x9DA070C8, 0x84BB4189, + 0x03235D46, 0x1A386C07, 0x31153FC4, 0x280E0E85, + 0x674F9842, 0x7E54A903, 0x5579FAC0, 0x4C62CB81, + 0x8138C51F, 0x9823F45E, 0xB30EA79D, 0xAA1596DC, + 0xE554001B, 0xFC4F315A, 0xD7626299, 0xCE7953D8, + 0x49E14F17, 0x50FA7E56, 0x7BD72D95, 0x62CC1CD4, + 0x2D8D8A13, 0x3496BB52, 0x1FBBE891, 0x06A0D9D0, + 0x5E7EF3EC, 0x4765C2AD, 0x6C48916E, 0x7553A02F, + 0x3A1236E8, 0x230907A9, 0x0824546A, 0x113F652B, + 0x96A779E4, 0x8FBC48A5, 0xA4911B66, 0xBD8A2A27, + 0xF2CBBCE0, 0xEBD08DA1, 0xC0FDDE62, 0xD9E6EF23, + 0x14BCE1BD, 0x0DA7D0FC, 0x268A833F, 0x3F91B27E, + 0x70D024B9, 0x69CB15F8, 0x42E6463B, 0x5BFD777A, + 0xDC656BB5, 0xC57E5AF4, 0xEE530937, 0xF7483876, + 0xB809AEB1, 0xA1129FF0, 0x8A3FCC33, 0x9324FD72, + /* T8_2 */ + 0x00000000, 0x01C26A37, 0x0384D46E, 0x0246BE59, + 0x0709A8DC, 0x06CBC2EB, 0x048D7CB2, 0x054F1685, + 0x0E1351B8, 0x0FD13B8F, 0x0D9785D6, 0x0C55EFE1, + 0x091AF964, 0x08D89353, 0x0A9E2D0A, 0x0B5C473D, + 0x1C26A370, 0x1DE4C947, 0x1FA2771E, 0x1E601D29, + 0x1B2F0BAC, 0x1AED619B, 0x18ABDFC2, 0x1969B5F5, + 0x1235F2C8, 0x13F798FF, 0x11B126A6, 0x10734C91, + 0x153C5A14, 0x14FE3023, 0x16B88E7A, 0x177AE44D, + 0x384D46E0, 0x398F2CD7, 0x3BC9928E, 0x3A0BF8B9, + 0x3F44EE3C, 0x3E86840B, 0x3CC03A52, 0x3D025065, + 0x365E1758, 0x379C7D6F, 0x35DAC336, 0x3418A901, + 0x3157BF84, 0x3095D5B3, 0x32D36BEA, 0x331101DD, + 0x246BE590, 0x25A98FA7, 0x27EF31FE, 0x262D5BC9, + 0x23624D4C, 0x22A0277B, 0x20E69922, 0x2124F315, + 0x2A78B428, 0x2BBADE1F, 0x29FC6046, 0x283E0A71, + 0x2D711CF4, 0x2CB376C3, 0x2EF5C89A, 0x2F37A2AD, + 0x709A8DC0, 0x7158E7F7, 0x731E59AE, 0x72DC3399, + 0x7793251C, 0x76514F2B, 0x7417F172, 0x75D59B45, + 0x7E89DC78, 0x7F4BB64F, 0x7D0D0816, 0x7CCF6221, + 0x798074A4, 0x78421E93, 0x7A04A0CA, 0x7BC6CAFD, + 0x6CBC2EB0, 0x6D7E4487, 0x6F38FADE, 0x6EFA90E9, + 0x6BB5866C, 0x6A77EC5B, 0x68315202, 0x69F33835, + 0x62AF7F08, 0x636D153F, 0x612BAB66, 0x60E9C151, + 0x65A6D7D4, 0x6464BDE3, 0x662203BA, 0x67E0698D, + 0x48D7CB20, 0x4915A117, 0x4B531F4E, 0x4A917579, + 0x4FDE63FC, 0x4E1C09CB, 0x4C5AB792, 0x4D98DDA5, + 0x46C49A98, 0x4706F0AF, 0x45404EF6, 0x448224C1, + 0x41CD3244, 0x400F5873, 0x4249E62A, 0x438B8C1D, + 0x54F16850, 0x55330267, 0x5775BC3E, 0x56B7D609, + 0x53F8C08C, 0x523AAABB, 0x507C14E2, 0x51BE7ED5, + 0x5AE239E8, 0x5B2053DF, 0x5966ED86, 0x58A487B1, + 0x5DEB9134, 0x5C29FB03, 0x5E6F455A, 0x5FAD2F6D, + 0xE1351B80, 0xE0F771B7, 0xE2B1CFEE, 0xE373A5D9, + 0xE63CB35C, 0xE7FED96B, 0xE5B86732, 0xE47A0D05, + 0xEF264A38, 0xEEE4200F, 0xECA29E56, 0xED60F461, + 0xE82FE2E4, 0xE9ED88D3, 0xEBAB368A, 0xEA695CBD, + 0xFD13B8F0, 0xFCD1D2C7, 0xFE976C9E, 0xFF5506A9, + 0xFA1A102C, 0xFBD87A1B, 0xF99EC442, 0xF85CAE75, + 0xF300E948, 0xF2C2837F, 0xF0843D26, 0xF1465711, + 0xF4094194, 0xF5CB2BA3, 0xF78D95FA, 0xF64FFFCD, + 0xD9785D60, 0xD8BA3757, 0xDAFC890E, 0xDB3EE339, + 0xDE71F5BC, 0xDFB39F8B, 0xDDF521D2, 0xDC374BE5, + 0xD76B0CD8, 0xD6A966EF, 0xD4EFD8B6, 0xD52DB281, + 0xD062A404, 0xD1A0CE33, 0xD3E6706A, 0xD2241A5D, + 0xC55EFE10, 0xC49C9427, 0xC6DA2A7E, 0xC7184049, + 0xC25756CC, 0xC3953CFB, 0xC1D382A2, 0xC011E895, + 0xCB4DAFA8, 0xCA8FC59F, 0xC8C97BC6, 0xC90B11F1, + 0xCC440774, 0xCD866D43, 0xCFC0D31A, 0xCE02B92D, + 0x91AF9640, 0x906DFC77, 0x922B422E, 0x93E92819, + 0x96A63E9C, 0x976454AB, 0x9522EAF2, 0x94E080C5, + 0x9FBCC7F8, 0x9E7EADCF, 0x9C381396, 0x9DFA79A1, + 0x98B56F24, 0x99770513, 0x9B31BB4A, 0x9AF3D17D, + 0x8D893530, 0x8C4B5F07, 0x8E0DE15E, 0x8FCF8B69, + 0x8A809DEC, 0x8B42F7DB, 0x89044982, 0x88C623B5, + 0x839A6488, 0x82580EBF, 0x801EB0E6, 0x81DCDAD1, + 0x8493CC54, 0x8551A663, 0x8717183A, 0x86D5720D, + 0xA9E2D0A0, 0xA820BA97, 0xAA6604CE, 0xABA46EF9, + 0xAEEB787C, 0xAF29124B, 0xAD6FAC12, 0xACADC625, + 0xA7F18118, 0xA633EB2F, 0xA4755576, 0xA5B73F41, + 0xA0F829C4, 0xA13A43F3, 0xA37CFDAA, 0xA2BE979D, + 0xB5C473D0, 0xB40619E7, 0xB640A7BE, 0xB782CD89, + 0xB2CDDB0C, 0xB30FB13B, 0xB1490F62, 0xB08B6555, + 0xBBD72268, 0xBA15485F, 0xB853F606, 0xB9919C31, + 0xBCDE8AB4, 0xBD1CE083, 0xBF5A5EDA, 0xBE9834ED, + /* T8_3 */ + 0x00000000, 0xB8BC6765, 0xAA09C88B, 0x12B5AFEE, + 0x8F629757, 0x37DEF032, 0x256B5FDC, 0x9DD738B9, + 0xC5B428EF, 0x7D084F8A, 0x6FBDE064, 0xD7018701, + 0x4AD6BFB8, 0xF26AD8DD, 0xE0DF7733, 0x58631056, + 0x5019579F, 0xE8A530FA, 0xFA109F14, 0x42ACF871, + 0xDF7BC0C8, 0x67C7A7AD, 0x75720843, 0xCDCE6F26, + 0x95AD7F70, 0x2D111815, 0x3FA4B7FB, 0x8718D09E, + 0x1ACFE827, 0xA2738F42, 0xB0C620AC, 0x087A47C9, + 0xA032AF3E, 0x188EC85B, 0x0A3B67B5, 0xB28700D0, + 0x2F503869, 0x97EC5F0C, 0x8559F0E2, 0x3DE59787, + 0x658687D1, 0xDD3AE0B4, 0xCF8F4F5A, 0x7733283F, + 0xEAE41086, 0x525877E3, 0x40EDD80D, 0xF851BF68, + 0xF02BF8A1, 0x48979FC4, 0x5A22302A, 0xE29E574F, + 0x7F496FF6, 0xC7F50893, 0xD540A77D, 0x6DFCC018, + 0x359FD04E, 0x8D23B72B, 0x9F9618C5, 0x272A7FA0, + 0xBAFD4719, 0x0241207C, 0x10F48F92, 0xA848E8F7, + 0x9B14583D, 0x23A83F58, 0x311D90B6, 0x89A1F7D3, + 0x1476CF6A, 0xACCAA80F, 0xBE7F07E1, 0x06C36084, + 0x5EA070D2, 0xE61C17B7, 0xF4A9B859, 0x4C15DF3C, + 0xD1C2E785, 0x697E80E0, 0x7BCB2F0E, 0xC377486B, + 0xCB0D0FA2, 0x73B168C7, 0x6104C729, 0xD9B8A04C, + 0x446F98F5, 0xFCD3FF90, 0xEE66507E, 0x56DA371B, + 0x0EB9274D, 0xB6054028, 0xA4B0EFC6, 0x1C0C88A3, + 0x81DBB01A, 0x3967D77F, 0x2BD27891, 0x936E1FF4, + 0x3B26F703, 0x839A9066, 0x912F3F88, 0x299358ED, + 0xB4446054, 0x0CF80731, 0x1E4DA8DF, 0xA6F1CFBA, + 0xFE92DFEC, 0x462EB889, 0x549B1767, 0xEC277002, + 0x71F048BB, 0xC94C2FDE, 0xDBF98030, 0x6345E755, + 0x6B3FA09C, 0xD383C7F9, 0xC1366817, 0x798A0F72, + 0xE45D37CB, 0x5CE150AE, 0x4E54FF40, 0xF6E89825, + 0xAE8B8873, 0x1637EF16, 0x048240F8, 0xBC3E279D, + 0x21E91F24, 0x99557841, 0x8BE0D7AF, 0x335CB0CA, + 0xED59B63B, 0x55E5D15E, 0x47507EB0, 0xFFEC19D5, + 0x623B216C, 0xDA874609, 0xC832E9E7, 0x708E8E82, + 0x28ED9ED4, 0x9051F9B1, 0x82E4565F, 0x3A58313A, + 0xA78F0983, 0x1F336EE6, 0x0D86C108, 0xB53AA66D, + 0xBD40E1A4, 0x05FC86C1, 0x1749292F, 0xAFF54E4A, + 0x322276F3, 0x8A9E1196, 0x982BBE78, 0x2097D91D, + 0x78F4C94B, 0xC048AE2E, 0xD2FD01C0, 0x6A4166A5, + 0xF7965E1C, 0x4F2A3979, 0x5D9F9697, 0xE523F1F2, + 0x4D6B1905, 0xF5D77E60, 0xE762D18E, 0x5FDEB6EB, + 0xC2098E52, 0x7AB5E937, 0x680046D9, 0xD0BC21BC, + 0x88DF31EA, 0x3063568F, 0x22D6F961, 0x9A6A9E04, + 0x07BDA6BD, 0xBF01C1D8, 0xADB46E36, 0x15080953, + 0x1D724E9A, 0xA5CE29FF, 0xB77B8611, 0x0FC7E174, + 0x9210D9CD, 0x2AACBEA8, 0x38191146, 0x80A57623, + 0xD8C66675, 0x607A0110, 0x72CFAEFE, 0xCA73C99B, + 0x57A4F122, 0xEF189647, 0xFDAD39A9, 0x45115ECC, + 0x764DEE06, 0xCEF18963, 0xDC44268D, 0x64F841E8, + 0xF92F7951, 0x41931E34, 0x5326B1DA, 0xEB9AD6BF, + 0xB3F9C6E9, 0x0B45A18C, 0x19F00E62, 0xA14C6907, + 0x3C9B51BE, 0x842736DB, 0x96929935, 0x2E2EFE50, + 0x2654B999, 0x9EE8DEFC, 0x8C5D7112, 0x34E11677, + 0xA9362ECE, 0x118A49AB, 0x033FE645, 0xBB838120, + 0xE3E09176, 0x5B5CF613, 0x49E959FD, 0xF1553E98, + 0x6C820621, 0xD43E6144, 0xC68BCEAA, 0x7E37A9CF, + 0xD67F4138, 0x6EC3265D, 0x7C7689B3, 0xC4CAEED6, + 0x591DD66F, 0xE1A1B10A, 0xF3141EE4, 0x4BA87981, + 0x13CB69D7, 0xAB770EB2, 0xB9C2A15C, 0x017EC639, + 0x9CA9FE80, 0x241599E5, 0x36A0360B, 0x8E1C516E, + 0x866616A7, 0x3EDA71C2, 0x2C6FDE2C, 0x94D3B949, + 0x090481F0, 0xB1B8E695, 0xA30D497B, 0x1BB12E1E, + 0x43D23E48, 0xFB6E592D, 0xE9DBF6C3, 0x516791A6, + 0xCCB0A91F, 0x740CCE7A, 0x66B96194, 0xDE0506F1, + /* T8_4 */ + 0x00000000, 0x3D6029B0, 0x7AC05360, 0x47A07AD0, + 0xF580A6C0, 0xC8E08F70, 0x8F40F5A0, 0xB220DC10, + 0x30704BC1, 0x0D106271, 0x4AB018A1, 0x77D03111, + 0xC5F0ED01, 0xF890C4B1, 0xBF30BE61, 0x825097D1, + 0x60E09782, 0x5D80BE32, 0x1A20C4E2, 0x2740ED52, + 0x95603142, 0xA80018F2, 0xEFA06222, 0xD2C04B92, + 0x5090DC43, 0x6DF0F5F3, 0x2A508F23, 0x1730A693, + 0xA5107A83, 0x98705333, 0xDFD029E3, 0xE2B00053, + 0xC1C12F04, 0xFCA106B4, 0xBB017C64, 0x866155D4, + 0x344189C4, 0x0921A074, 0x4E81DAA4, 0x73E1F314, + 0xF1B164C5, 0xCCD14D75, 0x8B7137A5, 0xB6111E15, + 0x0431C205, 0x3951EBB5, 0x7EF19165, 0x4391B8D5, + 0xA121B886, 0x9C419136, 0xDBE1EBE6, 0xE681C256, + 0x54A11E46, 0x69C137F6, 0x2E614D26, 0x13016496, + 0x9151F347, 0xAC31DAF7, 0xEB91A027, 0xD6F18997, + 0x64D15587, 0x59B17C37, 0x1E1106E7, 0x23712F57, + 0x58F35849, 0x659371F9, 0x22330B29, 0x1F532299, + 0xAD73FE89, 0x9013D739, 0xD7B3ADE9, 0xEAD38459, + 0x68831388, 0x55E33A38, 0x124340E8, 0x2F236958, + 0x9D03B548, 0xA0639CF8, 0xE7C3E628, 0xDAA3CF98, + 0x3813CFCB, 0x0573E67B, 0x42D39CAB, 0x7FB3B51B, + 0xCD93690B, 0xF0F340BB, 0xB7533A6B, 0x8A3313DB, + 0x0863840A, 0x3503ADBA, 0x72A3D76A, 0x4FC3FEDA, + 0xFDE322CA, 0xC0830B7A, 0x872371AA, 0xBA43581A, + 0x9932774D, 0xA4525EFD, 0xE3F2242D, 0xDE920D9D, + 0x6CB2D18D, 0x51D2F83D, 0x167282ED, 0x2B12AB5D, + 0xA9423C8C, 0x9422153C, 0xD3826FEC, 0xEEE2465C, + 0x5CC29A4C, 0x61A2B3FC, 0x2602C92C, 0x1B62E09C, + 0xF9D2E0CF, 0xC4B2C97F, 0x8312B3AF, 0xBE729A1F, + 0x0C52460F, 0x31326FBF, 0x7692156F, 0x4BF23CDF, + 0xC9A2AB0E, 0xF4C282BE, 0xB362F86E, 0x8E02D1DE, + 0x3C220DCE, 0x0142247E, 0x46E25EAE, 0x7B82771E, + 0xB1E6B092, 0x8C869922, 0xCB26E3F2, 0xF646CA42, + 0x44661652, 0x79063FE2, 0x3EA64532, 0x03C66C82, + 0x8196FB53, 0xBCF6D2E3, 0xFB56A833, 0xC6368183, + 0x74165D93, 0x49767423, 0x0ED60EF3, 0x33B62743, + 0xD1062710, 0xEC660EA0, 0xABC67470, 0x96A65DC0, + 0x248681D0, 0x19E6A860, 0x5E46D2B0, 0x6326FB00, + 0xE1766CD1, 0xDC164561, 0x9BB63FB1, 0xA6D61601, + 0x14F6CA11, 0x2996E3A1, 0x6E369971, 0x5356B0C1, + 0x70279F96, 0x4D47B626, 0x0AE7CCF6, 0x3787E546, + 0x85A73956, 0xB8C710E6, 0xFF676A36, 0xC2074386, + 0x4057D457, 0x7D37FDE7, 0x3A978737, 0x07F7AE87, + 0xB5D77297, 0x88B75B27, 0xCF1721F7, 0xF2770847, + 0x10C70814, 0x2DA721A4, 0x6A075B74, 0x576772C4, + 0xE547AED4, 0xD8278764, 0x9F87FDB4, 0xA2E7D404, + 0x20B743D5, 0x1DD76A65, 0x5A7710B5, 0x67173905, + 0xD537E515, 0xE857CCA5, 0xAFF7B675, 0x92979FC5, + 0xE915E8DB, 0xD475C16B, 0x93D5BBBB, 0xAEB5920B, + 0x1C954E1B, 0x21F567AB, 0x66551D7B, 0x5B3534CB, + 0xD965A31A, 0xE4058AAA, 0xA3A5F07A, 0x9EC5D9CA, + 0x2CE505DA, 0x11852C6A, 0x562556BA, 0x6B457F0A, + 0x89F57F59, 0xB49556E9, 0xF3352C39, 0xCE550589, + 0x7C75D999, 0x4115F029, 0x06B58AF9, 0x3BD5A349, + 0xB9853498, 0x84E51D28, 0xC34567F8, 0xFE254E48, + 0x4C059258, 0x7165BBE8, 0x36C5C138, 0x0BA5E888, + 0x28D4C7DF, 0x15B4EE6F, 0x521494BF, 0x6F74BD0F, + 0xDD54611F, 0xE03448AF, 0xA794327F, 0x9AF41BCF, + 0x18A48C1E, 0x25C4A5AE, 0x6264DF7E, 0x5F04F6CE, + 0xED242ADE, 0xD044036E, 0x97E479BE, 0xAA84500E, + 0x4834505D, 0x755479ED, 0x32F4033D, 0x0F942A8D, + 0xBDB4F69D, 0x80D4DF2D, 0xC774A5FD, 0xFA148C4D, + 0x78441B9C, 0x4524322C, 0x028448FC, 0x3FE4614C, + 0x8DC4BD5C, 0xB0A494EC, 0xF704EE3C, 0xCA64C78C, + /* T8_5 */ + 0x00000000, 0xCB5CD3A5, 0x4DC8A10B, 0x869472AE, + 0x9B914216, 0x50CD91B3, 0xD659E31D, 0x1D0530B8, + 0xEC53826D, 0x270F51C8, 0xA19B2366, 0x6AC7F0C3, + 0x77C2C07B, 0xBC9E13DE, 0x3A0A6170, 0xF156B2D5, + 0x03D6029B, 0xC88AD13E, 0x4E1EA390, 0x85427035, + 0x9847408D, 0x531B9328, 0xD58FE186, 0x1ED33223, + 0xEF8580F6, 0x24D95353, 0xA24D21FD, 0x6911F258, + 0x7414C2E0, 0xBF481145, 0x39DC63EB, 0xF280B04E, + 0x07AC0536, 0xCCF0D693, 0x4A64A43D, 0x81387798, + 0x9C3D4720, 0x57619485, 0xD1F5E62B, 0x1AA9358E, + 0xEBFF875B, 0x20A354FE, 0xA6372650, 0x6D6BF5F5, + 0x706EC54D, 0xBB3216E8, 0x3DA66446, 0xF6FAB7E3, + 0x047A07AD, 0xCF26D408, 0x49B2A6A6, 0x82EE7503, + 0x9FEB45BB, 0x54B7961E, 0xD223E4B0, 0x197F3715, + 0xE82985C0, 0x23755665, 0xA5E124CB, 0x6EBDF76E, + 0x73B8C7D6, 0xB8E41473, 0x3E7066DD, 0xF52CB578, + 0x0F580A6C, 0xC404D9C9, 0x4290AB67, 0x89CC78C2, + 0x94C9487A, 0x5F959BDF, 0xD901E971, 0x125D3AD4, + 0xE30B8801, 0x28575BA4, 0xAEC3290A, 0x659FFAAF, + 0x789ACA17, 0xB3C619B2, 0x35526B1C, 0xFE0EB8B9, + 0x0C8E08F7, 0xC7D2DB52, 0x4146A9FC, 0x8A1A7A59, + 0x971F4AE1, 0x5C439944, 0xDAD7EBEA, 0x118B384F, + 0xE0DD8A9A, 0x2B81593F, 0xAD152B91, 0x6649F834, + 0x7B4CC88C, 0xB0101B29, 0x36846987, 0xFDD8BA22, + 0x08F40F5A, 0xC3A8DCFF, 0x453CAE51, 0x8E607DF4, + 0x93654D4C, 0x58399EE9, 0xDEADEC47, 0x15F13FE2, + 0xE4A78D37, 0x2FFB5E92, 0xA96F2C3C, 0x6233FF99, + 0x7F36CF21, 0xB46A1C84, 0x32FE6E2A, 0xF9A2BD8F, + 0x0B220DC1, 0xC07EDE64, 0x46EAACCA, 0x8DB67F6F, + 0x90B34FD7, 0x5BEF9C72, 0xDD7BEEDC, 0x16273D79, + 0xE7718FAC, 0x2C2D5C09, 0xAAB92EA7, 0x61E5FD02, + 0x7CE0CDBA, 0xB7BC1E1F, 0x31286CB1, 0xFA74BF14, + 0x1EB014D8, 0xD5ECC77D, 0x5378B5D3, 0x98246676, + 0x852156CE, 0x4E7D856B, 0xC8E9F7C5, 0x03B52460, + 0xF2E396B5, 0x39BF4510, 0xBF2B37BE, 0x7477E41B, + 0x6972D4A3, 0xA22E0706, 0x24BA75A8, 0xEFE6A60D, + 0x1D661643, 0xD63AC5E6, 0x50AEB748, 0x9BF264ED, + 0x86F75455, 0x4DAB87F0, 0xCB3FF55E, 0x006326FB, + 0xF135942E, 0x3A69478B, 0xBCFD3525, 0x77A1E680, + 0x6AA4D638, 0xA1F8059D, 0x276C7733, 0xEC30A496, + 0x191C11EE, 0xD240C24B, 0x54D4B0E5, 0x9F886340, + 0x828D53F8, 0x49D1805D, 0xCF45F2F3, 0x04192156, + 0xF54F9383, 0x3E134026, 0xB8873288, 0x73DBE12D, + 0x6EDED195, 0xA5820230, 0x2316709E, 0xE84AA33B, + 0x1ACA1375, 0xD196C0D0, 0x5702B27E, 0x9C5E61DB, + 0x815B5163, 0x4A0782C6, 0xCC93F068, 0x07CF23CD, + 0xF6999118, 0x3DC542BD, 0xBB513013, 0x700DE3B6, + 0x6D08D30E, 0xA65400AB, 0x20C07205, 0xEB9CA1A0, + 0x11E81EB4, 0xDAB4CD11, 0x5C20BFBF, 0x977C6C1A, + 0x8A795CA2, 0x41258F07, 0xC7B1FDA9, 0x0CED2E0C, + 0xFDBB9CD9, 0x36E74F7C, 0xB0733DD2, 0x7B2FEE77, + 0x662ADECF, 0xAD760D6A, 0x2BE27FC4, 0xE0BEAC61, + 0x123E1C2F, 0xD962CF8A, 0x5FF6BD24, 0x94AA6E81, + 0x89AF5E39, 0x42F38D9C, 0xC467FF32, 0x0F3B2C97, + 0xFE6D9E42, 0x35314DE7, 0xB3A53F49, 0x78F9ECEC, + 0x65FCDC54, 0xAEA00FF1, 0x28347D5F, 0xE368AEFA, + 0x16441B82, 0xDD18C827, 0x5B8CBA89, 0x90D0692C, + 0x8DD55994, 0x46898A31, 0xC01DF89F, 0x0B412B3A, + 0xFA1799EF, 0x314B4A4A, 0xB7DF38E4, 0x7C83EB41, + 0x6186DBF9, 0xAADA085C, 0x2C4E7AF2, 0xE712A957, + 0x15921919, 0xDECECABC, 0x585AB812, 0x93066BB7, + 0x8E035B0F, 0x455F88AA, 0xC3CBFA04, 0x089729A1, + 0xF9C19B74, 0x329D48D1, 0xB4093A7F, 0x7F55E9DA, + 0x6250D962, 0xA90C0AC7, 0x2F987869, 0xE4C4ABCC, + /* T8_6 */ + 0x00000000, 0xA6770BB4, 0x979F1129, 0x31E81A9D, + 0xF44F2413, 0x52382FA7, 0x63D0353A, 0xC5A73E8E, + 0x33EF4E67, 0x959845D3, 0xA4705F4E, 0x020754FA, + 0xC7A06A74, 0x61D761C0, 0x503F7B5D, 0xF64870E9, + 0x67DE9CCE, 0xC1A9977A, 0xF0418DE7, 0x56368653, + 0x9391B8DD, 0x35E6B369, 0x040EA9F4, 0xA279A240, + 0x5431D2A9, 0xF246D91D, 0xC3AEC380, 0x65D9C834, + 0xA07EF6BA, 0x0609FD0E, 0x37E1E793, 0x9196EC27, + 0xCFBD399C, 0x69CA3228, 0x582228B5, 0xFE552301, + 0x3BF21D8F, 0x9D85163B, 0xAC6D0CA6, 0x0A1A0712, + 0xFC5277FB, 0x5A257C4F, 0x6BCD66D2, 0xCDBA6D66, + 0x081D53E8, 0xAE6A585C, 0x9F8242C1, 0x39F54975, + 0xA863A552, 0x0E14AEE6, 0x3FFCB47B, 0x998BBFCF, + 0x5C2C8141, 0xFA5B8AF5, 0xCBB39068, 0x6DC49BDC, + 0x9B8CEB35, 0x3DFBE081, 0x0C13FA1C, 0xAA64F1A8, + 0x6FC3CF26, 0xC9B4C492, 0xF85CDE0F, 0x5E2BD5BB, + 0x440B7579, 0xE27C7ECD, 0xD3946450, 0x75E36FE4, + 0xB044516A, 0x16335ADE, 0x27DB4043, 0x81AC4BF7, + 0x77E43B1E, 0xD19330AA, 0xE07B2A37, 0x460C2183, + 0x83AB1F0D, 0x25DC14B9, 0x14340E24, 0xB2430590, + 0x23D5E9B7, 0x85A2E203, 0xB44AF89E, 0x123DF32A, + 0xD79ACDA4, 0x71EDC610, 0x4005DC8D, 0xE672D739, + 0x103AA7D0, 0xB64DAC64, 0x87A5B6F9, 0x21D2BD4D, + 0xE47583C3, 0x42028877, 0x73EA92EA, 0xD59D995E, + 0x8BB64CE5, 0x2DC14751, 0x1C295DCC, 0xBA5E5678, + 0x7FF968F6, 0xD98E6342, 0xE86679DF, 0x4E11726B, + 0xB8590282, 0x1E2E0936, 0x2FC613AB, 0x89B1181F, + 0x4C162691, 0xEA612D25, 0xDB8937B8, 0x7DFE3C0C, + 0xEC68D02B, 0x4A1FDB9F, 0x7BF7C102, 0xDD80CAB6, + 0x1827F438, 0xBE50FF8C, 0x8FB8E511, 0x29CFEEA5, + 0xDF879E4C, 0x79F095F8, 0x48188F65, 0xEE6F84D1, + 0x2BC8BA5F, 0x8DBFB1EB, 0xBC57AB76, 0x1A20A0C2, + 0x8816EAF2, 0x2E61E146, 0x1F89FBDB, 0xB9FEF06F, + 0x7C59CEE1, 0xDA2EC555, 0xEBC6DFC8, 0x4DB1D47C, + 0xBBF9A495, 0x1D8EAF21, 0x2C66B5BC, 0x8A11BE08, + 0x4FB68086, 0xE9C18B32, 0xD82991AF, 0x7E5E9A1B, + 0xEFC8763C, 0x49BF7D88, 0x78576715, 0xDE206CA1, + 0x1B87522F, 0xBDF0599B, 0x8C184306, 0x2A6F48B2, + 0xDC27385B, 0x7A5033EF, 0x4BB82972, 0xEDCF22C6, + 0x28681C48, 0x8E1F17FC, 0xBFF70D61, 0x198006D5, + 0x47ABD36E, 0xE1DCD8DA, 0xD034C247, 0x7643C9F3, + 0xB3E4F77D, 0x1593FCC9, 0x247BE654, 0x820CEDE0, + 0x74449D09, 0xD23396BD, 0xE3DB8C20, 0x45AC8794, + 0x800BB91A, 0x267CB2AE, 0x1794A833, 0xB1E3A387, + 0x20754FA0, 0x86024414, 0xB7EA5E89, 0x119D553D, + 0xD43A6BB3, 0x724D6007, 0x43A57A9A, 0xE5D2712E, + 0x139A01C7, 0xB5ED0A73, 0x840510EE, 0x22721B5A, + 0xE7D525D4, 0x41A22E60, 0x704A34FD, 0xD63D3F49, + 0xCC1D9F8B, 0x6A6A943F, 0x5B828EA2, 0xFDF58516, + 0x3852BB98, 0x9E25B02C, 0xAFCDAAB1, 0x09BAA105, + 0xFFF2D1EC, 0x5985DA58, 0x686DC0C5, 0xCE1ACB71, + 0x0BBDF5FF, 0xADCAFE4B, 0x9C22E4D6, 0x3A55EF62, + 0xABC30345, 0x0DB408F1, 0x3C5C126C, 0x9A2B19D8, + 0x5F8C2756, 0xF9FB2CE2, 0xC813367F, 0x6E643DCB, + 0x982C4D22, 0x3E5B4696, 0x0FB35C0B, 0xA9C457BF, + 0x6C636931, 0xCA146285, 0xFBFC7818, 0x5D8B73AC, + 0x03A0A617, 0xA5D7ADA3, 0x943FB73E, 0x3248BC8A, + 0xF7EF8204, 0x519889B0, 0x6070932D, 0xC6079899, + 0x304FE870, 0x9638E3C4, 0xA7D0F959, 0x01A7F2ED, + 0xC400CC63, 0x6277C7D7, 0x539FDD4A, 0xF5E8D6FE, + 0x647E3AD9, 0xC209316D, 0xF3E12BF0, 0x55962044, + 0x90311ECA, 0x3646157E, 0x07AE0FE3, 0xA1D90457, + 0x579174BE, 0xF1E67F0A, 0xC00E6597, 0x66796E23, + 0xA3DE50AD, 0x05A95B19, 0x34414184, 0x92364A30, + /* T8_7 */ + 0x00000000, 0xCCAA009E, 0x4225077D, 0x8E8F07E3, + 0x844A0EFA, 0x48E00E64, 0xC66F0987, 0x0AC50919, + 0xD3E51BB5, 0x1F4F1B2B, 0x91C01CC8, 0x5D6A1C56, + 0x57AF154F, 0x9B0515D1, 0x158A1232, 0xD92012AC, + 0x7CBB312B, 0xB01131B5, 0x3E9E3656, 0xF23436C8, + 0xF8F13FD1, 0x345B3F4F, 0xBAD438AC, 0x767E3832, + 0xAF5E2A9E, 0x63F42A00, 0xED7B2DE3, 0x21D12D7D, + 0x2B142464, 0xE7BE24FA, 0x69312319, 0xA59B2387, + 0xF9766256, 0x35DC62C8, 0xBB53652B, 0x77F965B5, + 0x7D3C6CAC, 0xB1966C32, 0x3F196BD1, 0xF3B36B4F, + 0x2A9379E3, 0xE639797D, 0x68B67E9E, 0xA41C7E00, + 0xAED97719, 0x62737787, 0xECFC7064, 0x205670FA, + 0x85CD537D, 0x496753E3, 0xC7E85400, 0x0B42549E, + 0x01875D87, 0xCD2D5D19, 0x43A25AFA, 0x8F085A64, + 0x562848C8, 0x9A824856, 0x140D4FB5, 0xD8A74F2B, + 0xD2624632, 0x1EC846AC, 0x9047414F, 0x5CED41D1, + 0x299DC2ED, 0xE537C273, 0x6BB8C590, 0xA712C50E, + 0xADD7CC17, 0x617DCC89, 0xEFF2CB6A, 0x2358CBF4, + 0xFA78D958, 0x36D2D9C6, 0xB85DDE25, 0x74F7DEBB, + 0x7E32D7A2, 0xB298D73C, 0x3C17D0DF, 0xF0BDD041, + 0x5526F3C6, 0x998CF358, 0x1703F4BB, 0xDBA9F425, + 0xD16CFD3C, 0x1DC6FDA2, 0x9349FA41, 0x5FE3FADF, + 0x86C3E873, 0x4A69E8ED, 0xC4E6EF0E, 0x084CEF90, + 0x0289E689, 0xCE23E617, 0x40ACE1F4, 0x8C06E16A, + 0xD0EBA0BB, 0x1C41A025, 0x92CEA7C6, 0x5E64A758, + 0x54A1AE41, 0x980BAEDF, 0x1684A93C, 0xDA2EA9A2, + 0x030EBB0E, 0xCFA4BB90, 0x412BBC73, 0x8D81BCED, + 0x8744B5F4, 0x4BEEB56A, 0xC561B289, 0x09CBB217, + 0xAC509190, 0x60FA910E, 0xEE7596ED, 0x22DF9673, + 0x281A9F6A, 0xE4B09FF4, 0x6A3F9817, 0xA6959889, + 0x7FB58A25, 0xB31F8ABB, 0x3D908D58, 0xF13A8DC6, + 0xFBFF84DF, 0x37558441, 0xB9DA83A2, 0x7570833C, + 0x533B85DA, 0x9F918544, 0x111E82A7, 0xDDB48239, + 0xD7718B20, 0x1BDB8BBE, 0x95548C5D, 0x59FE8CC3, + 0x80DE9E6F, 0x4C749EF1, 0xC2FB9912, 0x0E51998C, + 0x04949095, 0xC83E900B, 0x46B197E8, 0x8A1B9776, + 0x2F80B4F1, 0xE32AB46F, 0x6DA5B38C, 0xA10FB312, + 0xABCABA0B, 0x6760BA95, 0xE9EFBD76, 0x2545BDE8, + 0xFC65AF44, 0x30CFAFDA, 0xBE40A839, 0x72EAA8A7, + 0x782FA1BE, 0xB485A120, 0x3A0AA6C3, 0xF6A0A65D, + 0xAA4DE78C, 0x66E7E712, 0xE868E0F1, 0x24C2E06F, + 0x2E07E976, 0xE2ADE9E8, 0x6C22EE0B, 0xA088EE95, + 0x79A8FC39, 0xB502FCA7, 0x3B8DFB44, 0xF727FBDA, + 0xFDE2F2C3, 0x3148F25D, 0xBFC7F5BE, 0x736DF520, + 0xD6F6D6A7, 0x1A5CD639, 0x94D3D1DA, 0x5879D144, + 0x52BCD85D, 0x9E16D8C3, 0x1099DF20, 0xDC33DFBE, + 0x0513CD12, 0xC9B9CD8C, 0x4736CA6F, 0x8B9CCAF1, + 0x8159C3E8, 0x4DF3C376, 0xC37CC495, 0x0FD6C40B, + 0x7AA64737, 0xB60C47A9, 0x3883404A, 0xF42940D4, + 0xFEEC49CD, 0x32464953, 0xBCC94EB0, 0x70634E2E, + 0xA9435C82, 0x65E95C1C, 0xEB665BFF, 0x27CC5B61, + 0x2D095278, 0xE1A352E6, 0x6F2C5505, 0xA386559B, + 0x061D761C, 0xCAB77682, 0x44387161, 0x889271FF, + 0x825778E6, 0x4EFD7878, 0xC0727F9B, 0x0CD87F05, + 0xD5F86DA9, 0x19526D37, 0x97DD6AD4, 0x5B776A4A, + 0x51B26353, 0x9D1863CD, 0x1397642E, 0xDF3D64B0, + 0x83D02561, 0x4F7A25FF, 0xC1F5221C, 0x0D5F2282, + 0x079A2B9B, 0xCB302B05, 0x45BF2CE6, 0x89152C78, + 0x50353ED4, 0x9C9F3E4A, 0x121039A9, 0xDEBA3937, + 0xD47F302E, 0x18D530B0, 0x965A3753, 0x5AF037CD, + 0xFF6B144A, 0x33C114D4, 0xBD4E1337, 0x71E413A9, + 0x7B211AB0, 0xB78B1A2E, 0x39041DCD, 0xF5AE1D53, + 0x2C8E0FFF, 0xE0240F61, 0x6EAB0882, 0xA201081C, + 0xA8C40105, 0x646E019B, 0xEAE10678, 0x264B06E6 + }; +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java new file mode 100644 index 0000000000000..951303b036d0a --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java @@ -0,0 +1,33 @@ +package org.apache.ignite.internal.processors.cache.database.wal.record; + +import org.apache.ignite.internal.pagemem.wal.record.WALRecord; + +/** + * Header record. + */ +public class HeaderRecord extends WALRecord { + /** */ + public static final long MAGIC = 0xB0D045A_CE7ED045AL; + + /** */ + private final int ver; + + /** + * @param ver Version. + */ + public HeaderRecord(int ver) { + this.ver = ver; + } + + /** + * @return Version. + */ + public int version() { + return ver; + } + + /** {@inheritDoc} */ + @Override public RecordType type() { + return RecordType.HEADER_RECORD; + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java new file mode 100644 index 0000000000000..f3bc5c8ba9ad0 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java @@ -0,0 +1,1624 @@ +package org.apache.ignite.internal.processors.cache.database.wal.serializer; + +import java.io.DataInput; +import java.io.EOFException; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.wal.record.CacheState; +import org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord; +import org.apache.ignite.internal.pagemem.wal.record.DataEntry; +import org.apache.ignite.internal.pagemem.wal.record.DataRecord; +import org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry; +import org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord; +import org.apache.ignite.internal.pagemem.wal.record.PageSnapshot; +import org.apache.ignite.internal.pagemem.wal.record.StoreOperationRecord; +import org.apache.ignite.internal.pagemem.wal.record.StoreOperationRecord.StoreOperationType; +import org.apache.ignite.internal.pagemem.wal.record.WALRecord; +import org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType; +import org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertFragmentRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.DataPageRemoveRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.DataPageSetFreeListPageRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.DataPageUpdateRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.FixCountRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.FixLeftmostChildRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.FixRemoveId; +import org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.InnerReplaceRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.InsertRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.MergeRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageAddRootRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageCutRootRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRootInlineRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRootRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateLastAllocatedIndex; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateLastSuccessfulFullSnapshotId; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateLastSuccessfulSnapshotId; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateNextSnapshotId; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.NewRootInitRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PageListMetaResetCountRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PagesListInitNewPageRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PagesListRemovePageRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetPreviousRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.RecycleRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.RemoveRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.ReplaceRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.SplitExistingPageRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.SplitForwardPageRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.TrackingPageDeltaRecord; +import org.apache.ignite.internal.processors.cache.CacheObject; +import org.apache.ignite.internal.processors.cache.CacheObjectContext; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheOperation; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.CacheVersionIO; +import org.apache.ignite.internal.processors.cache.database.wal.ByteBufferBackedDataInput; +import org.apache.ignite.internal.processors.cache.database.wal.FileInput; +import org.apache.ignite.internal.processors.cache.database.wal.FileWALPointer; +import org.apache.ignite.internal.processors.cache.database.wal.RecordSerializer; +import org.apache.ignite.internal.processors.cache.database.wal.SegmentEofException; +import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; +import org.apache.ignite.internal.processors.cache.database.wal.record.HeaderRecord; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor; + +import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC; + +/** + * Record V1 serializer. + */ +public class RecordV1Serializer implements RecordSerializer { + /** */ + private GridCacheSharedContext cctx; + + /** */ + private int pageSize; + + /** */ + private IgniteCacheObjectProcessor co; + + /** */ + private boolean skipCrc = IgniteSystemProperties.getBoolean(IGNITE_PDS_SKIP_CRC, false); + + /** + * @param cctx Cache shared context. + */ + public RecordV1Serializer(GridCacheSharedContext cctx) { + this.cctx = cctx; + + co = cctx.kernalContext().cacheObjects(); + pageSize = cctx.database().pageSize(); + } + + /** {@inheritDoc} */ + @Override public int version() { + return 1; + } + + /** {@inheritDoc} */ + @SuppressWarnings("CastConflictsWithInstanceof") + @Override public void writeRecord(WALRecord record, ByteBuffer buf) throws IgniteCheckedException { + assert record.size() > 0 && buf.remaining() >= record.size() : record.size(); + + int startPos = buf.position(); + + buf.put((byte)(record.type().ordinal() + 1)); + + switch (record.type()) { + case PAGE_RECORD: + PageSnapshot snap = (PageSnapshot)record; + + buf.putInt(snap.fullPageId().cacheId()); + buf.putLong(snap.fullPageId().pageId()); + buf.put(snap.pageData()); + + break; + + case STORE_OPERATION_RECORD: + StoreOperationRecord storeRec = (StoreOperationRecord)record; + + buf.put((byte)storeRec.operationType().ordinal()); + buf.putInt(storeRec.cacheId()); + buf.putLong(storeRec.link()); + buf.putInt(storeRec.indexId()); + + break; + + case MEMORY_RECOVERY: + MemoryRecoveryRecord memoryRecoveryRecord = (MemoryRecoveryRecord)record; + + buf.putLong(memoryRecoveryRecord.time()); + + break; + + case PARTITION_DESTROY: + PartitionDestroyRecord partDestroy = (PartitionDestroyRecord)record; + + buf.putInt(partDestroy.cacheId()); + buf.putInt(partDestroy.cacheId()); + + break; + + case META_PAGE_INIT: + MetaPageInitRecord updRootsRec = (MetaPageInitRecord)record; + + buf.putInt(updRootsRec.cacheId()); + buf.putLong(updRootsRec.pageId()); + + buf.putShort((short)updRootsRec.ioType()); + buf.putShort((short)updRootsRec.ioVersion()); + buf.putLong(updRootsRec.treeRoot()); + buf.putLong(updRootsRec.reuseListRoot()); + + break; + + case PARTITION_META_PAGE_UPDATE_COUNTERS: + MetaPageUpdatePartitionDataRecord partDataRec = (MetaPageUpdatePartitionDataRecord)record; + + buf.putInt(partDataRec.cacheId()); + buf.putLong(partDataRec.pageId()); + + buf.putLong(partDataRec.updateCounter()); + buf.putLong(partDataRec.globalRemoveId()); + buf.putInt(partDataRec.partitionSize()); + buf.put(partDataRec.state()); + buf.putInt(partDataRec.allocatedIndexCandidate()); + + break; + + case CHECKPOINT_RECORD: + CheckpointRecord cpRec = (CheckpointRecord)record; + + assert cpRec.checkpointMark() == null || cpRec.checkpointMark() instanceof FileWALPointer : + "Invalid WAL record: " + cpRec; + + FileWALPointer walPtr = (FileWALPointer)cpRec.checkpointMark(); + UUID cpId = cpRec.checkpointId(); + + buf.putLong(cpId.getMostSignificantBits()); + buf.putLong(cpId.getLeastSignificantBits()); + + buf.put(walPtr == null ? (byte)0 : 1); + + if (walPtr != null) { + buf.putInt(walPtr.index()); + buf.putInt(walPtr.fileOffset()); + buf.putInt(walPtr.length()); + } + + putCacheStates(buf, cpRec.cacheStates()); + + buf.put(cpRec.end() ? (byte)1 : 0); + + break; + + case DATA_RECORD: + DataRecord dataRec = (DataRecord)record; + + buf.putInt(dataRec.writeEntries().size()); + + for (DataEntry dataEntry : dataRec.writeEntries()) + putDataEntry(buf, dataEntry); + + break; + + case HEADER_RECORD: + buf.putLong(HeaderRecord.MAGIC); + + buf.putInt(((HeaderRecord)record).version()); + + break; + + case DATA_PAGE_INSERT_RECORD: + DataPageInsertRecord diRec = (DataPageInsertRecord)record; + + buf.putInt(diRec.cacheId()); + buf.putLong(diRec.pageId()); + + buf.putShort((short)diRec.payload().length); + + buf.put(diRec.payload()); + + break; + + case DATA_PAGE_UPDATE_RECORD: + DataPageUpdateRecord uRec = (DataPageUpdateRecord)record; + + buf.putInt(uRec.cacheId()); + buf.putLong(uRec.pageId()); + buf.putInt(uRec.itemId()); + + buf.putShort((short)uRec.payload().length); + + buf.put(uRec.payload()); + + break; + + case DATA_PAGE_INSERT_FRAGMENT_RECORD: + final DataPageInsertFragmentRecord difRec = (DataPageInsertFragmentRecord)record; + + buf.putInt(difRec.cacheId()); + buf.putLong(difRec.pageId()); + + buf.putLong(difRec.lastLink()); + buf.putInt(difRec.payloadSize()); + buf.put(difRec.payload()); + + break; + + case DATA_PAGE_REMOVE_RECORD: + DataPageRemoveRecord drRec = (DataPageRemoveRecord)record; + + buf.putInt(drRec.cacheId()); + buf.putLong(drRec.pageId()); + + buf.put((byte)drRec.itemId()); + + break; + + case DATA_PAGE_SET_FREE_LIST_PAGE: + DataPageSetFreeListPageRecord freeListRec = (DataPageSetFreeListPageRecord)record; + + buf.putInt(freeListRec.cacheId()); + buf.putLong(freeListRec.pageId()); + + buf.putLong(freeListRec.freeListPage()); + + break; + + case INIT_NEW_PAGE_RECORD: + InitNewPageRecord inpRec = (InitNewPageRecord)record; + + buf.putInt(inpRec.cacheId()); + buf.putLong(inpRec.pageId()); + + buf.putShort((short)inpRec.ioType()); + buf.putShort((short)inpRec.ioVersion()); + buf.putLong(inpRec.newPageId()); + + break; + + case BTREE_META_PAGE_INIT_ROOT: + MetaPageInitRootRecord imRec = (MetaPageInitRootRecord)record; + + buf.putInt(imRec.cacheId()); + buf.putLong(imRec.pageId()); + + buf.putLong(imRec.rootId()); + + break; + + case BTREE_META_PAGE_INIT_ROOT2: + MetaPageInitRootInlineRecord imRec2 = (MetaPageInitRootInlineRecord)record; + + buf.putInt(imRec2.cacheId()); + buf.putLong(imRec2.pageId()); + + buf.putLong(imRec2.rootId()); + + buf.putShort((short)imRec2.inlineSize()); + break; + + case BTREE_META_PAGE_ADD_ROOT: + MetaPageAddRootRecord arRec = (MetaPageAddRootRecord)record; + + buf.putInt(arRec.cacheId()); + buf.putLong(arRec.pageId()); + + buf.putLong(arRec.rootId()); + + break; + + case BTREE_META_PAGE_CUT_ROOT: + MetaPageCutRootRecord crRec = (MetaPageCutRootRecord)record; + + buf.putInt(crRec.cacheId()); + buf.putLong(crRec.pageId()); + + break; + + case BTREE_INIT_NEW_ROOT: + NewRootInitRecord riRec = (NewRootInitRecord)record; + + buf.putInt(riRec.cacheId()); + buf.putLong(riRec.pageId()); + + buf.putLong(riRec.rootId()); + buf.putShort((short)riRec.io().getType()); + buf.putShort((short)riRec.io().getVersion()); + buf.putLong(riRec.leftId()); + buf.putLong(riRec.rightId()); + + putRow(buf, riRec.rowBytes()); + + break; + + case BTREE_PAGE_RECYCLE: + RecycleRecord recRec = (RecycleRecord)record; + + buf.putInt(recRec.cacheId()); + buf.putLong(recRec.pageId()); + + buf.putLong(recRec.newPageId()); + + break; + + case BTREE_PAGE_INSERT: + InsertRecord inRec = (InsertRecord)record; + + buf.putInt(inRec.cacheId()); + buf.putLong(inRec.pageId()); + + buf.putShort((short)inRec.io().getType()); + buf.putShort((short)inRec.io().getVersion()); + buf.putShort((short)inRec.index()); + buf.putLong(inRec.rightId()); + + putRow(buf, inRec.rowBytes()); + + break; + + case BTREE_FIX_LEFTMOST_CHILD: + FixLeftmostChildRecord flRec = (FixLeftmostChildRecord)record; + + buf.putInt(flRec.cacheId()); + buf.putLong(flRec.pageId()); + + buf.putLong(flRec.rightId()); + + break; + + case BTREE_FIX_COUNT: + FixCountRecord fcRec = (FixCountRecord)record; + + buf.putInt(fcRec.cacheId()); + buf.putLong(fcRec.pageId()); + + buf.putShort((short)fcRec.count()); + + break; + + case BTREE_PAGE_REPLACE: + ReplaceRecord rRec = (ReplaceRecord)record; + + buf.putInt(rRec.cacheId()); + buf.putLong(rRec.pageId()); + + buf.putShort((short)rRec.io().getType()); + buf.putShort((short)rRec.io().getVersion()); + buf.putShort((short)rRec.index()); + + putRow(buf, rRec.rowBytes()); + + break; + + case BTREE_PAGE_REMOVE: + RemoveRecord rmRec = (RemoveRecord)record; + + buf.putInt(rmRec.cacheId()); + buf.putLong(rmRec.pageId()); + + buf.putShort((short)rmRec.index()); + buf.putShort((short)rmRec.count()); + + break; + + case BTREE_PAGE_INNER_REPLACE: + InnerReplaceRecord irRec = (InnerReplaceRecord)record; + + buf.putInt(irRec.cacheId()); + buf.putLong(irRec.pageId()); + + buf.putShort((short)irRec.destinationIndex()); + buf.putLong(irRec.sourcePageId()); + buf.putShort((short)irRec.sourceIndex()); + buf.putLong(irRec.removeId()); + + break; + + case BTREE_FORWARD_PAGE_SPLIT: + SplitForwardPageRecord sfRec = (SplitForwardPageRecord)record; + + buf.putInt(sfRec.cacheId()); + buf.putLong(sfRec.pageId()); + + buf.putLong(sfRec.forwardId()); + buf.putShort((short)sfRec.ioType()); + buf.putShort((short)sfRec.ioVersion()); + buf.putLong(sfRec.sourcePageId()); + buf.putShort((short)sfRec.middleIndex()); + buf.putShort((short)sfRec.count()); + + break; + + case BTREE_EXISTING_PAGE_SPLIT: + SplitExistingPageRecord seRec = (SplitExistingPageRecord)record; + + buf.putInt(seRec.cacheId()); + buf.putLong(seRec.pageId()); + + buf.putShort((short)seRec.middleIndex()); + buf.putLong(seRec.forwardId()); + + break; + + case BTREE_PAGE_MERGE: + MergeRecord mRec = (MergeRecord)record; + + buf.putInt(mRec.cacheId()); + buf.putLong(mRec.pageId()); + + buf.putLong(mRec.parentId()); + buf.putShort((short)mRec.parentIndex()); + buf.putLong(mRec.rightId()); + buf.put((byte)(mRec.isEmptyBranch() ? 1 : 0)); + + break; + + case PAGES_LIST_SET_NEXT: + PagesListSetNextRecord plNextRec = (PagesListSetNextRecord)record; + + buf.putInt(plNextRec.cacheId()); + buf.putLong(plNextRec.pageId()); + + buf.putLong(plNextRec.nextPageId()); + + break; + + case PAGES_LIST_SET_PREVIOUS: + PagesListSetPreviousRecord plPrevRec = (PagesListSetPreviousRecord)record; + + buf.putInt(plPrevRec.cacheId()); + buf.putLong(plPrevRec.pageId()); + + buf.putLong(plPrevRec.previousPageId()); + + break; + + case PAGES_LIST_INIT_NEW_PAGE: + PagesListInitNewPageRecord plNewRec = (PagesListInitNewPageRecord)record; + + buf.putInt(plNewRec.cacheId()); + buf.putLong(plNewRec.pageId()); + buf.putInt(plNewRec.ioType()); + buf.putInt(plNewRec.ioVersion()); + buf.putLong(plNewRec.newPageId()); + + buf.putLong(plNewRec.previousPageId()); + buf.putLong(plNewRec.dataPageId()); + + break; + + case PAGES_LIST_ADD_PAGE: + PagesListAddPageRecord plAddRec = (PagesListAddPageRecord)record; + + buf.putInt(plAddRec.cacheId()); + buf.putLong(plAddRec.pageId()); + + buf.putLong(plAddRec.dataPageId()); + + break; + + case PAGES_LIST_REMOVE_PAGE: + PagesListRemovePageRecord plRmvRec = (PagesListRemovePageRecord)record; + + buf.putInt(plRmvRec.cacheId()); + buf.putLong(plRmvRec.pageId()); + + buf.putLong(plRmvRec.removedPageId()); + + break; + + case BTREE_FIX_REMOVE_ID: + FixRemoveId frRec = (FixRemoveId)record; + + buf.putInt(frRec.cacheId()); + buf.putLong(frRec.pageId()); + + buf.putLong(frRec.removeId()); + + break; + + case TRACKING_PAGE_DELTA: + TrackingPageDeltaRecord tpDelta = (TrackingPageDeltaRecord)record; + + buf.putInt(tpDelta.cacheId()); + buf.putLong(tpDelta.pageId()); + + buf.putLong(tpDelta.pageIdToMark()); + buf.putLong(tpDelta.nextSnapshotId()); + buf.putLong(tpDelta.lastSuccessfulSnapshotId()); + + break; + + case META_PAGE_UPDATE_NEXT_SNAPSHOT_ID: + MetaPageUpdateNextSnapshotId mpUpdateNextSnapshotId = (MetaPageUpdateNextSnapshotId)record; + + buf.putInt(mpUpdateNextSnapshotId.cacheId()); + buf.putLong(mpUpdateNextSnapshotId.pageId()); + + buf.putLong(mpUpdateNextSnapshotId.nextSnapshotId()); + + break; + + case META_PAGE_UPDATE_LAST_SUCCESSFUL_FULL_SNAPSHOT_ID: + MetaPageUpdateLastSuccessfulFullSnapshotId mpUpdateLastSuccFullSnapshotId = + (MetaPageUpdateLastSuccessfulFullSnapshotId)record; + + buf.putInt(mpUpdateLastSuccFullSnapshotId.cacheId()); + buf.putLong(mpUpdateLastSuccFullSnapshotId.pageId()); + + buf.putLong(mpUpdateLastSuccFullSnapshotId.lastSuccessfulFullSnapshotId()); + + break; + + case META_PAGE_UPDATE_LAST_SUCCESSFUL_SNAPSHOT_ID: + MetaPageUpdateLastSuccessfulSnapshotId mpUpdateLastSuccSnapshotId = + (MetaPageUpdateLastSuccessfulSnapshotId)record; + + buf.putInt(mpUpdateLastSuccSnapshotId.cacheId()); + buf.putLong(mpUpdateLastSuccSnapshotId.pageId()); + + buf.putLong(mpUpdateLastSuccSnapshotId.lastSuccessfulSnapshotId()); + buf.putLong(mpUpdateLastSuccSnapshotId.lastSuccessfulSnapshotTag()); + + break; + + case META_PAGE_UPDATE_LAST_ALLOCATED_INDEX: + MetaPageUpdateLastAllocatedIndex mpUpdateLastAllocatedIdx = + (MetaPageUpdateLastAllocatedIndex) record; + + buf.putInt(mpUpdateLastAllocatedIdx.cacheId()); + buf.putLong(mpUpdateLastAllocatedIdx.pageId()); + + buf.putInt(mpUpdateLastAllocatedIdx.lastAllocatedIndex()); + + break; + + case PART_META_UPDATE_STATE: + PartitionMetaStateRecord partMetaStateRecord = (PartitionMetaStateRecord) record; + + buf.putInt(partMetaStateRecord.cacheId()); + + buf.putInt(partMetaStateRecord.partitionId()); + + buf.put(partMetaStateRecord.state()); + + buf.putLong(partMetaStateRecord.updateCounter()); + + break; + + case PAGE_LIST_META_RESET_COUNT_RECORD: + PageListMetaResetCountRecord pageListMetaResetCntRecord = (PageListMetaResetCountRecord) record; + + buf.putInt(pageListMetaResetCntRecord.cacheId()); + buf.putLong(pageListMetaResetCntRecord.pageId()); + + break; + + default: + throw new UnsupportedOperationException("Type: " + record.type()); + } + + if (!skipCrc) { + int curPos = buf.position(); + + buf.position(startPos); + + // This call will move buffer position to the end of the record again. + int crcVal = PureJavaCrc32.calcCrc32(buf, curPos - startPos); + + buf.putInt(crcVal); + } + else + buf.putInt(0); + } + + /** {@inheritDoc} */ + @Override public WALRecord readRecord(FileInput in0) throws IOException, IgniteCheckedException { + long startPos = -1; + + try (FileInput.Crc32CheckingFileInput in = in0.startRead(skipCrc)) { + startPos = in0.position(); + + WALRecord res = readRecord(in); + + assert res != null; + + res.size((int)(in0.position() - startPos + 4)); // Account for CRC which will be read afterwards. + + return res; + } + catch (EOFException | SegmentEofException e) { + throw e; + } + catch (Exception e) { + throw new IgniteCheckedException("Failed to read WAL record at position: " + startPos, e); + } + } + + /** + * @param in In. + */ + private WALRecord readRecord(ByteBufferBackedDataInput in) throws IOException, IgniteCheckedException { + int type = in.readUnsignedByte(); + + if (type == 0) + throw new SegmentEofException("Reached logical end of the segment", null); + + RecordType recType = RecordType.fromOrdinal(type - 1); + + if (recType == null) + throw new IOException("Unknown record type: " + type); + + WALRecord res; + + switch (recType) { + case PAGE_RECORD: + byte[] arr = new byte[pageSize]; + + int cacheId = in.readInt(); + long pageId = in.readLong(); + + in.readFully(arr); + + res = new PageSnapshot(new FullPageId(pageId, cacheId), arr); + + break; + + case STORE_OPERATION_RECORD: + StoreOperationRecord storeRec = new StoreOperationRecord(); + + storeRec.operationType(StoreOperationType.fromOrdinal(in.readByte() & 0xFF)); + storeRec.cacheId(in.readInt()); + storeRec.link(in.readLong()); + storeRec.indexId(in.readInt()); + + res = storeRec; + + break; + + case CHECKPOINT_RECORD: + long msb = in.readLong(); + long lsb = in.readLong(); + boolean hasPtr = in.readByte() != 0; + int idx = hasPtr ? in.readInt() : 0; + int offset = hasPtr ? in.readInt() : 0; + int len = hasPtr ? in.readInt() : 0; + + Map states = readPartitionStates(in); + + boolean end = in.readByte() != 0; + + FileWALPointer walPtr = hasPtr ? new FileWALPointer(idx, offset, len) : null; + + CheckpointRecord cpRec = new CheckpointRecord(new UUID(msb, lsb), walPtr, end); + + cpRec.cacheStates(states); + + res = cpRec; + + break; + + case META_PAGE_INIT: + cacheId = in.readInt(); + pageId = in.readLong(); + + int ioType = in.readUnsignedShort(); + int ioVer = in.readUnsignedShort(); + long treeRoot = in.readLong(); + long reuseListRoot = in.readLong(); + + res = new MetaPageInitRecord(cacheId, pageId, ioType, ioVer, treeRoot, reuseListRoot); + + break; + + case PARTITION_META_PAGE_UPDATE_COUNTERS: + cacheId = in.readInt(); + pageId = in.readLong(); + + long updCntr = in.readLong(); + long rmvId = in.readLong(); + int partSize = in.readInt(); + byte state = in.readByte(); + int allocatedIdxCandidate = in.readInt(); + + res = new MetaPageUpdatePartitionDataRecord(cacheId, pageId, updCntr, rmvId, partSize, state, allocatedIdxCandidate); + + break; + + case MEMORY_RECOVERY: + long ts = in.readLong(); + + res = new MemoryRecoveryRecord(ts); + + break; + + case PARTITION_DESTROY: + cacheId = in.readInt(); + int partId = in.readInt(); + + res = new PartitionDestroyRecord(cacheId, partId); + + break; + + case DATA_RECORD: + int entryCnt = in.readInt(); + + List entries = new ArrayList<>(entryCnt); + + for (int i = 0; i < entryCnt; i++) + entries.add(readDataEntry(in)); + + res = new DataRecord(entries); + + break; + + case HEADER_RECORD: + if (in.readLong() != HeaderRecord.MAGIC) + throw new EOFException("Magic is corrupted."); + + int ver = in.readInt(); + + res = new HeaderRecord(ver); + + break; + + case DATA_PAGE_INSERT_RECORD: { + cacheId = in.readInt(); + pageId = in.readLong(); + + int size = in.readUnsignedShort(); + + in.ensure(size); + + byte[] payload = new byte[size]; + + in.readFully(payload); + + res = new DataPageInsertRecord(cacheId, pageId, payload); + + break; + } + + case DATA_PAGE_UPDATE_RECORD: { + cacheId = in.readInt(); + pageId = in.readLong(); + + int itemId = in.readInt(); + + int size = in.readUnsignedShort(); + + in.ensure(size); + + byte[] payload = new byte[size]; + + in.readFully(payload); + + res = new DataPageUpdateRecord(cacheId, pageId, itemId, payload); + + break; + } + + case DATA_PAGE_INSERT_FRAGMENT_RECORD: { + cacheId = in.readInt(); + pageId = in.readLong(); + + final long lastLink = in.readLong(); + final int payloadSize = in.readInt(); + + final byte[] payload = new byte[payloadSize]; + + in.readFully(payload); + + res = new DataPageInsertFragmentRecord(cacheId, pageId, payload, lastLink); + + break; + } + + case DATA_PAGE_REMOVE_RECORD: + cacheId = in.readInt(); + pageId = in.readLong(); + + int itemId = in.readUnsignedByte(); + + res = new DataPageRemoveRecord(cacheId, pageId, itemId); + + break; + + case DATA_PAGE_SET_FREE_LIST_PAGE: + cacheId = in.readInt(); + pageId = in.readLong(); + + long freeListPage = in.readLong(); + + res = new DataPageSetFreeListPageRecord(cacheId, pageId, freeListPage); + + break; + + case INIT_NEW_PAGE_RECORD: + cacheId = in.readInt(); + pageId = in.readLong(); + + ioType = in.readUnsignedShort(); + ioVer = in.readUnsignedShort(); + long virtualPageId = in.readLong(); + + res = new InitNewPageRecord(cacheId, pageId, ioType, ioVer, virtualPageId); + + break; + + case BTREE_META_PAGE_INIT_ROOT: + cacheId = in.readInt(); + pageId = in.readLong(); + + long rootId = in.readLong(); + + res = new MetaPageInitRootRecord(cacheId, pageId, rootId); + + break; + + case BTREE_META_PAGE_INIT_ROOT2: + cacheId = in.readInt(); + pageId = in.readLong(); + + long rootId2 = in.readLong(); + int inlineSize = in.readShort(); + + res = new MetaPageInitRootInlineRecord(cacheId, pageId, rootId2, inlineSize); + + break; + + case BTREE_META_PAGE_ADD_ROOT: + cacheId = in.readInt(); + pageId = in.readLong(); + + rootId = in.readLong(); + + res = new MetaPageAddRootRecord(cacheId, pageId, rootId); + + break; + + case BTREE_META_PAGE_CUT_ROOT: + cacheId = in.readInt(); + pageId = in.readLong(); + + res = new MetaPageCutRootRecord(cacheId, pageId); + + break; + + case BTREE_INIT_NEW_ROOT: + cacheId = in.readInt(); + pageId = in.readLong(); + + rootId = in.readLong(); + ioType = in.readUnsignedShort(); + ioVer = in.readUnsignedShort(); + long leftId = in.readLong(); + long rightId = in.readLong(); + + BPlusIO io = BPlusIO.getBPlusIO(ioType, ioVer); + + byte[] rowBytes = new byte[io.getItemSize()]; + + in.readFully(rowBytes); + + res = new NewRootInitRecord<>(cacheId, pageId, rootId, (BPlusInnerIO)io, leftId, rowBytes, rightId); + + break; + + case BTREE_PAGE_RECYCLE: + cacheId = in.readInt(); + pageId = in.readLong(); + + long newPageId = in.readLong(); + + res = new RecycleRecord(cacheId, pageId, newPageId); + + break; + + case BTREE_PAGE_INSERT: + cacheId = in.readInt(); + pageId = in.readLong(); + + ioType = in.readUnsignedShort(); + ioVer = in.readUnsignedShort(); + int itemIdx = in.readUnsignedShort(); + rightId = in.readLong(); + + io = BPlusIO.getBPlusIO(ioType, ioVer); + + rowBytes = new byte[io.getItemSize()]; + + in.readFully(rowBytes); + + res = new InsertRecord<>(cacheId, pageId, io, itemIdx, rowBytes, rightId); + + break; + + case BTREE_FIX_LEFTMOST_CHILD: + cacheId = in.readInt(); + pageId = in.readLong(); + + rightId = in.readLong(); + + res = new FixLeftmostChildRecord(cacheId, pageId, rightId); + + break; + + case BTREE_FIX_COUNT: + cacheId = in.readInt(); + pageId = in.readLong(); + + int cnt = in.readUnsignedShort(); + + res = new FixCountRecord(cacheId, pageId, cnt); + + break; + + case BTREE_PAGE_REPLACE: + cacheId = in.readInt(); + pageId = in.readLong(); + + ioType = in.readUnsignedShort(); + ioVer = in.readUnsignedShort(); + itemIdx = in.readUnsignedShort(); + + io = BPlusIO.getBPlusIO(ioType, ioVer); + + rowBytes = new byte[io.getItemSize()]; + + in.readFully(rowBytes); + + res = new ReplaceRecord<>(cacheId, pageId, io, rowBytes, itemIdx); + + break; + + case BTREE_PAGE_REMOVE: + cacheId = in.readInt(); + pageId = in.readLong(); + + itemIdx = in.readUnsignedShort(); + cnt = in.readUnsignedShort(); + + res = new RemoveRecord(cacheId, pageId, itemIdx, cnt); + + break; + + case BTREE_PAGE_INNER_REPLACE: + cacheId = in.readInt(); + pageId = in.readLong(); + + int dstIdx = in.readUnsignedShort(); + long srcPageId = in.readLong(); + int srcIdx = in.readUnsignedShort(); + rmvId = in.readLong(); + + res = new InnerReplaceRecord<>(cacheId, pageId, dstIdx, srcPageId, srcIdx, rmvId); + + break; + + case BTREE_FORWARD_PAGE_SPLIT: + cacheId = in.readInt(); + pageId = in.readLong(); + + long fwdId = in.readLong(); + ioType = in.readUnsignedShort(); + ioVer = in.readUnsignedShort(); + srcPageId = in.readLong(); + int mid = in.readUnsignedShort(); + cnt = in.readUnsignedShort(); + + res = new SplitForwardPageRecord(cacheId, pageId, fwdId, ioType, ioVer, srcPageId, mid, cnt); + + break; + + case BTREE_EXISTING_PAGE_SPLIT: + cacheId = in.readInt(); + pageId = in.readLong(); + + mid = in.readUnsignedShort(); + fwdId = in.readLong(); + + res = new SplitExistingPageRecord(cacheId, pageId, mid, fwdId); + + break; + + case BTREE_PAGE_MERGE: + cacheId = in.readInt(); + pageId = in.readLong(); + + long prntId = in.readLong(); + int prntIdx = in.readUnsignedShort(); + rightId = in.readLong(); + boolean emptyBranch = in.readBoolean(); + + res = new MergeRecord<>(cacheId, pageId, prntId, prntIdx, rightId, emptyBranch); + + break; + + case BTREE_FIX_REMOVE_ID: + cacheId = in.readInt(); + pageId = in.readLong(); + + rmvId = in.readLong(); + + res = new FixRemoveId(cacheId, pageId, rmvId); + + break; + + case PAGES_LIST_SET_NEXT: + cacheId = in.readInt(); + pageId = in.readLong(); + long nextPageId = in.readLong(); + + res = new PagesListSetNextRecord(cacheId, pageId, nextPageId); + + break; + + case PAGES_LIST_SET_PREVIOUS: + cacheId = in.readInt(); + pageId = in.readLong(); + long prevPageId = in.readLong(); + + res = new PagesListSetPreviousRecord(cacheId, pageId, prevPageId); + + break; + + case PAGES_LIST_INIT_NEW_PAGE: + cacheId = in.readInt(); + pageId = in.readLong(); + ioType = in.readInt(); + ioVer = in.readInt(); + newPageId = in.readLong(); + prevPageId = in.readLong(); + long addDataPageId = in.readLong(); + + res = new PagesListInitNewPageRecord(cacheId, pageId, ioType, ioVer, newPageId, prevPageId, addDataPageId); + + break; + + case PAGES_LIST_ADD_PAGE: + cacheId = in.readInt(); + pageId = in.readLong(); + long dataPageId = in.readLong(); + + res = new PagesListAddPageRecord(cacheId, pageId, dataPageId); + + break; + + case PAGES_LIST_REMOVE_PAGE: + cacheId = in.readInt(); + pageId = in.readLong(); + long rmvdPageId = in.readLong(); + + res = new PagesListRemovePageRecord(cacheId, pageId, rmvdPageId); + + break; + + case TRACKING_PAGE_DELTA: + cacheId = in.readInt(); + pageId = in.readLong(); + + long pageIdToMark = in.readLong(); + long nextSnapshotId0 = in.readLong(); + long lastSuccessfulSnapshotId0 = in.readLong(); + + res = new TrackingPageDeltaRecord(cacheId, pageId, pageIdToMark, nextSnapshotId0, lastSuccessfulSnapshotId0); + + break; + + case META_PAGE_UPDATE_NEXT_SNAPSHOT_ID: + cacheId = in.readInt(); + pageId = in.readLong(); + + long nextSnapshotId = in.readLong(); + + res = new MetaPageUpdateNextSnapshotId(cacheId, pageId, nextSnapshotId); + + break; + + case META_PAGE_UPDATE_LAST_SUCCESSFUL_FULL_SNAPSHOT_ID: + cacheId = in.readInt(); + pageId = in.readLong(); + + long lastSuccessfulFullSnapshotId = in.readLong(); + + res = new MetaPageUpdateLastSuccessfulFullSnapshotId(cacheId, pageId, lastSuccessfulFullSnapshotId); + + break; + + case META_PAGE_UPDATE_LAST_SUCCESSFUL_SNAPSHOT_ID: + cacheId = in.readInt(); + pageId = in.readLong(); + + long lastSuccessfulSnapshotId = in.readLong(); + long lastSuccessfulSnapshotTag = in.readLong(); + + res = new MetaPageUpdateLastSuccessfulSnapshotId(cacheId, pageId, lastSuccessfulSnapshotId, lastSuccessfulSnapshotTag); + + break; + + case META_PAGE_UPDATE_LAST_ALLOCATED_INDEX: + cacheId = in.readInt(); + pageId = in.readLong(); + + int lastAllocatedIdx = in.readInt(); + + res = new MetaPageUpdateLastAllocatedIndex(cacheId, pageId, lastAllocatedIdx); + + break; + + case PART_META_UPDATE_STATE: + cacheId = in.readInt(); + partId = in.readInt(); + + state = in.readByte(); + + long updateCounter = in.readLong(); + + res = new PartitionMetaStateRecord(cacheId, partId, GridDhtPartitionState.fromOrdinal(state), updateCounter); + + break; + + case PAGE_LIST_META_RESET_COUNT_RECORD: + cacheId = in.readInt(); + pageId = in.readLong(); + + res = new PageListMetaResetCountRecord(cacheId, pageId); + break; + + case SWITCH_SEGMENT_RECORD: + throw new EOFException("END OF SEGMENT"); + + default: + throw new UnsupportedOperationException("Type: " + recType); + } + + return res; + } + + /** {@inheritDoc} */ + @SuppressWarnings("CastConflictsWithInstanceof") + @Override public int size(WALRecord record) throws IgniteCheckedException { + switch (record.type()) { + case PAGE_RECORD: + assert record instanceof PageSnapshot; + + PageSnapshot pageRec = (PageSnapshot)record; + + return pageRec.pageData().length + 12 + 1 + 4; + + case STORE_OPERATION_RECORD: + return 18 + 4; + + case CHECKPOINT_RECORD: + CheckpointRecord cpRec = (CheckpointRecord)record; + + assert cpRec.checkpointMark() == null || cpRec.checkpointMark() instanceof FileWALPointer : + "Invalid WAL record: " + cpRec; + + int cacheStatesSize = cacheStatesSize(cpRec.cacheStates()); + + FileWALPointer walPtr = (FileWALPointer)cpRec.checkpointMark(); + + return 19 + cacheStatesSize + (walPtr == null ? 0 : 12) + 4; + + case META_PAGE_INIT: + return 1 + /*cache ID*/4 + /*page ID*/8 + /*ioType*/2 + /*ioVer*/2 + /*tree root*/8 + /*reuse root*/8 + /*CRC*/4; + + case PARTITION_META_PAGE_UPDATE_COUNTERS: + return 1 + /*cache ID*/4 + /*page ID*/8 + /*upd cntr*/8 + /*rmv id*/8 + /*part size*/4 + /*state*/ 1 + + /*allocatedIdxCandidate*/ 4 + /*CRC*/4; + + case MEMORY_RECOVERY: + return 1 + 8 + 4; + + case PARTITION_DESTROY: + return 1 + /*cacheId*/4 + /*partId*/4 + /*CRC*/4; + + case DATA_RECORD: + DataRecord dataRec = (DataRecord)record; + + return 5 + dataSize(dataRec) + 4; + + case HEADER_RECORD: + return 13 + 4; + + case DATA_PAGE_INSERT_RECORD: + DataPageInsertRecord diRec = (DataPageInsertRecord)record; + + return 1 + 4 + 8 + 2 + + diRec.payload().length + 4; + + case DATA_PAGE_UPDATE_RECORD: + DataPageUpdateRecord uRec = (DataPageUpdateRecord)record; + + return 1 + 4 + 8 + 2 + 4 + + uRec.payload().length + 4; + + case DATA_PAGE_INSERT_FRAGMENT_RECORD: + final DataPageInsertFragmentRecord difRec = (DataPageInsertFragmentRecord)record; + + return 1 + 4 + 8 + 8 + 4 + difRec.payloadSize() + 4; + + case DATA_PAGE_REMOVE_RECORD: + return 1 + 4 + 8 + 1 + 4; + + case DATA_PAGE_SET_FREE_LIST_PAGE: + return 1 + 4 + 8 + 8 + 4; + + case INIT_NEW_PAGE_RECORD: + return 1 + 4 + 8 + 2 + 2 + 8 + 4; + + case BTREE_META_PAGE_INIT_ROOT: + return 1 + 4 + 8 + 8 + 4; + + case BTREE_META_PAGE_INIT_ROOT2: + return 1 + 4 + 8 + 8 + 4 + 2; + + case BTREE_META_PAGE_ADD_ROOT: + return 1 + 4 + 8 + 8 + 4; + + case BTREE_META_PAGE_CUT_ROOT: + return 1 + 4 + 8 + 4; + + case BTREE_INIT_NEW_ROOT: + NewRootInitRecord riRec = (NewRootInitRecord)record; + + return 1 + 4 + 8 + 8 + 2 + 2 + 8 + 8 + riRec.io().getItemSize() + 4; + + case BTREE_PAGE_RECYCLE: + return 1 + 4 + 8 + 8 + 4; + + case BTREE_PAGE_INSERT: + InsertRecord inRec = (InsertRecord)record; + + return 1 + 4 + 8 + 2 + 2 + 2 + 8 + inRec.io().getItemSize() + 4; + + case BTREE_FIX_LEFTMOST_CHILD: + return 1 + 4 + 8 + 8 + 4; + + case BTREE_FIX_COUNT: + return 1 + 4 + 8 + 2 + 4; + + case BTREE_PAGE_REPLACE: + ReplaceRecord rRec = (ReplaceRecord)record; + + return 1 + 4 + 8 + 2 + 2 + 2 + rRec.io().getItemSize() + 4; + + case BTREE_PAGE_REMOVE: + return 1 + 4 + 8 + 2 + 2 + 4; + + case BTREE_PAGE_INNER_REPLACE: + return 1 + 4 + 8 + 2 + 8 + 2 + 8 + 4; + + case BTREE_FORWARD_PAGE_SPLIT: + return 1 + 4 + 8 + 8 + 2 + 2 + 8 + 2 + 2 + 4; + + case BTREE_EXISTING_PAGE_SPLIT: + return 1 + 4 + 8 + 2 + 8 + 4; + + case BTREE_PAGE_MERGE: + return 1 + 4 + 8 + 8 + 2 + 8 + 1 + 4; + + case BTREE_FIX_REMOVE_ID: + return 1 + 4 + 8 + 8 + 4; + + case PAGES_LIST_SET_NEXT: + return 1 + 4 + 8 + 8 + 4; + + case PAGES_LIST_SET_PREVIOUS: + return 1 + 4 + 8 + 8 + 4; + + case PAGES_LIST_INIT_NEW_PAGE: + return 1 + 4 + 8 + 4 + 4 + 8 + 8 + 8 + 4; + + case PAGES_LIST_ADD_PAGE: + return 1 + 4 + 8 + 8 + 4; + + case PAGES_LIST_REMOVE_PAGE: + return 1 + 4 + 8 + 8 + 4; + + case TRACKING_PAGE_DELTA: + return 1 + 4 + 8 + 8 + 8 + 8 + 4; + + case META_PAGE_UPDATE_LAST_SUCCESSFUL_SNAPSHOT_ID: + return 1 + 4 + 8 + 8 + 8 + 4; + + case META_PAGE_UPDATE_LAST_SUCCESSFUL_FULL_SNAPSHOT_ID: + return 1 + 4 + 8 + 8 + 4; + + case META_PAGE_UPDATE_NEXT_SNAPSHOT_ID: + return 1 + 4 + 8 + 8 + 4; + + case META_PAGE_UPDATE_LAST_ALLOCATED_INDEX: + return 1 + 4 + 8 + 4 + 4; + + case PART_META_UPDATE_STATE: + return /*Type*/ 1 + /*cacheId*/ 4 + /*partId*/ 4 + /*State*/1 + /*Update Counter*/ 8 + /*CRC*/4; + + case PAGE_LIST_META_RESET_COUNT_RECORD: + return /*Type*/ 1 + /*cacheId*/ 4 + /*pageId*/ 8 + /*CRC*/4; + + case SWITCH_SEGMENT_RECORD: + return /*Type*/ 1 + /*CRC*/4; + + default: + throw new UnsupportedOperationException("Type: " + record.type()); + } + } + + /** + * @param dataRec Data record to serialize. + * @return Full data record size. + * @throws IgniteCheckedException If failed to obtain the length of one of the entries. + */ + private int dataSize(DataRecord dataRec) throws IgniteCheckedException { + int sz = 0; + + for (DataEntry entry : dataRec.writeEntries()) + sz += entrySize(entry); + + return sz; + } + + /** + * @param entry Entry to get size for. + * @return Entry size. + * @throws IgniteCheckedException If failed to get key or value bytes length. + */ + private int entrySize(DataEntry entry) throws IgniteCheckedException { + GridCacheContext cctx = this.cctx.cacheContext(entry.cacheId()); + CacheObjectContext coCtx = cctx.cacheObjectContext(); + + return + /*cache ID*/4 + + /*key*/entry.key().valueBytesLength(coCtx) + + /*value*/(entry.value() == null ? 4 : entry.value().valueBytesLength(coCtx)) + + /*op*/1 + + /*near xid ver*/CacheVersionIO.size(entry.nearXidVersion(), true) + + /*write ver*/CacheVersionIO.size(entry.writeVersion(), false) + + /*part ID*/4 + + /*expire Time*/8 + + /*part cnt*/8; + } + + /** + * @param states Partition states. + * @return Size required to write partition states. + */ + private int cacheStatesSize(Map states) { + // Need 4 bytes for the number of caches. + int size = 2; + + for (Map.Entry entry : states.entrySet()) { + // Cache ID. + size += 4; + + // Need 2 bytes for the number of partitions. + size += 2; + + CacheState state = entry.getValue(); + + // 2 bytes partition ID, size and counter per partition. + size += 18 * state.partitions().size(); + } + + return size; + } + + /** + * @param buf Buffer to write to. + * @param entry Data entry. + */ + private void putDataEntry(ByteBuffer buf, DataEntry entry) throws IgniteCheckedException { + buf.putInt(entry.cacheId()); + + if (!entry.key().putValue(buf)) + throw new AssertionError(); + + if (entry.value() == null) + buf.putInt(-1); + else if (!entry.value().putValue(buf)) + throw new AssertionError(); + + buf.put((byte)entry.op().ordinal()); + + putVersion(buf, entry.nearXidVersion(), true); + putVersion(buf, entry.writeVersion(), false); + + buf.putInt(entry.partitionId()); + buf.putLong(entry.partitionCounter()); + buf.putLong(entry.expireTime()); + } + + /** + * @param states Cache states. + */ + private void putCacheStates(ByteBuffer buf, Map states) { + buf.putShort((short)states.size()); + + for (Map.Entry entry : states.entrySet()) { + buf.putInt(entry.getKey()); + + CacheState state = entry.getValue(); + + // Need 2 bytes for the number of partitions. + buf.putShort((short)state.partitions().size()); + + for (Map.Entry partEntry : state.partitions().entrySet()) { + buf.putShort((short)(int)partEntry.getKey()); + + buf.putLong(partEntry.getValue().size()); + buf.putLong(partEntry.getValue().partitionCounter()); + } + } + } + + /** + * @param in Input to read from. + * @return Read entry. + */ + private DataEntry readDataEntry(ByteBufferBackedDataInput in) throws IOException, IgniteCheckedException { + int cacheId = in.readInt(); + + int keySize = in.readInt(); + byte keyType = in.readByte(); + byte[] keyBytes = new byte[keySize]; + in.readFully(keyBytes); + + int valSize = in.readInt(); + + byte valType = 0; + byte[] valBytes = null; + + if (valSize >= 0) { + valType = in.readByte(); + valBytes = new byte[valSize]; + in.readFully(valBytes); + } + + byte ord = in.readByte(); + + GridCacheOperation op = GridCacheOperation.fromOrdinal(ord & 0xFF); + + GridCacheVersion nearXidVer = readVersion(in, true); + GridCacheVersion writeVer = readVersion(in, false); + + int partId = in.readInt(); + long partCntr = in.readLong(); + long expireTime = in.readLong(); + + GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + + if (cacheCtx != null) { + CacheObjectContext coCtx = cacheCtx.cacheObjectContext(); + + KeyCacheObject key = co.toKeyCacheObject(coCtx, keyType, keyBytes); + CacheObject val = valBytes != null ? co.toCacheObject(coCtx, valType, valBytes) : null; + + return new DataEntry( + cacheId, + key, + val, + op, + nearXidVer, + writeVer, + expireTime, + partId, + partCntr + ); + } + else + return new LazyDataEntry( + cctx, + cacheId, + keyType, + keyBytes, + valType, + valBytes, + op, + nearXidVer, + writeVer, + expireTime, + partId, + partCntr); + } + + /** + * @param buf Buffer to read from. + * @return Read map. + */ + private Map readPartitionStates(DataInput buf) throws IOException { + int caches = buf.readShort() & 0xFFFF; + + if (caches == 0) + return Collections.emptyMap(); + + Map states = new HashMap<>(caches, 1.0f); + + for (int i = 0; i < caches; i++) { + int cacheId = buf.readInt(); + + int parts = buf.readShort() & 0xFFFF; + + CacheState state = new CacheState(); + + for (int p = 0; p < parts; p++) { + int partId = buf.readShort() & 0xFFFF; + long size = buf.readLong(); + long partCntr = buf.readLong(); + + state.addPartitionState(partId, size, partCntr); + } + + states.put(cacheId, state); + } + + return states; + } + + /** + * @param buf Buffer. + * @param ver Version to write. + * @param allowNull Is {@code null}version allowed. + */ + private void putVersion(ByteBuffer buf, GridCacheVersion ver, boolean allowNull) { + CacheVersionIO.write(buf, ver, allowNull); + } + + /** + * Changes the buffer position by the number of read bytes. + * + * @param in Data input to read from. + * @param allowNull Is {@code null}version allowed. + * @return Read cache version. + */ + private GridCacheVersion readVersion(ByteBufferBackedDataInput in, boolean allowNull) throws IOException { + // To be able to read serialization protocol version. + in.ensure(1); + + try { + int size = CacheVersionIO.readSize(in.buffer(), allowNull); + + in.ensure(size); + + return CacheVersionIO.read(in.buffer(), allowNull); + } + catch (IgniteCheckedException e) { + throw new IOException(e); + } + } + + /** + * @param buf Buffer. + * @param rowBytes Row bytes. + * @throws IgniteCheckedException If failed. + */ + @SuppressWarnings("unchecked") + private static void putRow(ByteBuffer buf, byte[] rowBytes) throws IgniteCheckedException { + assert rowBytes.length > 0; + + buf.put(rowBytes); + } +} diff --git a/pom.xml b/pom.xml index 45d478c05ccbc..74e7ef90c909f 100644 --- a/pom.xml +++ b/pom.xml @@ -91,6 +91,7 @@ modules/flink modules/kubernetes modules/zeromq + modules/pds From dfc35388d45ea2596d9a9e855f9e4a5ed8fa13cd Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Thu, 4 May 2017 17:25:15 +0300 Subject: [PATCH 142/311] first although failing test for PDS functionality --- ...gniteDbMultiNodePutGetRestartSelfTest.java | 236 ++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java new file mode 100644 index 0000000000000..4bc05f7fad7c5 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java @@ -0,0 +1,236 @@ +/* + * Copyright (C) GridGain Systems. All Rights Reserved. + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.cache.database; + +import java.io.File; +import java.io.Serializable; +import java.util.List; +import java.util.UUID; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.util.typedef.internal.S; +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.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteDbMultiNodePutGetRestartSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private File allocPath; + + /** */ + private static final int GRID_CNT = 3; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + MemoryConfiguration memCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(100 * 1024 * 1024); + + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + memCfg.setMemoryPolicies(memPlcCfg); + + cfg.setMemoryConfiguration(memCfg); + + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setIndexedTypes(Integer.class, DbValue.class); + + ccfg.setRebalanceMode(CacheRebalanceMode.NONE); + + ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + + cfg.setCacheConfiguration(ccfg); + + PersistenceConfiguration dbCfg = new PersistenceConfiguration(); + + cfg.setPersistenceConfiguration(dbCfg); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(discoSpi); + + cfg.setMarshaller(null); + + BinaryConfiguration bCfg = new BinaryConfiguration(); + + bCfg.setCompactFooter(false); + + cfg.setBinaryConfiguration(bCfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + super.beforeTest(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @throws Exception if failed. + */ + public void testPutGetSimple() throws Exception { + String home = U.getIgniteHome(); + + allocPath = new File(home, "work/db/" + UUID.randomUUID()); + + allocPath.mkdirs(); + + info(">>> Will use path: " + allocPath); + + startGrids(GRID_CNT); + + try { + IgniteEx ig = grid(0); + + checkPutGetSql(ig, true); + } + finally { + stopAllGrids(); + } + + info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + + startGrids(GRID_CNT); + + try { + IgniteEx ig = grid(0); + + checkPutGetSql(ig, false); + } + finally { + stopAllGrids(); + } + } + + private void checkPutGetSql(IgniteEx ig, boolean write) { + IgniteCache cache = ig.cache(null); + + if (write) { + try (IgniteDataStreamer streamer = ig.dataStreamer(null)) { + for (int i = 0; i < 10_000; i++) + streamer.addData(i, new DbValue(i, "value-" + i, i)); + } + } + + List> res = cache.query(new SqlFieldsQuery("select ival from dbvalue where ival < ? order by ival asc") + .setArgs(10_000)).getAll(); + + assertEquals(10_000, res.size()); + + for (int i = 0; i < 10_000; i++) { + assertEquals(1, res.get(i).size()); + assertEquals(i, res.get(i).get(0)); + } + + assertEquals(1, cache.query(new SqlFieldsQuery("select lval from dbvalue where ival = 7899")).getAll().size()); + assertEquals(5000, cache.query(new SqlFieldsQuery("select lval from dbvalue where ival >= 5000 and ival < 10000")) + .getAll().size()); + + for (int i = 0; i < 10_000; i++) + assertEquals(new DbValue(i, "value-" + i, i), cache.get(i)); + } + + /** + * + */ + private static class DbValue implements Serializable { + /** */ + @QuerySqlField(index = true) + private int iVal; + + /** */ + @QuerySqlField(index = true) + private String sVal; + + /** */ + @QuerySqlField + private long lVal; + + /** + * @param iVal Integer value. + * @param sVal String value. + * @param lVal Long value. + */ + public DbValue(int iVal, String sVal, long lVal) { + this.iVal = iVal; + this.sVal = sVal; + this.lVal = lVal; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + DbValue dbValue = (DbValue)o; + + return iVal == dbValue.iVal && lVal == dbValue.lVal && + !(sVal != null ? !sVal.equals(dbValue.sVal) : dbValue.sVal != null); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int res = iVal; + + res = 31 * res + (sVal != null ? sVal.hashCode() : 0); + res = 31 * res + (int)(lVal ^ (lVal >>> 32)); + + return res; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(DbValue.class, this); + } + } +} From 984f35f4a1e3ddec24cfa0bc86f6256055dc42d0 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Thu, 4 May 2017 17:35:13 +0300 Subject: [PATCH 143/311] ignite-12163 final move pds --- .../cache/database/FullPageIdIterable.java | 248 ---- .../FullPageIdIterableComparator.java | 51 + .../GridCacheDatabaseSharedManager.java | 2 +- .../cache/database/PageIdIterable.java | 24 - .../cache/db/GridCacheOffheapManager.java | 1101 +++++++++++++++++ 5 files changed, 1153 insertions(+), 273 deletions(-) delete mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterable.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterableComparator.java delete mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PageIdIterable.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/cache/db/GridCacheOffheapManager.java diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterable.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterable.java deleted file mode 100644 index f20acfa66573f..0000000000000 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterable.java +++ /dev/null @@ -1,248 +0,0 @@ -package org.apache.ignite.internal.processors.cache.database; - -import java.io.Serializable; -import java.util.Comparator; -import java.util.Iterator; -import java.util.Map; -import java.util.NavigableMap; -import java.util.NoSuchElementException; -import org.apache.ignite.internal.pagemem.FullPageId; -import org.apache.ignite.internal.pagemem.PageIdUtils; -import org.apache.ignite.internal.util.typedef.T2; -import org.jetbrains.annotations.Nullable; - -/** - * - */ -class FullPageIdIterable implements PageIdIterable { - /** (cacheId, partId) -> (lastAllocatedIndex, count) */ - private final NavigableMap, T2> pageCounts; - - /** */ - private final int totalPageCount; - - /** - * @param pageCounts Page counts map. - */ - FullPageIdIterable(NavigableMap, T2> pageCounts) { - this.pageCounts = pageCounts; - - int sum = 0; - - for (T2 t2 : pageCounts.values()) - sum += t2.get2(); - - totalPageCount = sum; - } - - /** - * @return Total page count. - */ - public int size() { - return totalPageCount; - } - - /** - * @param fullId Full page ID. - * @return Total page count below the given page ID. - */ - public int sizeBelow(FullPageId fullId) { - if (fullId == null) - return 0; - - T2 key = new T2<>(fullId.cacheId(), PageIdUtils.partId(fullId.pageId())); - - int sum = 0; - - for (T2 t2 : pageCounts.headMap(key).values()) - sum += t2.get2(); - - sum += PageIdUtils.pageIndex(fullId.pageId()); - - return sum; - } - - /** {@inheritDoc} */ - @Override public Iterator iterator() { - return new FullPageIdIterator(); - } - - /** - * - * @param fullId Full page ID. - * @return {@code True} if contains given ID. - */ - @Override public boolean contains(FullPageId fullId) { - int cacheId = fullId.cacheId(); - int partId = PageIdUtils.partId(fullId.pageId()); - long idx = PageIdUtils.pageIndex(fullId.pageId()); - - T2 cnt = pageCounts.get(new T2<>(cacheId, partId)); - - return cnt != null && cnt.get2() > idx; - } - - /** - * - * @param fullId Full page ID. - * @return Next element after the provided one. If provided element is the last one, returns null. - * If provided element isn't contained, returns the first element. - */ - @Override @Nullable public FullPageId next(@Nullable FullPageId fullId) { - if (isEmpty()) - return null; - - if (fullId == null) { - T2 firstKey = pageCounts.firstKey(); - - return new FullPageId(PageIdUtils.pageId(firstKey.get2(), (byte)0, 0), firstKey.get1()); - } - - T2 key = new T2<>(fullId.cacheId(), PageIdUtils.partId(fullId.pageId())); - int idx = PageIdUtils.pageIndex(fullId.pageId()); - - T2 cnt = pageCounts.get(key); - - if (cnt == null || idx > cnt.get2() - 1) { - T2 firstKey = pageCounts.firstKey(); - return new FullPageId(PageIdUtils.pageId(firstKey.get2(), (byte)0, 0), firstKey.get1()); - } - else if (idx == cnt.get2() - 1) { - NavigableMap, T2> tailMap = pageCounts.tailMap(key, false); - - if (tailMap.isEmpty()) - return null; - - T2 firstKey = tailMap.firstKey(); - - return new FullPageId(PageIdUtils.pageId(firstKey.get2(), (byte)0, 0), firstKey.get1()); - } - else - return new FullPageId(PageIdUtils.pageId(key.get2(), (byte)0, idx + 1), key.get1()); - } - - /** {@inheritDoc} */ - @Override public double progress(FullPageId current) { - if (pageCounts.isEmpty()) - return 1; - - if (current == null) - return 0; - - T2 key = new T2<>(current.cacheId(), PageIdUtils.partId(current.pageId())); - - return (double) pageCounts.headMap(key).size() / pageCounts.size(); - } - - /** - * - * @return {@code True} if empty. - */ - @Override public boolean isEmpty() { - return pageCounts.isEmpty(); - } - - /** - * - */ - private class FullPageIdIterator implements Iterator { - /** */ - private final Iterator, T2>> mapIter; - - /** */ - private Map.Entry, T2> currEntry; - - /** */ - private int currIdx; - - /** */ - private FullPageId next; - - /** */ - private FullPageIdIterator() { - mapIter = pageCounts.entrySet().iterator(); - - advance(); - } - - /** - * - */ - private void advance() { - if (currEntry == null && !mapIter.hasNext()) - return; - else if (currEntry == null && mapIter.hasNext()) - currEntry = mapIter.next(); - else if (currIdx < currEntry.getValue().get2() - 1) - currIdx++; - else if (mapIter.hasNext()) { - currEntry = mapIter.next(); - - currIdx = 0; - } - else { - next = null; - - return; - } - - int cacheId = currEntry.getKey().get1(); - int partId = currEntry.getKey().get2(); - - long pageId = PageIdUtils.pageId(partId, (byte)0, currIdx); - - next = new FullPageId(pageId, cacheId); - } - - /** {@inheritDoc} */ - @Override public boolean hasNext() { - return next != null; - } - - /** {@inheritDoc} */ - @Override public FullPageId next() { - FullPageId next = this.next; - - if (next == null) - throw new NoSuchElementException(); - - advance(); - - return next; - } - - /** {@inheritDoc} */ - @Override public void remove() { - throw new UnsupportedOperationException("remove"); - } - } -} - -/** - * - */ -class FullPageIdIterableComparator implements Comparator>, Serializable { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - static final FullPageIdIterableComparator INSTANCE = new FullPageIdIterableComparator(); - - /** {@inheritDoc} */ - @Override public int compare(T2 o1, T2 o2) { - if (o1.get1() < o2.get1()) - return -1; - - if (o1.get1() > o2.get1()) - return 1; - - if (o1.get2() < o2.get2()) - return -1; - - if (o1.get2() > o2.get2()) - return 1; - - return 0; - } -} - diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterableComparator.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterableComparator.java new file mode 100644 index 0000000000000..33d78cdcd1a46 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterableComparator.java @@ -0,0 +1,51 @@ +/* + * 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.database; + +import java.io.Serializable; +import java.util.Comparator; +import org.apache.ignite.internal.util.typedef.T2; + +/** + * + */ +public class FullPageIdIterableComparator implements Comparator>, Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + static final FullPageIdIterableComparator INSTANCE = new FullPageIdIterableComparator(); + + /** {@inheritDoc} */ + @Override public int compare(T2 o1, T2 o2) { + if (o1.get1() < o2.get1()) + return -1; + + if (o1.get1() > o2.get1()) + return 1; + + if (o1.get2() < o2.get2()) + return -1; + + if (o1.get2() > o2.get2()) + return 1; + + return 0; + } +} + diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 99fbcff8f5544..b73b8b323a19e 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -2437,7 +2437,7 @@ private WriteCheckpointPages( * @param cacheId Cache id. * @param part Partition. */ - static void completeSavingAllocatedIndex( + public static void completeSavingAllocatedIndex( PageMemoryEx pageMem, IgniteWriteAheadLogManager wal, int cacheId, int part ) throws IgniteCheckedException { long pageId = getSuperPageId(pageMem, cacheId, part); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PageIdIterable.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PageIdIterable.java deleted file mode 100644 index a5891fb931957..0000000000000 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PageIdIterable.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apache.ignite.internal.processors.cache.database; - -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.pagemem.FullPageId; -import org.jetbrains.annotations.Nullable; - -/** - * - */ -public interface PageIdIterable extends Iterable { - /** */ - public boolean contains(FullPageId fullId) throws IgniteCheckedException; - - /** */ - @Nullable public FullPageId next(@Nullable FullPageId fullId); - - /** */ - public double progress(FullPageId curr); - - /** - * - */ - public boolean isEmpty(); -} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/cache/db/GridCacheOffheapManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/cache/db/GridCacheOffheapManager.java new file mode 100644 index 0000000000000..d56bc940163de --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/cache/db/GridCacheOffheapManager.java @@ -0,0 +1,1101 @@ +/* + * 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.database.cache.db; + +import java.util.Iterator; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdAllocator; +import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.pagemem.wal.WALIterator; +import org.apache.ignite.internal.pagemem.wal.WALPointer; +import org.apache.ignite.internal.pagemem.wal.record.DataEntry; +import org.apache.ignite.internal.pagemem.wal.record.DataRecord; +import org.apache.ignite.internal.pagemem.wal.record.WALRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateNextSnapshotId; +import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.CacheObject; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl; +import org.apache.ignite.internal.processors.cache.IgniteRebalanceIterator; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.database.DbCheckpointListener; +import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.database.MetaStore; +import org.apache.ignite.internal.processors.cache.database.MetadataStorage; +import org.apache.ignite.internal.processors.cache.database.RootPage; +import org.apache.ignite.internal.processors.cache.database.RowStore; +import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionMetaIO; +import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseListImpl; +import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.util.lang.GridCursor; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.T2; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiTuple; +import org.jetbrains.annotations.Nullable; + +/** + * Used when persistence enabled. + */ +public class GridCacheOffheapManager extends IgniteCacheOffheapManagerImpl implements DbCheckpointListener { + /** */ + private MetaStore metaStore; + + /** */ + private ReuseListImpl reuseList; + + /** {@inheritDoc} */ + @Override protected void initDataStructures() throws IgniteCheckedException { + Metas metas = getOrAllocateCacheMetas(); + + RootPage reuseListRoot = metas.reuseListRoot; + + reuseList = new ReuseListImpl(cctx.cacheId(), + cctx.name(), + cctx.memoryPolicy().pageMemory(), + cctx.shared().wal(), + reuseListRoot.pageId().pageId(), + reuseListRoot.isAllocated()); + + RootPage metastoreRoot = metas.treeRoot; + + metaStore = new MetadataStorage(cctx.memoryPolicy().pageMemory(), + cctx.shared().wal(), + globalRemoveId(), + cctx.cacheId(), + PageIdAllocator.INDEX_PARTITION, + PageIdAllocator.FLAG_IDX, + reuseList, + metastoreRoot.pageId().pageId(), + metastoreRoot.isAllocated()); + + if (cctx.shared().ttl().eagerTtlEnabled()) { + final String name = "PendingEntries"; + + RootPage pendingRootPage = metaStore.getOrAllocateForTree(name); + + pendingEntries = new PendingEntriesTree( + cctx, + name, + cctx.memoryPolicy().pageMemory(), + pendingRootPage.pageId().pageId(), + reuseList, + pendingRootPage.isAllocated() + ); + } + + ((GridCacheDatabaseSharedManager)cctx.shared().database()).addCheckpointListener(this); + } + + /** {@inheritDoc} */ + @Override protected CacheDataStore createCacheDataStore0(final int p) + throws IgniteCheckedException { + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)cctx.shared().database(); + + if (!cctx.allowFastEviction()) + dbMgr.cancelOrWaitPartitionDestroy(cctx, p); + + boolean exists = cctx.shared().pageStore() != null + && cctx.shared().pageStore().exists(cctx.cacheId(), p); + + return new GridCacheDataStore(p, exists); + } + + /** {@inheritDoc} */ + @Override public void onCheckpointBegin(Context ctx) throws IgniteCheckedException { + assert cctx.memoryPolicy().pageMemory() instanceof PageMemoryEx; + + reuseList.saveMetadata(); + + boolean metaWasUpdated = false; + + for (CacheDataStore store : partDataStores.values()) { + RowStore rowStore = store.rowStore(); + + if (rowStore == null) + continue; + + metaWasUpdated |= saveStoreMetadata(store, ctx, !metaWasUpdated, false); + } + } + + /** + * @param store Store to save metadata. + * @throws IgniteCheckedException If failed. + */ + private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean saveMeta, + boolean beforeDestroy) throws IgniteCheckedException { + RowStore rowStore0 = store.rowStore(); + + boolean beforeSnapshot = ctx != null && ctx.nextSnapshot(); + + boolean wasSaveToMeta = false; + + if (rowStore0 != null) { + FreeListImpl freeList = (FreeListImpl)rowStore0.freeList(); + + freeList.saveMetadata(); + + long updCntr = store.updateCounter(); + int size = store.size(); + long rmvId = globalRemoveId().get(); + + PageMemoryEx pageMem = (PageMemoryEx)cctx.memoryPolicy().pageMemory(); + IgniteWriteAheadLogManager wal = cctx.shared().wal(); + + if (size > 0 || updCntr > 0) { + int state = -1; + + if (beforeDestroy) + state = GridDhtPartitionState.EVICTED.ordinal(); + else { + // localPartition will not acquire writeLock here because create=false. + GridDhtLocalPartition part = cctx.topology().localPartition(store.partId(), + AffinityTopologyVersion.NONE, false); + + if (part != null && part.state() != GridDhtPartitionState.EVICTED) + state = part.state().ordinal(); + } + + // Do not save meta for evicted partitions on next checkpoints. + if (state == -1) + return false; + + int cacheId = cctx.cacheId(); + long partMetaId = pageMem.partitionMetaPageId(cacheId, store.partId()); + long partMetaPage = pageMem.acquirePage(cacheId, partMetaId); + + try { + long pageAddr = pageMem.writeLock(cacheId, partMetaId, partMetaPage); + + try { + PagePartitionMetaIO io = PageIO.getPageIO(pageAddr); + + io.setUpdateCounter(pageAddr, updCntr); + io.setGlobalRemoveId(pageAddr, rmvId); + io.setSize(pageAddr, size); + + io.setPartitionState(pageAddr, (byte)state); + + int pageCount; + + if (beforeSnapshot) { + pageCount = cctx.shared().pageStore().pages(cctx.cacheId(), store.partId()); + io.setCandidatePageCount(pageAddr, pageCount); + + if (saveMeta) { + long metaPageId = pageMem.metaPageId(cctx.cacheId()); + long metaPage = pageMem.acquirePage(cctx.cacheId(), metaPageId); + + try { + long metaPageAddr = pageMem.writeLock(cctx.cacheId(), metaPageId, metaPage); + + try { + long nextSnapshotTag = io.getNextSnapshotTag(metaPageAddr); + io.setNextSnapshotTag(metaPageAddr, nextSnapshotTag + 1); + + if (PageHandler.isWalDeltaRecordNeeded(pageMem, cctx.cacheId(), metaPageId, + metaPage, wal, null)) + wal.log(new MetaPageUpdateNextSnapshotId(cctx.cacheId(), metaPageId, + nextSnapshotTag + 1)); + + addPartition(ctx.partitionStatMap(), metaPageAddr, io, cctx.cacheId(), PageIdAllocator.INDEX_PARTITION, + cctx.kernalContext().cache().context().pageStore().pages(cacheId, PageIdAllocator.INDEX_PARTITION)); + } + finally { + pageMem.writeUnlock(cctx.cacheId(), metaPageId, metaPage, null, true); + } + } + finally { + pageMem.releasePage(cctx.cacheId(), metaPageId, metaPage); + } + + wasSaveToMeta = true; + } + + GridDhtPartitionMap partMap = cctx.topology().localPartitionMap(); + + if (partMap.containsKey(store.partId()) && + partMap.get(store.partId()) == GridDhtPartitionState.OWNING) + addPartition(ctx.partitionStatMap(), pageAddr, io, cctx.cacheId(), store.partId(), + cctx.kernalContext().cache().context().pageStore().pages(cctx.cacheId(), store.partId())); + } + else + pageCount = io.getCandidatePageCount(pageAddr); + + if (PageHandler.isWalDeltaRecordNeeded(pageMem, cacheId, partMetaId, partMetaPage, wal, null)) + wal.log(new MetaPageUpdatePartitionDataRecord( + cacheId, + partMetaId, + updCntr, + rmvId, + size, + (byte)state, + pageCount + )); + } + finally { + pageMem.writeUnlock(cacheId, partMetaId, partMetaPage, null, true); + } + } + finally { + pageMem.releasePage(cacheId, partMetaId, partMetaPage); + } + } + } + + return wasSaveToMeta; + } + + /** + * @param map Map to add values to. + * @param pageAddr page address + * @param io Page Meta IO + * @param cacheId Cache ID. + * @param partition Partition ID. + * @param pages Number of pages to add. + */ + private static void addPartition( + Map, T2> map, + long pageAddr, + PagePartitionMetaIO io, + int cacheId, + int partition, + int pages + ) { + if (pages <= 1) + return; + + assert PageIO.getPageId(pageAddr) != 0; + + int lastAllocatedIdx = io.getLastPageCount(pageAddr); + map.put(new T2<>(cacheId, partition), new T2<>(lastAllocatedIdx, pages)); + } + + /** {@inheritDoc} */ + @Override protected void destroyCacheDataStore0(CacheDataStore store) throws IgniteCheckedException { + cctx.shared().database().checkpointReadLock(); + + try { + int p = store.partId(); + + saveStoreMetadata(store, null, false, true); + + PageMemoryEx pageMemory = (PageMemoryEx)cctx.memoryPolicy().pageMemory(); + + int tag = pageMemory.invalidate(cctx.cacheId(), p); + + cctx.shared().pageStore().onPartitionDestroyed(cctx.cacheId(), p, tag); + } + finally { + cctx.shared().database().checkpointReadUnlock(); + } + } + + /** {@inheritDoc} */ + @Override public void onPartitionCounterUpdated(int part, long cntr) { + CacheDataStore store = partDataStores.get(part); + + assert store != null; + + long oldCnt = store.updateCounter(); + + if (oldCnt < cntr) + store.updateCounter(cntr); + } + + /** {@inheritDoc} */ + @Override public void onPartitionInitialCounterUpdated(int part, long cntr) { + CacheDataStore store = partDataStores.get(part); + + assert store != null; + + long oldCnt = store.initialUpdateCounter(); + + if (oldCnt < cntr) + store.updateInitialCounter(cntr); + } + + /** {@inheritDoc} */ + @Override public long lastUpdatedPartitionCounter(int part) { + return partDataStores.get(part).updateCounter(); + } + + /** {@inheritDoc} */ + @Override public RootPage rootPageForIndex(String idxName) throws IgniteCheckedException { + return metaStore.getOrAllocateForTree(idxName); + } + + /** {@inheritDoc} */ + @Override public void dropRootPageForIndex(String idxName) throws IgniteCheckedException { + metaStore.dropRootPage(idxName); + } + + /** {@inheritDoc} */ + @Override public ReuseList reuseListForIndex(String idxName) { + return reuseList; + } + + /** {@inheritDoc} */ + @Override protected void destroyCacheDataStructures() { + assert cctx.affinityNode(); + + ((GridCacheDatabaseSharedManager)cctx.shared().database()).removeCheckpointListener(this); + } + + /** + * @return Meta root pages info. + * @throws IgniteCheckedException If failed. + */ + private Metas getOrAllocateCacheMetas() throws IgniteCheckedException { + PageMemoryEx pageMem = (PageMemoryEx) cctx.memoryPolicy().pageMemory(); + IgniteWriteAheadLogManager wal = cctx.shared().wal(); + + int cacheId = cctx.cacheId(); + long metaId = pageMem.metaPageId(cacheId); + long metaPage = pageMem.acquirePage(cacheId, metaId); + try { + final long pageAddr = pageMem.writeLock(cacheId, metaId, metaPage); + + boolean allocated = false; + + try { + long metastoreRoot, reuseListRoot; + + if (PageIO.getType(pageAddr) != PageIO.T_META) { + PageMetaIO pageIO = PageMetaIO.VERSIONS.latest(); + + pageIO.initNewPage(pageAddr, metaId, pageMem.pageSize()); + + metastoreRoot = pageMem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX); + reuseListRoot = pageMem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX); + + pageIO.setTreeRoot(pageAddr, metastoreRoot); + pageIO.setReuseListRoot(pageAddr, reuseListRoot); + + if (PageHandler.isWalDeltaRecordNeeded(pageMem, cacheId, metaId, metaPage, wal, null)) + wal.log(new MetaPageInitRecord( + cacheId, + metaId, + pageIO.getType(), + pageIO.getVersion(), + metastoreRoot, + reuseListRoot + )); + + allocated = true; + } + else { + PageMetaIO pageIO = PageIO.getPageIO(pageAddr); + + metastoreRoot = pageIO.getTreeRoot(pageAddr); + reuseListRoot = pageIO.getReuseListRoot(pageAddr); + + assert reuseListRoot != 0L; + } + + return new Metas( + new RootPage(new FullPageId(metastoreRoot, cacheId), allocated), + new RootPage(new FullPageId(reuseListRoot, cacheId), allocated)); + } + finally { + pageMem.writeUnlock(cacheId, metaId, metaPage, null, allocated); + } + } + finally { + pageMem.releasePage(cacheId, metaId, metaPage); + } + } + + /** {@inheritDoc} */ + @Override public IgniteRebalanceIterator rebalanceIterator(int part, AffinityTopologyVersion topVer, + Long partCntrSince) throws IgniteCheckedException { + if (partCntrSince == null) + return super.rebalanceIterator(part, topVer, partCntrSince); + + GridCacheDatabaseSharedManager database = (GridCacheDatabaseSharedManager)cctx.shared().database(); + + try { + WALPointer startPtr = database.searchPartitionCounter(cctx, part, partCntrSince); + + if (startPtr == null) { + assert false : "partCntr=" + partCntrSince + ", reservations=" + S.toString(Map.class, database.reservedForPreloading()); + + return super.rebalanceIterator(part, topVer, partCntrSince); + } + + WALIterator it = cctx.shared().wal().replay(startPtr); + + return new RebalanceIteratorAdapter(cctx, it, part); + } + catch (IgniteCheckedException e) { + U.warn(log, "Failed to create WAL-based rebalance iterator (a full partition will transferred to a " + + "remote node) [part=" + part + ", partCntrSince=" + partCntrSince + ", err=" + e + ']'); + + return super.rebalanceIterator(part, topVer, partCntrSince); + } + } + + /** + * + */ + private static class RebalanceIteratorAdapter implements IgniteRebalanceIterator { + /** Cache context. */ + private GridCacheContext cctx; + + /** WAL iterator. */ + private WALIterator walIt; + + /** Partition to scan. */ + private int part; + + /** */ + private Iterator entryIt; + + /** */ + private CacheDataRow next; + + /** + * @param cctx Cache context. + * @param walIt WAL iterator. + * @param part Partition ID. + */ + private RebalanceIteratorAdapter(GridCacheContext cctx, WALIterator walIt, int part) { + this.cctx = cctx; + this.walIt = walIt; + this.part = part; + + advance(); + } + + /** {@inheritDoc} */ + @Override public boolean historical() { + return true; + } + + /** {@inheritDoc} */ + @Override public void close() throws IgniteCheckedException { + walIt.close(); + } + + /** {@inheritDoc} */ + @Override public boolean isClosed() { + return walIt.isClosed(); + } + + /** {@inheritDoc} */ + @Override public boolean hasNextX() { + return hasNext(); + } + + /** {@inheritDoc} */ + @Override public CacheDataRow nextX() throws IgniteCheckedException { + return next(); + } + + /** {@inheritDoc} */ + @Override public void removeX() throws IgniteCheckedException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public Iterator iterator() { + return this; + } + + /** {@inheritDoc} */ + @Override public boolean hasNext() { + return next != null; + } + + /** {@inheritDoc} */ + @Override public CacheDataRow next() { + if (next == null) + throw new NoSuchElementException(); + + CacheDataRow val = next; + + advance(); + + return val; + } + + /** {@inheritDoc} */ + @Override public void remove() { + throw new UnsupportedOperationException(); + } + + /** + * + */ + private void advance() { + next = null; + + while (true) { + if (entryIt != null) { + while (entryIt.hasNext()) { + DataEntry entry = entryIt.next(); + + if (entry.cacheId() == cctx.cacheId() && + entry.partitionId() == part) { + + next = new DataEntryRow(entry); + + return; + } + } + } + + entryIt = null; + + while (walIt.hasNext()) { + IgniteBiTuple rec = walIt.next(); + + if (rec.get2() instanceof DataRecord) { + DataRecord data = (DataRecord)rec.get2(); + + entryIt = data.writeEntries().iterator(); + // Move on to the next valid data entry. + + break; + } + } + + if (entryIt == null) + return; + } + } + } + + /** + * Data entry row. + */ + private static class DataEntryRow implements CacheDataRow { + /** */ + private final DataEntry entry; + + /** + * @param entry Data entry. + */ + private DataEntryRow(DataEntry entry) { + this.entry = entry; + } + + /** {@inheritDoc} */ + @Override public KeyCacheObject key() { + return entry.key(); + } + + /** {@inheritDoc} */ + @Override public void key(KeyCacheObject key) { + throw new IllegalStateException(); + } + + /** {@inheritDoc} */ + @Override public CacheObject value() { + return entry.value(); + } + + /** {@inheritDoc} */ + @Override public GridCacheVersion version() { + return entry.writeVersion(); + } + + /** {@inheritDoc} */ + @Override public long expireTime() { + return entry.expireTime(); + } + + /** {@inheritDoc} */ + @Override public int partition() { + return entry.partitionId(); + } + + /** {@inheritDoc} */ + @Override public long link() { + return 0; + } + + /** {@inheritDoc} */ + @Override public void link(long link) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public int hash() { + return entry.key().hashCode(); + } + + /** {@inheritDoc} */ + @Override public int cacheId() { + return entry.cacheId(); + } + } + + /** + * + */ + private static class Metas { + /** */ + @GridToStringInclude + private final RootPage reuseListRoot; + + /** */ + @GridToStringInclude + private final RootPage treeRoot; + + /** + * @param treeRoot Metadata storage root. + * @param reuseListRoot Reuse list root. + */ + Metas(RootPage treeRoot, RootPage reuseListRoot) { + this.treeRoot = treeRoot; + this.reuseListRoot = reuseListRoot; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(Metas.class, this); + } + } + + /** + * + */ + private class GridCacheDataStore implements CacheDataStore { + /** */ + private final int partId; + + /** */ + private String name; + + /** */ + private volatile FreeListImpl freeList; + + /** */ + private volatile CacheDataStore delegate; + + /** */ + private final boolean exists; + + /** */ + private final AtomicBoolean init = new AtomicBoolean(); + + /** */ + private final CountDownLatch latch = new CountDownLatch(1); + + /** + * @param partId Partition. + * @param exists {@code True} if store for this index exists. + */ + private GridCacheDataStore(int partId, boolean exists) { + this.partId = partId; + this.exists = exists; + + name = treeName(partId); + } + + /** + * @return Store delegate. + * @throws IgniteCheckedException If failed. + */ + private CacheDataStore init0(boolean checkExists) throws IgniteCheckedException { + CacheDataStore delegate0 = delegate; + + if (delegate0 != null) + return delegate0; + + if (checkExists) { + if (!exists) + return null; + } + + IgniteCacheDatabaseSharedManager dbMgr = cctx.shared().database(); + + dbMgr.checkpointReadLock(); + + if (init.compareAndSet(false, true)) { + try { + Metas metas = getOrAllocatePartitionMetas(); + + RootPage reuseRoot = metas.reuseListRoot; + + freeList = new FreeListImpl( + cctx.cacheId(), + cctx.name() + "-" + partId, + (MemoryMetricsImpl)cctx.memoryPolicy().memoryMetrics(), + cctx.memoryPolicy(), + null, + cctx.shared().wal(), + reuseRoot.pageId().pageId(), + reuseRoot.isAllocated()) { + @Override protected long allocatePageNoReuse() throws IgniteCheckedException { + return pageMem.allocatePage(cacheId, partId, PageIdAllocator.FLAG_DATA); + } + }; + + CacheDataRowStore rowStore = new CacheDataRowStore(cctx, freeList, partId); + + RootPage treeRoot = metas.treeRoot; + + CacheDataTree dataTree = new CacheDataTree( + name, + freeList, + rowStore, + cctx, + treeRoot.pageId().pageId(), + treeRoot.isAllocated()) { + @Override protected long allocatePageNoReuse() throws IgniteCheckedException { + return pageMem.allocatePage(cacheId, partId, PageIdAllocator.FLAG_DATA); + } + }; + + PageMemoryEx pageMem = (PageMemoryEx)cctx.memoryPolicy().pageMemory(); + + delegate0 = new CacheDataStoreImpl(partId, name, rowStore, dataTree); + + int cacheId = cctx.cacheId(); + long partMetaId = pageMem.partitionMetaPageId(cacheId, partId); + long partMetaPage = pageMem.acquirePage(cacheId, partMetaId); + try { + long pageAddr = pageMem.readLock(cacheId, partMetaId, partMetaPage); + + try { + if (PageIO.getType(pageAddr) != 0) { + PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.latest(); + + delegate0.init(io.getSize(pageAddr), io.getUpdateCounter(pageAddr)); + + cctx.offheap().globalRemoveId().setIfGreater(io.getGlobalRemoveId(pageAddr)); + } + } + finally { + pageMem.readUnlock(cacheId, partMetaId, partMetaPage); + } + } + finally { + pageMem.releasePage(cacheId, partMetaId, partMetaPage); + } + + delegate = delegate0; + } + finally { + latch.countDown(); + + dbMgr.checkpointReadUnlock(); + } + } + else { + dbMgr.checkpointReadUnlock(); + + U.await(latch); + + delegate0 = delegate; + + if (delegate0 == null) + throw new IgniteCheckedException("Cache store initialization failed."); + } + + return delegate0; + } + + /** + * @return Partition metas. + */ + private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { + PageMemoryEx pageMem = (PageMemoryEx)cctx.memoryPolicy().pageMemory(); + IgniteWriteAheadLogManager wal = cctx.shared().wal(); + + int cacheId = cctx.cacheId(); + long partMetaId = pageMem.partitionMetaPageId(cacheId, partId); + long partMetaPage = pageMem.acquirePage(cacheId, partMetaId); + try { + boolean allocated = false; + long pageAddr = pageMem.writeLock(cacheId, partMetaId, partMetaPage); + + try { + long treeRoot, reuseListRoot; + + // Initialize new page. + if (PageIO.getType(pageAddr) != PageIO.T_PART_META) { + PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.latest(); + + io.initNewPage(pageAddr, partMetaId, pageMem.pageSize()); + + treeRoot = pageMem.allocatePage(cacheId, partId, PageMemory.FLAG_DATA); + reuseListRoot = pageMem.allocatePage(cacheId, partId, PageMemory.FLAG_DATA); + + assert PageIdUtils.flag(treeRoot) == PageMemory.FLAG_DATA; + assert PageIdUtils.flag(reuseListRoot) == PageMemory.FLAG_DATA; + + io.setTreeRoot(pageAddr, treeRoot); + io.setReuseListRoot(pageAddr, reuseListRoot); + + if (PageHandler.isWalDeltaRecordNeeded(pageMem, cacheId, partMetaId, partMetaPage, wal, null)) + wal.log(new MetaPageInitRecord( + cctx.cacheId(), + partMetaId, + io.getType(), + io.getVersion(), + treeRoot, + reuseListRoot + )); + + allocated = true; + } + else { + PagePartitionMetaIO io = PageIO.getPageIO(pageAddr); + + treeRoot = io.getTreeRoot(pageAddr); + reuseListRoot = io.getReuseListRoot(pageAddr); + + assert PageIdUtils.flag(treeRoot) == PageMemory.FLAG_DATA : + U.hexLong(treeRoot) + ", part=" + partId + ", cacheId=" + cacheId; + assert PageIdUtils.flag(reuseListRoot) == PageMemory.FLAG_DATA : + U.hexLong(reuseListRoot) + ", part=" + partId + ", cacheId=" + cacheId; + } + + return new Metas( + new RootPage(new FullPageId(treeRoot, cacheId), allocated), + new RootPage(new FullPageId(reuseListRoot, cacheId), allocated)); + } + finally { + pageMem.writeUnlock(cacheId, partMetaId, partMetaPage, null, allocated); + } + } + finally { + pageMem.releasePage(cacheId, partMetaId, partMetaPage); + } + } + + /** {@inheritDoc} */ + @Override public int partId() { + return partId; + } + + /** {@inheritDoc} */ + @Override public String name() { + return name; + } + + /** {@inheritDoc} */ + @Override public RowStore rowStore() { + CacheDataStore delegate0 = delegate; + + return delegate0 == null ? null : delegate0.rowStore(); + } + + /** {@inheritDoc} */ + @Override public int size() { + try { + CacheDataStore delegate0 = init0(true); + + return delegate0 == null ? 0 : delegate0.size(); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + } + + /** {@inheritDoc} */ + @Override public long updateCounter() { + try { + CacheDataStore delegate0 = init0(true); + + return delegate0 == null ? 0 : delegate0.updateCounter(); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + } + + /** {@inheritDoc} */ + @Override public void init(long size, long updCntr) { + throw new IllegalStateException("Should be never called."); + } + + /** {@inheritDoc} */ + @Override public void updateCounter(long val) { + try { + CacheDataStore delegate0 = init0(true); + + if (delegate0 != null) + delegate0.updateCounter(val); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + } + + /** {@inheritDoc} */ + @Override public long nextUpdateCounter() { + try { + CacheDataStore delegate0 = init0(false); + + return delegate0 == null ? 0 : delegate0.nextUpdateCounter(); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + } + + /** {@inheritDoc} */ + @Override public Long initialUpdateCounter() { + try { + CacheDataStore delegate0 = init0(true); + + return delegate0 == null ? 0 : delegate0.initialUpdateCounter(); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + } + + /** {@inheritDoc} */ + @Override public void updateInitialCounter(long cntr) { + try { + CacheDataStore delegate0 = init0(true); + + if (delegate0 != null) + delegate0.updateInitialCounter(cntr); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + } + + /** {@inheritDoc} */ + @Override public void update( + KeyCacheObject key, + CacheObject val, + GridCacheVersion ver, + long expireTime, + @Nullable CacheDataRow oldRow + ) throws IgniteCheckedException { + CacheDataStore delegate = init0(false); + + delegate.update(key, val, ver, expireTime, oldRow); + } + + /** {@inheritDoc} */ + @Override public void updateIndexes(KeyCacheObject key) throws IgniteCheckedException { + CacheDataStore delegate = init0(false); + + delegate.updateIndexes(key); + } + + /** {@inheritDoc} */ + @Override public CacheDataRow createRow(KeyCacheObject key, + CacheObject val, + GridCacheVersion ver, + long expireTime, + @Nullable CacheDataRow oldRow) throws IgniteCheckedException { + CacheDataStore delegate = init0(false); + + return delegate.createRow(key, val, ver, expireTime, oldRow); + } + + /** {@inheritDoc} */ + @Override public void invoke(KeyCacheObject key, OffheapInvokeClosure c) throws IgniteCheckedException { + CacheDataStore delegate = init0(false); + + delegate.invoke(key, c); + } + + /** {@inheritDoc} */ + @Override public void remove(KeyCacheObject key, int partId) throws IgniteCheckedException { + CacheDataStore delegate = init0(false); + + delegate.remove(key, partId); + } + + /** {@inheritDoc} */ + @Override public CacheDataRow find(KeyCacheObject key) throws IgniteCheckedException { + CacheDataStore delegate = init0(true); + + if (delegate != null) + return delegate.find(key); + + return null; + } + + /** {@inheritDoc} */ + @Override public GridCursor cursor() throws IgniteCheckedException { + CacheDataStore delegate = init0(true); + + if (delegate != null) + return delegate.cursor(); + + return EMPTY_CURSOR; + } + + /** {@inheritDoc} */ + @Override public GridCursor cursor(KeyCacheObject lower, + KeyCacheObject upper) throws IgniteCheckedException { + CacheDataStore delegate = init0(true); + + if (delegate != null) + return delegate.cursor(lower, upper); + + return EMPTY_CURSOR; + } + + /** {@inheritDoc} */ + @Override public void destroy() throws IgniteCheckedException { + // No need to destroy delegate. + } + } + + /** + * + */ + private static final GridCursor EMPTY_CURSOR = new GridCursor() { + /** {@inheritDoc} */ + @Override public boolean next() { + return false; + } + + /** {@inheritDoc} */ + @Override public CacheDataRow get() { + return null; + } + }; +} From 8f85be55769f18c4d5ff2182dc1acb88c7cdd1a9 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Thu, 4 May 2017 17:38:44 +0300 Subject: [PATCH 144/311] header removed --- .../database/IgniteDbMultiNodePutGetRestartSelfTest.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java index 4bc05f7fad7c5..e236b8c45e386 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java @@ -1,12 +1,3 @@ -/* - * Copyright (C) GridGain Systems. All Rights Reserved. - * _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - package org.apache.ignite.cache.database; import java.io.File; From 9a0ad843f20d82e800cd9934ea1ca19f88d92db9 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Thu, 4 May 2017 17:40:22 +0300 Subject: [PATCH 145/311] ignite-12163 header revert --- .../cache/db/GridCacheOffheapManager.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/cache/db/GridCacheOffheapManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/cache/db/GridCacheOffheapManager.java index d56bc940163de..c2b44d8bde3fd 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/cache/db/GridCacheOffheapManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/cache/db/GridCacheOffheapManager.java @@ -1,20 +1,3 @@ -/* - * 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.database.cache.db; import java.util.Iterator; From 4d55ba1202f5bf1ab32ad9e840b4a6144dba1295 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Thu, 4 May 2017 19:13:49 +0300 Subject: [PATCH 146/311] changes to CacheProcessor, first test passing (although assertion exception in logs) --- .../configuration/IgniteConfiguration.java | 1 + .../processors/cache/GridCacheProcessor.java | 54 ++++++++++++++++--- .../GridCacheDatabaseSharedManager.java | 8 ++- .../db => }/GridCacheOffheapManager.java | 19 +------ ...gniteDbMultiNodePutGetRestartSelfTest.java | 4 +- 5 files changed, 54 insertions(+), 32 deletions(-) rename modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/{cache/db => }/GridCacheOffheapManager.java (97%) diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index 97fe3121d16af..0b87b7b770534 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -485,6 +485,7 @@ public IgniteConfiguration(IgniteConfiguration cfg) { atomicCfg = cfg.getAtomicConfiguration(); binaryCfg = cfg.getBinaryConfiguration(); memCfg = cfg.getMemoryConfiguration(); + pstCfg = cfg.getPersistenceConfiguration(); cacheCfg = cfg.getCacheConfiguration(); cacheKeyCfg = cfg.getCacheKeyConfiguration(); cacheSanityCheckEnabled = cfg.isCacheSanityCheckEnabled(); 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 1bdada24867bf..2873ea9f10f49 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 @@ -18,6 +18,7 @@ package org.apache.ignite.internal.processors.cache; import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -57,6 +58,7 @@ import org.apache.ignite.configuration.FileSystemConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.NearCacheConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; import org.apache.ignite.configuration.TransactionConfiguration; import org.apache.ignite.events.EventType; import org.apache.ignite.internal.GridKernalContext; @@ -1487,7 +1489,25 @@ private GridCacheContext createCache(CacheConfiguration cfg, CacheConflictResolutionManager rslvrMgr = pluginMgr.createComponent(CacheConflictResolutionManager.class); GridCacheDrManager drMgr = pluginMgr.createComponent(GridCacheDrManager.class); CacheStoreManager storeMgr = pluginMgr.createComponent(CacheStoreManager.class); - IgniteCacheOffheapManager offheapMgr = pluginMgr.createComponent(IgniteCacheOffheapManager.class); + + IgniteCacheOffheapManager offheapMgr; + + if (ctx.config().getPersistenceConfiguration() != null) { + ClassLoader clsLdr = U.gridClassLoader(); + + try { + offheapMgr = (IgniteCacheOffheapManager) clsLdr + .loadClass("org.apache.ignite.internal.processors.cache.database.GridCacheOffheapManager") + .getConstructor() + .newInstance(); + } + catch (Exception e) { + throw new IgniteCheckedException("Failed to initialize offheap manager", e); + } + } + else + offheapMgr = new IgniteCacheOffheapManagerImpl(); + storeMgr.initialize(cfgStore, sesHolders); @@ -2125,9 +2145,34 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, GridCacheDeploymentManager depMgr = new GridCacheDeploymentManager(); GridCachePartitionExchangeManager exchMgr = new GridCachePartitionExchangeManager(); - IgniteCacheDatabaseSharedManager dbMgr = ctx.plugins().createComponent(IgniteCacheDatabaseSharedManager.class); + IgniteCacheDatabaseSharedManager dbMgr; + IgnitePageStoreManager pageStoreMgr = null; + IgniteWriteAheadLogManager walMgr = null; + + if (ctx.config().getPersistenceConfiguration() != null) { + ClassLoader clsLdr = U.gridClassLoader(); - if (dbMgr == null) + try { + dbMgr = (IgniteCacheDatabaseSharedManager) clsLdr + .loadClass("org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager") + .getConstructor(IgniteConfiguration.class) + .newInstance(ctx.config()); + + pageStoreMgr = (IgnitePageStoreManager) clsLdr + .loadClass("org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager") + .getConstructor(IgniteConfiguration.class) + .newInstance(ctx.config()); + + walMgr = (IgniteWriteAheadLogManager) clsLdr + .loadClass("org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager") + .getConstructor(IgniteConfiguration.class) + .newInstance(ctx.config()); + } + catch (Exception e) { + throw new IgniteCheckedException("Failed to initialize persistent store", e); + } + } + else dbMgr = new IgniteCacheDatabaseSharedManager(); IgniteCacheSnapshotManager snpMgr = ctx.plugins().createComponent(IgniteCacheSnapshotManager.class); @@ -2135,9 +2180,6 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, if (snpMgr == null) snpMgr = new IgniteCacheSnapshotManager(); - IgnitePageStoreManager pageStoreMgr = ctx.plugins().createComponent(IgnitePageStoreManager.class); - IgniteWriteAheadLogManager walMgr = ctx.plugins().createComponent(IgniteWriteAheadLogManager.class); - GridCacheIoManager ioMgr = new GridCacheIoManager(); CacheAffinitySharedManager topMgr = new CacheAffinitySharedManager(); GridCacheSharedTtlCleanupManager ttl = new GridCacheSharedTtlCleanupManager(); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index b73b8b323a19e..0f0af7f1bb253 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -266,7 +266,7 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan private final ConcurrentMap, T2> reservedForPreloading = new ConcurrentHashMap<>(); /** Snapshot manager. */ - private final IgniteCacheSnapshotManager snapshotMgr; + private IgniteCacheSnapshotManager snapshotMgr; /** * @param cfg Ignite configuration. @@ -292,8 +292,6 @@ public GridCacheDatabaseSharedManager(IgniteConfiguration cfg) { return tmpWriteBuf; } }; - - snapshotMgr = cctx.snapshot(); } /** @@ -327,6 +325,8 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { /** {@inheritDoc} */ @Override protected void start0() throws IgniteCheckedException { + snapshotMgr = cctx.snapshot(); + initDataBase(); if (!cctx.kernalContext().clientNode()) { @@ -343,8 +343,6 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { fileLockHolder = new FileLockHolder(storeMgr.workDir().getPath(), cctx.kernalContext(), log); } - - snapshotMgr.start(cctx); } /** diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/cache/db/GridCacheOffheapManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java similarity index 97% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/cache/db/GridCacheOffheapManager.java rename to modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java index d56bc940163de..95b8abd3a83ae 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/cache/db/GridCacheOffheapManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java @@ -1,21 +1,4 @@ -/* - * 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.database.cache.db; +package org.apache.ignite.internal.processors.cache.database; import java.util.Iterator; import java.util.Map; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java index e236b8c45e386..c999df53d4260 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java @@ -66,9 +66,7 @@ public class IgniteDbMultiNodePutGetRestartSelfTest extends GridCommonAbstractTe cfg.setCacheConfiguration(ccfg); - PersistenceConfiguration dbCfg = new PersistenceConfiguration(); - - cfg.setPersistenceConfiguration(dbCfg); + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); From c263ccc94ded32d87ecddb28312dd69978f1f1a3 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 5 May 2017 13:33:28 +0300 Subject: [PATCH 147/311] ignite-12163 add pds tests --- .../FullPageIdIterableComparator.java | 2 +- .../cache/database/file/FilePageStore.java | 12 +- ...istentStoreAtomicCacheRebalancingTest.java | 23 + ...tentStoreCacheRebalancingAbstractTest.java | 578 ++++++++ ...earCachePutGetWithPersistenceSelfTest.java | 39 + ...sistentStoreContinuousRestartSelfTest.java | 247 ++++ ...reDynamicCacheWithPersistenceSelfTest.java | 132 ++ ...ntStoreMultiNodePutGetRestartSelfTest.java | 236 +++ ...gnitePersistentStorePageSizesSelfTest.java | 138 ++ ...tStoreRecoveryAfterFileCorruptionTest.java | 328 +++++ ...tStoreRemoveDuringRebalancingSelfTest.java | 124 ++ ...reSingleNodePutGetPersistenceSelfTest.java | 39 + ...WithIndexingPutGetPersistenceSelfTest.java | 39 + ...PersistentStoreTxCacheRebalancingTest.java | 44 + .../IgnitePersistentStoreWalTlbSelfTest.java | 101 ++ ...eEvictionDuringPartitionClearSelfTest.java | 155 ++ ...gniteDbMultiNodePutGetRestartSelfTest.java | 22 +- .../db/IgniteDbPageEvictionSelfTest.java | 220 +++ .../IgniteDbWholeClusterRestartSelfTest.java | 141 ++ .../RebalancingOnNotStableTopologyTest.java | 196 +++ .../database/db/TransactionsHangTest.java | 286 ++++ ...niteCachePageStoreIntegrationSelfTest.java | 269 ++++ .../IgniteNoActualWalHistorySelfTest.java | 199 +++ ...IgniteWalDirectoriesConfigurationTest.java | 37 + .../IgniteWalHistoryReservationsSelfTest.java | 357 +++++ .../db/file/IgniteWalRecoverySelfTest.java | 1266 +++++++++++++++++ .../IgniteWalRecoverySeveralRestartsTest.java | 332 +++++ ...PageStoreCheckpointSimulationSelfTest.java | 985 +++++++++++++ .../db/file/PageStoreEvictionSelfTest.java | 275 ++++ .../file/WalRecoveryTxLogicalRecordsTest.java | 931 ++++++++++++ .../db/wal/crc/IgniteDataIntegrityTests.java | 120 ++ ...usTreeReuseListPageMemoryImplSelfTest.java | 89 ++ ...lusTreeSelfTestPageMemoryImplSelfTest.java | 88 ++ ...MetadataStoragePageMemoryImplSelfTest.java | 80 ++ .../pagemem/NoOpPageStoreManager.java | 179 +++ .../database/pagemem/NoOpWALManager.java | 106 ++ .../pagemem/PageMemoryImplNoLoadSelfTest.java | 76 + .../pagemem/PageMemoryImplReloadSelfTest.java | 354 +++++ .../database/pagemem/PageMemoryImplTest.java | 96 ++ .../GridChangeGlobalStateAbstractTest.java | 348 +++++ .../GridChangeGlobalStateCacheTest.java | 151 ++ ...GridChangeGlobalStateDataStreamerTest.java | 95 ++ ...ridChangeGlobalStateDataStructureTest.java | 261 ++++ .../GridChangeGlobalStateFailOverTest.java | 336 +++++ .../GridChangeGlobalStateServiceTest.java | 85 ++ .../GridChangeGlobalStateSuite.java | 24 + .../GridChangeGlobalStateTest.java | 694 +++++++++ .../extended/GridActivateExtensionTest.java | 221 +++ .../GridActivationAtomicCacheSuit.java | 62 + .../GridActivationCacheAbstractTestSuit.java | 91 ++ .../GridActivationLocalAndNearCacheSuit.java | 30 + .../GridActivationPartitionedCacheSuit.java | 63 + .../GridActivationReplicatedCacheSuit.java | 46 + .../IgnitePersistentStoreTestSuit2.java | 60 + .../IgnitePersistentStoreTestSuite.java | 75 + 55 files changed, 11563 insertions(+), 20 deletions(-) create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreAtomicCacheRebalancingTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java rename modules/pds/src/test/java/org/apache/ignite/cache/database/{ => db}/IgniteDbMultiNodePutGetRestartSelfTest.java (92%) create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalDirectoriesConfigurationTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/crc/IgniteDataIntegrityTests.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplReloadSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateCacheTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateSuite.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationAtomicCacheSuit.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationCacheAbstractTestSuit.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationPartitionedCacheSuit.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationReplicatedCacheSuit.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuit2.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuite.java diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterableComparator.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterableComparator.java index 33d78cdcd1a46..8e2afde4f43f1 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterableComparator.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterableComparator.java @@ -29,7 +29,7 @@ public class FullPageIdIterableComparator implements Comparator o1, T2 o2) { diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java index 02fa6b918a1a5..70278da270ead 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java @@ -419,9 +419,6 @@ private void init() throws IgniteCheckedException { assert pageBuf.capacity() == pageSize; assert pageBuf.position() == 0; assert pageBuf.order() == ByteOrder.nativeOrder(); - - int len = pageSize; - assert PageIO.getCrc(pageBuf) == 0 : U.hexLong(pageId); int crc32 = skipCrc ? 0 : PureJavaCrc32.calcCrc32(pageBuf, pageSize); @@ -430,6 +427,8 @@ private void init() throws IgniteCheckedException { pageBuf.position(0); + int len = pageSize; + do { int n = ch.write(pageBuf, off); @@ -510,11 +509,4 @@ private long allocPage() { return (int)(allocated.get() / pageSize); } - - /** - * Visible for testing - */ - FileChannel getCh() { - return ch; - } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreAtomicCacheRebalancingTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreAtomicCacheRebalancingTest.java new file mode 100644 index 0000000000000..8f4dc7ef2c5e7 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreAtomicCacheRebalancingTest.java @@ -0,0 +1,23 @@ +package org.apache.ignite.cache.database; + +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.configuration.CacheConfiguration; + +/** + * + */ +public class IgnitePersistentStoreAtomicCacheRebalancingTest extends IgnitePersistentStoreCacheRebalancingAbstractTest { + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String cacheName) { + CacheConfiguration ccfg = new CacheConfiguration(cacheName); + + ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setBackups(1); + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + + return ccfg; + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java new file mode 100644 index 0000000000000..c941a5cf4ebe0 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -0,0 +1,578 @@ +package org.apache.ignite.cache.database; + +import java.io.File; +import java.io.Serializable; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.QueryIndex; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.events.CacheRebalancingEvent; +import org.apache.ignite.events.EventType; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.G; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiPredicate; +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 org.apache.ignite.transactions.Transaction; + +/** + * Test for rebalancing and persistence integration. + */ +public abstract class IgnitePersistentStoreCacheRebalancingAbstractTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + protected boolean explicitTx; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg1 = cacheConfiguration(null); + ccfg1.setBackups(1); + ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + + CacheConfiguration ccfg2 = cacheConfiguration("indexed"); + ccfg2.setBackups(1); + ccfg2.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + + QueryEntity qryEntity = new QueryEntity(Integer.class.getName(), TestValue.class.getName()); + + LinkedHashMap fields = new LinkedHashMap<>(); + + fields.put("v1", Integer.class.getName()); + fields.put("v2", Integer.class.getName()); + + qryEntity.setFields(fields); + + QueryIndex qryIdx = new QueryIndex("v1", true); + + qryEntity.setIndexes(Collections.singleton(qryIdx)); + + ccfg2.setQueryEntities(Collections.singleton(qryEntity)); + + cfg.setCacheConfiguration(ccfg1, ccfg2); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); + dbCfg.setPageSize(1024); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(100 * 1024 * 1024); + memPlcCfg.setSwapFilePath("db"); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return 20 * 60 * 1000; + } + + /** + * @param cacheName Cache name. + * @return Cache configuration. + */ + protected abstract CacheConfiguration cacheConfiguration(String cacheName); + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + G.stopAll(true); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + U.delete(new File(U.getIgniteHome(), "db")); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + G.stopAll(true); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + U.delete(new File(U.getIgniteHome(), "db")); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + } + + /** + * Test that outdated partitions on restarted nodes are correctly replaced with newer versions. + * + * @throws Exception If fails. + */ + public void testRebalancingOnRestart() throws Exception { + Ignite ignite0 = startGrid(0); + + startGrid(1); + + IgniteEx ignite2 = startGrid(2); + + awaitPartitionMapExchange(); + + IgniteCache cache1 = ignite0.cache(null); + + for (int i = 0; i < 5000; i++) + cache1.put(i, i); + + ignite2.close(); + + awaitPartitionMapExchange(); + + ignite0.resetLostPartitions(Collections.singletonList(cache1.getName())); + + assert cache1.lostPartitions().isEmpty(); + + for (int i = 0; i < 5000; i++) + cache1.put(i, i * 2); + + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + + info(">>> Done puts..."); + + ignite2 = startGrid(2); + + awaitPartitionMapExchange(); + + IgniteCache cache3 = ignite2.cache(null); + + for (int i = 0; i < 100; i++) + assertEquals(String.valueOf(i), (Integer)(i * 2), cache3.get(i)); + } + + /** + * Test that outdated partitions on restarted nodes are correctly replaced with newer versions. + * + * @throws Exception If fails. + */ + public void testRebalancingOnRestartAfterCheckpoint() throws Exception { + IgniteEx ignite0 = startGrid(0); + + IgniteEx ignite1 = startGrid(1); + + IgniteEx ignite2 = startGrid(2); + IgniteEx ignite3 = startGrid(3); + + ignite0.cache(null).rebalance().get(); + ignite1.cache(null).rebalance().get(); + ignite2.cache(null).rebalance().get(); + ignite3.cache(null).rebalance().get(); + + awaitPartitionMapExchange(); + + IgniteCache cache1 = ignite0.cache(null); + + for (int i = 0; i < 1000; i++) + cache1.put(i, i); + + ignite0.context().cache().context().database().waitForCheckpoint("test"); + ignite1.context().cache().context().database().waitForCheckpoint("test"); + + info("++++++++++ After checkpoint"); + + ignite2.close(); + ignite3.close(); + + awaitPartitionMapExchange(); + + ignite0.resetLostPartitions(Collections.singletonList(cache1.getName())); + + assert cache1.lostPartitions().isEmpty(); + + for (int i = 0; i < 1000; i++) + cache1.put(i, i * 2); + + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + + info(">>> Done puts..."); + + ignite2 = startGrid(2); + ignite3 = startGrid(3); + + ignite2.cache(null).rebalance().get(); + ignite3.cache(null).rebalance().get(); + + awaitPartitionMapExchange(); + + IgniteCache cache2 = ignite2.cache(null); + IgniteCache cache3 = ignite3.cache(null); + + for (int i = 0; i < 100; i++) { + assertEquals(String.valueOf(i), (Integer)(i * 2), cache2.get(i)); + assertEquals(String.valueOf(i), (Integer)(i * 2), cache3.get(i)); + } + } + + /** + * Test that up-to-date partitions aren't rebalanced after cluster restarts gracefully. + * + * @throws Exception If fails. + */ + public void testNoRebalancingOnRestartDeactivated() throws Exception { + fail(); + IgniteEx ignite1 = (IgniteEx)G.start(getConfiguration("test1")); + IgniteEx ignite2 = (IgniteEx)G.start(getConfiguration("test2")); + IgniteEx ignite3 = (IgniteEx)G.start(getConfiguration("test3")); + IgniteEx ignite4 = (IgniteEx)G.start(getConfiguration("test4")); + + awaitPartitionMapExchange(); + + IgniteCache cache1 = ignite1.cache(null); + + final Collection parts = new HashSet<>(); + + for (int i = 0; i < 100; i++) { + cache1.put(i, i); + parts.add(ignite1.affinity(null).partition(i)); + } + + ignite1.active(false); + + ignite1.close(); + ignite2.close(); + ignite3.close(); + ignite4.close(); + + final AtomicInteger evtCnt = new AtomicInteger(); + + ignite1 = (IgniteEx)G.start(getConfiguration("test1")); + + cache1 = ignite1.cache(null); + + ignite1.active(false); + + ignite1.events().remoteListen(new IgniteBiPredicate() { + @Override public boolean apply(UUID uuid, CacheRebalancingEvent evt) { + if (evt.cacheName() == null && parts.contains(evt.partition())) + evtCnt.incrementAndGet(); + + return true; + } + }, null, EventType.EVT_CACHE_REBALANCE_PART_LOADED); + + ignite2 = (IgniteEx)G.start(getConfiguration("test2")); + ignite3 = (IgniteEx)G.start(getConfiguration("test3")); + ignite4 = (IgniteEx)G.start(getConfiguration("test4")); + + ignite1.active(true); + + awaitPartitionMapExchange(); + + assert evtCnt.get() == 0 : evtCnt.get(); + + IgniteCache cache2 = ignite2.cache(null); + IgniteCache cache3 = ignite3.cache(null); + IgniteCache cache4 = ignite4.cache(null); + + for (int i = 0; i < 100; i++) { + assert cache1.get(i).equals(i); + assert cache2.get(i).equals(i); + assert cache3.get(i).equals(i); + assert cache4.get(i).equals(i); + } + } + + /** + * Test that all data is correctly restored after non-graceful restart. + * + * @throws Exception If fails. + */ + public void testDataCorrectnessAfterRestart() throws Exception { + IgniteEx ignite1 = (IgniteEx)G.start(getConfiguration("test1")); + IgniteEx ignite2 = (IgniteEx)G.start(getConfiguration("test2")); + IgniteEx ignite3 = (IgniteEx)G.start(getConfiguration("test3")); + IgniteEx ignite4 = (IgniteEx)G.start(getConfiguration("test4")); + + awaitPartitionMapExchange(); + + IgniteCache cache1 = ignite1.cache(null); + + for (int i = 0; i < 100; i++) + cache1.put(i, i); + + ignite1.close(); + ignite2.close(); + ignite3.close(); + ignite4.close(); + + ignite1 = (IgniteEx)G.start(getConfiguration("test1")); + ignite2 = (IgniteEx)G.start(getConfiguration("test2")); + ignite3 = (IgniteEx)G.start(getConfiguration("test3")); + ignite4 = (IgniteEx)G.start(getConfiguration("test4")); + + awaitPartitionMapExchange(); + + cache1 = ignite1.cache(null); + IgniteCache cache2 = ignite2.cache(null); + IgniteCache cache3 = ignite3.cache(null); + IgniteCache cache4 = ignite4.cache(null); + + for (int i = 0; i < 100; i++) { + assert cache1.get(i).equals(i); + assert cache2.get(i).equals(i); + assert cache3.get(i).equals(i); + assert cache4.get(i).equals(i); + } + } + + /** + * Test that partitions are marked as lost when all owners leave cluster, but recover after nodes rejoin. + * + * @throws Exception If fails. + */ + public void testPartitionLossAndRecover() throws Exception { + Ignite ignite1 = G.start(getConfiguration("test1")); + Ignite ignite2 = G.start(getConfiguration("test2")); + IgniteEx ignite3 = (IgniteEx)G.start(getConfiguration("test3")); + IgniteEx ignite4 = (IgniteEx)G.start(getConfiguration("test4")); + + awaitPartitionMapExchange(); + + IgniteCache cache1 = ignite1.cache(null); + + for (int i = 0; i < 100; i++) + cache1.put(i, i); + + ignite1.active(false); + + ignite3.close(); + ignite4.close(); + + ignite1.active(true); + + awaitPartitionMapExchange(); + + assert !cache1.lostPartitions().isEmpty(); + + ignite3 = (IgniteEx)G.start(getConfiguration("test3")); + ignite4 = (IgniteEx)G.start(getConfiguration("test4")); + + awaitPartitionMapExchange(); + + ignite1.resetLostPartitions(Collections.singletonList(cache1.getName())); + + IgniteCache cache2 = ignite2.cache(null); + IgniteCache cache3 = ignite3.cache(null); + IgniteCache cache4 = ignite4.cache(null); + + for (int i = 0; i < 100; i++) { + assert cache1.get(i).equals(i); + assert cache2.get(i).equals(i); + assert cache3.get(i).equals(i); + assert cache4.get(i).equals(i); + } + } + + /** + * @throws Exception If failed. + */ + public void testTopologyChangesWithConstantLoad() throws Exception { + final int entriesCnt = 10_000; + int maxNodesCount = 4; + int topChanges = 20; + final String cacheName = "indexed"; + + final AtomicBoolean stop = new AtomicBoolean(); + + final ConcurrentMap map = new ConcurrentHashMap<>(); + + Ignite ignite = startGrid(0); + + IgniteCache cache = ignite.cache(cacheName); + + for (int i = 0; i < entriesCnt; i++) { + cache.put(i, new TestValue(i, i)); + map.put(i, new TestValue(i, i)); + } + + final AtomicInteger nodesCnt = new AtomicInteger(); + + IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable() { + @Override public Void call() throws Exception { + while (true) { + if (stop.get()) + return null; + + int k = ThreadLocalRandom.current().nextInt(entriesCnt); + int v1 = ThreadLocalRandom.current().nextInt(); + int v2 = ThreadLocalRandom.current().nextInt(); + + int n = nodesCnt.get(); + + if (n <= 0) + continue; + + Ignite ignite; + + try { + ignite = grid(ThreadLocalRandom.current().nextInt(n)); + } + catch (Exception ignored) { + continue; + } + + if (ignite == null) + continue; + + Transaction tx = null; + boolean success = true; + + if (explicitTx) + tx = ignite.transactions().txStart(); + + try { + ignite.cache(cacheName).put(k, new TestValue(v1, v2)); + } + catch (Exception e) { + success = false; + } + finally { + if (tx != null) { + try { + tx.commit(); + } + catch (Exception e) { + success = false; + } + } + } + + if (success) + map.put(k, new TestValue(v1, v2)); + } + } + }, 1, "load-runner"); + + for (int i = 0; i < topChanges; i++) { + U.sleep(3_000); + + boolean add; + if (nodesCnt.get() <= maxNodesCount / 2) + add = true; + else if (nodesCnt.get() > maxNodesCount) + add = false; + else + add = ThreadLocalRandom.current().nextBoolean(); + + if (add) + startGrid(nodesCnt.incrementAndGet()); + else + stopGrid(nodesCnt.getAndDecrement()); + + awaitPartitionMapExchange(); + + cache.rebalance().get(); + } + + stop.set(true); + + fut.get(); + + awaitPartitionMapExchange(); + + for (Map.Entry entry : map.entrySet()) + assertEquals(Integer.toString(entry.getKey()), entry.getValue(), cache.get(entry.getKey())); + } + + /** + * + */ + private static class TestValue implements Serializable { + /** V 1. */ + private final int v1; + /** V 2. */ + private final int v2; + + /** + * @param v1 V 1. + * @param v2 V 2. + */ + private TestValue(int v1, int v2) { + this.v1 = v1; + this.v2 = v2; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + TestValue val = (TestValue)o; + + return v1 == val.v1 && v2 == val.v2; + + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int res = v1; + + res = 31 * res + v2; + + return res; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "TestValue{" + + "v1=" + v1 + + ", v2=" + v2 + + '}'; + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java new file mode 100644 index 0000000000000..62e1dee02d69a --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java @@ -0,0 +1,39 @@ +package org.apache.ignite.cache.database; + +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.processors.database.IgniteDbClientNearCachePutGetTest; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** + * + */ +public class IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest extends IgniteDbClientNearCachePutGetTest { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + super.beforeTest(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java new file mode 100644 index 0000000000000..af8f2467b7f2e --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java @@ -0,0 +1,247 @@ +package org.apache.ignite.cache.database; + +import java.util.Map; +import java.util.Random; +import java.util.TreeMap; +import java.util.concurrent.Callable; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgnitePersistentStoreContinuousRestartSelfTest extends GridCommonAbstractTest { + /** */ + private static final int GRID_CNT = 4; + + /** */ + private static final int ENTRIES_COUNT = 10_000; + + /** */ + public static final String CACHE_NAME = "cache1"; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(400 * 1024 * 1024); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + CacheConfiguration ccfg1 = new CacheConfiguration(); + + ccfg1.setName(CACHE_NAME); + ccfg1.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + ccfg1.setAffinity(new RendezvousAffinityFunction(false, 128)); + ccfg1.setBackups(2); + + cfg.setCacheConfiguration(ccfg1); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + stopAllGrids(); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + } + + /** + * @throws IgniteCheckedException If failed. + */ + private void deleteWorkFiles() throws IgniteCheckedException { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_500_1_1() throws Exception { + checkRebalancingDuringLoad(1000, 500, 1, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_500_1_1() throws Exception { + checkRebalancingDuringLoad(8000, 500, 1, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_20000_1_1() throws Exception { + checkRebalancingDuringLoad(1000, 20000, 1, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_8000_1_1() throws Exception { + checkRebalancingDuringLoad(8000, 8000, 1, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_500_8_1() throws Exception { + checkRebalancingDuringLoad(1000, 500, 8, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_500_8_1() throws Exception { + checkRebalancingDuringLoad(8000, 500, 8, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_20000_8_1() throws Exception { + checkRebalancingDuringLoad(1000, 20000, 8, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_8000_8_1() throws Exception { + checkRebalancingDuringLoad(8000, 8000, 8, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_500_8_16() throws Exception { + checkRebalancingDuringLoad(1000, 500, 8, 16); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_500_8_16() throws Exception { + checkRebalancingDuringLoad(8000, 500, 8, 16); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_20000_8_16() throws Exception { + checkRebalancingDuringLoad(1000, 20000, 8, 16); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_8000_8_16() throws Exception { + checkRebalancingDuringLoad(8000, 8000, 8, 16); + } + + /** + * @throws Exception if failed. + */ + private void checkRebalancingDuringLoad( + int restartDelay, + int checkpointDelay, + int threads, + final int batch + ) throws Exception { + + startGrids(GRID_CNT); + + final Ignite load = ignite(0); + + try (IgniteDataStreamer s = load.dataStreamer(CACHE_NAME)) { + s.allowOverwrite(true); + + for (int i = 0; i < ENTRIES_COUNT; i++) + s.addData(i, i); + } + + final AtomicBoolean done = new AtomicBoolean(false); + + IgniteInternalFuture busyFut = GridTestUtils.runMultiThreadedAsync(new Callable() { + /** {@inheritDoc} */ + @Override public Object call() throws Exception { + IgniteCache cache = load.cache(CACHE_NAME); + Random rnd = ThreadLocalRandom.current(); + + while (!done.get()) { + Map map = new TreeMap<>(); + + for (int i = 0; i < batch; i++) + map.put(rnd.nextInt(ENTRIES_COUNT), rnd.nextInt()); + + cache.putAll(map); + } + + return null; + } + }, threads, "updater"); + + long end = System.currentTimeMillis() + 90_000; + + Random rnd = ThreadLocalRandom.current(); + + while (System.currentTimeMillis() < end) { + int idx = rnd.nextInt(GRID_CNT - 1) + 1; + + stopGrid(idx); + + U.sleep(restartDelay); + + startGrid(idx); + + U.sleep(restartDelay); + } + + done.set(true); + + busyFut.get(); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest.java new file mode 100644 index 0000000000000..43ed392d513a0 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest.java @@ -0,0 +1,132 @@ +package org.apache.ignite.cache.database; + +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.processors.database.IgniteDbDynamicCacheSelfTest; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** + * + */ +public class IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest extends IgniteDbDynamicCacheSelfTest { + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + System.setProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC, "true"); + + super.beforeTest(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + + System.clearProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(200 * 1024 * 1024); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + if ("client".equals(gridName)) + cfg.setClientMode(true); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testRestartAndCreate() throws Exception { + startGrids(3); + + Ignite ignite = ignite(0); + + CacheConfiguration ccfg1 = new CacheConfiguration(); + + ccfg1.setName("cache1"); + ccfg1.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + ccfg1.setRebalanceMode(CacheRebalanceMode.NONE); + ccfg1.setAffinity(new RendezvousAffinityFunction(false, 32)); + + CacheConfiguration ccfg2 = new CacheConfiguration(); + + ccfg2.setName("cache2"); + ccfg2.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg2.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + ccfg2.setRebalanceMode(CacheRebalanceMode.NONE); + ccfg2.setAffinity(new RendezvousAffinityFunction(false, 32)); + + ignite.createCache(ccfg1); + ignite.createCache(ccfg2); + + int iterations = 20; + + long stopTime = U.currentTimeMillis() + 20_000; + + for (int k = 0; k < iterations && U.currentTimeMillis() < stopTime; k++) { + log.info("Iteration: " + k); + + stopAllGrids(); + + startGrids(3); + + ignite = ignite(0); + + ignite.getOrCreateCache(ccfg1); + + ignite.getOrCreateCache(ccfg2); + + ignite.destroyCache(ccfg2.getName()); + + ignite.getOrCreateCache(ccfg2); + + ignite.destroyCache(ccfg1.getName()); + } + } + + /** + * @throws IgniteCheckedException If failed. + */ + private void deleteWorkFiles() throws IgniteCheckedException { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java new file mode 100644 index 0000000000000..ed004b7049076 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java @@ -0,0 +1,236 @@ +package org.apache.ignite.cache.database; + +import java.io.File; +import java.io.Serializable; +import java.util.List; +import java.util.UUID; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.util.typedef.internal.S; +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.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgnitePersistentStoreMultiNodePutGetRestartSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final int GRID_CNT = 3; + + /** */ + private final File allocPath; + + /** + * Default constructor. + */ + public IgnitePersistentStoreMultiNodePutGetRestartSelfTest() { + String home = U.getIgniteHome(); + + allocPath = new File(home, "work/db/" + UUID.randomUUID()); + + allocPath.mkdirs(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + MemoryConfiguration memCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(100 * 1024 * 1024); + + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + memCfg.setMemoryPolicies(memPlcCfg); + + cfg.setMemoryConfiguration(memCfg); + + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setIndexedTypes(Integer.class, DbValue.class); + + ccfg.setRebalanceMode(CacheRebalanceMode.NONE); + + ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + + cfg.setCacheConfiguration(ccfg); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(discoSpi); + + cfg.setMarshaller(null); + + BinaryConfiguration bCfg = new BinaryConfiguration(); + + bCfg.setCompactFooter(false); + + cfg.setBinaryConfiguration(bCfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + super.beforeTest(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @throws Exception if failed. + */ + public void testPutGetSimple() throws Exception { + + + info(">>> Will use path: " + allocPath); + + startGrids(GRID_CNT); + + try { + IgniteEx ig = grid(0); + + checkPutGetSql(ig, true); + } + finally { + stopAllGrids(); + } + + info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + + startGrids(GRID_CNT); + + try { + IgniteEx ig = grid(0); + + checkPutGetSql(ig, false); + } + finally { + stopAllGrids(); + } + } + + /** + * @param ig Ig. + * @param write Write. + */ + private void checkPutGetSql(IgniteEx ig, boolean write) { + IgniteCache cache = ig.cache(null); + + if (write) { + try (IgniteDataStreamer streamer = ig.dataStreamer(null)) { + for (int i = 0; i < 10_000; i++) + streamer.addData(i, new DbValue(i, "value-" + i, i)); + } + } + + List> res = cache.query(new SqlFieldsQuery("select ival from dbvalue where ival < ? order by ival asc") + .setArgs(10_000)).getAll(); + + assertEquals(10_000, res.size()); + + for (int i = 0; i < 10_000; i++) { + assertEquals(1, res.get(i).size()); + assertEquals(i, res.get(i).get(0)); + } + + assertEquals(1, cache.query(new SqlFieldsQuery("select lval from dbvalue where ival = 7899")).getAll().size()); + assertEquals(5000, cache.query(new SqlFieldsQuery("select lval from dbvalue where ival >= 5000 and ival < 10000")) + .getAll().size()); + + for (int i = 0; i < 10_000; i++) + assertEquals(new DbValue(i, "value-" + i, i), cache.get(i)); + } + + /** + * + */ + private static class DbValue implements Serializable { + /** */ + @QuerySqlField(index = true) + private int iVal; + + /** */ + @QuerySqlField(index = true) + private String sVal; + + /** */ + @QuerySqlField + private long lVal; + + /** + * @param iVal Integer value. + * @param sVal String value. + * @param lVal Long value. + */ + public DbValue(int iVal, String sVal, long lVal) { + this.iVal = iVal; + this.sVal = sVal; + this.lVal = lVal; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + DbValue dbVal = (DbValue)o; + + return iVal == dbVal.iVal && lVal == dbVal.lVal && + !(sVal != null ? !sVal.equals(dbVal.sVal) : dbVal.sVal != null); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int res = iVal; + + res = 31 * res + (sVal != null ? sVal.hashCode() : 0); + res = 31 * res + (int)(lVal ^ (lVal >>> 32)); + + return res; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(DbValue.class, this); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesSelfTest.java new file mode 100644 index 0000000000000..71e516061a85e --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesSelfTest.java @@ -0,0 +1,138 @@ +package org.apache.ignite.cache.database; + +import java.util.Random; +import java.util.concurrent.Callable; +import java.util.concurrent.ThreadLocalRandom; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgnitePersistentStorePageSizesSelfTest extends GridCommonAbstractTest { + /** */ + private int pageSize; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + MemoryConfiguration memCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(100 * 1024 * 1024); + + memCfg.setMemoryPolicies(memPlcCfg); + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + memCfg.setPageSize(pageSize); + + cfg.setMemoryConfiguration(memCfg); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + cfg.setCacheConfiguration( + new CacheConfiguration("partitioned") + .setAffinity(new RendezvousAffinityFunction(false, 32)) + ); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @throws Exception if failed. + */ + public void testPageSize_1k() throws Exception { + checkPageSize(1024); + } + + /** + * @throws Exception if failed. + */ + public void testPageSize_2k() throws Exception { + checkPageSize(2 * 1024); + } + + /** + * @throws Exception if failed. + */ + public void testPageSize_4k() throws Exception { + checkPageSize(4 * 1024); + } + + /** + * @throws Exception if failed. + */ + public void testPageSize_8k() throws Exception { + checkPageSize(8 * 1024); + } + + /** + * @throws Exception if failed. + */ + public void testPageSize_16k() throws Exception { + checkPageSize(16 * 1024); + } + + /** + * @throws Exception if failed. + */ + private void checkPageSize(int pageSize) throws Exception { + this.pageSize = pageSize; + + IgniteEx ignite = startGrid(0); + + try { + final IgniteCache cache = ignite.cache("partitioned"); + final long endTime = System.currentTimeMillis() + 60_000; + + GridTestUtils.runMultiThreaded(new Callable() { + @Override public Object call() throws Exception { + Random rnd = ThreadLocalRandom.current(); + + while (System.currentTimeMillis() < endTime) { + for (int i = 0; i < 500; i++) + cache.put(rnd.nextInt(100_000), rnd.nextInt()); + } + + return null; + } + }, 16, "runner"); + } + finally { + stopAllGrids(); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java new file mode 100644 index 0000000000000..1965369ccea36 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java @@ -0,0 +1,328 @@ +package org.apache.ignite.cache.database; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.FileChannel; +import java.util.Collection; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdAllocator; +import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.pagemem.PageUtils; +import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; +import org.apache.ignite.internal.pagemem.store.PageStore; +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.pagemem.wal.WALPointer; +import org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.file.FilePageStore; +import org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgnitePersistentStoreRecoveryAfterFileCorruptionTest extends GridCommonAbstractTest { + /** Total pages. */ + private static final int totalPages = 1024; + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES, "true"); + + stopAllGrids(); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + deleteWorkFiles(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES); + } + + /** + * @throws Exception if failed. + */ + public void testPageRecoveryAfterFileCorruption() throws Exception { + fail(); //todo @Ed + + IgniteEx ig = startGrid(0); + + GridCacheSharedContext shared = ig.context().cache().context(); + + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)shared.database(); + + IgnitePageStoreManager pageStore = shared.pageStore(); + + U.sleep(1_000); + + // Disable integrated checkpoint thread. + dbMgr.enableCheckpoints(false).get(); + + PageMemory mem = shared.database().memoryPolicy(null).pageMemory(); + + int cacheId = shared.cache().cache("partitioned").context().cacheId(); + + FullPageId[] pages = new FullPageId[totalPages]; + + for (int i = 0; i < totalPages; i++) { + FullPageId fullId = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId); + + pages[i] = fullId; + } + + generateWal( + (PageMemoryImpl)mem, + pageStore, + shared.wal(), + cacheId, + pages + ); + + eraseDataFromDisk((FilePageStoreManager)pageStore, cacheId, pages[0]); + + stopAllGrids(); + + ig = startGrid(0); + + checkRestore(ig, pages); + } + + /** + * @param pageStore Page store. + * @param cacheId Cache id. + * @param page Page. + */ + private void eraseDataFromDisk( + FilePageStoreManager pageStore, + int cacheId, + FullPageId page + ) throws IgniteCheckedException, IOException { + PageStore store = pageStore.getStore( + cacheId, + PageIdUtils.partId(page.pageId()) + ); + + FilePageStore filePageStore = (FilePageStore)store; + + FileChannel ch = U.field(filePageStore, "ch"); + + long size = ch.size(); + + ch.write(ByteBuffer.allocate((int)size - FilePageStore.HEADER_SIZE), FilePageStore.HEADER_SIZE); + + ch.force(false); + } + + /** + * @param ig Ig. + * @param pages Pages. + */ + private void checkRestore(IgniteEx ig, FullPageId[] pages) throws IgniteCheckedException { + GridCacheSharedContext shared = ig.context().cache().context(); + + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)shared.database(); + + dbMgr.enableCheckpoints(false).get(); + + PageMemory mem = shared.database().memoryPolicy(null).pageMemory(); + + for (FullPageId fullId : pages) { + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + long pageAddr = mem.readLock(fullId.cacheId(), fullId.pageId(), page); + + for (int j = PageIO.COMMON_HEADER_END; j < mem.pageSize(); j += 4) + assertEquals(j + (int)fullId.pageId(), PageUtils.getInt(pageAddr, j)); + + mem.readUnlock(fullId.cacheId(), fullId.pageId(), page); + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration("partitioned"); + + ccfg.setRebalanceMode(CacheRebalanceMode.NONE); + + cfg.setCacheConfiguration(ccfg); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(1024 * 1024 * 1024); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + pCfg.setCheckpointFrequency(500); + + cfg.setPersistenceConfiguration(pCfg); + + return cfg; + } + + /** + * @param mem Mem. + * @param storeMgr Store manager. + * @param wal Wal. + * @param cacheId Cache id. + * @param pages Pages. + */ + private void generateWal( + final PageMemoryImpl mem, + final IgnitePageStoreManager storeMgr, + final IgniteWriteAheadLogManager wal, + final int cacheId, FullPageId[] pages + ) throws Exception { + // Mark the start position. + CheckpointRecord cpRec = new CheckpointRecord(null, false); + + WALPointer start = wal.log(cpRec); + + wal.fsync(start); + + for (int i = 0; i < totalPages; i++) { + FullPageId fullId = pages[i]; + + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + long pageAddr = mem.writeLock(fullId.cacheId(), fullId.pageId(), page); + + PageIO.setPageId(pageAddr, fullId.pageId()); + + try { + for (int j = PageIO.COMMON_HEADER_END; j < mem.pageSize(); j += 4) + PageUtils.putInt(pageAddr, j, j + (int)fullId.pageId()); + } + finally { + mem.writeUnlock(fullId.cacheId(), fullId.pageId(), page, null, true); + } + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + + Collection pageIds = mem.beginCheckpoint(); + + info("Acquired pages for checkpoint: " + pageIds.size()); + + try { + ByteBuffer tmpBuf = ByteBuffer.allocate(mem.pageSize()); + + tmpBuf.order(ByteOrder.nativeOrder()); + + long begin = System.currentTimeMillis(); + + long cp = 0; + + long write = 0; + + for (int i = 0; i < totalPages; i++) { + FullPageId fullId = pages[i]; + + if (pageIds.contains(fullId)) { + long cpStart = System.nanoTime(); + + Integer tag = mem.getForCheckpoint(fullId, tmpBuf); + + if (tag == null) + continue; + + long cpEnd = System.nanoTime(); + + cp += cpEnd - cpStart; + tmpBuf.rewind(); + + for (int j = PageIO.COMMON_HEADER_END; j < mem.pageSize(); j += 4) + assertEquals(j + (int)fullId.pageId(), tmpBuf.getInt(j)); + + tmpBuf.rewind(); + + long writeStart = System.nanoTime(); + + storeMgr.write(cacheId, fullId.pageId(), tmpBuf, tag); + + long writeEnd = System.nanoTime(); + + write += writeEnd - writeStart; + + tmpBuf.rewind(); + } + } + + long syncStart = System.currentTimeMillis(); + + storeMgr.sync(cacheId, 0); + + long end = System.currentTimeMillis(); + + info("Written pages in " + (end - begin) + "ms, copy took " + (cp / 1_000_000) + "ms, " + + "write took " + (write / 1_000_000) + "ms, sync took " + (end - syncStart) + "ms"); + } + finally { + info("Finishing checkpoint..."); + + mem.finishCheckpoint(); + + info("Finished checkpoint"); + } + + wal.fsync(wal.log(new CheckpointRecord(null, false))); + + for (FullPageId fullId : pages) { + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + assertFalse("Page has a temp heap copy after the last checkpoint: [cacheId=" + + fullId.cacheId() + ", pageId=" + fullId.pageId() + "]", mem.hasTempCopy(page)); + + assertFalse("Page is dirty after the last checkpoint: [cacheId=" + + fullId.cacheId() + ", pageId=" + fullId.pageId() + "]", mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + } + + /** + * + */ + private void deleteWorkFiles() throws IgniteCheckedException { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java new file mode 100644 index 0000000000000..8ec773b3700d3 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java @@ -0,0 +1,124 @@ +package org.apache.ignite.cache.database; + +import java.io.File; +import java.util.concurrent.Callable; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.G; +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.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; + +/** + * + */ +public class IgnitePersistentStoreRemoveDuringRebalancingSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setCacheConfiguration(new CacheConfiguration().setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) + .setBackups(1).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC) + .setRebalanceMode(CacheRebalanceMode.SYNC)); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); + dbCfg.setPageSize(1024); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(100 * 1024 * 1024); + memPlcCfg.setSwapFilePath("db"); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + G.stopAll(true); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + U.delete(new File(U.getIgniteHome(), "db")); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + G.stopAll(true); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + U.delete(new File(U.getIgniteHome(), "db")); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + } + + /** + * @throws Exception if failed. + */ + public void testRemovesDuringRebalancing() throws Exception { + IgniteEx ig = startGrid(0); + + try (IgniteDataStreamer streamer = ig.dataStreamer(null)) { + streamer.allowOverwrite(true); + + for (int i = 0; i < 100_000; i++) + streamer.addData(i, i); + } + + final IgniteCache cache = ig.cache(null); + + IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable() { + @Override public Object call() throws Exception { + return startGrid(1); + } + }); + + for (int i = 0; i < 100_000; i++) + cache.remove(i); + + fut.get(); + + IgniteEx another = grid(1); + + IgniteCache cache1 = another.cache(null); + + for (int i = 0; i < 100_000; i++) + assertNull(cache1.localPeek(i)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java new file mode 100644 index 0000000000000..dbdb5f53be3f6 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java @@ -0,0 +1,39 @@ +package org.apache.ignite.cache.database; + +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.processors.database.IgniteDbSingleNodePutGetTest; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** + * + */ +public class IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest extends IgniteDbSingleNodePutGetTest { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + super.beforeTest(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java new file mode 100644 index 0000000000000..ee7548e589427 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java @@ -0,0 +1,39 @@ +package org.apache.ignite.cache.database; + +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.processors.database.IgniteDbSingleNodeWithIndexingPutGetTest; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** + * + */ +public class IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest extends IgniteDbSingleNodeWithIndexingPutGetTest { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + super.beforeTestsStarted(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java new file mode 100644 index 0000000000000..f09d2ae6d9fa0 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java @@ -0,0 +1,44 @@ +package org.apache.ignite.cache.database; + +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.CacheConfiguration; + +/** + * + */ +public class IgnitePersistentStoreTxCacheRebalancingTest extends IgnitePersistentStoreCacheRebalancingAbstractTest { + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String cacheName) { + CacheConfiguration ccfg = new CacheConfiguration(cacheName); + + ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setRebalanceMode(CacheRebalanceMode.SYNC); + ccfg.setBackups(1); + ccfg.setRebalanceDelay(10_000); + ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + + return ccfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + explicitTx = false; + } + + /** + * @throws Exception If failed. + */ + public void testTopologyChangesWithConstantLoadExplicitTx() throws Exception { + explicitTx = true; + + testTopologyChangesWithConstantLoad(); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java new file mode 100644 index 0000000000000..1248d307bf385 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java @@ -0,0 +1,101 @@ +package org.apache.ignite.cache.database; + +import javax.cache.CacheException; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +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.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgnitePersistentStoreWalTlbSelfTest extends GridCommonAbstractTest { + /** Ip finder. */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration<>(); + + cfg.setCacheConfiguration(ccfg); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + if (gridName.endsWith("1")) + cfg.setClientMode(true); + + cfg.setDiscoverySpi(discoSpi); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_TLB_SIZE, "640000000"); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_TLB_SIZE); + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return 30_000; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + stopAllGrids(); + + startGrids(2); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @throws Exception if failed. + */ + public void testWalDirectOutOfMemory() throws Exception { + + IgniteEx ig = grid(1); + boolean locked = true; + + try { + IgniteDataStreamer streamer = ig.dataStreamer(null); + for (int i = 0; i < 100_000; i++) { + streamer.addData(i, 1); + + if (i > 0 && i % 10_000 == 0) + info("Done put: " + i); + } + } catch (CacheException ignore) { + // expected + locked = false; + } finally { + assertFalse(locked); + stopAllGrids(); + } + } + +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java new file mode 100644 index 0000000000000..70819b859bfe8 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java @@ -0,0 +1,155 @@ +package org.apache.ignite.cache.database.db; + +import java.util.concurrent.Callable; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class DbPageEvictionDuringPartitionClearSelfTest extends GridCommonAbstractTest { + /** */ + public static final String CACHE_NAME = "cache"; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration("cache") + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) + .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC) + .setAffinity(new RendezvousAffinityFunction(false, 128)) + .setRebalanceMode(CacheRebalanceMode.SYNC) + .setBackups(1); + + cfg.setCacheConfiguration(ccfg); + + MemoryConfiguration memCfg = new MemoryConfiguration(); + + // Intentionally set small page cache size. + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setSize(70 * 1024 * 1024); + + memPlcCfg.setName("dfltMemPlc"); + + memCfg.setMemoryPolicies(memPlcCfg); + + memCfg.setDefaultMemoryPolicyName(memPlcCfg.getName()); + + cfg.setMemoryConfiguration(memCfg); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return 20 * 60 * 1000; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + System.setProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC, "true"); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + System.clearProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC); + } + + /** + * @throws Exception if failed. + */ + public void testPageEvictionOnNodeStart() throws Exception { + for (int r = 0; r < 3; r++) { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + startGrids(2); + + try { + Ignite ig = ignite(0); + + IgniteDataStreamer streamer = ig.dataStreamer(CACHE_NAME); + + for (int i = 0; i < 300_000; i++) { + streamer.addData(i, new TestValue(i)); + + if (i > 0 && i % 10_000 == 0) + info("Done: " + i); + } + + streamer.flush(); + + IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable() { + @Override public Object call() throws Exception { + IgniteEx ig = startGrid(2); + + info(">>>>>>>>>>>"); + info(">>>>>>>>>>>"); + info(">>>>>>>>>>>"); + + return ig; + } + }); + + for (int i = 500_000; i < 1_000_000; i++) { + streamer.addData(i, new TestValue(i)); + + if (i > 0 && i % 10_000 == 0) { + info("Done: " + i); + + U.sleep(1000); + } + } + + streamer.close(); + + fut.get(); + } + finally { + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + } + } + + /** + * + */ + private static class TestValue { + /** */ + private int id; + + /** */ + private byte[] payload = new byte[512]; + + /** + * @param id ID. + */ + private TestValue(int id) { + this.id = id; + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java similarity index 92% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java index c999df53d4260..dfebd1fe2a01d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgniteDbMultiNodePutGetRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java @@ -1,4 +1,4 @@ -package org.apache.ignite.cache.database; +package org.apache.ignite.cache.database.db; import java.io.File; import java.io.Serializable; @@ -14,7 +14,6 @@ import org.apache.ignite.configuration.BinaryConfiguration; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistenceConfiguration; import org.apache.ignite.internal.IgniteEx; @@ -24,6 +23,7 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.configuration.MemoryConfiguration; /** * @@ -42,17 +42,17 @@ public class IgniteDbMultiNodePutGetRestartSelfTest extends GridCommonAbstractTe @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - MemoryConfiguration memCfg = new MemoryConfiguration(); + MemoryConfiguration dbCfg = new MemoryConfiguration(); MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); memPlcCfg.setSize(100 * 1024 * 1024); - memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); - memCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + dbCfg.setMemoryPolicies(memPlcCfg); - cfg.setMemoryConfiguration(memCfg); + cfg.setMemoryConfiguration(dbCfg); CacheConfiguration ccfg = new CacheConfiguration(); @@ -138,6 +138,10 @@ public void testPutGetSimple() throws Exception { } } + /** + * @param ig Ig. + * @param write Write. + */ private void checkPutGetSql(IgniteEx ig, boolean write) { IgniteCache cache = ig.cache(null); @@ -201,10 +205,10 @@ public DbValue(int iVal, String sVal, long lVal) { if (o == null || getClass() != o.getClass()) return false; - DbValue dbValue = (DbValue)o; + DbValue dbVal = (DbValue)o; - return iVal == dbValue.iVal && lVal == dbValue.lVal && - !(sVal != null ? !sVal.equals(dbValue.sVal) : dbValue.sVal != null); + return iVal == dbVal.iVal && lVal == dbVal.lVal && + !(sVal != null ? !sVal.equals(dbVal.sVal) : dbVal.sVal != null); } /** {@inheritDoc} */ diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java new file mode 100644 index 0000000000000..38624385f2f6e --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java @@ -0,0 +1,220 @@ +package org.apache.ignite.cache.database.db; + +import java.io.Serializable; +import java.util.List; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.internal.S; +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.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteDbPageEvictionSelfTest extends GridCommonAbstractTest { + /** IP finder. */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** Test entry count. */ + public static final int ENTRY_CNT = 1_000_000; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); + + dbCfg.setPageSize(1024); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(50 * 1024 * 1024); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + CacheConfiguration ccfg = new CacheConfiguration<>(); + + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + ccfg.setRebalanceMode(CacheRebalanceMode.NONE); + ccfg.setIndexedTypes(DbKey.class, DbValue.class); + ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + + cfg.setCacheConfiguration(ccfg); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(discoSpi); + cfg.setMarshaller(null); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + assertNull(System.getProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE)); + + stopAllGrids(); + + startGrids(1); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @throws Exception if failed. + */ + public void testPageEvictionSql() throws Exception { + IgniteEx ig = grid(0); + + try (IgniteDataStreamer streamer = ig.dataStreamer(null)) { + for (int i = 0; i < ENTRY_CNT; i++) { + streamer.addData(new DbKey(i), new DbValue(i, "value-" + i, Long.MAX_VALUE - i)); + + if (i > 0 && i % 10_000 == 0) + info("Done put: " + i); + } + } + + IgniteCache cache = ignite(0).cache(null); + + for (int i = 0; i < ENTRY_CNT; i++) { + assertEquals(Long.MAX_VALUE - i, cache.get(new DbKey(i)).lVal); + + if (i > 0 && i % 10_000 == 0) + info("Done get: " + i); + } + + for (int i = 0; i < ENTRY_CNT; i++) { + List> rows = cache.query(new SqlFieldsQuery("select lVal from DbValue where iVal=?").setArgs(i)) + .getAll(); + + assertEquals(1, rows.size()); + assertEquals(Long.MAX_VALUE - i, rows.get(0).get(0)); + + if (i > 0 && i % 10_000 == 0) + info("Done SQL query: " + i); + } + } + + /** + * + */ + private static class DbKey implements Serializable { + /** */ + private int val; + + /** + * @param val Value. + */ + private DbKey(int val) { + this.val = val; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || !(o instanceof DbKey)) + return false; + + DbKey key = (DbKey)o; + + return val == key.val; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return val; + } + } + + /** + * + */ + private static class DbValue implements Serializable { + /** */ + @QuerySqlField(index = true) + private int iVal; + + /** */ + @QuerySqlField(index = true) + private String sVal; + + /** */ + @QuerySqlField + private long lVal; + + /** + * @param iVal Integer value. + * @param sVal String value. + * @param lVal Long value. + */ + private DbValue(int iVal, String sVal, long lVal) { + this.iVal = iVal; + this.sVal = sVal; + this.lVal = lVal; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + DbValue dbVal = (DbValue)o; + + return iVal == dbVal.iVal && lVal == dbVal.lVal && + !(sVal != null ? !sVal.equals(dbVal.sVal) : dbVal.sVal != null); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int res = iVal; + + res = 31 * res + (sVal != null ? sVal.hashCode() : 0); + res = 31 * res + (int)(lVal ^ (lVal >>> 32)); + + return res; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(DbValue.class, this); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java new file mode 100644 index 0000000000000..b57a6898f7845 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java @@ -0,0 +1,141 @@ +package org.apache.ignite.cache.database.db; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteDbWholeClusterRestartSelfTest extends GridCommonAbstractTest { + /** */ + private static final int GRID_CNT = 5; + + /** */ + private static final int ENTRIES_COUNT = 1_000; + + /** */ + public static final String CACHE_NAME = "cache1"; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(100 * 1024 * 1024); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + CacheConfiguration ccfg1 = new CacheConfiguration(); + + ccfg1.setName(CACHE_NAME); + ccfg1.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg1.setRebalanceMode(CacheRebalanceMode.SYNC); + ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + ccfg1.setAffinity(new RendezvousAffinityFunction(false, 32)); + ccfg1.setBackups(2); + + cfg.setLateAffinityAssignment(false); + + cfg.setCacheConfiguration(ccfg1); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + cfg.setConsistentId(gridName); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + stopAllGrids(); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + } + + /** + * @throws IgniteCheckedException If failed. + */ + private void deleteWorkFiles() throws IgniteCheckedException { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @throws Exception if failed. + */ + public void testRestarts() throws Exception { + startGrids(GRID_CNT); + + awaitPartitionMapExchange(); + + try (IgniteDataStreamer ds = ignite(0).dataStreamer(CACHE_NAME)) { + for (int i = 0; i < ENTRIES_COUNT; i++) + ds.addData(i, i); + } + + stopAllGrids(); + + List idxs = new ArrayList<>(); + + for (int i = 0; i < GRID_CNT; i++) + idxs.add(i); + + for (int r = 0; r < 10; r++) { + Collections.shuffle(idxs); + + info("Will start in the following order: " + idxs); + + for (Integer idx : idxs) + startGrid(idx); + + for (int g = 0; g < GRID_CNT; g++) { + Ignite ig = ignite(g); + + for (int k = 0; k < ENTRIES_COUNT; k++) + assertEquals("Failed to read [g=" + g + ", part=" + ig.affinity(CACHE_NAME).partition(k) + + ", nodes=" + ig.affinity(CACHE_NAME).mapKeyToPrimaryAndBackups(k) + ']', + k, ig.cache(CACHE_NAME).get(k)); + } + + stopAllGrids(); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java new file mode 100644 index 0000000000000..4950906fee872 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java @@ -0,0 +1,196 @@ +package org.apache.ignite.cache.database.db; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +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.PartitionLossPolicy; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy; + +/** + * We start writing to unstable cluster. + * After that we start killing node. + * There will be entries in WAL which belongs to evicted partitions. + * We should ignore them (not throw exceptions). This point is tested. + */ +public class RebalancingOnNotStableTopologyTest extends GridCommonAbstractTest { + /** Checkpoint frequency. */ + private static final long CHECKPOINT_FREQUENCY = 2_000_000; + + /** Cluster size. */ + private static final int CLUSTER_SIZE = 5; + + /** + * @throws Exception When fails. + */ + public void test() throws Exception { + stopAllGrids(); + + Ignite ex = startGrid(0); + + startGrid(1); + + final CountDownLatch startLatch = new CountDownLatch(1); + final CountDownLatch doneLatch = new CountDownLatch(1); + + final Ignite ex1 = ex; + + final AtomicBoolean stop = new AtomicBoolean(); + final AtomicInteger keyCnt = new AtomicInteger(); + + Thread thread = new Thread(new Runnable() { + @Override public void run() { + ex1.active(true); + + try { + checkTopology(2); + + startLatch.countDown(); + + IgniteCache cache1 = ex1.cache("cache1"); + + int key = keyCnt.get(); + + while (!stop.get()) { + if (key > 0 && (key % 500 == 0)) { + U.sleep(5); + + System.out.println("key = " + key); + } + + cache1.put(key, -key); + + key = keyCnt.incrementAndGet(); + } + } + catch (Throwable th) { + th.printStackTrace(); + } + + doneLatch.countDown(); + } + }); + + thread.setName("Data-Loader"); + thread.start(); + + startLatch.await(60, TimeUnit.SECONDS); + + for (int i = 2; i < CLUSTER_SIZE; i++) { + startGrid(i); + + U.sleep(5000); + } + + U.sleep(10000); + + IgniteProcessProxy.kill("db.RebalancingOnNotStableTopologyTest2"); + + Thread.sleep(5000); + + IgniteProcessProxy.kill("db.RebalancingOnNotStableTopologyTest1"); + + assert doneLatch.getCount() > 0; + + stop.set(true); + + doneLatch.await(600, TimeUnit.SECONDS); + + IgniteProcessProxy.killAll(); + + stopAllGrids(); + + //start cluster. it will cause memory restoration and reading WAL. + ex = startGrids(CLUSTER_SIZE); + + ex.active(true); + + checkTopology(CLUSTER_SIZE); + + IgniteCache cache1 = ex.cache("cache1"); + + assert keyCnt.get() > 0; + + for (int i = 0; i < keyCnt.get(); i++) + assertEquals(-i, cache1.get(i)); + + System.out.println("Test finished with total keys count = " + keyCnt.get()); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setActiveOnStart(false); + + CacheConfiguration ccfg = new CacheConfiguration<>(); + + ccfg.setName("cache1"); + ccfg.setPartitionLossPolicy(PartitionLossPolicy.READ_ONLY_SAFE); + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + ccfg.setBackups(2); + + cfg.setCacheConfiguration(ccfg); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + pCfg.setCheckpointFrequency(CHECKPOINT_FREQUENCY); + + cfg.setPersistenceConfiguration(pCfg); + + MemoryConfiguration memCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(200 * 1024 * 1024); + + memCfg.setMemoryPolicies(memPlcCfg); + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(memCfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected boolean isMultiJvm() { + return true; + } + + /** {@inheritDoc} */ + @Override protected boolean checkTopology() { + return false; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + stopAllGrids(); + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return TimeUnit.MINUTES.toMillis(10); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java new file mode 100644 index 0000000000000..175dad0962c04 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java @@ -0,0 +1,286 @@ +package org.apache.ignite.cache.database.db; + +import java.util.Random; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.configuration.TransactionConfiguration; +import org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; +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.junits.common.GridCommonAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.apache.ignite.transactions.TransactionIsolation; +import org.jsr166.LongAdder8; + +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; + +/** + * Checks that transactions don't hang during checkpoint creation. + */ +public class TransactionsHangTest extends GridCommonAbstractTest { + /** IP finder. */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** Page cache size. */ + private static final int PAGE_CACHE_SIZE = 512; + + /** Page size. */ + private static final Integer PAGE_SIZE = 16; + + /** Cache name. */ + private static final String CACHE_NAME = "TransactionsHangTest"; + + /** Number of insert threads. */ + public static final int THREADS_CNT = 32; + + /** Warm up period, seconds. */ + public static final int WARM_UP_PERIOD = 20; + + /** Duration. */ + public static final int DURATION = 180; + + /** Maximum count of inserted keys. */ + public static final int MAX_KEY_COUNT = 1_000_000; + + /** Checkpoint frequency. */ + public static final long CHECKPOINT_FREQUENCY = 20_000; + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return Long.MAX_VALUE; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + discoSpi.setIpFinder(IP_FINDER); + cfg.setDiscoverySpi(discoSpi); + + BinaryConfiguration binaryCfg = new BinaryConfiguration(); + binaryCfg.setCompactFooter(false); + cfg.setBinaryConfiguration(binaryCfg); + + cfg.setPeerClassLoadingEnabled(true); + + TcpCommunicationSpi tcpCommSpi = new TcpCommunicationSpi(); + + tcpCommSpi.setSharedMemoryPort(-1); + cfg.setCommunicationSpi(tcpCommSpi); + + TransactionConfiguration txCfg = new TransactionConfiguration(); + + txCfg.setDefaultTxIsolation(TransactionIsolation.READ_COMMITTED); + + cfg.setTransactionConfiguration(txCfg); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + pCfg.setCheckpointFrequency(CHECKPOINT_FREQUENCY); + + cfg.setPersistenceConfiguration(pCfg); + + MemoryConfiguration memCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(PAGE_CACHE_SIZE * 1024 * 1024); + + memCfg.setMemoryPolicies(memPlcCfg); + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + memCfg.setPageSize(PAGE_SIZE * 1024); + + cfg.setMemoryConfiguration(memCfg); + + return cfg; + } + + /** + * Creates cache configuration. + * + * @return Cache configuration. + * */ + private CacheConfiguration getCacheConfiguration() { + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setName(CACHE_NAME); + ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + ccfg.setAffinity(new RendezvousAffinityFunction(false, 64 * 4)); + ccfg.setReadFromBackup(true); + + ccfg.setCacheMode(CacheMode.PARTITIONED); + + return ccfg; + } + + /** + * Copied from customers benchmark. + * + * @throws Exception If failed. + * */ + public void testTransactionsDontHang() throws Exception { + try { + final Ignite g = startGrids(2); + + g.getOrCreateCache(getCacheConfiguration()); + + ExecutorService threadPool = Executors.newFixedThreadPool(THREADS_CNT); + final CyclicBarrier cyclicBarrier = new CyclicBarrier(THREADS_CNT); + + final AtomicBoolean interrupt = new AtomicBoolean(false); + final LongAdder8 operationCnt = new LongAdder8(); + + final IgniteCache cache = g.cache(CACHE_NAME); + + for (int i = 0; i < THREADS_CNT; i++) { + threadPool.submit(new Runnable() { + @Override public void run() { + try { + ThreadLocalRandom locRandom = ThreadLocalRandom.current(); + + cyclicBarrier.await(); + + while (!interrupt.get()) { + long randomKey = locRandom.nextLong(MAX_KEY_COUNT); + + TestEntity entity = TestEntity.newTestEntity(locRandom); + + try (Transaction tx = g.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { + cache.put(randomKey, entity); + + tx.commit(); + } + + operationCnt.increment(); + } + } + catch (Throwable e) { + System.out.println(e.toString()); + + throw new RuntimeException(e); + } + } + }); + } + + long stopTime = System.currentTimeMillis() + DURATION * 1000; + long totalOperations = 0; + int periods = 0; + long max = Long.MIN_VALUE, min = Long.MAX_VALUE; + + while (System.currentTimeMillis() < stopTime) { + U.sleep(1000); + + long sum = operationCnt.sumThenReset(); + periods++; + + if (periods > WARM_UP_PERIOD) { + totalOperations += sum; + + max = Math.max(max, sum); + min = Math.min(min, sum); + + System.out.println("Operation count: " + sum + " min=" + min + " max=" + max + " avg=" + totalOperations / (periods - WARM_UP_PERIOD)); + } + } + + interrupt.set(true); + + threadPool.shutdown(); + System.out.println("Test complete"); + + threadPool.awaitTermination(getTestTimeout(), TimeUnit.MILLISECONDS); + + IgniteTxManager tm = internalCache(cache).context().tm(); + + assertEquals("There are still active transactions", 0, tm.activeTransactions().size()); + } finally { + stopAllGrids(); + } + } + + /** + * Entity for test. + * */ + public static class TestEntity { + /** String value. */ + private String strVal; + + /** Long value. */ + private Long longVal; + + /** Int value. */ + private int intVal; + + /** + * @param strVal String value. + */ + public void setStrVal(String strVal) { + this.strVal = strVal; + } + + /** + * @param longVal Long value. + */ + public void setLongVal(Long longVal) { + this.longVal = longVal; + } + + /** + * @param intVal Integer value. + */ + public void setIntVal(int intVal) { + this.intVal = intVal; + } + + /** + * Creates test entity with random values. + * + * @param random Random seq generator. + * @return new test entity + * */ + private static TestEntity newTestEntity(Random random) { + TestEntity entity = new TestEntity(); + + entity.setLongVal((long) random.nextInt(1_000)); + entity.setIntVal(random.nextInt(1_000)); + entity.setStrVal("test" + random.nextInt(1_000)); + + return entity; + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java new file mode 100644 index 0000000000000..a24153e4134e2 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java @@ -0,0 +1,269 @@ +package org.apache.ignite.cache.database.db.file; + +import java.io.Serializable; +import java.util.List; +import java.util.concurrent.Callable; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.internal.S; +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.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; + +/** + * + */ +public class IgniteCachePageStoreIntegrationSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final int GRID_CNT = 3; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(100 * 1024 * 1024); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + cfg.setMemoryConfiguration(dbCfg); + + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setIndexedTypes(Integer.class, DbValue.class); + + ccfg.setRebalanceMode(CacheRebalanceMode.NONE); + + ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + + ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + + cfg.setCacheConfiguration(ccfg); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(discoSpi); + + cfg.setMarshaller(null); + + BinaryConfiguration bCfg = new BinaryConfiguration(); + + bCfg.setCompactFooter(false); + + cfg.setBinaryConfiguration(bCfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @throws Exception if failed. + */ + public void testPutGetSimple() throws Exception { + startGrids(GRID_CNT); + + try { + IgniteEx ig = grid(0); + + checkPutGetSql(ig, true); + } + finally { + stopAllGrids(); + } + + info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + + startGrids(GRID_CNT); + + try { + IgniteEx ig = grid(0); + + checkPutGetSql(ig, false); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + public void testPutMultithreaded() throws Exception { + startGrids(4); + + try { + final IgniteEx grid = grid(0); + + GridTestUtils.runMultiThreaded(new Callable() { + @Override public Object call() throws Exception { + for (int i = 0; i < 1000; i++) + grid.cache(null).put(i, i); + + return null; + } + }, 8, "updater"); + } + finally { + stopAllGrids(); + } + } + + /** + * @param ig Ignite instance. + * @param write Write flag. + */ + private void checkPutGetSql(Ignite ig, boolean write) { + IgniteCache cache = ig.cache(null); + + int entryCnt = 50_000; + + if (write) { + try (IgniteDataStreamer streamer = ig.dataStreamer(null)) { + streamer.allowOverwrite(true); + + for (int i = 0; i < entryCnt; i++) + streamer.addData(i, new DbValue(i, "value-" + i, i)); + } + } + + for (int i = 0; i < GRID_CNT; i++) { + IgniteEx ignite = grid(i); + + GridCacheAdapter cache0 = ignite.context().cache().internalCache(null); + + for (int k = 0; k < entryCnt; k++) + assertNull(cache0.peekEx(i)); + + assertEquals(entryCnt, ignite.cache(null).size()); + } + + for (int i = 0; i < entryCnt; i++) + assertEquals("i = " + i, new DbValue(i, "value-" + i, i), cache.get(i)); + + List> res = cache.query(new SqlFieldsQuery("select ival from dbvalue where ival < ? order by ival asc") + .setArgs(10_000)).getAll(); + + assertEquals(10_000, res.size()); + + for (int i = 0; i < 10_000; i++) { + assertEquals(1, res.get(i).size()); + assertEquals(i, res.get(i).get(0)); + } + + assertEquals(1, cache.query(new SqlFieldsQuery("select lval from dbvalue where ival = 7899")).getAll().size()); + assertEquals(5000, cache.query(new SqlFieldsQuery("select lval from dbvalue where ival >= 5000 and ival < 10000")) + .getAll().size()); + + for (int i = 0; i < 10_000; i++) + assertEquals(new DbValue(i, "value-" + i, i), cache.get(i)); + } + + /** + * + */ + private static class DbValue implements Serializable { + /** */ + @QuerySqlField(index = true) + private int iVal; + + /** */ + @QuerySqlField(index = true) + private String sVal; + + /** */ + @QuerySqlField + private long lVal; + + /** + * @param iVal Integer value. + * @param sVal String value. + * @param lVal Long value. + */ + private DbValue(int iVal, String sVal, long lVal) { + this.iVal = iVal; + this.sVal = sVal; + this.lVal = lVal; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + DbValue dbVal = (DbValue)o; + + return iVal == dbVal.iVal && lVal == dbVal.lVal && + !(sVal != null ? !sVal.equals(dbVal.sVal) : dbVal.sVal != null); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int res = iVal; + + res = 31 * res + (sVal != null ? sVal.hashCode() : 0); + res = 31 * res + (int)(lVal ^ (lVal >>> 32)); + + return res; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(DbValue.class, this); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java new file mode 100644 index 0000000000000..9fff8c97de7af --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java @@ -0,0 +1,199 @@ +package org.apache.ignite.cache.database.db.file; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.X; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteNoActualWalHistorySelfTest extends GridCommonAbstractTest { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration<>(); + + ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + ccfg.setRebalanceMode(CacheRebalanceMode.SYNC); + ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + + cfg.setCacheConfiguration(ccfg); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + dbCfg.setPageSize(4 * 1024); + + cfg.setMemoryConfiguration(dbCfg); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + pCfg.setWalSegmentSize(4 * 1024 * 1024); + pCfg.setWalHistorySize(2); + pCfg.setWalSegments(10); + + cfg.setPersistenceConfiguration(pCfg); + + cfg.setMarshaller(null); + + BinaryConfiguration binCfg = new BinaryConfiguration(); + + binCfg.setCompactFooter(false); + + cfg.setBinaryConfiguration(binCfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + } + + /** + * @throws Exception if failed. + */ + public void testWalBig() throws Exception { + try { + IgniteEx ignite = startGrid(1); + + IgniteCache cache = ignite.cache(null); + + Random rnd = new Random(); + + Map map = new HashMap<>(); + + for (int i = 0; i < 40_000; i++) { + if (i % 1000 == 0) + X.println(" >> " + i); + + int k = rnd.nextInt(300_000); + IndexedObject v = new IndexedObject(rnd.nextInt(10_000)); + + cache.put(k, v); + map.put(k, v); + } + + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)ignite.context().cache().context() + .database(); + + // Create many checkpoints to clean up the history. + dbMgr.wakeupForCheckpoint("test").get(); + dbMgr.wakeupForCheckpoint("test").get(); + dbMgr.wakeupForCheckpoint("test").get(); + dbMgr.wakeupForCheckpoint("test").get(); + dbMgr.wakeupForCheckpoint("test").get(); + dbMgr.wakeupForCheckpoint("test").get(); + dbMgr.wakeupForCheckpoint("test").get(); + + dbMgr.enableCheckpoints(false).get(); + + for (int i = 0; i < 50; i++) { + int k = rnd.nextInt(300_000); + IndexedObject v = new IndexedObject(rnd.nextInt(10_000)); + + cache.put(k, v); + map.put(k, v); + } + + stopGrid(1); + + ignite = startGrid(1); + + cache = ignite.cache(null); + + // Check. + for (Integer k : map.keySet()) + assertEquals(map.get(k), cache.get(k)); + } + finally { + stopAllGrids(); + } + } + + /** + * + */ + private static class IndexedObject { + /** */ + @QuerySqlField(index = true) + private int iVal; + + /** */ + private byte[] payload = new byte[1024]; + + /** + * @param iVal Integer value. + */ + private IndexedObject(int iVal) { + this.iVal = iVal; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (!(o instanceof IndexedObject)) + return false; + + IndexedObject that = (IndexedObject)o; + + return iVal == that.iVal; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return iVal; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IndexedObject.class, this); + } + } + + /** + * + */ + private enum EnumVal { + /** */ + VAL1, + + /** */ + VAL2, + + /** */ + VAL3 + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalDirectoriesConfigurationTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalDirectoriesConfigurationTest.java new file mode 100644 index 0000000000000..1050f6c029c97 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalDirectoriesConfigurationTest.java @@ -0,0 +1,37 @@ +package org.apache.ignite.cache.database.db.file; + +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteWalDirectoriesConfigurationTest extends GridCommonAbstractTest { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + pCfg.setWalStorePath("test/db/wal"); + + cfg.setPersistenceConfiguration(pCfg); + + return cfg; + } + + /** + * + */ + public void testPartialWalConfigurationNotAllowed() { + try { + startGrid(); + } + catch (Exception ignore) { + return; + } + + fail("Node successfully started with incorrect configuration, exception is expected."); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java new file mode 100644 index 0000000000000..555d3ba1c063d --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java @@ -0,0 +1,357 @@ +package org.apache.ignite.cache.database.db.file; + +import java.util.Map; +import java.util.concurrent.locks.Lock; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.lang.GridAbsPredicate; +import org.apache.ignite.internal.util.typedef.G; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteWalHistoryReservationsSelfTest extends GridCommonAbstractTest { + /** */ + private volatile boolean client; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setClientMode(client); + + MemoryConfiguration memCfg = new MemoryConfiguration(); + + memCfg.setMemoryPolicies(new MemoryPolicyConfiguration().setSize(200 * 1024 * 1024).setName("dfltMemPlc")); + + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(memCfg); + + CacheConfiguration ccfg1 = new CacheConfiguration(); + + ccfg1.setName("cache1"); + ccfg1.setBackups(1); + ccfg1.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + ccfg1.setAffinity(new RendezvousAffinityFunction(false, 32)); + + cfg.setCacheConfiguration(ccfg1); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + stopAllGrids(); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + client = false; + + stopAllGrids(); + + deleteWorkFiles(); + } + + /** + * @throws Exception If failed. + */ + public void testReservedOnExchange() throws Exception { + final int entryCnt = 10_000; + final int initGridCnt = 4; + + final IgniteEx ig0 = (IgniteEx)startGrids(initGridCnt); + + IgniteCache cache = ig0.cache("cache1"); + + for (int k = 0; k < entryCnt; k++) + cache.put(k, k); + + forceCheckpoint(); + + Lock lock = cache.lock(0); + + lock.lock(); + + try { + GridTestUtils.runAsync(new Runnable() { + @Override public void run() { + try { + startGrid(initGridCnt); + } + catch (Exception e) { + fail(e.getMessage()); + } + } + }); + + boolean reserved = GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + for (int g = 0; g < initGridCnt; g++) { + IgniteEx ig = grid(g); + + FileWriteAheadLogManager wal = (FileWriteAheadLogManager)ig.context().cache().context().wal(); + + Object archiver = GridTestUtils.getFieldValue(wal, "archiver"); + + synchronized (archiver) { + Map reserved = GridTestUtils.getFieldValue(archiver, "reserved"); + + if (reserved.isEmpty()) + return false; + } + } + + return true; + } + }, 10_000); + + assert reserved; + } + finally { + lock.unlock(); + } + + boolean released = GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + for (int g = 0; g < initGridCnt; g++) { + IgniteEx ig = grid(g); + + FileWriteAheadLogManager wal = (FileWriteAheadLogManager)ig.context().cache().context().wal(); + + Object archiver = GridTestUtils.getFieldValue(wal, "archiver"); + + synchronized (archiver) { + Map reserved = GridTestUtils.getFieldValue(archiver, "reserved"); + + if (!reserved.isEmpty()) + return false; + } + } + + return true; + } + }, 10_000); + + assert released; + } + + /** + * @throws Exception If failed. + */ + public void testRemovesArePreloadedIfHistoryIsAvailable() throws Exception { + int entryCnt = 10_000; + + Ignite ig0 = startGrids(2); + + IgniteCache cache = ig0.cache("cache1"); + + for (int k = 0; k < entryCnt; k++) + cache.put(k, k); + + forceCheckpoint(); + + stopGrid(1); + + for (int k = 0; k < entryCnt; k += 2) + cache.remove(k); + + forceCheckpoint(); + + Ignite ig1 = startGrid(1); + + IgniteCache cache1 = ig1.cache("cache1"); + + assertEquals(entryCnt / 2, cache.size()); + assertEquals(entryCnt / 2, cache1.size()); + + for (Integer k = 0; k < entryCnt; k++) { + if (k % 2 == 0) { + assertTrue("k=" + k, !cache.containsKey(k)); + assertTrue("k=" + k, !cache1.containsKey(k)); + } + else { + assertEquals("k=" + k, k, cache.get(k)); + assertEquals("k=" + k, k, cache1.get(k)); + } + } + } + + /** + * @throws Exception If failed. + */ + public void testNodeIsClearedIfHistoryIsUnavailable() throws Exception { + int entryCnt = 10_000; + + Ignite ig0 = startGrids(2); + + IgniteCache cache = ig0.cache("cache1"); + + for (int k = 0; k < entryCnt; k++) + cache.put(k, k); + + forceCheckpoint(); + + stopGrid(1); + + for (int k = 0; k < entryCnt; k += 2) + cache.remove(k); + + forceCheckpoint(); + + for (Integer k = 0; k < entryCnt; k++) { + if (k % 2 == 0) + assertTrue("k=" + k, !cache.containsKey(k)); + else + assertEquals("k=" + k, k, cache.get(k)); + } + + Ignite ig1 = startGrid(1); + + IgniteCache cache1 = ig1.cache("cache1"); + + assertEquals(entryCnt / 2, cache.size()); + assertEquals(entryCnt / 2, cache1.size()); + + for (Integer k = 0; k < entryCnt; k++) { + if (k % 2 == 0) { + assertTrue("k=" + k, !cache.containsKey(k)); + assertTrue("k=" + k, !cache1.containsKey(k)); + } + else { + assertEquals("k=" + k, k, cache.get(k)); + assertEquals("k=" + k, k, cache1.get(k)); + } + } + } + + /** + * @throws Exception If failed. + */ + public void testNodeLeftDuringExchange() throws Exception { + final int entryCnt = 10_000; + final int initGridCnt = 4; + + final IgniteEx ig0 = (IgniteEx)startGrids(initGridCnt); + + IgniteCache cache = ig0.cache("cache1"); + + for (int k = 0; k < entryCnt; k++) + cache.put(k, k); + + forceCheckpoint(); + + Lock lock = cache.lock(0); + + lock.lock(); + + try { + GridTestUtils.runAsync(new Runnable() { + @Override public void run() { + try { + startGrid(initGridCnt); + } + catch (Exception e) { + fail(e.getMessage()); + } + } + }); + + boolean reserved = GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + for (int g = 0; g < initGridCnt; g++) { + IgniteEx ig = grid(g); + + FileWriteAheadLogManager wal = (FileWriteAheadLogManager)ig.context().cache().context().wal(); + + Object archiver = GridTestUtils.getFieldValue(wal, "archiver"); + + synchronized (archiver) { + Map reserved = GridTestUtils.getFieldValue(archiver, "reserved"); + + if (reserved.isEmpty()) + return false; + } + } + + return true; + } + }, 10_000); + + assert reserved; + + stopGrid(initGridCnt - 1); + } + finally { + lock.unlock(); + } + + boolean released = GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + for (int g = 0; g < initGridCnt - 1; g++) { + IgniteEx ig = grid(g); + + FileWriteAheadLogManager wal = (FileWriteAheadLogManager)ig.context().cache().context().wal(); + + Object archiver = GridTestUtils.getFieldValue(wal, "archiver"); + + synchronized (archiver) { + Map reserved = GridTestUtils.getFieldValue(archiver, "reserved"); + + if (!reserved.isEmpty()) + return false; + } + } + + return true; + } + }, 10_000); + + assert released; + + awaitPartitionMapExchange(); + } + + /** + * @throws IgniteCheckedException If failed. + */ + private void deleteWorkFiles() throws IgniteCheckedException { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * + */ + private void forceCheckpoint() throws Exception { + for (Ignite ignite : G.allGrids()) { + if (ignite.cluster().localNode().isClient()) + continue; + + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)((IgniteEx)ignite).context() + .cache().context().database(); + + dbMgr.waitForCheckpoint("test"); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java new file mode 100644 index 0000000000000..0a656df3c85b9 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java @@ -0,0 +1,1266 @@ +package org.apache.ignite.cache.database.db.file; + +import java.io.File; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.Callable; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteCompute; +import org.apache.ignite.IgniteException; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageUtils; +import org.apache.ignite.internal.pagemem.wal.WALIterator; +import org.apache.ignite.internal.pagemem.wal.WALPointer; +import org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord; +import org.apache.ignite.internal.pagemem.wal.record.PageSnapshot; +import org.apache.ignite.internal.pagemem.wal.record.WALRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.PA; +import org.apache.ignite.internal.util.typedef.PAX; +import org.apache.ignite.internal.util.typedef.X; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiTuple; +import org.apache.ignite.lang.IgniteCallable; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.lang.IgniteRunnable; +import org.apache.ignite.resources.IgniteInstanceResource; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy; +import org.junit.Assert; +import sun.nio.ch.DirectBuffer; + +/** + * + */ +public class IgniteWalRecoverySelfTest extends GridCommonAbstractTest { + /** */ + private static final String HAS_CACHE = "HAS_CACHE"; + + /** */ + private static final int LARGE_ARR_SIZE = 1025; + + /** */ + private boolean fork; + + /** */ + private String cacheName; + + /** */ + private int walSegmentSize; + + /** {@inheritDoc} */ + @Override protected boolean isMultiJvm() { + return fork; + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration<>(cacheName); + + ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + ccfg.setRebalanceMode(CacheRebalanceMode.SYNC); + ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + ccfg.setNodeFilter(new RemoteNodeFilter()); + ccfg.setIndexedTypes(Integer.class, IndexedObject.class); + + cfg.setCacheConfiguration(ccfg); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + dbCfg.setPageSize(4 * 1024); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(1024 * 1024 * 1024); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + if (walSegmentSize != 0) + pCfg.setWalSegmentSize(walSegmentSize); + + cfg.setPersistenceConfiguration(pCfg); + + cfg.setMarshaller(null); + + BinaryConfiguration binCfg = new BinaryConfiguration(); + + binCfg.setCompactFooter(false); + + cfg.setBinaryConfiguration(binCfg); + + if (!getTestIgniteInstanceName(0).equals(gridName)) + cfg.setUserAttributes(F.asMap(HAS_CACHE, true)); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + cacheName = "partitioned"; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @throws Exception if failed. + */ + public void testWalBig() throws Exception { + try { + IgniteEx ignite = startGrid(1); + + IgniteCache cache = ignite.cache("partitioned"); + + Random rnd = new Random(); + + Map map = new HashMap<>(); + + for (int i = 0; i < 10_000; i++) { + if (i % 1000 == 0) + X.println(" >> " + i); + + int k = rnd.nextInt(300_000); + IndexedObject v = new IndexedObject(rnd.nextInt(10_000)); + + cache.put(k, v); + map.put(k, v); + } + + // Check. + for (Integer k : map.keySet()) + assertEquals(map.get(k), cache.get(k)); + + stopGrid(1); + + ignite = startGrid(1); + + cache = ignite.cache("partitioned"); + + // Check. + for (Integer k : map.keySet()) + assertEquals(map.get(k), cache.get(k)); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If fail. + */ + public void testSwitchClassLoader() throws Exception { + try { + final IgniteEx igniteEx = startGrid(1); + + // CustomDiscoveryMessage will trigger service tasks + startGrid(2); + + IgniteCache cache = igniteEx.cache("partitioned"); + + // Creates LoadCacheJobV2 +// cache.loadCache(null); + + final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); + final ClassLoader newCl = getExternalClassLoader(); + + Thread.currentThread().setContextClassLoader(newCl); + + for (int i = 0; i < 10; i++) + cache.put(i, i % 2 == 0 ? EnumVal.VAL1 : EnumVal.VAL2); + + for (int i = 0; i < 10; i++) + assert cache.containsKey(i); + + // Invokes ClearTask with new class loader + cache.clear(); + + Thread.currentThread().setContextClassLoader(oldCl); + + for (int i = 0; i < 10; i++) + cache.put(i, i % 2 == 0 ? EnumVal.VAL1 : EnumVal.VAL2); + + for (int i = 0; i < 10; i++) + assert cache.containsKey(i); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + public void testWalSimple() throws Exception { + try { + IgniteEx ignite = startGrid(1); + + IgniteCache cache = ignite.cache("partitioned"); + + info(" --> step1"); + + for (int i = 0; i < 10_000; i += 2) { +// X.println(" -> put: " + i); + + cache.put(i, new IndexedObject(i)); + } + + info(" --> step2"); + + for (int i = 0; i < 10_000; i += 3) + cache.put(i, new IndexedObject(i * 2)); + + info(" --> step3"); + + for (int i = 0; i < 10_000; i += 7) + cache.put(i, new IndexedObject(i * 3)); + + info(" --> check1"); + + // Check. + for (int i = 0; i < 10_000; i++) { + IndexedObject o; + + if (i % 7 == 0) + o = new IndexedObject(i * 3); + else if (i % 3 == 0) + o = new IndexedObject(i * 2); + else if (i % 2 == 0) + o = new IndexedObject(i); + else + o = null; + + assertEquals(o, cache.get(i)); + } + + stopGrid(1); + + ignite = startGrid(1); + + cache = ignite.cache("partitioned"); + + info(" --> check2"); + + // Check. + for (int i = 0; i < 10_000; i++) { + IndexedObject o; + + if (i % 7 == 0) + o = new IndexedObject(i * 3); + else if (i % 3 == 0) + o = new IndexedObject(i * 2); + else if (i % 2 == 0) + o = new IndexedObject(i); + else + o = null; + + assertEquals(o, cache.get(i)); + } + + info(" --> ok"); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If fail. + */ + public void testWalLargeValue() throws Exception { + try { + IgniteEx ignite = startGrid(1); + + IgniteCache cache = ignite.cache("partitioned"); + + for (int i = 0; i < 10_000; i++) { + final byte[] data = new byte[i]; + + Arrays.fill(data, (byte)i); + + cache.put(i, data); + + if (i % 1000 == 0) + X.println(" ---> put: " + i); + +// Assert.assertArrayEquals(data, (byte[])cache.get(i)); + } + +// info(" --> check1"); +// +// for (int i = 0; i < 25_000; i++) { +// final byte[] data = new byte[i]; +// +// Arrays.fill(data, (byte)i); +// +// final byte[] loaded = (byte[]) cache.get(i); +// +// Assert.assertArrayEquals(data, loaded); +// } + + stopGrid(1); + + ignite = startGrid(1); + + cache = ignite.cache("partitioned"); + + info(" --> check2"); + + for (int i = 0; i < 10_000; i++) { + final byte[] data = new byte[i]; + + Arrays.fill(data, (byte)i); + + final byte[] loaded = (byte[]) cache.get(i); + + Assert.assertArrayEquals(data, loaded); + + if (i % 1000 == 0) + X.println(" ---> get: " + i); + } + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + public void testWalRolloverMultithreadedDefault() throws Exception { + checkWalRolloverMultithreaded(false); + } + + /** + * @throws Exception if failed. + */ + public void testWalRolloverMultithreadedLogOnly() throws Exception { + checkWalRolloverMultithreaded(true); + } + + /** + * @throws Exception if failed. + */ + public void testHugeCheckpointRecord() throws Exception { + try { + System.setProperty("GRIDGAIN_DB_WAL_MODE", "LOG_ONLY"); + + final IgniteEx ignite = startGrid(1); + + for (int i = 0; i < 50; i++) { + CacheConfiguration ccfg = new CacheConfiguration<>("cache-" + i); + + // We can get 'too many open files' with default number of partitions. + ccfg.setAffinity(new RendezvousAffinityFunction(false, 128)); + + IgniteCache cache = ignite.getOrCreateCache(ccfg); + + cache.put(i, i); + } + + final long endTime = System.currentTimeMillis() + 30_000; + + IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable() { + @Override public Void call() throws Exception { + Random rnd = ThreadLocalRandom.current(); + + while (U.currentTimeMillis() < endTime) { + IgniteCache cache = ignite.cache("cache-" + rnd.nextInt(50)); + + cache.put(rnd.nextInt(50_000), rnd.nextInt()); + } + + return null; + } + }, 16, "put-thread"); + + while (System.currentTimeMillis() < endTime) { + ignite.context().cache().context().database().wakeupForCheckpoint("test").get(); + + U.sleep(500); + } + + fut.get(); + } + finally { + System.clearProperty("GRIDGAIN_DB_WAL_MODE"); + + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + private void checkWalRolloverMultithreaded(boolean logOnly) throws Exception { + if (logOnly) + System.setProperty("GRIDGAIN_DB_WAL_MODE", "LOG_ONLY"); + + walSegmentSize = 2 * 1024 * 1024; + + final long endTime = System.currentTimeMillis() + 3 * 60 * 1000; + + try { + IgniteEx ignite = startGrid(1); + + final IgniteCache cache = ignite.cache("partitioned"); + + GridTestUtils.runMultiThreaded(new Callable() { + @Override public Void call() throws Exception { + Random rnd = ThreadLocalRandom.current(); + + while (U.currentTimeMillis() < endTime) + cache.put(rnd.nextInt(50_000), rnd.nextInt()); + + return null; + } + }, 16, "put-thread"); + } + finally { + System.clearProperty("GRIDGAIN_DB_WAL_MODE"); + + stopAllGrids(); + } + } + + /** + * @throws Exception If fail. + */ + public void testWalRenameDirSimple() throws Exception { + try { + IgniteEx ignite = startGrid(1); + + IgniteCache cache = ignite.cache("partitioned"); + + for (int i = 0; i < 100; i++) + cache.put(i, new IndexedObject(i)); + + stopGrid(1); + + final File cacheDir = cacheDir("partitioned", ignite.context().discovery().consistentId().toString()); + + final boolean renamed = cacheDir.renameTo(new File(cacheDir.getParent(), "cache-partitioned0")); + + assert renamed; + + cacheName = "partitioned0"; + + ignite = startGrid(1); + + cache = ignite.cache(cacheName); + + for (int i = 0; i < 100; i++) + assertEquals(new IndexedObject(i), cache.get(i)); + } + finally { + stopAllGrids(); + } + } + + /** + * @param cacheName Cache name. + * @param consId Consistent ID. + * @return Cache dir. + * @throws IgniteCheckedException If fail. + */ + private File cacheDir(final String cacheName, String consId) throws IgniteCheckedException { + consId = consId.replaceAll("[\\.:]", "_"); + + final File dbDir = U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false); + + assert dbDir.exists(); + + final File consIdDir = new File(dbDir.getAbsolutePath(), consId); + + assert consIdDir.exists(); + + final File cacheDir = new File(consIdDir.getAbsolutePath(), "cache-" + cacheName); + + assert cacheDir.exists(); + + return cacheDir; + } + + /** + * @throws Exception if failed. + */ + public void testRecoveryNoCheckpoint() throws Exception { + try { + IgniteEx ctrlGrid = startGrid(0); + + fork = true; + + IgniteEx cacheGrid = startGrid(1); + + ctrlGrid.compute(ctrlGrid.cluster().forRemotes()).run(new LoadRunnable(false)); + + info("Killing remote process..."); + + ((IgniteProcessProxy)cacheGrid).kill(); + + final IgniteEx g0 = ctrlGrid; + + GridTestUtils.waitForCondition(new PA() { + /** {@inheritDoc} */ + @Override public boolean apply() { + return g0.cluster().nodes().size() == 1; + } + }, getTestTimeout()); + + fork = false; + + // Now start the grid and verify that updates were restored from WAL. + cacheGrid = startGrid(1); + + IgniteCache cache = cacheGrid.cache("partitioned"); + + for (int i = 0; i < 10_000; i++) + assertEquals(new IndexedObject(i), cache.get(i)); + + List> res = cache.query(new SqlFieldsQuery("select count(iVal) from IndexedObject")).getAll(); + + assertEquals(1, res.size()); + assertEquals(10_000L, res.get(0).get(0)); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + public void testRecoveryLargeNoCheckpoint() throws Exception { + try { + IgniteEx ctrlGrid = startGrid(0); + + fork = true; + + IgniteEx cacheGrid = startGrid(1); + + ctrlGrid.compute(ctrlGrid.cluster().forRemotes()).run(new LargeLoadRunnable(false)); + + info("Killing remote process..."); + + ((IgniteProcessProxy)cacheGrid).kill(); + + final IgniteEx g0 = ctrlGrid; + + GridTestUtils.waitForCondition(new PA() { + /** {@inheritDoc} */ + @Override public boolean apply() { + return g0.cluster().nodes().size() == 1; + } + }, getTestTimeout()); + + fork = false; + + // Now start the grid and verify that updates were restored from WAL. + cacheGrid = startGrid(1); + + IgniteCache cache = cacheGrid.cache("partitioned"); + + for (int i = 0; i < 1000; i++) { + final long[] data = new long[LARGE_ARR_SIZE]; + + Arrays.fill(data, i); + + final long[] loaded = (long[]) cache.get(i); + + Assert.assertArrayEquals(data, loaded); + } + } + finally { + stopAllGrids(); + } + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return TimeUnit.MINUTES.toMillis(20); + } + + /** + * @throws Exception if failed. + */ + public void testRandomCrash() throws Exception { + try { + IgniteEx ctrlGrid = startGrid(0); + + fork = true; + + IgniteEx cacheGrid = startGrid(1); + + IgniteCompute rmt = ctrlGrid.compute(ctrlGrid.cluster().forRemotes()); + + rmt.run(new LoadRunnable(false)); + + info(">>> Finished cache population."); + + rmt.run(new AsyncLoadRunnable()); + + Thread.sleep(20_000); + + info(">>> Killing remote process..."); + + ((IgniteProcessProxy)cacheGrid).kill(); + + startGrid(1); + + Boolean res = rmt.call(new VerifyCallable()); + + assertTrue(res); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + public void testLargeRandomCrash() throws Exception { + try { + IgniteEx ctrlGrid = startGrid(0); + + fork = true; + + IgniteEx cacheGrid = startGrid(1); + + IgniteCompute rmt = ctrlGrid.compute(ctrlGrid.cluster().forRemotes()); + + rmt.run(new LargeLoadRunnable(false)); + + info(">>> Finished cache population."); + + rmt.run(new AsyncLargeLoadRunnable()); + + Thread.sleep(20_000); + + info(">>> Killing remote process..."); + + ((IgniteProcessProxy)cacheGrid).kill(); + + startGrid(1); + + Boolean res = rmt.call(new VerifyLargeCallable()); + + assertTrue(res); + } + finally { + stopAllGrids(); + } + } + + /** + * + */ + private static class RemoteNodeFilter implements IgnitePredicate { + /** {@inheritDoc} */ + @Override public boolean apply(ClusterNode clusterNode) { + return clusterNode.attribute(HAS_CACHE) != null; + } + } + + /** + * @throws Exception If failed. + */ + public void testDestroyCache() throws Exception { + try { + IgniteEx ignite = startGrid(1); + + IgniteCache cache = ignite.getOrCreateCache("test"); + + cache.put(1, new IndexedObject(1)); + + ignite.destroyCache("test"); + + cache = ignite.getOrCreateCache("test"); + + // No entry available after cache destroy. + assertNull(cache.get(1)); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If fail. + */ + public void testEvictPartition() throws Exception { + try { + Ignite ignite1 = startGrid("node1"); + + IgniteCache cache1 = ignite1.cache(cacheName); + + for (int i = 0; i < 100; i++) + cache1.put(i, new IndexedObject(i)); + + Ignite ignite2 = startGrid("node2"); + + IgniteCache cache2 = ignite2.cache(cacheName); + + for (int i = 0; i < 100; i++) { + assertEquals(new IndexedObject(i), cache1.get(i)); + assertEquals(new IndexedObject(i), cache2.get(i)); + } + + ignite1.close(); + ignite2.close(); + + ignite1 = startGrid("node1"); + ignite2 = startGrid("node2"); + + cache1 = ignite1.cache(cacheName); + cache2 = ignite2.cache(cacheName); + + for (int i = 0; i < 100; i++) { + assertEquals(new IndexedObject(i), cache1.get(i)); + assertEquals(new IndexedObject(i), cache2.get(i)); + } + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + public void testApplyDeltaRecords() throws Exception { + try { + IgniteEx ignite0 = (IgniteEx)startGrid("node0"); + + IgniteCache cache0 = ignite0.cache(cacheName); + + for (int i = 0; i < 1000; i++) + cache0.put(i, new IndexedObject(i)); + + GridCacheSharedContext sharedCtx = ignite0.context().cache().context(); + + GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)sharedCtx.database(); + + db.waitForCheckpoint("test"); + db.enableCheckpoints(false).get(); + + // Log something to know where to start. + WALPointer ptr = sharedCtx.wal().log(new MemoryRecoveryRecord(U.currentTimeMillis())); + + info("Replay marker: " + ptr); + + for (int i = 1000; i < 5000; i++) + cache0.put(i, new IndexedObject(i)); + + info("Done puts..."); + + for (int i = 2_000; i < 3_000; i++) + cache0.remove(i); + + info("Done removes..."); + + for (int i = 5000; i < 6000; i++) + cache0.put(i, new IndexedObject(i)); + + info("Done puts..."); + + Map rolledPages = new HashMap<>(); + + int pageSize = sharedCtx.database().pageSize(); + + ByteBuffer buf1 = ByteBuffer.allocateDirect(pageSize); + + // Now check that deltas can be correctly applied. + try (WALIterator it = sharedCtx.wal().replay(ptr)) { + while (it.hasNext()) { + IgniteBiTuple tup = it.next(); + + WALRecord rec = tup.get2(); + + if (rec instanceof PageSnapshot) { + PageSnapshot page = (PageSnapshot)rec; + + rolledPages.put(page.fullPageId(), page.pageData()); + } + else if (rec instanceof PageDeltaRecord) { + PageDeltaRecord delta = (PageDeltaRecord)rec; + + FullPageId fullId = new FullPageId(delta.pageId(), delta.cacheId()); + + byte[] pageData = rolledPages.get(fullId); + + if (pageData == null) { + pageData = new byte[pageSize]; + + rolledPages.put(fullId, pageData); + } + + assertNotNull("Missing page snapshot [page=" + fullId + ", delta=" + delta + ']', pageData); + + buf1.order(ByteOrder.nativeOrder()); + + buf1.position(0); + buf1.put(pageData); + buf1.position(0); + + delta.applyDelta(sharedCtx + .database() + .memoryPolicy(null) + .pageMemory(), + + ((DirectBuffer)buf1).address()); + + buf1.position(0); + + buf1.get(pageData); + } + } + } + + info("Done apply..."); + + PageMemoryEx pageMem = (PageMemoryEx)db.memoryPolicy(null).pageMemory(); + + for (Map.Entry entry : rolledPages.entrySet()) { + FullPageId fullId = entry.getKey(); + + ignite0.context().cache().context().database().checkpointReadLock(); + + try { + long page = pageMem.acquirePage(fullId.cacheId(), fullId.pageId(), true); + + try { + long buf = pageMem.writeLock(fullId.cacheId(), fullId.pageId(), page, true); + + try { + byte[] data = entry.getValue(); + + for (int i = 0; i < data.length; i++) { + if (fullId.pageId() == TrackingPageIO.VERSIONS.latest().trackingPageFor(fullId.pageId(), db.pageSize())) + continue; // Skip tracking pages. + + assertEquals("page=" + fullId + ", pos=" + i, PageUtils.getByte(buf, i), data[i]); + } + } + finally { + pageMem.writeUnlock(fullId.cacheId(), fullId.pageId(), page, null, false, true); + } + } + finally { + pageMem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + finally { + ignite0.context().cache().context().database().checkpointReadUnlock(); + } + } + + ignite0.close(); + } + finally { + stopAllGrids(); + } + } + + /** + * + */ + private static class LoadRunnable implements IgniteRunnable { + /** */ + @IgniteInstanceResource + private Ignite ignite; + + /** */ + private boolean disableCheckpoints; + + /** + * @param disableCheckpoints Disable checkpoints flag. + */ + private LoadRunnable(boolean disableCheckpoints) { + this.disableCheckpoints = disableCheckpoints; + } + + /** {@inheritDoc} */ + @Override public void run() { + ignite.log().info("Started load."); + + if (disableCheckpoints) { + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)((IgniteEx)ignite).context() + .cache().context().database(); + + try { + dbMgr.enableCheckpoints(false).get(); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + } + + try { + boolean successfulWaiting = GridTestUtils.waitForCondition(new PAX() { + @Override public boolean applyx() { + return ignite.cache("partitioned") != null; + } + }, 10_000); + + assertTrue(successfulWaiting); + } + catch (IgniteInterruptedCheckedException e) { + throw new RuntimeException(e); + } + + IgniteCache cache = ignite.cache("partitioned"); + + for (int i = 0; i < 10_000; i++) + cache.put(i, new IndexedObject(i)); + + ignite.log().info("Finished load."); + } + } + + /** + * + */ + private static class AsyncLoadRunnable implements IgniteRunnable { + /** */ + @IgniteInstanceResource + private Ignite ignite; + + /** {@inheritDoc} */ + @Override public void run() { + try { + boolean successfulWaiting = GridTestUtils.waitForCondition(new PAX() { + @Override public boolean applyx() { + return ignite.cache("partitioned") != null; + } + }, 10_000); + + assertTrue(successfulWaiting); + } + catch (IgniteInterruptedCheckedException e) { + throw new RuntimeException(e); + } + + ignite.log().info(">>>>>>> Started load."); + + for (int i = 0; i < 4; i++) { + ignite.scheduler().callLocal(new Callable() { + @Override public Object call() throws Exception { + IgniteCache cache = ignite.cache("partitioned"); + + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + int cnt = 0; + + while (!Thread.currentThread().isInterrupted()) { + cache.put(rnd.nextInt(10_000), new IndexedObject(rnd.nextInt())); + + cnt++; + + if (cnt > 0 && cnt % 1_000 == 0) + ignite.log().info(">>>> Updated: " + cnt); + } + + return null; + } + }); + } + } + } + + /** + * + */ + private static class VerifyCallable implements IgniteCallable { + /** */ + @IgniteInstanceResource + private Ignite ignite; + + /** {@inheritDoc} */ + @Override public Boolean call() throws Exception { + try { + boolean successfulWaiting = GridTestUtils.waitForCondition(new PAX() { + @Override public boolean applyx() { + return ignite.cache("partitioned") != null; + } + }, 10_000); + + assertTrue(successfulWaiting); + } + catch (IgniteInterruptedCheckedException e) { + throw new RuntimeException(e); + } + + IgniteCache cache = ignite.cache("partitioned"); + + for (int i = 0; i < 10_000; i++) { + Object val = cache.get(i); + + if (val == null) { + ignite.log().warning("Failed to find a value for key: " + i); + + return false; + } + } + + return true; + } + } + + /** + * + */ + private static class LargeLoadRunnable implements IgniteRunnable { + /** */ + @IgniteInstanceResource + private Ignite ignite; + + /** */ + private boolean disableCheckpoints; + + /** + * @param disableCheckpoints Disable checkpoints flag. + */ + private LargeLoadRunnable(boolean disableCheckpoints) { + this.disableCheckpoints = disableCheckpoints; + } + + /** {@inheritDoc} */ + @Override public void run() { + try { + boolean successfulWaiting = GridTestUtils.waitForCondition(new PAX() { + @Override public boolean applyx() { + return ignite.cache("partitioned") != null; + } + }, 10_000); + + assertTrue(successfulWaiting); + } + catch (IgniteInterruptedCheckedException e) { + throw new RuntimeException(e); + } + + ignite.log().info("Started load."); + + if (disableCheckpoints) { + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)((IgniteEx)ignite).context() + .cache().context().database(); + + dbMgr.enableCheckpoints(false); + } + + IgniteCache cache = ignite.cache("partitioned"); + + for (int i = 0; i < 1000; i++) { + final long[] data = new long[LARGE_ARR_SIZE]; + + Arrays.fill(data, i); + + cache.put(i, data); + } + + ignite.log().info("Finished load."); + } + } + + /** + * + */ + private static class AsyncLargeLoadRunnable implements IgniteRunnable { + /** */ + @IgniteInstanceResource + private Ignite ignite; + + /** {@inheritDoc} */ + @Override public void run() { + try { + boolean successfulWaiting = GridTestUtils.waitForCondition(new PAX() { + @Override public boolean applyx() { + return ignite.cache("partitioned") != null; + } + }, 10_000); + + assertTrue(successfulWaiting); + } + catch (IgniteInterruptedCheckedException e) { + throw new RuntimeException(e); + } + + ignite.log().info(">>>>>>> Started load."); + + for (int i = 0; i < 1; i++) { + ignite.scheduler().callLocal(new Callable() { + @Override public Object call() throws Exception { + IgniteCache cache = ignite.cache("partitioned"); + + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + int cnt = 0; + + while (!Thread.currentThread().isInterrupted()) { + final long[] data = new long[LARGE_ARR_SIZE]; + + final int key = rnd.nextInt(1000); + + Arrays.fill(data, key); + +// System.out.println("> " + key); + + cache.put(key, data); + + cnt++; + + if (cnt > 0 && cnt % 1_000 == 0) + ignite.log().info(">>>> Updated: " + cnt); + } + + return null; + } + }); + } + } + } + + /** + * + */ + private static class VerifyLargeCallable implements IgniteCallable { + /** */ + @IgniteInstanceResource + private Ignite ignite; + + /** {@inheritDoc} */ + @Override public Boolean call() throws Exception { + try { + boolean successfulWaiting = GridTestUtils.waitForCondition(new PAX() { + @Override public boolean applyx() { + return ignite.cache("partitioned") != null; + } + }, 10_000); + + assertTrue(successfulWaiting); + } + catch (IgniteInterruptedCheckedException e) { + throw new RuntimeException(e); + } + + IgniteCache cache = ignite.cache("partitioned"); + + for (int i = 0; i < 1000; i++) { + final long[] data = new long[LARGE_ARR_SIZE]; + + Arrays.fill(data, i); + + final Object val = cache.get(i); + + if (val == null) { + ignite.log().warning("Failed to find a value for key: " + i); + + return false; + } + } + + return true; + } + } + + + /** + * + */ + private static class IndexedObject { + /** */ + @QuerySqlField(index = true) + private int iVal; + + /** + * @param iVal Integer value. + */ + private IndexedObject(int iVal) { + this.iVal = iVal; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (!(o instanceof IndexedObject)) + return false; + + IndexedObject that = (IndexedObject)o; + + return iVal == that.iVal; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return iVal; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IndexedObject.class, this); + } + } + + /** + * + */ + private enum EnumVal { + /** */ + VAL1, + + /** */ + VAL2, + + /** */ + VAL3 + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java new file mode 100644 index 0000000000000..109d6123bfc81 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java @@ -0,0 +1,332 @@ +package org.apache.ignite.cache.database.db.file; + +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteWalRecoverySeveralRestartsTest extends GridCommonAbstractTest { + /** */ + public static final int PAGE_SIZE = 1024; + + /** */ + private static final int KEYS_COUNT = 100_000; + + /** */ + private static final int LARGE_KEYS_COUNT = 5_000; + + /** */ + private static final Random rnd = new Random(System.currentTimeMillis()); + + /** */ + private String cacheName = "test"; + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return 3600_000; + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration<>(cacheName); + + ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg.setRebalanceMode(CacheRebalanceMode.NONE); + ccfg.setIndexedTypes(Integer.class, IndexedObject.class); + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + ccfg.setAffinity(new RendezvousAffinityFunction(false, 64 * 4)); // 64 per node + ccfg.setReadFromBackup(true); + + cfg.setCacheConfiguration(ccfg); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + dbCfg.setPageSize(PAGE_SIZE); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(500 * 1024 * 1024); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + cfg.setPersistenceConfiguration(pCfg); + + cfg.setMarshaller(null); + + BinaryConfiguration binCfg = new BinaryConfiguration(); + + binCfg.setCompactFooter(false); + + cfg.setBinaryConfiguration(binCfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + super.beforeTest(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @throws Exception if failed. + */ + public void testWalRecoverySeveralRestarts() throws Exception { + try { + IgniteEx ignite = startGrid(1); + + Random locRandom = ThreadLocalRandom.current(); + + try (IgniteDataStreamer dataLdr = ignite.dataStreamer(cacheName)) { + for (int i = 0; i < KEYS_COUNT; ++i) { + if (i % (KEYS_COUNT / 100) == 0) + info("Loading " + i * 100 / KEYS_COUNT + "%"); + + dataLdr.addData(i, new IndexedObject(i)); + } + } + + int size = ignite.cache(cacheName).size(); + + for (int restartCnt = 0; restartCnt < 5; ++restartCnt) { + stopGrid(1, true); + + info("Restart #" + restartCnt); + U.sleep(500); + + ignite = startGrid(1); + + IgniteCache cache = ignite.cache(cacheName); + + assertEquals(size, cache.size()); + + info("Restart #" + restartCnt); + + for (int i = 0; i < KEYS_COUNT / 100; ++i) { + assertNotNull(cache.get(locRandom.nextInt(KEYS_COUNT / 100))); + + cache.put(locRandom.nextInt(KEYS_COUNT / 100), new IndexedObject(locRandom.nextInt(KEYS_COUNT / 100))); + } + + cache.put(KEYS_COUNT + restartCnt, new IndexedObject(KEYS_COUNT + restartCnt)); + + // Check recovery for partition meta pages. + size = cache.size(); + } + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + public void testWalRecoveryWithDynamicCache() throws Exception { + try { + IgniteEx ignite = startGrid(1); + + CacheConfiguration dynCacheCfg = new CacheConfiguration<>(); + + dynCacheCfg.setName("dyncache"); + dynCacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + dynCacheCfg.setRebalanceMode(CacheRebalanceMode.NONE); + dynCacheCfg.setIndexedTypes(Integer.class, IndexedObject.class); + dynCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + dynCacheCfg.setAffinity(new RendezvousAffinityFunction(false, 64 * 4)); // 64 per node + dynCacheCfg.setReadFromBackup(true); + + ignite.getOrCreateCache(dynCacheCfg); + + try (IgniteDataStreamer dataLdr = ignite.dataStreamer("dyncache")) { + for (int i = 0; i < KEYS_COUNT; ++i) { + if (i % (KEYS_COUNT / 100) == 0) + info("Loading " + i * 100 / KEYS_COUNT + "%"); + + dataLdr.addData(i, new IndexedObject(i)); + } + } + + for (int restartCnt = 0; restartCnt < 5; ++restartCnt) { + stopGrid(1, true); + + info("Restart #" + restartCnt); + U.sleep(500); + + ignite = startGrid(1); + + ThreadLocalRandom locRandom = ThreadLocalRandom.current(); + + IgniteCache cache = ignite.getOrCreateCache(dynCacheCfg); + + for (int i = 0; i < KEYS_COUNT; ++i) + assertNotNull(cache.get(locRandom.nextInt(KEYS_COUNT))); + } + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + public void testWalRecoveryWithDynamicCacheLargeObjects() throws Exception { + try { + IgniteEx ignite = startGrid(1); + + CacheConfiguration dynCacheCfg = new CacheConfiguration<>(); + + dynCacheCfg.setName("dyncache"); + dynCacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + dynCacheCfg.setRebalanceMode(CacheRebalanceMode.NONE); + dynCacheCfg.setIndexedTypes(Integer.class, IndexedObject.class); + dynCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + dynCacheCfg.setAffinity(new RendezvousAffinityFunction(false, 64 * 4)); // 64 per node + dynCacheCfg.setReadFromBackup(true); + + ignite.getOrCreateCache(dynCacheCfg); + + try (IgniteDataStreamer dataLdr = ignite.dataStreamer("dyncache")) { + for (int i = 0; i < LARGE_KEYS_COUNT; ++i) { + if (i % (LARGE_KEYS_COUNT / 100) == 0) + info("Loading " + i * 100 / LARGE_KEYS_COUNT + "%"); + + IndexedObject obj = new IndexedObject(i); + + obj.payload = new byte[PAGE_SIZE + 2]; + + dataLdr.addData(i, obj); + } + } + + for (int restartCnt = 0; restartCnt < 5; ++restartCnt) { + stopGrid(1, true); + + info("Restart #" + restartCnt); + U.sleep(500); + + ignite = startGrid(1); + + ThreadLocalRandom locRandom = ThreadLocalRandom.current(); + + IgniteCache cache = ignite.getOrCreateCache(dynCacheCfg); + + for (int i = 0; i < LARGE_KEYS_COUNT; ++i) { + IndexedObject val = cache.get(locRandom.nextInt(LARGE_KEYS_COUNT)); + + assertNotNull(val); + + assertEquals(PAGE_SIZE + 2, val.payload.length); + } + } + } + finally { + stopAllGrids(); + } + } + + /** + * + */ + private static class IndexedObject { + /** */ + @QuerySqlField(index = true) + private int iVal; + + /** */ + @QuerySqlField(index = true) + private String strVal0; + + /** */ + @QuerySqlField(index = true) + private String strVal1; + + /** */ + private byte[] payload; + + /** + * @param iVal Integer value. + */ + private IndexedObject(int iVal) { + this.iVal = iVal; + + strVal0 = "String value #0 " + iVal + " " + GridTestUtils.randomString(rnd, 256); + strVal1 = GridTestUtils.randomString(rnd, 256); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + IndexedObject obj = (IndexedObject)o; + + if (iVal != obj.iVal) + return false; + + if (strVal0 != null ? !strVal0.equals(obj.strVal0) : obj.strVal0 != null) + return false; + + return strVal1 != null ? strVal1.equals(obj.strVal1) : obj.strVal1 == null; + + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int res = iVal; + + res = 31 * res + (strVal0 != null ? strVal0.hashCode() : 0); + res = 31 * res + (strVal1 != null ? strVal1.hashCode() : 0); + + return res; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IndexedObject.class, this); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java new file mode 100644 index 0000000000000..9cf97016acc07 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java @@ -0,0 +1,985 @@ +package org.apache.ignite.cache.database.db.file; + +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.nio.ByteOrder; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdAllocator; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.pagemem.PageUtils; +import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +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.internal.pagemem.store.IgnitePageStoreManager; +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.pagemem.wal.WALIterator; +import org.apache.ignite.internal.pagemem.wal.WALPointer; +import org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord; +import org.apache.ignite.internal.pagemem.wal.record.DataEntry; +import org.apache.ignite.internal.pagemem.wal.record.DataRecord; +import org.apache.ignite.internal.pagemem.wal.record.PageSnapshot; +import org.apache.ignite.internal.pagemem.wal.record.WALRecord; +import org.apache.ignite.internal.processors.cache.CacheObject; +import org.apache.ignite.internal.processors.cache.CacheObjectContext; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheOperation; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiTuple; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class PageStoreCheckpointSimulationSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final int TOTAL_PAGES = 1000; + + /** */ + private static final boolean VERBOSE = false; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration("partitioned"); + + ccfg.setRebalanceMode(CacheRebalanceMode.NONE); + + cfg.setCacheConfiguration(ccfg); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + cfg.setMemoryConfiguration(dbCfg); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + pCfg.setCheckpointFrequency(500); + + cfg.setPersistenceConfiguration(pCfg); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(discoSpi); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + stopAllGrids(); + + deleteWorkFiles(); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES, "true"); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES); + + stopAllGrids(); + + deleteWorkFiles(); + } + + /** + * @throws Exception if failed. + */ + public void testCheckpointSimulationMultiThreaded() throws Exception { + IgniteEx ig = startGrid(0); + + GridCacheSharedContext shared = ig.context().cache().context(); + + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)shared.database(); + + IgnitePageStoreManager pageStore = shared.pageStore(); + + U.sleep(1_000); + + // Disable integrated checkpoint thread. + dbMgr.enableCheckpoints(false).get(); + + // Must put something in partition 0 in order to initialize meta page. + // Otherwise we will violate page store integrity rules. + ig.cache("partitioned").put(0, 0); + + PageMemory mem = shared.database().memoryPolicy(null).pageMemory(); + + IgniteBiTuple, WALPointer> res; + + try { + res = runCheckpointing(ig, (PageMemoryImpl)mem, pageStore, shared.wal(), + shared.cache().cache("partitioned").context().cacheId()); + } + catch (Throwable th) { + log().error("Error while running checkpointing", th); + + throw th; + } + finally { + dbMgr.enableCheckpoints(true).get(); + + stopAllGrids(false); + } + + ig = startGrid(0); + + shared = ig.context().cache().context(); + + dbMgr = (GridCacheDatabaseSharedManager)shared.database(); + + dbMgr.enableCheckpoints(false).get(); + + mem = shared.database().memoryPolicy(null).pageMemory(); + + verifyReads(res.get1(), mem, res.get2(), shared.wal()); + } + + /** + * @throws Exception if failed. + */ + public void testGetForInitialWrite() throws Exception { + IgniteEx ig = startGrid(0); + + GridCacheSharedContext shared = ig.context().cache().context(); + + int cacheId = shared.cache().cache("partitioned").context().cacheId(); + + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)shared.database(); + + // Disable integrated checkpoint thread. + dbMgr.enableCheckpoints(false); + + PageMemory mem = shared.database().memoryPolicy(null).pageMemory(); + + IgniteWriteAheadLogManager wal = shared.wal(); + + WALPointer start = wal.log(new CheckpointRecord(null, false)); + + final FullPageId[] initWrites = new FullPageId[10]; + + ig.context().cache().context().database().checkpointReadLock(); + + try { + for (int i = 0; i < initWrites.length; i++) + initWrites[i] = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId); + + // Check getForInitialWrite methods. + for (FullPageId fullId : initWrites) { + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + try { + long pageAddr = mem.writeLock(fullId.cacheId(), fullId.pageId(), page); + + try { + DataPageIO.VERSIONS.latest().initNewPage(pageAddr, fullId.pageId(), mem.pageSize()); + + for (int i = PageIO.COMMON_HEADER_END; i < mem.pageSize(); i++) + PageUtils.putByte(pageAddr, i, (byte)0xAB); + } + finally { + mem.writeUnlock(fullId.cacheId(), fullId.pageId(), page, null, true); + } + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + + wal.fsync(null); + } + finally { + ig.context().cache().context().database().checkpointReadUnlock(); + stopAllGrids(false); + } + + ig = startGrid(0); + + shared = ig.context().cache().context(); + + dbMgr = (GridCacheDatabaseSharedManager)shared.database(); + + dbMgr.enableCheckpoints(false); + + wal = shared.wal(); + + try (WALIterator it = wal.replay(start)) { + it.nextX(); + + for (FullPageId initialWrite : initWrites) { + IgniteBiTuple tup = it.nextX(); + + assertTrue(String.valueOf(tup.get2()), tup.get2() instanceof PageSnapshot); + + PageSnapshot snap = (PageSnapshot)tup.get2(); + + FullPageId actual = snap.fullPageId(); + + //there are extra tracking pages, skip them + if (TrackingPageIO.VERSIONS.latest().trackingPageFor(actual.pageId(), mem.pageSize()) == actual.pageId()) { + tup = it.nextX(); + + assertTrue(tup.get2() instanceof PageSnapshot); + + actual = ((PageSnapshot)tup.get2()).fullPageId(); + } + + assertEquals(initialWrite, actual); + } + } + } + + /** + * @throws Exception if failed. + */ + public void testDataWalEntries() throws Exception { + IgniteEx ig = startGrid(0); + + GridCacheSharedContext sharedCtx = ig.context().cache().context(); + GridCacheContext cctx = sharedCtx.cache().cache("partitioned").context(); + + GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)sharedCtx.database(); + IgniteWriteAheadLogManager wal = sharedCtx.wal(); + + assertTrue(wal.isAlwaysWriteFullPages()); + + db.enableCheckpoints(false); + + final int cnt = 10; + + List entries = new ArrayList<>(cnt); + + for (int i = 0; i < cnt; i++) { + GridCacheOperation op = i % 2 == 0 ? GridCacheOperation.UPDATE : GridCacheOperation.DELETE; + + KeyCacheObject key = cctx.toCacheKeyObject(i); + + CacheObject val = null; + + if (op != GridCacheOperation.DELETE) + val = cctx.toCacheObject("value-" + i); + + entries.add(new DataEntry(cctx.cacheId(), key, val, op, null, cctx.versions().next(), 0L, + cctx.affinity().partition(i), i)); + } + + UUID cpId = UUID.randomUUID(); + + WALPointer start = wal.log(new CheckpointRecord(cpId, null, false)); + + wal.fsync(start); + + for (DataEntry entry : entries) + wal.log(new DataRecord(entry)); + + WALPointer end = wal.log(new CheckpointRecord(cpId, start, true)); + + wal.fsync(end); + + // Data will not be written to the page store. + stopAllGrids(); + + ig = startGrid(0); + + sharedCtx = ig.context().cache().context(); + cctx = sharedCtx.cache().cache("partitioned").context(); + + db = (GridCacheDatabaseSharedManager)sharedCtx.database(); + wal = sharedCtx.wal(); + + db.enableCheckpoints(false); + + try (WALIterator it = wal.replay(start)) { + IgniteBiTuple tup = it.nextX(); + + assert tup.get2() instanceof CheckpointRecord; + + assertEquals(start, tup.get1()); + + CheckpointRecord cpRec = (CheckpointRecord)tup.get2(); + + assertEquals(cpId, cpRec.checkpointId()); + assertNull(cpRec.checkpointMark()); + assertFalse(cpRec.end()); + + int idx = 0; + CacheObjectContext coctx = cctx.cacheObjectContext(); + + while (idx < entries.size()) { + tup = it.nextX(); + + assert tup.get2() instanceof DataRecord; + + DataRecord dataRec = (DataRecord)tup.get2(); + + DataEntry entry = entries.get(idx); + + assertEquals(1, dataRec.writeEntries().size()); + + DataEntry readEntry = dataRec.writeEntries().get(0); + + assertEquals(entry.cacheId(), readEntry.cacheId()); + assertEquals(entry.key().value(coctx, true), readEntry.key().value(coctx, true)); + assertEquals(entry.op(), readEntry.op()); + + if (entry.op() == GridCacheOperation.UPDATE) + assertEquals(entry.value().value(coctx, true), readEntry.value().value(coctx, true)); + else + assertNull(entry.value()); + + assertEquals(entry.writeVersion(), readEntry.writeVersion()); + assertEquals(entry.nearXidVersion(), readEntry.nearXidVersion()); + assertEquals(entry.partitionCounter(), readEntry.partitionCounter()); + + idx++; + } + + tup = it.nextX(); + + assert tup.get2() instanceof CheckpointRecord; + + assertEquals(end, tup.get1()); + + cpRec = (CheckpointRecord)tup.get2(); + + assertEquals(cpId, cpRec.checkpointId()); + assertEquals(start, cpRec.checkpointMark()); + assertTrue(cpRec.end()); + } + } + + /** + * @throws Exception if failed. + */ + public void testPageWalEntries() throws Exception { + IgniteEx ig = startGrid(0); + + GridCacheSharedContext sharedCtx = ig.context().cache().context(); + int cacheId = sharedCtx.cache().cache("partitioned").context().cacheId(); + + GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)sharedCtx.database(); + PageMemory pageMem = sharedCtx.database().memoryPolicy(null).pageMemory(); + IgniteWriteAheadLogManager wal = sharedCtx.wal(); + + db.enableCheckpoints(false).get(); + + int pageCnt = 100; + + List pageIds = new ArrayList<>(); + + for (int i = 0; i < pageCnt; i++) { + db.checkpointReadLock(); + try { + pageIds.add(new FullPageId(pageMem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, + PageIdAllocator.FLAG_IDX), cacheId)); + } + finally { + db.checkpointReadUnlock(); + } + } + + UUID cpId = UUID.randomUUID(); + + WALPointer start = wal.log(new CheckpointRecord(cpId, null, false)); + + wal.fsync(start); + + ig.context().cache().context().database().checkpointReadLock(); + + try { + for (FullPageId pageId : pageIds) + writePageData(pageId, pageMem); + } + finally { + ig.context().cache().context().database().checkpointReadUnlock(); + } + + WALPointer end = wal.log(new CheckpointRecord(cpId, start, true)); + + wal.fsync(end); + + // Data will not be written to the page store. + stopAllGrids(); + + ig = startGrid(0); + + sharedCtx = ig.context().cache().context(); + + db = (GridCacheDatabaseSharedManager)sharedCtx.database(); + wal = sharedCtx.wal(); + + db.enableCheckpoints(false); + + try (WALIterator it = wal.replay(start)) { + IgniteBiTuple tup = it.nextX(); + + assert tup.get2() instanceof CheckpointRecord : tup.get2(); + + assertEquals(start, tup.get1()); + + CheckpointRecord cpRec = (CheckpointRecord)tup.get2(); + + assertEquals(cpId, cpRec.checkpointId()); + assertNull(cpRec.checkpointMark()); + assertFalse(cpRec.end()); + + int idx = 0; + + while (idx < pageIds.size()) { + tup = it.nextX(); + + assert tup.get2() instanceof PageSnapshot : tup.get2().getClass(); + + PageSnapshot snap = (PageSnapshot)tup.get2(); + + //there are extra tracking pages, skip them + if (TrackingPageIO.VERSIONS.latest().trackingPageFor(snap.fullPageId().pageId(), pageMem.pageSize()) == snap.fullPageId().pageId()) { + tup = it.nextX(); + + assertTrue(tup.get2() instanceof PageSnapshot); + + snap = (PageSnapshot)tup.get2(); + } + + assertEquals(pageIds.get(idx), snap.fullPageId()); + + idx++; + } + + tup = it.nextX(); + + assert tup.get2() instanceof CheckpointRecord; + + assertEquals(end, tup.get1()); + + cpRec = (CheckpointRecord)tup.get2(); + + assertEquals(cpId, cpRec.checkpointId()); + assertEquals(start, cpRec.checkpointMark()); + assertTrue(cpRec.end()); + } + } + + /** + * @throws Exception if failed. + */ + public void testDirtyFlag() throws Exception { + IgniteEx ig = startGrid(0); + + GridCacheSharedContext shared = ig.context().cache().context(); + + int cacheId = shared.cache().cache("partitioned").context().cacheId(); + + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)shared.database(); + + // Disable integrated checkpoint thread. + dbMgr.enableCheckpoints(false); + + PageMemoryEx mem = (PageMemoryEx) dbMgr.memoryPolicy(null).pageMemory(); + + ig.context().cache().context().database().checkpointReadLock(); + + FullPageId[] pageIds = new FullPageId[100]; + + try { + for (int i = 0; i < pageIds.length; i++) + pageIds[i] = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId); + + for (FullPageId fullId : pageIds) { + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + assertTrue(mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); //page is dirty right after allocation + + long pageAddr = mem.writeLock(fullId.cacheId(), fullId.pageId(), page); + + PageIO.setPageId(pageAddr, fullId.pageId()); + + try { + assertTrue(mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); + } + finally { + mem.writeUnlock(fullId.cacheId(), fullId.pageId(),page, null,true); + } + + assertTrue(mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + } + finally { + ig.context().cache().context().database().checkpointReadUnlock(); + } + + Collection cpPages = mem.beginCheckpoint(); + + ig.context().cache().context().database().checkpointReadLock(); + + try { + for (FullPageId fullId : pageIds) { + assertTrue(cpPages.contains(fullId)); + + ByteBuffer buf = ByteBuffer.allocate(mem.pageSize()); + + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + assertFalse(mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); + + long pageAddr = mem.writeLock(fullId.cacheId(), fullId.pageId(), page); + + try { + assertFalse(mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); + + for (int i = PageIO.COMMON_HEADER_END; i < mem.pageSize(); i++) + PageUtils.putByte(pageAddr, i, (byte)1); + } + finally { + mem.writeUnlock(fullId.cacheId(), fullId.pageId(), page, null, true); + } + + assertTrue(mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); + + buf.rewind(); + + mem.getForCheckpoint(fullId, buf); + + buf.position(PageIO.COMMON_HEADER_END); + + while (buf.hasRemaining()) + assertEquals((byte)0, buf.get()); + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + } + finally { + ig.context().cache().context().database().checkpointReadUnlock(); + } + + mem.finishCheckpoint(); + + for (FullPageId fullId : pageIds) { + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + try { + assertTrue(mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + } + + /** + * @throws Exception if failed. + */ + private void writePageData(FullPageId fullId, PageMemory mem) throws Exception { + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + try { + long pageAddr = mem.writeLock(fullId.cacheId(), fullId.pageId(), page); + + try { + DataPageIO.VERSIONS.latest().initNewPage(pageAddr, fullId.pageId(), mem.pageSize()); + + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + for (int i = PageIO.COMMON_HEADER_END; i < mem.pageSize(); i++) + PageUtils.putByte(pageAddr, i, (byte)rnd.nextInt(255)); + } + finally { + mem.writeUnlock(fullId.cacheId(), fullId.pageId(), page, null, true); + } + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + + /** + * @param res Result map to verify. + * @param mem Memory. + */ + private void verifyReads( + Map res, + PageMemory mem, + WALPointer start, + IgniteWriteAheadLogManager wal + ) throws Exception { + Map replay = new HashMap<>(); + + try (WALIterator it = wal.replay(start)) { + IgniteBiTuple tup = it.nextX(); + + assertTrue("Invalid record: " + tup, tup.get2() instanceof CheckpointRecord); + + CheckpointRecord cpRec = (CheckpointRecord)tup.get2(); + + while (it.hasNextX()) { + tup = it.nextX(); + + WALRecord rec = tup.get2(); + + if (rec instanceof CheckpointRecord) { + CheckpointRecord end = (CheckpointRecord)rec; + + // Found the finish mark. + if (end.checkpointId().equals(cpRec.checkpointId()) && end.end()) + break; + } + else if (rec instanceof PageSnapshot) { + PageSnapshot page = (PageSnapshot)rec; + + replay.put(page.fullPageId(), page.pageData()); + } + } + } + + // Check read-through from the file store. + for (Map.Entry entry : res.entrySet()) { + FullPageId fullId = entry.getKey(); + int state = entry.getValue(); + + if (state == -1) { + info("Page was never written: " + fullId); + + continue; + } + + byte[] walData = replay.get(fullId); + + assertNotNull("Missing WAL record for a written page: " + fullId, walData); + + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + try { + long pageAddr = mem.readLock(fullId.cacheId(), fullId.pageId(), page); + + try { + for (int i = PageIO.COMMON_HEADER_END; i < mem.pageSize(); i++) { + assertEquals("Invalid state [pageId=" + fullId + ", pos=" + i + ']', + state & 0xFF, PageUtils.getByte(pageAddr, i) & 0xFF); + + assertEquals("Invalid WAL state [pageId=" + fullId + ", pos=" + i + ']', + state & 0xFF, walData[i] & 0xFF); + } + } + finally { + mem.readUnlock(fullId.cacheId(), fullId.pageId(), page); + } + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + } + + /** + * @param mem Memory to use. + * @param storeMgr Store manager. + * @param cacheId Cache ID. + * @return Result map of random operations. + * @throws Exception If failure occurred. + */ + private IgniteBiTuple, WALPointer> runCheckpointing( + final IgniteEx ig, + final PageMemoryImpl mem, + final IgnitePageStoreManager storeMgr, + final IgniteWriteAheadLogManager wal, + final int cacheId + ) throws Exception { + final ConcurrentMap resMap = new ConcurrentHashMap<>(); + + final FullPageId pages[] = new FullPageId[TOTAL_PAGES]; + Set allocated = new HashSet<>(); + + for (int i = 0; i < TOTAL_PAGES; i++) { + FullPageId fullId = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId); + + resMap.put(fullId, -1); + + pages[i] = fullId; + allocated.add(fullId); + } + + final AtomicBoolean run = new AtomicBoolean(true); + + // Simulate transaction lock. + final ReadWriteLock updLock = new ReentrantReadWriteLock(); + + // Mark the start position. + CheckpointRecord cpRec = new CheckpointRecord(null, false); + + WALPointer start = wal.log(cpRec); + + wal.fsync(start); + + IgniteInternalFuture updFut = GridTestUtils.runMultiThreadedAsync(new Callable() { + @Override public Object call() throws Exception { + while (true) { + FullPageId fullId = pages[ThreadLocalRandom.current().nextInt(TOTAL_PAGES)]; + + updLock.readLock().lock(); + + try { + if (!run.get()) + return null; + + ig.context().cache().context().database().checkpointReadLock(); + + try { + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + long pageAddr = mem.writeLock(fullId.cacheId(), fullId.pageId(), page); + + PageIO.setPageId(pageAddr, fullId.pageId()); + + try { + int state = resMap.get(fullId); + + if (state != -1) { + if (VERBOSE) + info("Verify page [fullId=" + fullId + ", state=" + state + + ", buf=" + pageAddr + + ", bhc=" + U.hexLong(System.identityHashCode(pageAddr)) + + ", page=" + U.hexLong(System.identityHashCode(page)) + ']'); + + for (int i = PageIO.COMMON_HEADER_END; i < mem.pageSize(); i++) + assertEquals("Verify page failed [fullId=" + fullId + + ", i=" + i + + ", state=" + state + + ", buf=" + pageAddr + + ", bhc=" + U.hexLong(System.identityHashCode(pageAddr)) + + ", page=" + U.hexLong(System.identityHashCode(page)) + ']', + state & 0xFF, PageUtils.getByte(pageAddr, i) & 0xFF); + } + + state = (state + 1) & 0xFF; + + if (VERBOSE) + info("Write page [fullId=" + fullId + ", state=" + state + + ", buf=" + pageAddr + + ", bhc=" + U.hexLong(System.identityHashCode(pageAddr)) + + ", page=" + U.hexLong(System.identityHashCode(page)) + ']'); + + for (int i = PageIO.COMMON_HEADER_END; i < mem.pageSize(); i++) + PageUtils.putByte(pageAddr, i, (byte)state); + + resMap.put(fullId, state); + } + finally { + mem.writeUnlock(fullId.cacheId(), fullId.pageId(),page, null,true); + } + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(),page);} + } + finally { + ig.context().cache().context().database().checkpointReadUnlock(); + } + } + finally { + updLock.readLock().unlock(); + } + } + } + }, 8, "update-thread"); + + int checkpoints = 20; + + while (checkpoints > 0) { + Map snapshot = null; + + Collection pageIds; + + updLock.writeLock().lock(); + + try { + snapshot = new HashMap<>(resMap); + + pageIds = mem.beginCheckpoint(); + + checkpoints--; + + if (checkpoints == 0) + // No more writes should be done at this point. + run.set(false); + + info("Acquired pages for checkpoint: " + pageIds.size()); + } + finally { + updLock.writeLock().unlock(); + } + + boolean ok = false; + + try { + ByteBuffer tmpBuf = ByteBuffer.allocate(mem.pageSize()); + + tmpBuf.order(ByteOrder.nativeOrder()); + + long begin = System.currentTimeMillis(); + + long cp = 0; + + long write = 0; + + for (FullPageId fullId : pageIds) { + long cpStart = System.nanoTime(); + + Integer tag = mem.getForCheckpoint(fullId, tmpBuf); + + if (tag == null) + continue; + + long cpEnd = System.nanoTime(); + + cp += cpEnd - cpStart; + + Integer state = snapshot.get(fullId); + + if (allocated.contains(fullId) && state != -1) { + tmpBuf.rewind(); + + Integer first = null; + + for (int i = PageIO.COMMON_HEADER_END; i < mem.pageSize(); i++) { + int val = tmpBuf.get(i) & 0xFF; + + if (first == null) + first = val; + + // Avoid string concat. + if (first != val) + assertEquals("Corrupted buffer at position [pageId=" + fullId + ", pos=" + i + ']', + (int)first, val); + + // Avoid string concat. + if (state != val) + assertEquals("Invalid value at position [pageId=" + fullId + ", pos=" + i + ']', + (int)state, val); + } + } + + tmpBuf.rewind(); + + long writeStart = System.nanoTime(); + + storeMgr.write(cacheId, fullId.pageId(), tmpBuf, tag); + + long writeEnd = System.nanoTime(); + + write += writeEnd - writeStart; + + tmpBuf.rewind(); + } + + long syncStart = System.currentTimeMillis(); + + storeMgr.sync(cacheId, 0); + + long end = System.currentTimeMillis(); + + info("Written pages in " + (end - begin) + "ms, copy took " + (cp / 1_000_000) + "ms, " + + "write took " + (write / 1_000_000) + "ms, sync took " + (end - syncStart) + "ms"); + + ok = true; + } + finally { + info("Finishing checkpoint..."); + + mem.finishCheckpoint(); + + info("Finished checkpoint"); + + if (!ok) { + info("Cancelling updates..."); + + run.set(false); + + updFut.get(); + } + } + + if (checkpoints != 0) + Thread.sleep(2_000); + } + + info("checkpoints=" + checkpoints + ", done=" + updFut.isDone()); + + updFut.get(); + + // Mark the end. + wal.fsync(wal.log(new CheckpointRecord(cpRec.checkpointId(), start, true))); + + assertEquals(0, mem.activePagesCount()); + + for (FullPageId fullId : pages) { + + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + assertFalse("Page has a temp heap copy after the last checkpoint: [cacheId=" + + fullId.cacheId() + ", pageId=" + fullId.pageId() + "]", mem.hasTempCopy(page)); + + assertFalse("Page is dirty after the last checkpoint: [cacheId=" + + fullId.cacheId() + ", pageId=" + fullId.pageId() + "]", mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + + return F.t((Map)resMap, start); + } + + /** + * + */ + private void deleteWorkFiles() throws IgniteCheckedException { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java new file mode 100644 index 0000000000000..531b5fe6e8b4f --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java @@ -0,0 +1,275 @@ +package org.apache.ignite.cache.database.db.file; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.Callable; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.pagemem.PageUtils; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * Test for page evictions. + */ +public class PageStoreEvictionSelfTest extends GridCommonAbstractTest { + /** */ + private static final int NUMBER_OF_SEGMENTS = 64; + + /** */ + private static final int PAGE_SIZE = 1024; + + /** */ + private static final long CHUNK_SIZE = 1024 * 1024; + + /** */ + private static final long MEMORY_LIMIT = 5 * CHUNK_SIZE; + + /** */ + private static final int PAGES_NUM = 128_000; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + final IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + cfg.setMemoryConfiguration(createDbConfig()); + + return cfg; + } + + /** + * @return DB config. + */ + private MemoryConfiguration createDbConfig() { + final MemoryConfiguration dbCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + memPlcCfg.setSize(MEMORY_LIMIT); + memPlcCfg.setName("dfltMemPlc"); + + dbCfg.setPageSize(PAGE_SIZE); + dbCfg.setConcurrencyLevel(NUMBER_OF_SEGMENTS); + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + return dbCfg; + } + + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + + stopAllGrids(); + + deleteWorkFiles(); + } + + /** + * @throws Exception If fail. + */ + public void testPageEviction() throws Exception { + final IgniteEx ig = startGrid(0); + ig.getOrCreateCache(new CacheConfiguration<>("partitioned")); + + final PageMemory memory = getMemory(ig); + + writeData(ig, memory, CU.cacheId("partitioned")); + } + + /** + * @param memory Page memory. + * @param cacheId Cache id. + * @throws IgniteCheckedException If failed. + */ + private void writeData(final IgniteEx ignite, final PageMemory memory, final int cacheId) throws Exception { + final int size = PAGES_NUM; + + final List pageIds = new ArrayList<>(size); + + IgniteCacheDatabaseSharedManager db = ignite.context().cache().context().database(); + + // Allocate. + for (int i = 0; i < size; i++) { + db.checkpointReadLock(); + try { + final FullPageId fullId = new FullPageId(memory.allocatePage(cacheId, i % 256, PageMemory.FLAG_DATA), + cacheId); + + pageIds.add(fullId); + } + finally { + db.checkpointReadUnlock(); + } + } + + System.out.println("Allocated pages: " + pageIds.size()); + + // Write data. (Causes evictions.) + final int part = PAGES_NUM / NUMBER_OF_SEGMENTS; + + final Collection futs = new ArrayList<>(); + + for (int i = 0; i < PAGES_NUM; i += part) + futs.add(runWriteInThread(ignite, i, i + part, memory, pageIds)); + + for (final IgniteInternalFuture fut : futs) + fut.get(); + + System.out.println("Wrote pages: " + pageIds.size()); + + // Read data. (Causes evictions.) + futs.clear(); + + for (int i = 0; i < PAGES_NUM; i += part) + futs.add(runReadInThread(ignite, i, i + part, memory, pageIds)); + + for (final IgniteInternalFuture fut : futs) + fut.get(); + + System.out.println("Read pages: " + pageIds.size()); + } + + /** + * @param start Start index. + * @param end End index. + * @param memory PageMemory. + * @param pageIds Allocated pages. + * @return Future. + * @throws Exception If fail. + */ + private IgniteInternalFuture runWriteInThread( + final IgniteEx ignite, + final int start, + final int end, + final PageMemory memory, + final List pageIds + ) throws Exception { + + return GridTestUtils.runAsync(new Callable() { + @Override public Object call() throws Exception { + IgniteCacheDatabaseSharedManager db = ignite.context().cache().context().database(); + + for (int i = start; i < end; i++) { + db.checkpointReadLock(); + + try { + FullPageId fullId = pageIds.get(i); + + long page = memory.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + final long pageAddr = memory.writeLock(fullId.cacheId(), fullId.pageId(), page); + + try { + PageIO.setPageId(pageAddr, fullId.pageId()); + + PageUtils.putLong(pageAddr, PageIO.COMMON_HEADER_END, i * 2); + } + finally { + memory.writeUnlock(fullId.cacheId(), fullId.pageId(), page, null, true); + } + } + finally { + memory.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + finally { + db.checkpointReadUnlock(); + } + } + + return null; + } + }); + } + + /** + * @param start Start index. + * @param end End index. + * @param memory PageMemory. + * @param pageIds Allocated pages. + * @return Future. + * @throws Exception If fail. + */ + private IgniteInternalFuture runReadInThread(final IgniteEx ignite, final int start, final int end, + final PageMemory memory, + final List pageIds) throws Exception { + return GridTestUtils.runAsync(new Callable() { + @Override public Object call() throws Exception { + IgniteCacheDatabaseSharedManager db = ignite.context().cache().context().database(); + + for (int i = start; i < end; i++) { + db.checkpointReadLock(); + + try { + final FullPageId fullId = pageIds.get(i); + + long page = memory.acquirePage(fullId.cacheId(), fullId.pageId()); + try { + final long pageAddr = memory.readLock(fullId.cacheId(), fullId.pageId(), page); + + try { + assertEquals(i * 2, PageUtils.getLong(pageAddr, PageIO.COMMON_HEADER_END)); + } + finally { + memory.readUnlock(fullId.cacheId(), fullId.pageId(), page); + } + } + finally { + memory.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + finally { + db.checkpointReadUnlock(); + } + } + + return null; + } + }); + } + + /** + * @param ig Ignite instance. + * @return Memory and store. + * @throws Exception If failed to initialize the store. + */ + private PageMemory getMemory(IgniteEx ig) throws Exception { + final GridCacheSharedContext sharedCtx = ig.context().cache().context(); + + final IgniteCacheDatabaseSharedManager db = sharedCtx.database(); + + return db.memoryPolicy(null).pageMemory(); + } + + /** + * @throws IgniteCheckedException If fail. + */ + private void deleteWorkFiles() throws IgniteCheckedException { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java new file mode 100644 index 0000000000000..7553896d85e6b --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java @@ -0,0 +1,931 @@ +package org.apache.ignite.cache.database.db.file; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReferenceArray; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.Ignition; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.QueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.pagemem.PageIdAllocator; +import org.apache.ignite.internal.pagemem.store.PageStore; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager; +import org.apache.ignite.internal.processors.cache.IgniteRebalanceIterator; +import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager; +import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl; +import org.apache.ignite.internal.processors.cache.database.freelist.PagesList; +import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseListImpl; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.T2; +import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.junit.Assert; + +/** + * + */ +public class WalRecoveryTxLogicalRecordsTest extends GridCommonAbstractTest { + /** Cache name. */ + private static final String CACHE_NAME = "cache"; + + /** */ + public static final int PARTS = 32; + + /** */ + public static final int WAL_HIST_SIZE = 30; + + /** */ + private int pageSize = 4 * 1024; + + /** */ + private CacheConfiguration extraCcfg; + + /** */ + private Long checkpointFreq; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration<>(CACHE_NAME); + + ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg.setRebalanceMode(CacheRebalanceMode.SYNC); + ccfg.setAffinity(new RendezvousAffinityFunction(false, PARTS)); + ccfg.setIndexedTypes(Integer.class, IndexedValue.class); + + if (extraCcfg != null) + cfg.setCacheConfiguration(ccfg, new CacheConfiguration<>(extraCcfg)); + else + cfg.setCacheConfiguration(ccfg); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + dbCfg.setPageSize(pageSize); + + cfg.setMemoryConfiguration(dbCfg); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + pCfg.setWalHistorySize(WAL_HIST_SIZE); + + if (checkpointFreq != null) + pCfg.setCheckpointFrequency(checkpointFreq); + + cfg.setPersistenceConfiguration(pCfg); + + cfg.setMarshaller(null); + + BinaryConfiguration binCfg = new BinaryConfiguration(); + + binCfg.setCompactFooter(false); + + cfg.setBinaryConfiguration(binCfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @throws Exception If failed. + */ + public void testWalTxSimple() throws Exception { + Ignite ignite = startGrid(); + + try { + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)((IgniteEx)ignite).context() + .cache().context().database(); + + dbMgr.enableCheckpoints(false).get(); + + IgniteCache cache = ignite.cache(CACHE_NAME); + + int txCnt = 100; + + int keysPerTx = 10; + + for (int i = 0; i < txCnt; i++) { + try (Transaction tx = ignite.transactions().txStart()) { + for (int j = 0; j < keysPerTx; j++) { + int k = i * keysPerTx + j; + + cache.put(k, new IndexedValue(k)); + } + + tx.commit(); + } + } + + for (int i = 0; i < txCnt; i++) { + for (int j = 0; j < keysPerTx; j++) { + int k = i * keysPerTx + j; + + assertEquals(k, cache.get(k).value()); + } + } + + stopGrid(); + + ignite = startGrid(); + + cache = ignite.cache(CACHE_NAME); + + for (int i = 0; i < txCnt; i++) { + for (int j = 0; j < keysPerTx; j++) { + int k = i * keysPerTx + j; + + assertEquals(k, cache.get(k).value()); + } + } + + for (int i = 0; i < txCnt; i++) { + for (int j = 0; j < keysPerTx; j++) { + int k = i * keysPerTx + j; + + QueryCursor> cur = cache.query( + new SqlFieldsQuery("select sVal from IndexedValue where iVal=?").setArgs(k)); + + List> vals = cur.getAll(); + + assertEquals(vals.size(), 1); + assertEquals("string-" + k, vals.get(0).get(0)); + } + } + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + public void testWalRecoveryRemoves() throws Exception { + Ignite ignite = startGrid(); + + try { + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)((IgniteEx)ignite).context() + .cache().context().database(); + + IgniteCache cache = ignite.cache(CACHE_NAME); + + int txCnt = 100; + + int keysPerTx = 10; + + for (int i = 0; i < txCnt; i++) { + try (Transaction tx = ignite.transactions().txStart()) { + for (int j = 0; j < keysPerTx; j++) { + int k = i * keysPerTx + j; + + cache.put(k, new IndexedValue(k)); + } + + tx.commit(); + } + } + + for (int i = 0; i < txCnt; i++) { + for (int j = 0; j < keysPerTx; j++) { + int k = i * keysPerTx + j; + + assertEquals(k, cache.get(k).value()); + } + } + + dbMgr.waitForCheckpoint("test"); + dbMgr.enableCheckpoints(false).get(); + + for (int i = 0; i < txCnt / 2; i++) { + try (Transaction tx = ignite.transactions().txStart()) { + for (int j = 0; j < keysPerTx; j++) { + int k = i * keysPerTx + j; + + cache.remove(k); + } + + tx.commit(); + } + } + + stopGrid(); + + ignite = startGrid(); + + cache = ignite.cache(CACHE_NAME); + + for (int i = 0; i < txCnt; i++) { + for (int j = 0; j < keysPerTx; j++) { + int k = i * keysPerTx + j; + + QueryCursor> cur = cache.query( + new SqlFieldsQuery("select sVal from IndexedValue where iVal=?").setArgs(k)); + + List> vals = cur.getAll(); + + if (i < txCnt / 2) { + assertNull(cache.get(k)); + assertTrue(F.isEmpty(vals)); + } + else { + assertEquals(k, cache.get(k).value()); + + assertEquals(1, vals.size()); + assertEquals("string-" + k, vals.get(0).get(0)); + } + } + } + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + public void testRebalanceIterator() throws Exception { + extraCcfg = new CacheConfiguration(CACHE_NAME + "2"); + extraCcfg.setAffinity(new RendezvousAffinityFunction(false, PARTS)); + + Ignite ignite = startGrid(); + + try { + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)((IgniteEx)ignite).context() + .cache().context().database(); + + dbMgr.waitForCheckpoint("test"); + + // This number depends on wal history size. + int entries = 25; + + IgniteCache cache = ignite.cache(CACHE_NAME); + IgniteCache cache2 = ignite.cache(CACHE_NAME + "2"); + + for (int i = 0; i < entries; i++) { + // Put to partition 0. + cache.put(i * PARTS, i * PARTS); + + // Put to partition 1. + cache.put(i * PARTS + 1, i * PARTS + 1); + + // Put to another cache. + cache2.put(i, i); + + dbMgr.waitForCheckpoint("test"); + } + + for (int i = 0; i < entries; i++) { + assertEquals((Integer)(i * PARTS), cache.get(i * PARTS)); + assertEquals((Integer)(i * PARTS + 1), cache.get(i * PARTS + 1)); + assertEquals((Integer)(i), cache2.get(i)); + } + + GridCacheContext cctx = ((IgniteEx)ignite).context().cache().cache(CACHE_NAME).context(); + IgniteCacheOffheapManager offh = cctx.offheap(); + AffinityTopologyVersion topVer = cctx.affinity().affinityTopologyVersion(); + + for (int i = 0; i < entries; i++) { + try (IgniteRebalanceIterator it = offh.rebalanceIterator(0, topVer, (long)i)) { + assertTrue("Not historical for iteration: " + i, it.historical()); + + assertNotNull(it); + + for (int j = i; j < entries; j++) { + assertTrue("i=" + i + ", j=" + j, it.hasNextX()); + + CacheDataRow row = it.next(); + + assertEquals(j * PARTS, (int)row.key().value(cctx.cacheObjectContext(), false)); + assertEquals(j * PARTS, (int)row.value().value(cctx.cacheObjectContext(), false)); + } + + assertFalse(it.hasNext()); + } + + try (IgniteRebalanceIterator it = offh.rebalanceIterator(1, topVer, (long)i)) { + assertNotNull(it); + + assertTrue("Not historical for iteration: " + i, it.historical()); + + for (int j = i; j < entries; j++) { + assertTrue(it.hasNextX()); + + CacheDataRow row = it.next(); + + assertEquals(j * PARTS + 1, (int)row.key().value(cctx.cacheObjectContext(), false)); + assertEquals(j * PARTS + 1, (int)row.value().value(cctx.cacheObjectContext(), false)); + } + + assertFalse(it.hasNext()); + } + } + + stopAllGrids(); + + // Check that iterator is valid after restart. + ignite = startGrid(); + + cctx = ((IgniteEx)ignite).context().cache().cache(CACHE_NAME).context(); + offh = cctx.offheap(); + topVer = cctx.affinity().affinityTopologyVersion(); + + for (int i = 0; i < entries; i++) { + long start = System.currentTimeMillis(); + + try (IgniteRebalanceIterator it = offh.rebalanceIterator(0, topVer, (long)i)) { + long end = System.currentTimeMillis(); + + info("Time to get iterator: " + (end - start)); + + assertTrue("Not historical for iteration: " + i, it.historical()); + + assertNotNull(it); + + start = System.currentTimeMillis(); + + for (int j = i; j < entries; j++) { + assertTrue("i=" + i + ", j=" + j, it.hasNextX()); + + CacheDataRow row = it.next(); + + assertEquals(j * PARTS, (int)row.key().value(cctx.cacheObjectContext(), false)); + assertEquals(j * PARTS, (int)row.value().value(cctx.cacheObjectContext(), false)); + } + + end = System.currentTimeMillis(); + + info("Time to iterate: " + (end - start)); + + assertFalse(it.hasNext()); + } + + try (IgniteRebalanceIterator it = offh.rebalanceIterator(1, topVer, (long)i)) { + assertNotNull(it); + + assertTrue("Not historical for iteration: " + i, it.historical()); + + for (int j = i; j < entries; j++) { + assertTrue(it.hasNextX()); + + CacheDataRow row = it.next(); + + assertEquals(j * PARTS + 1, (int)row.key().value(cctx.cacheObjectContext(), false)); + assertEquals(j * PARTS + 1, (int)row.value().value(cctx.cacheObjectContext(), false)); + } + + assertFalse(it.hasNext()); + } + } + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception if failed. + */ + public void testCheckpointHistory() throws Exception { + Ignite ignite = startGrid(); + + try { + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)((IgniteEx)ignite).context() + .cache().context().database(); + + dbMgr.waitForCheckpoint("test"); + + // This number depends on wal history size. + int entries = WAL_HIST_SIZE * 2; + + IgniteCache cache = ignite.cache(CACHE_NAME); + + for (int i = 0; i < entries; i++) { + // Put to partition 0. + cache.put(i * PARTS, i * PARTS); + + // Put to partition 1. + cache.put(i * PARTS + 1, i * PARTS + 1); + + dbMgr.waitForCheckpoint("test"); + } + + GridCacheDatabaseSharedManager.CheckpointHistory hist = dbMgr.checkpointHistory(); + + assertTrue(hist.checkpoints().size() <= WAL_HIST_SIZE); + + File cpDir = dbMgr.checkpointDirectory(); + + File[] cpFiles = cpDir.listFiles(); + + assertTrue(cpFiles.length <= WAL_HIST_SIZE * 2); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If failed. + */ + public void testWalAfterPreloading() throws Exception { + Ignite ignite = startGrid(); + + try { + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)((IgniteEx)ignite).context() + .cache().context().database(); + + dbMgr.enableCheckpoints(false).get(); + + int entries = 100; + + try (IgniteDataStreamer streamer = ignite.dataStreamer(CACHE_NAME)) { + for (int i = 0; i < entries; i++) + streamer.addData(i, i); + } + + IgniteCache cache = ignite.cache(CACHE_NAME); + + for (int i = 0; i < entries; i++) + assertEquals(new Integer(i), cache.get(i)); + + stopGrid(); + + ignite = startGrid(); + + cache = ignite.cache(CACHE_NAME); + + for (int i = 0; i < entries; i++) + assertEquals(new Integer(i), cache.get(i)); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If failed. + */ + public void testRecoveryRandomPutRemove() throws Exception { + try { + pageSize = 1024; + + extraCcfg = new CacheConfiguration(); + extraCcfg.setAffinity(new RendezvousAffinityFunction(false, PARTS)); + + Ignite ignite = startGrid(0); + + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)((IgniteEx)ignite).context() + .cache().context().database(); + + dbMgr.enableCheckpoints(false).get(); + + IgniteCache cache1 = ignite.cache(CACHE_NAME); + IgniteCache cache2 = ignite.cache(null); + + final int KEYS1 = 100; + + for (int i = 0; i < KEYS1; i++) + cache1.put(i, new IndexedValue(i)); + + for (int i = 0; i < KEYS1; i++) { + if (i % 2 == 0) + cache1.remove(i); + } + + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + for (int i = 0; i < KEYS1; i++) { + cache2.put(i, new byte[rnd.nextInt(512)]); + + if (rnd.nextBoolean()) + cache2.put(i, new byte[rnd.nextInt(512)]); + + if (rnd.nextBoolean()) + cache2.remove(i); + } + + ignite.close(); + + ignite = startGrid(0); + + ignite.cache(CACHE_NAME).put(1, new IndexedValue(0)); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If failed. + */ + public void testRecoveryNoPageLost1() throws Exception { + recoveryNoPageLost(false); + } + + /** + * @throws Exception If failed. + */ + public void testRecoveryNoPageLost2() throws Exception { + recoveryNoPageLost(true); + } + + /** + * @throws Exception If failed. + */ + public void testRecoveryNoPageLost3() throws Exception { + try { + pageSize = 1024; + checkpointFreq = 100L; + extraCcfg = new CacheConfiguration(); + extraCcfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + + List pages = null; + + for (int iter = 0; iter < 5; iter++) { + log.info("Start node: " + iter); + + Ignite ignite = startGrid(0); + + if (pages != null) { + List curPags = allocatedPages(ignite, null); + + assertEquals("Iter = " + iter, pages, curPags); + } + + final IgniteCache cache = ignite.cache(null); + + final int ops = ThreadLocalRandom.current().nextInt(10) + 10; + + GridTestUtils.runMultiThreaded(new Callable() { + @Override public Void call() throws Exception { + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + for (int i = 0; i < ops; i++) { + Integer key = rnd.nextInt(1000); + + cache.put(key, new byte[rnd.nextInt(512)]); + + if (rnd.nextBoolean()) + cache.remove(key); + } + + return null; + } + }, 10, "update"); + + pages = allocatedPages(ignite, null); + + Ignition.stop(ignite.name(), false); //will make checkpoint + } + } + finally { + stopAllGrids(); + } + } + + /** + * @param checkpoint Checkpoint enable flag. + * @throws Exception If failed. + */ + private void recoveryNoPageLost(boolean checkpoint) throws Exception { + try { + pageSize = 1024; + extraCcfg = new CacheConfiguration(); + extraCcfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + + List pages = null; + + AtomicInteger cnt = new AtomicInteger(); + + for (int iter = 0; iter < 5; iter++) { + log.info("Start node: " + iter); + + Ignite ignite = startGrid(0); + + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)((IgniteEx)ignite).context() + .cache().context().database(); + + if (!checkpoint) + dbMgr.enableCheckpoints(false).get(); + + if (pages != null) { + List curPags = allocatedPages(ignite, null); + + assertEquals(pages, curPags); + } + + IgniteCache cache = ignite.cache(null); + + for (int i = 0; i < 128; i++) + cache.put(cnt.incrementAndGet(), new byte[256 + iter * 100]); + + pages = allocatedPages(ignite, null); + + ignite.close(); + } + } + finally { + stopAllGrids(); + } + } + + /** + * @param ignite Node. + * @param cacheName Cache name. + * @return Allocated pages per-store. + * @throws Exception If failed. + */ + private List allocatedPages(Ignite ignite, String cacheName) throws Exception { + FilePageStoreManager storeMgr = + (FilePageStoreManager)((IgniteEx)ignite).context().cache().context().pageStore(); + + int parts = ignite.affinity(cacheName).partitions(); + + List res = new ArrayList<>(parts); + + for (int p = 0; p < parts; p++) { + PageStore store = storeMgr.getStore(CU.cacheId(cacheName), p); + + store.sync(); + + res.add(store.pages()); + } + + PageStore store = storeMgr.getStore(CU.cacheId(cacheName), PageIdAllocator.INDEX_PARTITION); + + store.sync(); + + res.add(store.pages()); + + return res; + } + + /** + * @throws Exception If failed. + */ + public void testFreeListRecovery() throws Exception { + try { + pageSize = 1024; + extraCcfg = new CacheConfiguration(); + + Ignite ignite = startGrid(0); + + IgniteCache cache1 = ignite.cache(CACHE_NAME); + IgniteCache cache2 = ignite.cache(null); + + final int KEYS1 = 2048; + + for (int i = 0; i < KEYS1; i++) + cache1.put(i, new IndexedValue(i)); + + for (int i = 0; i < KEYS1; i++) { + if (i % 2 == 0) + cache1.remove(i); + } + + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + for (int i = 0; i < KEYS1; i++) { + cache2.put(i, new byte[rnd.nextInt(512)]); + + if (rnd.nextBoolean()) + cache2.put(i, new byte[rnd.nextInt(512)]); + + if (rnd.nextBoolean()) + cache2.remove(i); + } + + Map, int[]>> cache1_1 = getFreeListData(ignite, CACHE_NAME); + Map, int[]>> cache2_1 = getFreeListData(ignite, null); + T2 rl1_1 = getReuseListData(ignite, CACHE_NAME); + T2 rl2_1 = getReuseListData(ignite, null); + + ignite.close(); + + ignite = startGrid(0); + + cache1 = ignite.cache(CACHE_NAME); + cache2 = ignite.cache(null); + + for (int i = 0; i < KEYS1; i++) { + cache1.get(i); + cache2.get(i); + } + + Map, int[]>> cache1_2 = getFreeListData(ignite, CACHE_NAME); + Map, int[]>> cache2_2 = getFreeListData(ignite, null); + T2 rl1_2 = getReuseListData(ignite, CACHE_NAME); + T2 rl2_2 = getReuseListData(ignite, null); + + checkEquals(cache1_1, cache1_2); + checkEquals(cache2_1, cache2_2); + checkEquals(rl1_1, rl1_2); + checkEquals(rl2_1, rl2_2); + } + finally { + stopAllGrids(); + } + } + + /** + * @param ignite Node. + * @param cacheName Cache name. + * @return Cache reuse list data. + */ + private T2 getReuseListData(Ignite ignite, String cacheName) { + GridCacheContext ctx = ((IgniteEx)ignite).context().cache().cache(cacheName).context(); + + ReuseListImpl reuseList = GridTestUtils.getFieldValue(ctx.offheap(), "reuseList"); + PagesList.Stripe[] bucket = GridTestUtils.getFieldValue(reuseList, "bucket"); + + long[] ids = null; + + if (bucket != null) { + ids = new long[bucket.length]; + + for (int i = 0; i < bucket.length; i++) + ids[i] = bucket[i].tailId; + } + +// AtomicIntegerArray cnts = GridTestUtils.getFieldValue(reuseList, PagesList.class, "cnts"); +// assertEquals(1, cnts.length()); + + return new T2<>(ids, 0); + } + + /** + * @param rl1 Data 1 (before stop). + * @param rl2 Data 2 (after restore). + */ + private void checkEquals(T2 rl1, T2 rl2) { + Assert.assertArrayEquals(rl1.get1(), rl2.get1()); + assertEquals(rl1.get2(), rl2.get2()); + } + + /** + * @param partsLists1 Data 1 (before stop). + * @param partsLists2 Data 2 (after restore). + */ + private void checkEquals(Map, int[]>> partsLists1, + Map, int[]>> partsLists2) { + assertEquals(partsLists1.size(), partsLists2.size()); + + for (Integer part : partsLists1.keySet()) { + T2, int[]> t1 = partsLists1.get(part); + T2, int[]> t2 = partsLists2.get(part); + + Map m1 = t1.get1(); + Map m2 = t2.get1(); + + assertEquals(m1.size(), m2.size()); + + for (Integer bucket : m1.keySet()) { + long tails1[] = m1.get(bucket); + long tails2[] = m2.get(bucket); + + Assert.assertArrayEquals(tails1, tails2); + } + + Assert.assertArrayEquals("Wrong counts [part=" + part + ']', t1.get2(), t2.get2()); + } + } + + /** + * @param ignite Node. + * @param cacheName Cache name. + * @return Cache free lists data. + */ + private Map, int[]>> getFreeListData(Ignite ignite, String cacheName) { + GridCacheContext ctx = ((IgniteEx)ignite).context().cache().cache(cacheName).context(); + + List parts = ctx.topology().localPartitions(); + + assertTrue(!parts.isEmpty()); + assertEquals(ctx.affinity().partitions(), parts.size()); + + Map, int[]>> res = new HashMap<>(); + + boolean foundNonEmpty = false; + boolean foundTails = false; + + for (GridDhtLocalPartition part : parts) { + FreeListImpl freeList = GridTestUtils.getFieldValue(part.dataStore(), "freeList"); + + if (freeList == null) + // Lazy store. + continue; + + AtomicReferenceArray buckets = GridTestUtils.getFieldValue(freeList, + FreeListImpl.class, "buckets"); + //AtomicIntegerArray cnts = GridTestUtils.getFieldValue(freeList, PagesList.class, "cnts"); + + assertNotNull(buckets); + //assertNotNull(cnts); + assertTrue(buckets.length() > 0); + //assertEquals(cnts.length(), buckets.length()); + + Map tailsPerBucket = new HashMap<>(); + + for (int i = 0; i < buckets.length(); i++) { + PagesList.Stripe[] tails = buckets.get(i); + + long ids[] = null; + + if (tails != null) { + ids = new long[tails.length]; + + for (int j = 0; j < tails.length; j++) + ids[j] = tails[j].tailId; + } + + tailsPerBucket.put(i, ids); + + if (tails != null) { + assertTrue(tails.length > 0); + + foundTails = true; + } + } + +// int[] cntsPerBucket = new int[cnts.length()]; +// +// for (int i = 0; i < cnts.length(); i++) { +// cntsPerBucket[i] = cnts.get(i); +// +// if (cntsPerBucket[i] > 0) +// foundNonEmpty = true; +// } + + res.put(part.id(), new T2<>(tailsPerBucket, (int[])null)); + } + + //assertTrue(foundNonEmpty); + assertTrue(foundTails); + + return res; + } + + /** + * + */ + private static class IndexedValue { + /** */ + @QuerySqlField(index = true) + private int iVal; + + /** */ + @QuerySqlField + private String sVal; + + /** + * @param iVal Indexed value. + */ + private IndexedValue(int iVal) { + this.iVal = iVal; + sVal = "string-" + iVal; + } + + /** + * @return Value. + */ + private int value() { + return iVal; + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/crc/IgniteDataIntegrityTests.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/crc/IgniteDataIntegrityTests.java new file mode 100644 index 0000000000000..b9b27c14f149e --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/crc/IgniteDataIntegrityTests.java @@ -0,0 +1,120 @@ +package org.apache.ignite.cache.database.db.wal.crc; + +import junit.framework.TestCase; +import java.io.EOFException; +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.util.concurrent.ThreadLocalRandom; +import org.apache.ignite.internal.processors.cache.database.wal.FileInput; +import org.apache.ignite.internal.processors.cache.database.wal.crc.IgniteDataIntegrityViolationException; +import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; + +/** + * + */ +public class IgniteDataIntegrityTests extends TestCase { + /** File input. */ + private FileInput fileInput; + + /** Random access file. */ + private RandomAccessFile randomAccessFile; + + /** {@inheritDoc} */ + @Override protected void setUp() throws Exception { + super.setUp(); + + File file = File.createTempFile("integrity", "dat"); + file.deleteOnExit(); + + randomAccessFile = new RandomAccessFile(file, "rw"); + + fileInput = new FileInput(randomAccessFile.getChannel(), ByteBuffer.allocate(1024)); + + PureJavaCrc32 pureJavaCrc32 = new PureJavaCrc32(); + + ByteBuffer buf = ByteBuffer.allocate(1024); + ThreadLocalRandom curr = ThreadLocalRandom.current(); + + for (int i = 0; i < 1024; i+=16) { + buf.putInt(curr.nextInt()); + buf.putInt(curr.nextInt()); + buf.putInt(curr.nextInt()); + buf.position(i); + buf.putInt(PureJavaCrc32.calcCrc32(buf, 12)); + } + + randomAccessFile.write(buf.array()); + randomAccessFile.getFD().sync(); + } + + /** + * + */ + public void testSuccessfulPath() throws Exception { + checkIntegrity(); + } + + /** + * + */ + public void testIntegrityViolationChecking() throws Exception { + toggleOneRandomBit(0, 1024 - 16); + + try { + checkIntegrity(); + + fail(); + } catch (IgniteDataIntegrityViolationException ex) { + //success + } + } + + /** + * + */ + public void testSkipingLastCorruptedEntry() throws Exception { + toggleOneRandomBit(1024 - 16, 1024); + + try { + checkIntegrity(); + + fail(); + } catch (EOFException ex) { + //success + } + } + + /** + * @param rangeFrom Range from. + * @param rangeTo Range to. + */ + private void toggleOneRandomBit(int rangeFrom, int rangeTo) throws IOException { + int pos = ThreadLocalRandom.current().nextInt(rangeFrom, rangeTo); + randomAccessFile.seek(pos); + + byte b = randomAccessFile.readByte(); + + b ^= (1 << 3); + + randomAccessFile.seek(pos); + randomAccessFile.writeByte(b); + randomAccessFile.getFD().sync(); + } + + /** + * + */ + private void checkIntegrity() throws Exception { + randomAccessFile.seek(0); + + for (int i = 0; i < 1024 / 16; i++) { + try(FileInput.Crc32CheckingFileInput in = fileInput.startRead(false)) { + in.readInt(); + in.readInt(); + in.readInt(); + } + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java new file mode 100644 index 0000000000000..e5a40d8e27b9c --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java @@ -0,0 +1,89 @@ +package org.apache.ignite.cache.database.pagemem; + +import java.nio.ByteBuffer; +import org.apache.ignite.internal.mem.DirectMemoryProvider; +import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.processors.database.BPlusTreeReuseSelfTest; +import org.apache.ignite.internal.util.lang.GridInClosure3X; +import org.apache.ignite.internal.util.typedef.CIX3; +import org.apache.ignite.testframework.junits.GridTestKernalContext; + +/** + * + */ +public class BPlusTreeReuseListPageMemoryImplSelfTest extends BPlusTreeReuseSelfTest { + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + super.beforeTest(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + } + + /** {@inheritDoc} */ + @Override protected PageMemory createPageMemory() throws Exception { + long[] sizes = new long[CPUS + 1]; + + for (int i = 0; i < sizes.length; i++) + sizes[i] = 1024 * MB / CPUS; + + sizes[CPUS] = 10 * MB; + + DirectMemoryProvider provider = new UnsafeMemoryProvider(sizes); + + GridCacheSharedContext sharedCtx = new GridCacheSharedContext<>( + new GridTestKernalContext(log), + null, + null, + null, + new NoOpPageStoreManager(), + new NoOpWALManager(), + new IgniteCacheDatabaseSharedManager(), + null, + null, + null, + null, + null, + null, + null, + null + ); + + PageMemory mem = new PageMemoryImpl(provider, sharedCtx, PAGE_SIZE, + new CIX3() { + @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { + assert false : "No evictions should happen during the test"; + } + }, new GridInClosure3X() { + @Override public void applyx(Long page, FullPageId fullPageId, PageMemoryEx pageMem) { + } + }, new CheckpointLockStateChecker() { + @Override public boolean checkpointLockIsHeldByThread() { + return true; + } + }); + + mem.start(); + + return mem; + } + + /** {@inheritDoc} */ + @Override protected long acquiredPages() { + return ((PageMemoryImpl)pageMem).acquiredPages(); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java new file mode 100644 index 0000000000000..061a4407cd934 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java @@ -0,0 +1,88 @@ +package org.apache.ignite.cache.database.pagemem; + +import java.nio.ByteBuffer; +import org.apache.ignite.internal.mem.DirectMemoryProvider; +import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.processors.database.BPlusTreeSelfTest; +import org.apache.ignite.internal.util.typedef.CIX3; +import org.apache.ignite.testframework.junits.GridTestKernalContext; + +/** + * + */ +public class BPlusTreeSelfTestPageMemoryImplSelfTest extends BPlusTreeSelfTest { + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + super.beforeTest(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + } + + /** {@inheritDoc} */ + @Override protected PageMemory createPageMemory() throws Exception { + long[] sizes = new long[CPUS + 1]; + + for (int i = 0; i < sizes.length; i++) + sizes[i] = 1024 * MB / CPUS; + + sizes[CPUS] = 10 * MB; + + DirectMemoryProvider provider = new UnsafeMemoryProvider(sizes); + + GridCacheSharedContext sharedCtx = new GridCacheSharedContext<>( + new GridTestKernalContext(log), + null, + null, + null, + new NoOpPageStoreManager(), + new NoOpWALManager(), + new IgniteCacheDatabaseSharedManager(), + null, + null, + null, + null, + null, + null, + null, + null + ); + + PageMemory mem = new PageMemoryImpl(provider, sharedCtx, PAGE_SIZE, + new CIX3() { + @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { + assert false : "No evictions should happen during the test"; + } + }, new CIX3(){ + @Override public void applyx(Long aLong, FullPageId fullPageId, PageMemoryEx ex) { + } + }, new CheckpointLockStateChecker() { + @Override public boolean checkpointLockIsHeldByThread() { + return true; + } + }); + + mem.start(); + + return mem; + } + + /** {@inheritDoc} */ + @Override protected long acquiredPages() { + return ((PageMemoryImpl)pageMem).acquiredPages(); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java new file mode 100644 index 0000000000000..a75031f598be8 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java @@ -0,0 +1,80 @@ +package org.apache.ignite.cache.database.pagemem; + +import java.io.File; +import java.nio.ByteBuffer; +import org.apache.ignite.internal.mem.DirectMemoryProvider; +import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.database.MetadataStorageSelfTest; +import org.apache.ignite.internal.util.lang.GridInClosure3X; +import org.apache.ignite.internal.util.typedef.CIX3; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.junits.GridTestKernalContext; + +/** + * + */ +public class MetadataStoragePageMemoryImplSelfTest extends MetadataStorageSelfTest{ + /** Make sure page is small enough to trigger multiple pages in a linked list. */ + public static final int PAGE_SIZE = 1024; + + /** */ + private static File allocationPath; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + allocationPath = U.resolveWorkDirectory(U.defaultWorkDirectory(), "pagemem", false); + } + + /** + * @param clean Clean flag. If {@code true}, will clean previous memory state and allocate + * new empty page memory. + * @return Page memory instance. + */ + @Override protected PageMemory memory(boolean clean) throws Exception { + long[] sizes = new long[10]; + + for (int i = 0; i < sizes.length; i++) + sizes[i] = 1024 * 1024; + + DirectMemoryProvider provider = new MappedFileMemoryProvider(log(), allocationPath, clean, sizes); + + GridCacheSharedContext sharedCtx = new GridCacheSharedContext<>( + new GridTestKernalContext(log), + null, + null, + null, + new NoOpPageStoreManager(), + new NoOpWALManager(), + new IgniteCacheDatabaseSharedManager(), + null, + null, + null, + null, + null, + null, + null, + null + ); + + return new PageMemoryImpl(provider, sharedCtx, PAGE_SIZE, + new CIX3() { + @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { + assert false : "No evictions should happen during the test"; + } + }, new GridInClosure3X() { + @Override public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) { + } + }, new CheckpointLockStateChecker() { + @Override public boolean checkpointLockIsHeldByThread() { + return true; + } + }); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java new file mode 100644 index 0000000000000..a17965522eaf7 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java @@ -0,0 +1,179 @@ +package org.apache.ignite.cache.database.pagemem; + +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.lang.IgniteFuture; + +/** + * + */ +public class NoOpPageStoreManager implements IgnitePageStoreManager { + /** */ + private ConcurrentMap allocators = new ConcurrentHashMap<>(); + + /** {@inheritDoc} */ + @Override public void beginRecover() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void finishRecover() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void initializeForCache(CacheConfiguration ccfg) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void shutdownForCache(GridCacheContext cacheCtx, boolean destroy) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onPartitionCreated(int cacheId, int partId) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onPartitionDestroyed(int cacheId, int partId, int tag) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void read(int cacheId, long pageId, ByteBuffer pageBuf) throws IgniteCheckedException { + + } + + /** {@inheritDoc} */ + @Override public boolean exists(int cacheId, int partId) throws IgniteCheckedException { + return false; + } + + /** {@inheritDoc} */ + @Override public void readHeader(int cacheId, int partId, ByteBuffer buf) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void write(int cacheId, long pageId, ByteBuffer pageBuf, int tag) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void sync(int cacheId, int partId) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void ensure(int cacheId, int partId) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public long pageOffset(int cacheId, long pageId) throws IgniteCheckedException { + return 0; + } + + /** {@inheritDoc} */ + @Override public long allocatePage(int cacheId, int partId, byte flags) throws IgniteCheckedException { + long root = PageIdUtils.pageId(partId, flags, 0); + + FullPageId fullId = new FullPageId(root, cacheId); + + AtomicInteger allocator = allocators.get(fullId); + + if (allocator == null) + allocator = F.addIfAbsent(allocators, fullId, new AtomicInteger(1)); + + return PageIdUtils.pageId(partId, flags, allocator.getAndIncrement()); + } + + /** {@inheritDoc} */ + @Override public int pages(int cacheId, int partId) throws IgniteCheckedException { + long root = PageIdUtils.pageId(partId, (byte)0, 0); + + FullPageId fullId = new FullPageId(root, cacheId); + + AtomicInteger allocator = allocators.get(fullId); + + if (allocator == null) + allocator = F.addIfAbsent(allocators, fullId, new AtomicInteger(2)); + + return allocator.get(); + } + + /** {@inheritDoc} */ + @Override public long metaPageId(int cacheId) { + return 1; + } + + /** {@inheritDoc} */ + @Override public void start(GridCacheSharedContext cctx) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void stop(boolean cancel) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onKernalStart(boolean reconnect) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onKernalStop(boolean cancel) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onDisconnected(IgniteFuture reconnectFut) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void printMemoryStats() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public Set savedCacheNames() { + return Collections.emptySet(); + } + + /** {@inheritDoc} */ + @Override public CacheConfiguration readConfiguration(String cacheName) { + return null; + } + + /** {@inheritDoc} */ + @Override public boolean hasIndexStore(int cacheId) { + return false; + } + + /** {@inheritDoc} */ + @Override public void onActivate(GridKernalContext kctx) { + + } + + /** {@inheritDoc} */ + @Override public void onDeActivate(GridKernalContext kctx) { + + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java new file mode 100644 index 0000000000000..5dfce5feb6dac --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java @@ -0,0 +1,106 @@ +package org.apache.ignite.cache.database.pagemem; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.pagemem.wal.StorageException; +import org.apache.ignite.internal.pagemem.wal.WALIterator; +import org.apache.ignite.internal.pagemem.wal.WALPointer; +import org.apache.ignite.internal.pagemem.wal.record.WALRecord; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.lang.IgniteFuture; + +/** + * + */ +public class NoOpWALManager implements IgniteWriteAheadLogManager { + /** {@inheritDoc} */ + @Override public boolean isAlwaysWriteFullPages() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean isFullSync() { + return false; + } + + /** {@inheritDoc} */ + @Override public void resumeLogging(WALPointer ptr) throws IgniteCheckedException { + + } + + /** {@inheritDoc} */ + @Override public WALPointer log(WALRecord entry) throws IgniteCheckedException, StorageException { + return null; + } + + /** {@inheritDoc} */ + @Override public void fsync(WALPointer ptr) throws IgniteCheckedException, StorageException { + + } + + /** {@inheritDoc} */ + @Override public WALIterator replay(WALPointer start) throws IgniteCheckedException, StorageException { + return null; + } + + /** {@inheritDoc} */ + @Override public boolean reserve(WALPointer start) throws IgniteCheckedException { + return false; + } + + /** {@inheritDoc} */ + @Override public void release(WALPointer start) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public int truncate(WALPointer ptr) { + return 0; + } + + /** {@inheritDoc} */ + @Override public boolean reserved(WALPointer ptr) { + return false; + } + + /** {@inheritDoc} */ + @Override public void start(GridCacheSharedContext cctx) throws IgniteCheckedException { + + } + + /** {@inheritDoc} */ + @Override public void stop(boolean cancel) { + + } + + /** {@inheritDoc} */ + @Override public void onKernalStart(boolean reconnect) throws IgniteCheckedException { + + } + + /** {@inheritDoc} */ + @Override public void onKernalStop(boolean cancel) { + + } + + /** {@inheritDoc} */ + @Override public void onDisconnected(IgniteFuture reconnectFut) { + + } + + /** {@inheritDoc} */ + @Override public void printMemoryStats() { + + } + + /** {@inheritDoc} */ + @Override public void onActivate(GridKernalContext kctx) throws IgniteCheckedException { + + } + + /** {@inheritDoc} */ + @Override public void onDeActivate(GridKernalContext kctx) throws IgniteCheckedException { + + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java new file mode 100644 index 0000000000000..912cd452a307e --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java @@ -0,0 +1,76 @@ +package org.apache.ignite.cache.database.pagemem; + +import java.io.File; +import java.nio.ByteBuffer; +import org.apache.ignite.internal.mem.DirectMemoryProvider; +import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.pagemem.impl.PageMemoryNoLoadSelfTest; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.util.lang.GridInClosure3X; +import org.apache.ignite.internal.util.typedef.CIX3; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.junits.GridTestKernalContext; + +/** + * + */ +public class PageMemoryImplNoLoadSelfTest extends PageMemoryNoLoadSelfTest { + /** + * @return Page memory implementation. + */ + @Override protected PageMemory memory() throws Exception { + File memDir = U.resolveWorkDirectory(U.defaultWorkDirectory(), "pagemem", false); + + long[] sizes = new long[10]; + + for (int i = 0; i < sizes.length; i++) + sizes[i] = 5 * 1024 * 1024; + + DirectMemoryProvider provider = new MappedFileMemoryProvider(log(), memDir, true, + sizes); + + GridCacheSharedContext sharedCtx = new GridCacheSharedContext<>( + new GridTestKernalContext(log), + null, + null, + null, + new NoOpPageStoreManager(), + new NoOpWALManager(), + new IgniteCacheDatabaseSharedManager(), + null, + null, + null, + null, + null, + null, + null, + null + ); + + return new PageMemoryImpl(provider, sharedCtx, PAGE_SIZE, + new CIX3() { + @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuffer, Integer tag) { + assert false : "No evictions should happen during the test"; + } + }, + new GridInClosure3X() { + @Override public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) { + } + }, new CheckpointLockStateChecker() { + @Override public boolean checkpointLockIsHeldByThread() { + return true; + } + }); + } + + /** {@inheritDoc} */ + @Override public void testPageHandleDeallocation() throws Exception { + // No-op. + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplReloadSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplReloadSelfTest.java new file mode 100644 index 0000000000000..2d654eb4654f6 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplReloadSelfTest.java @@ -0,0 +1,354 @@ +package org.apache.ignite.cache.database.pagemem; + +import java.io.File; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdAllocator; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.pagemem.PageUtils; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; +import org.apache.ignite.internal.util.lang.GridInClosure3X; +import org.apache.ignite.internal.util.typedef.CIX3; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.GridTestKernalContext; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.jsr166.ThreadLocalRandom8; + +/** + * + */ +public class PageMemoryImplReloadSelfTest extends GridCommonAbstractTest { + /** */ + public static final int PAGE_SIZE = 8 * 1024; + + /** */ + private static File allocationPath; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + allocationPath = U.resolveWorkDirectory(U.defaultWorkDirectory(), "pagemem", false); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + deleteRecursively(allocationPath); + } + + /** + * + */ + public void testPageContentReload() throws Exception { + fail(); //TODO @Ed + + PageMemory mem = memory(true); + + Collection pages = new ArrayList<>(); + + mem.start(); + + try { + for (int i = 0; i < 512; i++) + pages.add(allocatePage(mem)); + + for (FullPageId fullId : pages) { + assert TrackingPageIO.VERSIONS.latest().trackingPageFor(fullId.pageId(), PAGE_SIZE) != fullId.pageId(); + + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + long writeBuf = mem.writeLock(fullId.cacheId(), fullId.pageId(), page); + + PageIO.setPageId(writeBuf, fullId.pageId()); + + try { + for (int i = PageIO.COMMON_HEADER_END; i < 1024; i++) + PageUtils.putLong(writeBuf, PageIO.COMMON_HEADER_END + 8 * (i - PageIO.COMMON_HEADER_END), + fullId.pageId() * 1024 + i); + } + finally { + mem.writeUnlock(fullId.cacheId(), fullId.pageId(), page, null, true); + } + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + + for (FullPageId fullId : pages) { + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + try { + long pageAddr = mem.writeLock(fullId.cacheId(), fullId.pageId(), page); + + try { + for (int i = PageIO.COMMON_HEADER_END; i < 1024; i++) + assertEquals(fullId.pageId() * 1024 + i, + PageUtils.getLong(pageAddr, PageIO.COMMON_HEADER_END + 8 * (i - PageIO.COMMON_HEADER_END))); + + assertTrue(mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); + } + finally { + mem.readUnlock(fullId.cacheId(), fullId.pageId(), page); + } + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + } + finally { + mem.stop(); + } + + mem = memory(false); + + mem.start(); + + try { + for (FullPageId fullId : pages) { + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + try { + long pageAddr = mem.writeLock(fullId.cacheId(), fullId.pageId(), page); + + try { + for (int i = PageIO.COMMON_HEADER_END; i < 1024; i++) + assertEquals(fullId.pageId() * 1024 + i, + PageUtils.getLong(pageAddr, PageIO.COMMON_HEADER_END + 8 * (i - PageIO.COMMON_HEADER_END))); + } + finally { + mem.readUnlock(fullId.cacheId(), fullId.pageId(), page); + } + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + } + finally { + mem.stop(); + } + } + + /** + * @throws Exception If failed. + */ + public void testConcurrentReadWrite() throws Exception { + fail(); //TODO @Ed + final List pages = new ArrayList<>(); + + final Map map = new ConcurrentHashMap<>(); + + { + final PageMemory mem = memory(true); + + mem.start(); + + try { + for (int i = 0; i < 512; i++) + pages.add(allocatePage(mem)); + + for (FullPageId fullId : pages) { + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + writePage(mem, fullId.cacheId(), fullId.pageId(), page, 0, map); + + map.put(fullId, 0L); + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + + final AtomicBoolean stop = new AtomicBoolean(false); + final AtomicInteger ops = new AtomicInteger(); + + IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable() { + @Override public Object call() throws Exception { + ThreadLocalRandom8 rnd = ThreadLocalRandom8.current(); + + while (!stop.get()) { + FullPageId fullId = pages.get(rnd.nextInt(pages.size())); + + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + if (rnd.nextBoolean()) { + long val = rnd.nextLong(); + + writePage(mem, fullId.cacheId(), fullId.pageId(), page, val, map); + } + else + readPage(mem, fullId.cacheId(), fullId.pageId(), page, map); + + ops.incrementAndGet(); + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + + return null; + } + }, 8, "async-runner"); + + for (int i = 0; i < 60; i++) { + U.sleep(1_000); + + info("Ops/sec: " + ops.getAndSet(0)); + } + + stop.set(true); + + fut.get(); + + for (FullPageId fullId : pages) { + long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + readPage(mem, fullId.cacheId(), fullId.pageId(), page, map); + } + finally { + mem.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + } + finally { + mem.stop(); + } + } + + { + PageMemory mem0 = memory(false); + + mem0.start(); + + try { + for (FullPageId fullId : pages) { + long page = mem0.acquirePage(fullId.cacheId(), fullId.pageId()); + + try { + readPage(mem0, fullId.cacheId(), fullId.pageId(), page, map); + } + finally { + mem0.releasePage(fullId.cacheId(), fullId.pageId(), page); + } + } + } + finally { + mem0.stop(); + } + } + } + + /** + * @param clean Clean flag. If {@code true}, will clean previous memory state and allocate + * new empty page memory. + * @return Page memory instance. + */ + private PageMemory memory(boolean clean) throws Exception { + long[] sizes = new long[10]; + + for (int i = 0; i < sizes.length; i++) + sizes[i] = 5 * 1024 * 1024; + + MappedFileMemoryProvider provider = new MappedFileMemoryProvider(log(), allocationPath, clean, + sizes); + + GridCacheSharedContext sharedCtx = new GridCacheSharedContext<>( + new GridTestKernalContext(log), + null, + null, + null, + new NoOpPageStoreManager(), + new NoOpWALManager(), + new IgniteCacheDatabaseSharedManager(), + null, + null, + null, + null, + null, + null, + null, + null + ); + + return new PageMemoryImpl(provider, sharedCtx, PAGE_SIZE, + new CIX3() { + @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { + assert false : "No evictions should happen during the test"; + } + }, new GridInClosure3X() { + @Override public void applyx(Long page, FullPageId fullPageId, PageMemoryEx pageMem) { + } + }, new CheckpointLockStateChecker() { + @Override public boolean checkpointLockIsHeldByThread() { + return true; + } + }); + } + + /** + * @param val Value to write. + */ + private void writePage(PageMemory pageMem, int cacheId, long pageId, long page, long val, Map updateMap) { + long pageAddr = pageMem.writeLock(cacheId, pageId, page); + + try { + PageIO.setPageId(pageAddr, pageId); + + for (int i = PageIO.COMMON_HEADER_END; i < 1024; i++) + PageUtils.putLong(pageAddr, PageIO.COMMON_HEADER_END + 8 * (i - PageIO.COMMON_HEADER_END), val); + + updateMap.put(new FullPageId(pageId, cacheId), val); + } + finally { + pageMem.writeUnlock(cacheId, pageId, page, null, true); + } + } + + /** + * @param valMap Value map with control values. + */ + private void readPage(PageMemory pageMem, int cacheId, long pageId, long page, Map valMap) { + long pageAddr = pageMem.readLock(cacheId, pageId, page); + + try { + long expVal = valMap.get(new FullPageId(pageId, cacheId)); + + for (int i = PageIO.COMMON_HEADER_END; i < 1024; i++) { + long val = PageUtils.getLong(pageAddr, PageIO.COMMON_HEADER_END + 8 * (i - PageIO.COMMON_HEADER_END)); + + assertEquals("Unexpected value at position: " + i, expVal, val); + } + } + finally { + pageMem.readUnlock(cacheId, pageId, page); + } + } + + /** + * @param mem Memory. + * @return Page. + */ + public static FullPageId allocatePage(PageIdAllocator mem) throws IgniteCheckedException { + return new FullPageId(mem.allocatePage(0, 1, PageIdAllocator.FLAG_DATA), 0); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java new file mode 100644 index 0000000000000..b3665ccc31a82 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java @@ -0,0 +1,96 @@ +package org.apache.ignite.cache.database.pagemem; + +import java.nio.ByteBuffer; +import org.apache.ignite.internal.mem.DirectMemoryProvider; +import org.apache.ignite.internal.mem.IgniteOutOfMemoryException; +import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdAllocator; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.util.lang.GridInClosure3X; +import org.apache.ignite.internal.util.typedef.CIX3; +import org.apache.ignite.testframework.junits.GridTestKernalContext; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger; + +/** + * + */ +public class PageMemoryImplTest extends GridCommonAbstractTest { + /** Mb. */ + private static final long MB = 1024 * 1024; + + /** Page size. */ + private static final int PAGE_SIZE = 1024; + + /** + * @throws Exception if failed. + */ + public void testThatAllocationTooMuchPagesCauseToOOMException() throws Exception { + PageMemoryImpl memory = createPageMemory(); + + try { + while (!Thread.currentThread().isInterrupted()) + memory.allocatePage(1, PageIdAllocator.INDEX_PARTITION, PageIdAllocator.FLAG_IDX); + } + catch (IgniteOutOfMemoryException ignore) { + //Success + } + + assertFalse(memory.safeToUpdate()); + } + + /** + * + */ + private PageMemoryImpl createPageMemory() throws Exception { + long[] sizes = new long[5]; + + for (int i = 0; i < sizes.length; i++) + sizes[i] = 1024 * MB / 4; + + sizes[4] = 10 * MB; + + DirectMemoryProvider provider = new UnsafeMemoryProvider(sizes); + + GridCacheSharedContext sharedCtx = new GridCacheSharedContext<>( + new GridTestKernalContext(new GridTestLog4jLogger()), + null, + null, + null, + new NoOpPageStoreManager(), + new NoOpWALManager(), + new IgniteCacheDatabaseSharedManager(), + null, + null, + null, + null, + null, + null, + null, + null + ); + + PageMemoryImpl mem = new PageMemoryImpl(provider, sharedCtx, PAGE_SIZE, + new CIX3() { + @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { + assert false : "No evictions should happen during the test"; + } + }, new GridInClosure3X() { + @Override public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) { + } + }, new CheckpointLockStateChecker() { + @Override public boolean checkpointLockIsHeldByThread() { + return true; + } + }); + + mem.start(); + + return mem; + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java new file mode 100644 index 0000000000000..05921790ac902 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java @@ -0,0 +1,348 @@ +package org.apache.ignite.cache.database.standbycluster; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ThreadLocalRandom; +import org.apache.ignite.Ignite; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +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.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public abstract class GridChangeGlobalStateAbstractTest extends GridCommonAbstractTest { + /** Primary suffix. */ + private static final String primarySuffix = "-primary"; + + /** BackUp suffix. */ + private static final String backUpSuffix = "-backUp"; + + /** BackUp suffix. */ + private static final String clientSuffix = "-client"; + + /** Primary ip finder. */ + protected final TcpDiscoveryIpFinder primaryIpFinder = new TcpDiscoveryVmIpFinder(true); + + /** Back up ip finder. */ + protected final TcpDiscoveryIpFinder backUpIpFinder = new TcpDiscoveryVmIpFinder(true); + + /** Consistent id count. */ + private int consistentIdCnt; + + /** Nodes. */ + protected Map nodes = new ConcurrentHashMap<>(); + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + nodes.clear(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), testName(), true)); + + startPrimaryNodes(primaryNodes()); + + startPrimaryClientNodes(primaryClientNodes()); + + startBackUpNodes(backUpNodes()); + + startBackUpClientNodes(backUpClientNodes()); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAll(clientSuffix); + + stopAll(primarySuffix); + + stopAll(backUpSuffix); + + nodes.clear(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), testName(), true)); + } + + /** + * + */ + protected int primaryNodes() { + return 3; + } + + /** + * + */ + protected int primaryClientNodes() { + return 3; + } + + /** + * + */ + protected int backUpNodes() { + return 3; + } + + /** + * + */ + protected int backUpClientNodes() { + return 3; + } + + /** + * @param idx idx. + */ + protected Ignite primary(int idx) { + return nodes.get("node" + idx + primarySuffix); + } + + /** + * @param idx idx. + */ + protected Ignite primaryClient(int idx) { + return nodes.get("node" + idx + primarySuffix + clientSuffix); + } + + /** + * @param idx idx. + */ + protected Ignite backUp(int idx) { + return nodes.get("node" + idx + backUpSuffix); + } + + /** + * @param idx idx. + */ + protected Ignite backUpClient(int idx) { + return nodes.get("node" + idx + backUpSuffix + clientSuffix); + } + + /** + * @param cnt Count. + */ + protected void startPrimaryNodes(int cnt) throws Exception { + for (int i = 0; i < cnt; i++) + startPrimary(i); + } + + /** + * @param idx Index. + */ + protected void startPrimary(int idx) throws Exception { + String node = "node" + idx; + + String name = node + primarySuffix; + + IgniteConfiguration cfg = getConfiguration(name); + cfg.setConsistentId(node); + cfg.setActiveOnStart(true); + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(primaryIpFinder); + + Ignite ig = startGrid(name, cfg); + + nodes.put(name, ig); + } + + /** + * @param cnt Count. + */ + protected void startBackUpNodes(int cnt) throws Exception { + for (int i = 0; i < cnt; i++) + startBackUp(i); + } + + /** + * @param idx Index. + */ + protected void startBackUp(int idx) throws Exception { + String node = "node" + idx; + + String name = node + backUpSuffix; + + IgniteConfiguration cfg = getConfiguration(name); + cfg.setConsistentId(node); + cfg.setActiveOnStart(false); + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(backUpIpFinder); + + Ignite ig = startGrid(name, cfg); + + nodes.put(name, ig); + } + + /** + * @param cnt Count. + */ + protected void startPrimaryClientNodes(int cnt) throws Exception { + for (int i = 0; i < cnt; i++) { + String node = "node" + i; + + String name = node + primarySuffix + clientSuffix; + + IgniteConfiguration cfg = getConfiguration(name); + cfg.setConsistentId(node); + cfg.setClientMode(true); + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(primaryIpFinder); + + Ignite ig = startGrid(name, cfg); + + nodes.put(name, ig); + } + } + + /** + * @param cnt Count. + */ + protected void startBackUpClientNodes(int cnt) throws Exception { + for (int i = 0; i < cnt; i++) { + String node = "node" + i; + + String name = node + backUpSuffix + clientSuffix; + + IgniteConfiguration cfg = getConfiguration(name); + cfg.setConsistentId(node); + cfg.setActiveOnStart(false); + cfg.setClientMode(true); + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(backUpIpFinder); + + Ignite ig = startGrid(name, cfg); + + nodes.put(name, ig); + } + } + + /** + * + */ + protected Iterable allBackUpNodes(){ + List r = new ArrayList<>(); + + for (String name : this.nodes.keySet()) + if (name.contains(backUpSuffix)) + r.add(nodes.get(name)); + + return r; + } + + /** + * + */ + protected Ignite randomBackUp(boolean includeClient) { + int nodes = 0; + + List igs = new ArrayList<>(); + + for (String name : this.nodes.keySet()) + if (name.contains(backUpSuffix)){ + if (includeClient) + igs.add(this.nodes.get(name)); + else { + if (name.contains(clientSuffix)) + continue; + + igs.add(this.nodes.get(name)); + } + } + + int idx = ThreadLocalRandom.current().nextInt(0, igs.size()); + + return igs.get(idx); + } + + + /** + * @param i Idx. + */ + protected void stopPrimary(int i) { + String name = "node" + i + primarySuffix; + + nodes.get(name).close(); + + nodes.remove(name); + } + + /** + * + */ + protected void stopAllPrimary() { + stopAll(primarySuffix); + } + + /** + * + */ + protected void stopAllBackUp() { + stopAll(backUpSuffix); + } + + /** + * + */ + protected void stopAllClient() { + stopAll(clientSuffix); + } + + /** + * @param suffix Suffix. + */ + private void stopAll(String suffix) { + for (String name : nodes.keySet()) + if (name.contains(suffix)) { + Ignite ig = nodes.get(name); + + stopGrid(ig.name()); + + nodes.remove(name); + } + } + + /** + * @param gridName Grid name. + */ + @Override protected IgniteConfiguration getConfiguration(final String gridName) throws Exception { + final IgniteConfiguration cfg = super.getConfiguration(gridName); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + pCfg.setPersistenceStorePath(testName() + "/db"); + pCfg.setWalArchivePath(testName() + "/db/wal/archive"); + pCfg.setWalStorePath(testName() + "/db/wal"); + + cfg.setPersistenceConfiguration(pCfg); + + final MemoryConfiguration memCfg = new MemoryConfiguration(); + + memCfg.setPageSize(1024); + memCfg.setConcurrencyLevel(64); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + memPlcCfg.setSize(5 * 1024 * 1024); + memPlcCfg.setName("dfltMemPlc"); + + memCfg.setMemoryPolicies(memPlcCfg); + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(memCfg); + + return cfg; + } + + /** + * + */ + protected String testName() { + return getClass().getSimpleName(); + } + +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateCacheTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateCacheTest.java new file mode 100644 index 0000000000000..5152747732f7d --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateCacheTest.java @@ -0,0 +1,151 @@ +package org.apache.ignite.cache.database.standbycluster; + +import javax.cache.configuration.Configuration; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.GridCacheProcessor; +import org.apache.ignite.internal.util.typedef.F; + +/** + * + */ +public class GridChangeGlobalStateCacheTest extends GridChangeGlobalStateAbstractTest { + /** + * + */ + public void testCheckValueAfterActivation(){ + String cacheName = "my-cache"; + + Ignite ig1P = primary(0); + + Ignite ig1B = backUp(0); + Ignite ig2B = backUp(1); + Ignite ig3B = backUp(2); + + IgniteCache cacheP = ig1P.getOrCreateCache(cacheName); + + cacheP.put("key","value"); + + stopAllPrimary(); + + ig1B.active(true); + + IgniteCache cache1B = ig1B.cache(cacheName); + IgniteCache cache2B = ig2B.cache(cacheName); + IgniteCache cache3B = ig3B.cache(cacheName); + + assertTrue(cache1B != null); + assertTrue(cache2B != null); + assertTrue(cache3B != null); + + assertEquals(cache1B.get("key"), "value"); + assertEquals(cache2B.get("key"), "value"); + assertEquals(cache3B.get("key"), "value"); + } + + /** + * + */ + public void testMoreKeyValueAfterActivate() throws Exception { + String cacheName = "my-cache"; + + Ignite ig1P = primary(0); + Ignite ig2P = primary(1); + Ignite ig3P = primary(2); + + Ignite ig1B = backUp(0); + Ignite ig2B = backUp(1); + Ignite ig3B = backUp(2); + + CacheConfiguration cacheCfg = new CacheConfiguration<>(cacheName); + + IgniteCache cache1P = ig1P.getOrCreateCache(cacheCfg); + + for (int i = 0; i < 4_000; i++) + cache1P.put("key" + i, "value" + i); + + IgniteCache cache2P = ig2P.cache(cacheName); + + for (int i = 4_000; i < 8_000; i++) + cache2P.put("key" + i, "value" + i); + + IgniteCache cache3P = ig3P.cache(cacheName); + + for (int i = 8_000; i < 12_000; i++) + cache3P.put("key" + i, "value" + i); + + stopAllPrimary(); + + ig1B.active(true); + + IgniteCache cache1B = ig1B.cache(cacheName); + IgniteCache cache2B = ig2B.cache(cacheName); + IgniteCache cache3B = ig3B.cache(cacheName); + + assertTrue(cache1B != null); + assertTrue(cache2B != null); + assertTrue(cache3B != null); + + for (int i = 0; i < 4_000; i++) + assertEquals("value" + i, cache1B.get("key" + i)); + + for (int i = 4_000; i < 8_000; i++) + assertEquals("value" + i, cache2B.get("key" + i)); + + for (int i = 8_000; i < 12_000; i++) + assertEquals("value" + i, cache3B.get("key" + i)); + } + + /** + * @throws Exception if fail. + */ + public void testDeActivateAndActivateCacheValue() throws Exception { + String chName = "myCache"; + + Ignite ig1 = primary(0); + Ignite ig2 = primary(1); + Ignite ig3 = primary(2); + + IgniteCache cacheExp = ig1.getOrCreateCache(chName); + + Configuration cfgExp = cacheExp.getConfiguration(CacheConfiguration.class); + + cacheExp.put("key", "value"); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + ig2.active(false); + + IgniteEx ex1 = (IgniteEx)ig1; + IgniteEx ex2 = (IgniteEx)ig2; + IgniteEx ex3 = (IgniteEx)ig3; + + GridCacheProcessor cache1 = ex1.context().cache(); + GridCacheProcessor cache2 = ex2.context().cache(); + GridCacheProcessor cache3 = ex3.context().cache(); + + assertTrue(F.isEmpty(cache1.jcaches())); + assertTrue(F.isEmpty(cache2.jcaches())); + assertTrue(F.isEmpty(cache3.jcaches())); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + ig3.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + IgniteCache cacheAct = ig2.cache(chName); + + Configuration cfgAct = cacheAct.getConfiguration(CacheConfiguration.class); + + assertEquals("value", cacheAct.get("key")); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java new file mode 100644 index 0000000000000..28a167df2eeb3 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java @@ -0,0 +1,95 @@ +package org.apache.ignite.cache.database.standbycluster; + +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; + +/** + * + */ +public class GridChangeGlobalStateDataStreamerTest extends GridChangeGlobalStateAbstractTest { + /** {@inheritDoc} */ + @Override protected int backUpNodes() { + return 0; + } + + /** {@inheritDoc} */ + @Override protected int backUpClientNodes() { + return 0; + } + + /** + * + */ + public void testDeActivateAndActivateDataStreamer() throws InterruptedException { + + Ignite ig1 = primary(0); + Ignite ig2 = primary(1); + Ignite ig3 = primary(2); + + Ignite ig1C = primaryClient(0); + Ignite ig2C = primaryClient(1); + Ignite ig3C = primaryClient(2); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + assertTrue(ig1C.active()); + assertTrue(ig2C.active()); + assertTrue(ig3C.active()); + + String cacheName = "myStreamCache"; + + ig2C.getOrCreateCache(cacheName); + + try (IgniteDataStreamer stmr = ig1.dataStreamer(cacheName)) { + for (int i = 0; i < 100; i++) + stmr.addData(i, Integer.toString(i)); + } + + ig2C.active(false); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + assertTrue(!ig1C.active()); + assertTrue(!ig2C.active()); + assertTrue(!ig3C.active()); + + boolean fail = false; + + try { + IgniteDataStreamer strm2 = ig2.dataStreamer(cacheName); + } + catch (Exception e) { + fail = true; + + assertTrue(e.getMessage().contains("can not perform operation, because cluster inactive")); + } + + if (!fail) + fail("exception was not throw"); + + ig3C.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + assertTrue(ig1C.active()); + assertTrue(ig2C.active()); + assertTrue(ig3C.active()); + + try (IgniteDataStreamer stmr2 = ig2.dataStreamer(cacheName)) { + for (int i = 100; i < 200; i++) + stmr2.addData(i, Integer.toString(i)); + } + + IgniteCache cache = ig3.cache(cacheName); + + for (int i = 0; i < 200; i++) + assertEquals(String.valueOf(i), cache.get(i)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java new file mode 100644 index 0000000000000..d4e83d2ff1bf3 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java @@ -0,0 +1,261 @@ +package org.apache.ignite.cache.database.standbycluster; + +import java.util.concurrent.Callable; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteAtomicLong; +import org.apache.ignite.IgniteAtomicSequence; +import org.apache.ignite.IgniteCountDownLatch; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.GridCacheProcessor; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; + +import static org.apache.ignite.testframework.GridTestUtils.runAsync; + +/** + * + */ +public class GridChangeGlobalStateDataStructureTest extends GridChangeGlobalStateAbstractTest { + /** + * + */ + public void testDeActivateAndActivateAtomicLong() throws Exception{ + String lName = "myLong"; + + Ignite ig1 = primary(0); + Ignite ig2 = primary(1); + Ignite ig3 = primary(2); + + IgniteAtomicLong lexp = ig1.atomicLong(lName, 100, true); + + lexp.incrementAndGet(); + lexp.incrementAndGet(); + lexp.incrementAndGet(); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + ig2.active(false); + + IgniteEx ex1 = (IgniteEx)ig1; + IgniteEx ex2 = (IgniteEx)ig2; + IgniteEx ex3 = (IgniteEx)ig3; + + GridCacheProcessor cache1 = ex1.context().cache(); + GridCacheProcessor cache2 = ex2.context().cache(); + GridCacheProcessor cache3 = ex3.context().cache(); + + assertTrue(F.isEmpty(cache1.jcaches())); + assertTrue(F.isEmpty(cache2.jcaches())); + assertTrue(F.isEmpty(cache3.jcaches())); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + ig3.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + IgniteAtomicLong lact1 = ig1.atomicLong(lName, 0, false); + IgniteAtomicLong lact2 = ig2.atomicLong(lName, 0, false); + IgniteAtomicLong lact3 = ig3.atomicLong(lName, 0, false); + + assertEquals(103, lact1.get()); + assertEquals(103, lact2.get()); + assertEquals(103, lact3.get()); + + lact1.incrementAndGet(); + + assertEquals(104, lact1.get()); + assertEquals(104, lact2.get()); + assertEquals(104, lact3.get()); + + lact2.incrementAndGet(); + + assertEquals(105, lact1.get()); + assertEquals(105, lact2.get()); + assertEquals(105, lact3.get()); + + lact3.incrementAndGet(); + + assertEquals(106, lact3.get()); + assertEquals(106, lact3.get()); + assertEquals(106, lact3.get()); + } + + /** + * + */ + public void testDeActivateAndActivateCountDownLatch() throws Exception { + final AtomicInteger cnt = new AtomicInteger(); + + String latchName = "myLatch"; + + Ignite ig1 = primary(0); + Ignite ig2 = primary(1); + Ignite ig3 = primary(2); + + IgniteCountDownLatch latchExp1 = ig1.countDownLatch(latchName, 5, false, true); + + latchExp1.countDown(); + + assertEquals(4, latchExp1.count()); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + ig2.active(false); + + IgniteEx ex1 = (IgniteEx)ig1; + IgniteEx ex2 = (IgniteEx)ig2; + IgniteEx ex3 = (IgniteEx)ig3; + + GridCacheProcessor cache1 = ex1.context().cache(); + GridCacheProcessor cache2 = ex2.context().cache(); + GridCacheProcessor cache3 = ex3.context().cache(); + + assertTrue(F.isEmpty(cache1.jcaches())); + assertTrue(F.isEmpty(cache2.jcaches())); + assertTrue(F.isEmpty(cache3.jcaches())); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + ig3.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + final IgniteCountDownLatch latchAct1 = ig1.countDownLatch(latchName, 0, false, false); + final IgniteCountDownLatch latchAct2 = ig2.countDownLatch(latchName, 0, false, false); + final IgniteCountDownLatch latchAct3 = ig3.countDownLatch(latchName, 0, false, false); + + runAsync(new Callable() { + @Override public Void call() throws Exception { + latchAct1.await(); + cnt.incrementAndGet(); + return null; + } + }); + + runAsync(new Callable() { + @Override public Void call() throws Exception { + latchAct2.await(); + cnt.incrementAndGet(); + return null; + } + }); + + runAsync(new Callable() { + @Override public Void call() throws Exception { + latchAct3.await(); + cnt.incrementAndGet(); + return null; + } + }); + + + assertEquals(4, latchAct1.count()); + assertEquals(4, latchAct2.count()); + assertEquals(4, latchAct3.count()); + + latchAct1.countDown(); + latchAct2.countDown(); + latchAct3.countDown(); + + assertEquals(1, latchAct1.count()); + assertEquals(1, latchAct2.count()); + assertEquals(1, latchAct3.count()); + + latchAct1.countDown(); + + U.sleep(3000); + + assertEquals(3, cnt.get()); + } + + /** + * + */ + public void testDeActivateAndActivateAtomicSequence(){ + String seqName = "mySeq"; + + Ignite ig1 = primary(0); + Ignite ig2 = primary(1); + Ignite ig3 = primary(2); + + IgniteAtomicSequence seqExp1 = ig1.atomicSequence(seqName, 0, true); + IgniteAtomicSequence seqExp2 = ig2.atomicSequence(seqName, 0, false); + IgniteAtomicSequence seqExp3 = ig3.atomicSequence(seqName, 0, false); + + assertEquals(0, seqExp1.get()); + assertEquals(1000, seqExp2.get()); + assertEquals(2000, seqExp3.get()); + + seqExp1.incrementAndGet(); + seqExp2.incrementAndGet(); + seqExp3.incrementAndGet(); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + ig2.active(false); + + IgniteEx ex1 = (IgniteEx)ig1; + IgniteEx ex2 = (IgniteEx)ig2; + IgniteEx ex3 = (IgniteEx)ig3; + + GridCacheProcessor cache1 = ex1.context().cache(); + GridCacheProcessor cache2 = ex2.context().cache(); + GridCacheProcessor cache3 = ex3.context().cache(); + + assertTrue(F.isEmpty(cache1.jcaches())); + assertTrue(F.isEmpty(cache2.jcaches())); + assertTrue(F.isEmpty(cache3.jcaches())); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + ig3.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + IgniteAtomicSequence seqAct1 = ig1.atomicSequence(seqName, 0, false); + IgniteAtomicSequence seqAct2 = ig2.atomicSequence(seqName, 0, false); + IgniteAtomicSequence seqAct3 = ig3.atomicSequence(seqName, 0, false); + + assertEquals(1, seqAct1.get()); + assertEquals(1001, seqAct2.get()); + assertEquals(2001, seqAct3.get()); + + seqAct1.incrementAndGet(); + + assertEquals(2, seqAct1.get()); + assertEquals(1001, seqAct2.get()); + assertEquals(2001, seqAct3.get()); + + seqAct2.incrementAndGet(); + + assertEquals(2, seqAct1.get()); + assertEquals(1002, seqAct2.get()); + assertEquals(2001, seqAct3.get()); + + seqAct3.incrementAndGet(); + + assertEquals(2, seqAct1.get()); + assertEquals(1002, seqAct2.get()); + assertEquals(2002, seqAct3.get()); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java new file mode 100644 index 0000000000000..112bd73030c24 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java @@ -0,0 +1,336 @@ +package org.apache.ignite.cache.database.standbycluster; + +import java.util.concurrent.Callable; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.IgniteInternalFuture; + +import static java.lang.Thread.sleep; +import static org.apache.ignite.testframework.GridTestUtils.runAsync; + +/** + * + */ +public class GridChangeGlobalStateFailOverTest extends GridChangeGlobalStateAbstractTest { + /** {@inheritDoc} */ + @Override protected int primaryNodes() { + return 0; + } + + /** {@inheritDoc} */ + @Override protected int primaryClientNodes() { + return 0; + } + + /** {@inheritDoc} */ + @Override protected int backUpClientNodes() { + return 0; + } + + /** {@inheritDoc} */ + @Override protected int backUpNodes() { + return 4; + } + + /** + * + */ + public void testActivateDeActivateOnFixTopology() throws Exception { + final Ignite igB1 = backUp(0); + final Ignite igB2 = backUp(1); + final Ignite igB3 = backUp(2); + + assertTrue(!igB1.active()); + assertTrue(!igB2.active()); + assertTrue(!igB3.active()); + + final AtomicInteger cntA = new AtomicInteger(); + final AtomicInteger cntD = new AtomicInteger(); + + final AtomicLong timeA = new AtomicLong(); + final AtomicLong timeD = new AtomicLong(); + + final AtomicBoolean stop = new AtomicBoolean(); + + final AtomicBoolean canAct = new AtomicBoolean(true); + + try { + final IgniteInternalFuture af = runAsync(new Callable() { + @Override public Void call() throws Exception { + while (!stop.get()) { + Ignite ig = randomBackUp(false); + + if (canAct.get()) { + long start = System.currentTimeMillis(); + + ig.active(true); + + timeA.addAndGet((System.currentTimeMillis() - start)); + + cntA.incrementAndGet(); + + for (Ignite ign : allBackUpNodes()) + assertTrue(ign.active()); + + canAct.set(false); + } + + } + return null; + } + }); + + final IgniteInternalFuture df = runAsync(new Callable() { + @Override public Void call() throws Exception { + while (!stop.get()) { + Ignite ig = randomBackUp(false); + + if (!canAct.get()) { + long start = System.currentTimeMillis(); + + ig.active(false); + + timeD.addAndGet((System.currentTimeMillis() - start)); + + cntD.incrementAndGet(); + + for (Ignite ign : allBackUpNodes()) + assertTrue(!ign.active()); + + canAct.set(true); + } + + } + return null; + } + }); + + sleep(60_000); + + stop.set(true); + + af.get(); + df.get(); + } + finally { + log.info("total activate/deactivate:" + cntA.get() + "/" + cntD.get() + " aTime/dTime:" + + (timeA.get() / cntA.get() + "/" + (timeD.get() / cntD.get()) + " nodes: " + backUpNodes())); + } + } + + /** + * + */ + public void testActivateDeActivateOnJoiningNode() throws Exception { + final Ignite igB1 = backUp(0); + final Ignite igB2 = backUp(1); + final Ignite igB3 = backUp(2); + + assertTrue(!igB1.active()); + assertTrue(!igB2.active()); + assertTrue(!igB3.active()); + + final AtomicInteger cntA = new AtomicInteger(); + final AtomicInteger cntD = new AtomicInteger(); + + final AtomicLong timeA = new AtomicLong(); + final AtomicLong timeD = new AtomicLong(); + + final AtomicBoolean stop = new AtomicBoolean(); + + final AtomicBoolean canAct = new AtomicBoolean(true); + final AtomicInteger seqIdx = new AtomicInteger(backUpNodes()); + + try { + final IgniteInternalFuture af = runAsync(new Callable() { + @Override public Void call() throws Exception { + while (!stop.get()) { + Ignite ig = randomBackUp(false); + + if (canAct.get()) { + long start = System.currentTimeMillis(); + + ig.active(true); + + timeA.addAndGet((System.currentTimeMillis() - start)); + + cntA.incrementAndGet(); + + for (Ignite ign : allBackUpNodes()) + assertTrue(ign.active()); + + canAct.set(false); + } + + } + return null; + } + }); + + final IgniteInternalFuture df = runAsync(new Callable() { + @Override public Void call() throws Exception { + while (!stop.get()) { + Ignite ig = randomBackUp(false); + + if (!canAct.get()) { + long start = System.currentTimeMillis(); + + ig.active(false); + + timeD.addAndGet((System.currentTimeMillis() - start)); + + cntD.incrementAndGet(); + + for (Ignite ign : allBackUpNodes()) + assertTrue(!ign.active()); + + canAct.set(true); + } + + } + return null; + } + }); + + IgniteInternalFuture jf1 = runAsync(new Callable() { + @Override public Void call() throws Exception { + while (!stop.get()) + startBackUp(seqIdx.incrementAndGet()); + + return null; + } + }); + + IgniteInternalFuture jf2 = runAsync(new Callable() { + @Override public Void call() throws Exception { + while (!stop.get()) + startBackUp(seqIdx.incrementAndGet()); + + return null; + } + }); + + sleep(60_000); + + stop.set(true); + + af.get(); + df.get(); + jf1.get(); + jf2.get(); + } + finally { + log.info("total started nodes: " + (seqIdx.get() - backUpNodes())); + + log.info("total activate/deactivate:" + cntA.get() + "/" + cntD.get() + " aTime/dTime: " + + (timeA.get() / cntA.get() + "/" + (timeD.get() / cntD.get())) + ); + } + } + + /** + * + */ + public void testActivateDeActivateOnFixTopologyWithPutValues() throws Exception { + final Ignite igB1 = backUp(0); + final Ignite igB2 = backUp(1); + final Ignite igB3 = backUp(2); + + assertTrue(!igB1.active()); + assertTrue(!igB2.active()); + assertTrue(!igB3.active()); + + final CacheConfiguration ccfg = new CacheConfiguration<>(); + ccfg.setName("main-cache"); + + final AtomicInteger cnt = new AtomicInteger(); + + final AtomicInteger cntA = new AtomicInteger(); + final AtomicInteger cntD = new AtomicInteger(); + + final AtomicLong timeA = new AtomicLong(); + final AtomicLong timeD = new AtomicLong(); + + final AtomicBoolean stop = new AtomicBoolean(); + + final AtomicBoolean canAct = new AtomicBoolean(true); + + try { + final IgniteInternalFuture af = runAsync(new Callable() { + @Override public Void call() throws Exception { + while (!stop.get()) { + Ignite ig = randomBackUp(false); + + if (canAct.get()) { + long start = System.currentTimeMillis(); + + ig.active(true); + + IgniteCache cache = ig.getOrCreateCache(ccfg); + + cache.put("key" + cnt.get(), "value" + cnt.get()); + + cnt.incrementAndGet(); + + timeA.addAndGet((System.currentTimeMillis() - start)); + + cntA.incrementAndGet(); + + for (Ignite ign : allBackUpNodes()) + assertTrue(ign.active()); + + canAct.set(false); + } + + } + return null; + } + }); + + final IgniteInternalFuture df = runAsync(new Callable() { + @Override public Void call() throws Exception { + while (!stop.get()) { + Ignite ig = randomBackUp(false); + + if (!canAct.get()) { + long start = System.currentTimeMillis(); + + IgniteCache cache = ig.getOrCreateCache(ccfg); + + for (int i = 0; i < cnt.get(); i++) + assertEquals("value" + i, cache.get("key" + i)); + + ig.active(false); + + timeD.addAndGet((System.currentTimeMillis() - start)); + + cntD.incrementAndGet(); + + for (Ignite ign : allBackUpNodes()) + assertTrue(!ign.active()); + + canAct.set(true); + } + + } + return null; + } + }); + + sleep(60_000); + + stop.set(true); + + af.get(); + df.get(); + } + finally { + log.info("total activate/deactivate:" + cntA.get() + "/" + cntD.get() + " aTime/dTime:" + + (timeA.get() / cntA.get() + "/" + (timeD.get() / cntD.get()) + " nodes: " + backUpNodes())); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java new file mode 100644 index 0000000000000..5923d717b75c8 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java @@ -0,0 +1,85 @@ +package org.apache.ignite.cache.database.standbycluster; + +import java.util.Collection; +import org.apache.ignite.Ignite; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.services.Service; +import org.apache.ignite.services.ServiceConfiguration; +import org.apache.ignite.services.ServiceContext; +import org.apache.ignite.services.ServiceDescriptor; + +/** + * + */ +public class GridChangeGlobalStateServiceTest extends GridChangeGlobalStateAbstractTest { + /** {@inheritDoc} */ + @Override protected int backUpClientNodes() { + return 0; + } + + /** {@inheritDoc} */ + @Override protected int primaryNodes() { + return 1; + } + + /** {@inheritDoc} */ + @Override protected int backUpNodes() { + return 1; + } + + /** + * + */ + public void testDeployService() throws Exception { + Ignite ig1P = primary(0); + + Ignite ig1B = backUp(0); + + String serName = "service"; + + ServiceConfiguration serConf = new ServiceConfiguration(); + serConf.setTotalCount(1); + serConf.setName(serName); + serConf.setService(new TestService()); + + ig1P.services().deploy(serConf); + + stopAllPrimary(); + + ig1B.active(true); + + U.sleep(3000); + + Collection descs = ig1B.services().serviceDescriptors(); + + assertTrue(!F.isEmpty(descs)); + + TestService srv = ig1B.services().service(serName); + + assertTrue(srv != null); + } + + /** + * + */ + private static class TestService implements Service{ + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public void cancel(ServiceContext ctx) { + System.out.println("cancel service"); + } + + /** {@inheritDoc} */ + @Override public void init(ServiceContext ctx) throws Exception { + System.out.println("init service"); + } + + /** {@inheritDoc} */ + @Override public void execute(ServiceContext ctx) throws Exception { + System.out.println("execute service"); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateSuite.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateSuite.java new file mode 100644 index 0000000000000..10a8bfbb03e8d --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateSuite.java @@ -0,0 +1,24 @@ +package org.apache.ignite.cache.database.standbycluster; + +import junit.framework.TestSuite; + +/** + * + */ +public class GridChangeGlobalStateSuite extends TestSuite { + /** + * + */ + public static TestSuite suite() { + TestSuite suite = new TestSuite("Ignite Activate/DeActivate Cluster Test Suit"); + + suite.addTestSuite(GridChangeGlobalStateTest.class); + suite.addTestSuite(GridChangeGlobalStateCacheTest.class); + suite.addTestSuite(GridChangeGlobalStateDataStructureTest.class); + suite.addTestSuite(GridChangeGlobalStateDataStreamerTest.class); + suite.addTestSuite(GridChangeGlobalStateFailOverTest.class); +// suite.addTestSuite(GridChangeGlobalStateServiceTest.class); + + return suite; + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java new file mode 100644 index 0000000000000..7bbae98fe1949 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java @@ -0,0 +1,694 @@ +package org.apache.ignite.cache.database.standbycluster; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteAtomicSequence; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteServices; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.cache.GridCacheProcessor; +import org.apache.ignite.internal.util.typedef.F; + +import static org.apache.ignite.testframework.GridTestUtils.assertThrows; +import static org.apache.ignite.testframework.GridTestUtils.runAsync; + +/** + * + */ +public class GridChangeGlobalStateTest extends GridChangeGlobalStateAbstractTest { + /** + * @throws Exception if fail. + */ + public void testStopPrimaryAndActivateFromServerNode() throws Exception { + Ignite ig1P = primary(0); + Ignite ig2P = primary(1); + Ignite ig3P = primary(2); + + Ignite ig1B = backUp(0); + Ignite ig2B = backUp(1); + Ignite ig3B = backUp(2); + + assertTrue(ig1P.active()); + assertTrue(ig2P.active()); + assertTrue(ig3P.active()); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + stopAllPrimary(); + + ig2B.active(true); + + assertTrue(ig1B.active()); + assertTrue(ig2B.active()); + assertTrue(ig3B.active()); + } + + /** + * @throws Exception if fail. + */ + public void testStopPrimaryAndActivateFromClientNode() throws Exception { + Ignite ig1P = primary(0); + Ignite ig2P = primary(1); + Ignite ig3P = primary(2); + + Ignite ig1B = backUp(0); + Ignite ig2B = backUp(1); + Ignite ig3B = backUp(2); + + Ignite ig1C = backUpClient(0); + Ignite ig2C = backUpClient(1); + Ignite ig3C = backUpClient(2); + + assertTrue(ig1P.active()); + assertTrue(ig2P.active()); + assertTrue(ig3P.active()); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + assertTrue(!ig1C.active()); + assertTrue(!ig2C.active()); + assertTrue(!ig3C.active()); + + stopAllPrimary(); + + ig2B.active(true); + + assertTrue(ig1B.active()); + assertTrue(ig2B.active()); + assertTrue(ig3B.active()); + + assertTrue(ig1C.active()); + assertTrue(ig2C.active()); + assertTrue(ig3C.active()); + } + + /** + * @throws Exception if fail. + */ + public void testConcurrentActivateFromClientNodeAndServerNode() throws Exception { + final Ignite ig1B = backUp(0); + final Ignite ig2B = backUp(1); + final Ignite ig3B = backUp(2); + + final Ignite ig1C = backUpClient(0); + final Ignite ig2C = backUpClient(1); + final Ignite ig3C = backUpClient(2); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + stopAllPrimary(); + + final AtomicInteger exCnt = new AtomicInteger(); + + final CyclicBarrier barrier = new CyclicBarrier(backUpNodes() + backUpClientNodes()); + + IgniteInternalFuture f1 = runAsync(new Callable() { + @Override public Void call() throws Exception { + try { + barrier.await(); + ig1B.active(true); + }catch (Exception e){ + exCnt.incrementAndGet(); + } + return null; + } + }); + + IgniteInternalFuture f2 = runAsync(new Runnable() { + @Override public void run() { + try { + barrier.await(); + ig2B.active(true); + }catch (Exception e){ + exCnt.incrementAndGet(); + } + } + }); + + IgniteInternalFuture f3 = runAsync(new Runnable() { + @Override public void run() { + try { + barrier.await(); + ig3B.active(true); + }catch (Exception e){ + exCnt.incrementAndGet(); + } + } + }); + + IgniteInternalFuture f4 = runAsync(new Runnable() { + @Override public void run() { + try { + barrier.await(); + ig1C.active(true); + }catch (Exception e){ + exCnt.incrementAndGet(); + } + } + }); + + IgniteInternalFuture f5 = runAsync(new Runnable() { + @Override public void run() { + try { + barrier.await(); + ig2C.active(true); + }catch (Exception e){ + exCnt.incrementAndGet(); + } + } + }); + + IgniteInternalFuture f6 = runAsync(new Runnable() { + @Override public void run() { + try { + barrier.await(); + ig3C.active(true); + }catch (Exception e){ + exCnt.incrementAndGet(); + } + } + }); + + f1.get(); + f2.get(); + f3.get(); + + f4.get(); + f5.get(); + f6.get(); + + assertTrue(exCnt.get() > 0); + + assertTrue(ig1B.active()); + assertTrue(ig2B.active()); + assertTrue(ig3B.active()); + + assertTrue(ig1C.active()); + assertTrue(ig2C.active()); + assertTrue(ig3C.active()); + } + + /** + * @throws Exception if fail. + */ + public void testConcurrentActivateFromServerNode() throws Exception { + final Ignite ig1B = backUp(0); + final Ignite ig2B = backUp(1); + final Ignite ig3B = backUp(2); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + stopAllPrimary(); + + final AtomicInteger exCnt = new AtomicInteger(); + + final CyclicBarrier barrier = new CyclicBarrier(3); + + IgniteInternalFuture act1 = runAsync(new Runnable() { + @Override public void run() { + try { + barrier.await(); + ig1B.active(true); + }catch (Exception e){ + exCnt.incrementAndGet(); + } + } + }); + + IgniteInternalFuture act2 = runAsync(new Runnable() { + @Override public void run() { + try { + barrier.await(); + ig2B.active(true); + }catch (Exception e){ + exCnt.incrementAndGet(); + } + } + }); + + IgniteInternalFuture act3 = runAsync(new Runnable() { + @Override public void run() { + try { + barrier.await(); + ig3B.active(true); + }catch (Exception e){ + exCnt.incrementAndGet(); + } + } + }); + + act1.get(); + act2.get(); + act3.get(); + + assertEquals(2, exCnt.get()); + + assertTrue(ig1B.active()); + assertTrue(ig2B.active()); + assertTrue(ig3B.active()); + } + + /** + * + */ + public void testActiveAndInActiveAtTheSameTimeCluster() throws Exception { + Ignite ig1P = primary(0); + Ignite ig2P = primary(1); + Ignite ig3P = primary(2); + + Ignite ig1B = backUp(0); + Ignite ig2B = backUp(1); + Ignite ig3B = backUp(2); + + assertTrue(ig1P.cluster().nodes().size() == 6); + assertTrue(ig2P.cluster().nodes().size() == 6); + assertTrue(ig3P.cluster().nodes().size() == 6); + + List primaryNodes = Arrays.asList( + ig1P.cluster().localNode(), ig2P.cluster().localNode(), ig3P.cluster().localNode() + ); + + List backUpNodes = Arrays.asList( + ig1B.cluster().localNode(), ig3B.cluster().localNode(), ig3B.cluster().localNode() + ); + + assertTrue(!ig1P.cluster().forRemotes().nodes().containsAll(backUpNodes)); + assertTrue(!ig2P.cluster().forRemotes().nodes().containsAll(backUpNodes)); + assertTrue(!ig3P.cluster().forRemotes().nodes().containsAll(backUpNodes)); + + assertTrue(ig1B.cluster().nodes().size() == 6); + assertTrue(ig2B.cluster().nodes().size() == 6); + assertTrue(ig3B.cluster().nodes().size() == 6); + + assertTrue(!ig1B.cluster().forRemotes().nodes().containsAll(primaryNodes)); + assertTrue(!ig2B.cluster().forRemotes().nodes().containsAll(primaryNodes)); + assertTrue(!ig3B.cluster().forRemotes().nodes().containsAll(primaryNodes)); + } + + /** + * + */ + public void testActivateOnAlreadyActivatedCluster() throws Exception { + Ignite ig1P = primary(0); + Ignite ig2P = primary(1); + Ignite ig3P = primary(2); + + Ignite ig1B = backUp(0); + Ignite ig2B = backUp(1); + Ignite ig3B = backUp(2); + + Ignite ig1C = backUpClient(0); + Ignite ig2C = backUpClient(1); + Ignite ig3C = backUpClient(2); + + assertTrue(ig1P.active()); + assertTrue(ig2P.active()); + assertTrue(ig3P.active()); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + assertTrue(!ig1C.active()); + assertTrue(!ig2C.active()); + assertTrue(!ig3C.active()); + + stopAllPrimary(); + + ig2B.active(true); + + assertTrue(ig1B.active()); + assertTrue(ig2B.active()); + assertTrue(ig3B.active()); + + assertTrue(ig1C.active()); + assertTrue(ig2C.active()); + assertTrue(ig3C.active()); + + ig1B.active(true); + ig2B.active(true); + ig3B.active(true); + + ig1C.active(true); + ig2C.active(true); + ig3C.active(true); + + assertTrue(ig1B.active()); + assertTrue(ig2B.active()); + assertTrue(ig3B.active()); + + assertTrue(ig1C.active()); + assertTrue(ig2C.active()); + assertTrue(ig3C.active()); + } + + /** + * + */ + public void testTryUseCacheInActiveCluster() throws Exception { + Ignite ig1B = backUp(0); + Ignite ig2B = backUp(1); + Ignite ig3B = backUp(2); + + Ignite ig1C = backUpClient(0); + Ignite ig2C = backUpClient(1); + Ignite ig3C = backUpClient(2); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + assertTrue(!ig1C.active()); + assertTrue(!ig2C.active()); + assertTrue(!ig3C.active()); + + checkExceptionTryUseCache(ig1B); + checkExceptionTryUseCache(ig2B); + checkExceptionTryUseCache(ig3B); + + checkExceptionTryUseCache(ig1C); + checkExceptionTryUseCache(ig2C); + checkExceptionTryUseCache(ig3C); + } + + /** + * @param ig Ig. + */ + private void checkExceptionTryUseCache(final Ignite ig) { + assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + IgniteCache cache = ig.cache("cache"); + return null; + } + }, IgniteException.class, "can not perform operation, because cluster inactive"); + } + + /** + * + */ + public void testTryUseServiceInActiveCluster() throws Exception { + Ignite ig1B = backUp(0); + Ignite ig2B = backUp(1); + Ignite ig3B = backUp(2); + + Ignite ig1C = backUpClient(0); + Ignite ig2C = backUpClient(1); + Ignite ig3C = backUpClient(2); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + assertTrue(!ig1C.active()); + assertTrue(!ig2C.active()); + assertTrue(!ig3C.active()); + + checkExceptionTryUseService(ig1B); + checkExceptionTryUseService(ig2B); + checkExceptionTryUseService(ig3B); + + checkExceptionTryUseService(ig1C); + checkExceptionTryUseService(ig2C); + checkExceptionTryUseService(ig3C); + } + + /** + * + */ + private void checkExceptionTryUseService(final Ignite ig) { + assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + IgniteServices srvs = ig.services(); + + return null; + } + }, IgniteException.class, "can not perform operation, because cluster inactive"); + } + + /** + * + */ + public void testTryUseDataStructureInActiveCluster() throws Exception { + Ignite ig1B = backUp(0); + Ignite ig2B = backUp(1); + Ignite ig3B = backUp(2); + + Ignite ig1C = backUpClient(0); + Ignite ig2C = backUpClient(1); + Ignite ig3C = backUpClient(2); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + assertTrue(!ig1C.active()); + assertTrue(!ig2C.active()); + assertTrue(!ig3C.active()); + + checkExceptionTryUseDataStructure(ig1B); + checkExceptionTryUseDataStructure(ig2B); + checkExceptionTryUseDataStructure(ig3B); + + checkExceptionTryUseDataStructure(ig1C); + checkExceptionTryUseDataStructure(ig2C); + checkExceptionTryUseDataStructure(ig3C); + } + + /** + * + */ + private void checkExceptionTryUseDataStructure(final Ignite ig){ + assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + IgniteAtomicSequence seq = ig.atomicSequence("seq", 0, true); + return null; + } + }, IgniteException.class, "can not perform operation, because cluster inactive"); + } + + /** + * + */ + public void testFailGetLock() throws Exception { + Ignite ig1P = primary(0); + Ignite ig2P = primary(1); + Ignite ig3P = primary(2); + + Ignite ig1B = backUp(0); + Ignite ig2B = backUp(1); + Ignite ig3B = backUp(2); + + Ignite ig1C = backUpClient(0); + Ignite ig2C = backUpClient(1); + + final Ignite ig3C = backUpClient(2); + + assertTrue(ig1P.active()); + assertTrue(ig2P.active()); + assertTrue(ig3P.active()); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + assertTrue(!ig1C.active()); + assertTrue(!ig2C.active()); + assertTrue(!ig3C.active()); + + stopPrimary(0); + + boolean exc = false; + + try { + ig3C.active(true); + } + catch (IgniteException e) { + exc = true; + + log.error("stack trace from remote node", e); + + for (Throwable t : e.getSuppressed()) + assertTrue(t.getMessage().contains("can't get lock during")); + } + + if (!exc) + fail(); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + assertTrue(!ig1C.active()); + assertTrue(!ig2C.active()); + assertTrue(!ig3C.active()); + } + + /** + * + */ + public void testActivateAfterFailGetLock() throws Exception { + Ignite ig1P = primary(0); + Ignite ig2P = primary(1); + Ignite ig3P = primary(2); + + Ignite ig1CP = primaryClient(0); + Ignite ig2CP = primaryClient(1); + Ignite ig3CP = primaryClient(2); + + Ignite ig1B = backUp(0); + Ignite ig2B = backUp(1); + Ignite ig3B = backUp(2); + + Ignite ig1CB = backUpClient(0); + Ignite ig2CB = backUpClient(1); + Ignite ig3CB = backUpClient(2); + + assertTrue(ig1P.active()); + assertTrue(ig2P.active()); + assertTrue(ig3P.active()); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + assertTrue(!ig1CB.active()); + assertTrue(!ig2CB.active()); + assertTrue(!ig3CB.active()); + + stopPrimary(0); + + boolean exc = false; + + try { + ig3CB.active(true); + } + catch (IgniteException e) { + exc = true; + + log.error("stack trace from remote node", e); + + for (Throwable t : e.getSuppressed()) + assertTrue(t.getMessage().contains("can't get lock during")); + } + + if (!exc) + fail(); + + assertTrue(!ig1B.active()); + assertTrue(!ig2B.active()); + assertTrue(!ig3B.active()); + + assertTrue(!ig1CB.active()); + assertTrue(!ig2CB.active()); + assertTrue(!ig3CB.active()); + + assertTrue(ig2P.active()); + assertTrue(ig3P.active()); + + assertTrue(ig1CP.active()); + assertTrue(ig2CP.active()); + assertTrue(ig3CP.active()); + + stopAllPrimary(); + + ig2CB.active(true); + + assertTrue(ig1B.active()); + assertTrue(ig2B.active()); + assertTrue(ig3B.active()); + + assertTrue(ig1CB.active()); + assertTrue(ig2CB.active()); + assertTrue(ig3CB.active()); + } + + /** + * @throws Exception if fail. + */ + public void testDeActivateFromServerNode() throws Exception { + Ignite ig1 = primary(0); + Ignite ig2 = primary(1); + Ignite ig3 = primary(2); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + ig1.active(false); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + } + + /** + * @throws Exception if fail. + */ + public void testDeActivateFromClientNode() throws Exception { + Ignite ig1 = primary(0); + Ignite ig2 = primary(1); + Ignite ig3 = primary(2); + + Ignite ig1C = primaryClient(0); + Ignite ig2C = primaryClient(1); + Ignite ig3C = primaryClient(2); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + ig1C.active(false); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + assertTrue(!ig1C.active()); + assertTrue(!ig2C.active()); + assertTrue(!ig3C.active()); + } + + /** + * @throws Exception if fail. + */ + public void testDeActivateCheckCacheDestroy() throws Exception { + String chName = "myCache"; + + Ignite ig1 = primary(0); + Ignite ig2 = primary(1); + Ignite ig3 = primary(2); + + ig1.getOrCreateCache(chName); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + ig1.active(false); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + IgniteEx ex = (IgniteEx)ig1; + + GridCacheProcessor cache = ex.context().cache(); + + assertTrue(F.isEmpty(cache.jcaches())); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java new file mode 100644 index 0000000000000..24710c155181e --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java @@ -0,0 +1,221 @@ +package org.apache.ignite.cache.database.standbycluster.extended; + +import java.lang.reflect.Method; +import java.util.LinkedHashMap; +import java.util.Map; +import org.apache.ignite.Ignite; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.NearCacheConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.GridCacheAbstractFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheNearOnlyMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.resource.GridSpringResourceContext; +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.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; + +/** + * + */ +public class GridActivateExtensionTest extends GridCacheAbstractFullApiSelfTest { + /** Condition id. */ + private int condId; + + /** Primary ip finder. */ + private TcpDiscoveryIpFinder primaryIpFinder = new TcpDiscoveryVmIpFinder(true); + + /** Back up ip finder. */ + private TcpDiscoveryIpFinder backUpIpFinder = new TcpDiscoveryVmIpFinder(true); + + /** Back up cluster. */ + private static Map backUpCluster = new LinkedHashMap<>(); + + /** Test name. */ + private final String testName = testName(); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setConsistentId("ConsId" + (condId++)); + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(primaryIpFinder); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + pCfg.setPersistenceStorePath(testName + "/db"); + pCfg.setWalArchivePath(testName + "/db/wal/archive"); + pCfg.setWalStorePath(testName + "/db/wal"); + + cfg.setPersistenceConfiguration(pCfg); + + final MemoryConfiguration memCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setSize(5 * 1024 * 1024); + + memPlcCfg.setName("dfltMemPlc"); + + memCfg.setMemoryPolicies(memPlcCfg); + + memCfg.setDefaultMemoryPolicyName(memPlcCfg.getName()); + + memCfg.setPageSize(1024); + memCfg.setConcurrencyLevel(64); + + cfg.setMemoryConfiguration(memCfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), testName, true)); + + super.beforeTestsStarted(); + + if (onlyClient()) + return; + + int nodes = gridCount(); + + if (nodes != condId) + fail("checking fail"); + + condId = 0; + + log.info("start backup cluster"); + + for (String name: backUpCluster.keySet()){ + String n = name + "backUp"; + + IgniteConfiguration cfg = getConfiguration(n); + cfg.setActiveOnStart(false); + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(backUpIpFinder); + + startGrid(n, cfg); + + backUpCluster.put(name, n); + } + + log.info("shutdown main cluster"); + + for (String name : backUpCluster.keySet()){ + log.info(name + " stopping"); + + stopGrid(name); + } + + Ignite ig = grid(0); + + ig.active(true); + + log.info("activate backUp cluster"); + + assertEquals(true, ig.active()); + + Class c = getClass(); + + if (isNearTest(c)) { + for (int i = 0; i < gridCount(); i++) { + if (ignite(i).configuration().isClientMode()) { + Method m = getClientHasNearCacheMethod(); + + Boolean r = (Boolean)m.invoke(this); + + if (r != null && r) + ignite(i).createNearCache(null, new NearCacheConfiguration<>()); + else + ignite(i).cache(null); + + break; + } + } + } + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + + stopAllGrids(); + + backUpCluster.clear(); + + condId = 0; + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), testName, true)); + } + + /** {@inheritDoc} */ + @Override protected Ignite startGrid(String gridName, GridSpringResourceContext ctx) throws Exception { + if (!gridName.contains("backUp")) + backUpCluster.put(gridName, gridName); + + return super.startGrid(gridName, ctx); + } + + /** {@inheritDoc} */ + @Override protected IgniteEx grid(String name) { + String n = name; + + if (backUpCluster.containsKey(name)) + n = backUpCluster.get(name); + + return super.grid(n); + } + + /** + * + */ + public boolean onlyClient(){ + for (int i = 0; i < gridCount(); i++) + if (!grid(i).configuration().isClientMode()) + return false; + + return true; + } + + /** + * @param c class. + */ + private boolean isNearTest(Class c) { + Class p = c.getSuperclass(); + + while (!p.equals(Object.class)) { + if (p.equals(GridCacheNearOnlyMultiNodeFullApiSelfTest.class)) + return true; + + p = p.getSuperclass(); + } + + return false; + } + + /** + * + */ + public Method getClientHasNearCacheMethod() throws NoSuchMethodException { + Class p = getClass().getSuperclass(); + + while (!p.equals(Object.class)) { + if (p.equals(GridCacheNearOnlyMultiNodeFullApiSelfTest.class)) + return p.getDeclaredMethod("clientHasNearCache"); + + p = p.getSuperclass(); + } + + return null; + } + + /** + * + */ + protected String testName() { + return getClass().getSimpleName(); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationAtomicCacheSuit.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationAtomicCacheSuit.java new file mode 100644 index 0000000000000..d490958f88cb8 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationAtomicCacheSuit.java @@ -0,0 +1,62 @@ +package org.apache.ignite.cache.database.standbycluster.extended; + +import junit.framework.TestSuite; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAtomicFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAtomicNearEnabledFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicClientOnlyMultiNodeP2PDisabledFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicCopyOnReadDisabledMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicMultiNodeP2PDisabledFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearEnabledMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearOnlyMultiNodeP2PDisabledFullApiSelfTest; + +/** + * + */ +public class GridActivationAtomicCacheSuit extends GridActivationCacheAbstractTestSuit { + static { + addTest(GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.class); + addTest(GridCacheAtomicClientOnlyMultiNodeP2PDisabledFullApiSelfTest.class); + addTest(GridCacheAtomicCopyOnReadDisabledMultiNodeFullApiSelfTest.class); + addTest(GridCacheAtomicFullApiSelfTest.class); + addTest(GridCacheAtomicMultiNodeFullApiSelfTest.class); + addTest(GridCacheAtomicMultiNodeP2PDisabledFullApiSelfTest.class); + addTest(GridCacheAtomicNearEnabledFullApiSelfTest.class); + addTest(GridCacheAtomicNearEnabledMultiNodeFullApiSelfTest.class); + addTest(GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.class); + addTest(GridCacheAtomicNearOnlyMultiNodeP2PDisabledFullApiSelfTest.class); + +// addTest(GridCacheAtomicClientOnlyFairAffinityMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicClientOnlyMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicClientOnlyMultiJvmP2PDisabledFullApiSelfTest.class)); +// addTest(GridCacheAtomicCopyOnReadDisabledMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicFairAffinityMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicMultiJvmP2PDisabledFullApiSelfTest.class)); +// addTest(GridCacheAtomicOffHeapMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicOffHeapTieredMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicPrimaryWriteOrderFairAffinityMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicPrimaryWriteOrderMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicPrimaryWriteOrderMultiJvmP2PDisabledFullApiSelfTest.class)); +// addTest(GridCacheAtomicPrimaryWrityOrderOffHeapMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicPrimaryWrityOrderOffHeapTieredMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicNearEnabledFairAffinityMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicNearEnabledMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicNearEnabledPrimaryWriteOrderMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicNearOnlyMultiJvmFullApiSelfTest.class)); +// addTest(GridCacheAtomicNearOnlyMultiJvmP2PDisabledFullApiSelfTest.class)); + } + + /** + * + */ + public static TestSuite suite() { + TestSuite suite = buildSuite(); + + suite.setName("Activation Stand-by Cluster After Primary Cluster Stopped Check Atomic Cache"); + + return suite; + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationCacheAbstractTestSuit.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationCacheAbstractTestSuit.java new file mode 100644 index 0000000000000..8d4ecfb17ea10 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationCacheAbstractTestSuit.java @@ -0,0 +1,91 @@ +package org.apache.ignite.cache.database.standbycluster.extended; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import javassist.CannotCompileException; +import javassist.ClassClassPath; +import javassist.ClassPool; +import javassist.CtClass; +import javassist.NotFoundException; +import junit.framework.TestSuite; +import org.apache.ignite.IgniteException; + +/** + * + */ +public abstract class GridActivationCacheAbstractTestSuit { + /** Tests. */ + private static final List tests = new ArrayList<>(); + + /** Suffix. */ + private static final String SUFFIX = "Ex"; + + /** + * @return Suite. + */ + protected static TestSuite buildSuite() { + TestSuite suite = new TestSuite(); + + for (Class c : tests) + suite.addTestSuite(c); + + return suite; + } + + /** + * @param c Class. + */ + protected static void addTest(Class c){ + tests.add(transform(c)); + } + + + /** + * @param c Class to transform. + * @return Transformed class. + */ + private static Class transform(Class c){ + try { + ClassPool pool = ClassPool.getDefault(); + + pool.insertClassPath(new ClassClassPath(GridActivationCacheAbstractTestSuit.class)); + + String path = c.getProtectionDomain().getCodeSource().getLocation().getPath(); + + CtClass ct = pool.get(c.getName()); + + String name = c.getName() + SUFFIX; + + CtClass pr = pool.get(GridActivateExtensionTest.class.getName()); + + pr.setName(name); + + pr.setSuperclass(ct); + + pr.writeFile(path); + + return Class.forName(name); + } + catch (IOException e) { + System.out.println("Io exception: " + e.getMessage()); + + throw new IgniteException(e); + } + catch (CannotCompileException e) { + System.out.println("Cannot compile exception: " + e.getMessage()); + + throw new IgniteException(e); + } + catch (NotFoundException e) { + System.out.println("Not found exception: " + e.getMessage()); + + throw new IgniteException(e); + } + catch (ClassNotFoundException e) { + System.out.println("Class not found exception: " + e.getMessage()); + + throw new IgniteException(e); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java new file mode 100644 index 0000000000000..71bcf2c09a589 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java @@ -0,0 +1,30 @@ +package org.apache.ignite.cache.database.standbycluster.extended; + +import junit.framework.TestSuite; +import org.apache.ignite.internal.processors.cache.local.GridCacheLocalAtomicFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.local.GridCacheLocalFullApiSelfTest; + +/** + * + */ +public class GridActivationLocalAndNearCacheSuit extends GridActivationCacheAbstractTestSuit { + static { + addTest(GridCacheLocalAtomicFullApiSelfTest.class); + addTest(GridCacheLocalFullApiSelfTest.class); + +// addTest(GridCacheNearOnlyFairAffinityMultiJvmFullApiSelfTest.class); +// addTest(GridCacheNearOnlyMultiJvmFullApiSelfTest.class); +// addTest(GridCacheNearOnlyMultiJvmP2PDisabledFullApiSelfTest.class); + } + + /** + * + */ + public static TestSuite suite() { + TestSuite suite = buildSuite(); + + suite.setName("Activation Stand-by Cluster After Primary Cluster Stopped Check Local and Near Cache"); + + return suite; + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationPartitionedCacheSuit.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationPartitionedCacheSuit.java new file mode 100644 index 0000000000000..e34ee159ac8eb --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationPartitionedCacheSuit.java @@ -0,0 +1,63 @@ +package org.apache.ignite.cache.database.standbycluster.extended; + +import junit.framework.TestSuite; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedNearDisabledFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedNearDisabledMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedNearDisabledMultiNodeP2PDisabledFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.CachePartitionedMultiNodeLongTxTimeoutFullApiTest; +import org.apache.ignite.internal.processors.cache.distributed.near.CachePartitionedNearEnabledMultiNodeLongTxTimeoutFullApiTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheNearOnlyMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheNearOnlyMultiNodeP2PDisabledFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedClientOnlyNoPrimaryFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedCopyOnReadDisabledMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedLateAffDisabledMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedMultiNodeP2PDisabledFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedNearOnlyNoPrimaryFullApiSelfTest; + +/** + * + */ +public class GridActivationPartitionedCacheSuit extends GridActivationCacheAbstractTestSuit { + static { + addTest(CachePartitionedMultiNodeLongTxTimeoutFullApiTest.class); + addTest(CachePartitionedNearEnabledMultiNodeLongTxTimeoutFullApiTest.class); + addTest(GridCacheNearOnlyMultiNodeFullApiSelfTest.class); + addTest(GridCacheNearOnlyMultiNodeP2PDisabledFullApiSelfTest.class); + addTest(GridCachePartitionedClientOnlyNoPrimaryFullApiSelfTest.class); + addTest(GridCachePartitionedCopyOnReadDisabledMultiNodeFullApiSelfTest.class); + addTest(GridCachePartitionedFullApiSelfTest.class); + addTest(GridCachePartitionedLateAffDisabledMultiNodeFullApiSelfTest.class); + addTest(GridCachePartitionedMultiNodeFullApiSelfTest.class); + addTest(GridCachePartitionedMultiNodeP2PDisabledFullApiSelfTest.class); + addTest(GridCachePartitionedNearDisabledFullApiSelfTest.class); + addTest(GridCachePartitionedNearDisabledMultiNodeFullApiSelfTest.class); + addTest(GridCachePartitionedNearDisabledMultiNodeP2PDisabledFullApiSelfTest.class); + addTest(GridCachePartitionedNearOnlyNoPrimaryFullApiSelfTest.class); + +// addTest(GridCachePartitionedMultiJvmFullApiSelfTest.class); +// addTest(GridCachePartitionedCopyOnReadDisabledMultiJvmFullApiSelfTest.class); +// addTest(GridCachePartitionedFairAffinityMultiJvmFullApiSelfTest.class); +// addTest(GridCachePartitionedMultiJvmP2PDisabledFullApiSelfTest.class); +// addTest(GridCachePartitionedNearDisabledAtomicOffHeapTieredMultiJvmFullApiSelfTest.class); +// addTest(GridCachePartitionedNearDisabledFairAffinityMultiJvmFullApiSelfTest.class); +// addTest(GridCachePartitionedNearDisabledMultiJvmFullApiSelfTest.class); +// addTest(GridCachePartitionedNearDisabledMultiJvmP2PDisabledFullApiSelfTest.class); +// addTest(GridCachePartitionedNearDisabledOffHeapMultiJvmFullApiSelfTest.class); +// addTest(GridCachePartitionedNearDisabledOffHeapTieredMultiJvmFullApiSelfTest.class); +// addTest(GridCachePartitionedOffHeapMultiJvmFullApiSelfTest.class); +// addTest(GridCachePartitionedOffHeapTieredMultiJvmFullApiSelfTest.class); + } + + /** + * + */ + public static TestSuite suite() { + TestSuite suite = buildSuite(); + + suite.setName("Activation Stand-by Cluster After Primary Cluster Stopped Check Partitioned Cache"); + + return suite; + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationReplicatedCacheSuit.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationReplicatedCacheSuit.java new file mode 100644 index 0000000000000..7636b67a5e2c7 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationReplicatedCacheSuit.java @@ -0,0 +1,46 @@ +package org.apache.ignite.cache.database.standbycluster.extended; + +import junit.framework.TestSuite; +import org.apache.ignite.internal.processors.cache.distributed.replicated.CacheReplicatedRendezvousAffinityExcludeNeighborsMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.replicated.CacheReplicatedRendezvousAffinityMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedAtomicFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedAtomicMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedMultiNodeP2PDisabledFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedNearOnlyMultiNodeFullApiSelfTest; + +/** + * + */ +public class GridActivationReplicatedCacheSuit extends GridActivationCacheAbstractTestSuit { + static { + addTest(CacheReplicatedRendezvousAffinityExcludeNeighborsMultiNodeFullApiSelfTest.class); + addTest(CacheReplicatedRendezvousAffinityMultiNodeFullApiSelfTest.class); + addTest(GridCacheReplicatedAtomicFullApiSelfTest.class); + addTest(GridCacheReplicatedFullApiSelfTest.class); + addTest(GridCacheReplicatedMultiNodeFullApiSelfTest.class); + addTest(GridCacheReplicatedAtomicMultiNodeFullApiSelfTest.class); + addTest(GridCacheReplicatedMultiNodeP2PDisabledFullApiSelfTest.class); + addTest(GridCacheReplicatedNearOnlyMultiNodeFullApiSelfTest.class); + +// tests.add(transform(GridCacheReplicatedAtomicMultiJvmFullApiSelfTest.class)); +// tests.add(transform(GridCacheReplicatedAtomicPrimaryWriteOrderMultiJvmFullApiSelfTest.class)); +// tests.add(transform(GridCacheReplicatedMultiJvmFullApiSelfTest.class)); +// tests.add(transform(GridCacheReplicatedMultiJvmP2PDisabledFullApiSelfTest.class)); +// tests.add(transform(GridCacheReplicatedNearOnlyMultiJvmFullApiSelfTest.class)); +// tests.add(transform(GridCacheReplicatedOffHeapMultiJvmFullApiSelfTest.class)); +// tests.add(transform(GridCacheReplicatedOffHeapTieredMultiJvmFullApiSelfTest.class)); + } + + /** + * + */ + public static TestSuite suite() { + TestSuite suite = buildSuite(); + + suite.setName("Activation Stand-by Cluster After Primary Cluster Stopped Check Replicated Cache"); + + return suite; + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuit2.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuit2.java new file mode 100644 index 0000000000000..e3baf0453a22a --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuit2.java @@ -0,0 +1,60 @@ +package org.apache.ignite.testsuites; + +import junit.framework.TestSuite; +import org.apache.ignite.cache.database.IgnitePersistentStoreAtomicCacheRebalancingTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreTxCacheRebalancingTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreContinuousRestartSelfTest; +import org.apache.ignite.cache.database.IgnitePersistentStorePageSizesSelfTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreWalTlbSelfTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreRecoveryAfterFileCorruptionTest; +import org.apache.ignite.cache.database.db.DbPageEvictionDuringPartitionClearSelfTest; +import org.apache.ignite.cache.database.db.IgniteDbWholeClusterRestartSelfTest; +import org.apache.ignite.cache.database.db.RebalancingOnNotStableTopologyTest; +import org.apache.ignite.cache.database.db.TransactionsHangTest; +import org.apache.ignite.cache.database.db.file.IgniteNoActualWalHistorySelfTest; +import org.apache.ignite.cache.database.db.file.IgniteWalHistoryReservationsSelfTest; +import org.apache.ignite.cache.database.db.file.IgniteWalRecoverySelfTest; +import org.apache.ignite.cache.database.db.file.WalRecoveryTxLogicalRecordsTest; +import org.apache.ignite.cache.database.db.wal.crc.IgniteDataIntegrityTests; + +/** + * + */ +public class IgnitePersistentStoreTestSuit2 extends TestSuite { + /** + * @return Suite. + * @throws Exception If failed. + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("Ignite persistent Store Test Suite"); + + // Integrity test + suite.addTestSuite(IgniteDataIntegrityTests.class); + suite.addTestSuite(IgnitePersistentStoreRecoveryAfterFileCorruptionTest.class); + suite.addTestSuite(IgnitePersistentStorePageSizesSelfTest.class); + suite.addTestSuite(IgnitePersistentStoreWalTlbSelfTest.class); + + // WAL recovery test. + suite.addTestSuite(WalRecoveryTxLogicalRecordsTest.class); + suite.addTestSuite(IgniteWalRecoverySelfTest.class); + + suite.addTestSuite(TransactionsHangTest.class); + + suite.addTestSuite(IgniteNoActualWalHistorySelfTest.class); + + suite.addTestSuite(RebalancingOnNotStableTopologyTest.class); + + suite.addTestSuite(IgniteDbWholeClusterRestartSelfTest.class); + + suite.addTestSuite(DbPageEvictionDuringPartitionClearSelfTest.class); + + // Rebalancing test + suite.addTestSuite(IgnitePersistentStoreAtomicCacheRebalancingTest.class); + suite.addTestSuite(IgnitePersistentStoreTxCacheRebalancingTest.class); + suite.addTestSuite(IgniteWalHistoryReservationsSelfTest.class); + + suite.addTestSuite(IgnitePersistentStoreContinuousRestartSelfTest.class); + + return suite; + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuite.java new file mode 100644 index 0000000000000..b66e7e8ea6d25 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuite.java @@ -0,0 +1,75 @@ +package org.apache.ignite.testsuites; + +import junit.framework.TestSuite; +import org.apache.ignite.cache.database.IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest; +import org.apache.ignite.cache.database.db.IgniteDbMultiNodePutGetRestartSelfTest; +import org.apache.ignite.cache.database.db.IgniteDbPageEvictionSelfTest; +import org.apache.ignite.cache.database.db.file.IgniteCachePageStoreIntegrationSelfTest; +import org.apache.ignite.cache.database.db.file.IgniteWalDirectoriesConfigurationTest; +import org.apache.ignite.cache.database.db.file.PageStoreCheckpointSimulationSelfTest; +import org.apache.ignite.cache.database.db.file.PageStoreEvictionSelfTest; +import org.apache.ignite.cache.database.pagemem.BPlusTreeReuseListPageMemoryImplSelfTest; +import org.apache.ignite.cache.database.pagemem.BPlusTreeSelfTestPageMemoryImplSelfTest; +import org.apache.ignite.cache.database.pagemem.MetadataStoragePageMemoryImplSelfTest; +import org.apache.ignite.cache.database.pagemem.PageMemoryImplNoLoadSelfTest; +import org.apache.ignite.cache.database.pagemem.PageMemoryImplReloadSelfTest; +import org.apache.ignite.cache.database.pagemem.PageMemoryImplTest; +import org.apache.ignite.internal.processors.database.IgniteDbClientNearCachePutGetTest; +import org.apache.ignite.internal.processors.database.IgniteDbDynamicCacheSelfTest; +import org.apache.ignite.internal.processors.database.IgniteDbMultiNodePutGetTest; +import org.apache.ignite.internal.processors.database.IgniteDbMultiNodeWithIndexingPutGetTest; +import org.apache.ignite.internal.processors.database.IgniteDbSingleNodePutGetTest; +import org.apache.ignite.internal.processors.database.IgniteDbSingleNodeTinyPutGetTest; +import org.apache.ignite.internal.processors.database.IgniteDbSingleNodeWithIndexingPutGetTest; + + +/** + * + */ +public class IgnitePersistentStoreTestSuite extends TestSuite { + /** + * @return Suite. + * @throws Exception If failed. + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("Ignite Persistent Store Test Suite"); + + // Basic PageMemory tests. + suite.addTestSuite(PageMemoryImplNoLoadSelfTest.class); + suite.addTestSuite(PageMemoryImplReloadSelfTest.class); + suite.addTestSuite(MetadataStoragePageMemoryImplSelfTest.class); + suite.addTestSuite(PageStoreEvictionSelfTest.class); + suite.addTestSuite(PageMemoryImplTest.class); + + // Checkpointing smoke-test. + suite.addTestSuite(IgniteCachePageStoreIntegrationSelfTest.class); + suite.addTestSuite(PageStoreCheckpointSimulationSelfTest.class); + + // BTree tests with store page memory. + suite.addTestSuite(BPlusTreeSelfTestPageMemoryImplSelfTest.class); + suite.addTestSuite(BPlusTreeReuseListPageMemoryImplSelfTest.class); + + // Basic API tests. + suite.addTestSuite(IgniteDbSingleNodePutGetTest.class); + suite.addTestSuite(IgniteDbSingleNodeWithIndexingPutGetTest.class); + suite.addTestSuite(IgniteDbMultiNodePutGetTest.class); + suite.addTestSuite(IgniteDbMultiNodeWithIndexingPutGetTest.class); + suite.addTestSuite(IgniteDbSingleNodeTinyPutGetTest.class); + suite.addTestSuite(IgniteDbDynamicCacheSelfTest.class); + suite.addTestSuite(IgniteDbClientNearCachePutGetTest.class); + + // Persistence-enabled. + suite.addTestSuite(IgniteDbMultiNodePutGetRestartSelfTest.class); + suite.addTestSuite(IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.class); + suite.addTestSuite(IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.class); + suite.addTestSuite(IgniteDbPageEvictionSelfTest.class); + suite.addTestSuite(IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest.class); + suite.addTestSuite(IgniteWalDirectoriesConfigurationTest.class); + suite.addTestSuite(IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.class); + + return suite; + } +} From b1719ac58927032bc0a3608e781fa2b7b24163a3 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 5 May 2017 14:32:08 +0300 Subject: [PATCH 148/311] ignite-12163 minor update configuration --- .../apache/ignite/configuration/IgniteConfiguration.java | 7 +++++++ .../internal/processors/cache/GridCacheProcessor.java | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index 0b87b7b770534..ec1df5891e81a 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -2124,6 +2124,13 @@ public PersistenceConfiguration getPersistenceConfiguration() { return pstCfg; } + /** + * @return Flag {@code true} if persistent enable, {@code false} if disable. + */ + public boolean isPersistentEnable() { + return pstCfg != null; + } + /** * Sets persistence configuration. * 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 43a603275751a..9b1f94762ddc4 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 @@ -2146,7 +2146,7 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, IgnitePageStoreManager pageStoreMgr = null; IgniteWriteAheadLogManager walMgr = null; - if (ctx.config().getPersistenceConfiguration() != null) { + if (ctx.config().isPersistentEnable()) { ClassLoader clsLdr = U.gridClassLoader(); try { @@ -2174,9 +2174,6 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, IgniteCacheSnapshotManager snpMgr = ctx.plugins().createComponent(IgniteCacheSnapshotManager.class); - if (snpMgr == null) - snpMgr = new IgniteCacheSnapshotManager(); - GridCacheIoManager ioMgr = new GridCacheIoManager(); CacheAffinitySharedManager topMgr = new CacheAffinitySharedManager(); GridCacheSharedTtlCleanupManager ttl = new GridCacheSharedTtlCleanupManager(); From 92a490d7f5ca18ceb5b6fdf6364aa2e194d83f14 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 5 May 2017 15:10:59 +0300 Subject: [PATCH 149/311] ignite-12163 remove unnecessary delegate --- .../database/IgniteCacheDatabaseSharedManager.java | 13 ------------- .../preloader/GridDhtPartitionsExchangeFuture.java | 2 +- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 1fde564613e0e..2a2014c384487 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -536,19 +536,6 @@ public void onCacheStop(GridCacheContext cctx) { // No-op } - /** - * @param initiatorNodeId Snapshot message. - * @param snapshotOperation Snapshot operation. - * @return Snapshot creation init future or {@code null} if snapshot is not available. - * @throws IgniteCheckedException If failed. - */ - @Nullable public IgniteInternalFuture startLocalSnapshotOperation( - UUID initiatorNodeId, - SnapshotOperation snapshotOperation - ) throws IgniteCheckedException { - return null; - } - /** * @return Future that will be completed when indexes for given cache are restored. */ 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 3155cbaf32f1c..af614eed01984 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 @@ -953,7 +953,7 @@ private void distributedExchange() throws IgniteCheckedException { private void startLocalSnasphotOperation( StartSnapshotOperationAckDiscoveryMessage snapOpMsg ) throws IgniteCheckedException { - IgniteInternalFuture fut = cctx.database().startLocalSnapshotOperation( + IgniteInternalFuture fut = cctx.snapshot().startLocalSnapshotOperation( snapOpMsg.initiatorNodeId(), snapOpMsg.snapshotOperation() ); From f9fdd2c0d146da489e4c2a2b40f1736f7a15fad4 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 5 May 2017 15:17:28 +0300 Subject: [PATCH 150/311] ignite-12163 remove unnecessary delegate --- .../database/GridCacheDatabaseSharedManager.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 0f0af7f1bb253..277010f060c7b 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -584,19 +584,6 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { throw new IgniteCheckedException("Page eviction is not compatible with persistence: " + plcCfg.getName()); } - /** - * @param initiatorNodeId Snapshot message. - * @param snapshotOperation Snapshot operation. - * @return Snapshot creation init future or {@code null} if snapshot is not available. - * @throws IgniteCheckedException If failed. - */ - @Override @Nullable public IgniteInternalFuture startLocalSnapshotOperation( - UUID initiatorNodeId, - SnapshotOperation snapshotOperation - ) throws IgniteCheckedException { - return snapshotMgr.startLocalSnapshotOperation(initiatorNodeId, snapshotOperation); - } - /** * @param pageMem Page memory. */ @@ -605,7 +592,7 @@ private void markDirty(int cacheId, long pageId, PageMemory pageMem) { if (PageIdUtils.pageIndex(pageId) == 0) return; - long lastSuccessfulSnapshotTag = snapshotMgr.getLastSuccessfulSnapshotTagForCache(cacheId, (PageMemoryEx) pageMem); + long lastSuccessfulSnapshotTag = snapshotMgr.getLastSuccessfulSnapshotTagForCache(cacheId, pageMem); if (lastSuccessfulSnapshotTag < 0) //there is no full snapshot return; From 9cf52ace2943eb8a48ab944f449691e2c5b72982 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 5 May 2017 15:20:59 +0300 Subject: [PATCH 151/311] ignite-12163 fix error on start --- .../ignite/internal/processors/cache/GridCacheProcessor.java | 3 +++ .../cache/database/GridCacheDatabaseSharedManager.java | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) 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 9b1f94762ddc4..bf13f188506c9 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 @@ -2174,6 +2174,9 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, IgniteCacheSnapshotManager snpMgr = ctx.plugins().createComponent(IgniteCacheSnapshotManager.class); + if (snpMgr == null) + snpMgr = new IgniteCacheSnapshotManager(); + GridCacheIoManager ioMgr = new GridCacheIoManager(); CacheAffinitySharedManager topMgr = new CacheAffinitySharedManager(); GridCacheSharedTtlCleanupManager ttl = new GridCacheSharedTtlCleanupManager(); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 277010f060c7b..5cae4c2e6cddf 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -417,8 +417,6 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { readCheckpointAndRestoreMemory(); } - - snapshotMgr.onKernalStart(reconnect); } /** {@inheritDoc} */ From e224ff026121c59b348d260cd98b97fa298b9200 Mon Sep 17 00:00:00 2001 From: EdShangGG Date: Wed, 3 May 2017 19:32:51 +0300 Subject: [PATCH 152/311] fixing issue with message id (cherry picked from commit c4deff8) --- .../processors/cache/GridChangeGlobalStateMessageResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java index 62b67b17640d5..0d04ccb8fd11a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java @@ -157,7 +157,7 @@ public Throwable getError() { /** {@inheritDoc} */ @Override public short directType() { - return -46; + return -45; } /** {@inheritDoc} */ From 1aa2fe740c2d1db9f98aeeaa88844e9baecc1953 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 8 May 2017 12:11:02 +0300 Subject: [PATCH 153/311] ignite-gg-12163 fix testWalDirectOutOfMemory --- .../IgnitePersistentStoreWalTlbSelfTest.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java index 1248d307bf385..c295e1ea41ebb 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java @@ -4,6 +4,8 @@ import org.apache.ignite.IgniteDataStreamer; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistenceConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; @@ -28,6 +30,18 @@ public class IgnitePersistentStoreWalTlbSelfTest extends GridCommonAbstractTest cfg.setCacheConfiguration(ccfg); + MemoryConfiguration memCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(100 * 1024 * 1024); + + memCfg.setMemoryPolicies(memPlcCfg); + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(memCfg); + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); @@ -77,25 +91,27 @@ public class IgnitePersistentStoreWalTlbSelfTest extends GridCommonAbstractTest * @throws Exception if failed. */ public void testWalDirectOutOfMemory() throws Exception { - IgniteEx ig = grid(1); + boolean locked = true; try { - IgniteDataStreamer streamer = ig.dataStreamer(null); + IgniteDataStreamer streamer = ig.dataStreamer(null); for (int i = 0; i < 100_000; i++) { streamer.addData(i, 1); if (i > 0 && i % 10_000 == 0) info("Done put: " + i); } - } catch (CacheException ignore) { + } + catch (CacheException ignore) { // expected locked = false; - } finally { + } + finally { assertFalse(locked); + stopAllGrids(); } } - } From ce32505e352a72b1fd9ef04bf1d65d13cfaab669 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 8 May 2017 12:40:32 +0300 Subject: [PATCH 154/311] ignite-gg-12163 minor refactoring updates --- .../database/IgniteDbPutGetAbstractTest.java | 3 +- ...gnitePersistentStoreDynamicCacheTest.java} | 2 +- ...> IgnitePersistentStorePageSizesTest.java} | 6 +- ...tStoreRecoveryAfterFileCorruptionTest.java | 62 +++++++++---------- .../IgnitePersistentStoreTestSuit2.java | 4 +- .../IgnitePersistentStoreTestSuite.java | 4 +- 6 files changed, 40 insertions(+), 41 deletions(-) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest.java => IgnitePersistentStoreDynamicCacheTest.java} (97%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStorePageSizesSelfTest.java => IgnitePersistentStorePageSizesTest.java} (94%) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java index cfb9b087268ab..c93bb4472e039 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java @@ -57,9 +57,8 @@ public abstract class IgniteDbPutGetAbstractTest extends IgniteDbAbstractTest { * @return Ignite instance for testing. */ private IgniteEx ig() { - if (withClientNearCache()) { + if (withClientNearCache()) return grid(gridCount()); - } return grid(0); } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java index 43ed392d513a0..2a622ed0e4b17 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java @@ -19,7 +19,7 @@ /** * */ -public class IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest extends IgniteDbDynamicCacheSelfTest { +public class IgnitePersistentStoreDynamicCacheTest extends IgniteDbDynamicCacheSelfTest { /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java similarity index 94% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java index 71e516061a85e..31294ce894274 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java @@ -19,7 +19,7 @@ /** * */ -public class IgnitePersistentStorePageSizesSelfTest extends GridCommonAbstractTest { +public class IgnitePersistentStorePageSizesTest extends GridCommonAbstractTest { /** */ private int pageSize; @@ -41,11 +41,11 @@ public class IgnitePersistentStorePageSizesSelfTest extends GridCommonAbstractTe cfg.setMemoryConfiguration(memCfg); - PersistenceConfiguration pCfg = new PersistenceConfiguration(); + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); cfg.setCacheConfiguration( new CacheConfiguration("partitioned") - .setAffinity(new RendezvousAffinityFunction(false, 32)) + .setAffinity(new RendezvousAffinityFunction(false, 32)) ); return cfg; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java index 1965369ccea36..3c35884642239 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java @@ -40,6 +40,37 @@ public class IgnitePersistentStoreRecoveryAfterFileCorruptionTest extends GridCo /** Total pages. */ private static final int totalPages = 1024; + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration("partitioned"); + + ccfg.setRebalanceMode(CacheRebalanceMode.NONE); + + cfg.setCacheConfiguration(ccfg); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(1024 * 1024 * 1024); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + PersistenceConfiguration pCfg = new PersistenceConfiguration(); + + pCfg.setCheckpointFrequency(500); + + cfg.setPersistenceConfiguration(pCfg); + + return cfg; + } + /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES, "true"); @@ -162,37 +193,6 @@ private void checkRestore(IgniteEx ig, FullPageId[] pages) throws IgniteCheckedE } } - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - CacheConfiguration ccfg = new CacheConfiguration("partitioned"); - - ccfg.setRebalanceMode(CacheRebalanceMode.NONE); - - cfg.setCacheConfiguration(ccfg); - - MemoryConfiguration dbCfg = new MemoryConfiguration(); - - MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); - - memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(1024 * 1024 * 1024); - - dbCfg.setMemoryPolicies(memPlcCfg); - dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); - - cfg.setMemoryConfiguration(dbCfg); - - PersistenceConfiguration pCfg = new PersistenceConfiguration(); - - pCfg.setCheckpointFrequency(500); - - cfg.setPersistenceConfiguration(pCfg); - - return cfg; - } - /** * @param mem Mem. * @param storeMgr Store manager. diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuit2.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuit2.java index e3baf0453a22a..deddb5825755f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuit2.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuit2.java @@ -4,7 +4,7 @@ import org.apache.ignite.cache.database.IgnitePersistentStoreAtomicCacheRebalancingTest; import org.apache.ignite.cache.database.IgnitePersistentStoreTxCacheRebalancingTest; import org.apache.ignite.cache.database.IgnitePersistentStoreContinuousRestartSelfTest; -import org.apache.ignite.cache.database.IgnitePersistentStorePageSizesSelfTest; +import org.apache.ignite.cache.database.IgnitePersistentStorePageSizesTest; import org.apache.ignite.cache.database.IgnitePersistentStoreWalTlbSelfTest; import org.apache.ignite.cache.database.IgnitePersistentStoreRecoveryAfterFileCorruptionTest; import org.apache.ignite.cache.database.db.DbPageEvictionDuringPartitionClearSelfTest; @@ -31,7 +31,7 @@ public static TestSuite suite() throws Exception { // Integrity test suite.addTestSuite(IgniteDataIntegrityTests.class); suite.addTestSuite(IgnitePersistentStoreRecoveryAfterFileCorruptionTest.class); - suite.addTestSuite(IgnitePersistentStorePageSizesSelfTest.class); + suite.addTestSuite(IgnitePersistentStorePageSizesTest.class); suite.addTestSuite(IgnitePersistentStoreWalTlbSelfTest.class); // WAL recovery test. diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuite.java index b66e7e8ea6d25..e58ae09f0103d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuite.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuite.java @@ -2,7 +2,7 @@ import junit.framework.TestSuite; import org.apache.ignite.cache.database.IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreDynamicCacheTest; import org.apache.ignite.cache.database.IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest; import org.apache.ignite.cache.database.IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest; import org.apache.ignite.cache.database.db.IgniteDbMultiNodePutGetRestartSelfTest; @@ -66,7 +66,7 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.class); suite.addTestSuite(IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.class); suite.addTestSuite(IgniteDbPageEvictionSelfTest.class); - suite.addTestSuite(IgnitePersistentStoreDynamicCacheWithPersistenceSelfTest.class); + suite.addTestSuite(IgnitePersistentStoreDynamicCacheTest.class); suite.addTestSuite(IgniteWalDirectoriesConfigurationTest.class); suite.addTestSuite(IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.class); From f6ea4a1b2269ac97708860afceb84da2f31f1a29 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 8 May 2017 14:15:34 +0300 Subject: [PATCH 155/311] ignite-gg-12163 fix oom in test --- .../database/IgnitePersistentStoreWalTlbSelfTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java index c295e1ea41ebb..a03efe43892d5 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java @@ -15,6 +15,8 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import static org.apache.ignite.configuration.PersistenceConfiguration.DFLT_CHECKPOINT_PAGE_BUFFER_SIZE; + /** * */ @@ -42,7 +44,10 @@ public class IgnitePersistentStoreWalTlbSelfTest extends GridCommonAbstractTest cfg.setMemoryConfiguration(memCfg); - cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + cfg.setPersistenceConfiguration( + new PersistenceConfiguration() + .setCheckpointPageBufferSize(DFLT_CHECKPOINT_PAGE_BUFFER_SIZE + 1) + ); TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); From a383df739163fac9525730a3ecdca0213d358142 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 8 May 2017 15:20:57 +0300 Subject: [PATCH 156/311] ignite-gg-12163 provide callback handler, flush or evict page for snapshot Manager --- .../database/IgniteCacheSnapshotManager.java | 65 +++++----- .../GridCacheDatabaseSharedManager.java | 112 ++++-------------- 2 files changed, 54 insertions(+), 123 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java index 0721d10418484..39f4a67539a6f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java @@ -10,6 +10,8 @@ import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; +import org.apache.ignite.internal.util.lang.GridInClosure3X; +import org.apache.ignite.internal.util.typedef.CIX3; import org.apache.ignite.internal.util.typedef.T2; import org.jetbrains.annotations.Nullable; @@ -31,38 +33,6 @@ public class IgniteCacheSnapshotManager extends GridCacheSharedManagerAdapter { return null; } - /** - * @param cacheId Cache id. - * @param pageMem Page Memory. - */ - public long getLastSuccessfulSnapshotTagForCache(int cacheId, PageMemory pageMem) { - return 0; - } - - /** - * @param cacheId Cache ID. - * @param pageMem Page Memory. - * @return Next snapshot ID for given cache. - */ - public long getNextSnapshotTagForCache(int cacheId, PageMemory pageMem) { - return 0; - } - - /** - * - */ - public void restoreState() throws IgniteCheckedException { - - } - - /** - * @param fullId Full id. - */ - public void onPageEvict(FullPageId fullId) throws IgniteCheckedException { - - } - - /** * @param snapOp current snapshot operation. * @@ -71,10 +41,17 @@ public void onPageEvict(FullPageId fullId) throws IgniteCheckedException { public boolean onMarkCheckPointBegin( SnapshotOperation snapOp, NavigableMap, T2> map - ){ + ) throws IgniteCheckedException { return false; } + /** + * + */ + public void restoreState() throws IgniteCheckedException { + + } + /** * */ @@ -116,4 +93,26 @@ public void checkPointBufferCopyPage(FullPageId fullId, ByteBuffer tmpWriteBuf) public void onCacheStop(GridCacheContext cctx) { } + + /** + * + */ + public GridInClosure3X changeTrackerPageHandler(){ + return new CIX3() { + @Override public void applyx(Long aLong, FullPageId id, PageMemory memory) { + // No-op. + } + }; + } + + /** + * + */ + public GridInClosure3X flushDirtyPageHandler() { + return new CIX3() { + @Override public void applyx(FullPageId fullId, ByteBuffer pageBuf, Integer tag) { + + } + }; + } } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 5cae4c2e6cddf..0051baa2fee00 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -75,12 +75,10 @@ import org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord; import org.apache.ignite.internal.pagemem.wal.record.PageSnapshot; import org.apache.ignite.internal.pagemem.wal.record.WALRecord; -import org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateLastAllocatedIndex; import org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord; -import org.apache.ignite.internal.pagemem.wal.record.delta.TrackingPageDeltaRecord; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.ClusterState; import org.apache.ignite.internal.processors.cache.GridCacheContext; @@ -91,8 +89,6 @@ import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionMetaIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; import org.apache.ignite.internal.processors.cache.database.wal.FileWALPointer; import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; @@ -235,15 +231,9 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan /** */ private boolean stopping; - /** Tracking io. */ - private final TrackingPageIO trackingIO = TrackingPageIO.VERSIONS.latest(); - /** Page meta io. */ private final PageMetaIO pageMetaIO = PageMetaIO.VERSIONS.latest(); - /** Meta io. */ - private static final PageMetaIO metaIO = PageMetaIO.VERSIONS.latest(); - /** Checkpoint runner thread pool. */ private ExecutorService asyncRunner; @@ -559,16 +549,29 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { MemoryPolicyConfiguration cfg, MemoryMetricsImpl memMetrics ) { + final GridInClosure3X trackerPageHnd = snapshotMgr.changeTrackerPageHandler(); + + final GridInClosure3X flushDirtyPageHnd = snapshotMgr.flushDirtyPageHandler(); + return new PageMemoryImpl(memProvider, cctx, pageSize, new GridInClosure3X() { - @Override public void applyx(FullPageId fullId, ByteBuffer pageBuf, Integer tag) - throws IgniteCheckedException { - flushPageOnEvict(fullId, pageBuf, tag); + @Override public void applyx( + FullPageId fullId, + ByteBuffer pageBuf, + Integer tag + ) throws IgniteCheckedException { + storeMgr.write(fullId.cacheId(), fullId.pageId(), pageBuf, tag); + + flushDirtyPageHnd.applyx(fullId, pageBuf, tag); } }, new GridInClosure3X() { - @Override public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) { - markDirty(fullId.cacheId(), fullId.pageId(), pageMem); + @Override public void applyx( + Long page, + FullPageId fullId, + PageMemoryEx pageMem + ) throws IgniteCheckedException { + trackerPageHnd.applyx(page, fullId, pageMem); } }, this @@ -582,67 +585,6 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { throw new IgniteCheckedException("Page eviction is not compatible with persistence: " + plcCfg.getName()); } - /** - * @param pageMem Page memory. - */ - private void markDirty(int cacheId, long pageId, PageMemory pageMem) { - //skip super page - if (PageIdUtils.pageIndex(pageId) == 0) - return; - - long lastSuccessfulSnapshotTag = snapshotMgr.getLastSuccessfulSnapshotTagForCache(cacheId, pageMem); - - if (lastSuccessfulSnapshotTag < 0) //there is no full snapshot - return; - - long trackingPageId = trackingIO.trackingPageFor(pageId, pageMem.pageSize()); - - //skip tracking page - if (pageId == trackingPageId) - return; - - try { - long trackingPage = pageMem.acquirePage(cacheId, trackingPageId); - try { - long pageAddr = pageMem.writeLock(cacheId, trackingPageId, trackingPage); - - try { - //cooperative initialization - if (PageIO.getType(pageAddr) == 0) { - trackingIO.initNewPage(pageAddr, trackingPageId, pageMem.pageSize()); - - if (isWalDeltaRecordNeeded(pageMem, cacheId, trackingPageId, trackingPage, cctx.wal(), null)) { - cctx.wal().log(new InitNewPageRecord(cacheId, trackingPageId, trackingIO.getType(), - trackingIO.getVersion(), trackingPageId)); - } - } - - long nextSnapshotTag = snapshotMgr.getNextSnapshotTagForCache(cacheId, (PageMemoryEx) pageMem); - - trackingIO.markChanged(pageMem.pageBuffer(pageAddr), - pageId, - nextSnapshotTag, - lastSuccessfulSnapshotTag, - pageMem.pageSize()); - - if (PageHandler.isWalDeltaRecordNeeded(pageMem, cacheId, trackingPageId, trackingPage, cctx.wal(), null)) - cctx.wal().log(new TrackingPageDeltaRecord( - cacheId, trackingPageId, pageId, nextSnapshotTag, lastSuccessfulSnapshotTag)); - } - finally { - pageMem.writeUnlock(cacheId, trackingPageId, trackingPage, null, true); - } - } - finally { - pageMem.releasePage(cacheId, trackingPageId, trackingPage); - } - } - catch (IgniteCheckedException e) { - // TODO we should not allow next incremental snapshot since we've lost an updated page. - U.error(log, "There was an exception while updating tracking page: " + U.hexLong(trackingPageId), e); - } - } - /** * @param cancel Cancel flag. */ @@ -1629,16 +1571,6 @@ private void applyUpdate(GridCacheContext cacheCtx, DataEntry dataEntry) throws } } - /** - * @param fullId Full page ID. - * @param pageBuf Page buffer. - */ - private void flushPageOnEvict(FullPageId fullId, ByteBuffer pageBuf, int tag) throws IgniteCheckedException { - storeMgr.write(fullId.cacheId(), fullId.pageId(), pageBuf, tag); - - snapshotMgr.onPageEvict(fullId); - } - /** * @throws IgniteCheckedException If failed. */ @@ -2420,7 +2352,7 @@ private WriteCheckpointPages( * @param cacheId Cache id. * @param part Partition. */ - public static void completeSavingAllocatedIndex( + public void completeSavingAllocatedIndex( PageMemoryEx pageMem, IgniteWriteAheadLogManager wal, int cacheId, int part ) throws IgniteCheckedException { long pageId = getSuperPageId(pageMem, cacheId, part); @@ -2433,14 +2365,14 @@ public static void completeSavingAllocatedIndex( try { assert PageIO.getPageId(pageAddr) != 0; - int lastAllocatedIdx = metaIO.getLastPageCount(pageAddr); - int candidateAllocatedIdx = metaIO.getCandidatePageCount(pageAddr); + int lastAllocatedIdx = pageMetaIO.getLastPageCount(pageAddr); + int candidateAllocatedIdx = pageMetaIO.getCandidatePageCount(pageAddr); if (lastAllocatedIdx != candidateAllocatedIdx) { if (isWalDeltaRecordNeeded(pageMem, cacheId, pageId, page, wal, null)) wal.log(new MetaPageUpdateLastAllocatedIndex(cacheId, pageId, candidateAllocatedIdx)); - metaIO.setLastPageCount(pageAddr, candidateAllocatedIdx); + pageMetaIO.setLastPageCount(pageAddr, candidateAllocatedIdx); wasChanged = true; } From c51de7fbe170a9d0e44c1943a509ff0b27944ab4 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 8 May 2017 15:31:12 +0300 Subject: [PATCH 157/311] ignite-gg-12163 remove unnecessary method in dbSharedManager --- .../cache/database/IgniteCacheDatabaseSharedManager.java | 7 ------- .../cache/database/GridCacheDatabaseSharedManager.java | 7 ------- 2 files changed, 14 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 2a2014c384487..59cdb1d8f4827 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -165,13 +165,6 @@ private void startMemoryPolicies() { } } - /** - * - */ - public Object getSnapshotMgr() { - return null; - } - /** * @param dbCfg Database config. */ diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 0051baa2fee00..483fcc05a7842 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -291,13 +291,6 @@ public Checkpointer getCheckpointer() { return checkpointer; } - /** - * - */ - @Override public IgniteCacheSnapshotManager getSnapshotMgr() { - return snapshotMgr; - } - /** * For test use only. */ From 0c37da097830bab64ab9983f77d37c8d51cca101 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 9 May 2017 14:01:15 +0300 Subject: [PATCH 158/311] ignite-gg-12163 test refactoring --- .../cache/database/IgniteCacheSnapshotManager.java | 2 +- .../database/GridCacheDatabaseSharedManager.java | 5 +++-- ...ePersistentStoreCacheRebalancingAbstractTest.java | 12 ++++++------ .../IgniteChangeGlobalStateSuite.java} | 9 +++++++-- 4 files changed, 17 insertions(+), 11 deletions(-) rename modules/pds/src/test/java/org/apache/ignite/{cache/database/standbycluster/GridChangeGlobalStateSuite.java => testsuites/IgniteChangeGlobalStateSuite.java} (53%) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java index 39f4a67539a6f..aa6b0a5fe7884 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java @@ -111,7 +111,7 @@ public GridInClosure3X changeTrackerPageHandler(){ public GridInClosure3X flushDirtyPageHandler() { return new CIX3() { @Override public void applyx(FullPageId fullId, ByteBuffer pageBuf, Integer tag) { - + // No-op. } }; } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 483fcc05a7842..e5523caadd9ec 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -428,7 +428,7 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { onKernalStop0(true); - /*must be here, because after deactivate we can invoke activate and file lock must be already configured */ + /* Must be here, because after deactivate we can invoke activate and file lock must be already configured */ stopping = false; fileLockHolder = new FileLockHolder(storeMgr.workDir().getPath(), cctx.kernalContext(), log); @@ -1442,7 +1442,8 @@ private void applyLastUpdates(CheckpointStatus status) throws IgniteCheckedExcep * @throws IgniteCheckedException If failed to restore. */ private void restorePartitionState( - Map, T2> partStates) throws IgniteCheckedException { + Map, T2> partStates + ) throws IgniteCheckedException { Collection cacheContexts = cctx.cacheContexts(); for (GridCacheContext context : cacheContexts) { diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index c941a5cf4ebe0..551886a7dbff1 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -53,7 +53,7 @@ public abstract class IgnitePersistentStoreCacheRebalancingAbstractTest extends @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - CacheConfiguration ccfg1 = cacheConfiguration(null); + CacheConfiguration ccfg1 = cacheConfiguration("cache"); ccfg1.setBackups(1); ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); @@ -381,7 +381,7 @@ public void testPartitionLossAndRecover() throws Exception { awaitPartitionMapExchange(); - IgniteCache cache1 = ignite1.cache(null); + IgniteCache cache1 = ignite1.cache("cache"); for (int i = 0; i < 100; i++) cache1.put(i, i); @@ -395,7 +395,7 @@ public void testPartitionLossAndRecover() throws Exception { awaitPartitionMapExchange(); - assert !cache1.lostPartitions().isEmpty(); + assert !ignite1.cache("cache").lostPartitions().isEmpty(); ignite3 = (IgniteEx)G.start(getConfiguration("test3")); ignite4 = (IgniteEx)G.start(getConfiguration("test4")); @@ -404,9 +404,9 @@ public void testPartitionLossAndRecover() throws Exception { ignite1.resetLostPartitions(Collections.singletonList(cache1.getName())); - IgniteCache cache2 = ignite2.cache(null); - IgniteCache cache3 = ignite3.cache(null); - IgniteCache cache4 = ignite4.cache(null); + IgniteCache cache2 = ignite2.cache("cache"); + IgniteCache cache3 = ignite3.cache("cache"); + IgniteCache cache4 = ignite4.cache("cache"); for (int i = 0; i < 100; i++) { assert cache1.get(i).equals(i); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteChangeGlobalStateSuite.java similarity index 53% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateSuite.java rename to modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteChangeGlobalStateSuite.java index 10a8bfbb03e8d..a9a3c38745ae9 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateSuite.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteChangeGlobalStateSuite.java @@ -1,11 +1,16 @@ -package org.apache.ignite.cache.database.standbycluster; +package org.apache.ignite.testsuites; import junit.framework.TestSuite; +import org.apache.ignite.cache.database.standbycluster.GridChangeGlobalStateCacheTest; +import org.apache.ignite.cache.database.standbycluster.GridChangeGlobalStateDataStreamerTest; +import org.apache.ignite.cache.database.standbycluster.GridChangeGlobalStateDataStructureTest; +import org.apache.ignite.cache.database.standbycluster.GridChangeGlobalStateFailOverTest; +import org.apache.ignite.cache.database.standbycluster.GridChangeGlobalStateTest; /** * */ -public class GridChangeGlobalStateSuite extends TestSuite { +public class IgniteChangeGlobalStateSuite extends TestSuite { /** * */ From a14a594d2168c7e5bda56bc0cdc2492c5ffc1f82 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 9 May 2017 15:27:17 +0300 Subject: [PATCH 159/311] ignite-gg-12163 provide cache name --- ...tentStoreCacheRebalancingAbstractTest.java | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index 551886a7dbff1..9c7ff0cdd8278 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -7,6 +7,7 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; @@ -49,11 +50,14 @@ public abstract class IgnitePersistentStoreCacheRebalancingAbstractTest extends /** */ protected boolean explicitTx; + /** Cache name. */ + private final String cacheName = "cache"; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - CacheConfiguration ccfg1 = cacheConfiguration("cache"); + CacheConfiguration ccfg1 = cacheConfiguration(cacheName); ccfg1.setBackups(1); ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); @@ -153,7 +157,7 @@ public void testRebalancingOnRestart() throws Exception { awaitPartitionMapExchange(); - IgniteCache cache1 = ignite0.cache(null); + IgniteCache cache1 = ignite0.cache(cacheName); for (int i = 0; i < 5000; i++) cache1.put(i, i); @@ -182,7 +186,7 @@ public void testRebalancingOnRestart() throws Exception { awaitPartitionMapExchange(); - IgniteCache cache3 = ignite2.cache(null); + IgniteCache cache3 = ignite2.cache(cacheName); for (int i = 0; i < 100; i++) assertEquals(String.valueOf(i), (Integer)(i * 2), cache3.get(i)); @@ -201,10 +205,10 @@ public void testRebalancingOnRestartAfterCheckpoint() throws Exception { IgniteEx ignite2 = startGrid(2); IgniteEx ignite3 = startGrid(3); - ignite0.cache(null).rebalance().get(); - ignite1.cache(null).rebalance().get(); - ignite2.cache(null).rebalance().get(); - ignite3.cache(null).rebalance().get(); + ignite0.cache(cacheName).rebalance().get(); + ignite1.cache(cacheName).rebalance().get(); + ignite2.cache(cacheName).rebalance().get(); + ignite3.cache(cacheName).rebalance().get(); awaitPartitionMapExchange(); @@ -242,13 +246,13 @@ public void testRebalancingOnRestartAfterCheckpoint() throws Exception { ignite2 = startGrid(2); ignite3 = startGrid(3); - ignite2.cache(null).rebalance().get(); - ignite3.cache(null).rebalance().get(); + ignite2.cache(cacheName).rebalance().get(); + ignite3.cache(cacheName).rebalance().get(); awaitPartitionMapExchange(); - IgniteCache cache2 = ignite2.cache(null); - IgniteCache cache3 = ignite3.cache(null); + IgniteCache cache2 = ignite2.cache(cacheName); + IgniteCache cache3 = ignite3.cache(cacheName); for (int i = 0; i < 100; i++) { assertEquals(String.valueOf(i), (Integer)(i * 2), cache2.get(i)); @@ -270,13 +274,13 @@ public void testNoRebalancingOnRestartDeactivated() throws Exception { awaitPartitionMapExchange(); - IgniteCache cache1 = ignite1.cache(null); + IgniteCache cache1 = ignite1.cache(cacheName); final Collection parts = new HashSet<>(); for (int i = 0; i < 100; i++) { cache1.put(i, i); - parts.add(ignite1.affinity(null).partition(i)); + parts.add(ignite1.affinity(cacheName).partition(i)); } ignite1.active(false); @@ -290,13 +294,13 @@ public void testNoRebalancingOnRestartDeactivated() throws Exception { ignite1 = (IgniteEx)G.start(getConfiguration("test1")); - cache1 = ignite1.cache(null); + cache1 = ignite1.cache(cacheName); ignite1.active(false); ignite1.events().remoteListen(new IgniteBiPredicate() { @Override public boolean apply(UUID uuid, CacheRebalancingEvent evt) { - if (evt.cacheName() == null && parts.contains(evt.partition())) + if (Objects.equals(evt.cacheName(), cacheName) && parts.contains(evt.partition())) evtCnt.incrementAndGet(); return true; @@ -313,9 +317,9 @@ public void testNoRebalancingOnRestartDeactivated() throws Exception { assert evtCnt.get() == 0 : evtCnt.get(); - IgniteCache cache2 = ignite2.cache(null); - IgniteCache cache3 = ignite3.cache(null); - IgniteCache cache4 = ignite4.cache(null); + IgniteCache cache2 = ignite2.cache(cacheName); + IgniteCache cache3 = ignite3.cache(cacheName); + IgniteCache cache4 = ignite4.cache(cacheName); for (int i = 0; i < 100; i++) { assert cache1.get(i).equals(i); @@ -338,7 +342,7 @@ public void testDataCorrectnessAfterRestart() throws Exception { awaitPartitionMapExchange(); - IgniteCache cache1 = ignite1.cache(null); + IgniteCache cache1 = ignite1.cache(cacheName); for (int i = 0; i < 100; i++) cache1.put(i, i); @@ -355,10 +359,10 @@ public void testDataCorrectnessAfterRestart() throws Exception { awaitPartitionMapExchange(); - cache1 = ignite1.cache(null); - IgniteCache cache2 = ignite2.cache(null); - IgniteCache cache3 = ignite3.cache(null); - IgniteCache cache4 = ignite4.cache(null); + cache1 = ignite1.cache(cacheName); + IgniteCache cache2 = ignite2.cache(cacheName); + IgniteCache cache3 = ignite3.cache(cacheName); + IgniteCache cache4 = ignite4.cache(cacheName); for (int i = 0; i < 100; i++) { assert cache1.get(i).equals(i); @@ -381,7 +385,7 @@ public void testPartitionLossAndRecover() throws Exception { awaitPartitionMapExchange(); - IgniteCache cache1 = ignite1.cache("cache"); + IgniteCache cache1 = ignite1.cache(cacheName); for (int i = 0; i < 100; i++) cache1.put(i, i); @@ -395,7 +399,7 @@ public void testPartitionLossAndRecover() throws Exception { awaitPartitionMapExchange(); - assert !ignite1.cache("cache").lostPartitions().isEmpty(); + assert !ignite1.cache(cacheName).lostPartitions().isEmpty(); ignite3 = (IgniteEx)G.start(getConfiguration("test3")); ignite4 = (IgniteEx)G.start(getConfiguration("test4")); @@ -404,9 +408,9 @@ public void testPartitionLossAndRecover() throws Exception { ignite1.resetLostPartitions(Collections.singletonList(cache1.getName())); - IgniteCache cache2 = ignite2.cache("cache"); - IgniteCache cache3 = ignite3.cache("cache"); - IgniteCache cache4 = ignite4.cache("cache"); + IgniteCache cache2 = ignite2.cache(cacheName); + IgniteCache cache3 = ignite3.cache(cacheName); + IgniteCache cache4 = ignite4.cache(cacheName); for (int i = 0; i < 100; i++) { assert cache1.get(i).equals(i); From c3874579ea9d03342161b0f5c33052d6570e7ad0 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 10 May 2017 16:45:57 +0300 Subject: [PATCH 160/311] ignite-12163 simplify snapshot callback --- .../database/IgniteCacheSnapshotManager.java | 30 +++++++++---------- .../GridCacheDatabaseSharedManager.java | 12 +++----- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java index aa6b0a5fe7884..c9cde551741bc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java @@ -10,8 +10,6 @@ import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; -import org.apache.ignite.internal.util.lang.GridInClosure3X; -import org.apache.ignite.internal.util.typedef.CIX3; import org.apache.ignite.internal.util.typedef.T2; import org.jetbrains.annotations.Nullable; @@ -76,14 +74,14 @@ public void afterCheckpointPageWritten() { /** * @param fullId Full id. */ - public void checkPointCopyPage(FullPageId fullId) { + public void beforePageWrite(FullPageId fullId) { } /** * @param fullId Full id. */ - public void checkPointBufferCopyPage(FullPageId fullId, ByteBuffer tmpWriteBuf) { + public void onPageWrite(FullPageId fullId, ByteBuffer tmpWriteBuf) { } @@ -97,22 +95,22 @@ public void onCacheStop(GridCacheContext cctx) { /** * */ - public GridInClosure3X changeTrackerPageHandler(){ - return new CIX3() { - @Override public void applyx(Long aLong, FullPageId id, PageMemory memory) { - // No-op. - } - }; + public void onChangeTrackerPage( + Long page, + FullPageId fullId, + PageMemory pageMem + ) throws IgniteCheckedException { + } /** * */ - public GridInClosure3X flushDirtyPageHandler() { - return new CIX3() { - @Override public void applyx(FullPageId fullId, ByteBuffer pageBuf, Integer tag) { - // No-op. - } - }; + public void flushDirtyPageHandler( + FullPageId fullId, + ByteBuffer pageBuf, + Integer tag + ) throws IgniteCheckedException { + } } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index e5523caadd9ec..72d78181c2265 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -542,10 +542,6 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { MemoryPolicyConfiguration cfg, MemoryMetricsImpl memMetrics ) { - final GridInClosure3X trackerPageHnd = snapshotMgr.changeTrackerPageHandler(); - - final GridInClosure3X flushDirtyPageHnd = snapshotMgr.flushDirtyPageHandler(); - return new PageMemoryImpl(memProvider, cctx, pageSize, new GridInClosure3X() { @Override public void applyx( @@ -555,7 +551,7 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { ) throws IgniteCheckedException { storeMgr.write(fullId.cacheId(), fullId.pageId(), pageBuf, tag); - flushDirtyPageHnd.applyx(fullId, pageBuf, tag); + snapshotMgr.flushDirtyPageHandler(fullId, pageBuf, tag); } }, new GridInClosure3X() { @@ -564,7 +560,7 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { FullPageId fullId, PageMemoryEx pageMem ) throws IgniteCheckedException { - trackerPageHnd.applyx(page, fullId, pageMem); + snapshotMgr.onChangeTrackerPage(page,fullId,pageMem); } }, this @@ -2299,7 +2295,7 @@ private WriteCheckpointPages( tmpWriteBuf.rewind(); - snapshotMgr.checkPointCopyPage(fullId); + snapshotMgr.beforePageWrite(fullId); int cacheId = fullId.cacheId(); @@ -2321,7 +2317,7 @@ private WriteCheckpointPages( tmpWriteBuf.rewind(); } - snapshotMgr.checkPointBufferCopyPage(fullId, tmpWriteBuf); + snapshotMgr.onPageWrite(fullId, tmpWriteBuf); tmpWriteBuf.rewind(); From c60118daf9f185db2eab4c742da299dc98aa7ae2 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 10 May 2017 16:56:44 +0300 Subject: [PATCH 161/311] ignite-12163 minor renaming --- ...itePersistentStoreTestSuite.java => IgnitePdsTestSuite.java} | 2 +- ...tePersistentStoreTestSuit2.java => IgnitePdsTestSuite2.java} | 2 +- ...angeGlobalStateSuite.java => IgniteStandByClusterSuite.java} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename modules/pds/src/test/java/org/apache/ignite/testsuites/{IgnitePersistentStoreTestSuite.java => IgnitePdsTestSuite.java} (98%) rename modules/pds/src/test/java/org/apache/ignite/testsuites/{IgnitePersistentStoreTestSuit2.java => IgnitePdsTestSuite2.java} (97%) rename modules/pds/src/test/java/org/apache/ignite/testsuites/{IgniteChangeGlobalStateSuite.java => IgniteStandByClusterSuite.java} (94%) diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuite.java rename to modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java index e58ae09f0103d..ab85f4a02ae19 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuite.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java @@ -29,7 +29,7 @@ /** * */ -public class IgnitePersistentStoreTestSuite extends TestSuite { +public class IgnitePdsTestSuite extends TestSuite { /** * @return Suite. * @throws Exception If failed. diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuit2.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuit2.java rename to modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java index deddb5825755f..267dbe567a851 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePersistentStoreTestSuit2.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java @@ -20,7 +20,7 @@ /** * */ -public class IgnitePersistentStoreTestSuit2 extends TestSuite { +public class IgnitePdsTestSuite2 extends TestSuite { /** * @return Suite. * @throws Exception If failed. diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteChangeGlobalStateSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java similarity index 94% rename from modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteChangeGlobalStateSuite.java rename to modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java index a9a3c38745ae9..17b667d44aa85 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteChangeGlobalStateSuite.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java @@ -10,7 +10,7 @@ /** * */ -public class IgniteChangeGlobalStateSuite extends TestSuite { +public class IgniteStandByClusterSuite extends TestSuite { /** * */ From 8004287cfef875089a926a5422ebe09e4dc0ad7b Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Wed, 10 May 2017 17:40:24 +0300 Subject: [PATCH 162/311] IGNITE-GG-12163 IgniteComponentType mechanism employed to instantiate PDS managers --- .../ignite/internal/IgniteComponentType.java | 17 ++++++++++++- .../processors/cache/GridCacheProcessor.java | 24 ++++--------------- .../GridCacheDatabaseSharedManager.java | 6 +++-- .../database/file/FilePageStoreManager.java | 7 +++--- .../wal/FileWriteAheadLogManager.java | 6 +++-- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java index 0cd2fc16d1e2a..1b70ab4c556dd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java @@ -89,7 +89,22 @@ public enum IgniteComponentType { "org.apache.ignite.internal.processors.schedule.IgniteNoopScheduleProcessor", "org.apache.ignite.internal.processors.schedule.IgniteScheduleProcessor", "ignite-schedule" - ); + ), + + /** Database manager used when persistence is enabled. */ + DATABASE_MANAGER(null, + "org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager", + "ignite-pds"), + + /** Page store manager used when persistence is enabled. */ + PAGE_STORE_MANAGER(null, + "org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager", + "ignite-pds"), + + /** Write-Ahead Log manager used when persistence is enabled. */ + WAL_MANAGER(null, + "org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager", + "ignite-pds"); /** No-op class name. */ private final String noOpClsName; 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 bf13f188506c9..fb82ac6a5f76f 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 @@ -2147,27 +2147,11 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, IgniteWriteAheadLogManager walMgr = null; if (ctx.config().isPersistentEnable()) { - ClassLoader clsLdr = U.gridClassLoader(); + dbMgr = IgniteComponentType.DATABASE_MANAGER.create(ctx, false); - try { - dbMgr = (IgniteCacheDatabaseSharedManager) clsLdr - .loadClass("org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager") - .getConstructor(IgniteConfiguration.class) - .newInstance(ctx.config()); - - pageStoreMgr = (IgnitePageStoreManager) clsLdr - .loadClass("org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager") - .getConstructor(IgniteConfiguration.class) - .newInstance(ctx.config()); - - walMgr = (IgniteWriteAheadLogManager) clsLdr - .loadClass("org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager") - .getConstructor(IgniteConfiguration.class) - .newInstance(ctx.config()); - } - catch (Exception e) { - throw new IgniteCheckedException("Failed to initialize persistent store", e); - } + pageStoreMgr = IgniteComponentType.PAGE_STORE_MANAGER.create(ctx, false); + + walMgr = IgniteComponentType.WAL_MANAGER.create(ctx, false); } else dbMgr = new IgniteCacheDatabaseSharedManager(); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index e5523caadd9ec..605be125ccdf9 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -259,9 +259,11 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan private IgniteCacheSnapshotManager snapshotMgr; /** - * @param cfg Ignite configuration. + * @param ctx Kernal context. */ - public GridCacheDatabaseSharedManager(IgniteConfiguration cfg) { + public GridCacheDatabaseSharedManager(GridKernalContext ctx) { + IgniteConfiguration cfg = ctx.config(); + dbCfg = cfg.getPersistenceConfiguration(); assert dbCfg != null : "PageStore should not be created if persistence is disabled."; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java index fdfd3e0e07606..ae324629d92d0 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java @@ -79,15 +79,16 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen private final Set cachesWithoutIdx = Collections.newSetFromMap(new ConcurrentHashMap()); /** - * @param igniteCfg Ignite configuration. + * @param ctx Kernal context. */ - public FilePageStoreManager(IgniteConfiguration igniteCfg) { + public FilePageStoreManager(GridKernalContext ctx) { + igniteCfg = ctx.config(); + PersistenceConfiguration pstCfg = igniteCfg.getPersistenceConfiguration(); assert pstCfg != null : "WAL should not be created if persistence is disabled."; this.pstCfg = pstCfg; - this.igniteCfg = igniteCfg; } /** {@inheritDoc} */ diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java index e53a92d0d7218..7b39369cf3bda 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -157,9 +157,11 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl private ThreadLocal lastWALPtr = new ThreadLocal<>(); /** - * @param igCfg Ignite Configuration. + * @param ctx Kernal context. */ - public FileWriteAheadLogManager(IgniteConfiguration igCfg) { + public FileWriteAheadLogManager(GridKernalContext ctx) { + igCfg = ctx.config(); + PersistenceConfiguration dbCfg = igCfg.getPersistenceConfiguration(); assert dbCfg != null : "WAL should not be created if persistence is disabled."; From 2e3e97141502a3e4120d46ef314f8d3ac368e050 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Thu, 11 May 2017 11:17:07 +0300 Subject: [PATCH 163/311] ignite-12163 remove completeSavingAllocatedIndex method, add test for fullPageIdTable --- .../GridCacheDatabaseSharedManager.java | 53 ----- .../database/pagemem/FullPageIdTable.java | 4 +- .../database/pagemem/FullPageIdTableTest.java | 96 ++++++++ .../pagemem/PageIdDistributionTest.java | 215 ++++++++++++++++++ 4 files changed, 313 insertions(+), 55 deletions(-) create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 43905825b6acb..ef318adab501d 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -231,9 +231,6 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan /** */ private boolean stopping; - /** Page meta io. */ - private final PageMetaIO pageMetaIO = PageMetaIO.VERSIONS.latest(); - /** Checkpoint runner thread pool. */ private ExecutorService asyncRunner; @@ -2339,56 +2336,6 @@ private WriteCheckpointPages( } } - /** - * @param pageMem Page mem. - * @param cacheId Cache id. - * @param part Partition. - */ - public void completeSavingAllocatedIndex( - PageMemoryEx pageMem, IgniteWriteAheadLogManager wal, int cacheId, int part - ) throws IgniteCheckedException { - long pageId = getSuperPageId(pageMem, cacheId, part); - long page = pageMem.acquirePage(cacheId, pageId); - try { - long pageAddr = pageMem.writeLock(cacheId, pageId, page); - - boolean wasChanged = false; - - try { - assert PageIO.getPageId(pageAddr) != 0; - - int lastAllocatedIdx = pageMetaIO.getLastPageCount(pageAddr); - int candidateAllocatedIdx = pageMetaIO.getCandidatePageCount(pageAddr); - - if (lastAllocatedIdx != candidateAllocatedIdx) { - if (isWalDeltaRecordNeeded(pageMem, cacheId, pageId, page, wal, null)) - wal.log(new MetaPageUpdateLastAllocatedIndex(cacheId, pageId, candidateAllocatedIdx)); - - pageMetaIO.setLastPageCount(pageAddr, candidateAllocatedIdx); - - wasChanged = true; - } - } - finally { - pageMem.writeUnlock(cacheId, pageId, page, null, wasChanged); - } - } - finally { - pageMem.releasePage(cacheId, pageId, page); - } - } - - /** - * @param pageMem Page mem. - * @param cacheId Cache id. - * @param part Partition. - */ - private static long getSuperPageId(PageMemoryEx pageMem, int cacheId, int part) throws IgniteCheckedException { - return part == PageIdAllocator.INDEX_PARTITION ? - pageMem.metaPageId(cacheId) : - pageMem.partitionMetaPageId(cacheId, part); - } - /** * */ diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java index 2c5099843e543..ab2f86e511671 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java @@ -423,7 +423,7 @@ private void setKeyAt(int index, int cacheId, long pageId) { * @param tag Tag. * @return Distance scanned if the entry is found or negative distance scanned, if entry was not found. */ - int distanceFromIdeal(int cacheId, long pageId, int tag) { + public int distanceFromIdeal(int cacheId, long pageId, int tag) { int step = 1; int index = U.safeAbs(FullPageId.hashCode(cacheId, pageId)) % capacity; @@ -461,7 +461,7 @@ else if (res == EMPTY) * * @param visitor Visitor. */ - void visitAll(IgniteBiInClosure visitor) { + public void visitAll(IgniteBiInClosure visitor) { for (int i = 0; i < capacity; i++) { if (isValuePresentAt(i)) { long base = entryBase(i); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java new file mode 100644 index 0000000000000..cae865e450f56 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java @@ -0,0 +1,96 @@ +package org.apache.ignite.cache.database.pagemem; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import org.apache.ignite.internal.mem.DirectMemoryRegion; +import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.processors.cache.database.pagemem.FullPageIdTable; +import org.apache.ignite.internal.util.typedef.CI2; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class FullPageIdTableTest extends GridCommonAbstractTest { + /** */ + private static final int CACHE_ID_RANGE = 10; + + /** */ + private static final int PAGE_ID_RANGE = 1000; + + /** + * @throws Exception if failed. + */ + public void testRandomOperations() throws Exception { + long mem = FullPageIdTable.requiredMemory(CACHE_ID_RANGE * PAGE_ID_RANGE); + + UnsafeMemoryProvider prov = new UnsafeMemoryProvider(new long[] {mem}); + prov.start(); + + try { + long seed = U.currentTimeMillis(); + + info("Seed: " + seed + "L; //"); + + Random rnd = new Random(seed); + + DirectMemoryRegion region = prov.memory().regions().get(0); + + FullPageIdTable tbl = new FullPageIdTable(region.address(), region.size(), true); + + Map check = new HashMap<>(); + + for (int i = 0; i < 10_000; i++) { + int cacheId = rnd.nextInt(CACHE_ID_RANGE) + 1; + int pageId = rnd.nextInt(PAGE_ID_RANGE); + + FullPageId fullId = new FullPageId(pageId, cacheId); + + boolean put = rnd.nextInt(3) != -1; + + if (put) { + long val = rnd.nextLong(); + + tbl.put(cacheId, pageId, val, 0); + check.put(fullId, val); + } + else { + tbl.remove(cacheId, pageId, 0); + check.remove(fullId); + } + + verifyLinear(tbl, check); + + if (i > 0 && i % 1000 == 0) + info("Done: " + i); + } + } + finally { + prov.stop(); + } + } + + /** + * @param tbl Table to check. + * @param check Expected mapping. + */ + private void verifyLinear(FullPageIdTable tbl, Map check) { + final Map collector = new HashMap<>(); + + tbl.visitAll(new CI2() { + @Override public void apply(FullPageId fullId, Long val) { + if (collector.put(fullId, val) != null) + throw new AssertionError("Duplicate full page ID mapping: " + fullId); + } + }); + + assertEquals("Size check failed", check.size(), collector.size()); + + for (Map.Entry entry : check.entrySet()) + assertEquals("Mapping comparison failed for key: " + entry.getKey(), + entry.getValue(), collector.get(entry.getKey())); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java new file mode 100644 index 0000000000000..6d5841bafe0c9 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java @@ -0,0 +1,215 @@ +package org.apache.ignite.cache.database.pagemem; + +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import org.apache.ignite.internal.mem.DirectMemoryRegion; +import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.processors.cache.database.pagemem.FullPageIdTable; +import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.util.typedef.T2; +import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class PageIdDistributionTest extends GridCommonAbstractTest { + /** */ + private static final int[] CACHE_IDS = new int[] { + CU.cacheId("partitioned1"), + CU.cacheId("partitioned2"), + CU.cacheId("partitioned3"), + CU.cacheId("partitioned4"), + CU.cacheId("replicated1"), + CU.cacheId("replicated2"), + CU.cacheId("replicated3"), + CU.cacheId("replicated4"), + }; + + /** */ + private static final int PARTS = 1024; + + /** */ + private static final int PAGES = 10240; + + /** + * + */ + public void testDistributions() { + printPageIdDistribution( + CU.cacheId("partitioned"), 1024, 30_000, 32, 2.5f); + + printPageIdDistribution( + CU.cacheId("partitioned"), 1024, 30_000, 64, 2.5f); + + printPageIdDistribution( + CU.cacheId(null), 1024, 30_000, 32, 2.5f); + } + + /** + * @param cacheId Cache id. + * @param parts Parts. + * @param pagesPerPartition Pages per partition. + * @param segments Segments. + * @param capFactor Capacity factor. + */ + private void printPageIdDistribution( + int cacheId, + int parts, + int pagesPerPartition, + int segments, + float capFactor + ) { + int allIds = parts * pagesPerPartition; + + int perSegmentSize = allIds / segments; + int capacity = (int)(perSegmentSize * capFactor); + + info("Total ids: " + allIds); + + List> collisionsPerSegment = new ArrayList<>(segments); + + for (int i = 0; i < segments; i++) + collisionsPerSegment.add(new HashMap(allIds / segments, 1.0f)); + + int[] numInSegment = new int[segments]; + + for (int p = 0; p < parts; p++) { + for (int i = 0; i < pagesPerPartition; i++) { + long pageId = PageIdUtils.pageId(p, (byte)0, i); + + int segment = PageMemoryImpl.segmentIndex(cacheId, pageId, segments); + + int idxInSegment = U.safeAbs(FullPageId.hashCode(cacheId, pageId)) % capacity; + + Map idxCollisions = collisionsPerSegment.get(segment); + + Integer old = idxCollisions.get(idxInSegment); + idxCollisions.put(idxInSegment, old == null ? 1 : old + 1); + + numInSegment[segment]++; + } + } + + for (int i = 0; i < collisionsPerSegment.size(); i++) { + Map idxCollisions = collisionsPerSegment.get(i); + + int distinctPositions = idxCollisions.size(); + + int totalCnt = 0; + int nonZero = 0; + + for (Map.Entry collision : idxCollisions.entrySet()) { + if (collision.getValue() != null) { + totalCnt += collision.getValue(); + nonZero++; + } + } + + info(String.format("Segment stats [i=%d, total=%d, distinct=%d, spaceUsed=%d%%, avgItCnt=%.1f + ']", + i, numInSegment[i], distinctPositions, distinctPositions * 100 / numInSegment[i], + (float)totalCnt / nonZero)); + } + + info("=========================================================="); + } + + /** + * Uncomment and run this test manually to get data to plot histogram for per-element distance from ideal. + * You can use Octave to plot the histogram: + *
+     *     all = csvread("histo.txt");
+     *     hist(all, 200)
+     * 
+ * + * @throws Exception If failed. + */ + public void _testRealHistory() throws Exception { + int cap = CACHE_IDS.length * PARTS * PAGES; + + info("Capacity: " + cap); + + long mem = FullPageIdTable.requiredMemory(cap); + + info(U.readableSize(mem, true)); + + UnsafeMemoryProvider prov = new UnsafeMemoryProvider(new long[] {mem}); + prov.start(); + + try { + long seed = U.currentTimeMillis(); + + info("Seed: " + seed + "L; //"); + + Random rnd = new Random(seed); + + DirectMemoryRegion region = prov.memory().regions().get(0); + + FullPageIdTable tbl = new FullPageIdTable(region.address(), region.size(), true); + + Map, Integer> allocated = new HashMap<>(); + + for (int i = 0; i < cap; i++) { + int cacheId = CACHE_IDS[rnd.nextInt(CACHE_IDS.length)]; + int partId = rnd.nextInt(PARTS); + + T2 key = new T2<>(cacheId, partId); + + Integer pageIdx = allocated.get(key); + + pageIdx = pageIdx == null ? 1 : pageIdx + 1; + + if (pageIdx > PAGES) + continue; + + tbl.put(cacheId, PageIdUtils.pageId(partId, (byte)0, pageIdx), 1, 0); + + allocated.put(key, pageIdx); + + if (i > 0 && i % 100_000 == 0) + info("Done: " + i); + } + + int[] scans = new int[cap]; + + int cur = 0; + + for (T2 key : allocated.keySet()) { + Integer alloc = allocated.get(key); + + if (alloc != null) { + for (int idx = 1; idx <= alloc; idx++) { + scans[cur] = tbl.distanceFromIdeal(key.get1(), PageIdUtils.pageId(key.get2(), (byte)0, idx), 0); + + assert scans[cur] != -1; + + cur++; + } + } + } + + try (FileOutputStream out = new FileOutputStream("histo.txt")) { + PrintWriter w = new PrintWriter(new OutputStreamWriter(out)); + + for (int scan : scans) { + if (scan != 0) + w.println(scan); + } + + w.flush(); + } + } + finally { + prov.stop(); + } + } +} From 1cce2fcc960c5098cc684b6138ed306daf5dd5e4 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Thu, 11 May 2017 15:33:05 +0300 Subject: [PATCH 164/311] IGNITE-GG-12163 test dependencies were cleaned up in pom file --- modules/pds/pom.xml | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/modules/pds/pom.xml b/modules/pds/pom.xml index c3bcec6d0fb21..01ef5745e5077 100644 --- a/modules/pds/pom.xml +++ b/modules/pds/pom.xml @@ -47,40 +47,12 @@ ${project.version} - - commons-io - commons-io - ${common.io.version} - test - - - - org.apache.ignite - ignite-spring - ${project.version} - test - - log4j log4j test - - com.thoughtworks.xstream - xstream - ${xstream.version} - test - - - - org.apache.ignite - ignite-indexing - ${project.version} - test - - org.apache.ignite ignite-indexing @@ -97,13 +69,6 @@ test - - com.google.guava - guava - ${guava.version} - test - - org.javassist javassist From 94a305332882113bc68e6feb0263d104f0c673ad Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Fri, 12 May 2017 16:31:04 +0700 Subject: [PATCH 165/311] GG-11898 Fixed VisorSnapshotsStatusTask. --- .../apache/ignite/internal/visor/VisorMultiNodeTask.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorMultiNodeTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorMultiNodeTask.java index 563a236eae0fa..89a5fcff03e66 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorMultiNodeTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorMultiNodeTask.java @@ -79,6 +79,13 @@ public abstract class VisorMultiNodeTask implements ComputeTask jobNodes(VisorTaskArgument arg) { + return arg.getNodes(); + } + /** * Actual map logic. * @@ -88,7 +95,7 @@ public abstract class VisorMultiNodeTask implements ComputeTask map0(List subgrid, VisorTaskArgument arg) { - Collection nodeIds = arg.getNodes(); + Collection nodeIds = jobNodes(arg); Map map = U.newHashMap(nodeIds.size()); From 96c293caa79f8d448077e1c7272df371cadaa0d2 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 12 May 2017 19:50:41 +0300 Subject: [PATCH 166/311] IGNITE-GG-12163 (revert) test dependencies were cleaned up in pom file --- modules/pds/pom.xml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/modules/pds/pom.xml b/modules/pds/pom.xml index 01ef5745e5077..c3bcec6d0fb21 100644 --- a/modules/pds/pom.xml +++ b/modules/pds/pom.xml @@ -47,12 +47,40 @@ ${project.version} + + commons-io + commons-io + ${common.io.version} + test + + + + org.apache.ignite + ignite-spring + ${project.version} + test + + log4j log4j test + + com.thoughtworks.xstream + xstream + ${xstream.version} + test + + + + org.apache.ignite + ignite-indexing + ${project.version} + test + + org.apache.ignite ignite-indexing @@ -69,6 +97,13 @@ test + + com.google.guava + guava + ${guava.version} + test + + org.javassist javassist From 9b7c4ac8f337e8af7b8ef1dfab7e1ee86357bc7c Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Tue, 2 May 2017 16:40:57 +0300 Subject: [PATCH 167/311] IGNITE-5134: Explicit cast to PageMemoryNoStoreImpl in IgniteCacheDatabaseSharedManager (cherry picked from commit 77a2c20) --- .../IgniteCacheDatabaseSharedManager.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 8e53df6314390..540b9eaa23c54 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -746,7 +746,11 @@ public void ensureFreeSpace(MemoryPolicy memPlc) throws IgniteCheckedException { * @param memMetrics {@link MemoryMetrics} object to collect memory usage metrics. * @return Memory policy instance. */ - private MemoryPolicy initMemory(MemoryConfiguration memCfg, MemoryPolicyConfiguration plcCfg, MemoryMetricsImpl memMetrics) { + private MemoryPolicy initMemory( + MemoryConfiguration memCfg, + MemoryPolicyConfiguration plcCfg, + MemoryMetricsImpl memMetrics + ) { File allocPath = buildAllocPath(plcCfg); DirectMemoryProvider memProvider = allocPath == null ? @@ -757,23 +761,27 @@ private MemoryPolicy initMemory(MemoryConfiguration memCfg, MemoryPolicyConfigur PageMemory pageMem = createPageMemory(memProvider, memCfg, plcCfg, memMetrics); - return new MemoryPolicy(pageMem, plcCfg, memMetrics, createPageEvictionTracker(plcCfg, - (PageMemoryNoStoreImpl)pageMem)); + return new MemoryPolicy(pageMem, plcCfg, memMetrics, createPageEvictionTracker(plcCfg, pageMem)); } /** * @param plc Memory Policy Configuration. * @param pageMem Page memory. */ - private PageEvictionTracker createPageEvictionTracker(MemoryPolicyConfiguration plc, PageMemoryNoStoreImpl pageMem) { + private PageEvictionTracker createPageEvictionTracker(MemoryPolicyConfiguration plc, PageMemory pageMem) { if (Boolean.getBoolean("override.fair.fifo.page.eviction.tracker")) - return new FairFifoPageEvictionTracker(pageMem, plc, cctx); + return new FairFifoPageEvictionTracker((PageMemoryNoStoreImpl)pageMem, plc, cctx); + + if (plc.getPageEvictionMode() == DataPageEvictionMode.DISABLED) + return new NoOpPageEvictionTracker(); + + PageMemoryNoStoreImpl pageMemoryNoStore = (PageMemoryNoStoreImpl)pageMem; switch (plc.getPageEvictionMode()) { case RANDOM_LRU: - return new RandomLruPageEvictionTracker(pageMem, plc, cctx); + return new RandomLruPageEvictionTracker(pageMemoryNoStore, plc, cctx); case RANDOM_2_LRU: - return new Random2LruPageEvictionTracker(pageMem, plc, cctx); + return new Random2LruPageEvictionTracker(pageMemoryNoStore, plc, cctx); default: return new NoOpPageEvictionTracker(); } From 5eea8adaf2f5d4d39e5a629dc3261988ab6669c0 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Tue, 16 May 2017 10:59:02 +0300 Subject: [PATCH 168/311] apache headers are added, RAT checks pass --- .../database/IgniteCacheSnapshotManager.java | 17 + .../cache/database/DbCheckpointListener.java | 17 + .../GridCacheDatabaseSharedManager.java | 17 + .../database/GridCacheOffheapManager.java | 17 + .../cache/database/file/FilePageStore.java | 17 + .../database/file/FilePageStoreManager.java | 17 + .../database/pagemem/EvictCandidate.java | 17 + .../database/pagemem/FullPageIdTable.java | 17 + .../cache/database/pagemem/PageMemoryEx.java | 17 + .../database/pagemem/PageMemoryImpl.java | 17 + .../wal/ByteBufferBackedDataInput.java | 17 + .../wal/ByteBufferBackedDataInputImpl.java | 17 + .../cache/database/wal/FileInput.java | 17 + .../cache/database/wal/FileWALPointer.java | 17 + .../wal/FileWriteAheadLogManager.java | 17 + .../cache/database/wal/RecordSerializer.java | 17 + .../database/wal/SegmentEofException.java | 17 + ...IgniteDataIntegrityViolationException.java | 17 + .../cache/database/wal/crc/PureJavaCrc32.java | 17 + .../database/wal/record/HeaderRecord.java | 17 + .../wal/serializer/RecordV1Serializer.java | 17 + ...istentStoreAtomicCacheRebalancingTest.java | 17 + ...tentStoreCacheRebalancingAbstractTest.java | 17 + ...earCachePutGetWithPersistenceSelfTest.java | 17 + ...sistentStoreContinuousRestartSelfTest.java | 17 + ...IgnitePersistentStoreDynamicCacheTest.java | 17 + ...ntStoreMultiNodePutGetRestartSelfTest.java | 17 + .../IgnitePersistentStorePageSizesTest.java | 17 + ...tStoreRecoveryAfterFileCorruptionTest.java | 17 + ...tStoreRemoveDuringRebalancingSelfTest.java | 17 + ...reSingleNodePutGetPersistenceSelfTest.java | 17 + ...WithIndexingPutGetPersistenceSelfTest.java | 17 + ...PersistentStoreTxCacheRebalancingTest.java | 17 + .../IgnitePersistentStoreWalTlbSelfTest.java | 17 + ...eEvictionDuringPartitionClearSelfTest.java | 17 + ...gniteDbMultiNodePutGetRestartSelfTest.java | 17 + .../db/IgniteDbPageEvictionSelfTest.java | 17 + .../IgniteDbWholeClusterRestartSelfTest.java | 17 + .../RebalancingOnNotStableTopologyTest.java | 17 + .../database/db/TransactionsHangTest.java | 17 + ...niteCachePageStoreIntegrationSelfTest.java | 17 + .../IgniteNoActualWalHistorySelfTest.java | 17 + ...IgniteWalDirectoriesConfigurationTest.java | 17 + .../IgniteWalHistoryReservationsSelfTest.java | 17 + .../db/file/IgniteWalRecoverySelfTest.java | 17 + .../IgniteWalRecoverySeveralRestartsTest.java | 17 + ...PageStoreCheckpointSimulationSelfTest.java | 17 + .../db/file/PageStoreEvictionSelfTest.java | 17 + .../file/WalRecoveryTxLogicalRecordsTest.java | 17 + .../db/wal/crc/IgniteDataIntegrityTests.java | 17 + ...usTreeReuseListPageMemoryImplSelfTest.java | 17 + ...lusTreeSelfTestPageMemoryImplSelfTest.java | 17 + .../database/pagemem/FullPageIdTableTest.java | 17 + ...MetadataStoragePageMemoryImplSelfTest.java | 17 + .../pagemem/NoOpPageStoreManager.java | 17 + .../database/pagemem/NoOpWALManager.java | 17 + .../pagemem/PageIdDistributionTest.java | 17 + .../pagemem/PageMemoryImplNoLoadSelfTest.java | 17 + .../pagemem/PageMemoryImplReloadSelfTest.java | 17 + .../database/pagemem/PageMemoryImplTest.java | 17 + .../GridChangeGlobalStateAbstractTest.java | 17 + .../GridChangeGlobalStateCacheTest.java | 17 + ...GridChangeGlobalStateDataStreamerTest.java | 17 + ...ridChangeGlobalStateDataStructureTest.java | 17 + .../GridChangeGlobalStateFailOverTest.java | 17 + .../GridChangeGlobalStateServiceTest.java | 17 + .../GridChangeGlobalStateTest.java | 17 + .../extended/GridActivateExtensionTest.java | 17 + .../GridActivationAtomicCacheSuit.java | 17 + .../GridActivationCacheAbstractTestSuit.java | 17 + .../GridActivationLocalAndNearCacheSuit.java | 17 + .../GridActivationPartitionedCacheSuit.java | 17 + .../GridActivationReplicatedCacheSuit.java | 17 + ...ebalancingWithPersistenceAbstractTest.java | 583 ++++++++++++++++++ ...alancingWithPersistenceAtomicSelfTest.java | 41 ++ ...eRebalancingWithPersistenceTxSelfTest.java | 61 ++ .../IgniteDbContinuousRestartSelfTest.java | 273 ++++++++ .../ignite/testsuites/IgnitePdsTestSuite.java | 17 + .../testsuites/IgnitePdsTestSuite2.java | 17 + .../testsuites/IgniteStandByClusterSuite.java | 17 + 80 files changed, 2250 insertions(+) create mode 100644 modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAbstractTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAtomicSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceTxSelfTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/IgniteDbContinuousRestartSelfTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java index c9cde551741bc..5b87cf764d3ef 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java @@ -1,3 +1,20 @@ +/* + * 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.database; import java.nio.ByteBuffer; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/DbCheckpointListener.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/DbCheckpointListener.java index b23743b062de0..7f66790d9f0fb 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/DbCheckpointListener.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/DbCheckpointListener.java @@ -1,3 +1,20 @@ +/* + * 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.database; import java.util.Map; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index ef318adab501d..87c8174802d7f 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -1,3 +1,20 @@ +/* + * 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.database; import java.io.File; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java index 4bbd4806e32b7..74fe886974a72 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java @@ -1,3 +1,20 @@ +/* + * 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.database; import java.util.Iterator; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java index 70278da270ead..2042358213d11 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java @@ -1,3 +1,20 @@ +/* + * 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.database.file; import java.io.File; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java index ae324629d92d0..af47c290c98d9 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java @@ -1,3 +1,20 @@ +/* + * 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.database.file; import java.io.BufferedInputStream; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/EvictCandidate.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/EvictCandidate.java index 96dbdb289704c..906871f57cab0 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/EvictCandidate.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/EvictCandidate.java @@ -1,3 +1,20 @@ +/* + * 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.database.pagemem; import org.apache.ignite.internal.pagemem.FullPageId; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java index ab2f86e511671..2690fff7338cd 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java @@ -1,3 +1,20 @@ +/* + * 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.database.pagemem; import org.apache.ignite.internal.mem.IgniteOutOfMemoryException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java index 94fd95840073a..e8ae554643ef8 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java @@ -1,3 +1,20 @@ +/* + * 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.database.pagemem; import java.nio.ByteBuffer; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java index 70a9677e301ab..af3418b98f7aa 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java @@ -1,3 +1,20 @@ +/* + * 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.database.pagemem; import java.io.Closeable; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInput.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInput.java index d8303759d1228..220f27b494bd1 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInput.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInput.java @@ -1,3 +1,20 @@ +/* + * 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.database.wal; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInputImpl.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInputImpl.java index 9d3f88388dfa3..d5fc9ed470df4 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInputImpl.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInputImpl.java @@ -1,3 +1,20 @@ +/* + * 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.database.wal; import java.io.IOException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java index b6c30d17bc4ac..735ffb77dcb86 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java @@ -1,3 +1,20 @@ +/* + * 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.database.wal; import java.io.EOFException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java index 329ccda2ba4cc..1102054b5f8f2 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java @@ -1,3 +1,20 @@ +/* + * 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.database.wal; import org.apache.ignite.internal.pagemem.wal.WALPointer; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java index 7b39369cf3bda..30b56d72dbf49 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -1,3 +1,20 @@ +/* + * 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.database.wal; import java.io.EOFException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java index 8afc1ed41850a..649f8985057e6 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java @@ -1,3 +1,20 @@ +/* + * 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.database.wal; import java.io.IOException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/SegmentEofException.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/SegmentEofException.java index 75456f7df5274..fcb9fe3ff9f01 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/SegmentEofException.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/SegmentEofException.java @@ -1,3 +1,20 @@ +/* + * 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.database.wal; import org.apache.ignite.IgniteCheckedException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/IgniteDataIntegrityViolationException.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/IgniteDataIntegrityViolationException.java index f0a64222ee1b9..7c3eaa27fdac3 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/IgniteDataIntegrityViolationException.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/IgniteDataIntegrityViolationException.java @@ -1,3 +1,20 @@ +/* + * 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.database.wal.crc; import org.apache.ignite.IgniteException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/PureJavaCrc32.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/PureJavaCrc32.java index 9775a7560f5dd..a947b2883102c 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/PureJavaCrc32.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/PureJavaCrc32.java @@ -1,3 +1,20 @@ +/* + * 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.database.wal.crc; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java index 951303b036d0a..f9e25838d0e1a 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java @@ -1,3 +1,20 @@ +/* + * 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.database.wal.record; import org.apache.ignite.internal.pagemem.wal.record.WALRecord; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java index f3bc5c8ba9ad0..25b69d8f44902 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java @@ -1,3 +1,20 @@ +/* + * 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.database.wal.serializer; import java.io.DataInput; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreAtomicCacheRebalancingTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreAtomicCacheRebalancingTest.java index 8f4dc7ef2c5e7..d5aa1e0643bd3 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreAtomicCacheRebalancingTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreAtomicCacheRebalancingTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import org.apache.ignite.cache.CacheAtomicityMode; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index 9c7ff0cdd8278..a767fe14f80c7 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import java.io.File; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java index 62e1dee02d69a..e002563bb58eb 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import org.apache.ignite.configuration.IgniteConfiguration; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java index af8f2467b7f2e..ff577e52259da 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import java.util.Map; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java index 2a622ed0e4b17..548c9d4e7837f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import org.apache.ignite.Ignite; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java index ed004b7049076..45d5490eb6550 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import java.io.File; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java index 31294ce894274..9fc349bbc5356 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import java.util.Random; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java index 3c35884642239..af3ebe6b6091b 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import java.io.IOException; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java index 8ec773b3700d3..24238169be659 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import java.io.File; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java index dbdb5f53be3f6..f3153ea6277aa 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import org.apache.ignite.configuration.IgniteConfiguration; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java index ee7548e589427..14d6a06806f48 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import org.apache.ignite.configuration.IgniteConfiguration; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java index f09d2ae6d9fa0..fb71b8a6fa33e 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import org.apache.ignite.cache.CacheAtomicityMode; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java index a03efe43892d5..afdcbc768f113 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database; import javax.cache.CacheException; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java index 70819b859bfe8..aac609711631a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db; import java.util.concurrent.Callable; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java index dfebd1fe2a01d..ca1d8273b205e 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db; import java.io.File; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java index 38624385f2f6e..697b26ac96fe4 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db; import java.io.Serializable; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java index b57a6898f7845..5765780d5337f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db; import java.util.ArrayList; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java index 4950906fee872..3cc02a2c20a5a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db; import java.util.concurrent.CountDownLatch; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java index 175dad0962c04..35ed575fab913 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db; import java.util.Random; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java index a24153e4134e2..47fe4a570a96f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db.file; import java.io.Serializable; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java index 9fff8c97de7af..c53766ca2d072 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db.file; import java.util.HashMap; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalDirectoriesConfigurationTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalDirectoriesConfigurationTest.java index 1050f6c029c97..5160eb44cf01d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalDirectoriesConfigurationTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalDirectoriesConfigurationTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db.file; import org.apache.ignite.configuration.IgniteConfiguration; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java index 555d3ba1c063d..af27ee11b3cd1 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db.file; import java.util.Map; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java index 0a656df3c85b9..9ac7323a439a1 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db.file; import java.io.File; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java index 109d6123bfc81..f38e9f6cfe6d6 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db.file; import java.util.Random; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java index 9cf97016acc07..7cc4122d7a4d0 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db.file; import java.nio.ByteBuffer; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java index 531b5fe6e8b4f..c1ec4ed629c73 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db.file; import java.util.ArrayList; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java index 7553896d85e6b..e3e35a750fdfb 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db.file; import java.io.File; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/crc/IgniteDataIntegrityTests.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/crc/IgniteDataIntegrityTests.java index b9b27c14f149e..c40a4ed8b1f14 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/crc/IgniteDataIntegrityTests.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/crc/IgniteDataIntegrityTests.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.db.wal.crc; import junit.framework.TestCase; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java index e5a40d8e27b9c..2b7823350cd7b 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.pagemem; import java.nio.ByteBuffer; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java index 061a4407cd934..d62980656c7f2 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.pagemem; import java.nio.ByteBuffer; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java index cae865e450f56..c710164bde599 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.pagemem; import java.util.HashMap; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java index a75031f598be8..270de23a6f184 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.pagemem; import java.io.File; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java index a17965522eaf7..9d5fe69b22dba 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.pagemem; import java.nio.ByteBuffer; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java index 5dfce5feb6dac..fec5b081e2b5e 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.pagemem; import org.apache.ignite.IgniteCheckedException; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java index 6d5841bafe0c9..e0fbcf415973c 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.pagemem; import java.io.FileOutputStream; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java index 912cd452a307e..843aede17efad 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.pagemem; import java.io.File; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplReloadSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplReloadSelfTest.java index 2d654eb4654f6..7b0819aa13990 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplReloadSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplReloadSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.pagemem; import java.io.File; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java index b3665ccc31a82..9b879e2673353 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.pagemem; import java.nio.ByteBuffer; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java index 05921790ac902..b2ca19a3b5553 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster; import java.util.ArrayList; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateCacheTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateCacheTest.java index 5152747732f7d..06ceeec0fa764 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateCacheTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateCacheTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster; import javax.cache.configuration.Configuration; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java index 28a167df2eeb3..20ddd8202a624 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster; import org.apache.ignite.Ignite; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java index d4e83d2ff1bf3..a33a02eefa880 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster; import java.util.concurrent.Callable; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java index 112bd73030c24..2fb5137cd3f1f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster; import java.util.concurrent.Callable; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java index 5923d717b75c8..f6fbc2cb5e501 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster; import java.util.Collection; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java index 7bbae98fe1949..b7dd082ae1dfd 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster; import java.util.Arrays; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java index 24710c155181e..8c9854ac09e7d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster.extended; import java.lang.reflect.Method; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationAtomicCacheSuit.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationAtomicCacheSuit.java index d490958f88cb8..397d8d0085a01 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationAtomicCacheSuit.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationAtomicCacheSuit.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster.extended; import junit.framework.TestSuite; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationCacheAbstractTestSuit.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationCacheAbstractTestSuit.java index 8d4ecfb17ea10..553546a313fc2 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationCacheAbstractTestSuit.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationCacheAbstractTestSuit.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster.extended; import java.io.IOException; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java index 71bcf2c09a589..b6ef49ceace31 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster.extended; import junit.framework.TestSuite; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationPartitionedCacheSuit.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationPartitionedCacheSuit.java index e34ee159ac8eb..fc437ada6b58f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationPartitionedCacheSuit.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationPartitionedCacheSuit.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster.extended; import junit.framework.TestSuite; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationReplicatedCacheSuit.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationReplicatedCacheSuit.java index 7636b67a5e2c7..6cdc87bd4c92a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationReplicatedCacheSuit.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationReplicatedCacheSuit.java @@ -1,3 +1,20 @@ +/* + * 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.cache.database.standbycluster.extended; import junit.framework.TestSuite; diff --git a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAbstractTest.java new file mode 100644 index 0000000000000..8aa8f81f6c110 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAbstractTest.java @@ -0,0 +1,583 @@ +/* + * 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.grid.internal.processors.cache.database; + +import java.io.File; +import java.io.Serializable; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.QueryIndex; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.events.CacheRebalancingEvent; +import org.apache.ignite.events.EventType; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.G; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiPredicate; +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 org.apache.ignite.transactions.Transaction; + +/** + * Test for rebalancing and persistence integration. + */ +public abstract class CacheRebalancingWithPersistenceAbstractTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + protected boolean explicitTx = false; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg1 = cacheConfiguration(null); + ccfg1.setBackups(1); + ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + + CacheConfiguration ccfg2 = cacheConfiguration("indexed"); + ccfg2.setBackups(1); + ccfg2.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + + QueryEntity queryEntity = new QueryEntity(Integer.class.getName(), TestValue.class.getName()); + + LinkedHashMap fields = new LinkedHashMap<>(); + + fields.put("v1", Integer.class.getName()); + fields.put("v2", Integer.class.getName()); + + queryEntity.setFields(fields); + + QueryIndex queryIndex = new QueryIndex("v1", true); + + queryEntity.setIndexes(Collections.singleton(queryIndex)); + + ccfg2.setQueryEntities(Collections.singleton(queryEntity)); + + cfg.setCacheConfiguration(ccfg1, ccfg2); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); + dbCfg.setPageSize(1024); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(100 * 1024 * 1024); + memPlcCfg.setSwapFilePath("db"); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return 20 * 60 * 1000; + } + + /** + * @param cacheName Cache name. + * @return Cache configuration. + */ + protected abstract CacheConfiguration cacheConfiguration(String cacheName); + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + G.stopAll(true); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + U.delete(new File(U.getIgniteHome(), "db")); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + G.stopAll(true); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + + U.delete(new File(U.getIgniteHome(), "db")); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + } + + /** + * Test that outdated partitions on restarted nodes are correctly replaced with newer versions. + * @throws Exception If fails. + */ + public void testRebalancingOnRestart() throws Exception { + Ignite ignite0 = startGrid(0); + + startGrid(1); + + IgniteEx ignite2 = startGrid(2); + + awaitPartitionMapExchange(); + + IgniteCache cache1 = ignite0.cache(null); + + for (int i = 0; i < 5000; i++) + cache1.put(i, i); + + ignite2.close(); + + awaitPartitionMapExchange(); + + ignite0.resetLostPartitions(Collections.singletonList(cache1.getName())); + + assert cache1.lostPartitions().isEmpty(); + + for (int i = 0; i < 5000; i++) + cache1.put(i, i * 2); + + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + + info(">>> Done puts..."); + + ignite2 = startGrid(2); + + awaitPartitionMapExchange(); + + IgniteCache cache3 = ignite2.cache(null); + + for (int i = 0; i < 100; i++) { + assertEquals(String.valueOf(i), (Integer)(i * 2), cache3.get(i)); + } + } + + /** + * Test that outdated partitions on restarted nodes are correctly replaced with newer versions. + * @throws Exception If fails. + */ + public void testRebalancingOnRestartAfterCheckpoint() throws Exception { + IgniteEx ignite0 = startGrid(0); + + IgniteEx ignite1 = startGrid(1); + + IgniteEx ignite2 = startGrid(2); + IgniteEx ignite3 = startGrid(3); + + ignite0.cache(null).rebalance().get(); + ignite1.cache(null).rebalance().get(); + ignite2.cache(null).rebalance().get(); + ignite3.cache(null).rebalance().get(); + + awaitPartitionMapExchange(); + + IgniteCache cache1 = ignite0.cache(null); + + for (int i = 0; i < 1000; i++) + cache1.put(i, i); + + ignite0.context().cache().context().database().waitForCheckpoint("test"); + ignite1.context().cache().context().database().waitForCheckpoint("test"); + + info("++++++++++ After checkpoint"); + + ignite2.close(); + ignite3.close(); + + awaitPartitionMapExchange(); + + ignite0.resetLostPartitions(Collections.singletonList(cache1.getName())); + + assert cache1.lostPartitions().isEmpty(); + + for (int i = 0; i < 1000; i++) + cache1.put(i, i * 2); + + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + info(">>>>>>>>>>>>>>>>>"); + + info(">>> Done puts..."); + + ignite2 = startGrid(2); + ignite3 = startGrid(3); + + ignite2.cache(null).rebalance().get(); + ignite3.cache(null).rebalance().get(); + + awaitPartitionMapExchange(); + + IgniteCache cache2 = ignite2.cache(null); + IgniteCache cache3 = ignite3.cache(null); + + for (int i = 0; i < 100; i++) { + assertEquals(String.valueOf(i), (Integer)(i * 2), cache2.get(i)); + assertEquals(String.valueOf(i), (Integer)(i * 2), cache3.get(i)); + } + } + + /** + * Test that up-to-date partitions aren't rebalanced after cluster restarts gracefully. + * @throws Exception If fails. + */ + public void testNoRebalancingOnRestartDeactivated() throws Exception { + fail(); + IgniteEx ignite1 = (IgniteEx) G.start(getConfiguration("test1")); + IgniteEx ignite2 = (IgniteEx) G.start(getConfiguration("test2")); + IgniteEx ignite3 = (IgniteEx) G.start(getConfiguration("test3")); + IgniteEx ignite4 = (IgniteEx) G.start(getConfiguration("test4")); + + awaitPartitionMapExchange(); + + IgniteCache cache1 = ignite1.cache(null); + + final Collection parts = new HashSet<>(); + + for (int i = 0; i < 100; i++) { + cache1.put(i, i); + parts.add(ignite1.affinity(null).partition(i)); + } + + ignite1.active(false); + + ignite1.close(); + ignite2.close(); + ignite3.close(); + ignite4.close(); + + final AtomicInteger eventCount = new AtomicInteger(); + + ignite1 = (IgniteEx) G.start(getConfiguration("test1")); + + cache1 = ignite1.cache(null); + + ignite1.active(false); + + ignite1.events().remoteListen(new IgniteBiPredicate() { + @Override public boolean apply(UUID uuid, CacheRebalancingEvent event) { + if (event.cacheName() == null && parts.contains(event.partition())) + eventCount.incrementAndGet(); + + return true; + } + }, null, EventType.EVT_CACHE_REBALANCE_PART_LOADED); + + ignite2 = (IgniteEx) G.start(getConfiguration("test2")); + ignite3 = (IgniteEx) G.start(getConfiguration("test3")); + ignite4 = (IgniteEx) G.start(getConfiguration("test4")); + + ignite1.active(true); + + awaitPartitionMapExchange(); + + assert eventCount.get() == 0 : eventCount.get(); + + IgniteCache cache2 = ignite2.cache(null); + IgniteCache cache3 = ignite3.cache(null); + IgniteCache cache4 = ignite4.cache(null); + + for (int i = 0; i < 100; i++) { + assert cache1.get(i).equals(i); + assert cache2.get(i).equals(i); + assert cache3.get(i).equals(i); + assert cache4.get(i).equals(i); + } + } + + /** + * Test that all data is correctly restored after non-graceful restart. + * @throws Exception If fails. + */ + public void testDataCorrectnessAfterRestart() throws Exception { + IgniteEx ignite1 = (IgniteEx) G.start(getConfiguration("test1")); + IgniteEx ignite2 = (IgniteEx) G.start(getConfiguration("test2")); + IgniteEx ignite3 = (IgniteEx) G.start(getConfiguration("test3")); + IgniteEx ignite4 = (IgniteEx) G.start(getConfiguration("test4")); + + awaitPartitionMapExchange(); + + IgniteCache cache1 = ignite1.cache(null); + + for (int i = 0; i < 100; i++) { + cache1.put(i, i); + } + + ignite1.close(); + ignite2.close(); + ignite3.close(); + ignite4.close(); + + ignite1 = (IgniteEx) G.start(getConfiguration("test1")); + ignite2 = (IgniteEx) G.start(getConfiguration("test2")); + ignite3 = (IgniteEx) G.start(getConfiguration("test3")); + ignite4 = (IgniteEx) G.start(getConfiguration("test4")); + + awaitPartitionMapExchange(); + + cache1 = ignite1.cache(null); + IgniteCache cache2 = ignite2.cache(null); + IgniteCache cache3 = ignite3.cache(null); + IgniteCache cache4 = ignite4.cache(null); + + for (int i = 0; i < 100; i++) { + assert cache1.get(i).equals(i); + assert cache2.get(i).equals(i); + assert cache3.get(i).equals(i); + assert cache4.get(i).equals(i); + } + } + + /** + * Test that partitions are marked as lost when all owners leave cluster, but recover after nodes rejoin. + * @throws Exception If fails. + */ + public void testPartitionLossAndRecover() throws Exception { + Ignite ignite1 = G.start(getConfiguration("test1")); + Ignite ignite2 = G.start(getConfiguration("test2")); + IgniteEx ignite3 = (IgniteEx) G.start(getConfiguration("test3")); + IgniteEx ignite4 = (IgniteEx) G.start(getConfiguration("test4")); + + awaitPartitionMapExchange(); + + IgniteCache cache1 = ignite1.cache(null); + + for (int i = 0; i < 100; i++) { + cache1.put(i, i); + } + + ignite1.active(false); + + ignite3.close(); + ignite4.close(); + + ignite1.active(true); + + awaitPartitionMapExchange(); + + assert !cache1.lostPartitions().isEmpty(); + + ignite3 = (IgniteEx) G.start(getConfiguration("test3")); + ignite4 = (IgniteEx) G.start(getConfiguration("test4")); + + awaitPartitionMapExchange(); + + ignite1.resetLostPartitions(Collections.singletonList(cache1.getName())); + + IgniteCache cache2 = ignite2.cache(null); + IgniteCache cache3 = ignite3.cache(null); + IgniteCache cache4 = ignite4.cache(null); + + for (int i = 0; i < 100; i++) { + assert cache1.get(i).equals(i); + assert cache2.get(i).equals(i); + assert cache3.get(i).equals(i); + assert cache4.get(i).equals(i); + } + } + + /** + * @throws Exception If failed. + */ + public void testTopologyChangesWithConstantLoad() throws Exception { + final int entriesCount = 10_000; + int maxNodesCount = 4; + int topChanges = 20; + final String cacheName = "indexed"; + + final AtomicBoolean stop = new AtomicBoolean(); + + final ConcurrentMap map = new ConcurrentHashMap<>(); + + Ignite ignite = startGrid(0); + + IgniteCache cache = ignite.cache(cacheName); + + for (int i = 0; i < entriesCount; i++) { + cache.put(i, new TestValue(i, i)); + map.put(i, new TestValue(i, i)); + } + + final AtomicInteger nodesCount = new AtomicInteger(); + + IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable() { + @Override public Void call() throws Exception { + while (true) { + if (stop.get()) + return null; + + int k = ThreadLocalRandom.current().nextInt(entriesCount); + int v1 = ThreadLocalRandom.current().nextInt(); + int v2 = ThreadLocalRandom.current().nextInt(); + + int n = nodesCount.get(); + + if (n <= 0) + continue; + + Ignite ignite; + + try { + ignite = grid(ThreadLocalRandom.current().nextInt(n)); + } + catch (Exception e) { + continue; + } + + if (ignite == null) + continue; + + Transaction tx = null; + boolean success = true; + + if (explicitTx) { + tx = ignite.transactions().txStart(); + } + + try { + ignite.cache(cacheName).put(k, new TestValue(v1, v2)); + } + catch (Exception e) { + success = false; + } + finally { + if (tx != null) { + try { + tx.commit(); + } + catch (Exception e) { + success = false; + } + } + } + + if (success) + map.put(k, new TestValue(v1, v2)); + } + } + }, 1, "load-runner"); + + for (int i = 0; i < topChanges; i++) { + U.sleep(3_000); + + boolean add; + if (nodesCount.get() <= maxNodesCount / 2) + add = true; + else if (nodesCount.get() > maxNodesCount) + add = false; + else + add = ThreadLocalRandom.current().nextBoolean(); + + if (add) + startGrid(nodesCount.incrementAndGet()); + else + stopGrid(nodesCount.getAndDecrement()); + + awaitPartitionMapExchange(); + + cache.rebalance().get(); + } + + stop.set(true); + + fut.get(); + + awaitPartitionMapExchange(); + + for (Map.Entry entry : map.entrySet()) { + assertEquals(Integer.toString(entry.getKey()), entry.getValue(), cache.get(entry.getKey())); + } + } + + private static class TestValue implements Serializable { + private final int v1; + private final int v2; + + private TestValue(int v1, int v2) { + this.v1 = v1; + this.v2 = v2; + } + + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + TestValue value = (TestValue)o; + + if (v1 != value.v1) + return false; + return v2 == value.v2; + + } + + @Override public int hashCode() { + int result = v1; + result = 31 * result + v2; + return result; + } + + @Override public String toString() { + return "TestValue{" + + "v1=" + v1 + + ", v2=" + v2 + + '}'; + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAtomicSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAtomicSelfTest.java new file mode 100644 index 0000000000000..ef58c727ea211 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAtomicSelfTest.java @@ -0,0 +1,41 @@ +/* + * 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.grid.internal.processors.cache.database; + +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.configuration.CacheConfiguration; + +/** + * + */ +public class CacheRebalancingWithPersistenceAtomicSelfTest extends CacheRebalancingWithPersistenceAbstractTest { + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String cacheName) { + CacheConfiguration ccfg = new CacheConfiguration(cacheName); + + ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setBackups(1); + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + + return ccfg; + } + +} diff --git a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceTxSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceTxSelfTest.java new file mode 100644 index 0000000000000..c91e9e6bcef9e --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceTxSelfTest.java @@ -0,0 +1,61 @@ +/* + * 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.grid.internal.processors.cache.database; + +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.CacheConfiguration; + +/** + * + */ +public class CacheRebalancingWithPersistenceTxSelfTest extends CacheRebalancingWithPersistenceAbstractTest { + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String cacheName) { + CacheConfiguration ccfg = new CacheConfiguration(cacheName); + + ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setRebalanceMode(CacheRebalanceMode.SYNC); + ccfg.setBackups(1); + ccfg.setRebalanceDelay(10_000); + ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + + return ccfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + explicitTx = false; + } + + /** + * @throws Exception If failed. + */ + public void testTopologyChangesWithConstantLoadExplicitTx() throws Exception { + explicitTx = true; + + testTopologyChangesWithConstantLoad(); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/IgniteDbContinuousRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/IgniteDbContinuousRestartSelfTest.java new file mode 100644 index 0000000000000..1bf875003b9d6 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/IgniteDbContinuousRestartSelfTest.java @@ -0,0 +1,273 @@ +/* + * 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.grid.internal.processors.cache.database; + +import java.util.Map; +import java.util.Random; +import java.util.TreeMap; +import java.util.concurrent.Callable; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteDbContinuousRestartSelfTest extends GridCommonAbstractTest { + /** */ + private static final int GRID_CNT = 4; + + /** */ + private static final int ENTRIES_COUNT = 10_000; + + /** */ + public static final String CACHE_NAME = "cache1"; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setSize(400 * 1024 * 1024); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + CacheConfiguration ccfg1 = new CacheConfiguration(); + + ccfg1.setName(CACHE_NAME); + ccfg1.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + ccfg1.setAffinity(new RendezvousAffinityFunction(false, 128)); + ccfg1.setBackups(2); + + cfg.setCacheConfiguration(ccfg1); + + PersistenceConfiguration pdsCfg = new PersistenceConfiguration(); + + cfg.setPersistenceConfiguration(pdsCfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + + stopAllGrids(); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + System.clearProperty(IgniteSystemProperties.IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + } + + /** + * @throws IgniteCheckedException If failed. + */ + private void deleteWorkFiles() throws IgniteCheckedException { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "snapshot", false)); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_500_1_1() throws Exception { + checkRebalancingDuringLoad(1000, 500, 1, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_500_1_1() throws Exception { + checkRebalancingDuringLoad(8000, 500, 1, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_20000_1_1() throws Exception { + checkRebalancingDuringLoad(1000, 20000, 1, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_8000_1_1() throws Exception { + checkRebalancingDuringLoad(8000, 8000, 1, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_500_8_1() throws Exception { + checkRebalancingDuringLoad(1000, 500, 8, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_500_8_1() throws Exception { + checkRebalancingDuringLoad(8000, 500, 8, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_20000_8_1() throws Exception { + checkRebalancingDuringLoad(1000, 20000, 8, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_8000_8_1() throws Exception { + checkRebalancingDuringLoad(8000, 8000, 8, 1); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_500_8_16() throws Exception { + checkRebalancingDuringLoad(1000, 500, 8, 16); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_500_8_16() throws Exception { + checkRebalancingDuringLoad(8000, 500, 8, 16); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_1000_20000_8_16() throws Exception { + checkRebalancingDuringLoad(1000, 20000, 8, 16); + } + + /** + * @throws Exception if failed. + */ + public void testRebalancingDuringLoad_8000_8000_8_16() throws Exception { + checkRebalancingDuringLoad(8000, 8000, 8, 16); + } + + /** + * @throws Exception if failed. + */ + private void checkRebalancingDuringLoad( + int restartDelay, + int checkpointDelay, + int threads, + final int batch + ) throws Exception { + System.setProperty(IgniteSystemProperties.IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY, + String.valueOf(checkpointDelay)); + + startGrids(GRID_CNT); + + final Ignite load = ignite(0); + + try (IgniteDataStreamer s = load.dataStreamer(CACHE_NAME)) { + s.allowOverwrite(true); + + for (int i = 0; i < ENTRIES_COUNT; i++) + s.addData(i, i); + } + + final AtomicBoolean done = new AtomicBoolean(false); + + IgniteInternalFuture busyFut = GridTestUtils.runMultiThreadedAsync(new Callable() { + /** {@inheritDoc} */ + @Override + public Object call() throws Exception { + IgniteCache cache = load.cache(CACHE_NAME); + Random rnd = ThreadLocalRandom.current(); + + while (!done.get()) { + Map map = new TreeMap<>(); + + for (int i = 0; i < batch; i++) + map.put(rnd.nextInt(ENTRIES_COUNT), rnd.nextInt()); + + cache.putAll(map); + } + + return null; + } + }, threads, "updater"); + + long end = System.currentTimeMillis() + 90_000; + + Random rnd = ThreadLocalRandom.current(); + + while (System.currentTimeMillis() < end) { + int idx = rnd.nextInt(GRID_CNT - 1) + 1; + + stopGrid(idx); + + U.sleep(restartDelay); + + startGrid(idx); + + U.sleep(restartDelay); + } + + done.set(true); + + busyFut.get(); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java index ab85f4a02ae19..dd82dfa0eea38 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java @@ -1,3 +1,20 @@ +/* + * 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.testsuites; import junit.framework.TestSuite; diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java index 267dbe567a851..9b1d9267ac3c2 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java @@ -1,3 +1,20 @@ +/* + * 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.testsuites; import junit.framework.TestSuite; diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java index 17b667d44aa85..2d0006158621b 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java @@ -1,3 +1,20 @@ +/* + * 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.testsuites; import junit.framework.TestSuite; From 601722a3937bbc4d1305436d36739519ca645f5e Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Tue, 16 May 2017 16:26:50 +0300 Subject: [PATCH 169/311] Fixed deadlock (lockEntires sometimes acquires topology.writeLock). --- .../cache/distributed/dht/atomic/GridDhtAtomicCache.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index d287e3b063817..52968bd88017e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -1717,7 +1717,7 @@ private void updateAllAsyncInternal0( try { // If batch store update is enabled, we need to lock all entries. // First, need to acquire locks on cache entries, then check filter. - List locked = null; + List locked = lockEntries(req, req.topologyVersion());; Collection> deleted = null; @@ -1740,8 +1740,6 @@ private void updateAllAsyncInternal0( if (req.topologyLocked() || !needRemap(req.topologyVersion(), top.topologyVersion())) { ctx.shared().database().ensureFreeSpace(ctx.memoryPolicy()); - locked = lockEntries(req, req.topologyVersion()); - boolean hasNear = ctx.discovery().cacheNearNode(node, name()); // Assign next version for update inside entries lock. From eb80b4096a1705c7e2313ab006322f93fc49b0f4 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Tue, 16 May 2017 17:06:09 +0300 Subject: [PATCH 170/311] ignite-5068 : Minors. --- .../dht/GridDhtPartitionTopologyImpl.java | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) 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 fe7f9d7488dd9..e9c535f2f4302 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 @@ -959,7 +959,8 @@ else if (loc != null && state == RENTING && cctx.allowFastEviction()) List nodes = null; if (!topVer.equals(diffFromAffinityVer)) { - System.out.println("??? node2part [topVer=" + topVer + ", diffVer=" + diffFromAffinityVer + "]"); + U.warn(log, "Requested affinity version isn't equal to calculated diff, full iteration over " + + "node2part map required [topVer=" + topVer + ", diffVer=" + diffFromAffinityVer + ']'); nodes = new ArrayList<>(); @@ -970,8 +971,8 @@ else if (loc != null && state == RENTING && cctx.allowFastEviction()) ClusterNode n = cctx.discovery().node(entry.getKey()); - if (n != null && state != null && (state == MOVING || state == OWNING || state == RENTING) && !nodes.contains(n) - && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) { + if (n != null && state != null && (state == MOVING || state == OWNING || state == RENTING) + && !nodes.contains(n) && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) { nodes.add(n); } @@ -1206,8 +1207,6 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) node2part = partMap; - int diffFromAffinitySize = 0; - AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); if (diffFromAffinityVer.compareTo(affVer) <= 0) { @@ -1225,14 +1224,10 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) if (diffIds == null) diffFromAffinity.put(p, diffIds = U.newHashSet(3)); - if (diffIds.add(e.getKey())) { - diffFromAffinitySize++; - } + diffIds.add(e.getKey()); } else { if (diffIds != null && diffIds.remove(e.getKey())) { - diffFromAffinitySize--; - if (diffIds.isEmpty()) diffFromAffinity.remove(p); } @@ -1241,9 +1236,6 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) } diffFromAffinityVer = affVer; - - if (diffFromAffinitySize > 0) - U.error(log, "??? F diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); } boolean changed = false; @@ -1385,8 +1377,6 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) if (affVer.compareTo(diffFromAffinityVer) >= 0) { AffinityAssignment affAssignment = cctx.affinity().assignment(affVer); - int diffFromAffinitySize = 0; - // Add new mappings. for (Map.Entry e : parts.entrySet()) { int p = e.getKey(); @@ -1398,18 +1388,13 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) if (diffIds == null) diffFromAffinity.put(p, diffIds = U.newHashSet(3)); - if (diffIds.add(parts.nodeId())) { + if (diffIds.add(parts.nodeId())) changed = true; - - diffFromAffinitySize++; - } } else { if (diffIds != null && diffIds.remove(parts.nodeId())) { changed = true; - diffFromAffinitySize--; - if (diffIds.isEmpty()) diffFromAffinity.remove(p); } @@ -1425,8 +1410,6 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) if (ids != null && ids.remove(parts.nodeId())) { changed = true; - diffFromAffinitySize--; - if (ids.isEmpty()) diffFromAffinity.remove(p); } @@ -1434,9 +1417,6 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) } diffFromAffinityVer = affVer; - - if (diffFromAffinitySize > 0) - U.error(log, "??? S diffFromAffinitySize=" + diffFromAffinitySize + " [exchId=" + exchId + ",cacheId=" + cctx.cacheId() + ",cacheName=" + cctx.name() + "]"); } if (!affVer.equals(AffinityTopologyVersion.NONE) && affVer.compareTo(topVer) >= 0) { @@ -1467,7 +1447,7 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) lock.writeLock().lock(); try { - if (assignment.topologyVersion().compareTo(diffFromAffinityVer) >= 0) + if (assignment.topologyVersion().compareTo(diffFromAffinityVer) > 0) rebuildDiff(assignment); } finally { From 57efac0331bfa13a09ec1fcc979b6943014245df Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 16 May 2017 17:22:53 +0300 Subject: [PATCH 171/311] ignite-gg-12163 reduced memory requirements for test --- .../apache/ignite/cache/database/db/TransactionsHangTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java index 175dad0962c04..d3d3952125129 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java @@ -60,7 +60,7 @@ public class TransactionsHangTest extends GridCommonAbstractTest { public static final int DURATION = 180; /** Maximum count of inserted keys. */ - public static final int MAX_KEY_COUNT = 1_000_000; + public static final int MAX_KEY_COUNT = 500_000; /** Checkpoint frequency. */ public static final long CHECKPOINT_FREQUENCY = 20_000; @@ -107,6 +107,7 @@ public class TransactionsHangTest extends GridCommonAbstractTest { PersistenceConfiguration pCfg = new PersistenceConfiguration(); + pCfg.setWalHistorySize(1); pCfg.setCheckpointFrequency(CHECKPOINT_FREQUENCY); cfg.setPersistenceConfiguration(pCfg); From 3cf4c7b0175eb3556957df8865d049b14065bd49 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Tue, 16 May 2017 17:57:58 +0300 Subject: [PATCH 172/311] ignite-5068 : Handling of lost partitions. --- .../dht/GridClientPartitionTopology.java | 2 +- .../dht/GridDhtPartitionTopologyImpl.java | 99 +++++++------------ 2 files changed, 38 insertions(+), 63 deletions(-) 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 d55dda733e6a8..709224276bd0c 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 @@ -756,7 +756,7 @@ public long lastUpdateSequence() { /** {@inheritDoc} */ @Override public void onExchangeDone(AffinityAssignment assignment) { - // TODO + // no-op } /** {@inheritDoc} */ 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 e9c535f2f4302..58fb14ccec391 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 @@ -1553,17 +1553,13 @@ private void rebuildDiff(AffinityAssignment affAssignment) { } // Update map for remote node. else if (plc != PartitionLossPolicy.IGNORE) { - // TODO -// Set nodeIds = part2node.get(part); -// -// if (nodeIds != null) { -// for (UUID nodeId : nodeIds) { -// GridDhtPartitionMap nodeMap = node2part.get(nodeId); -// -// if (nodeMap.get(part) != EVICTED) -// nodeMap.put(part, LOST); -// } -// } + for (Map.Entry e : node2part.entrySet()) { + if (e.getKey().equals(cctx.localNodeId())) + continue; + + if (e.getValue().get(part) != EVICTED) + e.getValue().put(part, LOST); + } } if (cctx.events().isRecordable(EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST)) @@ -1584,57 +1580,36 @@ else if (plc != PartitionLossPolicy.IGNORE) { /** {@inheritDoc} */ @Override public void resetLostPartitions() { - // TODO - -// lock.writeLock().lock(); -// -// try { -// int parts = cctx.affinity().partitions(); -// long updSeq = updateSeq.incrementAndGet(); -// -// for (int part = 0; part < parts; part++) { -// Set nodeIds = part2node.get(part); -// -// if (nodeIds != null) { -// boolean lost = false; -// -// for (UUID node : nodeIds) { -// GridDhtPartitionMap map = node2part.get(node); -// -// if (map.get(part) == LOST) { -// lost = true; -// -// break; -// } -// } -// -// if (lost) { -// GridDhtLocalPartition locPart = localPartition(part, topVer, false); -// -// if (locPart != null) { -// boolean marked = locPart.own(); -// -// if (marked) -// updateLocal(locPart.id(), locPart.state(), updSeq); -// } -// -// for (UUID nodeId : nodeIds) { -// GridDhtPartitionMap nodeMap = node2part.get(nodeId); -// -// if (nodeMap.get(part) == LOST) -// nodeMap.put(part, OWNING); -// } -// } -// } -// } -// -// checkEvictions(updSeq, cctx.affinity().assignments(topVer)); -// -// cctx.needsRecovery(false); -// } -// finally { -// lock.writeLock().unlock(); -// } + lock.writeLock().lock(); + + try { + long updSeq = updateSeq.incrementAndGet(); + + for (Map.Entry e : node2part.entrySet()) { + for (Map.Entry e0 : e.getValue().entrySet()) { + if (e0.getValue() != LOST) + continue; + + e0.setValue(OWNING); + + GridDhtLocalPartition locPart = localPartition(e0.getKey(), topVer, false); + + if (locPart != null && locPart.state() == LOST) { + boolean marked = locPart.own(); + + if (marked) + updateLocal(locPart.id(), locPart.state(), updSeq); + } + } + } + + checkEvictions(updSeq, cctx.affinity().assignments(topVer)); + + cctx.needsRecovery(false); + } + finally { + lock.writeLock().unlock(); + } } /** {@inheritDoc} */ From 99acdb5605192d473fd5f0711090887054892020 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 16 May 2017 18:09:06 +0300 Subject: [PATCH 173/311] ignite-gg-12163 Fixed duplicates in FullPageIdTable. --- .../processors/cache/database/pagemem/FullPageIdTable.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java index 2690fff7338cd..01d7bce56c9fc 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java @@ -261,7 +261,12 @@ private int putKey(int cacheId, long pageId, int tag) { do { res = testKeyAt(index, cacheId, pageId, tag); - if (res == EMPTY || res == OUTDATED) { + if (res == OUTDATED) { + foundIndex = index; + + break; + } + else if (res == EMPTY) { if (foundIndex == -1) foundIndex = index; From 6d3821b92e252ba834da793295400eb8bf6d0813 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Wed, 17 May 2017 11:35:47 +0300 Subject: [PATCH 174/311] IGNITE-GG-12163 fixes around PartitionDestroy WAL record functionality --- .../pagemem/wal/record/delta/MetaPageInitRecord.java | 5 +---- .../cache/database/GridCacheDatabaseSharedManager.java | 7 +------ .../processors/cache/database/GridCacheOffheapManager.java | 3 +++ .../cache/database/wal/serializer/RecordV1Serializer.java | 2 +- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java index 3d351a26c2371..5c99d54f9baf8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java @@ -21,7 +21,6 @@ import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionMetaIO; /** * @@ -76,9 +75,7 @@ public int ioType() { /** {@inheritDoc} */ @Override public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException { - PageMetaIO io = ioType == PageIO.T_META ? - PageMetaIO.VERSIONS.forPage(pageAddr) : - PagePartitionMetaIO.VERSIONS.forPage(pageAddr); + PageMetaIO io = PageMetaIO.getPageIO(ioType, ioVer); io.initNewPage(pageAddr, newPageId, pageMem.pageSize()); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 87c8174802d7f..73d60722a1ca5 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -74,14 +74,12 @@ import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.mem.DirectMemoryProvider; import org.apache.ignite.internal.pagemem.FullPageId; -import org.apache.ignite.internal.pagemem.PageIdAllocator; import org.apache.ignite.internal.pagemem.PageIdUtils; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; import org.apache.ignite.internal.pagemem.store.PageStore; -import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; import org.apache.ignite.internal.pagemem.wal.StorageException; import org.apache.ignite.internal.pagemem.wal.WALIterator; import org.apache.ignite.internal.pagemem.wal.WALPointer; @@ -92,7 +90,6 @@ import org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord; import org.apache.ignite.internal.pagemem.wal.record.PageSnapshot; import org.apache.ignite.internal.pagemem.wal.record.WALRecord; -import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateLastAllocatedIndex; import org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord; @@ -104,7 +101,6 @@ import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionMetaIO; import org.apache.ignite.internal.processors.cache.database.wal.FileWALPointer; import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; @@ -134,7 +130,6 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY; import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC; import static org.apache.ignite.IgniteSystemProperties.IGNITE_WAL_REBALANCE_THRESHOLD; -import static org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler.isWalDeltaRecordNeeded; /** * @@ -1307,7 +1302,7 @@ else if (!F.eq(cpRec.checkpointId(), status.cpEndId)) final int cId = destroyRec.cacheId(); final int pId = destroyRec.partitionId(); - PageMemoryEx pageMem = (PageMemoryEx)cctx.cacheContext(cId).memoryPolicy().pageMemory(); + PageMemoryEx pageMem = getPageMemoryForCacheId(cId); pageMem.clearAsync(new P3() { @Override public boolean apply(Integer cacheId, Long pageId, Integer tag) { diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java index 74fe886974a72..5253818b6db8b 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java @@ -37,6 +37,7 @@ import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateNextSnapshotId; import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord; +import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.GridCacheContext; @@ -314,6 +315,8 @@ private static void addPartition( int tag = pageMemory.invalidate(cctx.cacheId(), p); + cctx.shared().wal().log(new PartitionDestroyRecord(cctx.cacheId(), p)); + cctx.shared().pageStore().onPartitionDestroyed(cctx.cacheId(), p, tag); } finally { diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java index 25b69d8f44902..f67f617ef68a9 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java @@ -171,7 +171,7 @@ public RecordV1Serializer(GridCacheSharedContext cctx) { PartitionDestroyRecord partDestroy = (PartitionDestroyRecord)record; buf.putInt(partDestroy.cacheId()); - buf.putInt(partDestroy.cacheId()); + buf.putInt(partDestroy.partitionId()); break; From 2a5a410316acf04934152bf267b199218ea6763b Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Wed, 17 May 2017 12:02:33 +0300 Subject: [PATCH 175/311] IGNITE-GG-12163 system property name fixed in test --- .../database/db/file/IgniteWalRecoverySelfTest.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java index 9ac7323a439a1..fd3ed7512861a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java @@ -60,6 +60,7 @@ import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.PA; import org.apache.ignite.internal.util.typedef.PAX; @@ -77,6 +78,8 @@ import org.junit.Assert; import sun.nio.ch.DirectBuffer; +import static org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE; + /** * */ @@ -406,7 +409,7 @@ public void testWalRolloverMultithreadedLogOnly() throws Exception { */ public void testHugeCheckpointRecord() throws Exception { try { - System.setProperty("GRIDGAIN_DB_WAL_MODE", "LOG_ONLY"); + System.setProperty(IGNITE_PDS_WAL_MODE, "LOG_ONLY"); final IgniteEx ignite = startGrid(1); @@ -446,7 +449,7 @@ public void testHugeCheckpointRecord() throws Exception { fut.get(); } finally { - System.clearProperty("GRIDGAIN_DB_WAL_MODE"); + System.clearProperty(IGNITE_PDS_WAL_MODE); stopAllGrids(); } @@ -457,7 +460,7 @@ public void testHugeCheckpointRecord() throws Exception { */ private void checkWalRolloverMultithreaded(boolean logOnly) throws Exception { if (logOnly) - System.setProperty("GRIDGAIN_DB_WAL_MODE", "LOG_ONLY"); + System.setProperty(IGNITE_PDS_WAL_MODE, "LOG_ONLY"); walSegmentSize = 2 * 1024 * 1024; @@ -480,7 +483,7 @@ private void checkWalRolloverMultithreaded(boolean logOnly) throws Exception { }, 16, "put-thread"); } finally { - System.clearProperty("GRIDGAIN_DB_WAL_MODE"); + System.clearProperty(IGNITE_PDS_WAL_MODE); stopAllGrids(); } From c4a12b048f62ab2a845c7fde49a2ed7f135e17e3 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 17 May 2017 12:14:58 +0300 Subject: [PATCH 176/311] ignite-12163 removed duplicate tests --- ...ebalancingWithPersistenceAbstractTest.java | 583 ------------------ ...alancingWithPersistenceAtomicSelfTest.java | 41 -- ...eRebalancingWithPersistenceTxSelfTest.java | 61 -- .../IgniteDbContinuousRestartSelfTest.java | 273 -------- 4 files changed, 958 deletions(-) delete mode 100644 modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAbstractTest.java delete mode 100644 modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAtomicSelfTest.java delete mode 100644 modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceTxSelfTest.java delete mode 100644 modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/IgniteDbContinuousRestartSelfTest.java diff --git a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAbstractTest.java deleted file mode 100644 index 8aa8f81f6c110..0000000000000 --- a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAbstractTest.java +++ /dev/null @@ -1,583 +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.grid.internal.processors.cache.database; - -import java.io.File; -import java.io.Serializable; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import org.apache.ignite.Ignite; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.cache.CacheWriteSynchronizationMode; -import org.apache.ignite.cache.QueryEntity; -import org.apache.ignite.cache.QueryIndex; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.configuration.MemoryConfiguration; -import org.apache.ignite.configuration.MemoryPolicyConfiguration; -import org.apache.ignite.configuration.PersistenceConfiguration; -import org.apache.ignite.events.CacheRebalancingEvent; -import org.apache.ignite.events.EventType; -import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; -import org.apache.ignite.internal.util.typedef.G; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.lang.IgniteBiPredicate; -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 org.apache.ignite.transactions.Transaction; - -/** - * Test for rebalancing and persistence integration. - */ -public abstract class CacheRebalancingWithPersistenceAbstractTest extends GridCommonAbstractTest { - /** */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - - /** */ - protected boolean explicitTx = false; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - CacheConfiguration ccfg1 = cacheConfiguration(null); - ccfg1.setBackups(1); - ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); - - CacheConfiguration ccfg2 = cacheConfiguration("indexed"); - ccfg2.setBackups(1); - ccfg2.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); - - QueryEntity queryEntity = new QueryEntity(Integer.class.getName(), TestValue.class.getName()); - - LinkedHashMap fields = new LinkedHashMap<>(); - - fields.put("v1", Integer.class.getName()); - fields.put("v2", Integer.class.getName()); - - queryEntity.setFields(fields); - - QueryIndex queryIndex = new QueryIndex("v1", true); - - queryEntity.setIndexes(Collections.singleton(queryIndex)); - - ccfg2.setQueryEntities(Collections.singleton(queryEntity)); - - cfg.setCacheConfiguration(ccfg1, ccfg2); - - MemoryConfiguration dbCfg = new MemoryConfiguration(); - - dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); - dbCfg.setPageSize(1024); - - MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); - - memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(100 * 1024 * 1024); - memPlcCfg.setSwapFilePath("db"); - - dbCfg.setMemoryPolicies(memPlcCfg); - dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); - - cfg.setMemoryConfiguration(dbCfg); - - cfg.setPersistenceConfiguration(new PersistenceConfiguration()); - - TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); - - discoSpi.setIpFinder(IP_FINDER); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected long getTestTimeout() { - return 20 * 60 * 1000; - } - - /** - * @param cacheName Cache name. - * @return Cache configuration. - */ - protected abstract CacheConfiguration cacheConfiguration(String cacheName); - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - G.stopAll(true); - - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - - U.delete(new File(U.getIgniteHome(), "db")); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - G.stopAll(true); - - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - - U.delete(new File(U.getIgniteHome(), "db")); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - } - - /** - * Test that outdated partitions on restarted nodes are correctly replaced with newer versions. - * @throws Exception If fails. - */ - public void testRebalancingOnRestart() throws Exception { - Ignite ignite0 = startGrid(0); - - startGrid(1); - - IgniteEx ignite2 = startGrid(2); - - awaitPartitionMapExchange(); - - IgniteCache cache1 = ignite0.cache(null); - - for (int i = 0; i < 5000; i++) - cache1.put(i, i); - - ignite2.close(); - - awaitPartitionMapExchange(); - - ignite0.resetLostPartitions(Collections.singletonList(cache1.getName())); - - assert cache1.lostPartitions().isEmpty(); - - for (int i = 0; i < 5000; i++) - cache1.put(i, i * 2); - - info(">>>>>>>>>>>>>>>>>"); - info(">>>>>>>>>>>>>>>>>"); - info(">>>>>>>>>>>>>>>>>"); - info(">>>>>>>>>>>>>>>>>"); - info(">>>>>>>>>>>>>>>>>"); - info(">>>>>>>>>>>>>>>>>"); - - info(">>> Done puts..."); - - ignite2 = startGrid(2); - - awaitPartitionMapExchange(); - - IgniteCache cache3 = ignite2.cache(null); - - for (int i = 0; i < 100; i++) { - assertEquals(String.valueOf(i), (Integer)(i * 2), cache3.get(i)); - } - } - - /** - * Test that outdated partitions on restarted nodes are correctly replaced with newer versions. - * @throws Exception If fails. - */ - public void testRebalancingOnRestartAfterCheckpoint() throws Exception { - IgniteEx ignite0 = startGrid(0); - - IgniteEx ignite1 = startGrid(1); - - IgniteEx ignite2 = startGrid(2); - IgniteEx ignite3 = startGrid(3); - - ignite0.cache(null).rebalance().get(); - ignite1.cache(null).rebalance().get(); - ignite2.cache(null).rebalance().get(); - ignite3.cache(null).rebalance().get(); - - awaitPartitionMapExchange(); - - IgniteCache cache1 = ignite0.cache(null); - - for (int i = 0; i < 1000; i++) - cache1.put(i, i); - - ignite0.context().cache().context().database().waitForCheckpoint("test"); - ignite1.context().cache().context().database().waitForCheckpoint("test"); - - info("++++++++++ After checkpoint"); - - ignite2.close(); - ignite3.close(); - - awaitPartitionMapExchange(); - - ignite0.resetLostPartitions(Collections.singletonList(cache1.getName())); - - assert cache1.lostPartitions().isEmpty(); - - for (int i = 0; i < 1000; i++) - cache1.put(i, i * 2); - - info(">>>>>>>>>>>>>>>>>"); - info(">>>>>>>>>>>>>>>>>"); - info(">>>>>>>>>>>>>>>>>"); - info(">>>>>>>>>>>>>>>>>"); - info(">>>>>>>>>>>>>>>>>"); - info(">>>>>>>>>>>>>>>>>"); - - info(">>> Done puts..."); - - ignite2 = startGrid(2); - ignite3 = startGrid(3); - - ignite2.cache(null).rebalance().get(); - ignite3.cache(null).rebalance().get(); - - awaitPartitionMapExchange(); - - IgniteCache cache2 = ignite2.cache(null); - IgniteCache cache3 = ignite3.cache(null); - - for (int i = 0; i < 100; i++) { - assertEquals(String.valueOf(i), (Integer)(i * 2), cache2.get(i)); - assertEquals(String.valueOf(i), (Integer)(i * 2), cache3.get(i)); - } - } - - /** - * Test that up-to-date partitions aren't rebalanced after cluster restarts gracefully. - * @throws Exception If fails. - */ - public void testNoRebalancingOnRestartDeactivated() throws Exception { - fail(); - IgniteEx ignite1 = (IgniteEx) G.start(getConfiguration("test1")); - IgniteEx ignite2 = (IgniteEx) G.start(getConfiguration("test2")); - IgniteEx ignite3 = (IgniteEx) G.start(getConfiguration("test3")); - IgniteEx ignite4 = (IgniteEx) G.start(getConfiguration("test4")); - - awaitPartitionMapExchange(); - - IgniteCache cache1 = ignite1.cache(null); - - final Collection parts = new HashSet<>(); - - for (int i = 0; i < 100; i++) { - cache1.put(i, i); - parts.add(ignite1.affinity(null).partition(i)); - } - - ignite1.active(false); - - ignite1.close(); - ignite2.close(); - ignite3.close(); - ignite4.close(); - - final AtomicInteger eventCount = new AtomicInteger(); - - ignite1 = (IgniteEx) G.start(getConfiguration("test1")); - - cache1 = ignite1.cache(null); - - ignite1.active(false); - - ignite1.events().remoteListen(new IgniteBiPredicate() { - @Override public boolean apply(UUID uuid, CacheRebalancingEvent event) { - if (event.cacheName() == null && parts.contains(event.partition())) - eventCount.incrementAndGet(); - - return true; - } - }, null, EventType.EVT_CACHE_REBALANCE_PART_LOADED); - - ignite2 = (IgniteEx) G.start(getConfiguration("test2")); - ignite3 = (IgniteEx) G.start(getConfiguration("test3")); - ignite4 = (IgniteEx) G.start(getConfiguration("test4")); - - ignite1.active(true); - - awaitPartitionMapExchange(); - - assert eventCount.get() == 0 : eventCount.get(); - - IgniteCache cache2 = ignite2.cache(null); - IgniteCache cache3 = ignite3.cache(null); - IgniteCache cache4 = ignite4.cache(null); - - for (int i = 0; i < 100; i++) { - assert cache1.get(i).equals(i); - assert cache2.get(i).equals(i); - assert cache3.get(i).equals(i); - assert cache4.get(i).equals(i); - } - } - - /** - * Test that all data is correctly restored after non-graceful restart. - * @throws Exception If fails. - */ - public void testDataCorrectnessAfterRestart() throws Exception { - IgniteEx ignite1 = (IgniteEx) G.start(getConfiguration("test1")); - IgniteEx ignite2 = (IgniteEx) G.start(getConfiguration("test2")); - IgniteEx ignite3 = (IgniteEx) G.start(getConfiguration("test3")); - IgniteEx ignite4 = (IgniteEx) G.start(getConfiguration("test4")); - - awaitPartitionMapExchange(); - - IgniteCache cache1 = ignite1.cache(null); - - for (int i = 0; i < 100; i++) { - cache1.put(i, i); - } - - ignite1.close(); - ignite2.close(); - ignite3.close(); - ignite4.close(); - - ignite1 = (IgniteEx) G.start(getConfiguration("test1")); - ignite2 = (IgniteEx) G.start(getConfiguration("test2")); - ignite3 = (IgniteEx) G.start(getConfiguration("test3")); - ignite4 = (IgniteEx) G.start(getConfiguration("test4")); - - awaitPartitionMapExchange(); - - cache1 = ignite1.cache(null); - IgniteCache cache2 = ignite2.cache(null); - IgniteCache cache3 = ignite3.cache(null); - IgniteCache cache4 = ignite4.cache(null); - - for (int i = 0; i < 100; i++) { - assert cache1.get(i).equals(i); - assert cache2.get(i).equals(i); - assert cache3.get(i).equals(i); - assert cache4.get(i).equals(i); - } - } - - /** - * Test that partitions are marked as lost when all owners leave cluster, but recover after nodes rejoin. - * @throws Exception If fails. - */ - public void testPartitionLossAndRecover() throws Exception { - Ignite ignite1 = G.start(getConfiguration("test1")); - Ignite ignite2 = G.start(getConfiguration("test2")); - IgniteEx ignite3 = (IgniteEx) G.start(getConfiguration("test3")); - IgniteEx ignite4 = (IgniteEx) G.start(getConfiguration("test4")); - - awaitPartitionMapExchange(); - - IgniteCache cache1 = ignite1.cache(null); - - for (int i = 0; i < 100; i++) { - cache1.put(i, i); - } - - ignite1.active(false); - - ignite3.close(); - ignite4.close(); - - ignite1.active(true); - - awaitPartitionMapExchange(); - - assert !cache1.lostPartitions().isEmpty(); - - ignite3 = (IgniteEx) G.start(getConfiguration("test3")); - ignite4 = (IgniteEx) G.start(getConfiguration("test4")); - - awaitPartitionMapExchange(); - - ignite1.resetLostPartitions(Collections.singletonList(cache1.getName())); - - IgniteCache cache2 = ignite2.cache(null); - IgniteCache cache3 = ignite3.cache(null); - IgniteCache cache4 = ignite4.cache(null); - - for (int i = 0; i < 100; i++) { - assert cache1.get(i).equals(i); - assert cache2.get(i).equals(i); - assert cache3.get(i).equals(i); - assert cache4.get(i).equals(i); - } - } - - /** - * @throws Exception If failed. - */ - public void testTopologyChangesWithConstantLoad() throws Exception { - final int entriesCount = 10_000; - int maxNodesCount = 4; - int topChanges = 20; - final String cacheName = "indexed"; - - final AtomicBoolean stop = new AtomicBoolean(); - - final ConcurrentMap map = new ConcurrentHashMap<>(); - - Ignite ignite = startGrid(0); - - IgniteCache cache = ignite.cache(cacheName); - - for (int i = 0; i < entriesCount; i++) { - cache.put(i, new TestValue(i, i)); - map.put(i, new TestValue(i, i)); - } - - final AtomicInteger nodesCount = new AtomicInteger(); - - IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable() { - @Override public Void call() throws Exception { - while (true) { - if (stop.get()) - return null; - - int k = ThreadLocalRandom.current().nextInt(entriesCount); - int v1 = ThreadLocalRandom.current().nextInt(); - int v2 = ThreadLocalRandom.current().nextInt(); - - int n = nodesCount.get(); - - if (n <= 0) - continue; - - Ignite ignite; - - try { - ignite = grid(ThreadLocalRandom.current().nextInt(n)); - } - catch (Exception e) { - continue; - } - - if (ignite == null) - continue; - - Transaction tx = null; - boolean success = true; - - if (explicitTx) { - tx = ignite.transactions().txStart(); - } - - try { - ignite.cache(cacheName).put(k, new TestValue(v1, v2)); - } - catch (Exception e) { - success = false; - } - finally { - if (tx != null) { - try { - tx.commit(); - } - catch (Exception e) { - success = false; - } - } - } - - if (success) - map.put(k, new TestValue(v1, v2)); - } - } - }, 1, "load-runner"); - - for (int i = 0; i < topChanges; i++) { - U.sleep(3_000); - - boolean add; - if (nodesCount.get() <= maxNodesCount / 2) - add = true; - else if (nodesCount.get() > maxNodesCount) - add = false; - else - add = ThreadLocalRandom.current().nextBoolean(); - - if (add) - startGrid(nodesCount.incrementAndGet()); - else - stopGrid(nodesCount.getAndDecrement()); - - awaitPartitionMapExchange(); - - cache.rebalance().get(); - } - - stop.set(true); - - fut.get(); - - awaitPartitionMapExchange(); - - for (Map.Entry entry : map.entrySet()) { - assertEquals(Integer.toString(entry.getKey()), entry.getValue(), cache.get(entry.getKey())); - } - } - - private static class TestValue implements Serializable { - private final int v1; - private final int v2; - - private TestValue(int v1, int v2) { - this.v1 = v1; - this.v2 = v2; - } - - @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - - TestValue value = (TestValue)o; - - if (v1 != value.v1) - return false; - return v2 == value.v2; - - } - - @Override public int hashCode() { - int result = v1; - result = 31 * result + v2; - return result; - } - - @Override public String toString() { - return "TestValue{" + - "v1=" + v1 + - ", v2=" + v2 + - '}'; - } - } -} diff --git a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAtomicSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAtomicSelfTest.java deleted file mode 100644 index ef58c727ea211..0000000000000 --- a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceAtomicSelfTest.java +++ /dev/null @@ -1,41 +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.grid.internal.processors.cache.database; - -import org.apache.ignite.cache.CacheAtomicityMode; -import org.apache.ignite.cache.CacheMode; -import org.apache.ignite.cache.CacheWriteSynchronizationMode; -import org.apache.ignite.configuration.CacheConfiguration; - -/** - * - */ -public class CacheRebalancingWithPersistenceAtomicSelfTest extends CacheRebalancingWithPersistenceAbstractTest { - /** {@inheritDoc} */ - @Override protected CacheConfiguration cacheConfiguration(String cacheName) { - CacheConfiguration ccfg = new CacheConfiguration(cacheName); - - ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); - ccfg.setCacheMode(CacheMode.PARTITIONED); - ccfg.setBackups(1); - ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); - - return ccfg; - } - -} diff --git a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceTxSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceTxSelfTest.java deleted file mode 100644 index c91e9e6bcef9e..0000000000000 --- a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/CacheRebalancingWithPersistenceTxSelfTest.java +++ /dev/null @@ -1,61 +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.grid.internal.processors.cache.database; - -import org.apache.ignite.cache.CacheAtomicityMode; -import org.apache.ignite.cache.CacheMode; -import org.apache.ignite.cache.CacheRebalanceMode; -import org.apache.ignite.cache.CacheWriteSynchronizationMode; -import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; -import org.apache.ignite.configuration.CacheConfiguration; - -/** - * - */ -public class CacheRebalancingWithPersistenceTxSelfTest extends CacheRebalancingWithPersistenceAbstractTest { - /** {@inheritDoc} */ - @Override protected CacheConfiguration cacheConfiguration(String cacheName) { - CacheConfiguration ccfg = new CacheConfiguration(cacheName); - - ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); - ccfg.setCacheMode(CacheMode.PARTITIONED); - ccfg.setRebalanceMode(CacheRebalanceMode.SYNC); - ccfg.setBackups(1); - ccfg.setRebalanceDelay(10_000); - ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); - ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); - - return ccfg; - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - super.afterTest(); - - explicitTx = false; - } - - /** - * @throws Exception If failed. - */ - public void testTopologyChangesWithConstantLoadExplicitTx() throws Exception { - explicitTx = true; - - testTopologyChangesWithConstantLoad(); - } -} diff --git a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/IgniteDbContinuousRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/IgniteDbContinuousRestartSelfTest.java deleted file mode 100644 index 1bf875003b9d6..0000000000000 --- a/modules/pds/src/test/java/org/apache/ignite/grid/internal/processors/cache/database/IgniteDbContinuousRestartSelfTest.java +++ /dev/null @@ -1,273 +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.grid.internal.processors.cache.database; - -import java.util.Map; -import java.util.Random; -import java.util.TreeMap; -import java.util.concurrent.Callable; -import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.ignite.Ignite; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.IgniteDataStreamer; -import org.apache.ignite.IgniteSystemProperties; -import org.apache.ignite.cache.CacheAtomicityMode; -import org.apache.ignite.cache.CacheWriteSynchronizationMode; -import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.configuration.MemoryConfiguration; -import org.apache.ignite.configuration.MemoryPolicyConfiguration; -import org.apache.ignite.configuration.PersistenceConfiguration; -import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.testframework.GridTestUtils; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; - -/** - * - */ -public class IgniteDbContinuousRestartSelfTest extends GridCommonAbstractTest { - /** */ - private static final int GRID_CNT = 4; - - /** */ - private static final int ENTRIES_COUNT = 10_000; - - /** */ - public static final String CACHE_NAME = "cache1"; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - MemoryConfiguration dbCfg = new MemoryConfiguration(); - - MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); - - memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(400 * 1024 * 1024); - - dbCfg.setMemoryPolicies(memPlcCfg); - dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); - - cfg.setMemoryConfiguration(dbCfg); - - CacheConfiguration ccfg1 = new CacheConfiguration(); - - ccfg1.setName(CACHE_NAME); - ccfg1.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); - ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); - ccfg1.setAffinity(new RendezvousAffinityFunction(false, 128)); - ccfg1.setBackups(2); - - cfg.setCacheConfiguration(ccfg1); - - PersistenceConfiguration pdsCfg = new PersistenceConfiguration(); - - cfg.setPersistenceConfiguration(pdsCfg); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - - stopAllGrids(); - - deleteWorkFiles(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - stopAllGrids(); - - System.clearProperty(IgniteSystemProperties.IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY); - - deleteWorkFiles(); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - super.afterTestsStopped(); - - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - } - - /** - * @throws IgniteCheckedException If failed. - */ - private void deleteWorkFiles() throws IgniteCheckedException { - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "snapshot", false)); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_1000_500_1_1() throws Exception { - checkRebalancingDuringLoad(1000, 500, 1, 1); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_8000_500_1_1() throws Exception { - checkRebalancingDuringLoad(8000, 500, 1, 1); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_1000_20000_1_1() throws Exception { - checkRebalancingDuringLoad(1000, 20000, 1, 1); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_8000_8000_1_1() throws Exception { - checkRebalancingDuringLoad(8000, 8000, 1, 1); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_1000_500_8_1() throws Exception { - checkRebalancingDuringLoad(1000, 500, 8, 1); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_8000_500_8_1() throws Exception { - checkRebalancingDuringLoad(8000, 500, 8, 1); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_1000_20000_8_1() throws Exception { - checkRebalancingDuringLoad(1000, 20000, 8, 1); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_8000_8000_8_1() throws Exception { - checkRebalancingDuringLoad(8000, 8000, 8, 1); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_1000_500_8_16() throws Exception { - checkRebalancingDuringLoad(1000, 500, 8, 16); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_8000_500_8_16() throws Exception { - checkRebalancingDuringLoad(8000, 500, 8, 16); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_1000_20000_8_16() throws Exception { - checkRebalancingDuringLoad(1000, 20000, 8, 16); - } - - /** - * @throws Exception if failed. - */ - public void testRebalancingDuringLoad_8000_8000_8_16() throws Exception { - checkRebalancingDuringLoad(8000, 8000, 8, 16); - } - - /** - * @throws Exception if failed. - */ - private void checkRebalancingDuringLoad( - int restartDelay, - int checkpointDelay, - int threads, - final int batch - ) throws Exception { - System.setProperty(IgniteSystemProperties.IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY, - String.valueOf(checkpointDelay)); - - startGrids(GRID_CNT); - - final Ignite load = ignite(0); - - try (IgniteDataStreamer s = load.dataStreamer(CACHE_NAME)) { - s.allowOverwrite(true); - - for (int i = 0; i < ENTRIES_COUNT; i++) - s.addData(i, i); - } - - final AtomicBoolean done = new AtomicBoolean(false); - - IgniteInternalFuture busyFut = GridTestUtils.runMultiThreadedAsync(new Callable() { - /** {@inheritDoc} */ - @Override - public Object call() throws Exception { - IgniteCache cache = load.cache(CACHE_NAME); - Random rnd = ThreadLocalRandom.current(); - - while (!done.get()) { - Map map = new TreeMap<>(); - - for (int i = 0; i < batch; i++) - map.put(rnd.nextInt(ENTRIES_COUNT), rnd.nextInt()); - - cache.putAll(map); - } - - return null; - } - }, threads, "updater"); - - long end = System.currentTimeMillis() + 90_000; - - Random rnd = ThreadLocalRandom.current(); - - while (System.currentTimeMillis() < end) { - int idx = rnd.nextInt(GRID_CNT - 1) + 1; - - stopGrid(idx); - - U.sleep(restartDelay); - - startGrid(idx); - - U.sleep(restartDelay); - } - - done.set(true); - - busyFut.get(); - } -} From bc4209bac205a682729d8ab174348bf188356565 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 17 May 2017 12:52:01 +0300 Subject: [PATCH 177/311] ignite-12163 fix test activation after fail get lock --- .../processors/cluster/GridClusterStateProcessor.java | 2 +- .../cache/database/GridCacheDatabaseSharedManager.java | 4 +++- .../processors/cache/database/file/FilePageStoreManager.java | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java index 1286ba9e5a29f..2cb6a1ecbc788 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java @@ -379,7 +379,7 @@ public void onFullResponseMessage(Map exs) { actx.setFail(); - // revert change if activation request fail + // Revert change if activation request fail. if (actx.activate) { try { cacheProc.onKernalStopCaches(true); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 73d60722a1ca5..a5274b9a93b67 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -437,7 +437,7 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { log.debug("DeActivate database manager [id=" + cctx.localNodeId() + " topVer=" + cctx.discovery().topologyVersionEx() + " ]"); - onKernalStop0(true); + onKernalStop0(false); /* Must be here, because after deactivate we can invoke activate and file lock must be already configured */ stopping = false; @@ -477,6 +477,8 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { cctx.localNodeId() + " path=" + fileLockHolder.lockPath() + "]"); fileLockHolder.tryLock(lockWaitTime); + + System.out.println("Lock: " + fileLockHolder.lockPath() + " node " + cctx.igniteInstanceName()); } /** {@inheritDoc} */ diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java index af47c290c98d9..1bb83d21b1fe9 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java @@ -154,6 +154,8 @@ public FilePageStoreManager(GridKernalContext ctx) { " topVer=" + cctx.discovery().topologyVersionEx() + " ]"); stop0(true); + + idxCacheStores.clear(); } /** {@inheritDoc} */ From 29a608314aa03471a5513d06322da2d7a48631ed Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 17 May 2017 13:03:01 +0300 Subject: [PATCH 178/311] ignite-12163 minor --- .../cache/database/GridCacheDatabaseSharedManager.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index a5274b9a93b67..632bdaf528154 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -477,8 +477,6 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { cctx.localNodeId() + " path=" + fileLockHolder.lockPath() + "]"); fileLockHolder.tryLock(lockWaitTime); - - System.out.println("Lock: " + fileLockHolder.lockPath() + " node " + cctx.igniteInstanceName()); } /** {@inheritDoc} */ From 44f276aa50945271d8a1f7d65d04df954ded04ef Mon Sep 17 00:00:00 2001 From: Eduard Shangareev Date: Wed, 17 May 2017 14:49:05 +0300 Subject: [PATCH 179/311] fixing db tests after 2.0 merge --- .../IgniteDbDynamicCacheSelfTest.java | 1 - .../database/IgniteDbPutGetAbstractTest.java | 27 +++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbDynamicCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbDynamicCacheSelfTest.java index 3b3e1defa5f44..20cdc2aaffcac 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbDynamicCacheSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbDynamicCacheSelfTest.java @@ -44,7 +44,6 @@ public class IgniteDbDynamicCacheSelfTest extends GridCommonAbstractTest { MemoryPolicyConfiguration plc = new MemoryPolicyConfiguration(); plc.setName("dfltPlc"); - plc.setMaxSize(200 * 1024 * 1024); dbCfg.setDefaultMemoryPolicyName("dfltPlc"); dbCfg.setMemoryPolicies(plc); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java index f085ebbaf21d7..0b0c7633b6817 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbPutGetAbstractTest.java @@ -57,9 +57,8 @@ public abstract class IgniteDbPutGetAbstractTest extends IgniteDbAbstractTest { * @return Ignite instance for testing. */ private IgniteEx ig() { - if (withClientNearCache()) { + if (withClientNearCache()) return grid(gridCount()); - } return grid(0); } @@ -79,7 +78,7 @@ private IgniteCache cache(String name) throws Exception { * */ public void testGradualRandomPutAllRemoveAll() throws Exception { - IgniteCache cache = cache(null); + IgniteCache cache = cache(DEFAULT_CACHE_NAME); final int cnt = KEYS_COUNT; @@ -206,7 +205,7 @@ public void testRandomPut() throws Exception { * @throws Exception if failed. */ public void testPutGetSimple() throws Exception { - IgniteCache cache = cache(null); + IgniteCache cache = cache(DEFAULT_CACHE_NAME); GridCacheAdapter internalCache = internalCache(cache); @@ -320,7 +319,7 @@ private int[] randomInts(final int size) { * @throws Exception if failed. */ public void testPutGetOverwrite() throws Exception { - final IgniteCache cache = cache(null); + final IgniteCache cache = cache(DEFAULT_CACHE_NAME); GridCacheAdapter internalCache = internalCache(cache); @@ -348,7 +347,7 @@ public void testPutGetOverwrite() throws Exception { * @throws Exception if failed. */ public void testOverwriteNormalSizeAfterSmallerSize() throws Exception { - final IgniteCache cache = cache(null); + final IgniteCache cache = cache(DEFAULT_CACHE_NAME); GridCacheAdapter internalCache = internalCache(cache); @@ -383,7 +382,7 @@ public void testPutDoesNotTriggerRead() throws Exception { * @throws Exception if failed. */ public void testPutGetMultipleObjects() throws Exception { - final IgniteCache cache = cache(null); + final IgniteCache cache = cache(DEFAULT_CACHE_NAME); GridCacheAdapter internalCache = internalCache(cache); @@ -456,7 +455,7 @@ public void testPutGetMultipleObjects() throws Exception { * @throws Exception if failed. */ public void testSizeClear() throws Exception { - final IgniteCache cache = cache(null); + final IgniteCache cache = cache(DEFAULT_CACHE_NAME); GridCacheAdapter internalCache = internalCache(cache); @@ -614,7 +613,7 @@ public void testMultithreadedPut() throws Exception { * @throws Exception if failed. */ public void testPutGetRandomUniqueMultipleObjects() throws Exception { - final IgniteCache cache = cache(null); + final IgniteCache cache = cache(DEFAULT_CACHE_NAME); GridCacheAdapter internalCache = internalCache(cache); @@ -681,7 +680,7 @@ private static int[] generateUniqueRandomKeys(int cnt, Random rnd) { * @throws Exception If failed. */ public void testPutPrimaryUniqueSecondaryDuplicates() throws Exception { - final IgniteCache cache = cache(null); + final IgniteCache cache = cache(DEFAULT_CACHE_NAME); GridCacheAdapter internalCache = internalCache(cache); @@ -725,7 +724,7 @@ public void testPutPrimaryUniqueSecondaryDuplicates() throws Exception { * @throws Exception if failed. */ public void testPutGetRandomNonUniqueMultipleObjects() throws Exception { - final IgniteCache cache = cache(null); + final IgniteCache cache = cache(DEFAULT_CACHE_NAME); GridCacheAdapter internalCache = internalCache(cache); @@ -771,7 +770,7 @@ public void testPutGetRandomNonUniqueMultipleObjects() throws Exception { * @throws Exception if failed. */ public void testPutGetRemoveMultipleForward() throws Exception { - final IgniteCache cache = cache(null); + final IgniteCache cache = cache(DEFAULT_CACHE_NAME); GridCacheAdapter internalCache = internalCache(cache); @@ -861,7 +860,7 @@ public void _testRandomPutGetRemove() throws Exception { } public void testPutGetRemoveMultipleBackward() throws Exception { - final IgniteCache cache = cache(null); + final IgniteCache cache = cache(DEFAULT_CACHE_NAME); GridCacheAdapter internalCache = internalCache(cache); @@ -905,7 +904,7 @@ public void testPutGetRemoveMultipleBackward() throws Exception { * @throws Exception if failed. */ public void testIndexOverwrite() throws Exception { - final IgniteCache cache = cache(null); + final IgniteCache cache = cache(DEFAULT_CACHE_NAME); GridCacheAdapter internalCache = internalCache(cache); From 4638af19c4402b5b99fe383653fe8918d09a0b81 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 17 May 2017 15:12:42 +0300 Subject: [PATCH 180/311] ignite-12163 muted test --- .../IgnitePersistentStoreCacheRebalancingAbstractTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index a767fe14f80c7..3ea6b95400eba 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -440,7 +440,7 @@ public void testPartitionLossAndRecover() throws Exception { /** * @throws Exception If failed. */ - public void testTopologyChangesWithConstantLoad() throws Exception { + public void _testTopologyChangesWithConstantLoad() throws Exception { final int entriesCnt = 10_000; int maxNodesCount = 4; int topChanges = 20; From 83cd97c76d7fc47073437615fd117840398ac4e1 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Wed, 17 May 2017 15:23:56 +0300 Subject: [PATCH 181/311] ignite-12163 muted test update --- .../IgnitePersistentStoreCacheRebalancingAbstractTest.java | 4 +++- .../database/IgnitePersistentStoreTxCacheRebalancingTest.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index 3ea6b95400eba..af08002df2216 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -440,7 +440,9 @@ public void testPartitionLossAndRecover() throws Exception { /** * @throws Exception If failed. */ - public void _testTopologyChangesWithConstantLoad() throws Exception { + public void testTopologyChangesWithConstantLoad() throws Exception { + fail("only for one run, must be removed soon"); + final int entriesCnt = 10_000; int maxNodesCount = 4; int topChanges = 20; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java index fb71b8a6fa33e..a5649165c60f4 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java @@ -54,6 +54,8 @@ public class IgnitePersistentStoreTxCacheRebalancingTest extends IgnitePersisten * @throws Exception If failed. */ public void testTopologyChangesWithConstantLoadExplicitTx() throws Exception { + fail("only for one run, must be removed soon"); + explicitTx = true; testTopologyChangesWithConstantLoad(); From b49754db2f392d49a5fb8656d7f2aaaa2f6eadab Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Thu, 18 May 2017 12:44:50 +0300 Subject: [PATCH 182/311] ignite-12163 Move oom test in separate suit --- .../IgnitePersistentStoreWalTlbSelfTest.java | 10 ++--- .../IgnitePdsOutOfMemoryTestSuite.java | 38 +++++++++++++++++++ .../testsuites/IgnitePdsTestSuite2.java | 2 - 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java index afdcbc768f113..e34337bc28883 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java @@ -18,7 +18,7 @@ package org.apache.ignite.cache.database; import javax.cache.CacheException; -import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.IgniteCache; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; @@ -118,13 +118,9 @@ public void testWalDirectOutOfMemory() throws Exception { boolean locked = true; try { - IgniteDataStreamer streamer = ig.dataStreamer(null); - for (int i = 0; i < 100_000; i++) { - streamer.addData(i, 1); + IgniteCache cache = ig.getOrCreateCache("cache"); - if (i > 0 && i % 10_000 == 0) - info("Done put: " + i); - } + cache.put(1, 1); } catch (CacheException ignore) { // expected diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java new file mode 100644 index 0000000000000..dc733bf26e28d --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java @@ -0,0 +1,38 @@ +/* + * 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.testsuites; + +import junit.framework.TestSuite; +import org.apache.ignite.cache.database.IgnitePersistentStoreWalTlbSelfTest; + +/** + * + */ +public class IgnitePdsOutOfMemoryTestSuite extends TestSuite { + /** + * @return Suite. + * @throws Exception If failed. + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("Ignite Persistent Store OOM Test Suite"); + + suite.addTestSuite(IgnitePersistentStoreWalTlbSelfTest.class); + + return suite; + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java index 9b1d9267ac3c2..223c3cb28cb9f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java @@ -22,7 +22,6 @@ import org.apache.ignite.cache.database.IgnitePersistentStoreTxCacheRebalancingTest; import org.apache.ignite.cache.database.IgnitePersistentStoreContinuousRestartSelfTest; import org.apache.ignite.cache.database.IgnitePersistentStorePageSizesTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreWalTlbSelfTest; import org.apache.ignite.cache.database.IgnitePersistentStoreRecoveryAfterFileCorruptionTest; import org.apache.ignite.cache.database.db.DbPageEvictionDuringPartitionClearSelfTest; import org.apache.ignite.cache.database.db.IgniteDbWholeClusterRestartSelfTest; @@ -49,7 +48,6 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(IgniteDataIntegrityTests.class); suite.addTestSuite(IgnitePersistentStoreRecoveryAfterFileCorruptionTest.class); suite.addTestSuite(IgnitePersistentStorePageSizesTest.class); - suite.addTestSuite(IgnitePersistentStoreWalTlbSelfTest.class); // WAL recovery test. suite.addTestSuite(WalRecoveryTxLogicalRecordsTest.class); From 91b6b13e16788fd528766b0954f0d843b27e3a23 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Mon, 15 May 2017 15:27:00 +0300 Subject: [PATCH 183/311] IGNITE-5215: Allow user to configure memory policy with maxSize lesser than default initialSize (cherry picked from commit 6319266) --- .../IgniteCacheDatabaseSharedManager.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 540b9eaa23c54..06249660063f8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -55,11 +55,13 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport; import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.LT; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiTuple; import org.apache.ignite.mxbean.MemoryMetricsMXBean; import org.jetbrains.annotations.Nullable; +import static org.apache.ignite.configuration.MemoryConfiguration.DFLT_MEMORY_POLICY_INITIAL_SIZE; import static org.apache.ignite.configuration.MemoryConfiguration.DFLT_MEM_PLC_DEFAULT_NAME; /** @@ -405,18 +407,28 @@ private static void checkDefaultPolicyConfiguration( * @param plcCfg MemoryPolicyConfiguration to validate. * @throws IgniteCheckedException If config is invalid. */ - private static void checkPolicySize(MemoryPolicyConfiguration plcCfg) throws IgniteCheckedException { + private void checkPolicySize(MemoryPolicyConfiguration plcCfg) throws IgniteCheckedException { if (plcCfg.getInitialSize() < MIN_PAGE_MEMORY_SIZE) throw new IgniteCheckedException("MemoryPolicy must have size more than 10MB (use " + "MemoryPolicyConfiguration.initialSize property to set correct size in bytes) " + "[name=" + plcCfg.getName() + ", size=" + U.readableSize(plcCfg.getInitialSize(), true) + "]" ); - if (plcCfg.getMaxSize() < plcCfg.getInitialSize()) - throw new IgniteCheckedException("MemoryPolicy maxSize must not be smaller than " + - "initialSize [name=" + plcCfg.getName() + - ", initSize=" + U.readableSize(plcCfg.getInitialSize(), true) + - ", maxSize=" + U.readableSize(plcCfg.getMaxSize(), true) + ']'); + if (plcCfg.getMaxSize() < plcCfg.getInitialSize()) { + if (plcCfg.getInitialSize() == DFLT_MEMORY_POLICY_INITIAL_SIZE) { + plcCfg.setInitialSize(plcCfg.getMaxSize()); + + LT.warn(log, "MemoryPolicy maxSize=" + U.readableSize(plcCfg.getMaxSize(), true) + + " is smaller than defaultInitialSize=" + + U.readableSize(MemoryConfiguration.DFLT_MEMORY_POLICY_INITIAL_SIZE, true) + + ", setting initialSize to " + U.readableSize(plcCfg.getMaxSize(), true)); + } else { + throw new IgniteCheckedException("MemoryPolicy maxSize must not be smaller than " + + "initialSize [name=" + plcCfg.getName() + + ", initSize=" + U.readableSize(plcCfg.getInitialSize(), true) + + ", maxSize=" + U.readableSize(plcCfg.getMaxSize(), true) + ']'); + } + } } /** From 59bc11bcc4338ab44a19ec80dd2ba3d62544808e Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Thu, 18 May 2017 15:10:40 +0300 Subject: [PATCH 184/311] Fixed MetaPageInitRecord --- .../internal/pagemem/wal/record/delta/MetaPageInitRecord.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java index 3d351a26c2371..19340c1e4a332 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java @@ -76,9 +76,7 @@ public int ioType() { /** {@inheritDoc} */ @Override public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException { - PageMetaIO io = ioType == PageIO.T_META ? - PageMetaIO.VERSIONS.forPage(pageAddr) : - PagePartitionMetaIO.VERSIONS.forPage(pageAddr); + PageMetaIO io = PageMetaIO.getPageIO(ioType, ioVer); io.initNewPage(pageAddr, newPageId, pageMem.pageSize()); From 294fec4e5b887bb5740d4f61ce3b1e295e405373 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Thu, 18 May 2017 20:41:13 +0300 Subject: [PATCH 185/311] ignite-12163 Corrected swap path in test, add lock tracker (wrapper for lock and readwritelock,count lock/unlock operation) --- .../ignite/internal/util/IgniteUtils.java | 177 +++++++++++++++++- ...tentStoreCacheRebalancingAbstractTest.java | 6 +- 2 files changed, 176 insertions(+), 7 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index ccf3a1da5db5d..704f36d9a9147 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -122,8 +122,10 @@ import java.util.concurrent.Future; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.jar.JarFile; import java.util.logging.ConsoleHandler; @@ -177,8 +179,6 @@ import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.IgniteNodeAttributes; -import org.apache.ignite.internal.binary.BinaryObjectEx; -import org.apache.ignite.internal.binary.BinaryUtils; import org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException; @@ -10123,4 +10123,177 @@ public static byte[] zip(@Nullable byte[] bytes) throws IgniteCheckedException { throw new IgniteCheckedException(e); } } + + /** + * @param lock Lock. + */ + public static ReentrantReadWriteLockTracer lockTracer(ReadWriteLock lock) { + return new ReentrantReadWriteLockTracer(lock); + } + + /** + * @param lock Lock. + */ + public static LockTracer lockTracer(Lock lock) { + return new LockTracer(lock); + } + + /** + * + */ + public static class ReentrantReadWriteLockTracer implements ReadWriteLock { + /** Read lock. */ + private final LockTracer readLock; + + /** Write lock. */ + private final LockTracer writeLock; + + /** + * @param delegate Delegate. + */ + public ReentrantReadWriteLockTracer(ReadWriteLock delegate) { + readLock = new LockTracer(delegate.readLock()); + writeLock = new LockTracer(delegate.writeLock()); + } + + /** {@inheritDoc} */ + @NotNull @Override public Lock readLock() { + return readLock; + } + + /** {@inheritDoc} */ + @NotNull @Override public Lock writeLock() { + return writeLock; + } + + /** + * + */ + public LockTracer getReadLock() { + return readLock; + } + + /** + * + */ + public LockTracer getWriteLock() { + return writeLock; + } + } + + /** + * + */ + public static class LockTracer implements Lock { + /** Delegate. */ + private final Lock delegate; + + private final AtomicLong cnt = new AtomicLong(); + + /** Count. */ + private final ConcurrentMap cntMap = new ConcurrentHashMap8<>(); + + /** + * @param delegate Delegate. + */ + public LockTracer(Lock delegate) { + this.delegate = delegate; + } + + /** + * + */ + private void inc(){ + cnt.incrementAndGet(); + + String name = Thread.currentThread().getName(); + + AtomicLong cnt = cntMap.get(name); + + if (cnt == null) { + AtomicLong cnt0 = cntMap.putIfAbsent(name, cnt = new AtomicLong()); + + if (cnt0 != null) + cnt = cnt0; + } + + cnt.incrementAndGet(); + } + + /** + * + */ + private void dec(){ + cnt.decrementAndGet(); + + String name = Thread.currentThread().getName(); + + AtomicLong cnt = cntMap.get(name); + + cnt.decrementAndGet(); + } + + /** {@inheritDoc} */ + @Override public void lock() { + delegate.lock(); + + inc(); + } + + /** {@inheritDoc} */ + @Override public void lockInterruptibly() throws InterruptedException { + delegate.lockInterruptibly(); + + inc(); + } + + /** {@inheritDoc} */ + @Override public boolean tryLock() { + if (delegate.tryLock()) { + inc(); + + return true; + } + else + return false; + } + + /** {@inheritDoc} */ + @Override public boolean tryLock(long time, @NotNull TimeUnit unit) throws InterruptedException { + if (delegate.tryLock(time, unit)) { + inc(); + + return true; + } + else + return false; + } + + /** {@inheritDoc} */ + @Override public void unlock() { + delegate.unlock(); + + dec(); + } + + /** {@inheritDoc} */ + @NotNull @Override public Condition newCondition() { + // Wrapper for condition not supported. + throw new UnsupportedOperationException(); + } + + /** + * + */ + public Map getLockUnlockCounters() { + return new HashMap<>(cntMap); + } + + /** + * + */ + public long getLockUnlockCounter() { + return cnt.get(); + } + } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index af08002df2216..4d33d227c4074 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -108,7 +108,7 @@ public abstract class IgnitePersistentStoreCacheRebalancingAbstractTest extends memPlcCfg.setName("dfltMemPlc"); memPlcCfg.setSize(100 * 1024 * 1024); - memPlcCfg.setSwapFilePath("db"); + memPlcCfg.setSwapFilePath("work/swap"); dbCfg.setMemoryPolicies(memPlcCfg); dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); @@ -142,8 +142,6 @@ public abstract class IgnitePersistentStoreCacheRebalancingAbstractTest extends System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - - U.delete(new File(U.getIgniteHome(), "db")); } /** {@inheritDoc} */ @@ -151,8 +149,6 @@ public abstract class IgnitePersistentStoreCacheRebalancingAbstractTest extends G.stopAll(true); deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - - U.delete(new File(U.getIgniteHome(), "db")); } /** {@inheritDoc} */ From f90cae22a8f444d5975b3b2ee1e8181f970e9296 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Thu, 18 May 2017 20:43:34 +0300 Subject: [PATCH 186/311] ignite-12163 revert load in oom test --- .../database/IgnitePersistentStoreWalTlbSelfTest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java index e34337bc28883..89bab33baf59f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java @@ -18,7 +18,7 @@ package org.apache.ignite.cache.database; import javax.cache.CacheException; -import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; @@ -118,9 +118,14 @@ public void testWalDirectOutOfMemory() throws Exception { boolean locked = true; try { - IgniteCache cache = ig.getOrCreateCache("cache"); + IgniteDataStreamer streamer = ig.dataStreamer(null); - cache.put(1, 1); + for (int i = 0; i < 100_000; i++) { + streamer.addData(i, 1); + + if (i > 0 && i % 10_000 == 0) + info("Done put: " + i); + } } catch (CacheException ignore) { // expected From 6ec62bb56991df0c77d72e3a507b8bbb1567e316 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Thu, 18 May 2017 21:29:22 +0300 Subject: [PATCH 187/311] ignite-12163 remove testNoRebalancingOnRestartDeactivated as deprecated --- ...tentStoreCacheRebalancingAbstractTest.java | 69 ------------------- 1 file changed, 69 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index 4d33d227c4074..663fe5bcb9587 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -273,75 +273,6 @@ public void testRebalancingOnRestartAfterCheckpoint() throws Exception { } } - /** - * Test that up-to-date partitions aren't rebalanced after cluster restarts gracefully. - * - * @throws Exception If fails. - */ - public void testNoRebalancingOnRestartDeactivated() throws Exception { - fail(); - IgniteEx ignite1 = (IgniteEx)G.start(getConfiguration("test1")); - IgniteEx ignite2 = (IgniteEx)G.start(getConfiguration("test2")); - IgniteEx ignite3 = (IgniteEx)G.start(getConfiguration("test3")); - IgniteEx ignite4 = (IgniteEx)G.start(getConfiguration("test4")); - - awaitPartitionMapExchange(); - - IgniteCache cache1 = ignite1.cache(cacheName); - - final Collection parts = new HashSet<>(); - - for (int i = 0; i < 100; i++) { - cache1.put(i, i); - parts.add(ignite1.affinity(cacheName).partition(i)); - } - - ignite1.active(false); - - ignite1.close(); - ignite2.close(); - ignite3.close(); - ignite4.close(); - - final AtomicInteger evtCnt = new AtomicInteger(); - - ignite1 = (IgniteEx)G.start(getConfiguration("test1")); - - cache1 = ignite1.cache(cacheName); - - ignite1.active(false); - - ignite1.events().remoteListen(new IgniteBiPredicate() { - @Override public boolean apply(UUID uuid, CacheRebalancingEvent evt) { - if (Objects.equals(evt.cacheName(), cacheName) && parts.contains(evt.partition())) - evtCnt.incrementAndGet(); - - return true; - } - }, null, EventType.EVT_CACHE_REBALANCE_PART_LOADED); - - ignite2 = (IgniteEx)G.start(getConfiguration("test2")); - ignite3 = (IgniteEx)G.start(getConfiguration("test3")); - ignite4 = (IgniteEx)G.start(getConfiguration("test4")); - - ignite1.active(true); - - awaitPartitionMapExchange(); - - assert evtCnt.get() == 0 : evtCnt.get(); - - IgniteCache cache2 = ignite2.cache(cacheName); - IgniteCache cache3 = ignite3.cache(cacheName); - IgniteCache cache4 = ignite4.cache(cacheName); - - for (int i = 0; i < 100; i++) { - assert cache1.get(i).equals(i); - assert cache2.get(i).equals(i); - assert cache3.get(i).equals(i); - assert cache4.get(i).equals(i); - } - } - /** * Test that all data is correctly restored after non-graceful restart. * From 17007b8589fb7d3fe9ed60ea39af1879b41140aa Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 19 May 2017 13:11:45 +0300 Subject: [PATCH 188/311] ignite-gg-12163 more info in IgniteDataIntegrityViolationException --- .../internal/processors/cache/database/wal/FileInput.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java index 735ffb77dcb86..1ba002fd2cd35 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java @@ -299,8 +299,12 @@ public Crc32CheckingFileInput(int position, boolean skipCheck) { int writtenCrc = this.readInt(); if ((val ^ writtenCrc) != 0 && !skipCheck) { - ensure(5); //if it last message we will skip it (EOF will be thrown) - throw new IgniteDataIntegrityViolationException(); + // If it last message we will skip it (EOF will be thrown). + ensure(5); + + throw new IgniteDataIntegrityViolationException( + "val: " + val + " writtenCrc: " + writtenCrc + ); } } From c3ddea4cd25192ea9cd0cb590f64daffb57f4444 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 19 May 2017 13:27:10 +0300 Subject: [PATCH 189/311] ignite-gg-12163 delegate create condition --- .../main/java/org/apache/ignite/internal/util/IgniteUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 704f36d9a9147..f8c23c721bf2c 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -10278,8 +10278,7 @@ private void dec(){ /** {@inheritDoc} */ @NotNull @Override public Condition newCondition() { - // Wrapper for condition not supported. - throw new UnsupportedOperationException(); + return delegate.newCondition(); } /** From d90f1d9a6cb24093b13dc62ed189034dae4d887e Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 19 May 2017 18:31:20 +0300 Subject: [PATCH 190/311] ignite-gg-12163 fix null cache name --- .../IgnitePersistentStoreCacheRebalancingAbstractTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index 663fe5bcb9587..d06ca2f2b83c7 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -225,7 +225,7 @@ public void testRebalancingOnRestartAfterCheckpoint() throws Exception { awaitPartitionMapExchange(); - IgniteCache cache1 = ignite0.cache(null); + IgniteCache cache1 = ignite0.cache(cacheName); for (int i = 0; i < 1000; i++) cache1.put(i, i); From 930c87c9dcdcc455858d39d534e88f631e598bdc Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 19 May 2017 18:56:59 +0300 Subject: [PATCH 191/311] Merge master into ignite-gg-12163 - fixing compilation --- .../processors/cache/ExchangeActions.java | 2 +- .../IgniteCacheDatabaseSharedManager.java | 2 -- .../GridDhtPartitionsExchangeFuture.java | 27 ++++++++------- .../GridCacheDatabaseSharedManager.java | 16 +++++---- .../database/pagemem/PageMemoryImpl.java | 33 ++++++++++++++----- ...tentStoreCacheRebalancingAbstractTest.java | 3 +- ...sistentStoreContinuousRestartSelfTest.java | 3 +- ...IgnitePersistentStoreDynamicCacheTest.java | 3 +- ...ntStoreMultiNodePutGetRestartSelfTest.java | 3 +- .../IgnitePersistentStorePageSizesTest.java | 3 +- ...tStoreRecoveryAfterFileCorruptionTest.java | 3 +- ...tStoreRemoveDuringRebalancingSelfTest.java | 3 +- .../IgnitePersistentStoreWalTlbSelfTest.java | 3 +- ...eEvictionDuringPartitionClearSelfTest.java | 3 +- ...gniteDbMultiNodePutGetRestartSelfTest.java | 3 +- .../db/IgniteDbPageEvictionSelfTest.java | 3 +- .../IgniteDbWholeClusterRestartSelfTest.java | 3 +- .../RebalancingOnNotStableTopologyTest.java | 3 +- .../database/db/TransactionsHangTest.java | 3 +- ...niteCachePageStoreIntegrationSelfTest.java | 3 +- .../IgniteWalHistoryReservationsSelfTest.java | 3 +- .../db/file/IgniteWalRecoverySelfTest.java | 3 +- .../IgniteWalRecoverySeveralRestartsTest.java | 3 +- .../db/file/PageStoreEvictionSelfTest.java | 3 +- ...usTreeReuseListPageMemoryImplSelfTest.java | 30 +++++++++-------- ...lusTreeSelfTestPageMemoryImplSelfTest.java | 31 +++++++++-------- .../database/pagemem/FullPageIdTableTest.java | 12 ++++--- ...MetadataStoragePageMemoryImplSelfTest.java | 30 +++++++++-------- .../pagemem/PageIdDistributionTest.java | 22 +++++++------ .../pagemem/PageMemoryImplNoLoadSelfTest.java | 22 ++++++++----- .../database/pagemem/PageMemoryImplTest.java | 31 +++++++++-------- .../GridChangeGlobalStateAbstractTest.java | 3 +- .../extended/GridActivateExtensionTest.java | 3 +- .../ignite/testsuites/IgnitePdsTestSuite.java | 2 -- 34 files changed, 193 insertions(+), 130 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java index eac11205c8f60..ca103b1195f86 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java @@ -262,7 +262,7 @@ void addClientCacheToStart(DynamicCacheChangeRequest req, DynamicCacheDescriptor * @param req Request. * @param desc Cache descriptor. */ - void addCacheToStop(DynamicCacheChangeRequest req, DynamicCacheDescriptor desc) { + public void addCacheToStop(DynamicCacheChangeRequest req, DynamicCacheDescriptor desc) { assert req.stop() : req; cachesToStop = add(cachesToStop, req, desc); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index b7224656fe42d..9049a8168e979 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -24,7 +24,6 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.UUID; import javax.management.JMException; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; @@ -40,7 +39,6 @@ import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl; -import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; 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 e64f0dd6b218c..c75b0a2a78b93 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 @@ -34,7 +34,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.ReadWriteLock; import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.IgniteNeedReconnectException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.cache.PartitionLossPolicy; @@ -47,21 +46,22 @@ import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.IgniteNeedReconnectException; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.events.DiscoveryCustomEvent; -import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; import org.apache.ignite.internal.managers.discovery.DiscoCache; +import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationType; import org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage; -import org.apache.ignite.internal.managers.discovery.DiscoCache; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; import org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage; import org.apache.ignite.internal.processors.cache.CacheInvalidStateException; +import org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask; import org.apache.ignite.internal.processors.cache.ClusterState; import org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch; -import org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask; +import org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest; import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; import org.apache.ignite.internal.processors.cache.ExchangeActions; import org.apache.ignite.internal.processors.cache.GridCacheContext; @@ -546,19 +546,21 @@ else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) { SnapshotOperation op = snapshotOperationMsg.snapshotOperation(); if (op.type() == SnapshotOperationType.RESTORE) { - if (reqs != null) - reqs = new ArrayList<>(reqs); - else - reqs = new ArrayList<>(); + assert exchActions == null; + + exchActions = new ExchangeActions(); List destroyRequests = getStopCacheRequests( cctx.cache(), op.cacheNames(), cctx.localNodeId()); - reqs.addAll(destroyRequests); + if (!F.isEmpty(destroyRequests)) { //Emulate destroy cache request + for (DynamicCacheChangeRequest req : destroyRequests) { + exchActions.addCacheToStop(req, cctx.cache() + .cacheDescriptor(CU.cacheId(req.cacheName()))); + } - if (!reqs.isEmpty()) { //Emulate destroy cache request if (op.type() == SnapshotOperationType.RESTORE) - cctx.cache().onCustomEvent(new DynamicCacheChangeBatch(reqs), topVer); + cctx.cache().onCustomEvent(new DynamicCacheChangeBatch(destroyRequests), topVer); onCacheChangeRequest(crdNode); } @@ -591,9 +593,6 @@ else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) { updateTopologies(crdNode); - if (exchActions != null && exchActions.hasStop()) - cctx.cache().context().database().beforeCachesStop(); - switch (exchange) { case ALL: { distributedExchange(); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 632bdaf528154..0b2019570fac3 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -527,7 +527,7 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { } /** {@inheritDoc} */ - @Override protected long[] calculateFragmentSizes(int concLvl, long cacheSize) { + protected long[] calculateFragmentSizes(int concLvl, long cacheSize) { if (concLvl < 2) concLvl = Runtime.getRuntime().availableProcessors(); @@ -549,11 +549,15 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { /** {@inheritDoc} */ @Override protected PageMemory createPageMemory( DirectMemoryProvider memProvider, - int pageSize, - MemoryPolicyConfiguration cfg, + MemoryConfiguration memCfg, + MemoryPolicyConfiguration plcCfg, MemoryMetricsImpl memMetrics ) { - return new PageMemoryImpl(memProvider, cctx, pageSize, + return new PageMemoryImpl( + memProvider, + calculateFragmentSizes(memCfg.getConcurrencyLevel(), plcCfg.getMaxSize()), + cctx, + memCfg.getPageSize(), new GridInClosure3X() { @Override public void applyx( FullPageId fullId, @@ -659,7 +663,7 @@ private void shutdownCheckpointer(boolean cancel) { if (cctx.kernalContext().query().moduleEnabled()) { for (GridCacheContext cacheCtx : (Collection)cctx.cacheContexts()) { - if (fut.isCacheAdded(cacheCtx.cacheId(), fut.topologyVersion()) && + if (fut.cacheAddedOnExchange(cacheCtx.cacheId(), cacheCtx.receivedFrom()) && !cctx.pageStore().hasIndexStore(cacheCtx.cacheId()) && cacheCtx.affinityNode()) { final int cacheId = cacheCtx.cacheId(); @@ -876,7 +880,7 @@ public void restoreState() throws IgniteCheckedException { continue; for (GridDhtLocalPartition part : cacheCtx.topology().currentLocalPartitions()) { - if (part.state() != GridDhtPartitionState.OWNING || part.size() <= ggWalRebalanceThreshold) + if (part.state() != GridDhtPartitionState.OWNING || part.publicSize() <= ggWalRebalanceThreshold) continue; for (Long cpTs : checkpointHist.checkpoints()) { diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java index af3418b98f7aa..4a7f1c58949bb 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java @@ -21,10 +21,12 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; @@ -38,7 +40,6 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.mem.DirectMemory; import org.apache.ignite.internal.mem.DirectMemoryProvider; import org.apache.ignite.internal.mem.DirectMemoryRegion; import org.apache.ignite.internal.mem.IgniteOutOfMemoryException; @@ -220,6 +221,9 @@ public class PageMemoryImpl implements PageMemoryEx { /** */ private boolean pageEvictWarned; + /** */ + private long[] sizes; + /** * @param directMemoryProvider Memory allocator to use. * @param sharedCtx Cache shared context. @@ -229,6 +233,7 @@ public class PageMemoryImpl implements PageMemoryEx { */ public PageMemoryImpl( DirectMemoryProvider directMemoryProvider, + long[] sizes, GridCacheSharedContext sharedCtx, int pageSize, GridInClosure3X flushDirtyPage, @@ -238,8 +243,10 @@ public PageMemoryImpl( assert sharedCtx != null; log = sharedCtx.logger(PageMemoryImpl.class); + this.sharedCtx = sharedCtx; this.directMemoryProvider = directMemoryProvider; + this.sizes = sizes; this.flushDirtyPage = flushDirtyPage; this.changeTracker = changeTracker; this.stateChecker = stateChecker; @@ -257,18 +264,26 @@ public PageMemoryImpl( /** {@inheritDoc} */ @Override public void start() throws IgniteException { - if (directMemoryProvider instanceof LifecycleAware) - ((LifecycleAware)directMemoryProvider).start(); + directMemoryProvider.initialize(sizes); + + List regions = new ArrayList<>(sizes.length); - DirectMemory memory = directMemoryProvider.memory(); + while (true) { + DirectMemoryRegion reg = directMemoryProvider.nextRegion(); + + if (reg == null) + break; + + regions.add(reg); + } nioAccess = SharedSecrets.getJavaNioAccess(); - int regs = memory.regions().size(); + int regs = regions.size(); segments = new Segment[regs - 1]; - DirectMemoryRegion cpReg = memory.regions().get(regs - 1); + DirectMemoryRegion cpReg = regions.get(regs - 1); checkpointPool = new PagePool(regs - 1, cpReg); @@ -281,11 +296,11 @@ public PageMemoryImpl( for (int i = 0; i < regs - 1; i++) { assert i < segments.length; - DirectMemoryRegion reg = memory.regions().get(i); + DirectMemoryRegion reg = regions.get(i); totalAllocated += reg.size(); - segments[i] = new Segment(i, memory.regions().get(i), checkpointPool.pages() / segments.length); + segments[i] = new Segment(i, regions.get(i), checkpointPool.pages() / segments.length); pages += segments[i].pages(); totalTblSize += segments[i].tableSize(); @@ -305,6 +320,8 @@ public PageMemoryImpl( if (log.isDebugEnabled()) log.debug("Stopping page memory."); + directMemoryProvider.shutdown(); + if (directMemoryProvider instanceof LifecycleAware) ((LifecycleAware)directMemoryProvider).stop(); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index 663fe5bcb9587..cd09e89459c8f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -107,7 +107,8 @@ public abstract class IgnitePersistentStoreCacheRebalancingAbstractTest extends MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(100 * 1024 * 1024); + memPlcCfg.setMaxSize(100 * 1024 * 1024); + memPlcCfg.setInitialSize(100 * 1024 * 1024); memPlcCfg.setSwapFilePath("work/swap"); dbCfg.setMemoryPolicies(memPlcCfg); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java index ff577e52259da..f666a23b022e0 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java @@ -63,7 +63,8 @@ public class IgnitePersistentStoreContinuousRestartSelfTest extends GridCommonAb MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(400 * 1024 * 1024); + memPlcCfg.setMaxSize(400 * 1024 * 1024); + memPlcCfg.setInitialSize(400 * 1024 * 1024); dbCfg.setMemoryPolicies(memPlcCfg); dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java index 548c9d4e7837f..cda2a4ab3315a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java @@ -73,7 +73,8 @@ public class IgnitePersistentStoreDynamicCacheTest extends IgniteDbDynamicCacheS MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(200 * 1024 * 1024); + memPlcCfg.setInitialSize(200 * 1024 * 1024); + memPlcCfg.setMaxSize(200 * 1024 * 1024); dbCfg.setMemoryPolicies(memPlcCfg); dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java index 45d5490eb6550..d67aafe4c6154 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java @@ -75,7 +75,8 @@ public IgnitePersistentStoreMultiNodePutGetRestartSelfTest() { MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(100 * 1024 * 1024); + memPlcCfg.setInitialSize(100 * 1024 * 1024); + memPlcCfg.setMaxSize(100 * 1024 * 1024); memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); memCfg.setMemoryPolicies(memPlcCfg); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java index 9fc349bbc5356..697bc49ce59e9 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java @@ -49,7 +49,8 @@ public class IgnitePersistentStorePageSizesTest extends GridCommonAbstractTest { MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(100 * 1024 * 1024); + memPlcCfg.setInitialSize(100 * 1024 * 1024); + memPlcCfg.setMaxSize(100 * 1024 * 1024); memCfg.setMemoryPolicies(memPlcCfg); memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java index af3ebe6b6091b..fbed6ee755778 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java @@ -72,7 +72,8 @@ public class IgnitePersistentStoreRecoveryAfterFileCorruptionTest extends GridCo MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(1024 * 1024 * 1024); + memPlcCfg.setInitialSize(1024 * 1024 * 1024); + memPlcCfg.setMaxSize(1024 * 1024 * 1024); dbCfg.setMemoryPolicies(memPlcCfg); dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java index 24238169be659..6b37a3a22edaf 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java @@ -63,7 +63,8 @@ public class IgnitePersistentStoreRemoveDuringRebalancingSelfTest extends GridCo MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(100 * 1024 * 1024); + memPlcCfg.setInitialSize(100 * 1024 * 1024); + memPlcCfg.setMaxSize(100 * 1024 * 1024); memPlcCfg.setSwapFilePath("db"); dbCfg.setMemoryPolicies(memPlcCfg); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java index 89bab33baf59f..692117d546e7f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java @@ -54,7 +54,8 @@ public class IgnitePersistentStoreWalTlbSelfTest extends GridCommonAbstractTest MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(100 * 1024 * 1024); + memPlcCfg.setInitialSize(100 * 1024 * 1024); + memPlcCfg.setMaxSize(100 * 1024 * 1024); memCfg.setMemoryPolicies(memPlcCfg); memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java index aac609711631a..dfbc54870ee63 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java @@ -63,7 +63,8 @@ public class DbPageEvictionDuringPartitionClearSelfTest extends GridCommonAbstra MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); - memPlcCfg.setSize(70 * 1024 * 1024); + memPlcCfg.setInitialSize(70 * 1024 * 1024); + memPlcCfg.setMaxSize(70 * 1024 * 1024); memPlcCfg.setName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java index ca1d8273b205e..d9f9a54787944 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java @@ -64,7 +64,8 @@ public class IgniteDbMultiNodePutGetRestartSelfTest extends GridCommonAbstractTe MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(100 * 1024 * 1024); + memPlcCfg.setInitialSize(100 * 1024 * 1024); + memPlcCfg.setMaxSize(100 * 1024 * 1024); dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); dbCfg.setMemoryPolicies(memPlcCfg); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java index 697b26ac96fe4..b7a57734b78f4 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java @@ -63,7 +63,8 @@ public class IgniteDbPageEvictionSelfTest extends GridCommonAbstractTest { MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(50 * 1024 * 1024); + memPlcCfg.setInitialSize(50 * 1024 * 1024); + memPlcCfg.setMaxSize(50 * 1024 * 1024); dbCfg.setMemoryPolicies(memPlcCfg); dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java index 5765780d5337f..cce3b6ec292aa 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java @@ -58,7 +58,8 @@ public class IgniteDbWholeClusterRestartSelfTest extends GridCommonAbstractTest MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(100 * 1024 * 1024); + memPlcCfg.setInitialSize(100 * 1024 * 1024); + memPlcCfg.setMaxSize(100 * 1024 * 1024); dbCfg.setMemoryPolicies(memPlcCfg); dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java index 3cc02a2c20a5a..d8df9738d83d9 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java @@ -174,7 +174,8 @@ public void test() throws Exception { MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(200 * 1024 * 1024); + memPlcCfg.setInitialSize(200 * 1024 * 1024); + memPlcCfg.setMaxSize(200 * 1024 * 1024); memCfg.setMemoryPolicies(memPlcCfg); memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java index 99caf8c880652..60d7f70815dfd 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java @@ -134,7 +134,8 @@ public class TransactionsHangTest extends GridCommonAbstractTest { MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(PAGE_CACHE_SIZE * 1024 * 1024); + memPlcCfg.setInitialSize(PAGE_CACHE_SIZE * 1024 * 1024); + memPlcCfg.setMaxSize(PAGE_CACHE_SIZE * 1024 * 1024); memCfg.setMemoryPolicies(memPlcCfg); memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java index 47fe4a570a96f..9107b1cf89626 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java @@ -67,7 +67,8 @@ public class IgniteCachePageStoreIntegrationSelfTest extends GridCommonAbstractT MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(100 * 1024 * 1024); + memPlcCfg.setInitialSize(100 * 1024 * 1024); + memPlcCfg.setMaxSize(100 * 1024 * 1024); dbCfg.setMemoryPolicies(memPlcCfg); dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java index af27ee11b3cd1..a92a29f2eff67 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java @@ -54,7 +54,8 @@ public class IgniteWalHistoryReservationsSelfTest extends GridCommonAbstractTest MemoryConfiguration memCfg = new MemoryConfiguration(); - memCfg.setMemoryPolicies(new MemoryPolicyConfiguration().setSize(200 * 1024 * 1024).setName("dfltMemPlc")); + memCfg.setMemoryPolicies(new MemoryPolicyConfiguration().setInitialSize(200 * 1024 * 1024) + .setMaxSize(200 * 1024 * 1024).setName("dfltMemPlc")); memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java index fd3ed7512861a..b2b034852f039 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java @@ -125,7 +125,8 @@ public class IgniteWalRecoverySelfTest extends GridCommonAbstractTest { MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(1024 * 1024 * 1024); + memPlcCfg.setInitialSize(1024 * 1024 * 1024); + memPlcCfg.setMaxSize(1024 * 1024 * 1024); dbCfg.setMemoryPolicies(memPlcCfg); dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java index f38e9f6cfe6d6..e5f1ec187eec6 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java @@ -85,7 +85,8 @@ public class IgniteWalRecoverySeveralRestartsTest extends GridCommonAbstractTest MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setName("dfltMemPlc"); - memPlcCfg.setSize(500 * 1024 * 1024); + memPlcCfg.setInitialSize(500 * 1024 * 1024); + memPlcCfg.setMaxSize(500 * 1024 * 1024); dbCfg.setMemoryPolicies(memPlcCfg); dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java index c1ec4ed629c73..275ed3fa621cb 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java @@ -77,7 +77,8 @@ private MemoryConfiguration createDbConfig() { final MemoryConfiguration dbCfg = new MemoryConfiguration(); MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); - memPlcCfg.setSize(MEMORY_LIMIT); + memPlcCfg.setInitialSize(MEMORY_LIMIT); + memPlcCfg.setMaxSize(MEMORY_LIMIT); memPlcCfg.setName("dfltMemPlc"); dbCfg.setPageSize(PAGE_SIZE); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java index 2b7823350cd7b..4cfc14f4fdd23 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java @@ -60,7 +60,7 @@ public class BPlusTreeReuseListPageMemoryImplSelfTest extends BPlusTreeReuseSelf sizes[CPUS] = 10 * MB; - DirectMemoryProvider provider = new UnsafeMemoryProvider(sizes); + DirectMemoryProvider provider = new UnsafeMemoryProvider(log); GridCacheSharedContext sharedCtx = new GridCacheSharedContext<>( new GridTestKernalContext(log), @@ -80,19 +80,23 @@ public class BPlusTreeReuseListPageMemoryImplSelfTest extends BPlusTreeReuseSelf null ); - PageMemory mem = new PageMemoryImpl(provider, sharedCtx, PAGE_SIZE, + PageMemory mem = new PageMemoryImpl( + provider, sizes, + sharedCtx, + PAGE_SIZE, new CIX3() { - @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { - assert false : "No evictions should happen during the test"; - } - }, new GridInClosure3X() { - @Override public void applyx(Long page, FullPageId fullPageId, PageMemoryEx pageMem) { - } - }, new CheckpointLockStateChecker() { - @Override public boolean checkpointLockIsHeldByThread() { - return true; - } - }); + @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { + assert false : "No evictions should happen during the test"; + } + }, + new GridInClosure3X() { + @Override public void applyx(Long page, FullPageId fullPageId, PageMemoryEx pageMem) { + } + }, new CheckpointLockStateChecker() { + @Override public boolean checkpointLockIsHeldByThread() { + return true; + } + }); mem.start(); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java index d62980656c7f2..82b2de4b89f91 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java @@ -59,7 +59,7 @@ public class BPlusTreeSelfTestPageMemoryImplSelfTest extends BPlusTreeSelfTest { sizes[CPUS] = 10 * MB; - DirectMemoryProvider provider = new UnsafeMemoryProvider(sizes); + DirectMemoryProvider provider = new UnsafeMemoryProvider(log); GridCacheSharedContext sharedCtx = new GridCacheSharedContext<>( new GridTestKernalContext(log), @@ -79,19 +79,24 @@ public class BPlusTreeSelfTestPageMemoryImplSelfTest extends BPlusTreeSelfTest { null ); - PageMemory mem = new PageMemoryImpl(provider, sharedCtx, PAGE_SIZE, + PageMemory mem = new PageMemoryImpl( + provider, sizes, + sharedCtx, + PAGE_SIZE, new CIX3() { - @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { - assert false : "No evictions should happen during the test"; - } - }, new CIX3(){ - @Override public void applyx(Long aLong, FullPageId fullPageId, PageMemoryEx ex) { - } - }, new CheckpointLockStateChecker() { - @Override public boolean checkpointLockIsHeldByThread() { - return true; - } - }); + @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { + assert false : "No evictions should happen during the test"; + } + }, + new CIX3(){ + @Override public void applyx(Long aLong, FullPageId fullPageId, PageMemoryEx ex) { + } + }, + new CheckpointLockStateChecker() { + @Override public boolean checkpointLockIsHeldByThread() { + return true; + } + }); mem.start(); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java index c710164bde599..df212be915a52 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java @@ -26,6 +26,7 @@ import org.apache.ignite.internal.processors.cache.database.pagemem.FullPageIdTable; import org.apache.ignite.internal.util.typedef.CI2; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.logger.java.JavaLogger; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; /** @@ -44,8 +45,11 @@ public class FullPageIdTableTest extends GridCommonAbstractTest { public void testRandomOperations() throws Exception { long mem = FullPageIdTable.requiredMemory(CACHE_ID_RANGE * PAGE_ID_RANGE); - UnsafeMemoryProvider prov = new UnsafeMemoryProvider(new long[] {mem}); - prov.start(); + UnsafeMemoryProvider prov = new UnsafeMemoryProvider(new JavaLogger()); + + prov.initialize(new long[] {mem}); + + DirectMemoryRegion region = prov.nextRegion(); try { long seed = U.currentTimeMillis(); @@ -54,8 +58,6 @@ public void testRandomOperations() throws Exception { Random rnd = new Random(seed); - DirectMemoryRegion region = prov.memory().regions().get(0); - FullPageIdTable tbl = new FullPageIdTable(region.address(), region.size(), true); Map check = new HashMap<>(); @@ -86,7 +88,7 @@ public void testRandomOperations() throws Exception { } } finally { - prov.stop(); + prov.shutdown(); } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java index 270de23a6f184..11e03868c2383 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java @@ -60,7 +60,7 @@ public class MetadataStoragePageMemoryImplSelfTest extends MetadataStorageSelfTe for (int i = 0; i < sizes.length; i++) sizes[i] = 1024 * 1024; - DirectMemoryProvider provider = new MappedFileMemoryProvider(log(), allocationPath, clean, sizes); + DirectMemoryProvider provider = new MappedFileMemoryProvider(log(), allocationPath); GridCacheSharedContext sharedCtx = new GridCacheSharedContext<>( new GridTestKernalContext(log), @@ -80,18 +80,22 @@ public class MetadataStoragePageMemoryImplSelfTest extends MetadataStorageSelfTe null ); - return new PageMemoryImpl(provider, sharedCtx, PAGE_SIZE, + return new PageMemoryImpl( + provider, sizes, + sharedCtx, + PAGE_SIZE, new CIX3() { - @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { - assert false : "No evictions should happen during the test"; - } - }, new GridInClosure3X() { - @Override public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) { - } - }, new CheckpointLockStateChecker() { - @Override public boolean checkpointLockIsHeldByThread() { - return true; - } - }); + @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { + assert false : "No evictions should happen during the test"; + } + }, + new GridInClosure3X() { + @Override public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) { + } + }, new CheckpointLockStateChecker() { + @Override public boolean checkpointLockIsHeldByThread() { + return true; + } + }); } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java index e0fbcf415973c..a37f981ad1af8 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java @@ -34,6 +34,7 @@ import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.logger.java.JavaLogger; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; /** @@ -151,16 +152,19 @@ private void printPageIdDistribution( * @throws Exception If failed. */ public void _testRealHistory() throws Exception { - int cap = CACHE_IDS.length * PARTS * PAGES; + int capacity = CACHE_IDS.length * PARTS * PAGES; - info("Capacity: " + cap); + info("Capacity: " + capacity); - long mem = FullPageIdTable.requiredMemory(cap); + long mem = FullPageIdTable.requiredMemory(capacity); info(U.readableSize(mem, true)); - UnsafeMemoryProvider prov = new UnsafeMemoryProvider(new long[] {mem}); - prov.start(); + UnsafeMemoryProvider prov = new UnsafeMemoryProvider(new JavaLogger()); + + prov.initialize(new long[] {mem}); + + DirectMemoryRegion region = prov.nextRegion(); try { long seed = U.currentTimeMillis(); @@ -169,13 +173,11 @@ public void _testRealHistory() throws Exception { Random rnd = new Random(seed); - DirectMemoryRegion region = prov.memory().regions().get(0); - FullPageIdTable tbl = new FullPageIdTable(region.address(), region.size(), true); Map, Integer> allocated = new HashMap<>(); - for (int i = 0; i < cap; i++) { + for (int i = 0; i < capacity; i++) { int cacheId = CACHE_IDS[rnd.nextInt(CACHE_IDS.length)]; int partId = rnd.nextInt(PARTS); @@ -196,7 +198,7 @@ public void _testRealHistory() throws Exception { info("Done: " + i); } - int[] scans = new int[cap]; + int[] scans = new int[capacity]; int cur = 0; @@ -226,7 +228,7 @@ public void _testRealHistory() throws Exception { } } finally { - prov.stop(); + prov.shutdown(); } } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java index 843aede17efad..141ce82f1ef1c 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java @@ -26,10 +26,10 @@ import org.apache.ignite.internal.pagemem.impl.PageMemoryNoLoadSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; import org.apache.ignite.internal.util.lang.GridInClosure3X; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; import org.apache.ignite.internal.util.typedef.CIX3; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.junits.GridTestKernalContext; @@ -49,8 +49,7 @@ public class PageMemoryImplNoLoadSelfTest extends PageMemoryNoLoadSelfTest { for (int i = 0; i < sizes.length; i++) sizes[i] = 5 * 1024 * 1024; - DirectMemoryProvider provider = new MappedFileMemoryProvider(log(), memDir, true, - sizes); + DirectMemoryProvider provider = new MappedFileMemoryProvider(log(), memDir); GridCacheSharedContext sharedCtx = new GridCacheSharedContext<>( new GridTestKernalContext(log), @@ -70,7 +69,11 @@ public class PageMemoryImplNoLoadSelfTest extends PageMemoryNoLoadSelfTest { null ); - return new PageMemoryImpl(provider, sharedCtx, PAGE_SIZE, + return new PageMemoryImpl( + provider, + sizes, + sharedCtx, + PAGE_SIZE, new CIX3() { @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuffer, Integer tag) { assert false : "No evictions should happen during the test"; @@ -79,11 +82,12 @@ public class PageMemoryImplNoLoadSelfTest extends PageMemoryNoLoadSelfTest { new GridInClosure3X() { @Override public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) { } - }, new CheckpointLockStateChecker() { - @Override public boolean checkpointLockIsHeldByThread() { - return true; - } - }); + }, + new CheckpointLockStateChecker() { + @Override public boolean checkpointLockIsHeldByThread() { + return true; + } + }); } /** {@inheritDoc} */ diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java index 9b879e2673353..bbcd383c32854 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java @@ -72,7 +72,7 @@ private PageMemoryImpl createPageMemory() throws Exception { sizes[4] = 10 * MB; - DirectMemoryProvider provider = new UnsafeMemoryProvider(sizes); + DirectMemoryProvider provider = new UnsafeMemoryProvider(log); GridCacheSharedContext sharedCtx = new GridCacheSharedContext<>( new GridTestKernalContext(new GridTestLog4jLogger()), @@ -92,19 +92,24 @@ private PageMemoryImpl createPageMemory() throws Exception { null ); - PageMemoryImpl mem = new PageMemoryImpl(provider, sharedCtx, PAGE_SIZE, + PageMemoryImpl mem = new PageMemoryImpl( + provider, + sizes, + sharedCtx, + PAGE_SIZE, new CIX3() { - @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { - assert false : "No evictions should happen during the test"; - } - }, new GridInClosure3X() { - @Override public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) { - } - }, new CheckpointLockStateChecker() { - @Override public boolean checkpointLockIsHeldByThread() { - return true; - } - }); + @Override public void applyx(FullPageId fullPageId, ByteBuffer byteBuf, Integer tag) { + assert false : "No evictions should happen during the test"; + } + }, + new GridInClosure3X() { + @Override public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) { + } + }, new CheckpointLockStateChecker() { + @Override public boolean checkpointLockIsHeldByThread() { + return true; + } + }); mem.start(); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java index b2ca19a3b5553..801d51908ac3c 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java @@ -344,7 +344,8 @@ private void stopAll(String suffix) { memCfg.setConcurrencyLevel(64); MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); - memPlcCfg.setSize(5 * 1024 * 1024); + memPlcCfg.setInitialSize(5 * 1024 * 1024); + memPlcCfg.setMaxSize(5 * 1024 * 1024); memPlcCfg.setName("dfltMemPlc"); memCfg.setMemoryPolicies(memPlcCfg); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java index 8c9854ac09e7d..02168bcb9c1c5 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java @@ -73,7 +73,8 @@ public class GridActivateExtensionTest extends GridCacheAbstractFullApiSelfTest MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); - memPlcCfg.setSize(5 * 1024 * 1024); + memPlcCfg.setInitialSize(5 * 1024 * 1024); + memPlcCfg.setMaxSize(5 * 1024 * 1024); memPlcCfg.setName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java index dd82dfa0eea38..c3e5a703253cb 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java @@ -32,7 +32,6 @@ import org.apache.ignite.cache.database.pagemem.BPlusTreeSelfTestPageMemoryImplSelfTest; import org.apache.ignite.cache.database.pagemem.MetadataStoragePageMemoryImplSelfTest; import org.apache.ignite.cache.database.pagemem.PageMemoryImplNoLoadSelfTest; -import org.apache.ignite.cache.database.pagemem.PageMemoryImplReloadSelfTest; import org.apache.ignite.cache.database.pagemem.PageMemoryImplTest; import org.apache.ignite.internal.processors.database.IgniteDbClientNearCachePutGetTest; import org.apache.ignite.internal.processors.database.IgniteDbDynamicCacheSelfTest; @@ -56,7 +55,6 @@ public static TestSuite suite() throws Exception { // Basic PageMemory tests. suite.addTestSuite(PageMemoryImplNoLoadSelfTest.class); - suite.addTestSuite(PageMemoryImplReloadSelfTest.class); suite.addTestSuite(MetadataStoragePageMemoryImplSelfTest.class); suite.addTestSuite(PageStoreEvictionSelfTest.class); suite.addTestSuite(PageMemoryImplTest.class); From 1924873b26d0704eb188faa3d6f4e6a4730ac126 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 19 May 2017 19:50:04 +0300 Subject: [PATCH 192/311] Merge branch ignite-gg-8.0.4.ea2 into ignite-gg-12163 --- modules/pds/pom.xml | 2 +- .../IgnitePersistentStoreWalTlbSelfTest.java | 7 +++++-- ...bPageEvictionDuringPartitionClearSelfTest.java | 2 +- .../IgniteDbMultiNodePutGetRestartSelfTest.java | 9 ++++++--- .../database/db/IgniteDbPageEvictionSelfTest.java | 7 +++++-- .../db/RebalancingOnNotStableTopologyTest.java | 10 ++++++---- .../IgniteCachePageStoreIntegrationSelfTest.java | 15 +++++++++------ .../db/file/IgniteNoActualWalHistorySelfTest.java | 9 ++++++--- .../db/file/PageStoreEvictionSelfTest.java | 2 +- .../db/file/WalRecoveryTxLogicalRecordsTest.java | 7 +++++-- 10 files changed, 45 insertions(+), 25 deletions(-) diff --git a/modules/pds/pom.xml b/modules/pds/pom.xml index c3bcec6d0fb21..01385a2cf4438 100644 --- a/modules/pds/pom.xml +++ b/modules/pds/pom.xml @@ -31,7 +31,7 @@ ignite-pds - 2.0.0-SNAPSHOT + 2.1.0-SNAPSHOT 2.4 diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java index 692117d546e7f..d720e87cf9f43 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java @@ -41,11 +41,14 @@ public class IgnitePersistentStoreWalTlbSelfTest extends GridCommonAbstractTest /** Ip finder. */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + /** Cache name. */ + private static final String CACHE_NAME = "cache"; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - CacheConfiguration ccfg = new CacheConfiguration<>(); + CacheConfiguration ccfg = new CacheConfiguration<>(CACHE_NAME); cfg.setCacheConfiguration(ccfg); @@ -119,7 +122,7 @@ public void testWalDirectOutOfMemory() throws Exception { boolean locked = true; try { - IgniteDataStreamer streamer = ig.dataStreamer(null); + IgniteDataStreamer streamer = ig.dataStreamer(CACHE_NAME); for (int i = 0; i < 100_000; i++) { streamer.addData(i, 1); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java index dfbc54870ee63..05067bd365c68 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java @@ -48,7 +48,7 @@ public class DbPageEvictionDuringPartitionClearSelfTest extends GridCommonAbstra @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - CacheConfiguration ccfg = new CacheConfiguration("cache") + CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME) .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC) .setAffinity(new RendezvousAffinityFunction(false, 128)) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java index d9f9a54787944..a0fc4bdfed94f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java @@ -55,6 +55,9 @@ public class IgniteDbMultiNodePutGetRestartSelfTest extends GridCommonAbstractTe /** */ private static final int GRID_CNT = 3; + /** */ + private static final String CACHE_NAME = "cache"; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); @@ -72,7 +75,7 @@ public class IgniteDbMultiNodePutGetRestartSelfTest extends GridCommonAbstractTe cfg.setMemoryConfiguration(dbCfg); - CacheConfiguration ccfg = new CacheConfiguration(); + CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME); ccfg.setIndexedTypes(Integer.class, DbValue.class); @@ -161,10 +164,10 @@ public void testPutGetSimple() throws Exception { * @param write Write. */ private void checkPutGetSql(IgniteEx ig, boolean write) { - IgniteCache cache = ig.cache(null); + IgniteCache cache = ig.cache(CACHE_NAME); if (write) { - try (IgniteDataStreamer streamer = ig.dataStreamer(null)) { + try (IgniteDataStreamer streamer = ig.dataStreamer(CACHE_NAME)) { for (int i = 0; i < 10_000; i++) streamer.addData(i, new DbValue(i, "value-" + i, i)); } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java index b7a57734b78f4..1d1ca46f467a1 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java @@ -50,6 +50,9 @@ public class IgniteDbPageEvictionSelfTest extends GridCommonAbstractTest { /** Test entry count. */ public static final int ENTRY_CNT = 1_000_000; + /** Cache name. */ + private static final String CACHE_NAME = "cache"; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); @@ -116,7 +119,7 @@ public class IgniteDbPageEvictionSelfTest extends GridCommonAbstractTest { public void testPageEvictionSql() throws Exception { IgniteEx ig = grid(0); - try (IgniteDataStreamer streamer = ig.dataStreamer(null)) { + try (IgniteDataStreamer streamer = ig.dataStreamer(CACHE_NAME)) { for (int i = 0; i < ENTRY_CNT; i++) { streamer.addData(new DbKey(i), new DbValue(i, "value-" + i, Long.MAX_VALUE - i)); @@ -125,7 +128,7 @@ public void testPageEvictionSql() throws Exception { } } - IgniteCache cache = ignite(0).cache(null); + IgniteCache cache = ignite(0).cache(CACHE_NAME); for (int i = 0; i < ENTRY_CNT; i++) { assertEquals(Long.MAX_VALUE - i, cache.get(new DbKey(i)).lVal); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java index d8df9738d83d9..d6385705c1c23 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java @@ -49,6 +49,9 @@ public class RebalancingOnNotStableTopologyTest extends GridCommonAbstractTest { /** Cluster size. */ private static final int CLUSTER_SIZE = 5; + /** */ + private static final String CACHE_NAME = "cache1"; + /** * @throws Exception When fails. */ @@ -76,7 +79,7 @@ public void test() throws Exception { startLatch.countDown(); - IgniteCache cache1 = ex1.cache("cache1"); + IgniteCache cache1 = ex1.cache(CACHE_NAME); int key = keyCnt.get(); @@ -136,7 +139,7 @@ public void test() throws Exception { checkTopology(CLUSTER_SIZE); - IgniteCache cache1 = ex.cache("cache1"); + IgniteCache cache1 = ex.cache(CACHE_NAME); assert keyCnt.get() > 0; @@ -152,9 +155,8 @@ public void test() throws Exception { cfg.setActiveOnStart(false); - CacheConfiguration ccfg = new CacheConfiguration<>(); + CacheConfiguration ccfg = new CacheConfiguration<>(CACHE_NAME); - ccfg.setName("cache1"); ccfg.setPartitionLossPolicy(PartitionLossPolicy.READ_ONLY_SAFE); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); ccfg.setCacheMode(CacheMode.PARTITIONED); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java index 9107b1cf89626..c0416d92ea835 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java @@ -56,6 +56,9 @@ public class IgniteCachePageStoreIntegrationSelfTest extends GridCommonAbstractT /** */ private static final int GRID_CNT = 3; + /** */ + private static final String CACHE_NAME = "cache"; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); @@ -77,7 +80,7 @@ public class IgniteCachePageStoreIntegrationSelfTest extends GridCommonAbstractT cfg.setMemoryConfiguration(dbCfg); - CacheConfiguration ccfg = new CacheConfiguration(); + CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME); ccfg.setIndexedTypes(Integer.class, DbValue.class); @@ -167,7 +170,7 @@ public void testPutMultithreaded() throws Exception { GridTestUtils.runMultiThreaded(new Callable() { @Override public Object call() throws Exception { for (int i = 0; i < 1000; i++) - grid.cache(null).put(i, i); + grid.cache(CACHE_NAME).put(i, i); return null; } @@ -183,12 +186,12 @@ public void testPutMultithreaded() throws Exception { * @param write Write flag. */ private void checkPutGetSql(Ignite ig, boolean write) { - IgniteCache cache = ig.cache(null); + IgniteCache cache = ig.cache(CACHE_NAME); int entryCnt = 50_000; if (write) { - try (IgniteDataStreamer streamer = ig.dataStreamer(null)) { + try (IgniteDataStreamer streamer = ig.dataStreamer(CACHE_NAME)) { streamer.allowOverwrite(true); for (int i = 0; i < entryCnt; i++) @@ -199,12 +202,12 @@ private void checkPutGetSql(Ignite ig, boolean write) { for (int i = 0; i < GRID_CNT; i++) { IgniteEx ignite = grid(i); - GridCacheAdapter cache0 = ignite.context().cache().internalCache(null); + GridCacheAdapter cache0 = ignite.context().cache().internalCache(CACHE_NAME); for (int k = 0; k < entryCnt; k++) assertNull(cache0.peekEx(i)); - assertEquals(entryCnt, ignite.cache(null).size()); + assertEquals(entryCnt, ignite.cache(CACHE_NAME).size()); } for (int i = 0; i < entryCnt; i++) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java index c53766ca2d072..f98bdedb86e36 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java @@ -42,11 +42,14 @@ * */ public class IgniteNoActualWalHistorySelfTest extends GridCommonAbstractTest { + /** Cache name. */ + private static final String CACHE_NAME = "cache"; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - CacheConfiguration ccfg = new CacheConfiguration<>(); + CacheConfiguration ccfg = new CacheConfiguration<>(CACHE_NAME); ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); ccfg.setRebalanceMode(CacheRebalanceMode.SYNC); @@ -104,7 +107,7 @@ public void testWalBig() throws Exception { try { IgniteEx ignite = startGrid(1); - IgniteCache cache = ignite.cache(null); + IgniteCache cache = ignite.cache(CACHE_NAME); Random rnd = new Random(); @@ -147,7 +150,7 @@ public void testWalBig() throws Exception { ignite = startGrid(1); - cache = ignite.cache(null); + cache = ignite.cache(CACHE_NAME); // Check. for (Integer k : map.keySet()) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java index 275ed3fa621cb..1c4358265c52f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java @@ -23,8 +23,8 @@ import java.util.concurrent.Callable; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistenceConfiguration; import org.apache.ignite.internal.IgniteEx; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java index e3e35a750fdfb..8b78c2150e250 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java @@ -71,6 +71,9 @@ public class WalRecoveryTxLogicalRecordsTest extends GridCommonAbstractTest { /** Cache name. */ private static final String CACHE_NAME = "cache"; + /** Cache 2 name. */ + private static final String CACHE2_NAME = "cache2"; + /** */ public static final int PARTS = 32; @@ -297,7 +300,7 @@ public void testWalRecoveryRemoves() throws Exception { * @throws Exception if failed. */ public void testRebalanceIterator() throws Exception { - extraCcfg = new CacheConfiguration(CACHE_NAME + "2"); + extraCcfg = new CacheConfiguration(CACHE2_NAME); extraCcfg.setAffinity(new RendezvousAffinityFunction(false, PARTS)); Ignite ignite = startGrid(); @@ -312,7 +315,7 @@ public void testRebalanceIterator() throws Exception { int entries = 25; IgniteCache cache = ignite.cache(CACHE_NAME); - IgniteCache cache2 = ignite.cache(CACHE_NAME + "2"); + IgniteCache cache2 = ignite.cache(CACHE2_NAME); for (int i = 0; i < entries; i++) { // Put to partition 0. From 39b440fccf5aee8d37aaa742b84e7f286b259c2e Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 19 May 2017 20:37:50 +0300 Subject: [PATCH 193/311] Merge branch master into ignite-gg-12163 --- .../database/GridCacheDatabaseSharedManager.java | 4 ++-- .../cache/database/pagemem/PageMemoryImpl.java | 15 --------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 0b2019570fac3..08857eec75d87 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -663,7 +663,7 @@ private void shutdownCheckpointer(boolean cancel) { if (cctx.kernalContext().query().moduleEnabled()) { for (GridCacheContext cacheCtx : (Collection)cctx.cacheContexts()) { - if (fut.cacheAddedOnExchange(cacheCtx.cacheId(), cacheCtx.receivedFrom()) && + if (cacheCtx.startTopologyVersion().equals(fut.topologyVersion()) && !cctx.pageStore().hasIndexStore(cacheCtx.cacheId()) && cacheCtx.affinityNode()) { final int cacheId = cacheCtx.cacheId(); @@ -880,7 +880,7 @@ public void restoreState() throws IgniteCheckedException { continue; for (GridDhtLocalPartition part : cacheCtx.topology().currentLocalPartitions()) { - if (part.state() != GridDhtPartitionState.OWNING || part.publicSize() <= ggWalRebalanceThreshold) + if (part.state() != GridDhtPartitionState.OWNING || part.dataStore().size() <= ggWalRebalanceThreshold) continue; for (Long cpTs : checkpointHist.checkpoints()) { diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java index 4a7f1c58949bb..21ebcbf05646d 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java @@ -17,8 +17,6 @@ package org.apache.ignite.internal.processors.cache.database.pagemem; -import java.io.Closeable; -import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; @@ -72,7 +70,6 @@ import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiTuple; -import org.apache.ignite.lifecycle.LifecycleAware; import sun.misc.JavaNioAccess; import sun.misc.SharedSecrets; import sun.nio.ch.DirectBuffer; @@ -321,18 +318,6 @@ public PageMemoryImpl( log.debug("Stopping page memory."); directMemoryProvider.shutdown(); - - if (directMemoryProvider instanceof LifecycleAware) - ((LifecycleAware)directMemoryProvider).stop(); - - if (directMemoryProvider instanceof Closeable) { - try { - ((Closeable)directMemoryProvider).close(); - } - catch (IOException e) { - throw new IgniteException(e); - } - } } /** {@inheritDoc} */ From 3f92485680647353f2cf9e774f6c4b891072e1ee Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 22 May 2017 11:09:23 +0300 Subject: [PATCH 194/311] ignite-gg-12163 fix null cache name, fix eviction test (init memory size) --- .../database/db/IgniteDbPageEvictionSelfTest.java | 14 +++++++------- .../db/file/PageStoreEvictionSelfTest.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java index 1d1ca46f467a1..ed68b64874519 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java @@ -57,11 +57,11 @@ public class IgniteDbPageEvictionSelfTest extends GridCommonAbstractTest { @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - MemoryConfiguration dbCfg = new MemoryConfiguration(); + MemoryConfiguration memCfg = new MemoryConfiguration(); - dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); + memCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); - dbCfg.setPageSize(1024); + memCfg.setPageSize(1024); MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); @@ -69,12 +69,12 @@ public class IgniteDbPageEvictionSelfTest extends GridCommonAbstractTest { memPlcCfg.setInitialSize(50 * 1024 * 1024); memPlcCfg.setMaxSize(50 * 1024 * 1024); - dbCfg.setMemoryPolicies(memPlcCfg); - dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + memCfg.setMemoryPolicies(memPlcCfg); + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); - cfg.setMemoryConfiguration(dbCfg); + cfg.setMemoryConfiguration(memCfg); - CacheConfiguration ccfg = new CacheConfiguration<>(); + CacheConfiguration ccfg = new CacheConfiguration<>(CACHE_NAME); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); ccfg.setRebalanceMode(CacheRebalanceMode.NONE); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java index 1c4358265c52f..cc43613bc3a4a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java @@ -54,7 +54,7 @@ public class PageStoreEvictionSelfTest extends GridCommonAbstractTest { private static final long CHUNK_SIZE = 1024 * 1024; /** */ - private static final long MEMORY_LIMIT = 5 * CHUNK_SIZE; + private static final long MEMORY_LIMIT = 10 * CHUNK_SIZE; /** */ private static final int PAGES_NUM = 128_000; From 05c6c4ebfba2f820eb1bdfec57cd4fe353d83b49 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Mon, 22 May 2017 11:18:29 +0300 Subject: [PATCH 195/311] Fixed whole cluster restart test --- .../IgniteDbWholeClusterRestartSelfTest.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java index cce3b6ec292aa..fa988f24d19db 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java @@ -34,6 +34,7 @@ import org.apache.ignite.configuration.PersistenceConfiguration; import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.spi.checkpoint.noop.NoopCheckpointSpi; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; /** @@ -76,6 +77,10 @@ public class IgniteDbWholeClusterRestartSelfTest extends GridCommonAbstractTest ccfg1.setBackups(2); cfg.setLateAffinityAssignment(false); + cfg.setActiveOnStart(false); + + // To avoid hostname lookup on start. + cfg.setCheckpointSpi(new NoopCheckpointSpi()); cfg.setCacheConfiguration(ccfg1); @@ -122,6 +127,8 @@ private void deleteWorkFiles() throws IgniteCheckedException { public void testRestarts() throws Exception { startGrids(GRID_CNT); + ignite(0).active(true); + awaitPartitionMapExchange(); try (IgniteDataStreamer ds = ignite(0).dataStreamer(CACHE_NAME)) { @@ -144,16 +151,21 @@ public void testRestarts() throws Exception { for (Integer idx : idxs) startGrid(idx); - for (int g = 0; g < GRID_CNT; g++) { - Ignite ig = ignite(g); + try { + ignite(0).active(true); - for (int k = 0; k < ENTRIES_COUNT; k++) - assertEquals("Failed to read [g=" + g + ", part=" + ig.affinity(CACHE_NAME).partition(k) + - ", nodes=" + ig.affinity(CACHE_NAME).mapKeyToPrimaryAndBackups(k) + ']', - k, ig.cache(CACHE_NAME).get(k)); - } + for (int g = 0; g < GRID_CNT; g++) { + Ignite ig = ignite(g); - stopAllGrids(); + for (int k = 0; k < ENTRIES_COUNT; k++) + assertEquals("Failed to read [g=" + g + ", part=" + ig.affinity(CACHE_NAME).partition(k) + + ", nodes=" + ig.affinity(CACHE_NAME).mapKeyToPrimaryAndBackups(k) + ']', + k, ig.cache(CACHE_NAME).get(k)); + } + } + finally { + stopAllGrids(); + } } } } From 4c575f0f433659760b2f17ea80cbc55d24109551 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Mon, 22 May 2017 12:13:43 +0300 Subject: [PATCH 196/311] ignite-gg-12163 WAL_REBALANCE_THRESHOLD property restored in test --- .../IgniteWalHistoryReservationsSelfTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java index a92a29f2eff67..d4d8de5c693e6 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java @@ -39,6 +39,8 @@ import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_WAL_REBALANCE_THRESHOLD; + /** * */ @@ -71,7 +73,13 @@ public class IgniteWalHistoryReservationsSelfTest extends GridCommonAbstractTest cfg.setCacheConfiguration(ccfg1); - cfg.setPersistenceConfiguration(new PersistenceConfiguration()); + PersistenceConfiguration pstCfg = new PersistenceConfiguration(); + + pstCfg.setPersistenceStorePath("/ramdisk/ignite/db/database"); + pstCfg.setWalStorePath("/ramdisk/ignite/db/wal"); + pstCfg.setWalArchivePath("/ramdisk/ignite/db/wal_archive"); + + cfg.setPersistenceConfiguration(pstCfg); return cfg; } @@ -85,6 +93,8 @@ public class IgniteWalHistoryReservationsSelfTest extends GridCommonAbstractTest /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { + System.clearProperty(IGNITE_WAL_REBALANCE_THRESHOLD); + client = false; stopAllGrids(); @@ -96,6 +106,8 @@ public class IgniteWalHistoryReservationsSelfTest extends GridCommonAbstractTest * @throws Exception If failed. */ public void testReservedOnExchange() throws Exception { + System.setProperty(IGNITE_WAL_REBALANCE_THRESHOLD, "0"); + final int entryCnt = 10_000; final int initGridCnt = 4; @@ -179,6 +191,8 @@ public void testReservedOnExchange() throws Exception { * @throws Exception If failed. */ public void testRemovesArePreloadedIfHistoryIsAvailable() throws Exception { + System.setProperty(IGNITE_WAL_REBALANCE_THRESHOLD, "0"); + int entryCnt = 10_000; Ignite ig0 = startGrids(2); @@ -268,6 +282,8 @@ public void testNodeIsClearedIfHistoryIsUnavailable() throws Exception { * @throws Exception If failed. */ public void testNodeLeftDuringExchange() throws Exception { + System.setProperty(IGNITE_WAL_REBALANCE_THRESHOLD, "0"); + final int entryCnt = 10_000; final int initGridCnt = 4; From 89d0cd2e925b3cd45ec8137b3e06d83fa6c8e55e Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Mon, 22 May 2017 12:26:49 +0300 Subject: [PATCH 197/311] ignite-gg-12163 local-specific configuration removed from test --- .../db/file/IgniteWalHistoryReservationsSelfTest.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java index d4d8de5c693e6..82a6ac13e7c8f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java @@ -73,13 +73,7 @@ public class IgniteWalHistoryReservationsSelfTest extends GridCommonAbstractTest cfg.setCacheConfiguration(ccfg1); - PersistenceConfiguration pstCfg = new PersistenceConfiguration(); - - pstCfg.setPersistenceStorePath("/ramdisk/ignite/db/database"); - pstCfg.setWalStorePath("/ramdisk/ignite/db/wal"); - pstCfg.setWalArchivePath("/ramdisk/ignite/db/wal_archive"); - - cfg.setPersistenceConfiguration(pstCfg); + cfg.setPersistenceConfiguration(new PersistenceConfiguration()); return cfg; } From 90717b4b7230ca5f5e0fd9318d0aa0a6f5e48064 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 22 May 2017 12:51:28 +0300 Subject: [PATCH 198/311] ignite-gg-12163 fix cache name walRecoveryTxLogicalRecordsTest --- .../file/WalRecoveryTxLogicalRecordsTest.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java index 8b78c2150e250..844f2f5fd89da 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java @@ -525,7 +525,7 @@ public void testRecoveryRandomPutRemove() throws Exception { try { pageSize = 1024; - extraCcfg = new CacheConfiguration(); + extraCcfg = new CacheConfiguration(CACHE2_NAME); extraCcfg.setAffinity(new RendezvousAffinityFunction(false, PARTS)); Ignite ignite = startGrid(0); @@ -536,7 +536,7 @@ public void testRecoveryRandomPutRemove() throws Exception { dbMgr.enableCheckpoints(false).get(); IgniteCache cache1 = ignite.cache(CACHE_NAME); - IgniteCache cache2 = ignite.cache(null); + IgniteCache cache2 = ignite.cache(CACHE2_NAME); final int KEYS1 = 100; @@ -592,7 +592,7 @@ public void testRecoveryNoPageLost3() throws Exception { try { pageSize = 1024; checkpointFreq = 100L; - extraCcfg = new CacheConfiguration(); + extraCcfg = new CacheConfiguration(CACHE2_NAME); extraCcfg.setAffinity(new RendezvousAffinityFunction(false, 32)); List pages = null; @@ -603,12 +603,12 @@ public void testRecoveryNoPageLost3() throws Exception { Ignite ignite = startGrid(0); if (pages != null) { - List curPags = allocatedPages(ignite, null); + List curPags = allocatedPages(ignite, CACHE2_NAME); assertEquals("Iter = " + iter, pages, curPags); } - final IgniteCache cache = ignite.cache(null); + final IgniteCache cache = ignite.cache(CACHE2_NAME); final int ops = ThreadLocalRandom.current().nextInt(10) + 10; @@ -629,7 +629,7 @@ public void testRecoveryNoPageLost3() throws Exception { } }, 10, "update"); - pages = allocatedPages(ignite, null); + pages = allocatedPages(ignite, CACHE2_NAME); Ignition.stop(ignite.name(), false); //will make checkpoint } @@ -646,7 +646,7 @@ public void testRecoveryNoPageLost3() throws Exception { private void recoveryNoPageLost(boolean checkpoint) throws Exception { try { pageSize = 1024; - extraCcfg = new CacheConfiguration(); + extraCcfg = new CacheConfiguration(CACHE2_NAME); extraCcfg.setAffinity(new RendezvousAffinityFunction(false, 32)); List pages = null; @@ -665,17 +665,17 @@ private void recoveryNoPageLost(boolean checkpoint) throws Exception { dbMgr.enableCheckpoints(false).get(); if (pages != null) { - List curPags = allocatedPages(ignite, null); + List curPags = allocatedPages(ignite, CACHE2_NAME); assertEquals(pages, curPags); } - IgniteCache cache = ignite.cache(null); + IgniteCache cache = ignite.cache(CACHE2_NAME); for (int i = 0; i < 128; i++) cache.put(cnt.incrementAndGet(), new byte[256 + iter * 100]); - pages = allocatedPages(ignite, null); + pages = allocatedPages(ignite, CACHE2_NAME); ignite.close(); } @@ -722,12 +722,12 @@ private List allocatedPages(Ignite ignite, String cacheName) throws Exc public void testFreeListRecovery() throws Exception { try { pageSize = 1024; - extraCcfg = new CacheConfiguration(); + extraCcfg = new CacheConfiguration(CACHE2_NAME); Ignite ignite = startGrid(0); IgniteCache cache1 = ignite.cache(CACHE_NAME); - IgniteCache cache2 = ignite.cache(null); + IgniteCache cache2 = ignite.cache(CACHE2_NAME); final int KEYS1 = 2048; @@ -752,16 +752,16 @@ public void testFreeListRecovery() throws Exception { } Map, int[]>> cache1_1 = getFreeListData(ignite, CACHE_NAME); - Map, int[]>> cache2_1 = getFreeListData(ignite, null); + Map, int[]>> cache2_1 = getFreeListData(ignite, CACHE2_NAME); T2 rl1_1 = getReuseListData(ignite, CACHE_NAME); - T2 rl2_1 = getReuseListData(ignite, null); + T2 rl2_1 = getReuseListData(ignite, CACHE2_NAME); ignite.close(); ignite = startGrid(0); cache1 = ignite.cache(CACHE_NAME); - cache2 = ignite.cache(null); + cache2 = ignite.cache(CACHE2_NAME); for (int i = 0; i < KEYS1; i++) { cache1.get(i); @@ -769,9 +769,9 @@ public void testFreeListRecovery() throws Exception { } Map, int[]>> cache1_2 = getFreeListData(ignite, CACHE_NAME); - Map, int[]>> cache2_2 = getFreeListData(ignite, null); + Map, int[]>> cache2_2 = getFreeListData(ignite, CACHE2_NAME); T2 rl1_2 = getReuseListData(ignite, CACHE_NAME); - T2 rl2_2 = getReuseListData(ignite, null); + T2 rl2_2 = getReuseListData(ignite, CACHE2_NAME); checkEquals(cache1_1, cache1_2); checkEquals(cache2_1, cache2_2); From cd17ee0fee9c3c5fba357f1190e5ffbe9a7e3681 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Mon, 22 May 2017 14:33:29 +0300 Subject: [PATCH 199/311] Fixed assertion error - page eviction should be before locking entry (cherry picked from commit 711bbb7) --- .../cache/distributed/dht/atomic/GridDhtAtomicCache.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index b8cb56f769509..0dafa2b5f4df1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -1765,6 +1765,8 @@ private void updateAllAsyncInternal0( ctx.shared().database().checkpointReadLock(); try { + ctx.shared().database().ensureFreeSpace(ctx.memoryPolicy()); + // If batch store update is enabled, we need to lock all entries. // First, need to acquire locks on cache entries, then check filter. List locked = lockEntries(req, req.topologyVersion());; @@ -1788,8 +1790,6 @@ private void updateAllAsyncInternal0( // Do not check topology version if topology was locked on near node by // external transaction or explicit lock. if (req.topologyLocked() || !needRemap(req.topologyVersion(), top.topologyVersion())) { - ctx.shared().database().ensureFreeSpace(ctx.memoryPolicy()); - boolean hasNear = ctx.discovery().cacheNearNode(node, name()); // Assign next version for update inside entries lock. From 2625dd8903b6b5ecee2b314ca6916310e65ace5e Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Mon, 22 May 2017 14:40:25 +0300 Subject: [PATCH 200/311] ignite-gg-12163 fix for WAL history reservation was ported, test was fixed --- ...IgniteDhtPartitionHistorySuppliersMap.java | 3 + .../GridCacheDatabaseSharedManager.java | 79 ++++++++++++------- .../IgniteWalHistoryReservationsSelfTest.java | 13 ++- 3 files changed, 66 insertions(+), 29 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionHistorySuppliersMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionHistorySuppliersMap.java index 333eb9733b063..15294c37e217a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionHistorySuppliersMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionHistorySuppliersMap.java @@ -80,6 +80,9 @@ public static IgniteDhtPartitionHistorySuppliersMap empty() { * @param cntr Partition counter. */ public synchronized void put(UUID nodeId, int cacheId, int partId, long cntr) { + if (map == null) + map = new HashMap<>(); + Map, Long> nodeMap = map.get(nodeId); if (nodeMap == null) { diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 08857eec75d87..0ea8b68759eb5 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -883,32 +883,23 @@ public void restoreState() throws IgniteCheckedException { if (part.state() != GridDhtPartitionState.OWNING || part.dataStore().size() <= ggWalRebalanceThreshold) continue; - for (Long cpTs : checkpointHist.checkpoints()) { - try { - CheckpointEntry entry = checkpointHist.entry(cpTs); - - if (!entry.cacheStates.containsKey(cacheCtx.cacheId()) || - !entry.cacheStates.get(cacheCtx.cacheId()).partitions().containsKey(part.id())) - continue; - - WALPointer ptr = searchPartitionCounter(cacheCtx, part.id(), entry.checkpointTimestamp()); - - if (ptr != null && cctx.wal().reserve(ptr)) { - Map> cacheMap = reservedForExchange.get(cacheCtx.cacheId()); + CheckpointEntry cpEntry = searchCheckpointEntry(cacheCtx, part.id(), null); - if (cacheMap == null) { - cacheMap = new HashMap<>(); + try { + if (cpEntry != null && cctx.wal().reserve(cpEntry.cpMark)) { + Map> cacheMap = reservedForExchange.get(cacheCtx.cacheId()); - reservedForExchange.put(cacheCtx.cacheId(), cacheMap); - } + if (cacheMap == null) { + cacheMap = new HashMap<>(); - cacheMap.put(part.id(), new T2<>(entry.partitionCounter(cacheCtx.cacheId(), part.id()), ptr)); + reservedForExchange.put(cacheCtx.cacheId(), cacheMap); } - } - catch (IgniteCheckedException ex) { - U.error(log, "Error while trying to reserve history", ex); - } + cacheMap.put(part.id(), new T2<>(cpEntry.partitionCounter(cacheCtx.cacheId(), part.id()), cpEntry.cpMark)); + } + } + catch (IgniteCheckedException ex) { + U.error(log, "Error while trying to reserve history", ex); } } } @@ -948,7 +939,12 @@ public void restoreState() throws IgniteCheckedException { /** {@inheritDoc} */ @Override public boolean reserveHistoryForPreloading(int cacheId, int partId, long cntr) { - WALPointer ptr = searchPartitionCounter(cctx.cacheContext(cacheId), partId, cntr); + CheckpointEntry cpEntry = searchCheckpointEntry(cctx.cacheContext(cacheId), partId, cntr); + + if (cpEntry == null) + return false; + + WALPointer ptr = cpEntry.cpMark; if (ptr == null) return false; @@ -1063,12 +1059,29 @@ public void cancelOrWaitPartitionDestroy(GridCacheContext cacheCtx, int pa * * @param cacheCtx Cache context. * @param part Partition ID. - * @param partCntrSince Partition counter. - * @return WAL pointer or {@code null} if failed to search. + * @param partCntrSince Partition counter or {@code null} to search for minimal counter. + * @return Checkpoint entry or {@code null} if failed to search. */ - public WALPointer searchPartitionCounter(GridCacheContext cacheCtx, int part, Long partCntrSince) { + @Nullable public WALPointer searchPartitionCounter(GridCacheContext cacheCtx, int part, @Nullable Long partCntrSince) { + CheckpointEntry entry = searchCheckpointEntry(cacheCtx, part, partCntrSince); + + if (entry == null) + return null; + + return entry.cpMark; + } + + /** + * Tries to search for a WAL pointer for the given partition counter start. + * + * @param cacheCtx Cache context. + * @param part Partition ID. + * @param partCntrSince Partition counter or {@code null} to search for minimal counter. + * @return Checkpoint entry or {@code null} if failed to search. + */ + @Nullable private CheckpointEntry searchCheckpointEntry(GridCacheContext cacheCtx, int part, @Nullable Long partCntrSince) { boolean hasGap = false; - WALPointer first = null; + CheckpointEntry first = null; for (Long cpTs : checkpointHist.checkpoints()) { try { @@ -1077,8 +1090,18 @@ public WALPointer searchPartitionCounter(GridCacheContext cacheCtx, int part, Lo Long foundCntr = entry.partitionCounter(cacheCtx.cacheId(), part); if (foundCntr != null) { - if (foundCntr <= partCntrSince) { - first = entry.cpMark; + if (partCntrSince == null) { + if (hasGap) { + first = entry; + + hasGap = false; + } + + if (first == null) + first = entry; + } + else if (foundCntr <= partCntrSince) { + first = entry; hasGap = false; } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java index 82a6ac13e7c8f..e24108582c33a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java @@ -114,6 +114,17 @@ public void testReservedOnExchange() throws Exception { forceCheckpoint(); + for (int k = 0; k < entryCnt; k++) + cache.put(k, k * 2); + + forceCheckpoint(); + + for (int k = 0; k < entryCnt; k++) + cache.put(k, k); + + forceCheckpoint(); + + Lock lock = cache.lock(0); lock.lock(); @@ -329,7 +340,7 @@ public void testNodeLeftDuringExchange() throws Exception { assert reserved; - stopGrid(initGridCnt - 1); + stopGrid(Integer.toString(initGridCnt - 1), true, false); } finally { lock.unlock(); From f3bb4740c3da5a32df03fd8ef2f08ace6ed9ffdc Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 22 May 2017 15:46:41 +0300 Subject: [PATCH 201/311] ignite-gg-12163 IGNITE_PDS_WAL_RECORD_ITERATOR_BUFFER_SIZE for avoid OOM --- .../cache/database/wal/FileWriteAheadLogManager.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java index 30b56d72dbf49..1ef9384d0d97c 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -109,6 +109,9 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl /** */ public static final String IGNITE_PDS_WAL_FSYNC_DELAY = "IGNITE_PDS_WAL_FSYNC_DELAY"; // TODO may be move to config + /** Ignite pds wal record iterator buffer size. */ + public static final String IGNITE_PDS_WAL_RECORD_ITERATOR_BUFFER_SIZE = "IGNITE_PDS_WAL_RECORD_ITERATOR_BUFFER_SIZE"; + /** */ public static final String IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES = "IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES"; @@ -1933,6 +1936,10 @@ public static class RecordsIterator extends GridCloseableIteratorAdapter Date: Mon, 22 May 2017 15:56:58 +0300 Subject: [PATCH 202/311] ignite-gg-12163 constant renamed for name consistency reasons --- .../java/org/apache/ignite/IgniteSystemProperties.java | 2 +- .../cache/database/GridCacheDatabaseSharedManager.java | 4 ++-- .../db/file/IgniteWalHistoryReservationsSelfTest.java | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) 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 3842d9bffb0a0..9d368a374de55 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -613,7 +613,7 @@ public final class IgniteSystemProperties { /** * WAL rebalance threshold. */ - public static final String IGNITE_WAL_REBALANCE_THRESHOLD = "IGNITE_WAL_REBALANCE_THRESHOLD"; + public static final String IGNITE_PDS_WAL_REBALANCE_THRESHOLD = "IGNITE_PDS_WAL_REBALANCE_THRESHOLD"; /** Returns true for system properties only avoiding sending sensitive information. */ private static final IgnitePredicate> PROPS_FILTER = new IgnitePredicate>() { diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 0ea8b68759eb5..c1fed9fbeef08 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -129,7 +129,7 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY; import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC; -import static org.apache.ignite.IgniteSystemProperties.IGNITE_WAL_REBALANCE_THRESHOLD; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD; /** * @@ -151,7 +151,7 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan /** */ private final int ggWalRebalanceThreshold = IgniteSystemProperties.getInteger( - IGNITE_WAL_REBALANCE_THRESHOLD, 500_000); + IGNITE_PDS_WAL_REBALANCE_THRESHOLD, 500_000); /** Checkpoint lock hold count. */ private static final ThreadLocal CHECKPOINT_LOCK_HOLD_COUNT = new ThreadLocal() { diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java index e24108582c33a..73d6febf7cc1c 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java @@ -39,7 +39,7 @@ import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import static org.apache.ignite.IgniteSystemProperties.IGNITE_WAL_REBALANCE_THRESHOLD; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD; /** * @@ -87,7 +87,7 @@ public class IgniteWalHistoryReservationsSelfTest extends GridCommonAbstractTest /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - System.clearProperty(IGNITE_WAL_REBALANCE_THRESHOLD); + System.clearProperty(IGNITE_PDS_WAL_REBALANCE_THRESHOLD); client = false; @@ -100,7 +100,7 @@ public class IgniteWalHistoryReservationsSelfTest extends GridCommonAbstractTest * @throws Exception If failed. */ public void testReservedOnExchange() throws Exception { - System.setProperty(IGNITE_WAL_REBALANCE_THRESHOLD, "0"); + System.setProperty(IGNITE_PDS_WAL_REBALANCE_THRESHOLD, "0"); final int entryCnt = 10_000; final int initGridCnt = 4; @@ -196,7 +196,7 @@ public void testReservedOnExchange() throws Exception { * @throws Exception If failed. */ public void testRemovesArePreloadedIfHistoryIsAvailable() throws Exception { - System.setProperty(IGNITE_WAL_REBALANCE_THRESHOLD, "0"); + System.setProperty(IGNITE_PDS_WAL_REBALANCE_THRESHOLD, "0"); int entryCnt = 10_000; @@ -287,7 +287,7 @@ public void testNodeIsClearedIfHistoryIsUnavailable() throws Exception { * @throws Exception If failed. */ public void testNodeLeftDuringExchange() throws Exception { - System.setProperty(IGNITE_WAL_REBALANCE_THRESHOLD, "0"); + System.setProperty(IGNITE_PDS_WAL_REBALANCE_THRESHOLD, "0"); final int entryCnt = 10_000; final int initGridCnt = 4; From e78441c03b2cb1e4d5d6f26462e98eb88b2720c9 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 22 May 2017 16:15:11 +0300 Subject: [PATCH 203/311] ignite-gg-12163 IGNITE_PDS_WAL_RECORD_ITERATOR_BUFFER_SIZE cosmetic update --- .../snapshot/StartSnapshotOperationDiscoveryMessage.java | 4 +++- .../cache/distributed/dht/GridDhtLocalPartition.java | 7 +++++-- .../cache/database/wal/FileWriteAheadLogManager.java | 3 +-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java index 700f4049abdfb..18bca36b183ad 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java @@ -115,7 +115,9 @@ public UUID initiatorNodeId() { return id; } - /** {@inheritDoc} */ + /** + * + */ public IgniteUuid operationId() { return operationId; } 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 1d910a3eace71..a35c1683c787f 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 @@ -141,8 +141,11 @@ public class GridDhtLocalPartition extends GridCacheConcurrentMapImpl implements * @param id Partition ID. * @param entryFactory Entry factory. */ - @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor") GridDhtLocalPartition(GridCacheContext cctx, - int id, GridCacheMapEntryFactory entryFactory) { + @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor") GridDhtLocalPartition( + GridCacheContext cctx, + int id, + GridCacheMapEntryFactory entryFactory + ) { super(cctx, entryFactory, Math.max(10, GridCacheAdapter.DFLT_START_CACHE_SIZE / cctx.affinity().partitions())); this.id = id; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java index 1ef9384d0d97c..2346f7e9c62fb 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -2012,8 +2012,7 @@ public RecordsIterator( this.end = end; this.log = log; - int tlbSize0 = 16 * tlbSize; - int buffSize0 = tlbSize0 < buffSize ? tlbSize0 : buffSize; + int buffSize0 = Math.min(16 * tlbSize, buffSize); // Do not allocate direct buffer for iterator. buf = ByteBuffer.allocate(buffSize0); From c95734eba2f0bba4ff8111c778267f404683eee0 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 22 May 2017 17:50:11 +0300 Subject: [PATCH 204/311] ignite-gg-12163 fix testPageRecoveryAfterFileCorruption --- .../processors/cache/GridCacheProcessor.java | 5 +- ...tStoreRecoveryAfterFileCorruptionTest.java | 59 ++++++++++++------- 2 files changed, 43 insertions(+), 21 deletions(-) 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 3f268716cb440..76ea847cfe345 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 @@ -1167,7 +1167,10 @@ private void startCache(GridCacheAdapter cache, QuerySchema schema) throws cacheCtx.onStarted(); if (log.isInfoEnabled()) - log.info("Started cache [name=" + U.maskName(cfg.getName()) + ", memoryPolicyName=" + cfg.getMemoryPolicyName() + ", mode=" + cfg.getCacheMode() + ']'); + log.info("Started cache [name=" + U.maskName(cfg.getName()) + + ", memoryPolicyName=" + cfg.getMemoryPolicyName() + + ", mode=" + cfg.getCacheMode() + ']' + ); } /** diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java index fbed6ee755778..fd77996c3caa3 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java @@ -22,8 +22,10 @@ import java.nio.ByteOrder; import java.nio.channels.FileChannel; import java.util.Collection; +import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; @@ -48,20 +50,35 @@ import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; 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.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import static org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager.IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES; + /** * */ public class IgnitePersistentStoreRecoveryAfterFileCorruptionTest extends GridCommonAbstractTest { + /** Ip finder. */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + /** Total pages. */ private static final int totalPages = 1024; + /** Cache name. */ + private final String cacheName = "cache"; + + /** Policy name. */ + private final String policyName = "dfltMemPlc"; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - CacheConfiguration ccfg = new CacheConfiguration("partitioned"); + CacheConfiguration ccfg = new CacheConfiguration(cacheName); + ccfg.setAffinity(new RendezvousAffinityFunction(true, 1)); ccfg.setRebalanceMode(CacheRebalanceMode.NONE); @@ -71,12 +88,12 @@ public class IgnitePersistentStoreRecoveryAfterFileCorruptionTest extends GridCo MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); - memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setName(policyName); memPlcCfg.setInitialSize(1024 * 1024 * 1024); memPlcCfg.setMaxSize(1024 * 1024 * 1024); dbCfg.setMemoryPolicies(memPlcCfg); - dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + dbCfg.setDefaultMemoryPolicyName(policyName); cfg.setMemoryConfiguration(dbCfg); @@ -86,12 +103,14 @@ public class IgnitePersistentStoreRecoveryAfterFileCorruptionTest extends GridCo cfg.setPersistenceConfiguration(pCfg); + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder)); + return cfg; } /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES, "true"); + System.setProperty(IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES, "true"); stopAllGrids(); @@ -111,42 +130,42 @@ public class IgnitePersistentStoreRecoveryAfterFileCorruptionTest extends GridCo * @throws Exception if failed. */ public void testPageRecoveryAfterFileCorruption() throws Exception { - fail(); //todo @Ed - IgniteEx ig = startGrid(0); - GridCacheSharedContext shared = ig.context().cache().context(); + IgniteCache cache = ig.cache(cacheName); - GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)shared.database(); + // Put for create data store and init meta page. + cache.put(1, 1); - IgnitePageStoreManager pageStore = shared.pageStore(); + GridCacheSharedContext sharedCtx = ig.context().cache().context(); + + GridCacheDatabaseSharedManager psMgr = (GridCacheDatabaseSharedManager)sharedCtx.database(); + + FilePageStoreManager pageStore = (FilePageStoreManager)sharedCtx.pageStore(); U.sleep(1_000); // Disable integrated checkpoint thread. - dbMgr.enableCheckpoints(false).get(); + psMgr.enableCheckpoints(false).get(); - PageMemory mem = shared.database().memoryPolicy(null).pageMemory(); + PageMemory mem = sharedCtx.database().memoryPolicy(policyName).pageMemory(); - int cacheId = shared.cache().cache("partitioned").context().cacheId(); + int cacheId = sharedCtx.cache().cache(cacheName).context().cacheId(); FullPageId[] pages = new FullPageId[totalPages]; - for (int i = 0; i < totalPages; i++) { - FullPageId fullId = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId); - - pages[i] = fullId; - } + for (int i = 0; i < totalPages; i++) + pages[i] = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId); generateWal( (PageMemoryImpl)mem, - pageStore, - shared.wal(), + sharedCtx.pageStore(), + sharedCtx.wal(), cacheId, pages ); - eraseDataFromDisk((FilePageStoreManager)pageStore, cacheId, pages[0]); + eraseDataFromDisk(pageStore, cacheId, pages[0]); stopAllGrids(); From e31f37171dcf3cf578432d93cfffa342f4e69cdd Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 22 May 2017 19:09:20 +0300 Subject: [PATCH 205/311] ignite-gg-12163 testPartitionLossAndRecover refactoring changes --- ...tentStoreCacheRebalancingAbstractTest.java | 71 +++++++++---------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index 108d9998a6b1d..6aa98af3d653f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -17,15 +17,10 @@ package org.apache.ignite.cache.database; -import java.io.File; import java.io.Serializable; -import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Objects; -import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -35,6 +30,7 @@ import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; 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.configuration.CacheConfiguration; @@ -42,14 +38,11 @@ import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.PersistenceConfiguration; -import org.apache.ignite.events.CacheRebalancingEvent; -import org.apache.ignite.events.EventType; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.typedef.G; import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.lang.IgniteBiPredicate; 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; @@ -75,6 +68,7 @@ public abstract class IgnitePersistentStoreCacheRebalancingAbstractTest extends IgniteConfiguration cfg = super.getConfiguration(gridName); CacheConfiguration ccfg1 = cacheConfiguration(cacheName); + ccfg1.setPartitionLossPolicy(PartitionLossPolicy.READ_ONLY_SAFE); ccfg1.setBackups(1); ccfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); @@ -99,10 +93,10 @@ public abstract class IgnitePersistentStoreCacheRebalancingAbstractTest extends cfg.setCacheConfiguration(ccfg1, ccfg2); - MemoryConfiguration dbCfg = new MemoryConfiguration(); + MemoryConfiguration memCfg = new MemoryConfiguration(); - dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); - dbCfg.setPageSize(1024); + memCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4); + memCfg.setPageSize(1024); MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); @@ -111,16 +105,14 @@ public abstract class IgnitePersistentStoreCacheRebalancingAbstractTest extends memPlcCfg.setInitialSize(100 * 1024 * 1024); memPlcCfg.setSwapFilePath("work/swap"); - dbCfg.setMemoryPolicies(memPlcCfg); - dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + memCfg.setMemoryPolicies(memPlcCfg); + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); - cfg.setMemoryConfiguration(dbCfg); + cfg.setMemoryConfiguration(memCfg); cfg.setPersistenceConfiguration(new PersistenceConfiguration()); - TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); - - discoSpi.setIpFinder(IP_FINDER); + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER)); return cfg; } @@ -147,7 +139,7 @@ public abstract class IgnitePersistentStoreCacheRebalancingAbstractTest extends /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - G.stopAll(true); + stopAllGrids(); deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); } @@ -323,45 +315,46 @@ public void testDataCorrectnessAfterRestart() throws Exception { * @throws Exception If fails. */ public void testPartitionLossAndRecover() throws Exception { - Ignite ignite1 = G.start(getConfiguration("test1")); - Ignite ignite2 = G.start(getConfiguration("test2")); - IgniteEx ignite3 = (IgniteEx)G.start(getConfiguration("test3")); - IgniteEx ignite4 = (IgniteEx)G.start(getConfiguration("test4")); + Ignite ignite1 = startGrid(0); + Ignite ignite2 = startGrid(1); + Ignite ignite3 = startGrid(2); + Ignite ignite4 = startGrid(3); awaitPartitionMapExchange(); - IgniteCache cache1 = ignite1.cache(cacheName); + IgniteCache cache1 = ignite1.cache(cacheName); - for (int i = 0; i < 100; i++) - cache1.put(i, i); + final int offset = 10; - ignite1.active(false); + for (int i = 0; i < 100; i++) + cache1.put(String.valueOf(i), String.valueOf(i + offset)); ignite3.close(); ignite4.close(); - ignite1.active(true); - awaitPartitionMapExchange(); assert !ignite1.cache(cacheName).lostPartitions().isEmpty(); - ignite3 = (IgniteEx)G.start(getConfiguration("test3")); - ignite4 = (IgniteEx)G.start(getConfiguration("test4")); + ignite3 = startGrid(2); + ignite4 = startGrid(3); - awaitPartitionMapExchange(); + ignite1.resetLostPartitions(Collections.singletonList(cacheName)); - ignite1.resetLostPartitions(Collections.singletonList(cache1.getName())); + IgniteCache cache2 = ignite2.cache(cacheName); + IgniteCache cache3 = ignite3.cache(cacheName); + IgniteCache cache4 = ignite4.cache(cacheName); - IgniteCache cache2 = ignite2.cache(cacheName); - IgniteCache cache3 = ignite3.cache(cacheName); - IgniteCache cache4 = ignite4.cache(cacheName); + //Thread.sleep(5_000); for (int i = 0; i < 100; i++) { - assert cache1.get(i).equals(i); - assert cache2.get(i).equals(i); - assert cache3.get(i).equals(i); - assert cache4.get(i).equals(i); + String key = String.valueOf(i); + String expected = String.valueOf(i + offset); + + assertEquals(expected, cache1.get(key)); + assertEquals(expected, cache2.get(key)); + assertEquals(expected, cache3.get(key)); + assertEquals(expected, cache4.get(key)); } } From 7058c71f10534d0f84bf9acf8b4690b5d4e45688 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 23 May 2017 11:02:01 +0300 Subject: [PATCH 206/311] Copy page to checkpoint pool (tmp page) if checkpoint in progress, no need flush changes from checkpoint pages to main memory after checkpoint complete. --- .../database/file/FilePageStoreManager.java | 14 +- .../database/pagemem/PageMemoryImpl.java | 509 ++++++++---------- ...PageStoreCheckpointSimulationSelfTest.java | 2 +- 3 files changed, 247 insertions(+), 278 deletions(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java index 1bb83d21b1fe9..3a5873d251677 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java @@ -117,12 +117,22 @@ public FilePageStoreManager(GridKernalContext ctx) { if (pstCfg.getPersistenceStorePath() != null) { File workDir0 = new File(pstCfg.getPersistenceStorePath()); + if (!workDir0.isAbsolute()) - workDir0 = U.resolveWorkDirectory(igniteCfg.getWorkDirectory(), pstCfg.getPersistenceStorePath(), false); + workDir0 = U.resolveWorkDirectory( + igniteCfg.getWorkDirectory(), + pstCfg.getPersistenceStorePath(), + false + ); + storeWorkDir = new File(workDir0, consId); } else - storeWorkDir = new File(U.resolveWorkDirectory(igniteCfg.getWorkDirectory(), "db", false), consId); + storeWorkDir = new File(U.resolveWorkDirectory( + igniteCfg.getWorkDirectory(), + "db", + false + ), consId); U.ensureDirectory(storeWorkDir, "page store work directory", log); } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java index 21ebcbf05646d..c05af572e122a 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java @@ -136,7 +136,7 @@ public class PageMemoryImpl implements PageMemoryEx { /** Page relative pointer. Does not change once a page is allocated. */ public static final int RELATIVE_PTR_OFFSET = 8; - /** Page ID offset */ + /** Page ID offset */ public static final int PAGE_ID_OFFSET = 16; /** Page cache ID offset. */ @@ -373,7 +373,7 @@ public PageMemoryImpl( /** {@inheritDoc} */ @Override public boolean isDirty(int cacheId, long pageId, long page) { - return isDirtyVisible(page, new FullPageId(pageId, cacheId)); + return isDirty(page); } /** {@inheritDoc} */ @@ -417,7 +417,7 @@ public PageMemoryImpl( "Pin counter must be 0 for a new page [relPtr=" + U.hexLong(relPtr) + ", absPtr=" + U.hexLong(absPtr) + ']'; - setDirty(fullId, absPtr, true, true, false); + setDirty(fullId, absPtr, true, true); if (isTrackingPage) { long pageAddr = absPtr + PAGE_OVERHEAD; @@ -428,8 +428,14 @@ public PageMemoryImpl( trackingIO.initNewPage(pageAddr, pageId, pageSize()); if (!sharedCtx.wal().isAlwaysWriteFullPages()) - sharedCtx.wal().log(new InitNewPageRecord(cacheId, pageId, trackingIO.getType(), - trackingIO.getVersion(), pageId)); + sharedCtx.wal().log( + new InitNewPageRecord( + cacheId, + pageId, + trackingIO.getType(), + trackingIO.getVersion(), pageId + ) + ); else sharedCtx.wal().log(new PageSnapshot(fullId, absPtr + PAGE_OVERHEAD, pageSize())); } @@ -483,8 +489,13 @@ public PageMemoryImpl( seg.readLock().lock(); try { - long relPtr = seg.loadedPages.get(cacheId, PageIdUtils.effectivePageId(pageId), seg.partTag(cacheId, partId), - INVALID_REL_PTR, INVALID_REL_PTR); + long relPtr = seg.loadedPages.get( + cacheId, + PageIdUtils.effectivePageId(pageId), + seg.partTag(cacheId, partId), + INVALID_REL_PTR, + INVALID_REL_PTR + ); // The page is loaded to the memory. if (relPtr != INVALID_REL_PTR) { @@ -503,8 +514,14 @@ public PageMemoryImpl( try { // Double-check. - long relPtr = seg.loadedPages.get(cacheId, PageIdUtils.effectivePageId(pageId), seg.partTag(cacheId, partId), - INVALID_REL_PTR, OUTDATED_REL_PTR); + long relPtr = seg.loadedPages.get( + cacheId, + PageIdUtils.effectivePageId(pageId), + seg.partTag(cacheId, partId), + INVALID_REL_PTR, + OUTDATED_REL_PTR + ); + long absPtr; if (relPtr == INVALID_REL_PTR) { @@ -523,9 +540,14 @@ public PageMemoryImpl( ", absPtr=" + U.hexLong(absPtr) + ']'; // We can clear dirty flag after the page has been allocated. - setDirty(fullId, absPtr, false, false, false); + setDirty(fullId, absPtr, false, false); - seg.loadedPages.put(cacheId, PageIdUtils.effectivePageId(pageId), relPtr, seg.partTag(cacheId, partId)); + seg.loadedPages.put( + cacheId, + PageIdUtils.effectivePageId(pageId), + relPtr, + seg.partTag(cacheId, partId) + ); long pageAddr = absPtr + PAGE_OVERHEAD; @@ -592,10 +614,10 @@ else if (relPtr == OUTDATED_REL_PTR) { * @param seg Segment. * @param cacheId Cache ID. * @param pageId Page ID. - * @param remove {@code True} if page should be removed. + * @param rmv {@code True} if page should be removed. * @return Relative pointer to refreshed page. */ - private long refreshOutdatedPage(Segment seg, int cacheId, long pageId, boolean remove) { + private long refreshOutdatedPage(Segment seg, int cacheId, long pageId, boolean rmv) { assert seg.writeLock().isHeldByCurrentThread(); int tag = seg.partTag(cacheId, PageIdUtils.partId(pageId)); @@ -621,7 +643,7 @@ private long refreshOutdatedPage(Segment seg, int cacheId, long pageId, boolean checkpointPool.releaseFreePage(tmpBufPtr); } - if (remove) + if (rmv) seg.loadedPages.remove(cacheId, PageIdUtils.effectivePageId(pageId), tag); return relPtr; @@ -753,196 +775,164 @@ private void tryToRestorePage(FullPageId fullId, long absPtr) throws IgniteCheck /** {@inheritDoc} */ @SuppressWarnings({"unchecked", "TooBroadScope"}) @Override public void finishCheckpoint() { - // Lock segment by segment and flush changes. - for (Segment seg : segments) { - GridLongList activePages = null; + for (Segment seg : segments) + seg.segCheckpointPages = null; + } - seg.writeLock().lock(); + /** {@inheritDoc} */ + @Override public Integer getForCheckpoint(FullPageId fullId, ByteBuffer tmpBuf) { + assert tmpBuf.remaining() == pageSize(); - try { - assert seg.segCheckpointPages != null : "Checkpoint has not been started."; + Segment seg = segment(fullId.cacheId(), fullId.pageId()); - for (FullPageId fullId : seg.segCheckpointPages) { - int partTag = seg.partTag(fullId.cacheId(), PageIdUtils.partId(fullId.pageId())); + long absPtr = 0; - long relPtr = seg.loadedPages.get(fullId.cacheId(), - PageIdUtils.effectivePageId(fullId.pageId()), partTag, INVALID_REL_PTR, OUTDATED_REL_PTR); + long relPtr; - // Checkpoint page may have been written by evict. - if (relPtr == INVALID_REL_PTR) - continue; + int tag; - if (relPtr == OUTDATED_REL_PTR) { - relPtr = refreshOutdatedPage(seg, fullId.cacheId(), - PageIdUtils.effectivePageId(fullId.pageId()), true); + seg.readLock().lock(); - seg.pool.releaseFreePage(relPtr); + try { + tag = seg.partTag(fullId.cacheId(), PageIdUtils.partId(fullId.pageId())); - continue; - } + relPtr = seg.loadedPages.get( + fullId.cacheId(), + PageIdUtils.effectivePageId(fullId.pageId()), + tag, + INVALID_REL_PTR, + OUTDATED_REL_PTR + ); - long absPtr = seg.absolute(relPtr); + // Page may have been cleared during eviction. We have nothing to do in this case. + if (relPtr == INVALID_REL_PTR) + return null; - boolean pinned = PageHeader.isAcquired(absPtr); + if (relPtr != OUTDATED_REL_PTR) { + absPtr = seg.absolute(relPtr); - if (pinned) { - // Pin the page one more time. - seg.acquirePage(absPtr); + // Pin the page until page will not be copied. + if (PageHeader.tempBufferPointer(absPtr) == INVALID_REL_PTR) + PageHeader.acquirePage(absPtr); + } + } + finally { + seg.readLock().unlock(); + } - if (activePages == null) - activePages = new GridLongList(seg.segCheckpointPages.size() / 2 + 1); + if (relPtr == OUTDATED_REL_PTR) { + seg.writeLock().lock(); - activePages.add(relPtr); - } - // Page is not pinned and nobody can pin it since we hold the segment write lock. - else { - flushPageTempBuffer(fullId, absPtr); + try { + // Double-check. + relPtr = seg.loadedPages.get( + fullId.cacheId(), + PageIdUtils.effectivePageId(fullId.pageId()), + seg.partTag( + fullId.cacheId(), + PageIdUtils.partId(fullId.pageId()) + ), + INVALID_REL_PTR, + OUTDATED_REL_PTR + ); - assert PageHeader.tempBufferPointer(absPtr) == INVALID_REL_PTR; - assert !PageHeader.tempDirty(absPtr) : "ptr=" + U.hexLong(absPtr) + ", fullId=" + fullId; - } + if (relPtr == INVALID_REL_PTR) + return null; + + if (relPtr == OUTDATED_REL_PTR) { + relPtr = refreshOutdatedPage( + seg, + fullId.cacheId(), + PageIdUtils.effectivePageId(fullId.pageId()), + true + ); + + seg.pool.releaseFreePage(relPtr); } + + return null; } finally { seg.writeLock().unlock(); } - // Must release active pages outside of segment write lock. - if (activePages != null) { - for (int p = 0; p < activePages.size(); p++) { - long relPtr = activePages.get(p); - - long absPtr = seg.absolute(relPtr); - - flushCheckpoint(absPtr); - - seg.readLock().lock(); - - try { - seg.releasePage(absPtr); - } - finally { - seg.readLock().unlock(); - } - } - } + } + else { + copyPageForCheckpoint(absPtr, fullId, tmpBuf); - seg.segCheckpointPages = null; + return tag; } } /** - * Checks if the page represented by the given full ID and absolute pointer has a temp buffer. If it has, this - * method will flush temp buffer data to the main page buffer as well as temp buffer dirty flag, release the - * temp buffer to segment pool and clear full page ID from checkpoint set. - *

- * This method must be called wither from segment write lock while page is not pinned (thus, no other thread has - * access to the page's write buffer, or when this page is pinned and locked for write. - * - * @param fullId Full page ID. - * @param absPtr Page absolute pointer. + * @param absPtr Absolute ptr. + * @param fullId Full id. + * @param tmpBuf Tmp buffer. */ - private void flushPageTempBuffer(FullPageId fullId, long absPtr) { - long tmpRelPtr = PageHeader.tempBufferPointer(absPtr); - - // The page has temp buffer, need to flush it to the main memory. - if (tmpRelPtr != INVALID_REL_PTR) { - long tmpAbsPtr = checkpointPool.absolute(tmpRelPtr); - - boolean tmpDirty = PageHeader.tempDirty(absPtr, false); - - // Page could have a temp write buffer, but be not dirty because - // it was not modified after getForWrite. - if (tmpDirty) - GridUnsafe.copyMemory(tmpAbsPtr + PAGE_OVERHEAD, absPtr + PAGE_OVERHEAD, - sysPageSize - PAGE_OVERHEAD); - - setDirty(fullId, absPtr, tmpDirty, true, false); - - PageHeader.tempBufferPointer(absPtr, INVALID_REL_PTR); + private void copyPageForCheckpoint(long absPtr, FullPageId fullId, ByteBuffer tmpBuf) { + assert absPtr != 0; - checkpointPool.releaseFreePage(tmpRelPtr); + long tmpRelPtr; - // We pinned the page when allocated the temp buffer, release it now. - int updated = PageHeader.releasePage(absPtr); + rwLock.writeLock(absPtr + PAGE_LOCK_OFFSET, OffheapReadWriteLock.TAG_LOCK_ALWAYS); - assert updated > 0 : "Checkpoint page should not be released by flushCheckpoint()"; - } - else { - // We can get here in two cases. - // 1) Page was not modified since the checkpoint started. - // 2) Page was dirty and was written to the store by evictPage(). Then it was loaded to memory again - // and may have already modified by a writer. - // In both cases we should just set page header dirty flag based on dirtyPages collection. - PageHeader.dirty(absPtr, segment(fullId.cacheId(), fullId.pageId()).dirtyPages.contains(fullId)); - } + try { + tmpRelPtr = PageHeader.tempBufferPointer(absPtr); - // It is important to clear checkpoint status before the write lock is released. - clearCheckpoint(fullId); - } + clearCheckpoint(fullId); - /** - * If page was concurrently modified during the checkpoint phase, this method will flush all changes from the - * temporary location to main memory. - * This method must be called outside of the segment write lock because we can ask for another pages - * while holding a page read or write lock. - */ - private void flushCheckpoint(long absPtr) { - rwLock.writeLock(absPtr + PAGE_LOCK_OFFSET, OffheapReadWriteLock.TAG_LOCK_ALWAYS); + if (tmpRelPtr != INVALID_REL_PTR) + PageHeader.tempBufferPointer(absPtr, INVALID_REL_PTR); + else { + copyInBuffer(absPtr, tmpBuf); - try { - assert PageHeader.isAcquired(absPtr); + PageHeader.dirty(absPtr, false); - FullPageId fullId = PageHeader.fullPageId(absPtr); + PageHeader.releasePage(absPtr); - flushPageTempBuffer(fullId, absPtr); + return; + } } finally { rwLock.writeUnlock(absPtr + PAGE_LOCK_OFFSET, OffheapReadWriteLock.TAG_LOCK_ALWAYS); } - } - /** {@inheritDoc} */ - @Override public Integer getForCheckpoint(FullPageId fullId, ByteBuffer tmpBuf) { - assert tmpBuf.remaining() == pageSize(); - - Segment seg = segment(fullId.cacheId(), fullId.pageId()); + assert tmpRelPtr != 0; - seg.readLock().lock(); + long tmpAbsPtr = checkpointPool.absolute(tmpRelPtr); - try { - int tag = seg.partTag(fullId.cacheId(), PageIdUtils.partId(fullId.pageId())); + copyInBuffer(tmpAbsPtr, tmpBuf); - long relPtr = seg.loadedPages.get(fullId.cacheId(), - PageIdUtils.effectivePageId(fullId.pageId()), tag, INVALID_REL_PTR, INVALID_REL_PTR); + GridUnsafe.setMemory(tmpAbsPtr + PAGE_OVERHEAD, pageSize(), (byte)0); - // Page may have been cleared during eviction. We have nothing to do in this case. - if (relPtr == INVALID_REL_PTR) - return null; + PageHeader.dirty(tmpAbsPtr, false); - long absPtr = seg.absolute(relPtr); + checkpointPool.releaseFreePage(tmpRelPtr); - if (tmpBuf.isDirect()) { - long tmpPtr = ((DirectBuffer)tmpBuf).address(); + // We pinned the page when allocated the temp buffer, release it now. + PageHeader.releasePage(absPtr); + } - GridUnsafe.copyMemory(absPtr + PAGE_OVERHEAD, tmpPtr, pageSize()); + /** + * @param absPtr Absolute ptr. + * @param tmpBuf Tmp buffer. + */ + private void copyInBuffer(long absPtr, ByteBuffer tmpBuf) { + if (tmpBuf.isDirect()) { + long tmpPtr = ((DirectBuffer)tmpBuf).address(); - assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 - assert GridUnsafe.getInt(tmpPtr + 4) == 0; //TODO GG-11480 - } - else { - byte[] arr = tmpBuf.array(); + GridUnsafe.copyMemory(absPtr + PAGE_OVERHEAD, tmpPtr, pageSize()); - assert arr != null; - assert arr.length == pageSize(); + assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + assert GridUnsafe.getInt(tmpPtr + 4) == 0; //TODO GG-11480 + } + else { + byte[] arr = tmpBuf.array(); - GridUnsafe.copyMemory(null, absPtr + PAGE_OVERHEAD, arr, GridUnsafe.BYTE_ARR_OFF, pageSize()); - } + assert arr != null; + assert arr.length == pageSize(); - return tag; - } - finally { - seg.readLock().unlock(); + GridUnsafe.copyMemory(null, absPtr + PAGE_OVERHEAD, arr, GridUnsafe.BYTE_ARR_OFF, pageSize()); } } @@ -985,13 +975,13 @@ private void flushCheckpoint(long absPtr) { /** {@inheritDoc} */ @Override public IgniteInternalFuture clearAsync( - GridPredicate3 predicate, + GridPredicate3 pred, boolean cleanDirty ) { CountDownFuture completeFut = new CountDownFuture(segments.length); for (Segment seg : segments) { - Runnable clear = new ClearSegmentRunnable(seg, predicate, cleanDirty, completeFut, pageSize()); + Runnable clear = new ClearSegmentRunnable(seg, pred, cleanDirty, completeFut, pageSize()); try { asyncRunner.execute(clear); @@ -1057,20 +1047,9 @@ private long readLockPage(long absPtr, FullPageId fullId, boolean force) { PageHeader.writeTimestamp(absPtr, U.currentTimeMillis()); - long tmpRelPtr = PageHeader.tempBufferPointer(absPtr); + assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 - if (tmpRelPtr == INVALID_REL_PTR) { - assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 - - return absPtr + PAGE_OVERHEAD; - } - else { - long tmpAbsPtr = checkpointPool.absolute(tmpRelPtr); - - assert GridUnsafe.getInt(tmpAbsPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 - - return tmpAbsPtr + PAGE_OVERHEAD; - } + return absPtr + PAGE_OVERHEAD; } /** {@inheritDoc} */ @@ -1105,7 +1084,7 @@ long tryWriteLockPage(long absPtr, FullPageId fullId, boolean checkTag) { if (!rwLock.tryWriteLock(absPtr + PAGE_LOCK_OFFSET, tag)) return 0; - return doWriteLockPage(absPtr, fullId); + return postWriteLockPage(absPtr, fullId); } /** @@ -1117,99 +1096,82 @@ private long writeLockPage(long absPtr, FullPageId fullId, boolean checkTag) { boolean locked = rwLock.writeLock(absPtr + PAGE_LOCK_OFFSET, tag); - return locked ? doWriteLockPage(absPtr, fullId) : 0; + return locked ? postWriteLockPage(absPtr, fullId) : 0; } /** * @param absPtr Absolute pointer. * @return Pointer to the page write buffer. */ - private long doWriteLockPage(long absPtr, FullPageId fullId) { + private long postWriteLockPage(long absPtr, FullPageId fullId) { PageHeader.writeTimestamp(absPtr, U.currentTimeMillis()); // Create a buffer copy if the page is scheduled for a checkpoint. - if (isInCheckpoint(fullId)) { - long tmpRelPtr = PageHeader.tempBufferPointer(absPtr); + if (isInCheckpoint(fullId) && PageHeader.tempBufferPointer(absPtr) == INVALID_REL_PTR) { + long tmpRelPtr = checkpointPool.borrowOrAllocateFreePage(fullId.pageId()); if (tmpRelPtr == INVALID_REL_PTR) { - tmpRelPtr = checkpointPool.borrowOrAllocateFreePage(fullId.pageId()); + rwLock.writeUnlock(absPtr + PAGE_LOCK_OFFSET, OffheapReadWriteLock.TAG_LOCK_ALWAYS); - if (tmpRelPtr == INVALID_REL_PTR) { - rwLock.writeUnlock(absPtr + PAGE_LOCK_OFFSET, OffheapReadWriteLock.TAG_LOCK_ALWAYS); - - throw new IgniteException("Failed to allocate temporary buffer for checkpoint " + + throw new IgniteException( + "Failed to allocate temporary buffer for checkpoint " + "(increase checkpointPageBufferSize configuration property)"); - } - - // Pin the page until checkpoint is not finished. - PageHeader.acquirePage(absPtr); + } - long tmpAbsPtr = checkpointPool.absolute(tmpRelPtr); + // Pin the page until checkpoint is not finished. + PageHeader.acquirePage(absPtr); - GridUnsafe.copyMemory(null, absPtr + PAGE_OVERHEAD, null, tmpAbsPtr + PAGE_OVERHEAD, pageSize()); + long tmpAbsPtr = checkpointPool.absolute(tmpRelPtr); - PageHeader.tempDirty(absPtr, false); - PageHeader.tempBufferPointer(absPtr, tmpRelPtr); + assert !PageHeader.tempDirty(tmpAbsPtr); - assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 - assert GridUnsafe.getInt(tmpAbsPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + GridUnsafe.copyMemory( + null, + absPtr + PAGE_OVERHEAD, + null, + tmpAbsPtr + PAGE_OVERHEAD, + pageSize() + ); - return tmpAbsPtr + PAGE_OVERHEAD; - } - else { - long newAbsPrt = checkpointPool.absolute(tmpRelPtr) + PAGE_OVERHEAD; - - assert GridUnsafe.getInt(newAbsPrt + 4) == 0; //TODO GG-11480 + PageHeader.dirty(absPtr, false); + PageHeader.tempBufferPointer(absPtr, tmpRelPtr); - return newAbsPrt; - } - } - else { assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 - - return absPtr + PAGE_OVERHEAD; + assert GridUnsafe.getInt(tmpAbsPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 } + + assert GridUnsafe.getInt(absPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + + return absPtr + PAGE_OVERHEAD; } /** * @param page Page pointer. - * @param walPolicy Full page WAL record policy. + * @param walPlc Full page WAL record policy. */ - private void writeUnlockPage(long page, FullPageId fullId, Boolean walPolicy, boolean markDirty, boolean restore) { - boolean dirtyVisible = isDirtyVisible(page, fullId); + private void writeUnlockPage( + long page, + FullPageId fullId, + Boolean walPlc, + boolean markDirty, + boolean restore + ) { + boolean dirty = isDirty(page); //if page is for restore, we shouldn't mark it as changed - if (!restore && markDirty && !dirtyVisible) { + if (!restore && markDirty && !dirty) changeTracker.apply(page, fullId, this); - } - - boolean pageWalRec = markDirty && walPolicy != FALSE && (walPolicy == TRUE || !dirtyVisible); - long pageId; - - long tmpRel = PageHeader.tempBufferPointer(page); - if (tmpRel != INVALID_REL_PTR) { - long tmpAbsPtr = checkpointPool.absolute(tmpRel); + boolean pageWalRec = markDirty && walPlc != FALSE && (walPlc == TRUE || !dirty); - assert GridUnsafe.getInt(tmpAbsPtr + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 - - if (markDirty) - setDirty(fullId, page, markDirty, false, true); - - beforeReleaseWrite(fullId, tmpAbsPtr + PAGE_OVERHEAD, pageWalRec); - - pageId = PageIO.getPageId(tmpAbsPtr + PAGE_OVERHEAD); - } - else { - assert GridUnsafe.getInt(page + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 + assert GridUnsafe.getInt(page + PAGE_OVERHEAD + 4) == 0; //TODO GG-11480 - if (markDirty) - setDirty(fullId, page, markDirty, false, false); + if (markDirty) + setDirty(fullId, page, markDirty, false); - beforeReleaseWrite(fullId, page + PAGE_OVERHEAD, pageWalRec); + beforeReleaseWrite(fullId, page + PAGE_OVERHEAD, pageWalRec); - pageId = PageIO.getPageId(page + PAGE_OVERHEAD); - } + long pageId = PageIO.getPageId(page + PAGE_OVERHEAD); rwLock.writeUnlock(page + PAGE_LOCK_OFFSET, PageIdUtils.tag(pageId)); } @@ -1276,31 +1238,6 @@ boolean isDirty(long absPtr) { return PageHeader.dirty(absPtr); } - /** - * @param absPtr Absolute pointer. - * @return {@code True} if page is dirty in temporary buffer. - */ - boolean isTempDirty(long absPtr) { - return PageHeader.tempDirty(absPtr); - } - - /** - * @param absPtr Absolute page pointer. - * @param fullId Full page ID. - * @return If page is visible to memory user as dirty. - */ - boolean isDirtyVisible(long absPtr, FullPageId fullId) { - Collection cp = segment(fullId.cacheId(), fullId.pageId()).segCheckpointPages; - - if (cp == null || !cp.contains(fullId)) - return isDirty(absPtr); - else { - long tmpPtr = PageHeader.tempBufferPointer(absPtr); - - return tmpPtr != INVALID_REL_PTR && PageHeader.tempDirty(absPtr); - } - } - /** * Gets the number of active pages across all segments. Used for test purposes only. * @@ -1320,11 +1257,11 @@ public int activePagesCount() { * * @param absPtr Absolute pointer. * @param dirty {@code True} dirty flag. - * @param forceAdd If this flag is {@code true}, then the page will be added to the dirty set regardless whether - * the old flag was dirty or not. + * @param forceAdd If this flag is {@code true}, then the page will be added to the dirty set regardless whether the + * old flag was dirty or not. */ - void setDirty(FullPageId pageId, long absPtr, boolean dirty, boolean forceAdd, boolean tmp) { - boolean wasDirty = tmp ? PageHeader.tempDirty(absPtr, dirty) : PageHeader.dirty(absPtr, dirty); + void setDirty(FullPageId pageId, long absPtr, boolean dirty, boolean forceAdd) { + boolean wasDirty = PageHeader.dirty(absPtr, dirty); if (dirty) { if (!wasDirty || forceAdd) @@ -1420,9 +1357,9 @@ protected PagePool(int idx, DirectMemoryRegion region) { /** * Allocates a new free page. * + * @param pageId Page ID to to initialize. * @return Relative pointer to the allocated page. * @throws GridOffHeapOutOfMemoryException If failed to allocate new free page. - * @param pageId Page ID to to initialize. */ private long borrowOrAllocateFreePage(long pageId) throws GridOffHeapOutOfMemoryException { long relPtr = borrowFreePage(); @@ -1458,9 +1395,9 @@ private long borrowFreePage() { } /** + * @param pageId Page ID. * @return Relative pointer of the allocated page. * @throws GridOffHeapOutOfMemoryException If failed to allocate new free page. - * @param pageId Page ID. */ private long allocateFreePage(long pageId) throws GridOffHeapOutOfMemoryException { long limit = region.address() + region.size(); @@ -1574,7 +1511,7 @@ private class Segment extends ReentrantReadWriteLock { private final int maxDirtyPages; /** */ - private final Map, Integer> partitionTagMap = new HashMap<>(); + private final Map, Integer> partTagMap = new HashMap<>(); /** * @param region Memory region. @@ -1646,8 +1583,8 @@ private int acquiredPages() { } /** - * @return Page relative pointer. * @param pageId Page ID. + * @return Page relative pointer. */ private long borrowOrAllocateFreePage(long pageId) { return pool.borrowOrAllocateFreePage(pageId); @@ -1678,10 +1615,16 @@ private boolean prepareEvict(FullPageId fullPageId, long absPtr) throws IgniteCh if (cpPages != null && cpPages.contains(fullPageId)) { assert storeMgr != null; - flushDirtyPage.applyx(fullPageId, wrapPointer(absPtr + PAGE_OVERHEAD, pageSize()), - partTag(fullPageId.cacheId(), PageIdUtils.partId(fullPageId.pageId()))); + flushDirtyPage.applyx( + fullPageId, + wrapPointer(absPtr + PAGE_OVERHEAD, pageSize()), + partTag( + fullPageId.cacheId(), + PageIdUtils.partId(fullPageId.pageId()) + ) + ); - setDirty(fullPageId, absPtr, false, true, false); + setDirty(fullPageId, absPtr, false, true); cpPages.remove(fullPageId); @@ -1810,8 +1753,14 @@ else if (pageTs < dirtyTs && dirty) { continue; } - loadedPages.remove(fullPageId.cacheId(), PageIdUtils.effectivePageId(fullPageId.pageId()), - partTag(fullPageId.cacheId(), PageIdUtils.partId(fullPageId.pageId()))); + loadedPages.remove( + fullPageId.cacheId(), + PageIdUtils.effectivePageId(fullPageId.pageId()), + partTag( + fullPageId.cacheId(), + PageIdUtils.partId(fullPageId.pageId()) + ) + ); return relEvictAddr; } @@ -1819,6 +1768,7 @@ else if (pageTs < dirtyTs && dirty) { /** * Will scan all segment pages to find one to evict it + * * @param cap Capacity. */ private long tryToFindSequentially(int cap) throws IgniteCheckedException { @@ -1857,8 +1807,14 @@ private long tryToFindSequentially(int cap) throws IgniteCheckedException { final FullPageId fullPageId = PageHeader.fullPageId(absEvictAddr); if (prepareEvict(fullPageId, absEvictAddr)) { - loadedPages.remove(fullPageId.cacheId(), PageIdUtils.effectivePageId(fullPageId.pageId()), - partTag(fullPageId.cacheId(), PageIdUtils.partId(fullPageId.pageId()))); + loadedPages.remove( + fullPageId.cacheId(), + PageIdUtils.effectivePageId(fullPageId.pageId()), + partTag( + fullPageId.cacheId(), + PageIdUtils.partId(fullPageId.pageId()) + ) + ); return addr; } @@ -1896,7 +1852,7 @@ private long absolute(long relPtr) { private int partTag(int cacheId, int partId) { assert getReadHoldCount() > 0 || getWriteHoldCount() > 0; - Integer tag = partitionTagMap.get(new T2<>(cacheId, partId)); + Integer tag = partTagMap.get(new T2<>(cacheId, partId)); if (tag == null) return 1; @@ -1914,31 +1870,34 @@ private int incrementPartTag(int cacheId, int partId) { T2 t = new T2<>(cacheId, partId); - Integer tag = partitionTagMap.get(t); + Integer tag = partTagMap.get(t); if (tag == null) { - partitionTagMap.put(t, 2); + partTagMap.put(t, 2); return 2; } else if (tag == Integer.MAX_VALUE) { U.warn(log, "Partition tag overflow [cacheId=" + cacheId + ", partId=" + partId + "]"); - partitionTagMap.put(t, 0); + partTagMap.put(t, 0); return 0; } else { - partitionTagMap.put(t, tag + 1); + partTagMap.put(t, tag + 1); return tag + 1; } } + /** + * @param cacheId Cache id. + */ private void resetPartTags(int cacheId) { assert getWriteHoldCount() > 0; - Iterator> iter = partitionTagMap.keySet().iterator(); + Iterator> iter = partTagMap.keySet().iterator(); while (iter.hasNext()) { T2 t = iter.next(); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java index 7cc4122d7a4d0..96178ef6b4be8 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java @@ -584,7 +584,7 @@ public void testDirtyFlag() throws Exception { long page = mem.acquirePage(fullId.cacheId(), fullId.pageId()); try { - assertFalse(mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); + assertTrue(mem.isDirty(fullId.cacheId(), fullId.pageId(), page)); long pageAddr = mem.writeLock(fullId.cacheId(), fullId.pageId(), page); From f8792edf9b9354c58a40060d38ee863acb6cf42b Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Thu, 11 May 2017 18:37:45 +0300 Subject: [PATCH 207/311] IGNITE-5175: Performance degradation using evictions in near-enabled caches (cherry picked from commit 9f2f30c) --- .../paged/PageEvictionMultinodeTest.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionMultinodeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionMultinodeTest.java index 7a58dd44e589a..c2c077520148a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionMultinodeTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionMultinodeTest.java @@ -17,12 +17,14 @@ package org.apache.ignite.internal.processors.cache.eviction.paged; import java.util.concurrent.ThreadLocalRandom; +import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.cache.CachePeekMode; import org.apache.ignite.cache.CacheWriteSynchronizationMode; import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; /** * @@ -39,9 +41,25 @@ public abstract class PageEvictionMultinodeTest extends PageEvictionAbstractTest private static final CacheWriteSynchronizationMode[] WRITE_MODES = {CacheWriteSynchronizationMode.PRIMARY_SYNC, CacheWriteSynchronizationMode.FULL_SYNC, CacheWriteSynchronizationMode.FULL_ASYNC}; + /** Client grid. */ + private Ignite clientGrid; + /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGridsMultiThreaded(4, false); + + clientGrid = startGrid("client"); + } + + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration configuration = super.getConfiguration(gridName); + + if (gridName.startsWith("client")) + configuration.setClientMode(true); + + return configuration; } /** {@inheritDoc} */ @@ -77,7 +95,7 @@ public void testPageEviction() throws Exception { * @throws Exception If failed. */ private void createCacheAndTestEvcition(CacheConfiguration cfg) throws Exception { - IgniteCache cache = ignite(0).getOrCreateCache(cfg); + IgniteCache cache = clientGrid.getOrCreateCache(cfg); for (int i = 1; i <= ENTRIES; i++) { ThreadLocalRandom r = ThreadLocalRandom.current(); @@ -105,6 +123,6 @@ else if (r.nextInt() % 13 == 0) // Eviction started, no OutOfMemory occurred, success. assertTrue(resultingSize < ENTRIES); - ignite(0).destroyCache(cfg.getName()); + clientGrid.destroyCache(cfg.getName()); } } From e1c825f034f4951c647aea9293f18bd0953b44e3 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Tue, 23 May 2017 18:25:04 +0300 Subject: [PATCH 208/311] ignite-gg-12163 backport of GG-12184 --- .../internal/MarshallerContextImpl.java | 6 +-- modules/pds/pom.xml | 49 +++++++++++++++++++ .../database/GridCacheOffheapManager.java | 3 ++ .../resources/META-INF/classnames.properties | 28 +++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 modules/pds/src/main/resources/META-INF/classnames.properties 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 40f104ebc075d..265481e055cec 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 @@ -126,11 +126,11 @@ public MarshallerContextImpl(@Nullable Collection plugins) { if (plugins != null && !plugins.isEmpty()) { for (PluginProvider plugin : plugins) { - URL pluginClsNames = ldr.getResource("META-INF/" + plugin.name().toLowerCase() + Enumeration pluginUrls = ldr.getResources("META-INF/" + plugin.name().toLowerCase() + ".classnames.properties"); - if (pluginClsNames != null) - processResource(pluginClsNames); + while (pluginUrls.hasMoreElements()) + processResource(pluginUrls.nextElement()); } } } diff --git a/modules/pds/pom.xml b/modules/pds/pom.xml index 01385a2cf4438..3bbccb9043d7d 100644 --- a/modules/pds/pom.xml +++ b/modules/pds/pom.xml @@ -114,6 +114,55 @@ + + org.codehaus.mojo + exec-maven-plugin + 1.3.2 + + + org.apache.ignite + ignite-tools + ${project.version} + + + + + process-classes + + java + + + true + org.apache.ignite.tools.classgen.ClassesGenerator + + ${project.basedir}/target/classes + + + + org.apache.ignite + + + + + + org.apache.maven.plugins maven-jar-plugin diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java index 5253818b6db8b..1bef00ba3a3c6 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java @@ -472,6 +472,9 @@ private Metas getOrAllocateCacheMetas() throws IgniteCheckedException { * */ private static class RebalanceIteratorAdapter implements IgniteRebalanceIterator { + /** Serial version uid. */ + private static final long serialVersionUID = 0L; + /** Cache context. */ private GridCacheContext cctx; diff --git a/modules/pds/src/main/resources/META-INF/classnames.properties b/modules/pds/src/main/resources/META-INF/classnames.properties new file mode 100644 index 0000000000000..3003e5f2cbb25 --- /dev/null +++ b/modules/pds/src/main/resources/META-INF/classnames.properties @@ -0,0 +1,28 @@ +# +# 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. +# + +org.apache.ignite.internal.processors.cache.database.FullPageIdIterableComparator +org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager$11 +org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager$7 +org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager$CheckpointEntryType +org.apache.ignite.internal.processors.cache.database.GridCacheOffheapManager$RebalanceIteratorAdapter +org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl$Segment +org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager$FileArchiver$1 +org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager$Mode +org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager$RecordsIterator +org.apache.ignite.internal.processors.cache.database.wal.SegmentEofException +org.apache.ignite.internal.processors.cache.database.wal.crc.IgniteDataIntegrityViolationException From 8de68c68eda96c9e24f3f89fb7bd90202d799502 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Tue, 23 May 2017 18:45:27 +0300 Subject: [PATCH 209/311] Renting primary node - fix. --- .../preloader/GridDhtPartitionsExchangeFuture.java | 12 +++++++++++- .../cache/database/GridCacheOffheapManager.java | 2 +- ...ePersistentStoreCacheRebalancingAbstractTest.java | 2 -- 3 files changed, 12 insertions(+), 4 deletions(-) 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 c75b0a2a78b93..dbcfeb9cc6268 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 @@ -1662,8 +1662,18 @@ else if (cntr == maxCntr.cnt) continue; CounterWithNodes maxCntr = maxCntrs.get(part.id()); + + if (maxCntr == null && cntr == 0) { + CounterWithNodes cntrObj = new CounterWithNodes(cntr, cctx.localNodeId()); - if (maxCntr == null || cntr > maxCntr.cnt) + for (UUID nodeId : msgs.keySet()) { + if (top.partitionState(nodeId, part.id()) == GridDhtPartitionState.OWNING) + cntrObj.nodes.add(nodeId); + } + + maxCntrs.put(part.id(), cntrObj); + } + else if (maxCntr == null || cntr > maxCntr.cnt) maxCntrs.put(part.id(), new CounterWithNodes(cntr, cctx.localNodeId())); else if (cntr == maxCntr.cnt) maxCntr.nodes.add(cctx.localNodeId()); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java index 1bef00ba3a3c6..9bced4282b47c 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java @@ -952,7 +952,7 @@ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { /** {@inheritDoc} */ @Override public void updateCounter(long val) { try { - CacheDataStore delegate0 = init0(true); + CacheDataStore delegate0 = init0(false); if (delegate0 != null) delegate0.updateCounter(val); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index 6aa98af3d653f..ecb12f596ff03 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -362,8 +362,6 @@ public void testPartitionLossAndRecover() throws Exception { * @throws Exception If failed. */ public void testTopologyChangesWithConstantLoad() throws Exception { - fail("only for one run, must be removed soon"); - final int entriesCnt = 10_000; int maxNodesCount = 4; int topChanges = 20; From dc3450e34db9f882a372a02777dc3122fceb8ca5 Mon Sep 17 00:00:00 2001 From: dpavlov Date: Tue, 23 May 2017 20:46:58 +0300 Subject: [PATCH 210/311] IGNITE-5267: Code commenting for WAL manager --- .../wal/FileWriteAheadLogManager.java | 138 ++++++++++++------ .../cache/database/wal/RecordSerializer.java | 2 +- .../database/wal/record/HeaderRecord.java | 2 +- 3 files changed, 96 insertions(+), 46 deletions(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java index 2346f7e9c62fb..a9a482a93d183 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -66,6 +66,7 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiTuple; import org.apache.ignite.lang.IgnitePredicate; +import org.jetbrains.annotations.Nullable; /** * File WAL manager. @@ -97,13 +98,13 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl } }; - /** */ + /** System property (env variable) for configuring DB WAL mode, see values in {@link Mode} */ public static final String IGNITE_PDS_WAL_MODE = "IGNITE_PDS_WAL_MODE"; - /** */ + /** Thread local byte buffer size */ public static final String IGNITE_PDS_WAL_TLB_SIZE = "IGNITE_PDS_WAL_TLB_SIZE"; - /** */ + /** WAL flush frequency for {@link Mode#BACKGROUND} log mode */ public static final String IGNITE_PDS_WAL_FLUSH_FREQ = "IGNITE_PDS_WAL_FLUSH_FREQUENCY"; /** */ @@ -118,17 +119,17 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl /** */ private static long fsyncDelayNanos = IgniteSystemProperties.getLong(IGNITE_PDS_WAL_FSYNC_DELAY, 1); - /** */ + /** Thread local byte buffer size, see {@link #tlb} */ public final int tlbSize = IgniteSystemProperties.getInteger(IGNITE_PDS_WAL_TLB_SIZE, 128 * 1024); - /** WAL flush frequency. Makes sense only for BACKGROUND log mode. */ + /** WAL flush frequency. Makes sense only for {@link Mode#BACKGROUND} log mode. */ public static final int FLUSH_FREQ = IgniteSystemProperties.getInteger(IGNITE_PDS_WAL_FLUSH_FREQ, 2_000); /** */ private final boolean alwaysWriteFullPages = IgniteSystemProperties.getBoolean(IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES, false); - /** */ + /** WAL segment size in bytes */ private long maxWalSegmentSize; /** */ @@ -143,14 +144,18 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl /** */ private File walArchiveDir; - /** */ + /** Current log segment handle */ private volatile FileWriteHandle currentHnd; - /** */ + /** Updater for {@link #currentHnd}, used for verify there are no concurrent update for current log segment handle */ private static final AtomicReferenceFieldUpdater currentHndUpd = AtomicReferenceFieldUpdater.newUpdater(FileWriteAheadLogManager.class, FileWriteHandle.class, "currentHnd"); - /** */ + /** + * Thread local byte buffer for saving serialized WAL records chain, see {@link FileWriteHandle#head}. + * Introduced to decrease number of buffers allocation. + * Used only for record itself is shorter than {@link #tlbSize}. + */ private final ThreadLocal tlb = new ThreadLocal() { @Override protected ByteBuffer initialValue() { ByteBuffer buf = ByteBuffer.allocateDirect(tlbSize); @@ -164,7 +169,7 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl /** */ private RecordSerializer serializer; - /** */ + /** WAL file archiver thread, started on server nodes at cluster init */ private volatile FileArchiver archiver; /** */ @@ -549,7 +554,7 @@ private FileWriteHandle rollOver(FileWriteHandle cur) throws StorageException, I assert swapped : "Concurrent updates on rollover are not allowed"; - hnd.signalNextAvailable(); + hnd.signalNextAvailable(); // let other threads to proceed with new segment } else hnd.awaitNext(); @@ -612,7 +617,10 @@ private FileWriteHandle restoreWriteHandle(FileWALPointer lastReadPtr) throws Ig /** * Fills the file header for a new segment. + * Calling this method signals we are done with the segment and it can be archived. + * If we don't have prepared file yet and achiever is busy this method blocks * + * @param curIdx current segment released by WAL writer * @return Initialized file handle. * @throws StorageException If IO exception occurred. * @throws IgniteCheckedException If failed. @@ -648,7 +656,7 @@ private FileWriteHandle initNextWriteHandle(int curIdx) throws StorageException, } /** - * + * Deletes temp files, creates and prepares new; Creates first segment if necessary */ private void checkOrPrepareFiles() throws IgniteCheckedException { // Clean temp files. @@ -741,8 +749,11 @@ private void createFile(File file) throws IgniteCheckedException { } /** + * Retrieves next available file to write WAL data, waiting + * if necessary for a segment to become available. + * * @param curIdx Current absolute WAL segment index. - * @return File. + * @return File ready for use as new WAL segment. * @throws IgniteCheckedException If failed. */ private File pollNextFile(int curIdx) throws IgniteCheckedException { @@ -797,25 +808,40 @@ private static FileDescriptor[] scan(File[] allFiles) { * the work WAL segment: S(N) = N % dbCfg.walSegments. * When a work segment is finished, it is given to the archiver. If the absolute index of last archived segment * is denoted by A and the absolute index of next segment we want to write is denoted by W, then we can allow - * write to S(W) if W - A <= walSegments. + * write to S(W) if W - A <= walSegments.
+ * + * Monitor of current object is used for notify on: + *

    + *
  • exception occurred ({@link FileArchiver#cleanException}!=null)
  • + *
  • stopping thread ({@link FileArchiver#stopped}==true)
  • + *
  • current file index changed ({@link FileArchiver#curAbsWalIdx})
  • + *
  • last archived file index was changed ({@link FileArchiver#lastAbsArchivedIdx})
  • + *
  • some WAL index was removed from {@link FileArchiver#locked} map
  • + *
*/ private class FileArchiver extends Thread { - /** */ + /** Exception which occurred during initial creation of files or during archiving WAL segment */ private IgniteCheckedException cleanException; - /** Absolute current segment index. */ + /** + * Absolute current segment index WAL Manger writes to. Guarded by this. + * Incremented during rollover. Also may be directly set if WAL is resuming logging after start. + */ private int curAbsWalIdx = -1; - /** */ + /** Last archived file index (absolute, 0-based). Guarded by this. */ private int lastAbsArchivedIdx = -1; - /** */ + /** current thread stopping advice */ private volatile boolean stopped; /** */ private NavigableMap reserved = new TreeMap<>(); - /** */ + /** + * Maps absolute segment index to locks counter. Lock on segment protects from archiving segment and may + * come from {@link RecordsIterator} during WAL replay. Map itself is guarded by this. + */ private Map locked = new HashMap<>(); /** @@ -959,10 +985,11 @@ private synchronized void release(int absIdx) { /** * Gets the absolute index of the next WAL segment available to write. + * Blocks till there are available file to write * - * @param curIdx Current index that we want to increment. + * @param curIdx Current absolute index that we want to increment. * @return Next index (curIdx+1) when it is ready to be written. - * @throws IgniteCheckedException If failed. + * @throws IgniteCheckedException If failed (if interrupted or if exception occurred in the archiver thread). */ private int nextAbsoluteSegmentIndex(int curIdx) throws IgniteCheckedException { try { @@ -1114,7 +1141,8 @@ private boolean checkStop() { } /** - * + * Background creation of all segments except first. First segment was created in main thread by + * {@link FileWriteAheadLogManager#checkOrPrepareFiles()} */ private void allocateRemainingFiles() throws IgniteCheckedException { checkFiles(1, true, new IgnitePredicate() { @@ -1158,7 +1186,7 @@ private static class FileDescriptor implements Comparable { /** */ protected final File file; - /** */ + /** Absolute WAL segment file index */ protected final int idx; /** */ @@ -1173,7 +1201,7 @@ private FileDescriptor(File file) { /** * @param file File. - * @param idx index + * @param idx Absolute WAL segment file index. */ private FileDescriptor(File file, Integer idx) { this.file = file; @@ -1337,13 +1365,18 @@ private class FileWriteHandle extends FileHandle { /** */ private final RecordSerializer serializer; - /** */ + /** See {@link FileWriteAheadLogManager#maxWalSegmentSize} */ private final long maxSegmentSize; - /** */ + /** + * Accumulated WAL records chain. + * This reference points to latest WAL record. + * When writing records chain is iterated from latest to oldest (see {@link WALRecord#previous()}) + * Records from chain are saved into buffer in reverse order + */ private final AtomicReference head = new AtomicReference<>(); - /** */ + /** Position in current file after the end of last written record (incremented after file channel write operation) */ private volatile long written; /** */ @@ -1352,24 +1385,27 @@ private class FileWriteHandle extends FileHandle { /** Environment failure. */ private volatile Throwable envFailed; - /** */ + /** Stop guard to provide warranty that only one thread will be successful in calling {@link #close(boolean)}*/ private final AtomicBoolean stop = new AtomicBoolean(false); /** */ private final Lock lock = new ReentrantLock(); - /** */ + /** Condition activated each time writeBuffer() completes. Used to wait previously flushed write to complete */ private final Condition writeComplete = lock.newCondition(); - /** */ + /** Condition for timed wait of several threads, see {@link #fsyncDelayNanos} */ private final Condition fsync = lock.newCondition(); - /** */ + /** + * Next segment available condition. + * Protection from "spurious wakeup" is provided by predicate {@link #ch}=null + */ private final Condition nextSegment = lock.newCondition(); /** * @param file Mapped file to use. - * @param idx Index for easy access. + * @param idx Absolute WAL segment file index for easy access. * @param pos Position. * @param maxSegmentSize Max segment size. * @param serializer Serializer. @@ -1398,12 +1434,12 @@ private FileWriteHandle( } /** - * @param rec Record. - * @return Pointer. + * @param rec Record to be added to record chain as new {@link #head} + * @return Pointer or null if roll over to next segment is required or already started by other thread. * @throws StorageException If failed. * @throws IgniteCheckedException If failed. */ - private WALPointer addRecord(WALRecord rec) throws StorageException, IgniteCheckedException { + @Nullable private WALPointer addRecord(WALRecord rec) throws StorageException, IgniteCheckedException { assert rec.size() > 0 || rec.getClass() == FakeRecord.class; boolean flushed = false; @@ -1533,7 +1569,7 @@ private long chainBeginPosition(WALRecord h) { } /** - * @param expHead Expected head of chain. + * @param expHead Expected head of chain. If head was changed, flush is not performed in this thread * @throws IgniteCheckedException If failed. * @throws StorageException If failed. */ @@ -1586,7 +1622,8 @@ private boolean flush(WALRecord expHead) throws StorageException, IgniteCheckedE } /** - * @param buf Buffer. + * Serializes WAL records chain to provided byte buffer + * @param buf Buffer, will be filled with records chain from end to beginning * @param head Head of the chain to write to the buffer. * @return Position in file for this buffer. * @throws IgniteCheckedException If failed. @@ -1734,9 +1771,8 @@ private boolean close(boolean rollOver) throws IgniteCheckedException, StorageEx return false; } - /** - * - */ + + /** Signals next segment available to wake up other worker threads waiting for WAL to write */ private void signalNextAvailable() { lock.lock(); @@ -1770,8 +1806,9 @@ private void awaitNext() throws IgniteCheckedException { } /** - * @param pos Position in file. - * @param buf Buffer. + * @param pos Position in file to start write from. + * May be checked against actual position to wait previous writes to complete + * @param buf Buffer to write to file * @throws StorageException If failed. * @throws IgniteCheckedException If failed. */ @@ -1794,6 +1831,8 @@ private void writeBuffer(long pos, ByteBuffer buf) throws StorageException, Igni while (written != pos) { assert written < pos : "written = " + written + ", pos = " + pos; // No one can write further than we are now. + // Permutation occurred between blocks write operations + // order of acquiring lock is not the same as order of write long now = U.currentTimeMillis(); if (now - lastLogged >= logBackoff) { @@ -1912,7 +1951,9 @@ private String safePosition() { } /** - * Fake record. + * Fake record is zero-sized record, which is not stored into file. + * Fake record is used for storing position in file {@link WALRecord#position()}. + * Fake record is allowed to have no previous record. */ private static final class FakeRecord extends WALRecord { /** @@ -2286,6 +2327,7 @@ private void releaseWorkSegment(int absIdx) { } } + /** Periodically flushes current file handle for {@link Mode#BACKGROUND} mode */ private class QueueFlusher extends Thread { /** */ private volatile boolean stopped; @@ -2315,6 +2357,7 @@ private QueueFlusher(String gridName) { } } + /** Signals stop, wakes up thread and waiting until completion */ private void shutdown() { stopped = true; @@ -2333,6 +2376,13 @@ private void shutdown() { * WAL Mode. */ private enum Mode { - NONE, LOG_ONLY, BACKGROUND, DEFAULT + NONE, LOG_ONLY, + + /** + * Write is performed periodically, initiated by background thread, + * calls to {@link IgniteWriteAheadLogManager#fsync(org.apache.ignite.internal.pagemem.wal.WALPointer)} have no effect. + * Using this mode will decrease persistence reliability for performance + */ + BACKGROUND, DEFAULT } } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java index 649f8985057e6..e3a972a9d6967 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java @@ -27,7 +27,7 @@ */ public interface RecordSerializer { /** - * @return writer + * @return serializer version */ public int version(); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java index f9e25838d0e1a..35ce761927160 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java @@ -26,7 +26,7 @@ public class HeaderRecord extends WALRecord { /** */ public static final long MAGIC = 0xB0D045A_CE7ED045AL; - /** */ + /** Serializer version */ private final int ver; /** From a245d620a6c4ca5c560171dcb6f69fa879a17481 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Thu, 25 May 2017 10:43:19 +0300 Subject: [PATCH 211/311] Corrected default checkpoint pool size --- .../apache/ignite/IgniteSystemProperties.java | 3 + .../configuration/MemoryConfiguration.java | 12 ++- .../pagemem/impl/PageMemoryNoStoreImpl.java | 14 ++- .../IgniteCacheDatabaseSharedManager.java | 86 ++++++++++++------- .../database/MetadataStorageSelfTest.java | 13 ++- .../GridCacheDatabaseSharedManager.java | 38 ++++++-- ...tentStoreCacheRebalancingAbstractTest.java | 2 + .../db/file/PageStoreEvictionSelfTest.java | 20 +++-- 8 files changed, 126 insertions(+), 62 deletions(-) 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 2832fbd3149af..d6015d71ddbbc 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -615,6 +615,9 @@ public final class IgniteSystemProperties { */ public static final String IGNITE_PDS_WAL_REBALANCE_THRESHOLD = "IGNITE_PDS_WAL_REBALANCE_THRESHOLD"; + /** Ignite page memory concurrency level. */ + public static final String IGNITE_OFFHEAP_LOCK_CONCURRENCY_LEVEL = "IGNITE_OFFHEAP_LOCK_CONCURRENCY_LEVEL"; + /** Returns true for system properties only avoiding sending sensitive information. */ private static final IgnitePredicate> PROPS_FILTER = new IgnitePredicate>() { @Override public boolean apply(final Map.Entry entry) { diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/MemoryConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/MemoryConfiguration.java index e6324dc0fdfe8..2d71e99a4b395 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/MemoryConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/MemoryConfiguration.java @@ -102,7 +102,7 @@ public class MemoryConfiguration implements Serializable { private String dfltMemPlcName = DFLT_MEM_PLC_DEFAULT_NAME; /** Size of memory (in bytes) to use for default MemoryPolicy. */ - private Long dfltMemPlcSize; + private long dfltMemPlcSize = DFLT_MEMORY_POLICY_MAX_SIZE; /** Memory policies. */ private MemoryPolicyConfiguration[] memPlcs; @@ -126,6 +126,8 @@ public long getSystemCacheInitialSize() { * @return {@code this} for chaining. */ public MemoryConfiguration setSystemCacheInitialSize(long sysCacheInitSize) { + A.ensure(sysCacheMaxSize > 0, "System cache initial size can not be less zero."); + this.sysCacheInitSize = sysCacheInitSize; return this; @@ -149,6 +151,8 @@ public long getSystemCacheMaxSize() { * @return {@code this} for chaining. */ public MemoryConfiguration setSystemCacheMaxSize(long sysCacheMaxSize) { + A.ensure(sysCacheMaxSize > 0, "System cache max size can not be less zero."); + this.sysCacheMaxSize = sysCacheMaxSize; return this; @@ -214,7 +218,7 @@ public MemoryConfiguration setMemoryPolicies(MemoryPolicyConfiguration... memPlc public MemoryPolicyConfiguration createDefaultPolicyConfig() { MemoryPolicyConfiguration memPlc = new MemoryPolicyConfiguration(); - long maxSize = (dfltMemPlcSize != null) ? dfltMemPlcSize : DFLT_MEMORY_POLICY_MAX_SIZE; + long maxSize = dfltMemPlcSize; if (maxSize < DFLT_MEMORY_POLICY_INITIAL_SIZE) memPlc.setInitialSize(maxSize); @@ -248,10 +252,10 @@ public MemoryConfiguration setConcurrencyLevel(int concLvl) { /** * Gets a size for default memory policy overridden by user. * - * @return default memory policy size overridden by user or -1 if nothing was specified. + * @return default memory policy size overridden by user or {@link #DFLT_MEMORY_POLICY_MAX_SIZE} if nothing was specified. */ public long getDefaultMemoryPolicySize() { - return (dfltMemPlcSize != null) ? dfltMemPlcSize : -1; + return dfltMemPlcSize; } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java index 7bc92d686efb5..b205991196b47 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java @@ -26,6 +26,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.mem.DirectMemoryProvider; import org.apache.ignite.internal.mem.DirectMemoryRegion; @@ -40,6 +41,7 @@ import org.apache.ignite.internal.util.offheap.GridOffHeapOutOfMemoryException; import org.apache.ignite.internal.util.typedef.internal.U; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_OFFHEAP_LOCK_CONCURRENCY_LEVEL; import static org.apache.ignite.internal.util.GridUnsafe.wrapPointer; /** @@ -143,6 +145,12 @@ public class PageMemoryNoStoreImpl implements PageMemory { /** */ private OffheapReadWriteLock rwLock; + /** Concurrency lvl. */ + private final int lockConcLvl = IgniteSystemProperties.getInteger( + IGNITE_OFFHEAP_LOCK_CONCURRENCY_LEVEL, + Runtime.getRuntime().availableProcessors() * 4 + ); + /** */ private final int totalPages; @@ -182,8 +190,7 @@ public PageMemoryNoStoreImpl( totalPages = (int)(memPlcCfg.getMaxSize() / sysPageSize); - // TODO configure concurrency level. - rwLock = new OffheapReadWriteLock(128); + rwLock = new OffheapReadWriteLock(lockConcLvl); } /** {@inheritDoc} */ @@ -516,9 +523,8 @@ public int pageIndex(int seqNo) { if (cmp < 0) high = mid - 1; - else if (cmp > 0) { + else if (cmp > 0) low = mid + 1; - } else return seg.pageIndex(seqNo); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 0a906b28cc0cc..098fa1ec31901 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -106,24 +106,21 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap * @throws IgniteCheckedException If failed. */ public void init() throws IgniteCheckedException { - if (memPlcMap == null) { - MemoryConfiguration memCfg = cctx.kernalContext().config().getMemoryConfiguration(); + MemoryConfiguration memCfg = cctx.kernalContext().config().getMemoryConfiguration(); - if (memCfg == null) - memCfg = new MemoryConfiguration(); + assert memCfg != null; - validateConfiguration(memCfg); + validateConfiguration(memCfg); - pageSize = memCfg.getPageSize(); + pageSize = memCfg.getPageSize(); - initPageMemoryPolicies(memCfg); + initPageMemoryPolicies(memCfg); - registerMetricsMBeans(); + registerMetricsMBeans(); - startMemoryPolicies(); + startMemoryPolicies(); - initPageMemoryDataStructures(memCfg); - } + initPageMemoryDataStructures(memCfg); } /** @@ -220,9 +217,11 @@ protected void initPageMemoryPolicies(MemoryConfiguration memCfg) { memPlcMap = U.newHashMap(2); memMetricsMap = U.newHashMap(2); - addMemoryPolicy(memCfg, + addMemoryPolicy( + memCfg, memCfg.createDefaultPolicyConfig(), - DFLT_MEM_PLC_DEFAULT_NAME); + DFLT_MEM_PLC_DEFAULT_NAME + ); U.warn(log, "No user-defined default MemoryPolicy found; system default of 1GB size will be used."); } @@ -234,9 +233,11 @@ protected void initPageMemoryPolicies(MemoryConfiguration memCfg) { memPlcMap = U.newHashMap(memPlcsCfgs.length + 2); memMetricsMap = U.newHashMap(memPlcsCfgs.length + 2); - addMemoryPolicy(memCfg, + addMemoryPolicy( + memCfg, memCfg.createDefaultPolicyConfig(), - DFLT_MEM_PLC_DEFAULT_NAME); + DFLT_MEM_PLC_DEFAULT_NAME + ); U.warn(log, "No user-defined default MemoryPolicy found; system default of 1GB size will be used."); } @@ -250,27 +251,34 @@ protected void initPageMemoryPolicies(MemoryConfiguration memCfg) { addMemoryPolicy(memCfg, memPlcCfg, memPlcCfg.getName()); } - addMemoryPolicy(memCfg, - createSystemMemoryPolicy(memCfg.getSystemCacheInitialSize(), memCfg.getSystemCacheMaxSize()), - SYSTEM_MEMORY_POLICY_NAME); + addMemoryPolicy( + memCfg, + createSystemMemoryPolicy( + memCfg.getSystemCacheInitialSize(), + memCfg.getSystemCacheMaxSize() + ), + SYSTEM_MEMORY_POLICY_NAME + ); } /** - * @param dbCfg Database config. + * @param memCfg Database config. * @param memPlcCfg Memory policy config. * @param memPlcName Memory policy name. */ - private void addMemoryPolicy(MemoryConfiguration dbCfg, - MemoryPolicyConfiguration memPlcCfg, - String memPlcName) { - String dfltMemPlcName = dbCfg.getDefaultMemoryPolicyName(); + private void addMemoryPolicy( + MemoryConfiguration memCfg, + MemoryPolicyConfiguration memPlcCfg, + String memPlcName + ) { + String dfltMemPlcName = memCfg.getDefaultMemoryPolicyName(); if (dfltMemPlcName == null) dfltMemPlcName = DFLT_MEM_PLC_DEFAULT_NAME; MemoryMetricsImpl memMetrics = new MemoryMetricsImpl(memPlcCfg); - MemoryPolicy memPlc = initMemory(dbCfg, memPlcCfg, memMetrics); + MemoryPolicy memPlc = initMemory(memCfg, memPlcCfg, memMetrics); memPlcMap.put(memPlcName, memPlc); @@ -328,8 +336,10 @@ private void validateConfiguration(MemoryConfiguration memCfg) throws IgniteChec Set plcNames = (plcCfgs != null) ? U.newHashSet(plcCfgs.length) : new HashSet(0); - checkSystemMemoryPolicySizeConfiguration(memCfg.getSystemCacheInitialSize(), - memCfg.getSystemCacheMaxSize()); + checkSystemMemoryPolicySizeConfiguration( + memCfg.getSystemCacheInitialSize(), + memCfg.getSystemCacheMaxSize() + ); if (plcCfgs != null) { for (MemoryPolicyConfiguration plcCfg : plcCfgs) { @@ -344,9 +354,10 @@ private void validateConfiguration(MemoryConfiguration memCfg) throws IgniteChec } checkDefaultPolicyConfiguration( - memCfg.getDefaultMemoryPolicyName(), - memCfg.getDefaultMemoryPolicySize(), - plcNames); + memCfg.getDefaultMemoryPolicyName(), + memCfg.getDefaultMemoryPolicySize(), + plcNames + ); } /** @@ -355,7 +366,10 @@ private void validateConfiguration(MemoryConfiguration memCfg) throws IgniteChec * * @throws IgniteCheckedException In case of validation violation. */ - private void checkSystemMemoryPolicySizeConfiguration(long sysCacheInitSize, long sysCacheMaxSize) throws IgniteCheckedException { + private static void checkSystemMemoryPolicySizeConfiguration( + long sysCacheInitSize, + long sysCacheMaxSize + ) throws IgniteCheckedException { if (sysCacheInitSize < MIN_PAGE_MEMORY_SIZE) throw new IgniteCheckedException("Initial size for system cache must have size more than 10MB (use " + "MemoryConfiguration.systemCacheInitialSize property to set correct size in bytes) " + @@ -388,7 +402,7 @@ private static void checkDefaultPolicyConfiguration( long dfltPlcSize, Collection plcNames ) throws IgniteCheckedException { - if (dfltPlcSize != -1) { + if (dfltPlcSize != MemoryConfiguration.DFLT_MEMORY_POLICY_MAX_SIZE) { if (!F.eq(dfltPlcName, MemoryConfiguration.DFLT_MEM_PLC_DEFAULT_NAME)) throw new IgniteCheckedException("User-defined MemoryPolicy configuration " + "and defaultMemoryPolicySize properties are set at the same time. " + @@ -843,7 +857,15 @@ protected PageMemory createPageMemory( MemoryPolicyConfiguration memPlcCfg, MemoryMetricsImpl memMetrics ) { - return new PageMemoryNoStoreImpl(log, memProvider, cctx, memCfg.getPageSize(), memPlcCfg, memMetrics, false); + return new PageMemoryNoStoreImpl( + log, + memProvider, + cctx, + memCfg.getPageSize(), + memPlcCfg, + memMetrics, + false + ); } /** diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MetadataStorageSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MetadataStorageSelfTest.java index b98f4294e810a..52064722c9400 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MetadataStorageSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MetadataStorageSelfTest.java @@ -17,6 +17,12 @@ package org.apache.ignite.internal.processors.database; +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicLong; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.mem.DirectMemoryProvider; import org.apache.ignite.internal.pagemem.FullPageId; @@ -30,13 +36,6 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import java.util.Random; -import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.atomic.AtomicLong; - /** * */ diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index c1fed9fbeef08..589ae133d7bca 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -150,7 +150,7 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan IgniteSystemProperties.getLong(IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY, 30_000); /** */ - private final int ggWalRebalanceThreshold = IgniteSystemProperties.getInteger( + private final int walRebalanceThreshold = IgniteSystemProperties.getInteger( IGNITE_PDS_WAL_REBALANCE_THRESHOLD, 500_000); /** Checkpoint lock hold count. */ @@ -355,15 +355,36 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { ); // Intentionally use identity comparison to check if configuration default has changed. - //noinspection NumberEquality + // Noinspection NumberEquality. if (cpBufSize == PersistenceConfiguration.DFLT_CHECKPOINT_PAGE_BUFFER_SIZE) { MemoryConfiguration memCfg = cctx.kernalContext().config().getMemoryConfiguration(); + assert memCfg != null; + + long totalSize = memCfg.getSystemCacheMaxSize(); + + if (memCfg.getMemoryPolicies() == null) + totalSize += MemoryConfiguration.DFLT_MEMORY_POLICY_MAX_SIZE; + else { + for (MemoryPolicyConfiguration memPlc : memCfg.getMemoryPolicies()) { + if (Long.MAX_VALUE - memPlc.getMaxSize() > totalSize) + totalSize += memPlc.getMaxSize(); + else { + totalSize = Long.MAX_VALUE; + + break; + } + } + + assert totalSize > 0; + } + // Limit the checkpoint page buffer size by 2GB. - //TODO find max page cache and use it instead of memCfg.getPageCacheSize() (replaced with Long.MAX_VALUE now) - long adjusted = Math.min(Long.MAX_VALUE / 4, 2 * 1024L * 1024L * 1024L); + long dfltSize = 2 * 1024L * 1024L * 1024L; + + long adjusted = Math.min(totalSize / 4, dfltSize); - if (memCfg != null && cpBufSize < adjusted) { + if (cpBufSize < adjusted) { U.quietAndInfo(log, "Default checkpoint page buffer size is too small, setting to an adjusted value: " + U.readableSize(adjusted, false) @@ -555,7 +576,10 @@ protected long[] calculateFragmentSizes(int concLvl, long cacheSize) { ) { return new PageMemoryImpl( memProvider, - calculateFragmentSizes(memCfg.getConcurrencyLevel(), plcCfg.getMaxSize()), + calculateFragmentSizes( + memCfg.getConcurrencyLevel(), + plcCfg.getMaxSize() + ), cctx, memCfg.getPageSize(), new GridInClosure3X() { @@ -880,7 +904,7 @@ public void restoreState() throws IgniteCheckedException { continue; for (GridDhtLocalPartition part : cacheCtx.topology().currentLocalPartitions()) { - if (part.state() != GridDhtPartitionState.OWNING || part.dataStore().size() <= ggWalRebalanceThreshold) + if (part.state() != GridDhtPartitionState.OWNING || part.dataStore().size() <= walRebalanceThreshold) continue; CheckpointEntry cpEntry = searchCheckpointEntry(cacheCtx, part.id(), null); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index ecb12f596ff03..6aa98af3d653f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -362,6 +362,8 @@ public void testPartitionLossAndRecover() throws Exception { * @throws Exception If failed. */ public void testTopologyChangesWithConstantLoad() throws Exception { + fail("only for one run, must be removed soon"); + final int entriesCnt = 10_000; int maxNodesCount = 4; int topChanges = 20; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java index cc43613bc3a4a..0d9f598ead849 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java @@ -59,6 +59,9 @@ public class PageStoreEvictionSelfTest extends GridCommonAbstractTest { /** */ private static final int PAGES_NUM = 128_000; + /** Cache name. */ + private final String cacheName = "cache"; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { final IgniteConfiguration cfg = super.getConfiguration(gridName); @@ -67,6 +70,8 @@ public class PageStoreEvictionSelfTest extends GridCommonAbstractTest { cfg.setMemoryConfiguration(createDbConfig()); + cfg.setCacheConfiguration(new CacheConfiguration<>(cacheName)); + return cfg; } @@ -74,19 +79,19 @@ public class PageStoreEvictionSelfTest extends GridCommonAbstractTest { * @return DB config. */ private MemoryConfiguration createDbConfig() { - final MemoryConfiguration dbCfg = new MemoryConfiguration(); + final MemoryConfiguration memCfg = new MemoryConfiguration(); MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); memPlcCfg.setInitialSize(MEMORY_LIMIT); memPlcCfg.setMaxSize(MEMORY_LIMIT); memPlcCfg.setName("dfltMemPlc"); - dbCfg.setPageSize(PAGE_SIZE); - dbCfg.setConcurrencyLevel(NUMBER_OF_SEGMENTS); - dbCfg.setMemoryPolicies(memPlcCfg); - dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + memCfg.setPageSize(PAGE_SIZE); + memCfg.setConcurrencyLevel(NUMBER_OF_SEGMENTS); + memCfg.setMemoryPolicies(memPlcCfg); + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); - return dbCfg; + return memCfg; } @@ -111,11 +116,10 @@ private MemoryConfiguration createDbConfig() { */ public void testPageEviction() throws Exception { final IgniteEx ig = startGrid(0); - ig.getOrCreateCache(new CacheConfiguration<>("partitioned")); final PageMemory memory = getMemory(ig); - writeData(ig, memory, CU.cacheId("partitioned")); + writeData(ig, memory, CU.cacheId(cacheName)); } /** From 54beab99c12762a53f539f68bf1003ebf9ea3e85 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Thu, 25 May 2017 20:19:22 +0300 Subject: [PATCH 212/311] ignite-gg-12138 stop nodes after test + small test refactoring --- .../internal/binary/BinaryObjectExceptionSelfTest.java | 10 ++++++++-- .../ipfinder/TcpDiscoveryIpFinderAbstractSelfTest.java | 7 +++++++ .../ipfinder/vm/TcpDiscoveryVmIpFinderSelfTest.java | 7 +++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java index e4be8244bf4e6..35756a4f609f1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java @@ -45,6 +45,9 @@ public class BinaryObjectExceptionSelfTest extends GridCommonAbstractTest { /** */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + /** Cache name. */ + private final String cacheName = "cache"; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); @@ -52,7 +55,10 @@ public class BinaryObjectExceptionSelfTest extends GridCommonAbstractTest { cfg.setMarshaller(new BinaryMarshaller()); cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER)); - cfg.setCacheConfiguration(new CacheConfiguration().setCopyOnRead(true)); + cfg.setCacheConfiguration( + new CacheConfiguration(cacheName) + .setCopyOnRead(true) + ); BinaryConfiguration bcfg = new BinaryConfiguration(); @@ -84,7 +90,7 @@ public class BinaryObjectExceptionSelfTest extends GridCommonAbstractTest { public void testUnexpectedFieldType() throws Exception { IgniteEx grid = grid(0); - IgniteCache cache = grid.cache(null); + IgniteCache cache = grid.cache(cacheName); cache.put(TEST_KEY, new Value()); diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/TcpDiscoveryIpFinderAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/TcpDiscoveryIpFinderAbstractSelfTest.java index 6f2201f8d34e4..465b38dbe7859 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/TcpDiscoveryIpFinderAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/TcpDiscoveryIpFinderAbstractSelfTest.java @@ -54,6 +54,13 @@ protected TcpDiscoveryIpFinderAbstractSelfTest() throws Exception { injectLogger(finder); } + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + /** * @throws Exception If any error occurs. */ diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/vm/TcpDiscoveryVmIpFinderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/vm/TcpDiscoveryVmIpFinderSelfTest.java index 25cb0834c536c..acc12c29142e2 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/vm/TcpDiscoveryVmIpFinderSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/vm/TcpDiscoveryVmIpFinderSelfTest.java @@ -223,6 +223,7 @@ public void testUnregistration() throws Exception { Ignition.stop("client1", true); Ignition.stop("client2", true); + Ignition.stop("client3", true); assertEquals(3 * srvSize, IP_FINDER.getRegisteredAddresses().size()); @@ -237,12 +238,14 @@ public void testUnregistration() throws Exception { Ignition.stop("server1", true); Ignition.stop("server2", true); - GridTestUtils.waitForCondition(new GridAbsPredicate() { + boolean res = GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { - return 0 == G.allGrids().size(); + return G.allGrids().isEmpty(); } }, 10000); + assertTrue(res); + assertTrue(3 * srvSize >= IP_FINDER.getRegisteredAddresses().size()); } From 59b88f5fef05e36cc50962d156e78b539f136e13 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Thu, 25 May 2017 20:25:48 +0300 Subject: [PATCH 213/311] ignite-gg-12163 fix testExchangeMessages after merge --- .../CacheExchangeMessageDuplicatedStateTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java index d8a20653c9a72..99e6afb6c6164 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java @@ -40,9 +40,10 @@ 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.testframework.GridTestUtils.getFieldValue; + /** * */ @@ -234,7 +235,7 @@ private void checkSingleMessages(int crdIdx) { * @param msg Message. */ private void checkFullMessage(GridDhtPartitionsFullMessage msg) { - Map dupPartsData = GridTestUtils.getFieldValue(msg, "dupPartsData"); + Map dupPartsData = getFieldValue(msg, "dupPartsData"); assertNotNull(dupPartsData); @@ -243,7 +244,8 @@ private void checkFullMessage(GridDhtPartitionsFullMessage msg) { assertFalse(dupPartsData.containsKey(CU.cacheId(AFF3_CACHE1))); - Map> partCntrs = GridTestUtils.getFieldValue(msg, "partCntrs"); + Map> partCntrs = + getFieldValue(getFieldValue(msg, "partCntrs"), "map"); if (partCntrs != null) { for (Map cntrs : partCntrs.values()) @@ -255,7 +257,7 @@ private void checkFullMessage(GridDhtPartitionsFullMessage msg) { * @param msg Message. */ private void checkSingleMessage(GridDhtPartitionsSingleMessage msg) { - Map dupPartsData = GridTestUtils.getFieldValue(msg, "dupPartsData"); + Map dupPartsData = getFieldValue(msg, "dupPartsData"); assertNotNull(dupPartsData); @@ -264,7 +266,7 @@ private void checkSingleMessage(GridDhtPartitionsSingleMessage msg) { assertFalse(dupPartsData.containsKey(CU.cacheId(AFF3_CACHE1))); - Map> partCntrs = GridTestUtils.getFieldValue(msg, "partCntrs"); + Map> partCntrs = getFieldValue(msg, "partCntrs"); if (partCntrs != null) { for (Map cntrs : partCntrs.values()) From 4608cc92b26419263c9b9deea3faa2fbf2b3dd7e Mon Sep 17 00:00:00 2001 From: Denis Magda Date: Thu, 25 May 2017 16:26:40 -0700 Subject: [PATCH 214/311] Renaming Persistence interfaces and methods to PersistentStore --- .../configuration/IgniteConfiguration.java | 14 ++++---- ...java => PersistentStoreConfiguration.java} | 32 +++++++++---------- .../processors/cache/GridCacheProcessor.java | 4 +-- .../GridCacheDatabaseSharedManager.java | 8 ++--- .../database/file/FilePageStoreManager.java | 12 +++---- .../wal/FileWriteAheadLogManager.java | 12 +++---- ...tentStoreCacheRebalancingAbstractTest.java | 4 +-- ...earCachePutGetWithPersistenceSelfTest.java | 4 +-- ...sistentStoreContinuousRestartSelfTest.java | 4 +-- ...IgnitePersistentStoreDynamicCacheTest.java | 4 +-- ...ntStoreMultiNodePutGetRestartSelfTest.java | 4 +-- .../IgnitePersistentStorePageSizesTest.java | 4 +-- ...tStoreRecoveryAfterFileCorruptionTest.java | 6 ++-- ...tStoreRemoveDuringRebalancingSelfTest.java | 4 +-- ...reSingleNodePutGetPersistenceSelfTest.java | 4 +-- ...WithIndexingPutGetPersistenceSelfTest.java | 4 +-- .../IgnitePersistentStoreWalTlbSelfTest.java | 8 ++--- ...eEvictionDuringPartitionClearSelfTest.java | 4 +-- ...gniteDbMultiNodePutGetRestartSelfTest.java | 4 +-- .../db/IgniteDbPageEvictionSelfTest.java | 4 +-- .../IgniteDbWholeClusterRestartSelfTest.java | 4 +-- .../RebalancingOnNotStableTopologyTest.java | 6 ++-- .../database/db/TransactionsHangTest.java | 6 ++-- ...niteCachePageStoreIntegrationSelfTest.java | 4 +-- .../IgniteNoActualWalHistorySelfTest.java | 6 ++-- ...IgniteWalDirectoriesConfigurationTest.java | 6 ++-- .../IgniteWalHistoryReservationsSelfTest.java | 4 +-- .../db/file/IgniteWalRecoverySelfTest.java | 7 ++-- .../IgniteWalRecoverySeveralRestartsTest.java | 6 ++-- ...PageStoreCheckpointSimulationSelfTest.java | 6 ++-- .../db/file/PageStoreEvictionSelfTest.java | 4 +-- .../file/WalRecoveryTxLogicalRecordsTest.java | 6 ++-- .../GridChangeGlobalStateAbstractTest.java | 8 ++--- .../extended/GridActivateExtensionTest.java | 8 ++--- 34 files changed, 112 insertions(+), 113 deletions(-) rename modules/core/src/main/java/org/apache/ignite/configuration/{PersistenceConfiguration.java => PersistentStoreConfiguration.java} (86%) diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index 2e3657fe64f33..30b2d28a20acd 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -455,7 +455,7 @@ public class IgniteConfiguration { private MemoryConfiguration memCfg; /** Persistence store configuration. */ - private PersistenceConfiguration pstCfg; + private PersistentStoreConfiguration pstCfg; /** Active on start flag. */ private boolean activeOnStart = DFLT_ACTIVE_ON_START; @@ -496,7 +496,7 @@ public IgniteConfiguration(IgniteConfiguration cfg) { atomicCfg = cfg.getAtomicConfiguration(); binaryCfg = cfg.getBinaryConfiguration(); memCfg = cfg.getMemoryConfiguration(); - pstCfg = cfg.getPersistenceConfiguration(); + pstCfg = cfg.getPersistentStoreConfiguration(); cacheCfg = cfg.getCacheConfiguration(); cacheKeyCfg = cfg.getCacheKeyConfiguration(); cacheSanityCheckEnabled = cfg.isCacheSanityCheckEnabled(); @@ -2147,28 +2147,28 @@ public IgniteConfiguration setMemoryConfiguration(MemoryConfiguration memCfg) { } /** - * Gets persistence configuration. + * Gets persistence configuration used by Apache Ignite Persistent Store. * * @return Persistence configuration. */ - public PersistenceConfiguration getPersistenceConfiguration() { + public PersistentStoreConfiguration getPersistentStoreConfiguration() { return pstCfg; } /** * @return Flag {@code true} if persistent enable, {@code false} if disable. */ - public boolean isPersistentEnable() { + public boolean isPersistentStoreEnabled() { return pstCfg != null; } /** - * Sets persistence configuration. + * Sets persistence configuration activating Apache Ignite Persistent Store. * * @param pstCfg Persistence configuration. * @return {@code this} for chaining. */ - public IgniteConfiguration setPersistenceConfiguration(PersistenceConfiguration pstCfg) { + public IgniteConfiguration setPersistentStoreConfiguration(PersistentStoreConfiguration pstCfg) { this.pstCfg = pstCfg; return this; diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/PersistenceConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java similarity index 86% rename from modules/core/src/main/java/org/apache/ignite/configuration/PersistenceConfiguration.java rename to modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java index 2918d92aeaf02..ac1e51404a5f1 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/PersistenceConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java @@ -19,9 +19,9 @@ import java.io.Serializable; /** - * Configures persistence module of Ignite node. + * Configures Apache Ignite Persistent store. */ -public class PersistenceConfiguration implements Serializable { +public class PersistentStoreConfiguration implements Serializable { /** */ private static final long serialVersionUID = 0L; @@ -48,7 +48,7 @@ public class PersistenceConfiguration implements Serializable { private static final int DFLT_WAL_SEGMENT_SIZE = 64 * 1024 * 1024; /** */ - private String persistenceStorePath; + private String persistenteStorePath; /** Checkpoint frequency. */ private long checkpointFreq = DFLT_CHECKPOINT_FREQ; @@ -80,15 +80,15 @@ public class PersistenceConfiguration implements Serializable { /** * */ - public String getPersistenceStorePath() { - return persistenceStorePath; + public String getPersistentStorePath() { + return persistenteStorePath; } /** * @param persistenceStorePath Persistence store path. */ - public PersistenceConfiguration setPersistenceStorePath(String persistenceStorePath) { - this.persistenceStorePath = persistenceStorePath; + public PersistentStoreConfiguration setPersistentStorePath(String persistenceStorePath) { + this.persistenteStorePath = persistenceStorePath; return this; } @@ -109,7 +109,7 @@ public long getCheckpointFrequency() { * @param checkpointFreq Checkpoint frequency in milliseconds. * @return {@code this} for chaining. */ - public PersistenceConfiguration setCheckpointFrequency(long checkpointFreq) { + public PersistentStoreConfiguration setCheckpointFrequency(long checkpointFreq) { this.checkpointFreq = checkpointFreq; return this; @@ -130,7 +130,7 @@ public int getLockWaitTime() { * @param lockWaitTime Lock wait time. * @return {@code this} for chaining. */ - public PersistenceConfiguration setLockWaitTime(int lockWaitTime) { + public PersistentStoreConfiguration setLockWaitTime(int lockWaitTime) { this.lockWaitTime = lockWaitTime; return this; @@ -155,7 +155,7 @@ public Long getCheckpointPageBufferSize() { * @param checkpointPageBufSize Checkpoint page buffer size. * @return {@code this} for chaining. */ - public PersistenceConfiguration setCheckpointPageBufferSize(long checkpointPageBufSize) { + public PersistentStoreConfiguration setCheckpointPageBufferSize(long checkpointPageBufSize) { this.checkpointPageBufSize = checkpointPageBufSize; return this; @@ -178,7 +178,7 @@ public int getCheckpointThreads() { * @param checkpointThreads Number of checkpoint threads. * @return {@code this} for chaining. */ - public PersistenceConfiguration setCheckpointThreads(int checkpointThreads) { + public PersistentStoreConfiguration setCheckpointThreads(int checkpointThreads) { this.checkpointThreads = checkpointThreads; return this; @@ -199,7 +199,7 @@ public int getWalHistorySize() { * @param walHistSize Number of WAL segments to keep after the checkpoint is finished. * @return {@code this} for chaining. */ - public PersistenceConfiguration setWalHistorySize(int walHistSize) { + public PersistentStoreConfiguration setWalHistorySize(int walHistSize) { this.walHistSize = walHistSize; return this; @@ -221,7 +221,7 @@ public int getWalSegments() { * @param walSegments Number of work WAL segments. * @return {@code this} for chaining. */ - public PersistenceConfiguration setWalSegments(int walSegments) { + public PersistentStoreConfiguration setWalSegments(int walSegments) { this.walSegments = walSegments; return this; @@ -238,7 +238,7 @@ public int getWalSegmentSize() { * @param walSegmentSize WAL segment size. * @return {@code this} for chaining. */ - public PersistenceConfiguration setWalSegmentSize(int walSegmentSize) { + public PersistentStoreConfiguration setWalSegmentSize(int walSegmentSize) { this.walSegmentSize = walSegmentSize; return this; @@ -260,7 +260,7 @@ public String getWalStorePath() { * @param walStorePath Write-ahead log persistence path, absolute or relative to Ignite work directory. * @return {@code this} for chaining. */ - public PersistenceConfiguration setWalStorePath(String walStorePath) { + public PersistentStoreConfiguration setWalStorePath(String walStorePath) { this.walStorePath = walStorePath; return this; @@ -281,7 +281,7 @@ public String getWalArchivePath() { * @param walArchivePath WAL archive directory. * @return {@code this} for chaining. */ - public PersistenceConfiguration setWalArchivePath(String walArchivePath) { + public PersistentStoreConfiguration setWalArchivePath(String walArchivePath) { this.walArchivePath = walArchivePath; return this; 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 76ea847cfe345..d7c1e3de04639 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 @@ -1400,7 +1400,7 @@ private GridCacheContext createCache(CacheConfiguration cfg, IgniteCacheOffheapManager offheapMgr; - if (ctx.config().getPersistenceConfiguration() != null) { + if (ctx.config().getPersistentStoreConfiguration() != null) { ClassLoader clsLdr = U.gridClassLoader(); try { @@ -2074,7 +2074,7 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, IgnitePageStoreManager pageStoreMgr = null; IgniteWriteAheadLogManager walMgr = null; - if (ctx.config().isPersistentEnable()) { + if (ctx.config().isPersistentStoreEnabled()) { dbMgr = IgniteComponentType.DATABASE_MANAGER.create(ctx, false); pageStoreMgr = IgniteComponentType.PAGE_STORE_MANAGER.create(ctx, false); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index c1fed9fbeef08..45b5abfdf5830 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -66,7 +66,7 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; -import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.events.EventType; import org.apache.ignite.internal.GridKernalContext; @@ -232,7 +232,7 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan private volatile boolean printCheckpointStats = true; /** Database configuration. */ - private final PersistenceConfiguration dbCfg; + private final PersistentStoreConfiguration dbCfg; /** */ private final Collection lsnrs = new CopyOnWriteArrayList<>(); @@ -273,7 +273,7 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan public GridCacheDatabaseSharedManager(GridKernalContext ctx) { IgniteConfiguration cfg = ctx.config(); - dbCfg = cfg.getPersistenceConfiguration(); + dbCfg = cfg.getPersistentStoreConfiguration(); assert dbCfg != null : "PageStore should not be created if persistence is disabled."; @@ -356,7 +356,7 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { // Intentionally use identity comparison to check if configuration default has changed. //noinspection NumberEquality - if (cpBufSize == PersistenceConfiguration.DFLT_CHECKPOINT_PAGE_BUFFER_SIZE) { + if (cpBufSize == PersistentStoreConfiguration.DFLT_CHECKPOINT_PAGE_BUFFER_SIZE) { MemoryConfiguration memCfg = cctx.kernalContext().config().getMemoryConfiguration(); // Limit the checkpoint page buffer size by 2GB. diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java index 3a5873d251677..c233b1ea41543 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java @@ -36,7 +36,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.pagemem.PageIdAllocator; import org.apache.ignite.internal.pagemem.PageIdUtils; @@ -84,7 +84,7 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen private final IgniteConfiguration igniteCfg; /** */ - private PersistenceConfiguration pstCfg; + private PersistentStoreConfiguration pstCfg; /** Absolute directory for file page store */ private File storeWorkDir; @@ -101,7 +101,7 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen public FilePageStoreManager(GridKernalContext ctx) { igniteCfg = ctx.config(); - PersistenceConfiguration pstCfg = igniteCfg.getPersistenceConfiguration(); + PersistentStoreConfiguration pstCfg = igniteCfg.getPersistentStoreConfiguration(); assert pstCfg != null : "WAL should not be created if persistence is disabled."; @@ -115,13 +115,13 @@ public FilePageStoreManager(GridKernalContext ctx) { String consId = U.maskForFileName(cctx.kernalContext().discovery().consistentId().toString()); - if (pstCfg.getPersistenceStorePath() != null) { - File workDir0 = new File(pstCfg.getPersistenceStorePath()); + if (pstCfg.getPersistentStorePath() != null) { + File workDir0 = new File(pstCfg.getPersistentStorePath()); if (!workDir0.isAbsolute()) workDir0 = U.resolveWorkDirectory( igniteCfg.getWorkDirectory(), - pstCfg.getPersistenceStorePath(), + pstCfg.getPersistentStorePath(), false ); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java index a9a482a93d183..f8b18efbba49e 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -45,7 +45,7 @@ import org.apache.ignite.IgniteLogger; import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.configuration.PersistenceConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; @@ -133,7 +133,7 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl private long maxWalSegmentSize; /** */ - private final PersistenceConfiguration dbCfg; + private final PersistentStoreConfiguration dbCfg; /** */ private IgniteConfiguration igCfg; @@ -187,7 +187,7 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl public FileWriteAheadLogManager(GridKernalContext ctx) { igCfg = ctx.config(); - PersistenceConfiguration dbCfg = igCfg.getPersistenceConfiguration(); + PersistentStoreConfiguration dbCfg = igCfg.getPersistentStoreConfiguration(); assert dbCfg != null : "WAL should not be created if persistence is disabled."; @@ -1154,7 +1154,7 @@ private void allocateRemainingFiles() throws IgniteCheckedException { } /** - * Validate files depending on {@link PersistenceConfiguration#getWalSegments()} and create if need. + * Validate files depending on {@link PersistentStoreConfiguration#getWalSegments()} and create if need. * Check end when exit condition return false or all files are passed. * * @param startWith Start with. @@ -1991,7 +1991,7 @@ public static class RecordsIterator extends GridCloseableIteratorAdapter Date: Thu, 25 May 2017 17:02:28 -0700 Subject: [PATCH 215/311] Added an example for PersistentStore --- .../example-persistent-store.xml | 71 +++++++++++++++ examples/pom.xml | 7 ++ .../ignite/examples/model/Organization.java | 9 ++ .../PersistentStoreExample.java | 88 +++++++++++++++++++ .../PersistentStoreExampleNodeStartup.java | 29 ++++++ 5 files changed, 204 insertions(+) create mode 100644 examples/config/persistentstore/example-persistent-store.xml create mode 100644 examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExample.java create mode 100644 examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExampleNodeStartup.java diff --git a/examples/config/persistentstore/example-persistent-store.xml b/examples/config/persistentstore/example-persistent-store.xml new file mode 100644 index 0000000000000..955ef8c8fc45d --- /dev/null +++ b/examples/config/persistentstore/example-persistent-store.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + java.lang.Long + org.apache.ignite.examples.model.Organization + + + + + + + + + + + + + + + + + 127.0.0.1:47500..47502 + + + + + + + + diff --git a/examples/pom.xml b/examples/pom.xml index 790565bdbb382..47682700ab0b2 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -67,6 +67,13 @@ ${project.version} + + org.apache.ignite + ignite-pds + ${project.version} + + + com.google.code.simple-spring-memcached spymemcached diff --git a/examples/src/main/java/org/apache/ignite/examples/model/Organization.java b/examples/src/main/java/org/apache/ignite/examples/model/Organization.java index 70d4eee7a7879..fc90c07eff3c2 100644 --- a/examples/src/main/java/org/apache/ignite/examples/model/Organization.java +++ b/examples/src/main/java/org/apache/ignite/examples/model/Organization.java @@ -61,6 +61,15 @@ public Organization(String name) { this.name = name; } + /** + * @param id Organization ID. + * @param name Organization name. + */ + public Organization(long id, String name) { + this.id = id; + this.name = name; + } + /** * @param name Name. * @param addr Address. diff --git a/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExample.java b/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExample.java new file mode 100644 index 0000000000000..2e066ef810b64 --- /dev/null +++ b/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExample.java @@ -0,0 +1,88 @@ +/* + * 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.examples.persistentstore; + +import java.util.List; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.Ignition; +import org.apache.ignite.cache.query.QueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.examples.model.Organization; + +/** + * This example demonstrates the usage of Apache Ignite Persistent Store. + *

+ * To execute this example you should start an instance of {@link PersistentStoreExampleNodeStartup} + * class which will start up an Apache Ignite remote server node with a proper configuration. + *

+ * When {@code UPDATE} parameter of this example is set to {@code true}, the example will populate + * the cache with some data and will then run a sample SQL query to fetch some results. + *

+ * When {@code UPDATE} parameter of this example is set to {@code false}, the example will run + * the SQL query against the cache without the initial data pre-loading from the store. + *

+ * You can populate the cache first with {@code UPDATE} set to {@code true}, then restart the nodes and + * run the example with {@code UPDATE} set to {@code false} to verify that Apache Ignite can work with the + * data that is in the persistence only. + */ +public class PersistentStoreExample { + /** */ + private static final boolean UPDATE = true; + + /** + * @param args Program arguments, ignored. + * @throws Exception If failed. + */ + public static void main(String[] args) throws Exception { + Ignition.setClientMode(true); + + try (Ignite ig = Ignition.start("examples/config/persistentstore/example-persistent-store.xml")) { + + IgniteCache cache = ig.cache("organization"); + + if (UPDATE) { + System.out.println("Populating the cache..."); + + try (IgniteDataStreamer streamer = ig.dataStreamer("organization")) { + streamer.allowOverwrite(true); + + for (long i = 0; i < 100_000; i++) { + streamer.addData(i, new Organization(i, "organization-" + i)); + + if (i > 0 && i % 10_000 == 0) + System.out.println("Done: " + i); + } + } + } + + // Run SQL without explicitly calling to loadCache(). + QueryCursor> cur = cache.query( + new SqlFieldsQuery("select id, name from Organization where name like ?") + .setArgs("organization-54321")); + + System.out.println("SQL Result: " + cur.getAll()); + + // Run get() without explicitly calling to loadCache(). + Organization org = cache.get(54321l); + + System.out.println("GET Result: " + org); + } + } +} diff --git a/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExampleNodeStartup.java b/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExampleNodeStartup.java new file mode 100644 index 0000000000000..ecada47d67243 --- /dev/null +++ b/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExampleNodeStartup.java @@ -0,0 +1,29 @@ +/* + * 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.examples.persistentstore; + +import org.apache.ignite.Ignition; + +/** + * @see PersistentStoreExampleNodeStartup + */ +public class PersistentStoreExampleNodeStartup { + public static void main(String[] args) throws Exception { + Ignition.start("examples/config/persistentstore/example-persistent-store.xml"); + } +} From a0fc2b0e6ab8903bd3007c5915c1a5fea9d43985 Mon Sep 17 00:00:00 2001 From: Denis Magda Date: Thu, 25 May 2017 17:25:37 -0700 Subject: [PATCH 216/311] Fixed PersistentStore configuration documentation --- .../PersistentStoreConfiguration.java | 85 ++++++++++--------- 1 file changed, 44 insertions(+), 41 deletions(-) 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 ac1e51404a5f1..b2e10f4588385 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 @@ -78,13 +78,16 @@ public class PersistentStoreConfiguration implements Serializable { private String walArchivePath; /** - * + * Returns a path the root directory where the Persistent Store will persist data and indexes. */ public String getPersistentStorePath() { return persistenteStorePath; } /** + * Sets a path to the root directory where the Persistent Store will persist data and indexes. + * By default the Persistent Store's files are located under Ignite work directory. + * * @param persistenceStorePath Persistence store path. */ public PersistentStoreConfiguration setPersistentStorePath(String persistenceStorePath) { @@ -103,8 +106,8 @@ public long getCheckpointFrequency() { } /** - * Sets checkpoint frequency. This is a minimal interval at which memory state will be written to a disk - * storage. If update rate is high, checkpoints can happen more frequently. + * Sets the checkpoint frequency which is a minimal interval when the memory state (updated data, indexes, etc.) + * will be written to the Persistent Store. If the rate is high, checkpoints can happen more frequently. * * @param checkpointFreq Checkpoint frequency in milliseconds. * @return {@code this} for chaining. @@ -116,70 +119,66 @@ public PersistentStoreConfiguration setCheckpointFrequency(long checkpointFreq) } /** - * Time out in second, while wait and try get file lock for start persist manager. + * Gets amount of memory allocated for a checkpoint temporary buffer. * - * @return Time for wait. + * @return Checkpoint page buffer size. */ - public int getLockWaitTime() { - return lockWaitTime; + public Long getCheckpointPageBufferSize() { + return checkpointPageBufSize; } /** - * Time out in milliseconds, while wait and try get file lock for start persist manager. + * Sets amount of memory allocated for the checkpoint temporary buffer. The buffer is used to create temporary + * copies of pages when the checkpoint process is in progress. * - * @param lockWaitTime Lock wait time. + * @param checkpointPageBufSize Checkpoint page buffer size. * @return {@code this} for chaining. */ - public PersistentStoreConfiguration setLockWaitTime(int lockWaitTime) { - this.lockWaitTime = lockWaitTime; + public PersistentStoreConfiguration setCheckpointPageBufferSize(long checkpointPageBufSize) { + this.checkpointPageBufSize = checkpointPageBufSize; return this; } - /** - * Gets amount of memory allocated for checkpoint temporary buffer. This buffer is used to create temporary - * copies of pages when checkpoint is in progress. + * Gets a number of threads to use for the checkpoint purposes. * - * @return Checkpoint page buffer size. + * @return Number of checkpoint threads. */ - public Long getCheckpointPageBufferSize() { - return checkpointPageBufSize; + public int getCheckpointThreads() { + return checkpointThreads; } /** - * Sets amount of memory allocated for checkpoint temporary buffer. This buffer is used to create temporary - * copies of pages when checkpoint is in progress. + * Sets a number of threads to use for the checkpoint purposes * - * @param checkpointPageBufSize Checkpoint page buffer size. + * @param checkpointThreads Number of checkpoint threads. One thread is used by default. * @return {@code this} for chaining. */ - public PersistentStoreConfiguration setCheckpointPageBufferSize(long checkpointPageBufSize) { - this.checkpointPageBufSize = checkpointPageBufSize; + public PersistentStoreConfiguration setCheckpointThreads(int checkpointThreads) { + this.checkpointThreads = checkpointThreads; return this; } - - /** - * Gets number of checkpoint threads to run. + * Time out in second, while wait and try get file lock for start persist manager. * - * @return Number of checkpoint threads. + * @return Time for wait. */ - public int getCheckpointThreads() { - return checkpointThreads; + public int getLockWaitTime() { + return lockWaitTime; } /** - * Sets number of checkpoint threads. + * Time out in milliseconds, while wait and try get file lock for start persist manager. * - * @param checkpointThreads Number of checkpoint threads. + * @param lockWaitTime Lock wait time. * @return {@code this} for chaining. */ - public PersistentStoreConfiguration setCheckpointThreads(int checkpointThreads) { - this.checkpointThreads = checkpointThreads; + public PersistentStoreConfiguration setLockWaitTime(int lockWaitTime) { + this.lockWaitTime = lockWaitTime; return this; } @@ -206,8 +205,7 @@ public PersistentStoreConfiguration setWalHistorySize(int walHistSize) { } /** - * Gets the number of Write Ahead Log segments to work with. Write-ahead log is written over a fixed number - * of preallocated file segments of fixed size. This parameter sets the number of these segments. + * Gets a number of Write-Ahead Log segments to work with. * * @return Number of work WAL segments. */ @@ -216,7 +214,8 @@ public int getWalSegments() { } /** - * Sets then number of work Write Ahead Log segments. + * Sets a number of Write Ahead Log segments to work with. Write-ahead log is written over a fixed number + * of pre-allocated file segments of fixed size. This parameter sets the number of these segments. * * @param walSegments Number of work WAL segments. * @return {@code this} for chaining. @@ -228,6 +227,8 @@ public PersistentStoreConfiguration setWalSegments(int walSegments) { } /** + * Gets size of a Write-Ahead Log segment. + * * @return WAL segment size. */ public int getWalSegmentSize() { @@ -235,7 +236,9 @@ public int getWalSegmentSize() { } /** - * @param walSegmentSize WAL segment size. + * Sets size of a Write-Ahead Log segment. + * + * @param walSegmentSize WAL segment size. 64 MB is used by default. * @return {@code this} for chaining. */ public PersistentStoreConfiguration setWalSegmentSize(int walSegmentSize) { @@ -245,8 +248,7 @@ public PersistentStoreConfiguration setWalSegmentSize(int walSegmentSize) { } /** - * Gets write-ahead log persistence path. If this path is relative, it will be resolved relative to - * Ignite work directory. + * Gets a path to the directory where Write-Ahead log is stored. * * @return Write-ahead log persistence path, absolute or relative to Ignite work directory. */ @@ -255,7 +257,8 @@ public String getWalStorePath() { } /** - * Sets write-ahead log persistence path. + * Sets a path to the directory where Write-Ahead log is stored . If this path is relative, it will be resolved + * relative to Ignite work directory. * * @param walStorePath Write-ahead log persistence path, absolute or relative to Ignite work directory. * @return {@code this} for chaining. @@ -267,7 +270,7 @@ public PersistentStoreConfiguration setWalStorePath(String walStorePath) { } /** - * Gets write-ahead log archive path. Full WAL segments will be copied to this directory before reuse. + * Gets a path to Write-Ahead log archive. Full WAL segments will be copied to this directory before reuse. * * @return WAL archive directory. */ @@ -276,7 +279,7 @@ public String getWalArchivePath() { } /** - * Sets write-ahead log archive path. Full WAL segments will be copied to this directory before reuse. + * Sets a path to store Write-Ahead log archive. Full WAL segments will be copied to this directory before reuse. * * @param walArchivePath WAL archive directory. * @return {@code this} for chaining. From 68ee06304209541a8a1fafaab8a149002d70022d Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 26 May 2017 11:35:31 +0300 Subject: [PATCH 217/311] ignite-gg-12163 fix concurrency lvl for rw lock by default --- .../pagemem/impl/PageMemoryNoStoreImpl.java | 3 ++- .../ignite/internal/util/IgniteUtils.java | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java index b205991196b47..dc72482634802 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java @@ -37,6 +37,7 @@ import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; import org.apache.ignite.internal.util.GridUnsafe; +import org.apache.ignite.internal.util.IgniteUtils; import org.apache.ignite.internal.util.OffheapReadWriteLock; import org.apache.ignite.internal.util.offheap.GridOffHeapOutOfMemoryException; import org.apache.ignite.internal.util.typedef.internal.U; @@ -148,7 +149,7 @@ public class PageMemoryNoStoreImpl implements PageMemory { /** Concurrency lvl. */ private final int lockConcLvl = IgniteSystemProperties.getInteger( IGNITE_OFFHEAP_LOCK_CONCURRENCY_LEVEL, - Runtime.getRuntime().availableProcessors() * 4 + IgniteUtils.nearestPow2(Runtime.getRuntime().availableProcessors() * 4) ); /** */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index d57c0f1220834..555238feb62d3 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -10185,6 +10185,29 @@ public static GridIntIterator forRange(final int start, final int cnt) { }; } + /** + * @param x X. + */ + public static int nearestPow2(int x) { + return nearestPow2(x, true); + } + + /** + * @param x X. + * @param less Less. + */ + public static int nearestPow2(int x, boolean less) { + int y = 1; + + while (y < x) + y *= 2; + + if (less) + y /= 2; + + return y; + } + /** * @param lock Lock. */ From 874096f33a68e61d96dfce2ef3af0f354b4ce102 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 26 May 2017 11:54:59 +0300 Subject: [PATCH 218/311] ignite-gg-12163 utils update nearestPow2 --- .../java/org/apache/ignite/internal/util/IgniteUtils.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 555238feb62d3..90de6837f1ad0 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -10197,10 +10197,16 @@ public static int nearestPow2(int x) { * @param less Less. */ public static int nearestPow2(int x, boolean less) { + assert x > 0 : "can not calculate for less zero"; + int y = 1; - while (y < x) + while (y < x){ + if ((long)y * 2 > Integer.MAX_VALUE) + return y; + y *= 2; + } if (less) y /= 2; From 13c5a5f37a448c5fde66538ff522ff2582db6146 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Fri, 26 May 2017 12:02:37 +0300 Subject: [PATCH 219/311] ignite-gg-12163 utils update --- .../java/org/apache/ignite/internal/util/IgniteUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 90de6837f1ad0..ba4717abc74e4 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -10199,11 +10199,11 @@ public static int nearestPow2(int x) { public static int nearestPow2(int x, boolean less) { assert x > 0 : "can not calculate for less zero"; - int y = 1; + long y = 1; while (y < x){ - if ((long)y * 2 > Integer.MAX_VALUE) - return y; + if (y * 2 > Integer.MAX_VALUE) + return (int)y; y *= 2; } @@ -10211,7 +10211,7 @@ public static int nearestPow2(int x, boolean less) { if (less) y /= 2; - return y; + return (int)y; } /** From 164e3188f303b3565a53634be713917b0f6e2e85 Mon Sep 17 00:00:00 2001 From: Ilya Lantukh Date: Fri, 26 May 2017 16:08:57 +0300 Subject: [PATCH 220/311] Fixed unhandled GridDhtInvalidPartitionException. --- .../dht/GridDhtGetSingleFuture.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java index d93831d7a6f06..9a7cfdcb4bb19 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java @@ -265,23 +265,28 @@ private void map0() { * @return {@code True} if mapped. */ private boolean map(KeyCacheObject key) { - GridDhtLocalPartition part = topVer.topologyVersion() > 0 ? - cache().topology().localPartition(cctx.affinity().partition(key), topVer, true) : - cache().topology().localPartition(key, false); + try { + GridDhtLocalPartition part = topVer.topologyVersion() > 0 ? + cache().topology().localPartition(cctx.affinity().partition(key), topVer, true) : + cache().topology().localPartition(key, false); - if (part == null) - return false; + if (part == null) + return false; - assert this.part == -1; + assert this.part == -1; - // By reserving, we make sure that partition won't be unloaded while processed. - if (part.reserve()) { - this.part = part.id(); + // By reserving, we make sure that partition won't be unloaded while processed. + if (part.reserve()) { + this.part = part.id(); - return true; + return true; + } + else + return false; } - else + catch (GridDhtInvalidPartitionException ex) { return false; + } } /** From a988b8ddee36209bae7a9fd7b3d6d39428bd4180 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Fri, 26 May 2017 17:08:55 +0300 Subject: [PATCH 221/311] IGNITE-GG-12163 JIRA for failing test with detailed description was created --- .../IgnitePersistentStoreCacheRebalancingAbstractTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index 75d655fb7172b..9f64f1b362adf 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -315,6 +315,8 @@ public void testDataCorrectnessAfterRestart() throws Exception { * @throws Exception If fails. */ public void testPartitionLossAndRecover() throws Exception { + fail("IGNITE-5302"); + Ignite ignite1 = startGrid(0); Ignite ignite2 = startGrid(1); Ignite ignite3 = startGrid(2); From 3450241fb101eaa6a6c0378f085097ba7609f1c0 Mon Sep 17 00:00:00 2001 From: Denis Magda Date: Fri, 26 May 2017 13:59:56 -0700 Subject: [PATCH 222/311] Fixed PersistentStore configuration documentation --- .../PersistentStoreConfiguration.java | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) 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 b2e10f4588385..94923c8489bdb 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 @@ -71,10 +71,10 @@ public class PersistentStoreConfiguration implements Serializable { /** Number of WAL segments to keep. */ private int walSegmentSize = DFLT_WAL_SEGMENT_SIZE; - /** Write-ahead log persistence path. */ + /** WAL persistence path. */ private String walStorePath; - /** Write-ahead log archive path. */ + /** WAL archive path. */ private String walArchivePath; /** @@ -184,18 +184,18 @@ public PersistentStoreConfiguration setLockWaitTime(int lockWaitTime) { } /** - * Gets the number checkpoints to keep in WAL history. + * Gets a total number of checkpoints to keep in the WAL history. * - * @return Number of WAL segments to keep after the checkpoint is finished. + * @return Number of WAL segments to keep after a checkpoint is finished. */ public int getWalHistorySize() { return walHistSize <= 0 ? DFLT_WAL_HISTORY_SIZE : walHistSize; } /** - * Sets the number of checkpoints to keep in WAL history. + * Sets a total number of checkpoints to keep in the WAL history. * - * @param walHistSize Number of WAL segments to keep after the checkpoint is finished. + * @param walHistSize Number of WAL segments to keep after a checkpoint is finished. * @return {@code this} for chaining. */ public PersistentStoreConfiguration setWalHistorySize(int walHistSize) { @@ -205,7 +205,7 @@ public PersistentStoreConfiguration setWalHistorySize(int walHistSize) { } /** - * Gets a number of Write-Ahead Log segments to work with. + * Gets a number of WAL segments to work with. * * @return Number of work WAL segments. */ @@ -214,10 +214,10 @@ public int getWalSegments() { } /** - * Sets a number of Write Ahead Log segments to work with. Write-ahead log is written over a fixed number - * of pre-allocated file segments of fixed size. This parameter sets the number of these segments. + * Sets a number of WAL segments to work with. For performance reasons, + * the whole WAL is split into files of fixed length called segments. * - * @param walSegments Number of work WAL segments. + * @param walSegments Number of WAL segments. * @return {@code this} for chaining. */ public PersistentStoreConfiguration setWalSegments(int walSegments) { @@ -227,7 +227,7 @@ public PersistentStoreConfiguration setWalSegments(int walSegments) { } /** - * Gets size of a Write-Ahead Log segment. + * Gets size of a WAL segment. * * @return WAL segment size. */ @@ -236,7 +236,7 @@ public int getWalSegmentSize() { } /** - * Sets size of a Write-Ahead Log segment. + * Sets size of a WAL segment. * * @param walSegmentSize WAL segment size. 64 MB is used by default. * @return {@code this} for chaining. @@ -248,19 +248,19 @@ public PersistentStoreConfiguration setWalSegmentSize(int walSegmentSize) { } /** - * Gets a path to the directory where Write-Ahead log is stored. + * Gets a path to the directory where WAL is stored. * - * @return Write-ahead log persistence path, absolute or relative to Ignite work directory. + * @return WAL persistence path, absolute or relative to Ignite work directory. */ public String getWalStorePath() { return walStorePath; } /** - * Sets a path to the directory where Write-Ahead log is stored . If this path is relative, it will be resolved - * relative to Ignite work directory. + * Sets a path to the directory where WAL is stored . If this path is relative, it will be resolved + * relatively to Ignite work directory. * - * @param walStorePath Write-ahead log persistence path, absolute or relative to Ignite work directory. + * @param walStorePath WAL persistence path, absolute or relative to Ignite work directory. * @return {@code this} for chaining. */ public PersistentStoreConfiguration setWalStorePath(String walStorePath) { @@ -270,7 +270,7 @@ public PersistentStoreConfiguration setWalStorePath(String walStorePath) { } /** - * Gets a path to Write-Ahead log archive. Full WAL segments will be copied to this directory before reuse. + * Gets a path to the WAL archive directory. * * @return WAL archive directory. */ @@ -279,7 +279,8 @@ public String getWalArchivePath() { } /** - * Sets a path to store Write-Ahead log archive. Full WAL segments will be copied to this directory before reuse. + * Sets a path for the WAL archive directory. Every WAL segment will be fully copied to this directory before + * it can be reused for WAL purposes. * * @param walArchivePath WAL archive directory. * @return {@code this} for chaining. From c68b61d3c3229c1c473cf06023df2ffe6d5aa547 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Fri, 26 May 2017 14:27:27 -0700 Subject: [PATCH 223/311] IGNITE-5295: NPE when Persistent Store is used and Memory Configuration is missing --- .../processors/cache/GridCacheProcessor.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 d7c1e3de04639..bed060158d55b 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 @@ -420,7 +420,7 @@ private void validate(IgniteConfiguration c, if (storesLocallyOnClient(c, cc)) throw new IgniteCheckedException("MemoryPolicy for client caches must be explicitly configured " + - "on client node startup. Use MemoryConfiguration to configure MemoryPolicy."); + "on client node startup. Use MemoryConfiguration to configure MemoryPolicy."); if (cc.getCacheMode() == LOCAL && !cc.getAffinity().getClass().equals(LocalAffinityFunction.class)) U.warn(log, "AffinityFunction configuration parameter will be ignored for local cache [cacheName=" + @@ -2075,11 +2075,19 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, IgniteWriteAheadLogManager walMgr = null; if (ctx.config().isPersistentStoreEnabled()) { - dbMgr = IgniteComponentType.DATABASE_MANAGER.create(ctx, false); + if (ctx.clientNode()) { + U.warn(log, "Persistent Store is not supported on client nodes (Persistent Store's" + + " configuration will be ignored)."); - pageStoreMgr = IgniteComponentType.PAGE_STORE_MANAGER.create(ctx, false); + dbMgr = new IgniteCacheDatabaseSharedManager(); + } + else { + dbMgr = IgniteComponentType.DATABASE_MANAGER.create(ctx, false); - walMgr = IgniteComponentType.WAL_MANAGER.create(ctx, false); + pageStoreMgr = IgniteComponentType.PAGE_STORE_MANAGER.create(ctx, false); + + walMgr = IgniteComponentType.WAL_MANAGER.create(ctx, false); + } } else dbMgr = new IgniteCacheDatabaseSharedManager(); From 43ddc7d5337635e49a7646d15bd85da22e8b7d4b Mon Sep 17 00:00:00 2001 From: Denis Magda Date: Wed, 31 May 2017 17:36:15 -0700 Subject: [PATCH 224/311] Fixed PersistentStore configuration documentation --- .../ignite/configuration/PersistentStoreConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 94923c8489bdb..ad97b861f89ba 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 @@ -106,8 +106,8 @@ public long getCheckpointFrequency() { } /** - * Sets the checkpoint frequency which is a minimal interval when the memory state (updated data, indexes, etc.) - * will be written to the Persistent Store. If the rate is high, checkpoints can happen more frequently. + * Sets the checkpointing frequency which is a minimal interval when the dirty pages will be written + * to the Persistent Store. If the rate is high, checkpointing will be triggered more frequently. * * @param checkpointFreq Checkpoint frequency in milliseconds. * @return {@code this} for chaining. From 3a44e3ac104775d58f24f193bd1cce1518526b91 Mon Sep 17 00:00:00 2001 From: Denis Magda Date: Wed, 31 May 2017 17:49:48 -0700 Subject: [PATCH 225/311] Renaming checkpoint to checkpointing in public interface --- .../PersistentStoreConfiguration.java | 65 ++++++++++--------- .../GridCacheDatabaseSharedManager.java | 12 ++-- ...tStoreRecoveryAfterFileCorruptionTest.java | 2 +- .../IgnitePersistentStoreWalTlbSelfTest.java | 4 +- .../RebalancingOnNotStableTopologyTest.java | 2 +- .../database/db/TransactionsHangTest.java | 2 +- ...PageStoreCheckpointSimulationSelfTest.java | 2 +- .../file/WalRecoveryTxLogicalRecordsTest.java | 2 +- 8 files changed, 46 insertions(+), 45 deletions(-) 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 ad97b861f89ba..14e3a7354d930 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 @@ -26,17 +26,17 @@ public class PersistentStoreConfiguration implements Serializable { private static final long serialVersionUID = 0L; /** */ - public static final int DFLT_CHECKPOINT_FREQ = 180000; + public static final int DFLT_CHECKPOINTING_FREQ = 180000; /** Lock default wait time, 10 sec. */ public static final int DFLT_LOCK_WAIT_TIME = 10 * 1000; /** */ @SuppressWarnings("UnnecessaryBoxing") - public static final Long DFLT_CHECKPOINT_PAGE_BUFFER_SIZE = new Long(256L * 1024 * 1024); + public static final Long DFLT_CHECKPOINTING_PAGE_BUFFER_SIZE = new Long(256L * 1024 * 1024); - /** Default number of checkpoint threads. */ - public static final int DFLT_CHECKPOINT_THREADS = 1; + /** Default number of checkpointing threads. */ + public static final int DFLT_CHECKPOINTING_THREADS = 1; /** */ private static final int DFLT_WAL_HISTORY_SIZE = 20; @@ -50,17 +50,17 @@ public class PersistentStoreConfiguration implements Serializable { /** */ private String persistenteStorePath; - /** Checkpoint frequency. */ - private long checkpointFreq = DFLT_CHECKPOINT_FREQ; + /** Checkpointing frequency. */ + private long checkpointingFreq = DFLT_CHECKPOINTING_FREQ; /** Lock wait time. */ private int lockWaitTime = DFLT_LOCK_WAIT_TIME; /** */ - private Long checkpointPageBufSize = DFLT_CHECKPOINT_PAGE_BUFFER_SIZE; + private Long checkpointingPageBufSize = DFLT_CHECKPOINTING_PAGE_BUFFER_SIZE; /** */ - private int checkpointThreads = DFLT_CHECKPOINT_THREADS; + private int checkpointingThreads = DFLT_CHECKPOINTING_THREADS; /** */ private int walHistSize = DFLT_WAL_HISTORY_SIZE; @@ -97,67 +97,68 @@ public PersistentStoreConfiguration setPersistentStorePath(String persistenceSto } /** - * Gets checkpoint frequency. + * Gets checkpointing frequency. * - * @return Checkpoint frequency in milliseconds. + * @return checkpointing frequency in milliseconds. */ - public long getCheckpointFrequency() { - return checkpointFreq <= 0 ? DFLT_CHECKPOINT_FREQ : checkpointFreq; + public long getCheckpointingFrequency() { + return checkpointingFreq <= 0 ? DFLT_CHECKPOINTING_FREQ : checkpointingFreq; } /** * Sets the checkpointing frequency which is a minimal interval when the dirty pages will be written * to the Persistent Store. If the rate is high, checkpointing will be triggered more frequently. * - * @param checkpointFreq Checkpoint frequency in milliseconds. + * @param checkpointingFreq checkpointing frequency in milliseconds. * @return {@code this} for chaining. */ - public PersistentStoreConfiguration setCheckpointFrequency(long checkpointFreq) { - this.checkpointFreq = checkpointFreq; + public PersistentStoreConfiguration setCheckpointingFrequency(long checkpointingFreq) { + this.checkpointingFreq = checkpointingFreq; return this; } /** - * Gets amount of memory allocated for a checkpoint temporary buffer. + * Gets amount of memory allocated for a checkpointing temporary buffer. * - * @return Checkpoint page buffer size. + * @return checkpointing page buffer size in bytes. */ - public Long getCheckpointPageBufferSize() { - return checkpointPageBufSize; + public Long getCheckpointingPageBufferSize() { + return checkpointingPageBufSize; } /** - * Sets amount of memory allocated for the checkpoint temporary buffer. The buffer is used to create temporary - * copies of pages when the checkpoint process is in progress. + * Sets amount of memory allocated for the checkpointing temporary buffer. The buffer is used to create temporary + * copies of pages that are being written to disk and being update in parallel while the checkpointing is in + * progress. * - * @param checkpointPageBufSize Checkpoint page buffer size. + * @param checkpointingPageBufSize checkpointing page buffer size in bytes. * @return {@code this} for chaining. */ - public PersistentStoreConfiguration setCheckpointPageBufferSize(long checkpointPageBufSize) { - this.checkpointPageBufSize = checkpointPageBufSize; + public PersistentStoreConfiguration setCheckpointingPageBufferSize(long checkpointingPageBufSize) { + this.checkpointingPageBufSize = checkpointingPageBufSize; return this; } /** - * Gets a number of threads to use for the checkpoint purposes. + * Gets a number of threads to use for the checkpointing purposes. * - * @return Number of checkpoint threads. + * @return Number of checkpointing threads. */ - public int getCheckpointThreads() { - return checkpointThreads; + public int getCheckpointingThreads() { + return checkpointingThreads; } /** - * Sets a number of threads to use for the checkpoint purposes + * Sets a number of threads to use for the checkpointing purposes. * - * @param checkpointThreads Number of checkpoint threads. One thread is used by default. + * @param checkpointingThreads Number of checkpointing threads. One thread is used by default. * @return {@code this} for chaining. */ - public PersistentStoreConfiguration setCheckpointThreads(int checkpointThreads) { - this.checkpointThreads = checkpointThreads; + public PersistentStoreConfiguration setCheckpointingThreads(int checkpointingThreads) { + this.checkpointingThreads = checkpointingThreads; return this; } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index a78ba279b0747..0f75b0ddb8339 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -277,7 +277,7 @@ public GridCacheDatabaseSharedManager(GridKernalContext ctx) { assert dbCfg != null : "PageStore should not be created if persistence is disabled."; - checkpointFreq = dbCfg.getCheckpointFrequency(); + checkpointFreq = dbCfg.getCheckpointingFrequency(); lockWaitTime = dbCfg.getLockWaitTime(); @@ -343,12 +343,12 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { * */ @Override public void initDataBase() throws IgniteCheckedException { - Long cpBufSize = dbCfg.getCheckpointPageBufferSize(); + Long cpBufSize = dbCfg.getCheckpointingPageBufferSize(); - if (dbCfg.getCheckpointThreads() > 1) + if (dbCfg.getCheckpointingThreads() > 1) asyncRunner = new ThreadPoolExecutor( - dbCfg.getCheckpointThreads(), - dbCfg.getCheckpointThreads(), + dbCfg.getCheckpointingThreads(), + dbCfg.getCheckpointingThreads(), 30L, TimeUnit.SECONDS, new LinkedBlockingQueue() @@ -356,7 +356,7 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { // Intentionally use identity comparison to check if configuration default has changed. // Noinspection NumberEquality. - if (cpBufSize == PersistentStoreConfiguration.DFLT_CHECKPOINT_PAGE_BUFFER_SIZE) { + if (cpBufSize == PersistentStoreConfiguration.DFLT_CHECKPOINTING_PAGE_BUFFER_SIZE) { MemoryConfiguration memCfg = cctx.kernalContext().config().getMemoryConfiguration(); assert memCfg != null; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java index d22a12fe40609..fd73204c87be6 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java @@ -99,7 +99,7 @@ public class IgnitePersistentStoreRecoveryAfterFileCorruptionTest extends GridCo PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); - pCfg.setCheckpointFrequency(500); + pCfg.setCheckpointingFrequency(500); cfg.setPersistentStoreConfiguration(pCfg); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java index db1f644a5fbb1..26e2aa6d433ed 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java @@ -32,7 +32,7 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import static org.apache.ignite.configuration.PersistentStoreConfiguration.DFLT_CHECKPOINT_PAGE_BUFFER_SIZE; +import static org.apache.ignite.configuration.PersistentStoreConfiguration.DFLT_CHECKPOINTING_PAGE_BUFFER_SIZE; /** * @@ -67,7 +67,7 @@ public class IgnitePersistentStoreWalTlbSelfTest extends GridCommonAbstractTest cfg.setPersistentStoreConfiguration( new PersistentStoreConfiguration() - .setCheckpointPageBufferSize(DFLT_CHECKPOINT_PAGE_BUFFER_SIZE + 1) + .setCheckpointingPageBufferSize(DFLT_CHECKPOINTING_PAGE_BUFFER_SIZE + 1) ); TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java index 7f4f287e18f51..e85c639faf444 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java @@ -167,7 +167,7 @@ public void test() throws Exception { PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); - pCfg.setCheckpointFrequency(CHECKPOINT_FREQUENCY); + pCfg.setCheckpointingFrequency(CHECKPOINT_FREQUENCY); cfg.setPersistentStoreConfiguration(pCfg); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java index 074b408fbbae0..3d57ba4ed550e 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java @@ -125,7 +125,7 @@ public class TransactionsHangTest extends GridCommonAbstractTest { PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); pCfg.setWalHistorySize(1); - pCfg.setCheckpointFrequency(CHECKPOINT_FREQUENCY); + pCfg.setCheckpointingFrequency(CHECKPOINT_FREQUENCY); cfg.setPersistentStoreConfiguration(pCfg); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java index 92629f7ab44b9..f4445053f01a0 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java @@ -106,7 +106,7 @@ public class PageStoreCheckpointSimulationSelfTest extends GridCommonAbstractTes PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); - pCfg.setCheckpointFrequency(500); + pCfg.setCheckpointingFrequency(500); cfg.setPersistentStoreConfiguration(pCfg); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java index cf0684a186f54..fa537231eb586 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java @@ -116,7 +116,7 @@ public class WalRecoveryTxLogicalRecordsTest extends GridCommonAbstractTest { pCfg.setWalHistorySize(WAL_HIST_SIZE); if (checkpointFreq != null) - pCfg.setCheckpointFrequency(checkpointFreq); + pCfg.setCheckpointingFrequency(checkpointFreq); cfg.setPersistentStoreConfiguration(pCfg); From c6fe26b8aae298e2645d3ed8e14e24836caef6e1 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Thu, 1 Jun 2017 20:12:10 +0300 Subject: [PATCH 226/311] IGNITE-5267 - Added tx participating node IDs to transaction record. --- .../internal/pagemem/wal/record/TxRecord.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/TxRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/TxRecord.java index c2877df12b691..6aa899cfc4bc9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/TxRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/TxRecord.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.pagemem.wal.record; +import java.util.UUID; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; /** @@ -62,6 +63,9 @@ public static TxAction fromOrdinal(int ord) { /** */ private GridCacheVersion dhtVer; + /** */ + private UUID[] participatingNodeIds; + /** {@inheritDoc} */ @Override public RecordType type() { return RecordType.TX_RECORD; @@ -108,4 +112,18 @@ public TxAction action() { public void action(TxAction action) { this.action = action; } + + /** + * @param participatingNodeIds Participating node IDs. + */ + public void participatingNodeIds(UUID[] participatingNodeIds) { + this.participatingNodeIds = participatingNodeIds; + } + + /** + * @return Participating node IDs. + */ + public UUID[] participatingNodeId() { + return participatingNodeIds; + } } From 281d105f65f3dfd04c4ffa0ee82d052335506d93 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 2 Jun 2017 11:18:40 +0300 Subject: [PATCH 227/311] Unmuted test --- .../IgnitePersistentStoreCacheRebalancingAbstractTest.java | 2 -- .../database/IgnitePersistentStoreTxCacheRebalancingTest.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java index 9f64f1b362adf..74118ef9c54fa 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheRebalancingAbstractTest.java @@ -364,8 +364,6 @@ public void testPartitionLossAndRecover() throws Exception { * @throws Exception If failed. */ public void testTopologyChangesWithConstantLoad() throws Exception { - fail("only for one run, must be removed soon"); - final int entriesCnt = 10_000; int maxNodesCount = 4; int topChanges = 20; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java index a5649165c60f4..fb71b8a6fa33e 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java @@ -54,8 +54,6 @@ public class IgnitePersistentStoreTxCacheRebalancingTest extends IgnitePersisten * @throws Exception If failed. */ public void testTopologyChangesWithConstantLoadExplicitTx() throws Exception { - fail("only for one run, must be removed soon"); - explicitTx = true; testTopologyChangesWithConstantLoad(); From c7a7e64237e8a2549d43e5e8ba6a3d77529cc150 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 2 Jun 2017 14:12:17 +0300 Subject: [PATCH 228/311] IGNITE-5267 - Fixed compilation after merge from master --- .../processors/query/h2/H2IndexingAbstractGeoSelfTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java index fb6a104acb5c3..e9f96e39f738f 100644 --- a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java +++ b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java @@ -227,7 +227,7 @@ private static void destroy(IgniteCache cache, IgniteEx grid, boolean dynamic) { if (!dynamic) cache.destroy(); else - grid.context().cache().dynamicDestroyCache(cache.getName(), true, true); + grid.context().cache().dynamicDestroyCache(cache.getName(), true, true, false); } /** From 7e45010b4848d0a570995e6dc938875710d846d8 Mon Sep 17 00:00:00 2001 From: sboikov Date: Sun, 4 Jun 2017 11:02:31 +0300 Subject: [PATCH 229/311] ignite-5075 'logical' caches sharing the same 'physical' cache group --- .../configuration/CacheConfiguration.java | 21 + .../managers/communication/GridIoManager.java | 12 +- .../managers/discovery/DiscoCache.java | 30 +- .../discovery/GridDiscoveryManager.java | 178 +- .../ignite/internal/pagemem/PageUtils.java | 16 + .../pagemem/snapshot/SnapshotOperation.java | 18 +- .../pagemem/store/IgnitePageStoreManager.java | 50 +- .../pagemem/wal/record/CheckpointRecord.java | 22 +- .../MetaPageUpdatePartitionDataRecord.java | 14 +- .../affinity/GridAffinityAssignmentCache.java | 38 +- .../cache/CacheAffinitySharedManager.java | 627 +-- .../CacheClientReconnectDiscoveryData.java | 66 +- .../internal/processors/cache/CacheData.java | 22 +- .../processors/cache/CacheGroupContext.java | 964 +++++ .../processors/cache/CacheGroupData.java | 147 + .../cache/CacheGroupDescriptor.java | 210 + .../cache/CacheJoinNodeDiscoveryData.java | 4 +- .../processors/cache/CacheMetricsImpl.java | 10 +- .../cache/CacheNodeCommonDiscoveryData.java | 19 + .../cache/CacheOffheapEvictionManager.java | 11 +- .../processors/cache/ClusterCachesInfo.java | 531 ++- .../cache/ClusterCachesReconnectResult.java | 61 + .../cache/DynamicCacheDescriptor.java | 26 + .../processors/cache/ExchangeActions.java | 86 +- .../processors/cache/GridCacheAdapter.java | 63 +- .../cache/GridCacheAffinityManager.java | 62 +- .../processors/cache/GridCacheAttributes.java | 21 +- .../cache/GridCacheClearAllRunnable.java | 2 +- .../cache/GridCacheConcurrentMap.java | 55 +- .../cache/GridCacheConcurrentMapImpl.java | 171 +- .../processors/cache/GridCacheContext.java | 167 +- .../processors/cache/GridCacheEntryInfo.java | 37 +- .../cache/GridCacheEventManager.java | 36 - .../cache/GridCacheGroupIdMessage.java | 110 + .../processors/cache/GridCacheIdMessage.java | 117 + .../processors/cache/GridCacheIoManager.java | 282 +- .../cache/GridCacheLocalConcurrentMap.java | 56 +- .../processors/cache/GridCacheMapEntry.java | 76 +- .../processors/cache/GridCacheMessage.java | 97 +- .../GridCachePartitionExchangeManager.java | 298 +- .../processors/cache/GridCachePreloader.java | 23 +- .../cache/GridCachePreloaderAdapter.java | 46 +- .../processors/cache/GridCacheProcessor.java | 476 ++- .../cache/GridCacheSharedContext.java | 4 +- .../processors/cache/GridCacheTtlManager.java | 22 +- .../processors/cache/GridCacheUtils.java | 42 +- .../GridChangeGlobalStateMessageResponse.java | 20 +- .../cache/GridNoStorageCacheMap.java | 30 +- .../cache/IgniteCacheOffheapManager.java | 169 +- .../cache/IgniteCacheOffheapManagerImpl.java | 1260 ++++-- .../cache/affinity/GridCacheAffinityImpl.java | 9 +- .../cache/database/CacheDataRow.java | 5 - .../cache/database/CacheDataRowAdapter.java | 65 +- .../cache/database/CacheSearchRow.java | 5 + .../IgniteCacheDatabaseSharedManager.java | 9 +- .../database/IgniteCacheSnapshotManager.java | 14 +- .../processors/cache/database/MetaStore.java | 6 +- .../cache/database/MetadataStorage.java | 22 +- .../processors/cache/database/RowStore.java | 29 +- .../cache/database/tree/BPlusTree.java | 39 +- .../cache/database/tree/io/PageIO.java | 30 + .../tree/io/PagePartitionCountersIO.java | 175 + .../database/tree/io/PagePartitionMetaIO.java | 20 + .../GridCacheTtlUpdateRequest.java | 4 +- .../GridDistributedBaseMessage.java | 4 +- .../GridDistributedCacheAdapter.java | 13 +- .../GridDistributedTxFinishResponse.java | 28 +- .../GridDistributedTxRemoteAdapter.java | 2 + .../GridCachePartitionedConcurrentMap.java | 76 +- .../dht/GridClientPartitionTopology.java | 25 +- .../dht/GridDhtAffinityAssignmentRequest.java | 10 +- .../GridDhtAffinityAssignmentResponse.java | 12 +- .../dht/GridDhtAssignmentFetchFuture.java | 22 +- .../distributed/dht/GridDhtCacheAdapter.java | 363 +- .../distributed/dht/GridDhtCacheEntry.java | 16 +- .../distributed/dht/GridDhtGetFuture.java | 8 +- .../dht/GridDhtGetSingleFuture.java | 39 +- .../dht/GridDhtLocalPartition.java | 444 +- .../distributed/dht/GridDhtLockResponse.java | 2 +- .../dht/GridDhtPartitionTopology.java | 9 +- .../dht/GridDhtPartitionTopologyImpl.java | 278 +- .../dht/GridDhtTransactionalCacheAdapter.java | 37 +- .../dht/GridDhtTxFinishResponse.java | 14 +- .../GridDhtTxOnePhaseCommitAckRequest.java | 16 +- .../dht/GridDhtTxPrepareFuture.java | 4 +- .../dht/GridPartitionedGetFuture.java | 2 +- .../dht/GridPartitionedSingleGetFuture.java | 2 +- .../GridDhtAtomicAbstractUpdateRequest.java | 4 +- .../dht/atomic/GridDhtAtomicCache.java | 68 +- .../dht/atomic/GridDhtAtomicCacheEntry.java | 53 - .../GridDhtAtomicDeferredUpdateResponse.java | 4 +- .../dht/atomic/GridDhtAtomicNearResponse.java | 4 +- .../atomic/GridDhtAtomicUpdateResponse.java | 5 +- .../GridNearAtomicAbstractUpdateRequest.java | 4 +- .../GridNearAtomicCheckUpdateRequest.java | 4 +- .../atomic/GridNearAtomicUpdateResponse.java | 4 +- .../dht/colocated/GridDhtColocatedCache.java | 24 +- .../colocated/GridDhtColocatedCacheEntry.java | 52 - .../dht/preloader/GridDhtForceKeysFuture.java | 15 +- .../preloader/GridDhtForceKeysRequest.java | 4 +- .../preloader/GridDhtForceKeysResponse.java | 8 +- .../GridDhtPartitionDemandMessage.java | 12 +- .../preloader/GridDhtPartitionDemander.java | 262 +- .../preloader/GridDhtPartitionSupplier.java | 73 +- .../GridDhtPartitionSupplyMessage.java | 116 +- .../GridDhtPartitionsAbstractMessage.java | 26 +- .../GridDhtPartitionsExchangeFuture.java | 259 +- .../GridDhtPartitionsFullMessage.java | 74 +- .../GridDhtPartitionsSingleMessage.java | 62 +- .../GridDhtPartitionsSingleRequest.java | 7 +- .../dht/preloader/GridDhtPreloader.java | 419 +- .../distributed/near/GridNearAtomicCache.java | 2 +- .../near/GridNearCacheAdapter.java | 16 +- .../distributed/near/GridNearGetRequest.java | 4 +- .../distributed/near/GridNearGetResponse.java | 4 +- .../GridNearOptimisticTxPrepareFuture.java | 21 +- .../near/GridNearSingleGetRequest.java | 4 +- .../near/GridNearSingleGetResponse.java | 6 +- .../near/GridNearTransactionalCache.java | 4 +- .../near/GridNearTxFinishResponse.java | 14 +- .../cache/local/GridLocalCache.java | 21 +- .../local/atomic/GridLocalAtomicCache.java | 4 +- .../GridCacheDistributedQueryManager.java | 10 +- .../cache/query/GridCacheQueryManager.java | 4 +- .../cache/query/GridCacheQueryRequest.java | 3 +- .../cache/query/GridCacheQueryResponse.java | 4 +- .../CacheContinuousQueryBatchAck.java | 4 +- .../CacheContinuousQueryEventBuffer.java | 5 +- .../CacheContinuousQueryHandler.java | 66 +- .../CacheContinuousQueryListener.java | 20 + .../CacheContinuousQueryManager.java | 59 +- .../query/continuous/CounterSkipContext.java | 78 + .../cache/transactions/IgniteTxAdapter.java | 2 +- .../cache/transactions/IgniteTxEntry.java | 4 +- .../cache/transactions/IgniteTxHandler.java | 26 +- .../transactions/IgniteTxLocalAdapter.java | 2 + .../cache/transactions/TxLocksRequest.java | 20 +- .../cache/transactions/TxLocksResponse.java | 28 +- .../cluster/GridClusterStateProcessor.java | 9 +- .../processors/query/GridQueryProcessor.java | 4 +- .../internal/processors/query/QueryUtils.java | 29 +- .../visor/cache/VisorCachePartitionsTask.java | 2 +- ...CacheAtomicSingleMessageCountSelfTest.java | 2 +- .../cache/CacheDeferredDeleteQueueTest.java | 2 +- ...eDhtLocalPartitionAfterRemoveSelfTest.java | 2 +- ...cheExchangeMessageDuplicatedStateTest.java | 54 +- .../CacheGroupsMetricsRebalanceTest.java | 140 + .../cache/CacheOffheapMapEntrySelfTest.java | 9 +- ...ridCacheConditionalDeploymentSelfTest.java | 18 + .../processors/cache/GridCacheLeakTest.java | 3 +- .../GridCacheOrderedPreloadingSelfTest.java | 14 +- .../cache/GridCacheTtlManagerSelfTest.java | 3 +- .../cache/IgniteCacheGroupsTest.java | 3765 +++++++++++++++++ .../IgniteCachePeekModesAbstractTest.java | 2 +- .../cache/IgniteCacheStartTest.java | 5 +- .../cache/IgniteOnePhaseCommitInvokeTest.java | 4 +- ...teTopologyValidatorGridSplitCacheTest.java | 8 +- ...gniteTxStoreExceptionAbstractSelfTest.java | 4 +- ...ridCacheBinaryObjectsAbstractSelfTest.java | 2 +- .../GridCacheQueueCleanupSelfTest.java | 13 +- .../GridCacheSetAbstractSelfTest.java | 17 +- .../GridCacheSetFailoverAbstractSelfTest.java | 6 +- .../IgnitePartitionedQueueNoBackupsTest.java | 6 +- ...IgnitePartitionedSetNoBackupsSelfTest.java | 6 +- .../CacheDiscoveryDataConcurrentJoinTest.java | 17 + .../distributed/CacheGroupsPreloadTest.java | 194 + .../CacheLateAffinityAssignmentTest.java | 6 +- ...gniteCachePartitionLossPolicySelfTest.java | 19 +- .../IgniteCacheReadFromBackupTest.java | 5 +- ...bledMultiNodeWithGroupFullApiSelfTest.java | 35 + .../atomic/IgniteCacheAtomicProtocolTest.java | 7 +- ...omicMultiNodeWithGroupFullApiSelfTest.java | 34 + ...bledMultiNodeWithGroupFullApiSelfTest.java | 35 + .../near/GridCacheNearReadersSelfTest.java | 4 +- ...onedMultiNodeWithGroupFullApiSelfTest.java | 34 + .../GridCacheReplicatedPreloadSelfTest.java | 3 +- .../IgniteCacheClientNearCacheExpiryTest.java | 20 +- .../expiry/IgniteCacheTtlCleanupSelfTest.java | 2 +- ...niteCacheJdbcBlobStoreNodeRestartTest.java | 3 + ...heLocalAtomicWithGroupFullApiSelfTest.java | 34 + .../local/GridCacheLocalFullApiSelfTest.java | 1 - ...ridCacheLocalWithGroupFullApiSelfTest.java | 34 + ...ousQueryConcurrentPartitionUpdateTest.java | 229 +- ...ntinuousQueryFailoverAbstractSelfTest.java | 7 +- .../TxOptimisticDeadlockDetectionTest.java | 2 +- .../TxPessimisticDeadlockDetectionTest.java | 2 +- .../hashmap/GridCacheTestContext.java | 6 +- .../GridCacheMessageSelfTest.java | 30 + .../ignite/testframework/GridTestUtils.java | 9 + .../junits/GridAbstractTest.java | 17 + .../junits/common/GridCommonAbstractTest.java | 64 + .../IgniteCacheFullApiSelfTestSuite.java | 13 + .../IgniteCacheMetricsSelfTestSuite.java | 3 + .../testsuites/IgniteCacheTestSuite3.java | 4 + .../testsuites/IgniteCacheTestSuite4.java | 2 + .../processors/query/h2/IgniteH2Indexing.java | 3 +- .../query/h2/database/H2PkHashIndex.java | 4 +- .../query/h2/database/H2RowFactory.java | 2 +- .../processors/query/h2/database/H2Tree.java | 6 +- .../query/h2/database/H2TreeIndex.java | 26 +- .../h2/twostep/GridReduceQueryExecutor.java | 12 +- .../cache/IgniteCacheGroupsSqlTest.java | 317 ++ .../IgniteCacheNoClassQuerySelfTest.java | 23 +- .../IgniteCacheWithIndexingTestSuite.java | 3 + .../GridCacheDatabaseSharedManager.java | 298 +- .../database/GridCacheOffheapManager.java | 490 ++- .../database/file/FilePageStoreManager.java | 202 +- .../cache/database/pagemem/PageMemoryEx.java | 8 +- .../database/pagemem/PageMemoryImpl.java | 10 +- .../wal/serializer/RecordV1Serializer.java | 12 +- .../IgnitePersistentStoreCacheGroupsTest.java | 516 +++ ...nitePersistentStoreDataStructuresTest.java | 205 + ...ntStoreMultiNodePutGetRestartSelfTest.java | 2 - ...xingAndGroupPutGetPersistenceSelfTest.java | 42 + .../pagemem/NoOpPageStoreManager.java | 22 +- .../ignite/testsuites/IgnitePdsTestSuite.java | 5 + .../testsuites/IgnitePdsTestSuite2.java | 5 +- modules/yardstick/pom.xml | 6 + .../yardstick/IgniteBenchmarkArguments.java | 39 +- .../apache/ignite/yardstick/IgniteNode.java | 23 +- .../cache/IgniteCacheAbstractBenchmark.java | 158 + .../cache/IgniteGetAllBenchmark.java | 3 + .../cache/IgniteGetAllPutAllTxBenchmark.java | 2 + .../cache/IgniteGetAndPutBenchmark.java | 2 + .../cache/IgniteGetAndPutTxBenchmark.java | 2 + .../yardstick/cache/IgniteGetBenchmark.java | 35 +- .../IgniteGetEntriesPutAllTxBenchmark.java | 2 + .../cache/IgniteInvokeBenchmark.java | 2 + .../cache/IgniteInvokeTxBenchmark.java | 2 + .../IgniteInvokeWithInjectionBenchmark.java | 2 + .../cache/IgnitePutAllBenchmark.java | 2 + .../IgnitePutAllSerializableTxBenchmark.java | 2 + .../yardstick/cache/IgnitePutBenchmark.java | 2 + .../cache/IgnitePutGetBatchBenchmark.java | 2 + .../cache/IgnitePutGetBenchmark.java | 2 + .../cache/IgnitePutGetEntryBenchmark.java | 2 + .../cache/IgnitePutGetEntryTxBenchmark.java | 2 + .../cache/IgnitePutGetTxBatchBenchmark.java | 2 + .../cache/IgnitePutGetTxBenchmark.java | 2 + ...nitePutIfAbsentIndexedValue1Benchmark.java | 2 + .../IgnitePutIndexedValue1Benchmark.java | 2 + .../IgnitePutIndexedValue2Benchmark.java | 2 + .../IgnitePutIndexedValue8Benchmark.java | 2 + .../IgnitePutRandomValueSizeBenchmark.java | 2 + .../cache/IgnitePutRemoveBenchmark.java | 2 + .../yardstick/cache/IgnitePutTxBenchmark.java | 2 + .../cache/IgnitePutTxImplicitBenchmark.java | 2 + .../IgnitePutTxPrimaryOnlyBenchmark.java | 2 + .../IgnitePutTxSkipLocalBackupBenchmark.java | 2 + .../cache/IgnitePutValue8Benchmark.java | 2 + .../IgniteReplaceIndexedValue1Benchmark.java | 2 + .../cache/IgniteScanQueryBenchmark.java | 88 + .../cache/IgniteSqlQueryBenchmark.java | 16 +- ...gniteSqlQueryDistributedJoinBenchmark.java | 24 +- .../cache/IgniteSqlQueryJoinBenchmark.java | 14 +- .../cache/IgniteSqlQueryPutBenchmark.java | 8 +- .../IgniteSqlQueryPutSeparatedBenchmark.java | 4 + .../cache/jdbc/JdbcPutGetBenchmark.java | 4 +- .../IgniteCacheRandomOperationBenchmark.java | 46 +- .../yardstick/cache/load/model/ModelUtil.java | 6 +- 260 files changed, 14449 insertions(+), 4079 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupData.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupDescriptor.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesReconnectResult.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGroupIdMessage.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionCountersIO.java delete mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCacheEntry.java delete mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCacheEntry.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupsMetricsRebalanceTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGroupsPreloadTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledMultiNodeWithGroupFullApiSelfTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicMultiNodeWithGroupFullApiSelfTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearEnabledMultiNodeWithGroupFullApiSelfTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeWithGroupFullApiSelfTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalAtomicWithGroupFullApiSelfTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalWithGroupFullApiSelfTest.java create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsSqlTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheGroupsTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDataStructuresTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java create mode 100644 modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteScanQueryBenchmark.java diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java index 21f2fba7adfbc..67b75906958df 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java @@ -202,6 +202,9 @@ public class CacheConfiguration extends MutableConfiguration { /** Cache name. */ private String name; + /** Cache group name. */ + private String grpName; + /** Name of {@link MemoryPolicyConfiguration} for this cache */ private String memPlcName; @@ -408,6 +411,7 @@ public CacheConfiguration(CompleteConfiguration cfg) { evictFilter = cc.getEvictionFilter(); evictPlc = cc.getEvictionPolicy(); expiryPolicyFactory = cc.getExpiryPolicyFactory(); + grpName = cc.getGroupName(); indexedTypes = cc.getIndexedTypes(); interceptor = cc.getInterceptor(); invalidate = cc.isInvalidate(); @@ -454,6 +458,23 @@ public CacheConfiguration(CompleteConfiguration cfg) { writeSync = cc.getWriteSynchronizationMode(); } + /** + * @return Cache group name. + */ + public String getGroupName() { + return grpName; + } + + /** + * @param grpName Cache group name. + * @return {@code this} for chaining. + */ + public CacheConfiguration setGroupName(String grpName) { + this.grpName = grpName; + + return this; + } + /** * Cache name or {@code null} if not provided, then this will be considered a default * cache which can be accessed via {@link Ignite#cache(String)} method. Otherwise, if name diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java index 698baf868dbc2..ea49dbe46fd28 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java @@ -1008,7 +1008,7 @@ private void onMessage0(UUID nodeId, GridIoMessage msg, IgniteRunnable msgC) { } default: - assert plc >= 0 : "Negative policy: " + plc; + assert plc >= 0 : "Negative policy [plc=" + plc + ", msg=" + msg + ']'; if (isReservedGridIoPolicy(plc)) throw new IgniteCheckedException("Failed to process message with policy of reserved range. " + @@ -1153,10 +1153,14 @@ private void processRegularMessage( pools.poolForPolicy(plc).execute(c); } catch (RejectedExecutionException e) { - U.error(log, "Failed to process regular message due to execution rejection. Will attempt to process " + - "message in the listener thread instead.", e); + if (!ctx.isStopping()) { + U.error(log, "Failed to process regular message due to execution rejection. Will attempt to process " + + "message in the listener thread instead.", e); - c.run(); + c.run(); + } + else if (log.isDebugEnabled()) + log.debug("Failed to process regular message due to execution rejection: " + msg); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoCache.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoCache.java index 5247ac1b28091..22c2d0775fa78 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoCache.java @@ -69,7 +69,7 @@ public class DiscoCache { /** Affinity cache nodes by cache name. */ @GridToStringInclude - private final Map> affCacheNodes; + private final Map> cacheGrpAffNodes; /** Node map. */ private final Map nodeMap; @@ -91,7 +91,7 @@ public class DiscoCache { * @param allNodesWithCaches All nodes with at least one cache configured. * @param rmtNodesWithCaches Remote nodes with at least one cache configured. * @param allCacheNodes Cache nodes by cache name. - * @param affCacheNodes Affinity cache nodes by cache name. + * @param cacheGrpAffNodes Affinity nodes by cache group ID. * @param nodeMap Node map. * @param nearEnabledCaches Caches where at least one node has near cache enabled. * @param alives Alive nodes. @@ -105,7 +105,7 @@ public class DiscoCache { List allNodesWithCaches, List rmtNodesWithCaches, Map> allCacheNodes, - Map> affCacheNodes, + Map> cacheGrpAffNodes, Map nodeMap, Set nearEnabledCaches, Set alives) { @@ -118,7 +118,7 @@ public class DiscoCache { this.allNodesWithCaches = allNodesWithCaches; this.rmtNodesWithCaches = rmtNodesWithCaches; this.allCacheNodes = allCacheNodes; - this.affCacheNodes = affCacheNodes; + this.cacheGrpAffNodes = cacheGrpAffNodes; this.nodeMap = nodeMap; this.nearEnabledCaches = nearEnabledCaches; this.alives.addAll(alives); @@ -235,25 +235,11 @@ public List cacheNodes(Integer cacheId) { } /** - * Gets all nodes that have cache with given ID and should participate in affinity calculation. With - * partitioned cache nodes with near-only cache do not participate in affinity node calculation. - * - * @param cacheName Cache name. - * @return Collection of nodes. - */ - public List cacheAffinityNodes(@Nullable String cacheName) { - return cacheAffinityNodes(CU.cacheId(cacheName)); - } - - /** - * Gets all nodes that have cache with given ID and should participate in affinity calculation. With - * partitioned cache nodes with near-only cache do not participate in affinity node calculation. - * - * @param cacheId Cache ID. - * @return Collection of nodes. + * @param grpId Cache group ID. + * @return All nodes that participate in affinity calculation. */ - public List cacheAffinityNodes(int cacheId) { - return emptyIfNull(affCacheNodes.get(cacheId)); + public List cacheGroupAffinityNodes(int grpId) { + return emptyIfNull(cacheGrpAffNodes.get(grpId)); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java index 7c702c2f70ba4..e144d9a5af24d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java @@ -69,7 +69,7 @@ import org.apache.ignite.internal.managers.communication.GridIoManager; import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.jobmetrics.GridJobMetrics; import org.apache.ignite.internal.processors.security.SecurityContext; @@ -251,11 +251,14 @@ public class GridDiscoveryManager extends GridManagerAdapter { new ConcurrentHashMap8<>(); /** Local node initialization event listeners. */ - private final Collection> localNodeInitLsnrs = new ArrayList<>(); + private final Collection> locNodeInitLsnrs = new ArrayList<>(); /** Map of dynamic cache filters. */ private Map registeredCaches = new HashMap<>(); + /** */ + private Map registeredCacheGrps = new HashMap<>(); + /** */ private final GridSpinBusyLock busyLock = new GridSpinBusyLock(); @@ -320,25 +323,56 @@ private MemoryUsage getHeapMemoryUsage() { spi.setNodeAttributes(ctx.nodeAttributes(), VER); } + /** + * + */ + public void onLocalNodeJoin() { + registeredCacheGrps.clear(); + registeredCaches.clear(); + } + + /** + * @param grpDesc Cache group descriptor. + * @param filter Node filter. + * @param cacheMode Cache mode. + */ + public void addCacheGroup(CacheGroupDescriptor grpDesc, IgnitePredicate filter, CacheMode cacheMode) { + CacheGroupAffinity old = registeredCacheGrps.put(grpDesc.groupId(), + new CacheGroupAffinity(grpDesc.cacheOrGroupName(), filter, cacheMode)); + + assert old == null : old; + } + + /** + * @param grpDesc Cache group descriptor. + */ + public void removeCacheGroup(CacheGroupDescriptor grpDesc) { + CacheGroupAffinity rmvd = registeredCacheGrps.remove(grpDesc.groupId()); + + assert rmvd != null : grpDesc.cacheOrGroupName(); + } + /** * Adds dynamic cache filter. * + * @param grpId Cache group ID. * @param cacheName Cache name. - * @param filter Cache filter. * @param nearEnabled Near enabled flag. - * @param cacheMode Cache mode. */ public void setCacheFilter( + int grpId, String cacheName, - IgnitePredicate filter, - boolean nearEnabled, - CacheMode cacheMode + boolean nearEnabled ) { if (!registeredCaches.containsKey(cacheName)) { - if (cacheMode == CacheMode.REPLICATED) + CacheGroupAffinity grp = registeredCacheGrps.get(grpId); + + assert grp != null : "Failed to find cache group [grpId=" + grpId + ", cache=" + cacheName + ']'; + + if (grp.cacheMode == CacheMode.REPLICATED) nearEnabled = false; - - registeredCaches.put(cacheName, new CachePredicate(filter, nearEnabled, cacheMode)); + + registeredCaches.put(cacheName, new CachePredicate(grp, nearEnabled)); } } @@ -401,7 +435,7 @@ public Map> clientNodesMap() { } } - return res; + return res == null ? Collections.>emptyMap() : res; } /** @@ -493,7 +527,7 @@ private void updateClientNodes(UUID leftNodeId) { /** {@inheritDoc} */ @Override public void onLocalNodeInitialized(ClusterNode locNode) { - for (IgniteInClosure lsnr : localNodeInitLsnrs) + for (IgniteInClosure lsnr : locNodeInitLsnrs) lsnr.apply(locNode); } @@ -639,6 +673,7 @@ else if (type == EVT_CLIENT_NODE_DISCONNECTED) { locJoin = new GridFutureAdapter<>(); registeredCaches.clear(); + registeredCacheGrps.clear(); for (AffinityTopologyVersion histVer : discoCacheHist.keySet()) { Object rmvd = discoCacheHist.remove(histVer); @@ -801,7 +836,7 @@ public void setCustomEventListener(Class m * @param lsnr Listener to add. */ public void addLocalNodeInitializedEventListener(IgniteInClosure lsnr) { - localNodeInitLsnrs.add(lsnr); + locNodeInitLsnrs.add(lsnr); } /** @@ -1741,28 +1776,15 @@ public Collection remoteCacheNodes(AffinityTopologyVersion topVer) return resolveDiscoCache(CU.cacheId(null), topVer).oldestAliveServerNodeWithCache(); } - /** - * Gets cache nodes for cache with given name that participate in affinity calculation. - * - * @param cacheName Cache name. - * @param topVer Topology version. - * @return Collection of cache affinity nodes. - */ - public Collection cacheAffinityNodes(@Nullable String cacheName, AffinityTopologyVersion topVer) { - int cacheId = CU.cacheId(cacheName); - - return resolveDiscoCache(cacheId, topVer).cacheAffinityNodes(cacheId); - } - /** * Gets cache nodes for cache with given ID that participate in affinity calculation. * - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param topVer Topology version. * @return Collection of cache affinity nodes. */ - public Collection cacheAffinityNodes(int cacheId, AffinityTopologyVersion topVer) { - return resolveDiscoCache(cacheId, topVer).cacheAffinityNodes(cacheId); + public Collection cacheGroupAffinityNodes(int grpId, AffinityTopologyVersion topVer) { + return resolveDiscoCache(grpId, topVer).cacheGroupAffinityNodes(grpId); } /** @@ -1778,6 +1800,19 @@ public boolean cacheAffinityNode(ClusterNode node, String cacheName) { return pred != null && pred.dataNode(node); } + /** + * Checks if node is a data node for the given cache group. + * + * @param node Node to check. + * @param grpId Cache group ID. + * @return {@code True} if node is a cache data node. + */ + public boolean cacheGroupAffinityNode(ClusterNode node, int grpId) { + CacheGroupAffinity aff = registeredCacheGrps.get(grpId); + + return CU.affinityNode(node, aff.cacheFilter); + } + /** * @param node Node to check. * @param cacheName Cache name. @@ -1825,7 +1860,7 @@ public Map nodeCaches(ClusterNode node) { if (!CU.isSystemCache(cacheName) && !CU.isIgfsCache(ctx.config(), cacheName) && pred != null && pred.cacheNode(node)) - caches.put(cacheName, pred.cacheMode); + caches.put(cacheName, pred.aff.cacheMode); } return caches; @@ -1845,21 +1880,21 @@ public boolean hasNearCache(int cacheId, AffinityTopologyVersion topVer) { /** * Gets discovery cache for given topology version. * - * @param cacheId Cache ID (participates in exception message). + * @param grpId Cache group ID (participates in exception message). * @param topVer Topology version. * @return Discovery cache. */ - private DiscoCache resolveDiscoCache(int cacheId, AffinityTopologyVersion topVer) { + private DiscoCache resolveDiscoCache(int grpId, AffinityTopologyVersion topVer) { Snapshot snap = topSnap.get(); DiscoCache cache = AffinityTopologyVersion.NONE.equals(topVer) || topVer.equals(snap.topVer) ? snap.discoCache : discoCacheHist.get(topVer); if (cache == null) { - DynamicCacheDescriptor desc = ctx.cache().cacheDescriptor(cacheId); + CacheGroupDescriptor desc = ctx.cache().cacheGroupDescriptors().get(grpId); throw new IgniteException("Failed to resolve nodes topology [" + - "cacheName=" + (desc != null ? desc.cacheConfiguration().getName() : "N/A") + + "cacheGrp=" + (desc != null ? desc.cacheOrGroupName() : "N/A") + ", topVer=" + topVer + ", history=" + discoCacheHist.keySet() + ", snap=" + snap + @@ -2073,7 +2108,7 @@ public void reconnect() { " [rmtNodes=" + rmtNodes + ", loc=" + loc + ']'; Map> allCacheNodes = U.newHashMap(allNodes.size()); - Map> affCacheNodes = U.newHashMap(allNodes.size()); + Map> cacheGrpAffNodes = U.newHashMap(allNodes.size()); Set allNodesWithCaches = new TreeSet<>(GridNodeOrderComparator.INSTANCE); Set rmtNodesWithCaches = new TreeSet<>(GridNodeOrderComparator.INSTANCE); @@ -2085,6 +2120,20 @@ public void reconnect() { assert node.order() != 0 : "Invalid node order [locNode=" + loc + ", node=" + node + ']'; assert !node.isDaemon(); + for (Map.Entry e : registeredCacheGrps.entrySet()) { + CacheGroupAffinity grpAff = e.getValue(); + Integer grpId = e.getKey(); + + if (CU.affinityNode(node, grpAff.cacheFilter)) { + List nodes = cacheGrpAffNodes.get(grpId); + + if (nodes == null) + cacheGrpAffNodes.put(grpId, nodes = new ArrayList<>()); + + nodes.add(node); + } + } + for (Map.Entry entry : registeredCaches.entrySet()) { String cacheName = entry.getKey(); CachePredicate filter = entry.getValue(); @@ -2100,9 +2149,6 @@ public void reconnect() { addToMap(allCacheNodes, cacheName, node); - if (filter.dataNode(node)) - addToMap(affCacheNodes, cacheName, node); - if (filter.nearNode(node)) nearEnabledCaches.add(CU.cacheId(cacheName)); } @@ -2119,7 +2165,7 @@ public void reconnect() { U.sealList(allNodesWithCaches), U.sealList(rmtNodesWithCaches), Collections.unmodifiableMap(allCacheNodes), - Collections.unmodifiableMap(affCacheNodes), + Collections.unmodifiableMap(cacheGrpAffNodes), Collections.unmodifiableMap(nodeMap), Collections.unmodifiableSet(nearEnabledCaches), alives); @@ -2731,33 +2777,61 @@ private Snapshot(AffinityTopologyVersion topVer, DiscoCache discoCache) { } } + /** + * + */ + private static class CacheGroupAffinity { + /** */ + private final String name; + + /** Nodes filter. */ + private final IgnitePredicate cacheFilter; + + /** Cache mode. */ + private final CacheMode cacheMode; + + /** + * @param name Name. + * @param cacheFilter Node filter. + * @param cacheMode Cache mode. + */ + CacheGroupAffinity( + String name, + IgnitePredicate cacheFilter, + CacheMode cacheMode) { + this.name = name; + this.cacheFilter = cacheFilter; + this.cacheMode = cacheMode; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "CacheGroupAffinity [name=" + name + ']'; + } + } + /** * Cache predicate. */ private static class CachePredicate { /** Cache filter. */ - private final IgnitePredicate cacheFilter; + private final CacheGroupAffinity aff; /** If near cache is enabled on data nodes. */ private final boolean nearEnabled; - /** Cache mode. */ - private final CacheMode cacheMode; - /** Collection of client near nodes. */ private final ConcurrentHashMap clientNodes; /** - * @param cacheFilter Cache filter. + * @param aff Cache group affinity. * @param nearEnabled Near enabled flag. - * @param cacheMode Cache mode. */ - private CachePredicate(IgnitePredicate cacheFilter, boolean nearEnabled, CacheMode cacheMode) { - assert cacheFilter != null; + private CachePredicate(CacheGroupAffinity aff, boolean nearEnabled) { + assert aff != null; - this.cacheFilter = cacheFilter; + this.aff = aff; this.nearEnabled = nearEnabled; - this.cacheMode = cacheMode; clientNodes = new ConcurrentHashMap<>(); } @@ -2792,7 +2866,7 @@ public boolean onNodeLeft(UUID leftNodeId) { * @return {@code True} if this node is a data node for given cache. */ public boolean dataNode(ClusterNode node) { - return CU.affinityNode(node, cacheFilter); + return CU.affinityNode(node, aff.cacheFilter); } /** @@ -2800,7 +2874,7 @@ public boolean dataNode(ClusterNode node) { * @return {@code True} if cache is accessible on the given node. */ public boolean cacheNode(ClusterNode node) { - return !node.isDaemon() && (CU.affinityNode(node, cacheFilter) || clientNodes.containsKey(node.id())); + return !node.isDaemon() && (CU.affinityNode(node, aff.cacheFilter) || clientNodes.containsKey(node.id())); } /** @@ -2808,7 +2882,7 @@ public boolean cacheNode(ClusterNode node) { * @return {@code True} if near cache is present on the given nodes. */ public boolean nearNode(ClusterNode node) { - if (CU.affinityNode(node, cacheFilter)) + if (CU.affinityNode(node, aff.cacheFilter)) return nearEnabled; Boolean near = clientNodes.get(node.id()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java index f82436823ecfd..3fa5954e88afd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java @@ -135,6 +135,22 @@ public static void putBytes(long addr, int off, byte[] bytes, int bytesOff) { GridUnsafe.copyMemory(bytes, GridUnsafe.BYTE_ARR_OFF + bytesOff, null, addr + off, bytes.length - bytesOff); } + /** + * @param addr Address. + * @param off Offset. + * @param bytes Bytes array. + * @param bytesOff Bytes array offset. + * @param len Length. + */ + public static void putBytes(long addr, int off, byte[] bytes, int bytesOff, int len) { + assert addr > 0 : addr; + assert off >= 0; + assert bytes != null; + assert bytesOff >= 0 && (bytesOff < bytes.length || bytes.length == 0) : bytesOff; + + GridUnsafe.copyMemory(bytes, GridUnsafe.BYTE_ARR_OFF + bytesOff, null, addr + off, len); + } + /** * @param addr Address. * @param off Offset. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index 39a76dd59d6bd..bdcc05a3e4726 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -37,7 +37,10 @@ public class SnapshotOperation implements Serializable { */ private final long snapshotId; - /** */ + /** Cache group ids. */ + private final Set cacheGrpIds; + + /** Cache names. */ private final Set cacheNames; /** Message. */ @@ -49,6 +52,7 @@ public class SnapshotOperation implements Serializable { /** * @param type Type. * @param snapshotId Snapshot id. + * @param cacheGrpIds Cache group ids. * @param cacheNames Cache names. * @param msg * @param extraParam Additional parameter. @@ -56,12 +60,14 @@ public class SnapshotOperation implements Serializable { public SnapshotOperation( SnapshotOperationType type, long snapshotId, + Set cacheGrpIds, Set cacheNames, String msg, Object extraParam ) { this.type = type; this.snapshotId = snapshotId; + this.cacheGrpIds = cacheGrpIds; this.cacheNames = cacheNames; this.msg = msg; this.extraParam = extraParam; @@ -84,10 +90,17 @@ public long id() { } /** - * Cache names included to this snapshot. + * Cache group ids included to this snapshot. * * @return Cache names. */ + public Set cacheGroupIds() { + return cacheGrpIds; + } + + /** + * Cache names included to this snapshot. + */ public Set cacheNames() { return cacheNames; } @@ -170,6 +183,7 @@ public static File getMovingPathParameter(SnapshotOperation op) { "type=" + type + ", snapshotId=" + snapshotId + ", cacheNames=" + cacheNames + + ", cacheGroupIds=" + cacheGrpIds + ", msg='" + msg + '\'' + ", extraParam=" + extraParam + '}'; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java index 0453ecbab8811..11a3804fe558a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java @@ -17,14 +17,14 @@ package org.apache.ignite.internal.pagemem.store; -import java.util.Set; +import java.nio.ByteBuffer; +import java.util.Map; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; +import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheSharedManager; - -import java.nio.ByteBuffer; import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport; /** @@ -44,39 +44,40 @@ public interface IgnitePageStoreManager extends GridCacheSharedManager, IgniteCh /** * Callback called when a cache is starting. * + * @param grpDesc Cache group descriptor. * @param ccfg Cache configuration of the cache being started. * @throws IgniteCheckedException If failed to handle cache start callback. */ - public void initializeForCache(CacheConfiguration ccfg) throws IgniteCheckedException; + public void initializeForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) throws IgniteCheckedException; /** * Callback called when a cache is stopping. After this callback is invoked, no data associated with * the given cache will be stored on disk. * - * @param cacheCtx Cache context of the cache being stopped. + * @param grp Cache group being stopped. * @param destroy Flag indicating if the cache is being destroyed and data should be cleaned. * @throws IgniteCheckedException If failed to handle cache destroy callback. */ - public void shutdownForCache(GridCacheContext cacheCtx, boolean destroy) throws IgniteCheckedException; + public void shutdownForCacheGroup(CacheGroupContext grp, boolean destroy) throws IgniteCheckedException; /** * Callback called when a partition is created on the local node. * - * @param cacheId Cache ID where the partition is being created. + * @param grpId Cache group ID where the partition is being created. * @param partId ID of the partition being created. * @throws IgniteCheckedException If failed to handle partition create callback. */ - public void onPartitionCreated(int cacheId, int partId) throws IgniteCheckedException; + public void onPartitionCreated(int grpId, int partId) throws IgniteCheckedException; /** * Callback called when a partition for the given cache is evicted from the local node. * After this callback is invoked, no data associated with the partition will be stored on disk. * - * @param cacheId Cache ID of the evicted partition. + * @param grpId Cache group ID of the evicted partition. * @param partId Partition ID. * @throws IgniteCheckedException If failed to handle partition destroy callback. */ - public void onPartitionDestroyed(int cacheId, int partId, int tag) throws IgniteCheckedException; + public void onPartitionDestroyed(int grpId, int partId, int tag) throws IgniteCheckedException; /** * Reads a page for the given cache ID. Cache ID may be {@code 0} if the page is a meta page. @@ -89,17 +90,17 @@ public interface IgnitePageStoreManager extends GridCacheSharedManager, IgniteCh public void read(int cacheId, long pageId, ByteBuffer pageBuf) throws IgniteCheckedException; /** - * Checks if page exists. + * Checks if partition store exists. * - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param partId Partition ID. - * @return {@code True} if page exists. + * @return {@code True} if partition store exists. * @throws IgniteCheckedException If failed. */ - public boolean exists(int cacheId, int partId) throws IgniteCheckedException; + public boolean exists(int grpId, int partId) throws IgniteCheckedException; /** - * Reads a header of apage store. + * Reads a header of a page store. * * @param cacheId Cache ID. * @param partId Partition ID. @@ -174,19 +175,14 @@ public interface IgnitePageStoreManager extends GridCacheSharedManager, IgniteCh public long metaPageId(int cacheId); /** - * @return set of cache names which configurations were saved - */ - public Set savedCacheNames(); - - /** - * @param cacheName Cache name. - * @return saved configuration for cache + * @return Saved cache configurations. + * @throws IgniteCheckedException If failed. */ - public CacheConfiguration readConfiguration(String cacheName); + public Map readCacheConfigurations() throws IgniteCheckedException; /** - * @param cacheId Cache ID. - * @return {@code True} if index store for given cache existed before node started. + * @param grpId Cache group ID. + * @return {@code True} if index store for given cache group existed before node started. */ - public boolean hasIndexStore(int cacheId); + public boolean hasIndexStore(int grpId); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CheckpointRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CheckpointRecord.java index 7aaf1c565e885..cfcd62a13e39a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CheckpointRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CheckpointRecord.java @@ -35,7 +35,7 @@ public class CheckpointRecord extends WALRecord { private boolean end; /** */ - private Map cacheStates; + private Map cacheGrpStates; /** Safe replay pointer. */ private WALPointer cpMark; @@ -65,28 +65,28 @@ public CheckpointRecord(UUID cpId, WALPointer cpMark, boolean end) { } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param state Cache state. */ - public void addCacheState(int cacheId, CacheState state) { - if (cacheStates == null) - cacheStates = new HashMap<>(); + public void addCacheGroupState(int grpId, CacheState state) { + if (cacheGrpStates == null) + cacheGrpStates = new HashMap<>(); - cacheStates.put(cacheId, state); + cacheGrpStates.put(grpId, state); } /** - * @param cacheStates Cache states. + * @param cacheGrpStates Cache states. */ - public void cacheStates(Map cacheStates) { - this.cacheStates = cacheStates; + public void cacheGroupStates(Map cacheGrpStates) { + this.cacheGrpStates = cacheGrpStates; } /** * @return Cache states. */ - public Map cacheStates() { - return cacheStates != null ? cacheStates : Collections.emptyMap(); + public Map cacheGroupStates() { + return cacheGrpStates != null ? cacheGrpStates : Collections.emptyMap(); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java index ef57c46f56a99..b28dd528350e1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java @@ -41,6 +41,9 @@ public class MetaPageUpdatePartitionDataRecord extends PageDeltaRecord { /** */ private int allocatedIdxCandidate; + /** */ + private long cntrsPageId; + /** * @param cacheId Cache ID. * @param pageId Page ID. @@ -52,7 +55,7 @@ public MetaPageUpdatePartitionDataRecord( long updateCntr, long globalRmvId, int partSize, - byte state, + long cntrsPageId, byte state, int allocatedIdxCandidate ) { super(cacheId, pageId); @@ -62,6 +65,7 @@ public MetaPageUpdatePartitionDataRecord( this.partSize = partSize; this.state = state; this.allocatedIdxCandidate = allocatedIdxCandidate; + this.cntrsPageId = cntrsPageId; } /** @@ -85,6 +89,13 @@ public int partitionSize() { return partSize; } + /** + * @return Partition size. + */ + public long countersPageId() { + return cntrsPageId; + } + /** * @return Partition state */ @@ -99,6 +110,7 @@ public byte state() { io.setUpdateCounter(pageAddr, updateCntr); io.setGlobalRemoveId(pageAddr, globalRmvId); io.setSize(pageAddr, partSize); + io.setCountersPageId(pageAddr, cntrsPageId); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java index 4830f0650ecbd..b4784620b8e99 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java @@ -60,11 +60,11 @@ public class GridAffinityAssignmentCache { /** Cleanup history size. */ private final int MAX_HIST_SIZE = getInteger(IGNITE_AFFINITY_HISTORY_SIZE, 500); - /** Cache name. */ - private final String cacheName; + /** Group name if specified or cache name. */ + private final String cacheOrGrpName; - /** */ - private final int cacheId; + /** Group ID. */ + private final int grpId; /** Number of backups. */ private final int backups; @@ -115,7 +115,8 @@ public class GridAffinityAssignmentCache { * Constructs affinity cached calculations. * * @param ctx Kernal context. - * @param cacheName Cache name. + * @param cacheOrGrpName Cache or cache group name. + * @param grpId Group ID. * @param aff Affinity function. * @param nodeFilter Node filter. * @param backups Number of backups. @@ -123,7 +124,8 @@ public class GridAffinityAssignmentCache { */ @SuppressWarnings("unchecked") public GridAffinityAssignmentCache(GridKernalContext ctx, - String cacheName, + String cacheOrGrpName, + int grpId, AffinityFunction aff, IgnitePredicate nodeFilter, int backups, @@ -132,16 +134,16 @@ public GridAffinityAssignmentCache(GridKernalContext ctx, assert ctx != null; assert aff != null; assert nodeFilter != null; + assert grpId != 0; this.ctx = ctx; this.aff = aff; this.nodeFilter = nodeFilter; - this.cacheName = cacheName; + this.cacheOrGrpName = cacheOrGrpName; + this.grpId = grpId; this.backups = backups; this.locCache = locCache; - cacheId = CU.cacheId(cacheName); - log = ctx.log(GridAffinityAssignmentCache.class); partsCnt = aff.partitions(); @@ -161,17 +163,17 @@ public Object similarAffinityKey() { } /** - * @return Cache name. + * @return Group name if it is specified, otherwise cache name. */ - public String cacheName() { - return cacheName; + public String cacheOrGroupName() { + return cacheOrGrpName; } /** - * @return Cache ID. + * @return Cache group ID. */ - public int cacheId() { - return cacheId; + public int groupId() { + return grpId; } /** @@ -269,7 +271,7 @@ public List> calculate(AffinityTopologyVersion topVer, Discove List sorted; if (!locCache) { - sorted = new ArrayList<>(discoCache.cacheAffinityNodes(cacheId())); + sorted = new ArrayList<>(discoCache.cacheGroupAffinityNodes(groupId())); Collections.sort(sorted, GridNodeOrderComparator.INSTANCE); } @@ -432,7 +434,7 @@ public Set backupPartitions(UUID nodeId, AffinityTopologyVersion topVer */ public void dumpDebugInfo() { if (!readyFuts.isEmpty()) { - U.warn(log, "Pending affinity ready futures [cache=" + cacheName + ", lastVer=" + lastVersion() + "]:"); + U.warn(log, "Pending affinity ready futures [grp=" + cacheOrGrpName + ", lastVer=" + lastVersion() + "]:"); for (AffinityReadyFuture fut : readyFuts.values()) U.warn(log, ">>> " + fut); @@ -461,7 +463,7 @@ public AffinityAssignment cachedAffinity(AffinityTopologyVersion topVer) { if (cache == null) { throw new IllegalStateException("Getting affinity for topology version earlier than affinity is " + "calculated [locNode=" + ctx.discovery().localNode() + - ", cache=" + cacheName + + ", grp=" + cacheOrGrpName + ", topVer=" + topVer + ", head=" + head.get().topologyVersion() + ", history=" + affCache.keySet() + 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 962f137bbf4ea..44bb04f4eb6d9 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 @@ -72,7 +72,7 @@ public class CacheAffinitySharedManager extends GridCacheSharedManagerAdap private boolean lateAffAssign; /** Affinity information for all started caches (initialized on coordinator). */ - private ConcurrentMap caches = new ConcurrentHashMap<>(); + private ConcurrentMap grpHolders = new ConcurrentHashMap<>(); /** Last topology version when affinity was calculated (updated from exchange thread). */ private AffinityTopologyVersion affCalcVer; @@ -81,7 +81,7 @@ public class CacheAffinitySharedManager extends GridCacheSharedManagerAdap private AffinityTopologyVersion lastAffVer; /** Registered caches (updated from exchange thread). */ - private final Map registeredCaches = new HashMap<>(); + private final Map registeredGrps = new HashMap<>(); /** */ private WaitRebalanceInfo waitInfo; @@ -131,14 +131,14 @@ public class CacheAffinitySharedManager extends GridCacheSharedManagerAdap void onDiscoveryEvent(int type, ClusterNode node, AffinityTopologyVersion topVer) { if (type == EVT_NODE_JOINED && node.isLocal()) { // Clean-up in case of client reconnect. - registeredCaches.clear(); + registeredGrps.clear(); affCalcVer = null; lastAffVer = null; - for (DynamicCacheDescriptor desc : cctx.cache().cacheDescriptors()) - registeredCaches.put(desc.cacheId(), desc); + for (CacheGroupDescriptor desc : cctx.cache().cacheGroupDescriptors().values()) + registeredGrps.put(desc.groupId(), desc); } if (!CU.clientNode(node) && (type == EVT_NODE_FAILED || type == EVT_NODE_JOINED || type == EVT_NODE_LEFT)) { @@ -159,7 +159,7 @@ boolean onCustomEvent(CacheAffinityChangeMessage msg) { if (msg.exchangeId() != null) { if (log.isDebugEnabled()) { - log.debug("Need process affinity change message [lastAffVer=" + lastAffVer + + log.debug("Ignore affinity change message [lastAffVer=" + lastAffVer + ", msgExchId=" + msg.exchangeId() + ", msgVer=" + msg.topologyVersion() + ']'); } @@ -193,14 +193,14 @@ boolean onCustomEvent(CacheAffinityChangeMessage msg) { /** * @param topVer Expected topology version. */ - private void onCacheStopped(AffinityTopologyVersion topVer) { + private void onCacheGroupStopped(AffinityTopologyVersion topVer) { CacheAffinityChangeMessage msg = null; synchronized (mux) { if (waitInfo == null || !waitInfo.topVer.equals(topVer)) return; - if (waitInfo.waitCaches.isEmpty()) { + if (waitInfo.waitGrps.isEmpty()) { msg = affinityChangeMessage(waitInfo); waitInfo = null; @@ -218,9 +218,9 @@ private void onCacheStopped(AffinityTopologyVersion topVer) { /** * @param top Topology. - * @param checkCacheId Cache ID. + * @param checkGrpId Group ID. */ - void checkRebalanceState(GridDhtPartitionTopology top, Integer checkCacheId) { + void checkRebalanceState(GridDhtPartitionTopology top, Integer checkGrpId) { if (!lateAffAssign) return; @@ -234,14 +234,14 @@ void checkRebalanceState(GridDhtPartitionTopology top, Integer checkCacheId) { assert affCalcVer.equals(waitInfo.topVer) : "Invalid affinity version [calcVer=" + affCalcVer + ", waitVer=" + waitInfo.topVer + ']'; - Map partWait = waitInfo.waitCaches.get(checkCacheId); + Map partWait = waitInfo.waitGrps.get(checkGrpId); boolean rebalanced = true; if (partWait != null) { - CacheHolder cache = caches.get(checkCacheId); + CacheGroupHolder grpHolder = grpHolders.get(checkGrpId); - if (cache != null) { + if (grpHolder != null) { for (Iterator> it = partWait.entrySet().iterator(); it.hasNext(); ) { Map.Entry e = it.next(); @@ -261,9 +261,9 @@ void checkRebalanceState(GridDhtPartitionTopology top, Integer checkCacheId) { } if (rebalanced) { - waitInfo.waitCaches.remove(checkCacheId); + waitInfo.waitGrps.remove(checkGrpId); - if (waitInfo.waitCaches.isEmpty()) { + if (waitInfo.waitGrps.isEmpty()) { msg = affinityChangeMessage(waitInfo); waitInfo = null; @@ -292,7 +292,7 @@ void checkRebalanceState(GridDhtPartitionTopology top, Integer checkCacheId) { Map>> assignmentsChange = U.newHashMap(waitInfo.assignments.size()); for (Map.Entry>> e : waitInfo.assignments.entrySet()) { - Integer cacheId = e.getKey(); + Integer grpId = e.getKey(); Map> assignment = e.getValue(); @@ -301,23 +301,23 @@ void checkRebalanceState(GridDhtPartitionTopology top, Integer checkCacheId) { for (Map.Entry> e0 : assignment.entrySet()) assignment0.put(e0.getKey(), toIds0(e0.getValue())); - assignmentsChange.put(cacheId, assignment0); + assignmentsChange.put(grpId, assignment0); } return new CacheAffinityChangeMessage(waitInfo.topVer, assignmentsChange, waitInfo.deploymentIds); } /** - * @param cctx Cache context. + * @param grp Cache group. */ - public void onCacheCreated(GridCacheContext cctx) { - final Integer cacheId = cctx.cacheId(); + void onCacheGroupCreated(CacheGroupContext grp) { + final Integer grpId = grp.groupId(); - if (!caches.containsKey(cctx.cacheId())) { - cctx.io().addHandler(cacheId, GridDhtAffinityAssignmentResponse.class, + if (!grpHolders.containsKey(grp.groupId())) { + cctx.io().addCacheGroupHandler(grpId, GridDhtAffinityAssignmentResponse.class, new IgniteBiInClosure() { @Override public void apply(UUID nodeId, GridDhtAffinityAssignmentResponse res) { - processAffinityAssignmentResponse(nodeId, res); + processAffinityAssignmentResponse(grpId, nodeId, res); } }); } @@ -327,28 +327,14 @@ public void onCacheCreated(GridCacheContext cctx) { * @param exchActions Cache change requests to execute on exchange. */ private void updateCachesInfo(ExchangeActions exchActions) { - for (ExchangeActions.ActionData action : exchActions.cacheStopRequests()) { - DynamicCacheDescriptor desc = registeredCaches.remove(action.descriptor().cacheId()); + for (CacheGroupDescriptor stopDesc : exchActions.cacheGroupsToStop()) { + CacheGroupDescriptor rmvd = registeredGrps.remove(stopDesc.groupId()); - assert desc != null : action.request().cacheName(); + assert rmvd != null : stopDesc.cacheOrGroupName(); } - for (ExchangeActions.ActionData action : exchActions.cacheStartRequests()) { - DynamicCacheChangeRequest req = action.request(); - - Integer cacheId = action.descriptor().cacheId(); - - DynamicCacheDescriptor desc = new DynamicCacheDescriptor(cctx.kernalContext(), - req.startCacheConfiguration(), - req.cacheType(), - false, - action.descriptor().receivedFrom(), - action.descriptor().staticallyConfigured(), - action.descriptor().sql(), - req.deploymentId(), - req.schema()); - - DynamicCacheDescriptor old = registeredCaches.put(cacheId, desc); + for (CacheGroupDescriptor startDesc : exchActions.cacheGroupsToStart()) { + CacheGroupDescriptor old = registeredGrps.put(startDesc.groupId(), startDesc); assert old == null : old; } @@ -365,7 +351,7 @@ private void updateCachesInfo(ExchangeActions exchActions) { */ public boolean onCacheChangeRequest(final GridDhtPartitionsExchangeFuture fut, boolean crd, - ExchangeActions exchActions) + final ExchangeActions exchActions) throws IgniteCheckedException { assert exchActions != null && !exchActions.empty() : exchActions; @@ -373,9 +359,9 @@ public boolean onCacheChangeRequest(final GridDhtPartitionsExchangeFuture fut, updateCachesInfo(exchActions); // Affinity did not change for existing caches. - forAllCaches(crd && lateAffAssign, new IgniteInClosureX() { + forAllCacheGroups(crd && lateAffAssign, new IgniteInClosureX() { @Override public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException { - if (fut.stopping(aff.cacheId())) + if (exchActions.cacheGroupStopping(aff.groupId())) return; aff.clientEventTopologyChange(fut.discoveryEvent(), fut.topologyVersion()); @@ -397,8 +383,8 @@ public boolean onCacheChangeRequest(final GridDhtPartitionsExchangeFuture fut, nearCfg = req.nearCacheConfiguration(); } else { - startCache = cctx.cacheContext(action.descriptor().cacheId()) == null && - CU.affinityNode(cctx.localNode(), req.startCacheConfiguration().getNodeFilter()); + startCache = cctx.cacheContext(cacheDesc.cacheId()) == null && + CU.affinityNode(cctx.localNode(), cacheDesc.groupDescriptor().config().getNodeFilter()); } try { @@ -406,102 +392,122 @@ public boolean onCacheChangeRequest(final GridDhtPartitionsExchangeFuture fut, cctx.cache().prepareCacheStart(cacheDesc, nearCfg, fut.topologyVersion()); if (fut.cacheAddedOnExchange(cacheDesc.cacheId(), cacheDesc.receivedFrom())) { - if (fut.discoCache().cacheAffinityNodes(req.cacheName()).isEmpty()) + if (fut.discoCache().cacheGroupAffinityNodes(cacheDesc.groupId()).isEmpty()) U.quietAndWarn(log, "No server nodes found for cache client: " + req.cacheName()); } } + } + catch (IgniteCheckedException e) { + U.error(log, "Failed to initialize cache. Will try to rollback cache start routine. " + + "[cacheName=" + req.cacheName() + ']', e); - if (!crd || !lateAffAssign) { - GridCacheContext cacheCtx = cctx.cacheContext(cacheDesc.cacheId()); - - if (cacheCtx != null && !cacheCtx.isLocal()) { - boolean clientCacheStarted = - req.clientStartOnly() && req.initiatingNodeId().equals(cctx.localNodeId()); + cctx.cache().forceCloseCache(fut.topologyVersion(), action, e); + } + } - if (clientCacheStarted) - initAffinity(cacheDesc, cacheCtx.affinity().affinityCache(), fut, lateAffAssign); - else if (!req.clientStartOnly()) { - assert fut.topologyVersion().equals(cacheCtx.startTopologyVersion()); + Set gprs = new HashSet<>(); - GridAffinityAssignmentCache aff = cacheCtx.affinity().affinityCache(); + for (ExchangeActions.ActionData action : exchActions.newAndClientCachesStartRequests()) { + Integer grpId = action.descriptor().groupId(); - assert aff.lastVersion().equals(AffinityTopologyVersion.NONE) : aff.lastVersion(); + if (gprs.add(grpId)) { + if (crd && lateAffAssign) + initStartedGroupOnCoordinator(fut, action.descriptor().groupDescriptor());else { + CacheGroupContext grp = cctx.cache().cacheGroup(grpId); - List> assignment = aff.calculate(fut.topologyVersion(), - fut.discoveryEvent(), fut.discoCache()); + if (grp != null && !grp.isLocal() && grp.localStartVersion().equals(fut.topologyVersion())) { + assert grp.affinity().lastVersion().equals(AffinityTopologyVersion.NONE) : grp.affinity().lastVersion(); - aff.initialize(fut.topologyVersion(), assignment); - } + initAffinity(registeredGrps.get(grp.groupId()), grp.affinity(), fut); } } - else - initStartedCacheOnCoordinator(fut, cacheDesc.cacheId()); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to initialize cache. Will try to rollback cache start routine. " + - "[cacheName=" + req.cacheName() + ']', e); - - cctx.cache().forceCloseCache(fut.topologyVersion(), action, e); } } - for (DynamicCacheChangeRequest req : exchActions.closeRequests(cctx.localNodeId())) { - Integer cacheId = CU.cacheId(req.cacheName()); + List closeReqs = exchActions.closeRequests(cctx.localNodeId()); - cctx.cache().blockGateway(req); + for (ExchangeActions.ActionData req : closeReqs) { + cctx.cache().blockGateway(req.request()); if (crd) { - GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + CacheGroupContext grp = cctx.cache().cacheGroup(req.descriptor().groupId()); + + assert grp != null; + + if (grp.affinityNode()) + continue; - // Client cache was stopped, need create 'client' CacheHolder. - if (cacheCtx != null && !cacheCtx.affinityNode()) { - CacheHolder cache = caches.remove(cacheId); + boolean grpClosed = false; - assert !cache.client() : cache; + if (grp.sharedGroup()) { + boolean cacheRemaining = false; - cache = CacheHolder2.create(cctx, - cctx.cache().cacheDescriptor(cacheId), - fut, - cache.affinity()); + for (GridCacheContext ctx : cctx.cacheContexts()) { + if (ctx.group() == grp && !cacheClosed(ctx.cacheId(), closeReqs)) { + cacheRemaining = true; - caches.put(cacheId, cache); + break; + } + } + + if (!cacheRemaining) + grpClosed = true; } - } - } + else + grpClosed = true; - Set stoppedCaches = null; + // All client cache groups were stopped, need create 'client' CacheGroupHolder. + if (grpClosed) { + CacheGroupHolder grpHolder = grpHolders.remove(grp.groupId()); - for (ExchangeActions.ActionData action : exchActions.cacheStopRequests()) { - DynamicCacheDescriptor desc = action.descriptor(); + if (grpHolder != null) { + assert !grpHolder.client() : grpHolder; + grpHolder = CacheGroupHolder2.create(cctx, + registeredGrps.get(grp.groupId()), + fut, + grp.affinity()); + + grpHolders.put(grp.groupId(), grpHolder); + } + } + } + } + + for (ExchangeActions.ActionData action : exchActions.cacheStopRequests()) cctx.cache().blockGateway(action.request()); - if (crd && lateAffAssign && desc.cacheConfiguration().getCacheMode() != LOCAL) { - CacheHolder cache = caches.remove(desc.cacheId()); + Set stoppedGrps = null; + + if (crd && lateAffAssign) { + for (CacheGroupDescriptor grpDesc : exchActions.cacheGroupsToStop()) { + if (grpDesc.config().getCacheMode() != LOCAL) { + CacheGroupHolder cacheGrp = grpHolders.remove(grpDesc.groupId()); - assert cache != null : action.request(); + assert cacheGrp != null : grpDesc; - if (stoppedCaches == null) - stoppedCaches = new HashSet<>(); + if (stoppedGrps == null) + stoppedGrps = new HashSet<>(); - stoppedCaches.add(cache.cacheId()); + stoppedGrps.add(cacheGrp.groupId()); - cctx.io().removeHandler(desc.cacheId(), GridDhtAffinityAssignmentResponse.class); + cctx.io().removeHandler(true, cacheGrp.groupId(), GridDhtAffinityAssignmentResponse.class); + } } } - if (stoppedCaches != null) { + if (stoppedGrps != null) { boolean notify = false; synchronized (mux) { if (waitInfo != null) { - for (Integer cacheId : stoppedCaches) { - boolean rmv = waitInfo.waitCaches.remove(cacheId) != null; + for (Integer grpId : stoppedGrps) { + boolean rmv = waitInfo.waitGrps.remove(grpId) != null; if (rmv) { notify = true; - waitInfo.assignments.remove(cacheId); + waitInfo.assignments.remove(grpId); } } } @@ -512,7 +518,7 @@ else if (!req.clientStartOnly()) { cctx.kernalContext().closure().runLocalSafe(new Runnable() { @Override public void run() { - onCacheStopped(topVer); + onCacheGroupStopped(topVer); } }); } @@ -521,13 +527,27 @@ else if (!req.clientStartOnly()) { return exchActions.clientOnlyExchange(); } + /** + * @param cacheId Cache ID. + * @param closeReqs Close requests. + * @return {@code True} if requests contain request for given cache ID. + */ + private boolean cacheClosed(int cacheId, List closeReqs) { + for (ExchangeActions.ActionData req : closeReqs) { + if (req.descriptor().cacheId() == cacheId) + return true; + } + + return false; + } + /** * */ public void removeAllCacheInfo() { - caches.clear(); + grpHolders.clear(); - registeredCaches.clear(); + registeredGrps.clear(); } /** @@ -555,13 +575,13 @@ public void onExchangeChangeAffinityMessage(GridDhtPartitionsExchangeFuture exch final Map>> affCache = new HashMap<>(); - forAllCaches(crd, new IgniteInClosureX() { + forAllCacheGroups(crd, new IgniteInClosureX() { @Override public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException { List> idealAssignment = aff.idealAssignment(); assert idealAssignment != null; - Map> cacheAssignment = assignment.get(aff.cacheId()); + Map> cacheAssignment = assignment.get(aff.groupId()); List> newAssignment; @@ -611,25 +631,25 @@ public void onChangeAffinityMessage(final GridDhtPartitionsExchangeFuture exchFu final Map>> affCache = new HashMap<>(); - forAllCaches(crd, new IgniteInClosureX() { + forAllCacheGroups(crd, new IgniteInClosureX() { @Override public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException { AffinityTopologyVersion affTopVer = aff.lastVersion(); assert affTopVer.topologyVersion() > 0 : affTopVer; - DynamicCacheDescriptor desc = registeredCaches.get(aff.cacheId()); + CacheGroupDescriptor desc = registeredGrps.get(aff.groupId()); - assert desc != null : aff.cacheName(); + assert desc != null : aff.cacheOrGroupName(); IgniteUuid deploymentId = desc.deploymentId(); - if (!deploymentId.equals(deploymentIds.get(aff.cacheId()))) { + if (!deploymentId.equals(deploymentIds.get(aff.groupId()))) { aff.clientEventTopologyChange(exchFut.discoveryEvent(), topVer); return; } - Map> change = affChange.get(aff.cacheId()); + Map> change = affChange.get(aff.groupId()); if (change != null) { assert !change.isEmpty() : msg; @@ -644,7 +664,7 @@ public void onChangeAffinityMessage(final GridDhtPartitionsExchangeFuture exchFu List nodes = toNodes(topVer, e.getValue()); assert !nodes.equals(assignment.get(part)) : "Assignment did not change " + - "[cache=" + aff.cacheName() + + "[cacheGrp=" + aff.cacheOrGroupName() + ", part=" + part + ", cur=" + F.nodeIds(assignment.get(part)) + ", new=" + F.nodeIds(nodes) + @@ -680,7 +700,7 @@ public void onClientEvent(final GridDhtPartitionsExchangeFuture fut, boolean crd if (lateAffAssign) { if (!locJoin) { - forAllCaches(crd, new IgniteInClosureX() { + forAllCacheGroups(crd, new IgniteInClosureX() { @Override public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException { AffinityTopologyVersion topVer = fut.topologyVersion(); @@ -693,7 +713,7 @@ public void onClientEvent(final GridDhtPartitionsExchangeFuture fut, boolean crd } else { if (!locJoin) { - forAllCaches(false, new IgniteInClosureX() { + forAllCacheGroups(false, new IgniteInClosureX() { @Override public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException { AffinityTopologyVersion topVer = fut.topologyVersion(); @@ -726,11 +746,11 @@ public void removeDhtAssignmentFetchFuture(GridDhtAssignmentFetchFuture fut) { } /** + * @param grpId Cache group ID. * @param nodeId Node ID. * @param res Response. */ - private void processAffinityAssignmentResponse(UUID nodeId, - GridDhtAffinityAssignmentResponse res) { + private void processAffinityAssignmentResponse(Integer grpId, UUID nodeId, GridDhtAffinityAssignmentResponse res) { if (log.isDebugEnabled()) log.debug("Processing affinity assignment response [node=" + nodeId + ", res=" + res + ']'); @@ -744,11 +764,11 @@ private void processAffinityAssignmentResponse(UUID nodeId, * @param c Cache closure. * @throws IgniteCheckedException If failed */ - private void forAllRegisteredCaches(IgniteInClosureX c) throws IgniteCheckedException { + private void forAllRegisteredCacheGroups(IgniteInClosureX c) throws IgniteCheckedException { assert lateAffAssign; - for (DynamicCacheDescriptor cacheDesc : registeredCaches.values()) { - if (cacheDesc.cacheConfiguration().getCacheMode() == LOCAL) + for (CacheGroupDescriptor cacheDesc : registeredGrps.values()) { + if (cacheDesc.config().getCacheMode() == LOCAL) continue; c.applyx(cacheDesc); @@ -759,56 +779,60 @@ private void forAllRegisteredCaches(IgniteInClosureX c) * @param crd Coordinator flag. * @param c Closure. */ - private void forAllCaches(boolean crd, IgniteInClosureX c) { + private void forAllCacheGroups(boolean crd, IgniteInClosureX c) { if (crd) { - for (CacheHolder cache : caches.values()) - c.apply(cache.affinity()); + for (CacheGroupHolder grp : grpHolders.values()) + c.apply(grp.affinity()); } else { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.kernalContext().cache().cacheGroups()) { + if (grp.isLocal()) continue; - c.apply(cacheCtx.affinity().affinityCache()); + c.apply(grp.affinity()); } } } /** * @param fut Exchange future. - * @param cacheId Cache ID. + * @param grpDesc Cache group descriptor. * @throws IgniteCheckedException If failed. */ - private void initStartedCacheOnCoordinator(GridDhtPartitionsExchangeFuture fut, final Integer cacheId) + private void initStartedGroupOnCoordinator(GridDhtPartitionsExchangeFuture fut, final CacheGroupDescriptor grpDesc) throws IgniteCheckedException { - CacheHolder cache = caches.get(cacheId); + assert grpDesc != null && grpDesc.groupId() != 0 : grpDesc; - GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + if (grpDesc.config().getCacheMode() == LOCAL) + return; - if (cache == null) { - DynamicCacheDescriptor desc = cctx.cache().cacheDescriptor(cacheId); + Integer grpId = grpDesc.groupId(); - assert desc != null : cacheId; + CacheGroupHolder grpHolder = grpHolders.get(grpId); - if (desc.cacheConfiguration().getCacheMode() == LOCAL) - return; + CacheGroupContext grp = cctx.kernalContext().cache().cacheGroup(grpId); - cache = cacheCtx != null ? new CacheHolder1(cacheCtx, null) : CacheHolder2.create(cctx, desc, fut, null); + if (grpHolder == null) { + grpHolder = grp != null ? + new CacheGroupHolder1(grp, null) : + CacheGroupHolder2.create(cctx, grpDesc, fut, null); - CacheHolder old = caches.put(cacheId, cache); + CacheGroupHolder old = grpHolders.put(grpId, grpHolder); assert old == null : old; - List> newAff = cache.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); + List> newAff = grpHolder.affinity().calculate(fut.topologyVersion(), + fut.discoveryEvent(), + fut.discoCache()); - cache.affinity().initialize(fut.topologyVersion(), newAff); + grpHolder.affinity().initialize(fut.topologyVersion(), newAff); } - else if (cache.client() && cacheCtx != null) { - assert cache.affinity().idealAssignment() != null; + else if (grpHolder.client() && grp != null) { + assert grpHolder.affinity().idealAssignment() != null; - cache = new CacheHolder1(cacheCtx, cache.affinity()); + grpHolder = new CacheGroupHolder1(grp, grpHolder.affinity()); - caches.put(cacheId, cache); + grpHolders.put(grpId, grpHolder); } } @@ -824,14 +848,16 @@ public void initStartedCaches(boolean crd, final GridDhtPartitionsExchangeFuture fut, Collection descs) throws IgniteCheckedException { for (DynamicCacheDescriptor desc : descs) { - if (!registeredCaches.containsKey(desc.cacheId())) - registeredCaches.put(desc.cacheId(), desc); + CacheGroupDescriptor grpDesc = desc.groupDescriptor(); + + if (!registeredGrps.containsKey(grpDesc.groupId())) + registeredGrps.put(grpDesc.groupId(), grpDesc); } if (crd && lateAffAssign) { - forAllRegisteredCaches(new IgniteInClosureX() { - @Override public void applyx(DynamicCacheDescriptor desc) throws IgniteCheckedException { - CacheHolder cache = cache(fut, desc); + forAllRegisteredCacheGroups(new IgniteInClosureX() { + @Override public void applyx(CacheGroupDescriptor desc) throws IgniteCheckedException { + CacheGroupHolder cache = groupHolder(fut, desc); if (cache.affinity().lastVersion().equals(AffinityTopologyVersion.NONE)) { List> assignment = @@ -843,30 +869,28 @@ public void initStartedCaches(boolean crd, }); } else { - forAllCaches(false, new IgniteInClosureX() { + forAllCacheGroups(false, new IgniteInClosureX() { @Override public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException { if (aff.lastVersion().equals(AffinityTopologyVersion.NONE)) - initAffinity(registeredCaches.get(aff.cacheId()), aff, fut, false); + initAffinity(registeredGrps.get(aff.groupId()), aff, fut); } }); } } /** - * @param desc Cache descriptor. + * @param desc Cache group descriptor. * @param aff Affinity. * @param fut Exchange future. - * @param fetch Force fetch flag. * @throws IgniteCheckedException If failed. */ - private void initAffinity(DynamicCacheDescriptor desc, + private void initAffinity(CacheGroupDescriptor desc, GridAffinityAssignmentCache aff, - GridDhtPartitionsExchangeFuture fut, - boolean fetch) + GridDhtPartitionsExchangeFuture fut) throws IgniteCheckedException { - assert desc != null; + assert desc != null : aff.cacheOrGroupName(); - if (!fetch && canCalculateAffinity(desc, aff, fut)) { + if (canCalculateAffinity(desc, aff, fut)) { List> assignment = aff.calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); aff.initialize(fut.topologyVersion(), assignment); @@ -884,26 +908,26 @@ private void initAffinity(DynamicCacheDescriptor desc, } /** - * @param desc Cache descriptor. + * @param desc Cache group descriptor. * @param aff Affinity. * @param fut Exchange future. * @return {@code True} if local node can calculate affinity on it's own for this partition map exchange. */ - private boolean canCalculateAffinity(DynamicCacheDescriptor desc, + private boolean canCalculateAffinity(CacheGroupDescriptor desc, GridAffinityAssignmentCache aff, GridDhtPartitionsExchangeFuture fut) { - assert desc != null : aff.cacheName(); + assert desc != null : aff.cacheOrGroupName(); // Do not request affinity from remote nodes if affinity function is not centralized. - if (!aff.centralizedAffinityFunction()) + if (!lateAffAssign && !aff.centralizedAffinityFunction()) return true; // If local node did not initiate exchange or local node is the only cache node in grid. - Collection affNodes = cctx.discovery().cacheAffinityNodes(aff.cacheId(), fut.topologyVersion()); + Collection affNodes = fut.discoCache().cacheGroupAffinityNodes(aff.groupId()); - return fut.cacheAddedOnExchange(aff.cacheId(), desc.receivedFrom()) || + return fut.cacheGroupAddedOnExchange(aff.groupId(), desc.receivedFrom()) || !fut.exchangeId().nodeId().equals(cctx.localNodeId()) || - (affNodes.size() == 1 && affNodes.contains(cctx.localNode())); + (affNodes.isEmpty() || (affNodes.size() == 1 && affNodes.contains(cctx.localNode()))); } /** @@ -923,13 +947,15 @@ public void onServerJoin(final GridDhtPartitionsExchangeFuture fut, boolean crd) if (lateAffAssign) { if (locJoin) { if (crd) { - forAllRegisteredCaches(new IgniteInClosureX() { - @Override public void applyx(DynamicCacheDescriptor cacheDesc) throws IgniteCheckedException { + forAllRegisteredCacheGroups(new IgniteInClosureX() { + @Override public void applyx(CacheGroupDescriptor desc) throws IgniteCheckedException { AffinityTopologyVersion topVer = fut.topologyVersion(); - CacheHolder cache = cache(fut, cacheDesc); + CacheGroupHolder cache = groupHolder(fut, desc); - List> newAff = cache.affinity().calculate(topVer, fut.discoveryEvent(), fut.discoCache()); + List> newAff = cache.affinity().calculate(topVer, + fut.discoveryEvent(), + fut.discoCache()); cache.affinity().initialize(topVer, newAff); } @@ -954,21 +980,21 @@ public void onServerJoin(final GridDhtPartitionsExchangeFuture fut, boolean crd) if (crd && lateAffAssign) { if (log.isDebugEnabled()) { log.debug("Computed new affinity after node join [topVer=" + fut.topologyVersion() + - ", waitCaches=" + (info != null ? cacheNames(info.waitCaches.keySet()) : null) + ']'); + ", waitGrps=" + (info != null ? groupNames(info.waitGrps.keySet()) : null) + ']'); } } } } /** - * @param cacheIds Cache IDs. + * @param grpIds Cache group IDs. * @return Cache names. */ - private String cacheNames(Collection cacheIds) { + private String groupNames(Collection grpIds) { StringBuilder names = new StringBuilder(); - for (Integer cacheId : cacheIds) { - String name = registeredCaches.get(cacheId).cacheConfiguration().getName(); + for (Integer grpId : grpIds) { + String name = registeredGrps.get(grpId).cacheOrGroupName(); if (names.length() != 0) names.append(", "); @@ -988,21 +1014,24 @@ private void fetchAffinityOnJoin(GridDhtPartitionsExchangeFuture fut) throws Ign List fetchFuts = new ArrayList<>(); - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - DynamicCacheDescriptor cacheDesc = registeredCaches.get(cacheCtx.cacheId()); - - if (cctx.localNodeId().equals(cacheDesc.receivedFrom())) { - List> assignment = - cacheCtx.affinity().affinityCache().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); + if (fut.cacheGroupAddedOnExchange(grp.groupId(), grp.receivedFrom())) { + List> assignment = grp.affinity().calculate(fut.topologyVersion(), + fut.discoveryEvent(), + fut.discoCache()); - cacheCtx.affinity().affinityCache().initialize(fut.topologyVersion(), assignment); + grp.affinity().initialize(fut.topologyVersion(), assignment); } else { + CacheGroupDescriptor grpDesc = registeredGrps.get(grp.groupId()); + + assert grpDesc != null : grp.cacheOrGroupName(); + GridDhtAssignmentFetchFuture fetchFut = new GridDhtAssignmentFetchFuture(cctx, - cacheDesc, + grpDesc, topVer, fut.discoCache()); @@ -1015,9 +1044,9 @@ private void fetchAffinityOnJoin(GridDhtPartitionsExchangeFuture fut) throws Ign for (int i = 0; i < fetchFuts.size(); i++) { GridDhtAssignmentFetchFuture fetchFut = fetchFuts.get(i); - Integer cacheId = fetchFut.cacheId(); + Integer grpId = fetchFut.groupId(); - fetchAffinity(fut, cctx.cacheContext(cacheId).affinity().affinityCache(), fetchFut); + fetchAffinity(fut, cctx.cache().cacheGroup(grpId).affinity(), fetchFut); } } @@ -1076,11 +1105,11 @@ public boolean onServerLeft(final GridDhtPartitionsExchangeFuture fut) throws Ig boolean centralizedAff; if (lateAffAssign) { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - cacheCtx.affinity().affinityCache().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); + grp.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); } centralizedAff = true; @@ -1107,11 +1136,11 @@ public boolean onServerLeft(final GridDhtPartitionsExchangeFuture fut) throws Ig private void initAffinityNoLateAssignment(GridDhtPartitionsExchangeFuture fut) throws IgniteCheckedException { assert !lateAffAssign; - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - initAffinity(registeredCaches.get(cacheCtx.cacheId()), cacheCtx.affinity().affinityCache(), fut, false); + initAffinity(registeredGrps.get(grp.groupId()), grp.affinity(), fut); } } @@ -1122,35 +1151,38 @@ private void initAffinityNoLateAssignment(GridDhtPartitionsExchangeFuture fut) t */ private IgniteInternalFuture initCoordinatorCaches(final GridDhtPartitionsExchangeFuture fut) throws IgniteCheckedException { + assert lateAffAssign; + final List> futs = new ArrayList<>(); - forAllRegisteredCaches(new IgniteInClosureX() { - @Override public void applyx(DynamicCacheDescriptor desc) throws IgniteCheckedException { - CacheHolder cache = caches.get(desc.cacheId()); + forAllRegisteredCacheGroups(new IgniteInClosureX() { + @Override public void applyx(CacheGroupDescriptor desc) throws IgniteCheckedException { + CacheGroupHolder grpHolder = grpHolders.get(desc.groupId()); - if (cache != null) { - if (cache.client()) - cache.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); + if (grpHolder != null) { + if (grpHolder.client()) // Affinity for non-client holders calculated in {@link #onServerLeft}. + grpHolder.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache()); return; } - final Integer cacheId = desc.cacheId(); + // Need initialize holders and affinity if this node became coordinator during this exchange. + final Integer grpId = desc.groupId(); - GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + CacheGroupContext grp = cctx.cache().cacheGroup(grpId); - if (cacheCtx == null) { - cctx.io().addHandler(desc.cacheId(), GridDhtAffinityAssignmentResponse.class, + if (grp == null) { + cctx.io().addCacheGroupHandler(desc.groupId(), GridDhtAffinityAssignmentResponse.class, new IgniteBiInClosure() { @Override public void apply(UUID nodeId, GridDhtAffinityAssignmentResponse res) { - processAffinityAssignmentResponse(nodeId, res); + processAffinityAssignmentResponse(grpId, nodeId, res); } } ); - cache = CacheHolder2.create(cctx, desc, fut, null); + grpHolder = CacheGroupHolder2.create(cctx, desc, fut, null); - final GridAffinityAssignmentCache aff = cache.affinity(); + final GridAffinityAssignmentCache aff = grpHolder.affinity(); List exchFuts = cctx.exchange().exchangeFutures(); @@ -1160,9 +1192,10 @@ private IgniteInternalFuture initCoordinatorCaches(final GridDhtPartitionsExc ", total=" + exchFuts.size() + ']'; final GridDhtPartitionsExchangeFuture prev = exchFuts.get(idx + 1); + if (log.isDebugEnabled()) { log.debug("Need initialize affinity on coordinator [" + - "cache=" + desc.cacheConfiguration().getName() + + "cacheGrp=" + desc.cacheOrGroupName() + "prevAff=" + prev.topologyVersion() + ']'); } @@ -1191,9 +1224,9 @@ private IgniteInternalFuture initCoordinatorCaches(final GridDhtPartitionsExc futs.add(affFut); } else - cache = new CacheHolder1(cacheCtx, null); + grpHolder = new CacheGroupHolder1(grp, null); - CacheHolder old = caches.put(cache.cacheId(), cache); + CacheGroupHolder old = grpHolders.put(grpHolder.groupId(), grpHolder); assert old == null : old; } @@ -1219,38 +1252,36 @@ private IgniteInternalFuture initCoordinatorCaches(final GridDhtPartitionsExc * @return Cache holder. * @throws IgniteCheckedException If failed. */ - private CacheHolder cache(GridDhtPartitionsExchangeFuture fut, DynamicCacheDescriptor desc) + private CacheGroupHolder groupHolder(GridDhtPartitionsExchangeFuture fut, final CacheGroupDescriptor desc) throws IgniteCheckedException { assert lateAffAssign; - final Integer cacheId = desc.cacheId(); - - CacheHolder cache = caches.get(cacheId); + CacheGroupHolder cacheGrp = grpHolders.get(desc.groupId()); - if (cache != null) - return cache; + if (cacheGrp != null) + return cacheGrp; - GridCacheContext cacheCtx = cctx.cacheContext(desc.cacheId()); + final CacheGroupContext grp = cctx.cache().cacheGroup(desc.groupId()); - if (cacheCtx == null) { - cctx.io().addHandler(cacheId, GridDhtAffinityAssignmentResponse.class, + if (grp == null) { + cctx.io().addCacheGroupHandler(desc.groupId(), GridDhtAffinityAssignmentResponse.class, new IgniteBiInClosure() { @Override public void apply(UUID nodeId, GridDhtAffinityAssignmentResponse res) { - processAffinityAssignmentResponse(nodeId, res); + processAffinityAssignmentResponse(desc.groupId(), nodeId, res); } } ); - cache = CacheHolder2.create(cctx, desc, fut, null); + cacheGrp = CacheGroupHolder2.create(cctx, desc, fut, null); } else - cache = new CacheHolder1(cacheCtx, null); + cacheGrp = new CacheGroupHolder1(grp, null); - CacheHolder old = caches.put(cache.cacheId(), cache); + CacheGroupHolder old = grpHolders.put(desc.groupId(), cacheGrp); assert old == null : old; - return cache; + return cacheGrp; } /** @@ -1261,18 +1292,20 @@ private CacheHolder cache(GridDhtPartitionsExchangeFuture fut, DynamicCacheDescr */ @Nullable private WaitRebalanceInfo initAffinityOnNodeJoin(final GridDhtPartitionsExchangeFuture fut, boolean crd) throws IgniteCheckedException { + assert lateAffAssign; + AffinityTopologyVersion topVer = fut.topologyVersion(); final Map>> affCache = new HashMap<>(); if (!crd) { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - boolean latePrimary = cacheCtx.rebalanceEnabled(); + boolean latePrimary = grp.rebalanceEnabled(); - initAffinityOnNodeJoin(fut, cacheCtx.affinity().affinityCache(), null, latePrimary, affCache); + initAffinityOnNodeJoin(fut, grp.affinity(), null, latePrimary, affCache); } return null; @@ -1280,9 +1313,9 @@ private CacheHolder cache(GridDhtPartitionsExchangeFuture fut, DynamicCacheDescr else { final WaitRebalanceInfo waitRebalanceInfo = new WaitRebalanceInfo(topVer); - forAllRegisteredCaches(new IgniteInClosureX() { - @Override public void applyx(DynamicCacheDescriptor cacheDesc) throws IgniteCheckedException { - CacheHolder cache = cache(fut, cacheDesc); + forAllRegisteredCacheGroups(new IgniteInClosureX() { + @Override public void applyx(CacheGroupDescriptor desc) throws IgniteCheckedException { + CacheGroupHolder cache = groupHolder(fut, desc); boolean latePrimary = cache.rebalanceEnabled; @@ -1307,14 +1340,15 @@ private void initAffinityOnNodeJoin(GridDhtPartitionsExchangeFuture fut, WaitRebalanceInfo rebalanceInfo, boolean latePrimary, Map>> affCache) - throws IgniteCheckedException { + throws IgniteCheckedException + { assert lateAffAssign; AffinityTopologyVersion topVer = fut.topologyVersion(); AffinityTopologyVersion affTopVer = aff.lastVersion(); - assert affTopVer.topologyVersion() > 0 : "Affinity is not initialized [cache=" + aff.cacheName() + + assert affTopVer.topologyVersion() > 0 : "Affinity is not initialized [grp=" + aff.cacheOrGroupName() + ", topVer=" + affTopVer + ", node=" + cctx.localNodeId() + ']'; List> curAff = aff.assignments(affTopVer); @@ -1405,7 +1439,7 @@ private List latePrimaryAssignment( } if (rebalance != null) - rebalance.add(aff.cacheId(), part, newNodes.get(0).id(), newNodes); + rebalance.add(aff.groupId(), part, newNodes.get(0).id(), newNodes); return nodes0; } @@ -1448,6 +1482,8 @@ public IgniteInternalFuture>>> initAffinity */ private Map>> initAffinityOnNodeLeft0(final GridDhtPartitionsExchangeFuture fut) throws IgniteCheckedException { + assert lateAffAssign; + final AffinityTopologyVersion topVer = fut.topologyVersion(); final WaitRebalanceInfo waitRebalanceInfo = new WaitRebalanceInfo(topVer); @@ -1456,24 +1492,24 @@ private Map>> initAffinityOnNodeLeft0(final Gri final Map>> assignment = new HashMap<>(); - forAllRegisteredCaches(new IgniteInClosureX() { - @Override public void applyx(DynamicCacheDescriptor cacheDesc) throws IgniteCheckedException { - CacheHolder cache = cache(fut, cacheDesc); + forAllRegisteredCacheGroups(new IgniteInClosureX() { + @Override public void applyx(CacheGroupDescriptor desc) throws IgniteCheckedException { + CacheGroupHolder grpHolder = groupHolder(fut, desc); - if (!cache.rebalanceEnabled) + if (!grpHolder.rebalanceEnabled) return; - AffinityTopologyVersion affTopVer = cache.affinity().lastVersion(); + AffinityTopologyVersion affTopVer = grpHolder.affinity().lastVersion(); assert affTopVer.topologyVersion() > 0 && !affTopVer.equals(topVer) : "Invalid affinity version " + - "[last=" + affTopVer + ", futVer=" + topVer + ", cache=" + cache.name() + ']'; + "[last=" + affTopVer + ", futVer=" + topVer + ", grp=" + desc.cacheOrGroupName() + ']'; - List> curAssignment = cache.affinity().assignments(affTopVer); - List> newAssignment = cache.affinity().idealAssignment(); + List> curAssignment = grpHolder.affinity().assignments(affTopVer); + List> newAssignment = grpHolder.affinity().idealAssignment(); assert newAssignment != null; - GridDhtPartitionTopology top = cache.topology(fut); + GridDhtPartitionTopology top = grpHolder.topology(fut); Map> cacheAssignment = null; @@ -1487,7 +1523,7 @@ private Map>> initAffinityOnNodeLeft0(final Gri List newNodes0 = null; assert newPrimary == null || aliveNodes.contains(newPrimary) : "Invalid new primary [" + - "cache=" + cache.name() + + "grp=" + desc.cacheOrGroupName() + ", node=" + newPrimary + ", topVer=" + topVer + ']'; @@ -1496,7 +1532,7 @@ private Map>> initAffinityOnNodeLeft0(final Gri GridDhtPartitionState state = top.partitionState(newPrimary.id(), p); if (state != GridDhtPartitionState.OWNING) { - newNodes0 = latePrimaryAssignment(cache.affinity(), + newNodes0 = latePrimaryAssignment(grpHolder.affinity(), p, curPrimary, newNodes, @@ -1511,7 +1547,7 @@ private Map>> initAffinityOnNodeLeft0(final Gri ClusterNode curNode = curNodes.get(i); if (top.partitionState(curNode.id(), p) == GridDhtPartitionState.OWNING) { - newNodes0 = latePrimaryAssignment(cache.affinity(), + newNodes0 = latePrimaryAssignment(grpHolder.affinity(), p, curNode, newNodes, @@ -1526,7 +1562,7 @@ private Map>> initAffinityOnNodeLeft0(final Gri for (ClusterNode owner : owners) { if (aliveNodes.contains(owner)) { - newNodes0 = latePrimaryAssignment(cache.affinity(), + newNodes0 = latePrimaryAssignment(grpHolder.affinity(), p, owner, newNodes, @@ -1549,7 +1585,7 @@ private Map>> initAffinityOnNodeLeft0(final Gri } if (cacheAssignment != null) - assignment.put(cache.cacheId(), cacheAssignment); + assignment.put(grpHolder.groupId(), cacheAssignment); } }); @@ -1562,7 +1598,7 @@ private Map>> initAffinityOnNodeLeft0(final Gri if (log.isDebugEnabled()) { log.debug("Computed new affinity after node left [topVer=" + topVer + - ", waitCaches=" + (info != null ? cacheNames(info.waitCaches.keySet()) : null) + ']'); + ", waitGrps=" + (info != null ? groupNames(info.waitGrps.keySet()) : null) + ']'); } } @@ -1621,7 +1657,7 @@ private List toNodes(AffinityTopologyVersion topVer, List ids /** * */ - abstract static class CacheHolder { + abstract static class CacheGroupHolder { /** */ private final GridAffinityAssignmentCache aff; @@ -1633,7 +1669,7 @@ abstract static class CacheHolder { * @param aff Affinity cache. * @param initAff Existing affinity cache. */ - CacheHolder(boolean rebalanceEnabled, + CacheGroupHolder(boolean rebalanceEnabled, GridAffinityAssignmentCache aff, @Nullable GridAffinityAssignmentCache initAff) { this.aff = aff; @@ -1650,10 +1686,10 @@ abstract static class CacheHolder { abstract boolean client(); /** - * @return Cache ID. + * @return Group ID. */ - int cacheId() { - return aff.cacheId(); + int groupId() { + return aff.groupId(); } /** @@ -1663,13 +1699,6 @@ int partitions() { return aff.partitions(); } - /** - * @return Cache name. - */ - String name() { - return aff.cacheName(); - } - /** * @param fut Exchange future. * @return Cache topology. @@ -1687,20 +1716,20 @@ GridAffinityAssignmentCache affinity() { /** * Created cache is started on coordinator. */ - private class CacheHolder1 extends CacheHolder { + private class CacheGroupHolder1 extends CacheGroupHolder { /** */ - private final GridCacheContext cctx; + private final CacheGroupContext grp; /** - * @param cctx Cache context. + * @param grp Cache group. * @param initAff Current affinity. */ - CacheHolder1(GridCacheContext cctx, @Nullable GridAffinityAssignmentCache initAff) { - super(cctx.rebalanceEnabled(), cctx.affinity().affinityCache(), initAff); + CacheGroupHolder1(CacheGroupContext grp, @Nullable GridAffinityAssignmentCache initAff) { + super(grp.rebalanceEnabled(), grp.affinity(), initAff); - assert !cctx.isLocal() : cctx.name(); + assert !grp.isLocal() : grp; - this.cctx = cctx; + this.grp = grp; } /** {@inheritDoc} */ @@ -1708,57 +1737,42 @@ private class CacheHolder1 extends CacheHolder { return false; } - /** {@inheritDoc} */ - @Override public int partitions() { - return cctx.affinity().partitions(); - } - - /** {@inheritDoc} */ - @Override public String name() { - return cctx.name(); - } - - /** {@inheritDoc} */ - @Override public int cacheId() { - return cctx.cacheId(); - } - /** {@inheritDoc} */ @Override public GridDhtPartitionTopology topology(GridDhtPartitionsExchangeFuture fut) { - return cctx.topology(); + return grp.topology(); } } /** * Created if cache is not started on coordinator. */ - private static class CacheHolder2 extends CacheHolder { + private static class CacheGroupHolder2 extends CacheGroupHolder { /** */ private final GridCacheSharedContext cctx; /** * @param cctx Context. - * @param cacheDesc Cache descriptor. + * @param grpDesc Cache group descriptor. * @param fut Exchange future. * @param initAff Current affinity. * @return Cache holder. * @throws IgniteCheckedException If failed. */ - static CacheHolder2 create( + static CacheGroupHolder2 create( GridCacheSharedContext cctx, - DynamicCacheDescriptor cacheDesc, + CacheGroupDescriptor grpDesc, GridDhtPartitionsExchangeFuture fut, @Nullable GridAffinityAssignmentCache initAff) throws IgniteCheckedException { - assert cacheDesc != null; + assert grpDesc != null; assert !cctx.kernalContext().clientNode(); - CacheConfiguration ccfg = cacheDesc.cacheConfiguration(); + CacheConfiguration ccfg = grpDesc.config(); - assert ccfg != null : cacheDesc; + assert ccfg != null : grpDesc; assert ccfg.getCacheMode() != LOCAL : ccfg.getName(); - assert !cctx.discovery().cacheAffinityNodes(ccfg.getName(), - fut.topologyVersion()).contains(cctx.localNode()) : cacheDesc.cacheName(); + assert !cctx.discovery().cacheGroupAffinityNodes(grpDesc.groupId(), + fut.topologyVersion()).contains(cctx.localNode()) : grpDesc.cacheOrGroupName(); AffinityFunction affFunc = cctx.cache().clone(ccfg.getAffinity()); @@ -1768,13 +1782,14 @@ static CacheHolder2 create( U.startLifecycleAware(F.asList(affFunc)); GridAffinityAssignmentCache aff = new GridAffinityAssignmentCache(cctx.kernalContext(), - ccfg.getName(), + grpDesc.cacheOrGroupName(), + grpDesc.groupId(), affFunc, ccfg.getNodeFilter(), ccfg.getBackups(), ccfg.getCacheMode() == LOCAL); - return new CacheHolder2(ccfg.getRebalanceMode() != NONE, cctx, aff, initAff); + return new CacheGroupHolder2(ccfg.getRebalanceMode() != NONE, cctx, aff, initAff); } /** @@ -1783,7 +1798,7 @@ static CacheHolder2 create( * @param aff Affinity. * @param initAff Current affinity. */ - CacheHolder2( + CacheGroupHolder2( boolean rebalanceEnabled, GridCacheSharedContext cctx, GridAffinityAssignmentCache aff, @@ -1800,7 +1815,7 @@ static CacheHolder2 create( /** {@inheritDoc} */ @Override public GridDhtPartitionTopology topology(GridDhtPartitionsExchangeFuture fut) { - return cctx.exchange().clientTopology(cacheId(), fut); + return cctx.exchange().clientTopology(groupId(), fut); } } @@ -1812,7 +1827,7 @@ class WaitRebalanceInfo { private final AffinityTopologyVersion topVer; /** */ - private Map> waitCaches; + private Map> waitGrps; /** */ private Map>> assignments; @@ -1831,9 +1846,9 @@ class WaitRebalanceInfo { * @return {@code True} if there are partitions waiting for rebalancing. */ boolean empty() { - if (waitCaches != null) { - assert !waitCaches.isEmpty(); - assert waitCaches.size() == assignments.size(); + if (waitGrps != null) { + assert !waitGrps.isEmpty(); + assert waitGrps.size() == assignments.size(); return false; } @@ -1842,34 +1857,34 @@ boolean empty() { } /** - * @param cacheId Cache ID. + * @param grpId Group ID. * @param part Partition. * @param waitNode Node rebalancing data. * @param assignment New assignment. */ - void add(Integer cacheId, Integer part, UUID waitNode, List assignment) { + void add(Integer grpId, Integer part, UUID waitNode, List assignment) { assert !F.isEmpty(assignment) : assignment; - if (waitCaches == null) { - waitCaches = new HashMap<>(); + if (waitGrps == null) { + waitGrps = new HashMap<>(); assignments = new HashMap<>(); deploymentIds = new HashMap<>(); } - Map cacheWaitParts = waitCaches.get(cacheId); + Map cacheWaitParts = waitGrps.get(grpId); if (cacheWaitParts == null) { - waitCaches.put(cacheId, cacheWaitParts = new HashMap<>()); + waitGrps.put(grpId, cacheWaitParts = new HashMap<>()); - deploymentIds.put(cacheId, registeredCaches.get(cacheId).deploymentId()); + deploymentIds.put(grpId, registeredGrps.get(grpId).deploymentId()); } cacheWaitParts.put(part, waitNode); - Map> cacheAssignment = assignments.get(cacheId); + Map> cacheAssignment = assignments.get(grpId); if (cacheAssignment == null) - assignments.put(cacheId, cacheAssignment = new HashMap<>()); + assignments.put(grpId, cacheAssignment = new HashMap<>()); cacheAssignment.put(part, assignment); } @@ -1877,7 +1892,7 @@ void add(Integer cacheId, Integer part, UUID waitNode, List assignm /** {@inheritDoc} */ @Override public String toString() { return "WaitRebalanceInfo [topVer=" + topVer + - ", caches=" + (waitCaches != null ? waitCaches.keySet() : null) + ']'; + ", grps=" + (waitGrps != null ? waitGrps.keySet() : null) + ']'; } } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClientReconnectDiscoveryData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClientReconnectDiscoveryData.java index a30331ff0404b..6a6f40d90f998 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClientReconnectDiscoveryData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClientReconnectDiscoveryData.java @@ -30,16 +30,29 @@ public class CacheClientReconnectDiscoveryData implements Serializable { /** */ private static final long serialVersionUID = 0L; + /** */ + private final Map clientCacheGrps; + /** */ private final Map clientCaches; /** * @param clientCaches Information about caches started on re-joining client node. + * @param clientCacheGrps Information about cach groups started on re-joining client node. */ - CacheClientReconnectDiscoveryData(Map clientCaches) { + CacheClientReconnectDiscoveryData(Map clientCacheGrps, + Map clientCaches) { + this.clientCacheGrps = clientCacheGrps; this.clientCaches = clientCaches; } + /** + * @return Information about caches started on re-joining client node. + */ + Map clientCacheGroups() { + return clientCacheGrps; + } + /** * @return Information about caches started on re-joining client node. */ @@ -47,6 +60,53 @@ Map clientCaches() { return clientCaches; } + /** + * + */ + static class CacheGroupInfo implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final CacheConfiguration ccfg; + + /** */ + private final IgniteUuid deploymentId; + + /** Flags added for future usage. */ + private final long flags; + + /** + * @param ccfg Cache group configuration. + * @param deploymentId Cache group deployment ID. + * @param flags Flags (for future usage). + */ + CacheGroupInfo(CacheConfiguration ccfg, + IgniteUuid deploymentId, + long flags) { + assert ccfg != null; + assert deploymentId != null; + + this.ccfg = ccfg; + this.deploymentId = deploymentId; + this.flags = flags; + } + + /** + * @return Cache group configuration. + */ + CacheConfiguration config() { + return ccfg; + } + + /** + * @return Cache group deployment ID. + */ + IgniteUuid deploymentId() { + return deploymentId; + } + } + /** * */ @@ -67,7 +127,7 @@ static class CacheInfo implements Serializable { private final boolean nearCache; /** Flags added for future usage. */ - private final byte flags; + private final long flags; /** * @param ccfg Cache configuration. @@ -80,7 +140,7 @@ static class CacheInfo implements Serializable { CacheType cacheType, IgniteUuid deploymentId, boolean nearCache, - byte flags) { + long flags) { assert ccfg != null; assert cacheType != null; assert deploymentId != null; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheData.java index 3e2c259912437..b728d9611ccb3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheData.java @@ -35,7 +35,10 @@ public class CacheData implements Serializable { private final CacheConfiguration cacheCfg; /** */ - private final Integer cacheId; + private final int cacheId; + + /** */ + private final int grpId; /** */ private final CacheType cacheType; @@ -59,11 +62,12 @@ public class CacheData implements Serializable { private final boolean template; /** Flags added for future usage. */ - private final byte flags; + private final long flags; /** * @param cacheCfg Cache configuration. * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param cacheType Cache ID. * @param deploymentId Cache deployment ID. * @param schema Query schema. @@ -75,6 +79,7 @@ public class CacheData implements Serializable { */ CacheData(CacheConfiguration cacheCfg, int cacheId, + int grpId, CacheType cacheType, IgniteUuid deploymentId, QuerySchema schema, @@ -82,14 +87,16 @@ public class CacheData implements Serializable { boolean staticCfg, boolean sql, boolean template, - byte flags) { + long flags) { assert cacheCfg != null; assert rcvdFrom != null : cacheCfg.getName(); assert deploymentId != null : cacheCfg.getName(); assert template || cacheId != 0 : cacheCfg.getName(); + assert template || grpId != 0 : cacheCfg.getName(); this.cacheCfg = cacheCfg; this.cacheId = cacheId; + this.grpId = grpId; this.cacheType = cacheType; this.deploymentId = deploymentId; this.schema = schema; @@ -100,10 +107,17 @@ public class CacheData implements Serializable { this.flags = flags; } + /** + * @return Cache group ID. + */ + public int groupId() { + return grpId; + } + /** * @return Cache ID. */ - public Integer cacheId() { + public int cacheId() { return cacheId; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java new file mode 100644 index 0000000000000..b85c41deed186 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java @@ -0,0 +1,964 @@ +/* + * 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 java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.cache.affinity.AffinityFunction; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataPageEvictionMode; +import org.apache.ignite.configuration.TopologyValidator; +import org.apache.ignite.events.CacheRebalancingEvent; +import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.affinity.AffinityAssignment; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; +import org.apache.ignite.internal.processors.cache.database.MemoryPolicy; +import org.apache.ignite.internal.processors.cache.database.freelist.FreeList; +import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentRequest; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentResponse; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopologyImpl; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader; +import org.apache.ignite.internal.processors.cache.query.continuous.CounterSkipContext; +import org.apache.ignite.internal.processors.query.QueryUtils; +import org.apache.ignite.internal.util.typedef.CI1; +import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.LT; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiInClosure; +import org.apache.ignite.lang.IgniteFuture; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.lang.IgniteUuid; +import org.jetbrains.annotations.Nullable; + +import static org.apache.ignite.cache.CacheMode.LOCAL; +import static org.apache.ignite.cache.CacheRebalanceMode.NONE; +import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_UNLOADED; +import static org.apache.ignite.internal.managers.communication.GridIoPolicy.AFFINITY_POOL; + +/** + * + */ +public class CacheGroupContext { + /** + * Unique group ID. Currently for shared group it is generated as group name hash, + * for non-shared as cache name hash (see {@link ClusterCachesInfo#checkCacheConflict}). + */ + private final int grpId; + + /** Node ID cache group was received from. */ + private final UUID rcvdFrom; + + /** Flag indicating that this cache group is in a recovery mode due to partitions loss. */ + private boolean needsRecovery; + + /** */ + private final AffinityTopologyVersion locStartVer; + + /** */ + private final CacheConfiguration ccfg; + + /** */ + private final GridCacheSharedContext ctx; + + /** */ + private final boolean affNode; + + /** */ + private final CacheType cacheType; + + /** */ + private final byte ioPlc; + + /** */ + private final boolean depEnabled; + + /** */ + private final boolean storeCacheId; + + /** */ + private volatile List caches; + + /** */ + private volatile List contQryCaches; + + /** */ + private final IgniteLogger log; + + /** */ + private GridAffinityAssignmentCache aff; + + /** */ + private GridDhtPartitionTopologyImpl top; + + /** */ + private IgniteCacheOffheapManager offheapMgr; + + /** */ + private GridCachePreloader preldr; + + /** */ + private final MemoryPolicy memPlc; + + /** */ + private final CacheObjectContext cacheObjCtx; + + /** */ + private final FreeList freeList; + + /** */ + private final ReuseList reuseList; + + /** */ + private boolean drEnabled; + + /** */ + private boolean qryEnabled; + + /** + * @param grpId Group ID. + * @param ctx Context. + * @param rcvdFrom Node ID cache group was received from. + * @param cacheType Cache type. + * @param ccfg Cache configuration. + * @param affNode Affinity node flag. + * @param memPlc Memory policy. + * @param cacheObjCtx Cache object context. + * @param freeList Free list. + * @param reuseList Reuse list. + * @param locStartVer Topology version when group was started on local node. + */ + CacheGroupContext( + GridCacheSharedContext ctx, + int grpId, + UUID rcvdFrom, + CacheType cacheType, + CacheConfiguration ccfg, + boolean affNode, + MemoryPolicy memPlc, + CacheObjectContext cacheObjCtx, + FreeList freeList, + ReuseList reuseList, + AffinityTopologyVersion locStartVer) { + assert ccfg != null; + assert memPlc != null || !affNode; + assert grpId != 0 : "Invalid group ID [cache=" + ccfg.getName() + ", grpName=" + ccfg.getGroupName() + ']'; + + this.grpId = grpId; + this.rcvdFrom = rcvdFrom; + this.ctx = ctx; + this.ccfg = ccfg; + this.affNode = affNode; + this.memPlc = memPlc; + this.cacheObjCtx = cacheObjCtx; + this.freeList = freeList; + this.reuseList = reuseList; + this.locStartVer = locStartVer; + this.cacheType = cacheType; + + ioPlc = cacheType.ioPolicy(); + + depEnabled = ctx.kernalContext().deploy().enabled() && !ctx.kernalContext().cacheObjects().isBinaryEnabled(ccfg); + + storeCacheId = affNode && memPlc.config().getPageEvictionMode() != DataPageEvictionMode.DISABLED; + + log = ctx.kernalContext().log(getClass()); + + caches = new ArrayList<>(); + } + + /** + * @return {@code True} if this is cache group for one of system caches. + */ + public boolean systemCache() { + return !sharedGroup() && CU.isSystemCache(ccfg.getName()); + } + + /** + * @return Node ID initiated cache group start. + */ + public UUID receivedFrom() { + return rcvdFrom; + } + + /** + * @return {@code True} if cacheId should be stored in data pages. + */ + public boolean storeCacheIdInDataPage() { + return storeCacheId; + } + + /** + * @return {@code True} if deployment is enabled. + */ + public boolean deploymentEnabled() { + return depEnabled; + } + + /** + * @return Preloader. + */ + public GridCachePreloader preloader() { + return preldr; + } + + /** + * @return IO policy for the given cache group. + */ + public byte ioPolicy() { + return ioPlc; + } + + /** + * @param cctx Cache context. + * @throws IgniteCheckedException If failed. + */ + void onCacheStarted(GridCacheContext cctx) throws IgniteCheckedException { + addCacheContext(cctx); + + offheapMgr.onCacheStarted(cctx); + } + + /** + * @param cacheName Cache name. + * @return {@code True} if group contains cache with given name. + */ + public boolean hasCache(String cacheName) { + List caches = this.caches; + + for (int i = 0; i < caches.size(); i++) { + if (caches.get(i).name().equals(cacheName)) + return true; + } + + return false; + } + + /** + * @param cctx Cache context. + */ + private void addCacheContext(GridCacheContext cctx) { + assert cacheType.userCache() == cctx.userCache() : cctx.name(); + assert grpId == cctx.groupId() : cctx.name(); + + ArrayList caches = new ArrayList<>(this.caches); + + assert sharedGroup() || caches.isEmpty(); + + boolean add = caches.add(cctx); + + assert add : cctx.name(); + + if (!qryEnabled && QueryUtils.isEnabled(cctx.config())) + qryEnabled = true; + + if (!drEnabled && cctx.isDrEnabled()) + drEnabled = true; + + this.caches = caches; + } + + /** + * @param cctx Cache context. + */ + private void removeCacheContext(GridCacheContext cctx) { + ArrayList caches = new ArrayList<>(this.caches); + + // It is possible cache was not added in case of errors on cache start. + for (Iterator it = caches.iterator(); it.hasNext();) { + GridCacheContext next = it.next(); + + if (next == cctx) { + assert sharedGroup() || caches.size() == 1 : caches.size(); + + it.remove(); + + break; + } + } + + if (QueryUtils.isEnabled(cctx.config())) { + boolean qryEnabled = false; + + for (int i = 0; i < caches.size(); i++) { + if (QueryUtils.isEnabled(caches.get(i).config())) { + qryEnabled = true; + + break; + } + } + + this.qryEnabled = qryEnabled; + } + + if (cctx.isDrEnabled()) { + boolean drEnabled = false; + + for (int i = 0; i < caches.size(); i++) { + if (caches.get(i).isDrEnabled()) { + drEnabled = true; + + break; + } + } + + this.drEnabled = drEnabled; + } + + this.caches = caches; + } + + /** + * @return Cache context if group contains single cache. + */ + public GridCacheContext singleCacheContext() { + List caches = this.caches; + + assert !sharedGroup() && caches.size() == 1; + + return caches.get(0); + } + + /** + * + */ + public void unwindUndeploys() { + List caches = this.caches; + + for (int i = 0; i < caches.size(); i++) { + GridCacheContext cctx = caches.get(i); + + cctx.deploy().unwind(cctx); + } + } + + /** + * @param type Event type to check. + * @return {@code True} if given event type should be recorded. + */ + public boolean eventRecordable(int type) { + return cacheType.userCache() && ctx.gridEvents().isRecordable(type); + } + + /** + * Adds rebalancing event. + * + * @param part Partition. + * @param type Event type. + * @param discoNode Discovery node. + * @param discoType Discovery event type. + * @param discoTs Discovery event timestamp. + */ + public void addRebalanceEvent(int part, int type, ClusterNode discoNode, int discoType, long discoTs) { + assert discoNode != null; + assert type > 0; + assert discoType > 0; + assert discoTs > 0; + + if (!eventRecordable(type)) + LT.warn(log, "Added event without checking if event is recordable: " + U.gridEventName(type)); + + List caches = this.caches; + + for (int i = 0; i < caches.size(); i++) { + GridCacheContext cctx = caches.get(i); + + if (cctx.recordEvent(type)) { + cctx.gridEvents().record(new CacheRebalancingEvent(cctx.name(), + cctx.localNode(), + "Cache rebalancing event.", + type, + part, + discoNode, + discoType, + discoTs)); + } + } + } + /** + * Adds partition unload event. + * + * @param part Partition. + */ + public void addUnloadEvent(int part) { + if (!eventRecordable(EVT_CACHE_REBALANCE_PART_UNLOADED)) + LT.warn(log, "Added event without checking if event is recordable: " + + U.gridEventName(EVT_CACHE_REBALANCE_PART_UNLOADED)); + + List caches = this.caches; + + for (int i = 0; i < caches.size(); i++) { + GridCacheContext cctx = caches.get(i); + + cctx.gridEvents().record(new CacheRebalancingEvent(cctx.name(), + cctx.localNode(), + "Cache unloading event.", + EVT_CACHE_REBALANCE_PART_UNLOADED, + part, + null, + 0, + 0)); + } + } + + /** + * @param part Partition. + * @param key Key. + * @param evtNodeId Event node ID. + * @param type Event type. + * @param newVal New value. + * @param hasNewVal Has new value flag. + * @param oldVal Old values. + * @param hasOldVal Has old value flag. + * @param keepBinary Keep binary flag. + */ + public void addCacheEvent( + int part, + KeyCacheObject key, + UUID evtNodeId, + int type, + @Nullable CacheObject newVal, + boolean hasNewVal, + @Nullable CacheObject oldVal, + boolean hasOldVal, + boolean keepBinary + ) { + List caches = this.caches; + + for (int i = 0; i < caches.size(); i++) { + GridCacheContext cctx = caches.get(i); + + cctx.events().addEvent(part, + key, + evtNodeId, + (IgniteUuid)null, + null, + type, + newVal, + hasNewVal, + oldVal, + hasOldVal, + null, + null, + null, + keepBinary); + } + } + + /** + * @return {@code True} if contains cache with query indexing enabled. + */ + public boolean queriesEnabled() { + return qryEnabled; + } + + /** + * @return {@code True} if fast eviction is allowed. + */ + public boolean allowFastEviction() { + return ctx.database().persistenceEnabled() && !queriesEnabled(); + } + + /** + * @return {@code True} in case replication is enabled. + */ + public boolean isDrEnabled() { + return drEnabled; + } + + /** + * @return Free List. + */ + public FreeList freeList() { + return freeList; + } + + /** + * @return Reuse List. + */ + public ReuseList reuseList() { + return reuseList; + } + + /** + * @return Cache object context. + */ + public CacheObjectContext cacheObjectContext() { + return cacheObjCtx; + } + + /** + * @return Cache shared context. + */ + public GridCacheSharedContext shared() { + return ctx; + } + + /** + * @return Memory policy. + */ + public MemoryPolicy memoryPolicy() { + return memPlc; + } + + /** + * @return {@code True} if local node is affinity node. + */ + public boolean affinityNode() { + return affNode; + } + + /** + * @return Topology. + */ + public GridDhtPartitionTopology topology() { + if (top == null) + throw new IllegalStateException("Topology is not initialized: " + name()); + + return top; + } + + /** + * @return Offheap manager. + */ + public IgniteCacheOffheapManager offheap() { + return offheapMgr; + } + + /** + * @return Current cache state. Must only be modified during exchange. + */ + public boolean needsRecovery() { + return needsRecovery; + } + + /** + * @param needsRecovery Needs recovery flag. + */ + public void needsRecovery(boolean needsRecovery) { + this.needsRecovery = needsRecovery; + } + + /** + * @return Topology version when group was started on local node. + */ + public AffinityTopologyVersion localStartVersion() { + return locStartVer; + } + + /** + * @return {@code True} if cache is local. + */ + public boolean isLocal() { + return ccfg.getCacheMode() == LOCAL; + } + + /** + * @return Cache configuration. + */ + public CacheConfiguration config() { + return ccfg; + } + + /** + * @return Cache node filter. + */ + public IgnitePredicate nodeFilter() { + return ccfg.getNodeFilter(); + } + + /** + * @return Configured user objects which should be initialized/stopped on group start/stop. + */ + Collection configuredUserObjects() { + return Arrays.asList(ccfg.getAffinity(), ccfg.getNodeFilter(), ccfg.getTopologyValidator()); + } + + /** + * @return Configured topology validator. + */ + @Nullable public TopologyValidator topologyValidator() { + return ccfg.getTopologyValidator(); + } + + /** + * @return Configured affinity function. + */ + public AffinityFunction affinityFunction() { + return ccfg.getAffinity(); + } + + /** + * @return Affinity. + */ + public GridAffinityAssignmentCache affinity() { + return aff; + } + + /** + * @return Group name or {@code null} if group name was not specified for cache. + */ + @Nullable public String name() { + return ccfg.getGroupName(); + } + + /** + * @return Group name if it is specified, otherwise cache name. + */ + public String cacheOrGroupName() { + return ccfg.getGroupName() != null ? ccfg.getGroupName() : ccfg.getName(); + } + + /** + * @return Group ID. + */ + public int groupId() { + return grpId; + } + + /** + * @return {@code True} if group can contain multiple caches. + */ + public boolean sharedGroup() { + return ccfg.getGroupName() != null; + } + + /** + * + */ + public void onKernalStop() { + aff.cancelFutures(new IgniteCheckedException("Failed to wait for topology update, node is stopping.")); + + preldr.onKernalStop(); + + offheapMgr.onKernalStop(); + } + + /** + * @param cctx Cache context. + * @param destroy Destroy flag. + */ + void stopCache(GridCacheContext cctx, boolean destroy) { + if (top != null) + top.onCacheStopped(cctx.cacheId()); + + offheapMgr.stopCache(cctx.cacheId(), destroy); + + removeCacheContext(cctx); + } + + /** + * + */ + void stopGroup() { + IgniteCheckedException err = + new IgniteCheckedException("Failed to wait for topology update, cache (or node) is stopping."); + + aff.cancelFutures(err); + + offheapMgr.stop(); + + ctx.io().removeCacheGroupHandlers(grpId); + } + + /** + * @return IDs of caches in this group. + */ + public Set cacheIds() { + List caches = this.caches; + + Set ids = U.newHashSet(caches.size()); + + for (int i = 0; i < caches.size(); i++) + ids.add(caches.get(i).cacheId()); + + return ids; + } + + /** + * @return Caches in this group. + */ + public List caches() { + return this.caches; + } + + /** + * @return {@code True} if group contains caches. + */ + boolean hasCaches() { + List caches = this.caches; + + return !caches.isEmpty(); + } + + /** + * @param part Partition ID. + */ + public void onPartitionEvicted(int part) { + List caches = this.caches; + + for (int i = 0; i < caches.size(); i++) { + GridCacheContext cctx = caches.get(i); + + if (cctx.isDrEnabled()) + cctx.dr().partitionEvicted(part); + + cctx.continuousQueries().onPartitionEvicted(part); + + cctx.dataStructures().onPartitionEvicted(part); + } + } + + /** + * @param cctx Cache context. + */ + public void addCacheWithContinuousQuery(GridCacheContext cctx) { + assert sharedGroup() : cacheOrGroupName(); + assert cctx.group() == this : cctx.name(); + assert !cctx.isLocal() : cctx.name(); + + synchronized (this) { + List contQryCaches = this.contQryCaches; + + if (contQryCaches == null) + contQryCaches = new ArrayList<>(); + + contQryCaches.add(cctx); + + this.contQryCaches = contQryCaches; + } + } + + /** + * @param cctx Cache context. + */ + public void removeCacheWithContinuousQuery(GridCacheContext cctx) { + assert sharedGroup() : cacheOrGroupName(); + assert cctx.group() == this : cctx.name(); + assert !cctx.isLocal() : cctx.name(); + + synchronized (this) { + List contQryCaches = this.contQryCaches; + + if (contQryCaches == null) + return; + + contQryCaches.remove(cctx); + + if (contQryCaches.isEmpty()) + contQryCaches = null; + + this.contQryCaches = contQryCaches; + } + } + + /** + * @param cacheId ID of cache initiated counter update. + * @param part Partition number. + * @param cntr Counter. + * @param topVer Topology version for current operation. + */ + public void onPartitionCounterUpdate(int cacheId, + int part, + long cntr, + AffinityTopologyVersion topVer, + boolean primary) { + assert sharedGroup(); + + if (isLocal()) + return; + + List contQryCaches = this.contQryCaches; + + if (contQryCaches == null) + return; + + CounterSkipContext skipCtx = null; + + for (int i = 0; i < contQryCaches.size(); i++) { + GridCacheContext cctx = contQryCaches.get(i); + + if (cacheId != cctx.cacheId()) + skipCtx = cctx.continuousQueries().skipUpdateCounter(skipCtx, part, cntr, topVer, primary); + } + + final List procC = skipCtx != null ? skipCtx.processClosures() : null; + + if (procC != null) { + ctx.kernalContext().closure().runLocalSafe(new Runnable() { + @Override public void run() { + for (Runnable c : procC) + c.run(); + } + }); + } + } + + /** + * @throws IgniteCheckedException If failed. + */ + public void start() throws IgniteCheckedException { + aff = new GridAffinityAssignmentCache(ctx.kernalContext(), + cacheOrGroupName(), + grpId, + ccfg.getAffinity(), + ccfg.getNodeFilter(), + ccfg.getBackups(), + ccfg.getCacheMode() == LOCAL); + + if (ccfg.getCacheMode() != LOCAL) { + top = new GridDhtPartitionTopologyImpl(ctx, this); + + if (!ctx.kernalContext().clientNode()) { + ctx.io().addCacheGroupHandler(groupId(), GridDhtAffinityAssignmentRequest.class, + new IgniteBiInClosure() { + @Override public void apply(UUID nodeId, GridDhtAffinityAssignmentRequest msg) { + processAffinityAssignmentRequest(nodeId, msg); + } + }); + } + + preldr = new GridDhtPreloader(this); + + preldr.start(); + } + else + preldr = new GridCachePreloaderAdapter(this); + + if (ctx.kernalContext().config().getPersistentStoreConfiguration() != null) { + ClassLoader clsLdr = U.gridClassLoader(); + + try { + offheapMgr = (IgniteCacheOffheapManager) clsLdr + .loadClass("org.apache.ignite.internal.processors.cache.database.GridCacheOffheapManager") + .getConstructor() + .newInstance(); + } + catch (Exception e) { + throw new IgniteCheckedException("Failed to initialize offheap manager", e); + } + } + else + offheapMgr = new IgniteCacheOffheapManagerImpl(); + + offheapMgr.start(ctx, this); + + ctx.affinity().onCacheGroupCreated(this); + } + + /** + * @param nodeId Node ID. + * @param req Request. + */ + private void processAffinityAssignmentRequest(final UUID nodeId, + final GridDhtAffinityAssignmentRequest req) { + if (log.isDebugEnabled()) + log.debug("Processing affinity assignment request [node=" + nodeId + ", req=" + req + ']'); + + IgniteInternalFuture fut = aff.readyFuture(req.topologyVersion()); + + if (fut != null) { + fut.listen(new CI1>() { + @Override public void apply(IgniteInternalFuture fut) { + processAffinityAssignmentRequest0(nodeId, req); + } + }); + } + else + processAffinityAssignmentRequest0(nodeId, req); + } + + /** + * @param nodeId Node ID. + * @param req Request. + */ + private void processAffinityAssignmentRequest0(UUID nodeId, final GridDhtAffinityAssignmentRequest req) { + AffinityTopologyVersion topVer = req.topologyVersion(); + + if (log.isDebugEnabled()) + log.debug("Affinity is ready for topology version, will send response [topVer=" + topVer + + ", node=" + nodeId + ']'); + + AffinityAssignment assignment = aff.cachedAffinity(topVer); + + GridDhtAffinityAssignmentResponse res = new GridDhtAffinityAssignmentResponse( + req.futureId(), + grpId, + topVer, + assignment.assignment()); + + if (aff.centralizedAffinityFunction()) { + assert assignment.idealAssignment() != null; + + res.idealAffinityAssignment(assignment.idealAssignment()); + } + + try { + ctx.io().send(nodeId, res, AFFINITY_POOL); + } + catch (IgniteCheckedException e) { + U.error(log, "Failed to send affinity assignment response to remote node [node=" + nodeId + ']', e); + } + } + + /** + * @param reconnectFut Reconnect future. + */ + public void onDisconnected(IgniteFuture reconnectFut) { + IgniteCheckedException err = new IgniteClientDisconnectedCheckedException(reconnectFut, + "Failed to wait for topology update, client disconnected."); + + if (aff != null) + aff.cancelFutures(err); + } + + /** + * @return {@code True} if rebalance is enabled. + */ + public boolean rebalanceEnabled() { + return ccfg.getRebalanceMode() != NONE; + } + + /** + * + */ + public void onReconnected() { + aff.onReconnected(); + + if (top != null) + top.onReconnected(); + + preldr.onReconnected(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "CacheGroupContext [grp=" + cacheOrGroupName() + ']'; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupData.java new file mode 100644 index 0000000000000..a290caf8e51a2 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupData.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; + +import java.io.Serializable; +import java.util.Map; +import java.util.UUID; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteUuid; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class CacheGroupData implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final int grpId; + + /** */ + private final String grpName; + + /** */ + private final AffinityTopologyVersion startTopVer; + + /** */ + private final UUID rcvdFrom; + + /** */ + private final IgniteUuid deploymentId; + + /** */ + private final CacheConfiguration cacheCfg; + + /** */ + @GridToStringInclude + private final Map caches; + + /** */ + private long flags; + + /** + * @param cacheCfg Cache configuration. + * @param grpName Group name. + * @param grpId Group ID. + * @param rcvdFrom Node ID cache group received from. + * @param startTopVer Start version for dynamically started group. + * @param deploymentId Deployment ID. + * @param caches Cache group caches. + */ + CacheGroupData( + CacheConfiguration cacheCfg, + @Nullable String grpName, + int grpId, + UUID rcvdFrom, + @Nullable AffinityTopologyVersion startTopVer, + IgniteUuid deploymentId, + Map caches, + long flags) { + assert cacheCfg != null; + assert grpId != 0; + assert deploymentId != null; + + this.cacheCfg = cacheCfg; + this.grpName = grpName; + this.grpId = grpId; + this.rcvdFrom = rcvdFrom; + this.startTopVer = startTopVer; + this.deploymentId = deploymentId; + this.caches = caches; + this.flags = flags; + } + + /** + * @return Start version for dynamically started group. + */ + @Nullable public AffinityTopologyVersion startTopologyVersion() { + return startTopVer; + } + + /** + * @return Node ID group was received from. + */ + public UUID receivedFrom() { + return rcvdFrom; + } + + /** + * @return Group name. + */ + @Nullable public String groupName() { + return grpName; + } + + /** + * @return Group ID. + */ + public int groupId() { + return grpId; + } + + /** + * @return Deployment ID. + */ + public IgniteUuid deploymentId() { + return deploymentId; + } + + /** + * @return Configuration. + */ + public CacheConfiguration config() { + return cacheCfg; + } + + /** + * @return Group caches. + */ + Map caches() { + return caches; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(CacheGroupData.class, this); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupDescriptor.java new file mode 100644 index 0000000000000..c4976e52ccce4 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupDescriptor.java @@ -0,0 +1,210 @@ +/* + * 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 java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.util.tostring.GridToStringExclude; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteUuid; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class CacheGroupDescriptor { + /** */ + private final int grpId; + + /** */ + private final String grpName; + + /** */ + private final AffinityTopologyVersion startTopVer; + + /** */ + private final UUID rcvdFrom; + + /** */ + private final IgniteUuid deploymentId; + + /** */ + @GridToStringExclude + private final CacheConfiguration cacheCfg; + + /** */ + @GridToStringInclude + private Map caches; + + /** */ + private AffinityTopologyVersion rcvdFromVer; + + /** + * @param cacheCfg Cache configuration. + * @param grpName Group name. + * @param grpId Group ID. + * @param rcvdFrom Node ID cache group received from. + * @param startTopVer Start version for dynamically started group. + * @param deploymentId Deployment ID. + * @param caches Cache group caches. + */ + CacheGroupDescriptor( + CacheConfiguration cacheCfg, + @Nullable String grpName, + int grpId, + UUID rcvdFrom, + @Nullable AffinityTopologyVersion startTopVer, + IgniteUuid deploymentId, + Map caches) { + assert cacheCfg != null; + assert grpId != 0; + + this.grpName = grpName; + this.grpId = grpId; + this.rcvdFrom = rcvdFrom; + this.startTopVer = startTopVer; + this.deploymentId = deploymentId; + this.cacheCfg = cacheCfg; + this.caches = caches; + } + + /** + * @return Node ID group was received from. + */ + public UUID receivedFrom() { + return rcvdFrom; + } + + /** + * @return Deployment ID. + */ + public IgniteUuid deploymentId() { + return deploymentId; + } + + /** + * @param cacheName Cache name + * @param cacheId Cache ID. + */ + void onCacheAdded(String cacheName, int cacheId) { + assert cacheName != null; + assert cacheId != 0 : cacheName; + + Map caches = new HashMap<>(this.caches); + + caches.put(cacheName, cacheId); + + this.caches = caches; + } + + /** + * @param cacheName Cache name + * @param cacheId Cache ID. + */ + void onCacheStopped(String cacheName, int cacheId) { + assert cacheName != null; + assert cacheId != 0; + + Map caches = new HashMap<>(this.caches); + + Integer rmvd = caches.remove(cacheName); + + assert rmvd != null && rmvd == cacheId : cacheName; + + this.caches = caches; + } + + /** + * @return {@code True} if group contains cache. + */ + boolean hasCaches() { + return caches != null && !caches.isEmpty(); + } + + /** + * @return {@code True} if group can contain multiple caches. + */ + public boolean sharedGroup() { + return grpName != null; + } + + /** + * @return Group name if it is specified, otherwise cache name. + */ + public String cacheOrGroupName() { + return grpName != null ? grpName : cacheCfg.getName(); + } + + /** + * @return Group name or {@code null} if group name was not specified for cache. + */ + @Nullable public String groupName() { + return grpName; + } + + /** + * @return Group ID. + */ + public int groupId() { + return grpId; + } + + /** + * @return Configuration. + */ + public CacheConfiguration config() { + return cacheCfg; + } + + /** + * @return Group caches. + */ + public Map caches() { + return caches; + } + + /** + * @return Topology version when node provided cache configuration was started. + */ + @Nullable AffinityTopologyVersion receivedFromStartVersion() { + return rcvdFromVer; + } + + /** + * @param rcvdFromVer Topology version when node provided cache configuration was started. + */ + void receivedFromStartVersion(AffinityTopologyVersion rcvdFromVer) { + this.rcvdFromVer = rcvdFromVer; + } + + /** + * @return Start version for dynamically started group. + */ + @Nullable public AffinityTopologyVersion startTopologyVersion() { + return startTopVer; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(CacheGroupDescriptor.class, this, "cacheName", cacheCfg.getName()); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java index afc01c943ed4d..58c9d823036fe 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java @@ -111,7 +111,7 @@ static class CacheInfo implements Serializable { private final boolean sql; /** Flags added for future usage. */ - private final byte flags; + private final long flags; /** * @param ccfg Cache configuration. @@ -119,7 +119,7 @@ static class CacheInfo implements Serializable { * @param sql SQL flag - {@code true} if cache was created with {@code CREATE TABLE}. * @param flags Flags (for future usage). */ - CacheInfo(CacheConfiguration ccfg, CacheType cacheType, boolean sql, byte flags) { + CacheInfo(CacheConfiguration ccfg, CacheType cacheType, boolean sql, long flags) { this.ccfg = ccfg; this.cacheType = cacheType; this.sql = sql; 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 2ee8cc459acfa..73973e4a6acfc 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 @@ -218,7 +218,10 @@ public void delegate(CacheMetricsImpl delegate) { /** {@inheritDoc} */ @Override public long getOffHeapPrimaryEntriesCount() { try { - return cctx.offheap().entriesCount(true, false, cctx.affinity().affinityTopologyVersion()); + return cctx.offheap().cacheEntriesCount(cctx.cacheId(), + true, + false, + cctx.affinity().affinityTopologyVersion()); } catch (IgniteCheckedException ignored) { return 0; @@ -228,7 +231,10 @@ public void delegate(CacheMetricsImpl delegate) { /** {@inheritDoc} */ @Override public long getOffHeapBackupEntriesCount() { try { - return cctx.offheap().entriesCount(false, true, cctx.affinity().affinityTopologyVersion()); + return cctx.offheap().cacheEntriesCount(cctx.cacheId(), + false, + true, + cctx.affinity().affinityTopologyVersion()); } catch (IgniteCheckedException ignored) { return 0; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java index 84a33dccb5066..4c70cb90d5d76 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java @@ -38,22 +38,41 @@ class CacheNodeCommonDiscoveryData implements Serializable { @GridToStringInclude private final Map templates; + /** */ + @GridToStringInclude + private final Map cacheGrps; + /** */ private final Map> clientNodesMap; /** * @param caches Started caches. * @param templates Configured templates. + * @param cacheGrps Started cache groups. * @param clientNodesMap Information about cache client nodes. */ CacheNodeCommonDiscoveryData(Map caches, Map templates, + Map cacheGrps, Map> clientNodesMap) { + assert caches != null; + assert templates != null; + assert cacheGrps != null; + assert clientNodesMap != null; + this.caches = caches; this.templates = templates; + this.cacheGrps = cacheGrps; this.clientNodesMap = clientNodesMap; } + /** + * @return Started cache groups. + */ + Map cacheGroups() { + return cacheGrps; + } + /** * @return Started caches. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOffheapEvictionManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOffheapEvictionManager.java index b4047a855a7e2..d737c8bfca328 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOffheapEvictionManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOffheapEvictionManager.java @@ -41,15 +41,10 @@ public class CacheOffheapEvictionManager extends GridCacheManagerAdapter impleme return; try { - if (e.markObsoleteIfEmpty(null) || e.obsolete()) { - e.context().cache().removeEntry(e); + boolean evicted = e.evictInternal(GridCacheVersionManager.EVICT_VER, null, false) + || e.markObsoleteIfEmpty(null); - return; - } - - boolean evicted = cctx.userCache() && e.evictInternal(GridCacheVersionManager.EVICT_VER, null, false); - - if (evicted) + if (evicted && !e.isDht()) // GridDhtCacheEntry removes entry when obsoleted. cctx.cache().removeEntry(e); } catch (IgniteCheckedException ex) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index 7ff5622e0cf59..08c08c7b08003 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -43,8 +43,11 @@ import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteInClosure; +import org.apache.ignite.lang.IgniteUuid; import org.apache.ignite.spi.discovery.DiscoveryDataBag; +import org.jetbrains.annotations.Nullable; import static org.apache.ignite.cache.CacheMode.LOCAL; import static org.apache.ignite.cache.CacheMode.PARTITIONED; @@ -61,6 +64,9 @@ class ClusterCachesInfo { /** Dynamic caches. */ private final ConcurrentMap registeredCaches = new ConcurrentHashMap<>(); + /** */ + private final ConcurrentMap registeredCacheGrps = new ConcurrentHashMap<>(); + /** Cache templates. */ private final ConcurrentMap registeredTemplates = new ConcurrentHashMap<>(); @@ -68,13 +74,13 @@ class ClusterCachesInfo { private final IgniteLogger log; /** */ - private Map cachesOnDisconnect; + private CachesOnDisconnect cachesOnDisconnect; /** */ private CacheJoinNodeDiscoveryData joinDiscoData; /** */ - private CacheNodeCommonDiscoveryData gridData; + private GridData gridData; /** */ private List> locJoinStartCaches; @@ -93,11 +99,40 @@ class ClusterCachesInfo { /** * @param joinDiscoData Information about configured caches and templates. + * @throws IgniteCheckedException If configuration validation failed. */ - void onStart(CacheJoinNodeDiscoveryData joinDiscoData) { + void onStart(CacheJoinNodeDiscoveryData joinDiscoData) throws IgniteCheckedException { this.joinDiscoData = joinDiscoData; - processJoiningNode(joinDiscoData, ctx.localNodeId()); + Map grpCfgs = new HashMap<>(); + + for (CacheJoinNodeDiscoveryData.CacheInfo info : joinDiscoData.caches().values()) { + if (info.config().getGroupName() == null) + continue; + + CacheConfiguration ccfg = grpCfgs.get(info.config().getGroupName()); + + if (ccfg == null) + grpCfgs.put(info.config().getGroupName(), info.config()); + else + validateCacheGroupConfiguration(ccfg, info.config()); + } + + String conflictErr = processJoiningNode(joinDiscoData, ctx.localNodeId(), true); + + if (conflictErr != null) + throw new IgniteCheckedException("Failed to start configured cache. " + conflictErr); + } + + /** + * @param cacheName Cache name. + * @param grpName Group name. + * @return Group ID. + */ + private int cacheGroupId(String cacheName, @Nullable String grpName) { + assert cacheName != null; + + return grpName != null ? CU.cacheId(grpName) : CU.cacheId(cacheName); } /** @@ -105,14 +140,19 @@ void onStart(CacheJoinNodeDiscoveryData joinDiscoData) { * @throws IgniteCheckedException If failed. */ void onKernalStart(boolean checkConsistency) throws IgniteCheckedException { + if (gridData != null && gridData.conflictErr != null) + throw new IgniteCheckedException(gridData.conflictErr); + if (checkConsistency && joinDiscoData != null && gridData != null) { for (CacheJoinNodeDiscoveryData.CacheInfo locCacheInfo : joinDiscoData.caches().values()) { CacheConfiguration locCfg = locCacheInfo.config(); - CacheData cacheData = gridData.caches().get(locCfg.getName()); + CacheData cacheData = gridData.gridData.caches().get(locCfg.getName()); if (cacheData != null) checkCache(locCacheInfo, cacheData, cacheData.receivedFrom()); + + validateStartCacheConfiguration(locCfg); } } @@ -136,6 +176,9 @@ private void checkCache(CacheJoinNodeDiscoveryData.CacheInfo locInfo, CacheData CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "cacheMode", "Cache mode", locAttr.cacheMode(), rmtAttr.cacheMode(), true); + CU.checkAttributeMismatch(log, rmtAttr.groupName(), rmt, "groupName", "Cache group name", + locAttr.groupName(), rmtAttr.groupName(), true); + CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "sql", "SQL flag", locAttr.sql(), rmtAttr.sql(), true); @@ -149,6 +192,9 @@ private void checkCache(CacheJoinNodeDiscoveryData.CacheInfo locInfo, CacheData CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "cachePreloadMode", "Cache preload mode", locAttr.cacheRebalanceMode(), rmtAttr.cacheRebalanceMode(), true); + CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "topologyValidator", + "Cache topology validator", locAttr.topologyValidatorClassName(), rmtAttr.topologyValidatorClassName(), true); + ClusterNode rmtNode = ctx.discovery().node(rmt); if (CU.affinityNode(ctx.discovery().localNode(), locInfo.config().getNodeFilter()) @@ -249,6 +295,7 @@ boolean onCacheChangeRequested(DynamicCacheChangeBatch batch, AffinityTopologyVe DynamicCacheDescriptor templateDesc = new DynamicCacheDescriptor(ctx, ccfg, req.cacheType(), + null, true, req.initiatingNodeId(), false, @@ -276,6 +323,17 @@ boolean onCacheChangeRequested(DynamicCacheChangeBatch batch, AffinityTopologyVe if (req.start()) { if (desc == null) { + String conflictErr = checkCacheConflict(req.startCacheConfiguration()); + + if (conflictErr != null) { + U.warn(log, "Ignore cache start request. " + conflictErr); + + ctx.cache().completeCacheStartFuture(req, false, new IgniteCheckedException("Failed to start " + + "cache. " + conflictErr)); + + continue; + } + if (req.clientStartOnly()) { ctx.cache().completeCacheStartFuture(req, false, new IgniteCheckedException("Failed to start " + "client cache (a cache with the given name is not started): " + req.cacheName())); @@ -286,9 +344,19 @@ boolean onCacheChangeRequested(DynamicCacheChangeBatch batch, AffinityTopologyVe assert req.cacheType() != null : req; assert F.eq(ccfg.getName(), req.cacheName()) : req; + int cacheId = CU.cacheId(req.cacheName()); + + CacheGroupDescriptor grpDesc = registerCacheGroup(exchangeActions, + topVer, + ccfg, + cacheId, + req.initiatingNodeId(), + req.deploymentId()); + DynamicCacheDescriptor startDesc = new DynamicCacheDescriptor(ctx, ccfg, req.cacheType(), + grpDesc, false, req.initiatingNodeId(), false, @@ -301,10 +369,9 @@ boolean onCacheChangeRequested(DynamicCacheChangeBatch batch, AffinityTopologyVe assert old == null; ctx.discovery().setCacheFilter( + grpDesc.groupId(), ccfg.getName(), - ccfg.getNodeFilter(), - ccfg.getNearConfiguration() != null, - ccfg.getCacheMode()); + ccfg.getNearConfiguration() != null); ctx.discovery().addClientNode(req.cacheName(), req.initiatingNodeId(), @@ -380,8 +447,6 @@ else if (req.resetLostPartitions()) { } } else if (req.stop()) { - assert req.stop() ^ req.close() : req; - if (desc != null) { if (req.sql() && !desc.sql()) { ctx.cache().completeCacheStartFuture(req, false, @@ -401,13 +466,27 @@ else if (req.stop()) { DynamicCacheDescriptor old = registeredCaches.remove(req.cacheName()); - assert old != null : "Dynamic cache map was concurrently modified [req=" + req + ']'; + assert old != null && old == desc : "Dynamic cache map was concurrently modified [req=" + req + ']'; ctx.discovery().removeCacheFilter(req.cacheName()); needExchange = true; exchangeActions.addCacheToStop(req, desc); + + CacheGroupDescriptor grpDesc = registeredCacheGrps.get(desc.groupId()); + + assert grpDesc != null && grpDesc.groupId() == desc.groupId() : desc; + + grpDesc.onCacheStopped(desc.cacheName(), desc.cacheId()); + + if (!grpDesc.hasCaches()) { + registeredCacheGrps.remove(grpDesc.groupId()); + + ctx.discovery().removeCacheGroup(grpDesc); + + exchangeActions.addCacheGroupToStop(grpDesc); + } } } else if (req.close()) { @@ -487,10 +566,24 @@ void collectJoiningNodeData(DiscoveryDataBag dataBag) { */ private Serializable joinDiscoveryData() { if (cachesOnDisconnect != null) { + Map cacheGrpsInfo = new HashMap<>(); Map cachesInfo = new HashMap<>(); + Map grps = cachesOnDisconnect.cacheGrps; + Map caches = cachesOnDisconnect.caches; + + for (CacheGroupContext grp : ctx.cache().cacheGroups()) { + CacheGroupDescriptor desc = grps.get(grp.groupId()); + + assert desc != null : grp.cacheOrGroupName(); + + cacheGrpsInfo.put(grp.groupId(), new CacheClientReconnectDiscoveryData.CacheGroupInfo(desc.config(), + desc.deploymentId(), + 0)); + } + for (IgniteInternalCache cache : ctx.cache().caches()) { - DynamicCacheDescriptor desc = cachesOnDisconnect.get(cache.name()); + DynamicCacheDescriptor desc = caches.get(cache.name()); assert desc != null : cache.name(); @@ -498,10 +591,10 @@ private Serializable joinDiscoveryData() { desc.cacheType(), desc.deploymentId(), cache.context().isNear(), - (byte)0)); + 0)); } - return new CacheClientReconnectDiscoveryData(cachesInfo); + return new CacheClientReconnectDiscoveryData(cacheGrpsInfo, cachesInfo); } else { assert ctx.config().isDaemon() || joinDiscoData != null || !ctx.state().active(); @@ -564,6 +657,11 @@ List cachesReceivedFromJoin(UUID joinedNodeId) { */ void onDiscoveryEvent(int type, ClusterNode node, AffinityTopologyVersion topVer) { if (type == EVT_NODE_JOINED && !ctx.isDaemon()) { + for (CacheGroupDescriptor desc : registeredCacheGrps.values()) { + if (node.id().equals(desc.receivedFrom())) + desc.receivedFromStartVersion(topVer); + } + for (DynamicCacheDescriptor desc : registeredCaches.values()) { if (node.id().equals(desc.receivedFrom())) desc.receivedFromStartVersion(topVer); @@ -599,11 +697,27 @@ void collectGridNodeData(DiscoveryDataBag dataBag) { * @return Information about started caches. */ private CacheNodeCommonDiscoveryData collectCommonDiscoveryData() { + Map cacheGrps = new HashMap<>(); + + for (CacheGroupDescriptor grpDesc : registeredCacheGrps.values()) { + CacheGroupData grpData = new CacheGroupData(grpDesc.config(), + grpDesc.groupName(), + grpDesc.groupId(), + grpDesc.receivedFrom(), + grpDesc.startTopologyVersion(), + grpDesc.deploymentId(), + grpDesc.caches(), + 0); + + cacheGrps.put(grpDesc.groupId(), grpData); + } + Map caches = new HashMap<>(); for (DynamicCacheDescriptor desc : registeredCaches.values()) { CacheData cacheData = new CacheData(desc.cacheConfiguration(), desc.cacheId(), + desc.groupId(), desc.cacheType(), desc.deploymentId(), desc.schema(), @@ -611,7 +725,7 @@ private CacheNodeCommonDiscoveryData collectCommonDiscoveryData() { desc.staticallyConfigured(), desc.sql(), false, - (byte)0); + 0); caches.put(desc.cacheName(), cacheData); } @@ -620,6 +734,7 @@ private CacheNodeCommonDiscoveryData collectCommonDiscoveryData() { for (DynamicCacheDescriptor desc : registeredTemplates.values()) { CacheData cacheData = new CacheData(desc.cacheConfiguration(), + 0, 0, desc.cacheType(), desc.deploymentId(), @@ -628,12 +743,15 @@ private CacheNodeCommonDiscoveryData collectCommonDiscoveryData() { desc.staticallyConfigured(), false, true, - (byte)0); + 0); templates.put(desc.cacheName(), cacheData); } - return new CacheNodeCommonDiscoveryData(caches, templates, ctx.discovery().clientNodesMap()); + return new CacheNodeCommonDiscoveryData(caches, + templates, + cacheGrps, + ctx.discovery().clientNodesMap()); } /** @@ -648,11 +766,36 @@ void onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data) { CacheNodeCommonDiscoveryData cachesData = (CacheNodeCommonDiscoveryData)data.commonData(); + // Replace locally registered data with actual data received from cluster. + registeredCaches.clear(); + registeredCacheGrps.clear(); + ctx.discovery().onLocalNodeJoin(); + + for (CacheGroupData grpData : cachesData.cacheGroups().values()) { + CacheGroupDescriptor grpDesc = new CacheGroupDescriptor( + grpData.config(), + grpData.groupName(), + grpData.groupId(), + grpData.receivedFrom(), + grpData.startTopologyVersion(), + grpData.deploymentId(), + grpData.caches()); + + CacheGroupDescriptor old = registeredCacheGrps.put(grpDesc.groupId(), grpDesc); + + assert old == null : old; + + ctx.discovery().addCacheGroup(grpDesc, + grpData.config().getNodeFilter(), + grpData.config().getCacheMode()); + } + for (CacheData cacheData : cachesData.templates().values()) { DynamicCacheDescriptor desc = new DynamicCacheDescriptor( ctx, cacheData.cacheConfiguration(), cacheData.cacheType(), + null, true, cacheData.receivedFrom(), cacheData.staticallyConfigured(), @@ -664,12 +807,17 @@ void onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data) { } for (CacheData cacheData : cachesData.caches().values()) { + CacheGroupDescriptor grpDesc = registeredCacheGrps.get(cacheData.groupId()); + + assert grpDesc != null : cacheData.cacheConfiguration().getName(); + CacheConfiguration cfg = cacheData.cacheConfiguration(); DynamicCacheDescriptor desc = new DynamicCacheDescriptor( ctx, cacheData.cacheConfiguration(), cacheData.cacheType(), + grpDesc, false, cacheData.receivedFrom(), cacheData.staticallyConfigured(), @@ -682,10 +830,9 @@ void onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data) { registeredCaches.put(cacheData.cacheConfiguration().getName(), desc); ctx.discovery().setCacheFilter( + grpDesc.groupId(), cfg.getName(), - cfg.getNodeFilter(), - cfg.getNearConfiguration() != null, - cfg.getCacheMode()); + cfg.getNearConfiguration() != null); } if (!F.isEmpty(cachesData.clientNodesMap())) { @@ -697,7 +844,24 @@ void onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data) { } } - gridData = cachesData; + String conflictErr = null; + + if (joinDiscoData != null) { + for (Map.Entry e : joinDiscoData.caches().entrySet()) { + if (!registeredCaches.containsKey(e.getKey())) { + conflictErr = checkCacheConflict(e.getValue().config()); + + if (conflictErr != null) { + conflictErr = "Failed to start configured cache due to conflict with started caches. " + + conflictErr; + + break; + } + } + } + } + + gridData = new GridData(cachesData, conflictErr); if (!disconnectedState()) initStartCachesForLocalJoin(false); @@ -730,6 +894,7 @@ private void initStartCachesForLocalJoin(boolean firstNode) { DynamicCacheDescriptor desc0 = new DynamicCacheDescriptor(ctx, locCfg.config(), desc.cacheType(), + desc.groupDescriptor(), desc.template(), desc.receivedFrom(), desc.staticallyConfigured(), @@ -744,7 +909,9 @@ private void initStartCachesForLocalJoin(boolean firstNode) { desc = desc0; } - if (locCfg != null || joinDiscoData.startCaches() || CU.affinityNode(ctx.discovery().localNode(), cfg.getNodeFilter())) { + if (locCfg != null || + joinDiscoData.startCaches() || + CU.affinityNode(ctx.discovery().localNode(), desc.groupDescriptor().config().getNodeFilter())) { // Move system and internal caches first. if (desc.cacheType().userCache()) locJoinStartCaches.add(new T2<>(desc, nearCfg)); @@ -773,7 +940,7 @@ void onJoiningNodeDataReceived(DiscoveryDataBag.JoiningNodeDiscoveryData data) { processClientReconnectData((CacheClientReconnectDiscoveryData) joiningNodeData, data.joiningNodeId()); } else if (joiningNodeData instanceof CacheJoinNodeDiscoveryData) - processJoiningNode((CacheJoinNodeDiscoveryData)joiningNodeData, data.joiningNodeId()); + processJoiningNode((CacheJoinNodeDiscoveryData)joiningNodeData, data.joiningNodeId(), false); } } @@ -796,11 +963,60 @@ private void processClientReconnectData(CacheClientReconnectDiscoveryData client } } + /** + * @param cfg Cache configuration. + * @return {@code True} if validation passed. + */ + private String checkCacheConflict(CacheConfiguration cfg) { + int cacheId = CU.cacheId(cfg.getName()); + + if (cacheGroupByName(cfg.getName()) != null) + return "Cache name conflict with existing cache group (change cache name) [cacheName=" + cfg.getName() + ']'; + + if (cfg.getGroupName() != null) { + DynamicCacheDescriptor desc = registeredCaches.get(cfg.getGroupName()); + + if (desc != null) + return "Cache group name conflict with existing cache (change group name) [cacheName=" + cfg.getName() + + ", conflictingCacheName=" + desc.cacheName() + ']'; + } + + for (DynamicCacheDescriptor desc : registeredCaches.values()) { + if (desc.cacheId() == cacheId) + return "Cache ID conflict (change cache name) [cacheName=" + cfg.getName() + + ", conflictingCacheName=" + desc.cacheName() + ']'; + } + + int grpId = cacheGroupId(cfg.getName(), cfg.getGroupName()); + + if (cfg.getGroupName() != null) { + if (cacheGroupByName(cfg.getGroupName()) == null) { + CacheGroupDescriptor desc = registeredCacheGrps.get(grpId); + + if (desc != null) + return "Cache group ID conflict (change cache group name) [cacheName=" + cfg.getName() + + ", groupName=" + cfg.getGroupName() + + (desc.sharedGroup() ? ", conflictingGroupName=" : ", conflictingCacheName=") + desc.cacheOrGroupName() + ']'; + } + } + else { + CacheGroupDescriptor desc = registeredCacheGrps.get(grpId); + + if (desc != null) + return "Cache group ID conflict (change cache name) [cacheName=" + cfg.getName() + + (desc.sharedGroup() ? ", conflictingGroupName=" : ", conflictingCacheName=") + desc.cacheOrGroupName() + ']'; + } + + return null; + } + /** * @param joinData Joined node discovery data. * @param nodeId Joined node ID. + * @param locJoin {@code True} if called on local node join. + * @return Configuration conflict error. */ - private void processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID nodeId) { + private String processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID nodeId, boolean locJoin) { for (CacheJoinNodeDiscoveryData.CacheInfo cacheInfo : joinData.templates().values()) { CacheConfiguration cfg = cacheInfo.config(); @@ -808,6 +1024,7 @@ private void processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID nodeId DynamicCacheDescriptor desc = new DynamicCacheDescriptor(ctx, cfg, cacheInfo.cacheType(), + null, true, nodeId, true, @@ -825,9 +1042,35 @@ private void processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID nodeId CacheConfiguration cfg = cacheInfo.config(); if (!registeredCaches.containsKey(cfg.getName())) { + String conflictErr = checkCacheConflict(cfg); + + if (conflictErr != null) { + if (locJoin) + return conflictErr; + + U.warn(log, "Ignore cache received from joining node. " + conflictErr); + + continue; + } + + int cacheId = CU.cacheId(cfg.getName()); + + CacheGroupDescriptor grpDesc = registerCacheGroup(null, + null, + cfg, + cacheId, + nodeId, + joinData.cacheDeploymentId()); + + ctx.discovery().setCacheFilter( + grpDesc.groupId(), + cfg.getName(), + cfg.getNearConfiguration() != null); + DynamicCacheDescriptor desc = new DynamicCacheDescriptor(ctx, cfg, cacheInfo.cacheType(), + grpDesc, false, nodeId, true, @@ -838,12 +1081,6 @@ private void processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID nodeId DynamicCacheDescriptor old = registeredCaches.put(cfg.getName(), desc); assert old == null : old; - - ctx.discovery().setCacheFilter( - cfg.getName(), - cfg.getNodeFilter(), - cfg.getNearConfiguration() != null, - cfg.getCacheMode()); } ctx.discovery().addClientNode(cfg.getName(), nodeId, cfg.getNearConfiguration() != null); @@ -856,6 +1093,158 @@ private void processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID nodeId desc.cacheConfiguration().getNearConfiguration() != null); } } + + return null; + } + + /** + * @param grpName Group name. + * @return Group descriptor if group found. + */ + @Nullable private CacheGroupDescriptor cacheGroupByName(String grpName) { + assert grpName != null; + + for (CacheGroupDescriptor grpDesc : registeredCacheGrps.values()) { + if (grpName.equals(grpDesc.groupName())) + return grpDesc; + } + + return null; + } + + /** + * @param cacheName Cache name. + * @return Group descriptor. + */ + @Nullable private CacheGroupDescriptor nonSharedCacheGroupByCacheName(String cacheName) { + assert cacheName != null; + + for (CacheGroupDescriptor grpDesc : registeredCacheGrps.values()) { + if (!grpDesc.sharedGroup() && grpDesc.caches().containsKey(cacheName)) + return grpDesc; + } + + return null; + } + + /** + * @param exchActions Optional exchange actions to update if new group was added. + * @param curTopVer Current topology version if dynamic cache started. + * @param startedCacheCfg Cache configuration. + * @param cacheId Cache ID. + * @param rcvdFrom Node ID cache was recived from. + * @param deploymentId Deployment ID. + * @return Group descriptor. + */ + private CacheGroupDescriptor registerCacheGroup( + @Nullable ExchangeActions exchActions, + @Nullable AffinityTopologyVersion curTopVer, + CacheConfiguration startedCacheCfg, + Integer cacheId, + UUID rcvdFrom, + IgniteUuid deploymentId) { + if (startedCacheCfg.getGroupName() != null) { + CacheGroupDescriptor desc = cacheGroupByName(startedCacheCfg.getGroupName()); + + if (desc != null) { + desc.onCacheAdded(startedCacheCfg.getName(), cacheId); + + return desc; + } + } + + int grpId = cacheGroupId(startedCacheCfg.getName(), startedCacheCfg.getGroupName()); + + Map caches = Collections.singletonMap(startedCacheCfg.getName(), cacheId); + + CacheGroupDescriptor grpDesc = new CacheGroupDescriptor( + startedCacheCfg, + startedCacheCfg.getGroupName(), + grpId, + rcvdFrom, + curTopVer != null ? curTopVer.nextMinorVersion() : null, + deploymentId, + caches); + + CacheGroupDescriptor old = registeredCacheGrps.put(grpId, grpDesc); + + assert old == null : old; + + ctx.discovery().addCacheGroup(grpDesc, grpDesc.config().getNodeFilter(), startedCacheCfg.getCacheMode()); + + if (exchActions != null) + exchActions.addCacheGroupToStart(grpDesc); + + return grpDesc; + } + + /** + * @return Registered cache groups. + */ + ConcurrentMap registeredCacheGroups() { + return registeredCacheGrps; + } + + /** + * @param ccfg Cache configuration to start. + * @throws IgniteCheckedException If failed. + */ + void validateStartCacheConfiguration(CacheConfiguration ccfg) throws IgniteCheckedException { + if (ccfg.getGroupName() != null) { + CacheGroupDescriptor grpDesc = cacheGroupByName(ccfg.getGroupName()); + + if (grpDesc != null) { + assert ccfg.getGroupName().equals(grpDesc.groupName()); + + validateCacheGroupConfiguration(grpDesc.config(), ccfg); + } + } + } + + /** + * @param cfg Existing configuration. + * @param startCfg Cache configuration to start. + * @throws IgniteCheckedException If validation failed. + */ + private void validateCacheGroupConfiguration(CacheConfiguration cfg, CacheConfiguration startCfg) + throws IgniteCheckedException { + GridCacheAttributes attr1 = new GridCacheAttributes(cfg, false); + GridCacheAttributes attr2 = new GridCacheAttributes(startCfg, false); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "cacheMode", "Cache mode", + cfg.getCacheMode(), startCfg.getCacheMode(), true); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "affinity", "Affinity function", + attr1.cacheAffinityClassName(), attr2.cacheAffinityClassName(), true); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "affinityPartitionsCount", + "Affinity partitions count", attr1.affinityPartitionsCount(), attr2.affinityPartitionsCount(), true); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "nodeFilter", "Node filter", + attr1.nodeFilterClassName(), attr2.nodeFilterClassName(), true); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "memoryPolicyName", "Memory policy", + cfg.getMemoryPolicyName(), startCfg.getMemoryPolicyName(), true); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "topologyValidator", "Topology validator", + attr1.topologyValidatorClassName(), attr2.topologyValidatorClassName(), true); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "partitionLossPolicy", "Partition Loss Policy", + cfg.getPartitionLossPolicy(), startCfg.getPartitionLossPolicy(), true); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "rebalanceMode", "Rebalance mode", + cfg.getRebalanceMode(), startCfg.getRebalanceMode(), true); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "rebalanceDelay", "Rebalance delay", + cfg.getRebalanceDelay(), startCfg.getRebalanceDelay(), false); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "rebalanceOrder", "Rebalance order", + cfg.getRebalanceOrder(), startCfg.getRebalanceOrder(), false); + + if (cfg.getCacheMode() == PARTITIONED) { + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "backups", "Backups", + cfg.getBackups(), startCfg.getBackups(), true); + } } /** @@ -876,8 +1265,11 @@ ConcurrentMap registeredTemplates() { * */ void onDisconnect() { - cachesOnDisconnect = new HashMap<>(registeredCaches); + cachesOnDisconnect = new CachesOnDisconnect( + new HashMap<>(registeredCacheGrps), + new HashMap<>(registeredCaches)); + registeredCacheGrps.clear(); registeredCaches.clear(); registeredTemplates.clear(); @@ -885,14 +1277,41 @@ void onDisconnect() { } /** - * @return Stopped caches names. + * @return Information about stopped caches and cache groups. */ - Set onReconnected() { + ClusterCachesReconnectResult onReconnected() { assert disconnectedState(); Set stoppedCaches = new HashSet<>(); + Set stoppedCacheGrps = new HashSet<>(); + + for (Map.Entry e : cachesOnDisconnect.cacheGrps.entrySet()) { + CacheGroupDescriptor locDesc = e.getValue(); + + CacheGroupDescriptor desc; + boolean stopped = true; - for(Map.Entry e : cachesOnDisconnect.entrySet()) { + if (locDesc.sharedGroup()) { + desc = cacheGroupByName(locDesc.groupName()); + + if (desc != null && desc.deploymentId().equals(locDesc.deploymentId())) + stopped = false; + } + else { + desc = nonSharedCacheGroupByCacheName(locDesc.config().getName()); + + if (desc != null && + (surviveReconnect(locDesc.config().getName()) || desc.deploymentId().equals(locDesc.deploymentId()))) + stopped = false; + } + + if (stopped) + stoppedCacheGrps.add(locDesc.groupId()); + else + assert locDesc.groupId() == desc.groupId(); + } + + for (Map.Entry e : cachesOnDisconnect.caches.entrySet()) { DynamicCacheDescriptor desc = e.getValue(); String cacheName = e.getKey(); @@ -920,7 +1339,7 @@ Set onReconnected() { cachesOnDisconnect = null; - return stoppedCaches; + return new ClusterCachesReconnectResult(stoppedCacheGrps, stoppedCaches); } /** @@ -942,6 +1361,48 @@ private boolean surviveReconnect(String cacheName) { * */ void clearCaches() { + registeredCacheGrps.clear(); + registeredCaches.clear(); } + + /** + * + */ + static class GridData { + /** */ + private final CacheNodeCommonDiscoveryData gridData; + + /** */ + private final String conflictErr; + + /** + * @param gridData Grid data. + * @param conflictErr Cache configuration conflict error. + */ + GridData(CacheNodeCommonDiscoveryData gridData, String conflictErr) { + this.gridData = gridData; + this.conflictErr = conflictErr; + } + } + + /** + * + */ + private static class CachesOnDisconnect { + /** */ + final Map cacheGrps; + + /** */ + final Map caches; + + /** + * @param cacheGrps Cache groups. + * @param caches Caches. + */ + CachesOnDisconnect(Map cacheGrps, Map caches) { + this.cacheGrps = cacheGrps; + this.caches = caches; + } + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesReconnectResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesReconnectResult.java new file mode 100644 index 0000000000000..23854c3359d99 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesReconnectResult.java @@ -0,0 +1,61 @@ +/* + * 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 java.util.Set; +import org.apache.ignite.internal.util.typedef.internal.S; + +/** + * + */ +class ClusterCachesReconnectResult { + /** */ + private final Set stoppedCacheGrps; + + /** */ + private final Set stoppedCaches; + + /** + * @param stoppedCacheGrps Stopped cache groups. + * @param stoppedCaches Stopped caches. + */ + ClusterCachesReconnectResult(Set stoppedCacheGrps, + Set stoppedCaches) { + this.stoppedCacheGrps = stoppedCacheGrps; + this.stoppedCaches = stoppedCaches; + } + + /** + * @return Stopped cache groups. + */ + Set stoppedCacheGroups() { + return stoppedCacheGrps; + } + + /** + * @return Stopped caches. + */ + Set stoppedCaches() { + return stoppedCaches; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(ClusterCachesReconnectResult.class, this); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java index a682f635a9767..315013de7e103 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java @@ -93,10 +93,14 @@ public class DynamicCacheDescriptor { /** Current schema. */ private QuerySchema schema; + /** */ + private final CacheGroupDescriptor grpDesc; + /** * @param ctx Context. * @param cacheCfg Cache configuration. * @param cacheType Cache type. + * @param grpDesc Group descriptor. * @param template {@code True} if this is template configuration. * @param rcvdFrom ID of node provided cache configuration * @param staticCfg {@code True} if cache statically configured. @@ -108,6 +112,7 @@ public class DynamicCacheDescriptor { public DynamicCacheDescriptor(GridKernalContext ctx, CacheConfiguration cacheCfg, CacheType cacheType, + CacheGroupDescriptor grpDesc, boolean template, UUID rcvdFrom, boolean staticCfg, @@ -115,6 +120,7 @@ public DynamicCacheDescriptor(GridKernalContext ctx, IgniteUuid deploymentId, QuerySchema schema) { assert cacheCfg != null; + assert grpDesc != null || template; assert schema != null; if (cacheCfg.getCacheMode() == CacheMode.REPLICATED && cacheCfg.getNearConfiguration() != null) { @@ -125,6 +131,7 @@ public DynamicCacheDescriptor(GridKernalContext ctx, this.cacheCfg = cacheCfg; this.cacheType = cacheType; + this.grpDesc = grpDesc; this.template = template; this.rcvdFrom = rcvdFrom; this.staticCfg = staticCfg; @@ -140,6 +147,24 @@ public DynamicCacheDescriptor(GridKernalContext ctx, } } + /** + * @return Cache group ID. + */ + public int groupId() { + assert grpDesc != null : this; + + return grpDesc.groupId(); + } + + /** + * @return Cache group descriptor. + */ + public CacheGroupDescriptor groupDescriptor() { + assert grpDesc != null : this; + + return grpDesc; + } + /** * @return Cache ID. */ @@ -203,6 +228,7 @@ public CacheConfiguration cacheConfiguration() { * * @param proc Object processor. * @return Cache object context. + * @throws IgniteCheckedException If failed. */ public CacheObjectContext cacheObjectContext(IgniteCacheObjectProcessor proc) throws IgniteCheckedException { if (objCtx == null) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java index dc22669ae85b3..8282b0c661bc4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java @@ -33,6 +33,12 @@ * Cache change requests to execute when receive {@link DynamicCacheChangeBatch} event. */ public class ExchangeActions { + /** */ + private List cacheGrpsToStart; + + /** */ + private List cacheGrpsToStop; + /** */ private Map cachesToStart; @@ -57,6 +63,8 @@ public class ExchangeActions { boolean clientOnlyExchange() { return F.isEmpty(cachesToStart) && F.isEmpty(cachesToStop) && + F.isEmpty(cacheGrpsToStart) && + F.isEmpty(cacheGrpsToStop) && F.isEmpty(cachesToResetLostParts); } @@ -64,8 +72,8 @@ boolean clientOnlyExchange() { * @param nodeId Local node ID. * @return Close cache requests. */ - List closeRequests(UUID nodeId) { - List res = null; + List closeRequests(UUID nodeId) { + List res = null; if (cachesToClose != null) { for (ActionData req : cachesToClose.values()) { @@ -73,12 +81,12 @@ List closeRequests(UUID nodeId) { if (res == null) res = new ArrayList<>(cachesToClose.size()); - res.add(req.req); + res.add(req); } } } - return res != null ? res : Collections.emptyList(); + return res != null ? res : Collections.emptyList(); } /** @@ -288,6 +296,74 @@ void addCacheToResetLostPartitions(DynamicCacheChangeRequest req, DynamicCacheDe cachesToResetLostParts = add(cachesToResetLostParts, req, desc); } + /** + * @param grpDesc Group descriptor. + */ + void addCacheGroupToStart(CacheGroupDescriptor grpDesc) { + assert grpDesc != null; + + if (cacheGrpsToStart == null) + cacheGrpsToStart = new ArrayList<>(); + + cacheGrpsToStart.add(grpDesc); + } + + /** + * @return Cache groups to start. + */ + public List cacheGroupsToStart() { + return cacheGrpsToStart != null ? cacheGrpsToStart : Collections.emptyList(); + } + + /** + * @param grpId Group ID. + * @return {@code True} if given cache group starting. + */ + public boolean cacheGroupStarting(int grpId) { + if (cacheGrpsToStart != null) { + for (CacheGroupDescriptor grp : cacheGrpsToStart) { + if (grp.groupId() == grpId) + return true; + } + } + + return false; + } + + /** + * @param grpDesc Group descriptor. + */ + public void addCacheGroupToStop(CacheGroupDescriptor grpDesc) { + assert grpDesc != null; + + if (cacheGrpsToStop == null) + cacheGrpsToStop = new ArrayList<>(); + + cacheGrpsToStop.add(grpDesc); + } + + /** + * @return Cache groups to start. + */ + public List cacheGroupsToStop() { + return cacheGrpsToStop != null ? cacheGrpsToStop : Collections.emptyList(); + } + + /** + * @param grpId Group ID. + * @return {@code True} if given cache group stopping. + */ + public boolean cacheGroupStopping(int grpId) { + if (cacheGrpsToStop != null) { + for (CacheGroupDescriptor grp : cacheGrpsToStop) { + if (grp.groupId() == grpId) + return true; + } + } + + return false; + } + /** * @return {@code True} if there are no cache change actions. */ @@ -296,6 +372,8 @@ public boolean empty() { F.isEmpty(clientCachesToStart) && F.isEmpty(cachesToStop) && F.isEmpty(cachesToClose) && + F.isEmpty(cacheGrpsToStart) && + F.isEmpty(cacheGrpsToStop) && F.isEmpty(cachesToResetLostParts); } 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 a84d093c30a0e..2ee6c336de2cf 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 @@ -303,15 +303,6 @@ protected GridCacheAdapter() { */ @SuppressWarnings("OverriddenMethodCallDuringObjectConstruction") protected GridCacheAdapter(GridCacheContext ctx) { - this(ctx, DFLT_START_CACHE_SIZE); - } - - /** - * @param ctx Cache context. - * @param startSize Start size. - */ - @SuppressWarnings("OverriddenMethodCallDuringObjectConstruction") - protected GridCacheAdapter(GridCacheContext ctx, int startSize) { this(ctx, null); } @@ -390,7 +381,7 @@ public GridCacheConcurrentMap map() { * @param e Map entry. */ public void incrementSize(GridCacheMapEntry e) { - map.incrementPublicSize(e); + map.incrementPublicSize(null, e); } /** @@ -398,7 +389,7 @@ public void incrementSize(GridCacheMapEntry e) { * @param e Map entry. */ public void decrementSize(GridCacheMapEntry e) { - map.decrementPublicSize(e); + map.decrementPublicSize(null, e); } /** @@ -549,22 +540,13 @@ protected void init() { // No-op. } - /** - * @return Entry factory. - */ - protected abstract GridCacheMapEntryFactory entryFactory(); - /** * Starts this cache. Child classes should override this method * to provide custom start-up behavior. * * @throws IgniteCheckedException If start failed. */ - public void start() throws IgniteCheckedException { - if (map == null) { - map = new GridCacheLocalConcurrentMap(ctx, entryFactory(), DFLT_START_CACHE_SIZE); - } - } + public abstract void start() throws IgniteCheckedException; /** * Startup info. @@ -718,7 +700,7 @@ public void onKernalStop() { IgniteCacheOffheapManager offheapMgr = ctx.isNear() ? ctx.near().dht().context().offheap() : ctx.offheap(); - its.add(offheapMgr.entriesIterator(modes.primary, modes.backup, topVer, ctx.keepBinary())); + its.add(offheapMgr.cacheEntriesIterator(ctx, modes.primary, modes.backup, topVer, ctx.keepBinary())); } } else if (modes.heap) { @@ -945,7 +927,7 @@ public final GridCacheEntryEx entryEx(KeyCacheObject key) { * @return Entry (never {@code null}). */ public GridCacheEntryEx entryEx(KeyCacheObject key, AffinityTopologyVersion topVer) { - GridCacheEntryEx e = map.putEntryIfObsoleteOrAbsent(topVer, key, true, false); + GridCacheEntryEx e = map.putEntryIfObsoleteOrAbsent(ctx, topVer, key, true, false); assert e != null; @@ -961,10 +943,11 @@ public GridCacheEntryEx entryEx(KeyCacheObject key, AffinityTopologyVersion topV */ @Nullable private GridCacheEntryEx entry0(KeyCacheObject key, AffinityTopologyVersion topVer, boolean create, boolean touch) { - GridCacheMapEntry cur = map.getEntry(key); + GridCacheMapEntry cur = map.getEntry(ctx, key); if (cur == null || cur.obsolete()) { cur = map.putEntryIfObsoleteOrAbsent( + ctx, topVer, key, create, touch); @@ -984,7 +967,7 @@ public final Iterable entries() { * @return Set of internal cached entry representations. */ public final Iterable allEntries() { - return map.entries(); + return map.entries(ctx.cacheId()); } /** {@inheritDoc} */ @@ -994,7 +977,7 @@ public final Iterable allEntries() { /** {@inheritDoc} */ @Override public final Set keySet() { - return new KeySet(map.entrySet()); + return new KeySet(map.entrySet(ctx.cacheId())); } /** @@ -1004,7 +987,7 @@ public final Iterable allEntries() { public final void removeIfObsolete(KeyCacheObject key) { assert key != null; - GridCacheMapEntry entry = map.getEntry(key); + GridCacheMapEntry entry = map.getEntry(ctx, key); if (entry != null && entry.obsolete()) removeEntry(entry); @@ -1913,7 +1896,7 @@ protected final IgniteInternalFuture> getAllAsync0( boolean skipEntry = readNoEntry; if (readNoEntry) { - CacheDataRow row = ctx.offheap().read(key); + CacheDataRow row = ctx.offheap().read(ctx, key); if (row != null) { long expireTime = row.expireTime(); @@ -2908,7 +2891,7 @@ protected IgniteInternalFuture getAndRemoveAsync0(final K key) { List keys = new ArrayList<>(Math.min(REMOVE_ALL_KEYS_BATCH, size())); do { - for (Iterator it = ctx.offheap().iterator(true, true, null); + for (Iterator it = ctx.offheap().cacheIterator(ctx.cacheId(), true, true, null); it.hasNext() && keys.size() < REMOVE_ALL_KEYS_BATCH; ) keys.add((K)it.next().key()); @@ -3711,7 +3694,8 @@ IgniteInternalFuture globalLoadCacheAsync(@Nullable IgniteBiPredicate p try { return ctx.kernalContext().task().execute( new SizeTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), peekModes), null); - } catch (ClusterGroupEmptyException e) { + } + catch (ClusterGroupEmptyException e) { return new GridFinishedFuture<>(0); } } @@ -3773,12 +3757,12 @@ IgniteInternalFuture globalLoadCacheAsync(@Nullable IgniteBiPredicate p /** {@inheritDoc} */ @Override public int size() { - return map.publicSize(); + return map.publicSize(ctx.cacheId()); } /** {@inheritDoc} */ @Override public long sizeLong() { - return map.publicSize(); + return map.publicSize(ctx.cacheId()); } /** {@inheritDoc} */ @@ -3788,12 +3772,12 @@ IgniteInternalFuture globalLoadCacheAsync(@Nullable IgniteBiPredicate p /** {@inheritDoc} */ @Override public int primarySize() { - return map.publicSize(); + return map.publicSize(ctx.cacheId()); } /** {@inheritDoc} */ @Override public long primarySizeLong() { - return map.publicSize(); + return map.publicSize(ctx.cacheId()); } /** {@inheritDoc} */ @@ -3910,7 +3894,10 @@ private Iterator> igniteIterator(boolean keepBinary, try { IgniteCacheOffheapManager mgr = ctx.offheap(); - return mgr != null ? mgr.entriesCount(false, true, ctx.affinity().affinityTopologyVersion()) : -1; + return mgr != null ? mgr.cacheEntriesCount(ctx.cacheId(), + false, + true, + ctx.affinity().affinityTopologyVersion()) : -1; } catch (IgniteCheckedException ignore) { return 0; @@ -4432,7 +4419,7 @@ private boolean clearLocally0(K key, boolean readers) { public Set> entrySet(@Nullable CacheEntryPredicate... filter) { boolean keepBinary = ctx.keepBinary(); - return new EntrySet(map.entrySet(filter), keepBinary); + return new EntrySet(map.entrySet(ctx.cacheId(), filter), keepBinary); } /** @@ -6504,7 +6491,7 @@ private KeySet(Set internalSet) { /** {@inheritDoc} */ @Override public boolean contains(Object o) { - GridCacheMapEntry entry = map.getEntry(ctx.toCacheKeyObject(o)); + GridCacheMapEntry entry = map.getEntry(ctx, ctx.toCacheKeyObject(o)); return entry != null && internalSet.contains(entry); } @@ -6594,7 +6581,7 @@ private EntrySet(Set internalSet, boolean keepBinary) { /** {@inheritDoc} */ @Override public boolean contains(Object o) { - GridCacheMapEntry entry = map.getEntry(ctx.toCacheKeyObject(o)); + GridCacheMapEntry entry = map.getEntry(ctx, ctx.toCacheKeyObject(o)); return entry != null && internalSet.contains(entry); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java index 2bb6f6c8adfe4..702b848130d10 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java @@ -28,14 +28,12 @@ import org.apache.ignite.cache.affinity.AffinityFunction; import org.apache.ignite.cache.affinity.AffinityKeyMapper; import org.apache.ignite.cluster.ClusterNode; -import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.processors.affinity.AffinityAssignment; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.lang.IgniteFuture; import org.jetbrains.annotations.Nullable; /** @@ -63,12 +61,7 @@ public class GridCacheAffinityManager extends GridCacheManagerAdapter { affFunction = cctx.config().getAffinity(); affMapper = cctx.config().getAffinityMapper(); - aff = new GridAffinityAssignmentCache(cctx.kernalContext(), - cctx.name(), - affFunction, - cctx.config().getNodeFilter(), - cctx.config().getBackups(), - cctx.isLocal()); + aff = cctx.group().affinity(); } /** {@inheritDoc} */ @@ -78,42 +71,6 @@ public class GridCacheAffinityManager extends GridCacheManagerAdapter { aff.calculate(LOC_CACHE_TOP_VER, null, null); } - /** {@inheritDoc} */ - @Override protected void onKernalStop0(boolean cancel) { - cancelFutures(); - } - - /** - * - */ - public void cancelFutures() { - if (!starting.get()) - // Ignoring attempt to stop manager that has never been started. - return; - - IgniteCheckedException err = - new IgniteCheckedException("Failed to wait for topology update, cache (or node) is stopping."); - - if (aff != null) - aff.cancelFutures(err); - } - - /** {@inheritDoc} */ - @Override public void onDisconnected(IgniteFuture reconnectFut) { - IgniteCheckedException err = new IgniteClientDisconnectedCheckedException(reconnectFut, - "Failed to wait for topology update, client disconnected."); - - if (aff != null) - aff.cancelFutures(err); - } - - /** - * - */ - public void onReconnected() { - aff.onReconnected(); - } - /** {@inheritDoc} */ @Override protected void stop0(boolean cancel, boolean destroy) { aff = null; @@ -442,23 +399,6 @@ public AffinityTopologyVersion affinityTopologyVersion() { return aff0.lastVersion(); } - /** - * Dumps debug information. - */ - public void dumpDebugInfo() { - GridAffinityAssignmentCache aff0 = aff; - - if (aff0 != null) - aff0.dumpDebugInfo(); - } - - /** - * @return Affinity cache. - */ - public GridAffinityAssignmentCache affinityCache() { - return aff; - } - /** * @param part Partition. * @param startVer Start version. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java index 4af2518724a4a..7d971599d6fcc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java @@ -52,6 +52,7 @@ public class GridCacheAttributes implements Serializable { /** * @param cfg Cache configuration. + * @param sql SQL flag. */ public GridCacheAttributes(CacheConfiguration cfg, boolean sql) { ccfg = cfg; @@ -60,10 +61,10 @@ public GridCacheAttributes(CacheConfiguration cfg, boolean sql) { } /** - * Public no-arg constructor for {@link Externalizable}. + * @return Cache group name. */ - public GridCacheAttributes() { - // No-op. + public String groupName() { + return ccfg.getGroupName(); } /** @@ -277,6 +278,20 @@ public String interceptorClassName() { return className(ccfg.getInterceptor()); } + /** + * @return Node filter class name. + */ + String nodeFilterClassName() { + return className(ccfg.getNodeFilter()); + } + + /** + * @return Topology validator class name. + */ + String topologyValidatorClassName() { + return className(ccfg.getTopologyValidator()); + } + /** * @return SQL flag. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java index df1922502fd46..d37cecb5d48d3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java @@ -82,7 +82,7 @@ public GridCacheClearAllRunnable(GridCacheAdapter cache, GridCacheVersion if (!ctx.isNear()) { if (id == 0) - ctx.offheap().clear(readers); + ctx.offheap().clearCache(ctx, readers); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java index 9f20d64ef164d..282faafb9781a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java @@ -18,7 +18,10 @@ package org.apache.ignite.internal.processors.cache; import java.util.Set; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.util.typedef.internal.S; import org.jetbrains.annotations.Nullable; /** @@ -27,15 +30,17 @@ public interface GridCacheConcurrentMap { /** * Returns the entry associated with the specified key in the - * HashMap. Returns null if the HashMap contains no mapping + * HashMap. Returns null if the HashMap contains no mapping * for this key. * + * @param ctx Cache context. * @param key Key. * @return Entry. */ - @Nullable public GridCacheMapEntry getEntry(KeyCacheObject key); + @Nullable public GridCacheMapEntry getEntry(GridCacheContext ctx, KeyCacheObject key); /** + * @param ctx Cache context. * @param topVer Topology version. * @param key Key. * @param create Create flag. @@ -44,6 +49,7 @@ public interface GridCacheConcurrentMap { * couldn't be created. */ @Nullable public GridCacheMapEntry putEntryIfObsoleteOrAbsent( + GridCacheContext ctx, AffinityTopologyVersion topVer, KeyCacheObject key, boolean create, @@ -70,39 +76,66 @@ public interface GridCacheConcurrentMap { * It excludes entries that are marked as deleted. * It also does not include entries from underlying data store. * + * @param cacheId Cache ID. * @return the number of publicly available key-value mappings in this map. */ - public int publicSize(); + public int publicSize(int cacheId); /** * Increments public size. * * @param e Entry that caused public size change. + * @param hld Cache map (passed as optimization to avoid cache map lookup for shared groups). */ - public void incrementPublicSize(GridCacheEntryEx e); + public void incrementPublicSize(@Nullable CacheMapHolder hld, GridCacheEntryEx e); /** * Decrements public size. * * @param e Entry that caused public size change. + * @param hld Cache map (passed as optimization to avoid cache map lookup for shared groups). */ - public void decrementPublicSize(GridCacheEntryEx e); + public void decrementPublicSize(@Nullable CacheMapHolder hld, GridCacheEntryEx e); /** + * @param cacheId Cache ID. * @param filter Filter. * @return Iterable of the mappings contained in this map, excluding entries in unvisitable state. */ - public Iterable entries(CacheEntryPredicate... filter); + public Iterable entries(int cacheId, CacheEntryPredicate... filter); /** + * @param cacheId Cache ID. * @param filter Filter. - * @return Iterable of the mappings contained in this map, including entries in unvisitable state. + * @return Set of the mappings contained in this map. */ - public Iterable allEntries(CacheEntryPredicate... filter); + public Set entrySet(int cacheId, CacheEntryPredicate... filter); /** - * @param filter Filter. - * @return Set of the mappings contained in this map. + * */ - public Set entrySet(CacheEntryPredicate... filter); + static class CacheMapHolder { + /** */ + public final GridCacheContext cctx; + + /** */ + public final AtomicInteger size = new AtomicInteger(); + + /** */ + public final ConcurrentMap map; + + /** + * @param cctx Cache context. + * @param map Map. + */ + public CacheMapHolder(GridCacheContext cctx, ConcurrentMap map) { + this.cctx = cctx; + this.map = map; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(CacheMapHolder.class, this); + } + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java index b02a2b7b66bf4..37f2a51fa7d61 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java @@ -20,15 +20,14 @@ import java.util.AbstractSet; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.Set; -import java.util.concurrent.ConcurrentMap; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.lang.IgnitePredicate; import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; -import org.jsr166.ConcurrentHashMap8; import static org.apache.ignite.events.EventType.EVT_CACHE_ENTRY_CREATED; import static org.apache.ignite.events.EventType.EVT_CACHE_ENTRY_DESTROYED; @@ -37,78 +36,49 @@ * Implementation of concurrent cache map. */ public abstract class GridCacheConcurrentMapImpl implements GridCacheConcurrentMap { - /** Default load factor. */ - private static final float DFLT_LOAD_FACTOR = 0.75f; - - /** Default concurrency level. */ - private static final int DFLT_CONCUR_LEVEL = Runtime.getRuntime().availableProcessors() * 2; - - /** Internal map. */ - private final ConcurrentMap map; - /** Map entry factory. */ private final GridCacheMapEntryFactory factory; - /** Cache context. */ - private final GridCacheContext ctx; - /** * Creates a new, empty map with the specified initial * capacity. * - * @param ctx Cache context. * @param factory Entry factory. - * @param initialCapacity the initial capacity. The implementation - * performs internal sizing to accommodate this many elements. * @throws IllegalArgumentException if the initial capacity is * negative. */ - public GridCacheConcurrentMapImpl(GridCacheContext ctx, GridCacheMapEntryFactory factory, int initialCapacity) { - this(ctx, factory, initialCapacity, DFLT_LOAD_FACTOR, DFLT_CONCUR_LEVEL); + public GridCacheConcurrentMapImpl(GridCacheMapEntryFactory factory) { + this.factory = factory; } - /** - * Creates a new, empty map with the specified initial - * capacity, load factor and concurrency level. - * - * @param ctx Cache context. - * @param factory Entry factory. - * @param initialCapacity the initial capacity. The implementation - * performs internal sizing to accommodate this many elements. - * @param loadFactor the load factor threshold, used to control resizing. - * Resizing may be performed when the average number of elements per - * bin exceeds this threshold. - * @param concurrencyLevel the estimated number of concurrently - * updating threads. The implementation performs internal sizing - * to try to accommodate this many threads. - * @throws IllegalArgumentException if the initial capacity is - * negative or the load factor or concurrencyLevel are - * non-positive. - */ - public GridCacheConcurrentMapImpl( - GridCacheContext ctx, - GridCacheMapEntryFactory factory, - int initialCapacity, - float loadFactor, - int concurrencyLevel - ) { - this.ctx = ctx; - this.factory = factory; + /** {@inheritDoc} */ + @Nullable @Override public GridCacheMapEntry getEntry(GridCacheContext ctx, KeyCacheObject key) { + CacheMapHolder hld = entriesMapIfExists(ctx.cacheIdBoxed()); - map = new ConcurrentHashMap8<>(initialCapacity, loadFactor, concurrencyLevel); + return hld != null ? hld.map.get(key) : null; } /** {@inheritDoc} */ - @Nullable @Override public GridCacheMapEntry getEntry(KeyCacheObject key) { - return map.get(key); + @Nullable @Override public GridCacheMapEntry putEntryIfObsoleteOrAbsent( + GridCacheContext ctx, + final AffinityTopologyVersion topVer, + KeyCacheObject key, + final boolean create, + final boolean touch) { + return putEntryIfObsoleteOrAbsent(null, ctx, topVer, key, create, touch); } - /** {@inheritDoc} */ - @Nullable @Override public GridCacheMapEntry putEntryIfObsoleteOrAbsent(final AffinityTopologyVersion topVer, + protected final GridCacheMapEntry putEntryIfObsoleteOrAbsent( + @Nullable CacheMapHolder hld, + GridCacheContext ctx, + final AffinityTopologyVersion topVer, KeyCacheObject key, final boolean create, final boolean touch) { + if (hld == null) + hld = entriesMapIfExists(ctx.cacheIdBoxed()); + GridCacheMapEntry cur = null; GridCacheMapEntry created = null; GridCacheMapEntry created0 = null; @@ -120,7 +90,7 @@ public GridCacheConcurrentMapImpl( try { while (!done) { - GridCacheMapEntry entry = map.get(key); + GridCacheMapEntry entry = hld != null ? hld.map.get(key) : null; created = null; doomed = null; @@ -134,12 +104,18 @@ public GridCacheConcurrentMapImpl( reserved = true; } + if (hld == null) { + hld = entriesMap(ctx); + + assert hld != null; + } + created0 = factory.create(ctx, topVer, key); } cur = created = created0; - done = map.putIfAbsent(created.key(), created) == null; + done = hld.map.putIfAbsent(created.key(), created) == null; } else done = true; @@ -162,10 +138,10 @@ public GridCacheConcurrentMapImpl( cur = created = created0; - done = map.replace(entry.key(), doomed, created); + done = hld.map.replace(entry.key(), doomed, created); } else - done = map.remove(entry.key(), doomed); + done = hld.map.remove(entry.key(), doomed); } else { cur = entry; @@ -231,17 +207,30 @@ public GridCacheConcurrentMapImpl( } finally { if (reserved) - release(sizeChange, cur); + release(sizeChange, hld, cur); else { if (sizeChange != 0) { assert sizeChange == -1; + assert doomed != null; - decrementPublicSize(cur); + decrementPublicSize(hld, doomed); } } } } + /** + * @param cctx Cache context. + * @return Map for given cache ID. + */ + @Nullable protected abstract CacheMapHolder entriesMap(GridCacheContext cctx); + + /** + * @param cacheId Cache ID. + * @return Map for given cache ID. + */ + @Nullable protected abstract CacheMapHolder entriesMapIfExists(Integer cacheId); + /** * */ @@ -258,63 +247,75 @@ protected void release() { /** * @param sizeChange Size delta. + * @param hld Map holder. * @param e Map entry. */ - protected void release(int sizeChange, GridCacheEntryEx e) { + protected void release(int sizeChange, CacheMapHolder hld, GridCacheEntryEx e) { if (sizeChange == 1) - incrementPublicSize(e); + incrementPublicSize(hld, e); else if (sizeChange == -1) - decrementPublicSize(e); + decrementPublicSize(hld, e); } /** {@inheritDoc} */ @Override public boolean removeEntry(final GridCacheEntryEx entry) { - boolean removed = map.remove(entry.key(), entry); + GridCacheContext ctx = entry.context(); + + CacheMapHolder hld = entriesMapIfExists(ctx.cacheIdBoxed()); + + boolean rmv = hld != null && hld.map.remove(entry.key(), entry); - if (removed) { - if (ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED)) + if (rmv) { + if (ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED)) { // Event notification. - ctx.events().addEvent(entry.partition(), entry.key(), ctx.localNodeId(), (IgniteUuid)null, null, - EVT_CACHE_ENTRY_DESTROYED, null, false, null, false, null, null, null, false); + ctx.events().addEvent(entry.partition(), + entry.key(), + ctx.localNodeId(), + (IgniteUuid)null, + null, + EVT_CACHE_ENTRY_DESTROYED, + null, + false, + null, + false, + null, + null, + null, + false); + } synchronized (entry) { if (!entry.deleted()) - decrementPublicSize(entry); + decrementPublicSize(hld, entry); } } - return removed; + return rmv; } /** {@inheritDoc} */ - @Override public int internalSize() { - return map.size(); - } + @Override public Collection entries(int cacheId, final CacheEntryPredicate... filter) { + CacheMapHolder hld = entriesMapIfExists(cacheId); + + if (hld == null) + return Collections.emptyList(); - /** {@inheritDoc} */ - @Override public Collection entries(final CacheEntryPredicate... filter) { final IgnitePredicate p = new IgnitePredicate() { @Override public boolean apply(GridCacheMapEntry entry) { return entry.visitable(filter); } }; - return F.viewReadOnly(map.values(), F.identity(), p); + return F.viewReadOnly(hld.map.values(), F.identity(), p); } /** {@inheritDoc} */ - @Override public Collection allEntries(final CacheEntryPredicate... filter) { - final IgnitePredicate p = new IgnitePredicate() { - @Override public boolean apply(GridCacheMapEntry entry) { - return F.isAll(entry, filter); - } - }; + @Override public Set entrySet(int cacheId, final CacheEntryPredicate... filter) { + final CacheMapHolder hld = entriesMapIfExists(cacheId); - return F.viewReadOnly(map.values(), F.identity(), p); - } + if (hld == null) + return Collections.emptySet(); - /** {@inheritDoc} */ - @Override public Set entrySet(final CacheEntryPredicate... filter) { final IgnitePredicate p = new IgnitePredicate() { @Override public boolean apply(GridCacheMapEntry entry) { return entry.visitable(filter); @@ -323,7 +324,7 @@ else if (sizeChange == -1) return new AbstractSet() { @Override public Iterator iterator() { - return F.iterator0(map.values(), true, p); + return F.iterator0(hld.map.values(), true, p); } @Override public int size() { @@ -336,7 +337,7 @@ else if (sizeChange == -1) GridCacheMapEntry entry = (GridCacheMapEntry)o; - return entry.equals(map.get(entry.key())) && p.apply(entry); + return entry.equals(hld.map.get(entry.key())) && p.apply(entry); } }; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java index 190e9521fa2df..44cf4e056104e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java @@ -45,6 +45,7 @@ import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.events.EventType; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteKernal; @@ -56,8 +57,6 @@ import org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.database.MemoryPolicy; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeList; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; @@ -84,7 +83,6 @@ import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor; import org.apache.ignite.internal.processors.closure.GridClosureProcessor; import org.apache.ignite.internal.processors.plugin.CachePluginManager; -import org.apache.ignite.internal.processors.query.QueryUtils; import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor; import org.apache.ignite.internal.util.F0; import org.apache.ignite.internal.util.lang.GridFunc; @@ -106,9 +104,10 @@ import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; -import static org.apache.ignite.cache.CacheRebalanceMode.NONE; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC; +import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_STARTED; +import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_STOPPED; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.OWNING; /** @@ -135,14 +134,8 @@ public class GridCacheContext implements Externalizable { /** Cache shared context. */ private GridCacheSharedContext sharedCtx; - /** Memory policy. */ - private MemoryPolicy memPlc; - - /** FreeList instance this cache is associated with. */ - private FreeList freeList; - - /** ReuseList instance this cache is associated with */ - private ReuseList reuseList; + /** Cache group. */ + private CacheGroupContext grp; /** Logger. */ private IgniteLogger log; @@ -177,9 +170,6 @@ public class GridCacheContext implements Externalizable { /** Replication manager. */ private GridCacheDrManager drMgr; - /** */ - private IgniteCacheOffheapManager offheapMgr; - /** Conflict resolver manager. */ private CacheConflictResolutionManager rslvrMgr; @@ -210,6 +200,9 @@ public class GridCacheContext implements Externalizable { /** Cache ID. */ private int cacheId; + /** Cache ID. */ + private Integer cacheIdBoxed; + /** Cache type. */ private CacheType cacheType; @@ -237,18 +230,12 @@ public class GridCacheContext implements Externalizable { /** Topology version when cache was started on local node. */ private AffinityTopologyVersion locStartTopVer; - /** */ - private UUID rcvdFrom; - /** Dynamic cache deployment ID. */ private IgniteUuid dynamicDeploymentId; /** Updates allowed flag. */ private boolean updatesAllowed; - /** Flag indicating that this cache is in a recovery mode. */ - private boolean needsRecovery; - /** Deployment enabled flag for this specific cache */ private boolean depEnabled; @@ -258,6 +245,12 @@ public class GridCacheContext implements Externalizable { /** */ private boolean customAffMapper; + /** Whether {@link EventType#EVT_CACHE_REBALANCE_STARTED} was sent (used only for REPLICATED cache). */ + private volatile boolean rebalanceStartedEvtSent; + + /** Whether {@link EventType#EVT_CACHE_REBALANCE_STOPPED} was sent (used only for REPLICATED cache). */ + private volatile boolean rebalanceStoppedEvtSent; + /** * Empty constructor required for {@link Externalizable}. */ @@ -269,9 +262,9 @@ public GridCacheContext() { * @param ctx Kernal context. * @param sharedCtx Cache shared context. * @param cacheCfg Cache configuration. + * @param grp Cache group. * @param cacheType Cache type. - * @param memPlc MemoryPolicy instance. - * @param freeList FreeList instance. + * @param locStartTopVer Topology version when cache was started on local node. * @param affNode {@code True} if local node is affinity node. * @param updatesAllowed Updates allowed flag. * @param evtMgr Cache event manager. @@ -291,14 +284,11 @@ public GridCacheContext( GridKernalContext ctx, GridCacheSharedContext sharedCtx, CacheConfiguration cacheCfg, + CacheGroupContext grp, CacheType cacheType, AffinityTopologyVersion locStartTopVer, - UUID rcvdFrom, boolean affNode, boolean updatesAllowed, - MemoryPolicy memPlc, - FreeList freeList, - ReuseList reuseList, /* * Managers in starting order! @@ -313,7 +303,6 @@ public GridCacheContext( CacheDataStructuresManager dataStructuresMgr, GridCacheTtlManager ttlMgr, GridCacheDrManager drMgr, - IgniteCacheOffheapManager offheapMgr, CacheConflictResolutionManager rslvrMgr, CachePluginManager pluginMgr, GridCacheAffinityManager affMgr @@ -323,6 +312,7 @@ public GridCacheContext( assert cacheCfg != null; assert locStartTopVer != null : cacheCfg.getName(); + assert grp != null; assert evtMgr != null; assert storeMgr != null; assert evictMgr != null; @@ -333,22 +323,17 @@ public GridCacheContext( assert ttlMgr != null; assert rslvrMgr != null; assert pluginMgr != null; - assert offheapMgr != null; this.ctx = ctx; this.sharedCtx = sharedCtx; this.cacheCfg = cacheCfg; + this.grp = grp; this.cacheType = cacheType; this.locStartTopVer = locStartTopVer; - this.rcvdFrom = rcvdFrom; this.affNode = affNode; this.updatesAllowed = updatesAllowed; this.depEnabled = ctx.deploy().enabled() && !cacheObjects().isBinaryEnabled(cacheCfg); - this.memPlc = memPlc; - this.freeList = freeList; - this.reuseList = reuseList; - /* * Managers in starting order! * =========================== @@ -361,7 +346,6 @@ public GridCacheContext( this.dataStructuresMgr = add(dataStructuresMgr); this.ttlMgr = add(ttlMgr); this.drMgr = add(drMgr); - this.offheapMgr = add(offheapMgr); this.rslvrMgr = add(rslvrMgr); this.pluginMgr = add(pluginMgr); this.affMgr = add(affMgr); @@ -374,6 +358,8 @@ public GridCacheContext( cacheId = CU.cacheId(cacheName); + cacheIdBoxed = cacheId; + plc = cacheType.ioPolicy(); Factory factory = cacheCfg.getExpiryPolicyFactory(); @@ -386,6 +372,20 @@ public GridCacheContext( itHolder = new CacheWeakQueryIteratorsHolder(log); } + /** + * @return Cache group ID. + */ + public int groupId() { + return grp.groupId(); + } + + /** + * @return Cache group. + */ + public CacheGroupContext group() { + return grp; + } + /** * @return {@code True} if custom {@link AffinityKeyMapper} is configured for cache. */ @@ -459,13 +459,6 @@ public void onStarted() { startLatch.countDown(); } - /** - * @return Node ID cache was received from. - */ - public UUID receivedFrom() { - return rcvdFrom; - } - /** * @return Topology version when cache was started on local node. */ @@ -524,6 +517,13 @@ public int cacheId() { return cacheId; } + /** + * @return Cache ID. + */ + public Integer cacheIdBoxed() { + return cacheIdBoxed; + } + /** * @return {@code True} if should use system transactions which are isolated from user transactions. */ @@ -721,21 +721,7 @@ public String name() { * @return Memory policy. */ public MemoryPolicy memoryPolicy() { - return memPlc; - } - - /** - * @return Free List. - */ - public FreeList freeList() { - return freeList; - } - - /** - * @return Reuse List. - */ - public ReuseList reuseList() { - return reuseList; + return grp.memoryPolicy(); } /** @@ -775,7 +761,7 @@ public UUID nodeId() { * @return {@code True} if rebalance is enabled. */ public boolean rebalanceEnabled() { - return cacheCfg.getRebalanceMode() != NONE; + return grp.rebalanceEnabled(); } /** @@ -853,6 +839,18 @@ public GridDhtPartitionTopology topology() { return topology(cache); } + /** + * @return DHT cache. + */ + public GridDhtCacheAdapter dhtCache() { + GridCacheAdapter cache = this.cache; + + if (cache == null) + throw new IllegalStateException("Cache stopped: " + cacheName); + + return isNear() ? ((GridNearCacheAdapter)cache).dht() : dht(); + } + /** * @return Topology version future. */ @@ -1073,7 +1071,7 @@ public GridCacheDrManager dr() { * @return Offheap manager. */ public IgniteCacheOffheapManager offheap() { - return offheapMgr; + return grp.offheap(); } /** @@ -1944,20 +1942,6 @@ public boolean updatesAllowed() { return updatesAllowed; } - /** - * @return Current cache state. Must only be modified during exchange. - */ - public boolean needsRecovery() { - return needsRecovery; - } - - /** - * @param needsRecovery Needs recovery flag. - */ - public void needsRecovery(boolean needsRecovery) { - this.needsRecovery = needsRecovery; - } - /** * Nulling references to potentially leak-prone objects. */ @@ -2027,7 +2011,6 @@ public boolean allowFastLocalRead(int part, List affNodes, Affinity topology().partitionState(localNodeId(), part) == OWNING : "result = " + result + ", persistenceEnabled = " + ctx.cache().context().database().persistenceEnabled() + ", partitionState = " + topology().partitionState(localNodeId(), part); - ; return result; } @@ -2044,13 +2027,6 @@ public boolean readNoEntry(@Nullable IgniteCacheExpiryPolicy expiryPlc, boolean return !config().isOnheapCacheEnabled() && !readers && expiryPlc == null; } - /** - * @return {@code True} if fast eviction is allowed. - */ - public boolean allowFastEviction() { - return shared().database().persistenceEnabled() && !QueryUtils.isEnabled(cacheCfg); - } - /** * @param part Partition. * @param affNodes Affinity nodes. @@ -2066,6 +2042,35 @@ private boolean hasPartition(int part, List affNodes, AffinityTopol || (top.partitionState(localNodeId(), part) == OWNING); } + /** + * @param type Event type. + * @return {@code True} if event should be recorded. + */ + public boolean recordEvent(int type) { + if (isReplicated()) { + if (type == EVT_CACHE_REBALANCE_STARTED) { + if (!rebalanceStartedEvtSent) { + rebalanceStartedEvtSent = true; + + return true; + } + else + return false; + } + else if (type == EVT_CACHE_REBALANCE_STOPPED) { + if (!rebalanceStoppedEvtSent) { + rebalanceStoppedEvtSent = true; + + return true; + } + else + return false; + } + } + + return true; + } + /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { U.writeString(out, igniteInstanceName()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java index c0e1c55936aa7..7371153d4ae5d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java @@ -317,17 +317,17 @@ public void unmarshalValue(GridCacheContext ctx, ClassLoader ldr) throws I } /** + * @param ctx Cache object context. * @return Marshalled size. + * @throws IgniteCheckedException If failed. */ - public int marshalledSize(GridCacheContext ctx) throws IgniteCheckedException { + public int marshalledSize(CacheObjectContext ctx) throws IgniteCheckedException { int size = 0; - CacheObjectContext cacheObjCtx = ctx.cacheObjectContext(); - if (val != null) - size += val.valueBytes(cacheObjCtx).length; + size += val.valueBytes(ctx).length; - size += key.valueBytes(cacheObjCtx).length; + size += key.valueBytes(ctx).length; return SIZE_OVERHEAD + size; } @@ -337,12 +337,20 @@ public int marshalledSize(GridCacheContext ctx) throws IgniteCheckedException { * @throws IgniteCheckedException In case of error. */ public void marshal(GridCacheContext ctx) throws IgniteCheckedException { + marshal(ctx.cacheObjectContext()); + } + + /** + * @param ctx Cache context. + * @throws IgniteCheckedException In case of error. + */ + public void marshal(CacheObjectContext ctx) throws IgniteCheckedException { assert key != null; - key.prepareMarshal(ctx.cacheObjectContext()); + key.prepareMarshal(ctx); if (val != null) - val.prepareMarshal(ctx.cacheObjectContext()); + val.prepareMarshal(ctx); if (expireTime == 0) expireTime = -1; @@ -362,10 +370,21 @@ public void marshal(GridCacheContext ctx) throws IgniteCheckedException { * @throws IgniteCheckedException If unmarshalling failed. */ public void unmarshal(GridCacheContext ctx, ClassLoader clsLdr) throws IgniteCheckedException { - key.finishUnmarshal(ctx.cacheObjectContext(), clsLdr); + unmarshal(ctx.cacheObjectContext(), clsLdr); + } + + /** + * Unmarshalls entry. + * + * @param ctx Cache context. + * @param clsLdr Class loader. + * @throws IgniteCheckedException If unmarshalling failed. + */ + public void unmarshal(CacheObjectContext ctx, ClassLoader clsLdr) throws IgniteCheckedException { + key.finishUnmarshal(ctx, clsLdr); if (val != null) - val.finishUnmarshal(ctx.cacheObjectContext(), clsLdr); + val.finishUnmarshal(ctx, clsLdr); long remaining = expireTime; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java index 93c5950ab8ba1..a96730556b940 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java @@ -367,42 +367,6 @@ public void addEvent( return null; } - /** - * Adds preloading event. - * - * @param part Partition. - * @param type Event type. - * @param discoNode Discovery node. - * @param discoType Discovery event type. - * @param discoTs Discovery event timestamp. - */ - public void addPreloadEvent(int part, int type, ClusterNode discoNode, int discoType, long discoTs) { - assert discoNode != null; - assert type > 0; - assert discoType > 0; - assert discoTs > 0; - - if (!cctx.events().isRecordable(type)) - LT.warn(log, "Added event without checking if event is recordable: " + U.gridEventName(type)); - - cctx.gridEvents().record(new CacheRebalancingEvent(cctx.name(), cctx.localNode(), - "Cache rebalancing event.", type, part, discoNode, discoType, discoTs)); - } - - /** - * Adds partition unload event. - * - * @param part Partition. - */ - public void addUnloadEvent(int part) { - if (!cctx.events().isRecordable(EVT_CACHE_REBALANCE_PART_UNLOADED)) - LT.warn(log, "Added event without checking if event is recordable: " + - U.gridEventName(EVT_CACHE_REBALANCE_PART_UNLOADED)); - - cctx.gridEvents().record(new CacheRebalancingEvent(cctx.name(), cctx.localNode(), - "Cache unloading event.", EVT_CACHE_REBALANCE_PART_UNLOADED, part, null, 0, 0)); - } - /** * @param type Event type. * @return {@code True} if event is recordable. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGroupIdMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGroupIdMessage.java new file mode 100644 index 0000000000000..09c143b0c0dd3 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGroupIdMessage.java @@ -0,0 +1,110 @@ +/* + * 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 java.nio.ByteBuffer; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageWriter; + +/** + * Message related to particular cache group. + */ +public abstract class GridCacheGroupIdMessage extends GridCacheMessage { + /** Cache group ID. */ + @GridToStringInclude + protected int grpId; + + /** + * @return Cache group ID. + */ + public int groupId() { + return grpId; + } + + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return true; + } + + /** {@inheritDoc} */ + @Override public final int handlerId() { + return grpId; + } + + /** {@inheritDoc} */ + @Override public byte fieldsCount() { + return 3; + } + + /** {@inheritDoc} */ + @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) { + writer.setBuffer(buf); + + if (!super.writeTo(buf, writer)) + return false; + + if (!writer.isHeaderWritten()) { + if (!writer.writeHeader(directType(), fieldsCount())) + return false; + + writer.onHeaderWritten(); + } + + switch (writer.state()) { + case 2: + if (!writer.writeInt("grpId", grpId)) + return false; + + writer.incrementState(); + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) { + reader.setBuffer(buf); + + if (!reader.beforeMessageRead()) + return false; + + if (!super.readFrom(buf, reader)) + return false; + + switch (reader.state()) { + case 2: + grpId = reader.readInt("grpId"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + } + + return reader.afterMessageRead(GridCacheGroupIdMessage.class); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridCacheGroupIdMessage.class, this); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java new file mode 100644 index 0000000000000..6c20bdd15bdd6 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java @@ -0,0 +1,117 @@ +/* + * 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 java.nio.ByteBuffer; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageWriter; + +/** + * Message related to particular cache. + */ +public abstract class GridCacheIdMessage extends GridCacheMessage { + /** Cache ID. */ + @GridToStringInclude + protected int cacheId; + + /** + * @return Cache ID. + */ + public int cacheId() { + return cacheId; + } + + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return false; + } + + /** + * @param cacheId Cache ID. + */ + public void cacheId(int cacheId) { + this.cacheId = cacheId; + } + + /** {@inheritDoc} */ + @Override public byte fieldsCount() { + return 3; + } + + /** {@inheritDoc} */ + @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) { + writer.setBuffer(buf); + + if (!super.writeTo(buf, writer)) + return false; + + if (!writer.isHeaderWritten()) { + if (!writer.writeHeader(directType(), fieldsCount())) + return false; + + writer.onHeaderWritten(); + } + + switch (writer.state()) { + case 2: + if (!writer.writeInt("cacheId", cacheId)) + return false; + + writer.incrementState(); + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) { + reader.setBuffer(buf); + + if (!reader.beforeMessageRead()) + return false; + + if (!super.readFrom(buf, reader)) + return false; + + switch (reader.state()) { + case 2: + cacheId = reader.readInt("cacheId"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + } + + return reader.afterMessageRead(GridCacheIdMessage.class); + } + + /** {@inheritDoc} */ + @Override public int handlerId() { + return cacheId; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridCacheIdMessage.class, this); + } +} 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 bb316456b4371..a2510470a8337 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 @@ -110,16 +110,11 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter { /** Number of retries using to send messages. */ private int retryCnt; - /** Indexed class handlers. */ - private volatile Map idxClsHandlers = new HashMap<>(); + /** */ + private final MessageHandlers cacheHandlers = new MessageHandlers(); - /** Handler registry. */ - private ConcurrentMap> - clsHandlers = new ConcurrentHashMap8<>(); - - /** Ordered handler registry. */ - private ConcurrentMap> orderedHandlers = - new ConcurrentHashMap8<>(); + /** */ + private final MessageHandlers grpHandlers = new MessageHandlers(); /** Stopping flag. */ private boolean stopping; @@ -144,17 +139,19 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter { if (cacheMsg.partitionExchangeMessage()) { if (cacheMsg instanceof GridDhtAffinityAssignmentRequest) { + GridDhtAffinityAssignmentRequest msg0 = (GridDhtAffinityAssignmentRequest)cacheMsg; + assert cacheMsg.topologyVersion() != null : cacheMsg; AffinityTopologyVersion startTopVer = new AffinityTopologyVersion(cctx.localNode().order()); - DynamicCacheDescriptor cacheDesc = cctx.cache().cacheDescriptor(cacheMsg.cacheId()); + CacheGroupDescriptor desc = cctx.cache().cacheGroupDescriptors().get(msg0.groupId()); - if (cacheDesc != null) { - if (cacheDesc.startTopologyVersion() != null) - startTopVer = cacheDesc.startTopologyVersion(); - else if (cacheDesc.receivedFromStartVersion() != null) - startTopVer = cacheDesc.receivedFromStartVersion(); + if (desc != null) { + if (desc.startTopologyVersion() != null) + startTopVer = desc.startTopologyVersion(); + else if (desc.receivedFromStartVersion() != null) + startTopVer = desc.receivedFromStartVersion(); } // Need to wait for exchange to avoid race between cache start and affinity request. @@ -165,7 +162,7 @@ else if (cacheDesc.receivedFromStartVersion() != null) log.debug("Wait for exchange before processing message [msg=" + msg + ", node=" + nodeId + ", waitVer=" + startTopVer + - ", cacheDesc=" + cacheDesc + ']'); + ", cacheDesc=" + descriptorForMessage(cacheMsg) + ']'); } fut.listen(new CI1>() { @@ -260,21 +257,31 @@ else if (cacheDesc.receivedFromStartVersion() != null) */ @SuppressWarnings("unchecked") private void handleMessage(UUID nodeId, GridCacheMessage cacheMsg) { + handleMessage(nodeId, cacheMsg, cacheMsg.cacheGroupMessage() ? grpHandlers : cacheHandlers); + } + + /** + * @param nodeId Sender node ID. + * @param cacheMsg Message. + * @param msgHandlers Message handlers. + */ + @SuppressWarnings("unchecked") + private void handleMessage(UUID nodeId, GridCacheMessage cacheMsg, MessageHandlers msgHandlers) { int msgIdx = cacheMsg.lookupIndex(); IgniteBiInClosure c = null; if (msgIdx >= 0) { - Map idxClsHandlers0 = idxClsHandlers; + Map idxClsHandlers0 = msgHandlers.idxClsHandlers; - IgniteBiInClosure[] cacheClsHandlers = idxClsHandlers0.get(cacheMsg.cacheId()); + IgniteBiInClosure[] cacheClsHandlers = idxClsHandlers0.get(cacheMsg.handlerId()); if (cacheClsHandlers != null) c = cacheClsHandlers[msgIdx]; } if (c == null) - c = clsHandlers.get(new ListenerKey(cacheMsg.cacheId(), cacheMsg.getClass())); + c = msgHandlers.clsHandlers.get(new ListenerKey(cacheMsg.handlerId(), cacheMsg.getClass())); if (c == null) { IgniteLogger log = cacheMsg.messageLogger(cctx); @@ -285,12 +292,12 @@ private void handleMessage(UUID nodeId, GridCacheMessage cacheMsg) { msg0.append(", locTopVer=").append(cctx.exchange().readyAffinityVersion()). append(", msgTopVer=").append(cacheMsg.topologyVersion()). - append(", cacheDesc=").append(cctx.cache().cacheDescriptor(cacheMsg.cacheId())). + append(", desc=").append(descriptorForMessage(cacheMsg)). append(']'); msg0.append(U.nl()).append("Registered listeners:"); - Map idxClsHandlers0 = idxClsHandlers; + Map idxClsHandlers0 = msgHandlers.idxClsHandlers; for (Map.Entry e : idxClsHandlers0.entrySet()) msg0.append(U.nl()).append(e.getKey()).append("=").append(Arrays.toString(e.getValue())); @@ -323,7 +330,10 @@ private void handleMessage(UUID nodeId, GridCacheMessage cacheMsg) { @Override protected void onKernalStop0(boolean cancel) { cctx.gridIO().removeMessageListener(TOPIC_CACHE); - for (Object ordTopic : orderedHandlers.keySet()) + for (Object ordTopic : cacheHandlers.orderedHandlers.keySet()) + cctx.gridIO().removeMessageListener(ordTopic); + + for (Object ordTopic : grpHandlers.orderedHandlers.keySet()) cctx.gridIO().removeMessageListener(ordTopic); boolean interrupted = false; @@ -520,14 +530,17 @@ else if (cacheMsg instanceof GridNearAtomicCheckUpdateRequest) */ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInClosure c) throws IgniteCheckedException { - GridCacheContext ctx = cctx.cacheContext(msg.cacheId()); + assert msg != null; + + GridCacheContext ctx = msg instanceof GridCacheIdMessage ? + cctx.cacheContext(((GridCacheIdMessage)msg).cacheId()) : null; switch (msg.directType()) { case 30: { GridDhtLockRequest req = (GridDhtLockRequest)msg; GridDhtLockResponse res = new GridDhtLockResponse( - ctx.cacheId(), + req.cacheId(), req.version(), req.futureId(), req.miniId(), @@ -560,17 +573,17 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC GridDhtAtomicUpdateRequest req = (GridDhtAtomicUpdateRequest)msg; GridDhtAtomicUpdateResponse res = new GridDhtAtomicUpdateResponse( - ctx.cacheId(), + req.cacheId(), req.partition(), req.futureId(), - ctx.deploymentEnabled()); + false); res.onError(req.classError()); sendResponseOnFailedMessage(nodeId, res, cctx, ctx.ioPolicy()); if (req.nearNodeId() != null) { - GridDhtAtomicNearResponse nearRes = new GridDhtAtomicNearResponse(ctx.cacheId(), + GridDhtAtomicNearResponse nearRes = new GridDhtAtomicNearResponse(req.cacheId(), req.partition(), req.nearFutureId(), nodeId, @@ -588,12 +601,12 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC GridNearAtomicFullUpdateRequest req = (GridNearAtomicFullUpdateRequest)msg; GridNearAtomicUpdateResponse res = new GridNearAtomicUpdateResponse( - ctx.cacheId(), + req.cacheId(), nodeId, req.futureId(), req.partition(), false, - ctx.deploymentEnabled()); + false); res.error(req.classError()); @@ -606,10 +619,10 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC GridDhtForceKeysRequest req = (GridDhtForceKeysRequest)msg; GridDhtForceKeysResponse res = new GridDhtForceKeysResponse( - ctx.cacheId(), + req.cacheId(), req.futureId(), req.miniId(), - ctx.deploymentEnabled() + false ); res.error(req.classError()); @@ -629,7 +642,7 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC GridNearGetRequest req = (GridNearGetRequest)msg; GridNearGetResponse res = new GridNearGetResponse( - ctx.cacheId(), + req.cacheId(), req.futureId(), req.miniId(), req.version(), @@ -645,7 +658,7 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC case 50: { GridNearGetResponse res = (GridNearGetResponse)msg; - CacheGetFuture fut = (CacheGetFuture)ctx.mvcc().future(res.futureId()); + CacheGetFuture fut = (CacheGetFuture)cctx.mvcc().future(res.futureId()); if (fut == null) { if (log.isDebugEnabled()) @@ -665,7 +678,7 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC GridNearLockRequest req = (GridNearLockRequest)msg; GridNearLockResponse res = new GridNearLockResponse( - ctx.cacheId(), + req.cacheId(), req.version(), req.futureId(), req.miniId(), @@ -673,7 +686,7 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC 0, req.classError(), null, - ctx.deploymentEnabled()); + false); sendResponseOnFailedMessage(nodeId, res, cctx, ctx.ioPolicy()); } @@ -712,7 +725,7 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC cctx.deploymentEnabled()); cctx.io().sendOrderedMessage( - ctx.node(nodeId), + cctx.node(nodeId), TOPIC_CACHE.topic(QUERY_TOPIC_PREFIX, nodeId, req.id()), res, ctx.ioPolicy(), @@ -731,7 +744,7 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC GridNearSingleGetRequest req = (GridNearSingleGetRequest)msg; GridNearSingleGetResponse res = new GridNearSingleGetResponse( - ctx.cacheId(), + req.cacheId(), req.futureId(), req.topologyVersion(), null, @@ -748,7 +761,7 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC case 117: { GridNearSingleGetResponse res = (GridNearSingleGetResponse)msg; - GridPartitionedSingleGetFuture fut = (GridPartitionedSingleGetFuture)ctx.mvcc() + GridPartitionedSingleGetFuture fut = (GridPartitionedSingleGetFuture)cctx.mvcc() .future(new IgniteUuid(IgniteUuid.VM_ID, res.futureId())); if (fut == null) { @@ -769,12 +782,12 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC GridNearAtomicSingleUpdateRequest req = (GridNearAtomicSingleUpdateRequest)msg; GridNearAtomicUpdateResponse res = new GridNearAtomicUpdateResponse( - ctx.cacheId(), + req.cacheId(), nodeId, req.futureId(), req.partition(), false, - ctx.deploymentEnabled()); + false); res.error(req.classError()); @@ -787,12 +800,12 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC GridNearAtomicSingleUpdateInvokeRequest req = (GridNearAtomicSingleUpdateInvokeRequest)msg; GridNearAtomicUpdateResponse res = new GridNearAtomicUpdateResponse( - ctx.cacheId(), + req.cacheId(), nodeId, req.futureId(), req.partition(), false, - ctx.deploymentEnabled()); + false); res.error(req.classError()); @@ -805,12 +818,12 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC GridNearAtomicSingleUpdateFilterRequest req = (GridNearAtomicSingleUpdateFilterRequest)msg; GridNearAtomicUpdateResponse res = new GridNearAtomicUpdateResponse( - ctx.cacheId(), + req.cacheId(), nodeId, req.futureId(), req.partition(), false, - ctx.deploymentEnabled()); + false); res.error(req.classError()); @@ -823,17 +836,17 @@ private void processFailedMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInC GridDhtAtomicSingleUpdateRequest req = (GridDhtAtomicSingleUpdateRequest)msg; GridDhtAtomicUpdateResponse res = new GridDhtAtomicUpdateResponse( - ctx.cacheId(), + req.cacheId(), req.partition(), req.futureId(), - ctx.deploymentEnabled()); + false); res.onError(req.classError()); sendResponseOnFailedMessage(nodeId, res, cctx, ctx.ioPolicy()); if (req.nearNodeId() != null) { - GridDhtAtomicNearResponse nearRes = new GridDhtAtomicNearResponse(ctx.cacheId(), + GridDhtAtomicNearResponse nearRes = new GridDhtAtomicNearResponse(req.cacheId(), req.partition(), req.nearFutureId(), nodeId, @@ -887,8 +900,8 @@ private void processMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInClosure if (txState != null) txState.unwindEvicts(cctx); } - else { - GridCacheContext ctx = cctx.cacheContext(msg.cacheId()); + else if (msg instanceof GridCacheIdMessage) { + GridCacheContext ctx = cctx.cacheContext(((GridCacheIdMessage)msg).cacheId()); if (ctx != null) CU.unwindEvicts(ctx); @@ -1180,79 +1193,125 @@ void sendNoRetry(ClusterNode node, } /** - * Adds message handler. - * - * @param cacheId Cache ID. + * @param hndId Message handler ID. * @param type Type of message. * @param c Handler. */ - @SuppressWarnings({"unchecked"}) - public void addHandler( - int cacheId, + public void addCacheHandler( + int hndId, Class type, IgniteBiInClosure c) { + assert !type.isAssignableFrom(GridCacheGroupIdMessage.class) : type; + + addHandler(hndId, type, c, cacheHandlers); + } + + /** + * @param hndId Message handler ID. + * @param type Type of message. + * @param c Handler. + */ + public void addCacheGroupHandler( + int hndId, + Class type, + IgniteBiInClosure c) { + assert !type.isAssignableFrom(GridCacheIdMessage.class) : type; + + addHandler(hndId, type, c, grpHandlers); + } + + /** + * @param hndId Message handler ID. + * @param type Type of message. + * @param c Handler. + * @param msgHandlers Message handlers. + */ + @SuppressWarnings({"unchecked"}) + private void addHandler( + int hndId, + Class type, + IgniteBiInClosure c, + MessageHandlers msgHandlers) { int msgIdx = messageIndex(type); if (msgIdx != -1) { - Map idxClsHandlers0 = idxClsHandlers; + Map idxClsHandlers0 = msgHandlers.idxClsHandlers; - IgniteBiInClosure[] cacheClsHandlers = idxClsHandlers0.get(cacheId); + IgniteBiInClosure[] cacheClsHandlers = idxClsHandlers0.get(hndId); if (cacheClsHandlers == null) { cacheClsHandlers = new IgniteBiInClosure[GridCacheMessage.MAX_CACHE_MSG_LOOKUP_INDEX]; - idxClsHandlers0.put(cacheId, cacheClsHandlers); + idxClsHandlers0.put(hndId, cacheClsHandlers); } if (cacheClsHandlers[msgIdx] != null) - throw new IgniteException("Duplicate cache message ID found [cacheId=" + cacheId + + throw new IgniteException("Duplicate cache message ID found [hndId=" + hndId + ", type=" + type + ']'); cacheClsHandlers[msgIdx] = c; - idxClsHandlers = idxClsHandlers0; + msgHandlers.idxClsHandlers = idxClsHandlers0; return; } else { - ListenerKey key = new ListenerKey(cacheId, type); + ListenerKey key = new ListenerKey(hndId, type); - if (clsHandlers.putIfAbsent(key, + if (msgHandlers.clsHandlers.putIfAbsent(key, (IgniteBiInClosure)c) != null) - assert false : "Handler for class already registered [cacheId=" + cacheId + ", cls=" + type + - ", old=" + clsHandlers.get(key) + ", new=" + c + ']'; + assert false : "Handler for class already registered [hndId=" + hndId + ", cls=" + type + + ", old=" + msgHandlers.clsHandlers.get(key) + ", new=" + c + ']'; } IgniteLogger log0 = log; if (log0 != null && log0.isTraceEnabled()) log0.trace( - "Registered cache communication handler [cacheId=" + cacheId + ", type=" + type + + "Registered cache communication handler [hndId=" + hndId + ", type=" + type + ", msgIdx=" + msgIdx + ", handler=" + c + ']'); } /** * @param cacheId Cache ID to remove handlers for. */ - public void removeHandlers(int cacheId) { - assert cacheId != 0; + void removeCacheHandlers(int cacheId) { + removeHandlers(cacheHandlers, cacheId); + } + + /** + * @param grpId Cache group ID to remove handlers for. + */ + void removeCacheGroupHandlers(int grpId) { + removeHandlers(grpHandlers, grpId); + } + + /** + * @param msgHandlers Handlers. + * @param hndId ID to remove handlers for. + */ + private void removeHandlers(MessageHandlers msgHandlers, int hndId) { + assert hndId != 0; - idxClsHandlers.remove(cacheId); + msgHandlers.idxClsHandlers.remove(hndId); - for (Iterator iter = clsHandlers.keySet().iterator(); iter.hasNext(); ) { + for (Iterator iter = msgHandlers.clsHandlers.keySet().iterator(); iter.hasNext(); ) { ListenerKey key = iter.next(); - if (key.cacheId == cacheId) + if (key.hndId == hndId) iter.remove(); } } /** - * @param cacheId Cache ID to remove handlers for. + * @param cacheGrp {@code True} if cache group handler, {@code false} if cache handler. + * @param hndId Handler ID. * @param type Message type. */ - public void removeHandler(int cacheId, Class type) { - clsHandlers.remove(new ListenerKey(cacheId, type)); + public void removeHandler(boolean cacheGrp, int hndId, Class type) { + MessageHandlers msgHandlers = cacheGrp ? grpHandlers : cacheHandlers; + + msgHandlers.clsHandlers.remove(new ListenerKey(hndId, type)); } /** @@ -1273,17 +1332,36 @@ private int messageIndex(Class msgCls) { } } + /** + * @param topic Topic. + * @param c Handler. + */ + public void addOrderedCacheHandler(Object topic, IgniteBiInClosure c) { + addOrderedHandler(false, topic, c); + } + + /** + * @param topic Topic. + * @param c Handler. + */ + public void addOrderedCacheGroupHandler(Object topic, IgniteBiInClosure c) { + addOrderedHandler(true, topic, c); + } + /** * Adds ordered message handler. * + * @param cacheGrp {@code True} if cache group message, {@code false} if cache message. * @param topic Topic. * @param c Handler. */ @SuppressWarnings({"unchecked"}) - public void addOrderedHandler(Object topic, IgniteBiInClosure c) { + private void addOrderedHandler(boolean cacheGrp, Object topic, IgniteBiInClosure c) { + MessageHandlers msgHandlers = cacheGrp ? grpHandlers : cacheHandlers; + IgniteLogger log0 = log; - if (orderedHandlers.putIfAbsent(topic, c) == null) { + if (msgHandlers.orderedHandlers.putIfAbsent(topic, c) == null) { cctx.gridIO().addMessageListener(topic, new OrderedMessageListener( (IgniteBiInClosure)c)); @@ -1298,10 +1376,13 @@ else if (log0 != null) /** * Removed ordered message handler. * + * @param cacheGrp {@code True} if cache group message, {@code false} if cache message. * @param topic Topic. */ - public void removeOrderedHandler(Object topic) { - if (orderedHandlers.remove(topic) != null) { + public void removeOrderedHandler(boolean cacheGrp, Object topic) { + MessageHandlers msgHandlers = cacheGrp ? grpHandlers : cacheHandlers; + + if (msgHandlers.orderedHandlers.remove(topic) != null) { cctx.gridIO().removeMessageListener(topic); if (log != null && log.isDebugEnabled()) @@ -1352,12 +1433,43 @@ private void unmarshall(UUID nodeId, GridCacheMessage cacheMsg) { } } + /** + * @param msg Message. + * @return Cache or group descriptor. + */ + private Object descriptorForMessage(GridCacheMessage msg) { + if (msg instanceof GridCacheIdMessage) + return cctx.cache().cacheDescriptor(((GridCacheIdMessage)msg).cacheId()); + else if (msg instanceof GridCacheGroupIdMessage) + return cctx.cache().cacheGroupDescriptors().get(((GridCacheGroupIdMessage)msg).groupId()); + + return null; + } + /** {@inheritDoc} */ @Override public void printMemoryStats() { X.println(">>> "); X.println(">>> Cache IO manager memory stats [igniteInstanceName=" + cctx.igniteInstanceName() + ']'); - X.println(">>> clsHandlersSize: " + clsHandlers.size()); - X.println(">>> orderedHandlersSize: " + orderedHandlers.size()); + X.println(">>> cacheClsHandlersSize: " + cacheHandlers.clsHandlers.size()); + X.println(">>> cacheOrderedHandlersSize: " + cacheHandlers.orderedHandlers.size()); + X.println(">>> cacheGrpClsHandlersSize: " + grpHandlers.clsHandlers.size()); + X.println(">>> cacheGrpOrderedHandlersSize: " + grpHandlers.orderedHandlers.size()); + } + + /** + * + */ + static class MessageHandlers { + /** Indexed class handlers. */ + volatile Map idxClsHandlers = new HashMap<>(); + + /** Handler registry. */ + ConcurrentMap> + clsHandlers = new ConcurrentHashMap8<>(); + + /** Ordered handler registry. */ + ConcurrentMap> orderedHandlers = + new ConcurrentHashMap8<>(); } /** @@ -1391,17 +1503,17 @@ private class OrderedMessageListener implements GridMessageListener { */ private static class ListenerKey { /** Cache ID. */ - private int cacheId; + private int hndId; /** Message class. */ private Class msgCls; /** - * @param cacheId Cache ID. + * @param hndId Handler ID. * @param msgCls Message class. */ - private ListenerKey(int cacheId, Class msgCls) { - this.cacheId = cacheId; + private ListenerKey(int hndId, Class msgCls) { + this.hndId = hndId; this.msgCls = msgCls; } @@ -1415,12 +1527,12 @@ private ListenerKey(int cacheId, Class msgCls) { ListenerKey that = (ListenerKey)o; - return cacheId == that.cacheId && msgCls.equals(that.msgCls); + return hndId == that.hndId && msgCls.equals(that.msgCls); } /** {@inheritDoc} */ @Override public int hashCode() { - int res = cacheId; + int res = hndId; res = 31 * res + msgCls.hashCode(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheLocalConcurrentMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheLocalConcurrentMap.java index db99272ef685d..63cfe1f443fdd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheLocalConcurrentMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheLocalConcurrentMap.java @@ -18,37 +18,65 @@ package org.apache.ignite.internal.processors.cache; -import java.util.concurrent.atomic.AtomicInteger; +import org.jetbrains.annotations.Nullable; +import org.jsr166.ConcurrentHashMap8; /** * GridCacheConcurrentMap implementation for local and near caches. */ public class GridCacheLocalConcurrentMap extends GridCacheConcurrentMapImpl { /** */ - private final AtomicInteger pubSize = new AtomicInteger(); + private final int cacheId; - public GridCacheLocalConcurrentMap(GridCacheContext ctx, - GridCacheMapEntryFactory factory, int initialCapacity) { - super(ctx, factory, initialCapacity); + /** */ + private final CacheMapHolder entryMap; + + /** + * @param cctx Cache context. + * @param factory Entry factory. + * @param initCap Initial capacity. + */ + public GridCacheLocalConcurrentMap(GridCacheContext cctx, GridCacheMapEntryFactory factory, int initCap) { + super(factory); + + this.cacheId = cctx.cacheId(); + this.entryMap = new CacheMapHolder(cctx, + new ConcurrentHashMap8(initCap, 0.75f, Runtime.getRuntime().availableProcessors() * 2)); } - public GridCacheLocalConcurrentMap(GridCacheContext ctx, - GridCacheMapEntryFactory factory, int initialCapacity, float loadFactor, int concurrencyLevel) { - super(ctx, factory, initialCapacity, loadFactor, concurrencyLevel); + /** {@inheritDoc} */ + @Override public int internalSize() { + return entryMap.map.size(); } /** {@inheritDoc} */ - @Override public int publicSize() { - return pubSize.get(); + @Nullable @Override protected CacheMapHolder entriesMap(GridCacheContext cctx) { + return entryMap; } /** {@inheritDoc} */ - @Override public void incrementPublicSize(GridCacheEntryEx e) { - pubSize.incrementAndGet(); + @Nullable @Override protected CacheMapHolder entriesMapIfExists(Integer cacheId) { + return entryMap; } /** {@inheritDoc} */ - @Override public void decrementPublicSize(GridCacheEntryEx e) { - pubSize.decrementAndGet(); + @Override public int publicSize(int cacheId) { + assert this.cacheId == cacheId; + + return entryMap.size.get(); + } + + /** {@inheritDoc} */ + @Override public void incrementPublicSize(CacheMapHolder hld, GridCacheEntryEx e) { + assert cacheId == e.context().cacheId(); + + entryMap.size.incrementAndGet(); + } + + /** {@inheritDoc} */ + @Override public void decrementPublicSize(CacheMapHolder hld, GridCacheEntryEx e) { + assert cacheId == e.context().cacheId(); + + entryMap.size.decrementAndGet(); } } 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 5e57ca4505229..28656fb79903b 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 @@ -981,7 +981,7 @@ else if (interceptorVal != val0) if (cctx.deferredDelete() && deletedUnlocked() && !isInternal() && !detached()) deletedUnlocked(false); - updateCntr0 = nextPartCounter(topVer); + updateCntr0 = nextPartitionCounter(topVer, tx == null || tx.local(), updateCntr); if (updateCntr != null && updateCntr != 0) updateCntr0 = updateCntr; @@ -1160,7 +1160,7 @@ protected Object keyValue(boolean cpy) { } } - updateCntr0 = nextPartCounter(topVer); + updateCntr0 = nextPartitionCounter(topVer, tx == null || tx.local(), updateCntr); if (updateCntr != null && updateCntr != 0) updateCntr0 = updateCntr; @@ -1562,7 +1562,7 @@ else if (ttl != CU.TTL_ZERO) updateMetrics(op, metrics); if (lsnrCol != null) { - long updateCntr = nextPartCounter(AffinityTopologyVersion.NONE); + long updateCntr = nextPartitionCounter(AffinityTopologyVersion.NONE, true, null); cctx.continuousQueries().onEntryUpdated( lsnrCol, @@ -1651,6 +1651,7 @@ else if (ttl != CU.TTL_ZERO) (op == GridCacheOperation.TRANSFORM || cctx.loadPreviousValue())); c = new AtomicCacheUpdateClosure(this, + topVer, newVer, op, writeObj, @@ -1677,7 +1678,7 @@ else if (ttl != CU.TTL_ZERO) c.call(dataRow); } else - cctx.offheap().invoke(key, localPartition(), c); + cctx.offheap().invoke(cctx, key, localPartition(), c); GridCacheUpdateAtomicResult updateRes = c.updateRes; @@ -1722,7 +1723,7 @@ else if (ttl != CU.TTL_ZERO) else evtVal = (CacheObject)writeObj; - long updateCntr0 = nextPartCounter(); + long updateCntr0 = nextPartitionCounter(topVer, primary, updateCntr); if (updateCntr != null) updateCntr0 = updateCntr; @@ -2612,7 +2613,7 @@ else if (deletedUnlocked()) long updateCntr = 0; if (!preload) - updateCntr = nextPartCounter(topVer); + updateCntr = nextPartitionCounter(topVer, true, null); if (walEnabled) { cctx.shared().wal().log(new DataRecord(new DataEntry( @@ -2668,33 +2669,15 @@ protected void onUpdateFinished(long cntr) { } /** + * @param topVer Topology version for current operation. + * @param primary Primary node update flag. + * @param primaryCntr Counter assigned on primary node. * @return Update counter. */ - protected long nextPartCounter() { + protected long nextPartitionCounter(AffinityTopologyVersion topVer, boolean primary, @Nullable Long primaryCntr) { return 0; } - /** - * @param topVer Topology version. - * @return Update counter. - */ - private long nextPartCounter(AffinityTopologyVersion topVer) { - long updateCntr; - - if (!cctx.isLocal() && !isNear()) { - GridDhtLocalPartition locPart = cctx.topology().localPartition(partition(), topVer, false); - - if (locPart == null) - return 0; - - updateCntr = locPart.nextUpdateCounter(); - } - else - updateCntr = 0; - - return updateCntr; - } - /** {@inheritDoc} */ @Override public synchronized GridCacheVersionedEntryEx versionedEntry(final boolean keepBinary) throws IgniteCheckedException, GridCacheEntryRemovedException { @@ -3192,7 +3175,8 @@ private IgniteTxLocalAdapter currentTx() { synchronized (this) { checkObsolete(); - cctx.offheap().updateIndexes(key, localPartition()); + if (cctx.queries().enabled()) + cctx.offheap().updateIndexes(cctx, key, localPartition()); } } @@ -3227,14 +3211,14 @@ private IgniteTxLocalAdapter currentTx() { * @param oldRow Old row if available. * @throws IgniteCheckedException If update failed. */ - protected void storeValue(@Nullable CacheObject val, + protected void storeValue(CacheObject val, long expireTime, GridCacheVersion ver, @Nullable CacheDataRow oldRow) throws IgniteCheckedException { assert Thread.holdsLock(this); assert val != null : "null values in update for key: " + key; - cctx.offheap().invoke(key, localPartition(), new UpdateClosure(this, val, ver, expireTime)); + cctx.offheap().invoke(cctx, key, localPartition(), new UpdateClosure(this, val, ver, expireTime)); } /** @@ -3276,7 +3260,7 @@ protected void logUpdate(GridCacheOperation op, CacheObject val, GridCacheVersio protected void removeValue() throws IgniteCheckedException { assert Thread.holdsLock(this); - cctx.offheap().remove(key, partition(), localPartition()); + cctx.offheap().remove(cctx, key, partition(), localPartition()); } /** {@inheritDoc} */ @@ -3606,7 +3590,7 @@ protected void incrementMapPublicSize() { GridDhtLocalPartition locPart = localPartition(); if (locPart != null) - locPart.incrementPublicSize(this); + locPart.incrementPublicSize(null, this); else cctx.incrementPublicSize(this); } @@ -3618,7 +3602,7 @@ protected void decrementMapPublicSize() { GridDhtLocalPartition locPart = localPartition(); if (locPart != null) - locPart.decrementPublicSize(this); + locPart.decrementPublicSize(null, this); else cctx.decrementPublicSize(this); } @@ -3930,7 +3914,9 @@ private static class UpdateClosure implements IgniteCacheOffheapManager.OffheapI if (oldRow != null) oldRow.key(entry.key); - newRow = entry.cctx.offheap().dataStore(entry.localPartition()).createRow(entry.key, + newRow = entry.cctx.offheap().dataStore(entry.localPartition()).createRow( + entry.cctx, + entry.key, val, ver, expireTime, @@ -3963,6 +3949,9 @@ private static class AtomicCacheUpdateClosure implements IgniteCacheOffheapManag /** */ private final GridCacheMapEntry entry; + /** */ + private final AffinityTopologyVersion topVer; + /** */ private GridCacheVersion newVer; @@ -4026,7 +4015,9 @@ private static class AtomicCacheUpdateClosure implements IgniteCacheOffheapManag /** */ private CacheDataRow oldRow; - AtomicCacheUpdateClosure(GridCacheMapEntry entry, + AtomicCacheUpdateClosure( + GridCacheMapEntry entry, + AffinityTopologyVersion topVer, GridCacheVersion newVer, GridCacheOperation op, Object writeObj, @@ -4047,6 +4038,7 @@ private static class AtomicCacheUpdateClosure implements IgniteCacheOffheapManag assert op == UPDATE || op == DELETE || op == TRANSFORM : op; this.entry = entry; + this.topVer = topVer; this.newVer = newVer; this.op = op; this.writeObj = writeObj; @@ -4282,7 +4274,9 @@ else if (updateExpireTime && expiryPlc != null && entry.val != null){ } if (needUpdate) { - newRow = entry.localPartition().dataStore().createRow(entry.key, + newRow = entry.localPartition().dataStore().createRow( + entry.cctx, + entry.key, storeLoadedVal, newVer, entry.expireTimeExtras(), @@ -4413,7 +4407,7 @@ else if (interceptorVal != updated0) { ", locNodeId=" + cctx.localNodeId() + ']'; } - long updateCntr0 = entry.nextPartCounter(); + long updateCntr0 = entry.nextPartitionCounter(topVer, primary, updateCntr); if (updateCntr != null) updateCntr0 = updateCntr; @@ -4421,7 +4415,9 @@ else if (interceptorVal != updated0) { entry.logUpdate(op, updated, newVer, newExpireTime, updateCntr0); if (!entry.isNear()) { - newRow = entry.localPartition().dataStore().createRow(entry.key, + newRow = entry.localPartition().dataStore().createRow( + entry.cctx, + entry.key, updated, newVer, newExpireTime, @@ -4495,7 +4491,7 @@ private void remove(@Nullable GridCacheVersionConflictContext conflictCtx, // Must persist inside synchronization in non-tx mode. cctx.store().remove(null, entry.key); - long updateCntr0 = entry.nextPartCounter(); + long updateCntr0 = entry.nextPartitionCounter(topVer, primary, updateCntr); if (updateCntr != null) updateCntr0 = updateCntr; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java index 4de465ce79fbc..11916e92270fd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java @@ -84,9 +84,15 @@ public abstract class GridCacheMessage implements Message { @GridDirectTransient private boolean skipPrepare; - /** Cache ID. */ - @GridToStringInclude - protected int cacheId; + /** + * @return ID to distinguish message handlers for the same messages but for different caches/cache groups. + */ + public abstract int handlerId(); + + /** + * @return {@code True} if cache group message. + */ + public abstract boolean cacheGroupMessage(); /** * @return Error, if any. @@ -169,20 +175,6 @@ void messageId(long msgId) { this.msgId = msgId; } - /** - * @return Cache ID. - */ - public int cacheId() { - return cacheId; - } - - /** - * @param cacheId Cache ID. - */ - public void cacheId(int cacheId) { - this.cacheId = cacheId; - } - /** * Gets topology version or -1 in case of topology version is not required for this message. * @@ -205,6 +197,15 @@ public AffinityTopologyVersion topologyVersion() { * @throws IgniteCheckedException If failed. */ protected final void prepareObject(@Nullable Object o, GridCacheContext ctx) throws IgniteCheckedException { + prepareObject(o, ctx.shared()); + } + + /** + * @param o Object to prepare for marshalling. + * @param ctx Context. + * @throws IgniteCheckedException If failed. + */ + protected final void prepareObject(@Nullable Object o, GridCacheSharedContext ctx) throws IgniteCheckedException { assert addDepInfo || forceAddDepInfo; if (!skipPrepare && o != null) { @@ -279,24 +280,28 @@ public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws /** * @param info Entry to marshal. * @param ctx Context. + * @param cacheObjCtx Cache object context. * @throws IgniteCheckedException If failed. */ - protected final void marshalInfo(GridCacheEntryInfo info, GridCacheContext ctx) throws IgniteCheckedException { + protected final void marshalInfo(GridCacheEntryInfo info, + GridCacheSharedContext ctx, + CacheObjectContext cacheObjCtx + ) throws IgniteCheckedException { assert ctx != null; if (info != null) { - info.marshal(ctx); + info.marshal(cacheObjCtx); if (addDepInfo) { if (info.key() != null) - prepareObject(info.key().value(ctx.cacheObjectContext(), false), ctx); + prepareObject(info.key().value(cacheObjCtx, false), ctx); CacheObject val = info.value(); if (val != null) { - val.finishUnmarshal(ctx.cacheObjectContext(), ctx.deploy().globalLoader()); + val.finishUnmarshal(cacheObjCtx, ctx.deploy().globalLoader()); - prepareObject(CU.value(val, ctx, false), ctx); + prepareObject(val.value(cacheObjCtx, false), ctx); } } } @@ -314,7 +319,7 @@ protected final void unmarshalInfo(GridCacheEntryInfo info, GridCacheContext ctx assert ctx != null; if (info != null) - info.unmarshal(ctx, ldr); + info.unmarshal(ctx.cacheObjectContext(), ldr); } /** @@ -324,13 +329,14 @@ protected final void unmarshalInfo(GridCacheEntryInfo info, GridCacheContext ctx */ protected final void marshalInfos( Iterable infos, - GridCacheContext ctx + GridCacheSharedContext ctx, + CacheObjectContext cacheObjCtx ) throws IgniteCheckedException { assert ctx != null; if (infos != null) for (GridCacheEntryInfo e : infos) - marshalInfo(e, ctx); + marshalInfo(e, ctx, cacheObjCtx); } /** @@ -369,14 +375,14 @@ protected final void marshalTx(Iterable txEntries, GridCacheShare if (addDepInfo) { if (e.key() != null) - prepareObject(e.key().value(cctx.cacheObjectContext(), false), cctx); + prepareObject(e.key().value(cctx.cacheObjectContext(), false), ctx); if (e.value() != null) - prepareObject(e.value().value(cctx.cacheObjectContext(), false), cctx); + prepareObject(e.value().value(cctx.cacheObjectContext(), false), ctx); if (e.entryProcessors() != null) { for (T2, Object[]> entProc : e.entryProcessors()) - prepareObject(entProc.get1(), cctx); + prepareObject(entProc.get1(), ctx); } } else if (p2pEnabled && e.entryProcessors() != null) { @@ -384,7 +390,7 @@ else if (p2pEnabled && e.entryProcessors() != null) { forceAddDepInfo = true; for (T2, Object[]> entProc : e.entryProcessors()) - prepareObject(entProc.get1(), cctx); + prepareObject(entProc.get1(), ctx); } } } @@ -435,7 +441,7 @@ protected final void unmarshalTx(Iterable txEntries, Object arg = args[i]; if (addDepInfo) - prepareObject(arg, ctx); + prepareObject(arg, ctx.shared()); argsBytes[i] = arg == null ? null : CU.marshal(ctx, arg); } @@ -487,7 +493,7 @@ protected final void unmarshalTx(Iterable txEntries, for (Object o : col) { if (addDepInfo) - prepareObject(o, ctx); + prepareObject(o, ctx.shared()); byteCol.add(o == null ? null : CU.marshal(ctx, o)); } @@ -522,7 +528,7 @@ protected final void prepareMarshalCacheObject(CacheObject obj, GridCacheContext obj.prepareMarshal(ctx.cacheObjectContext()); if (addDepInfo) - prepareObject(obj.value(ctx.cacheObjectContext(), false), ctx); + prepareObject(obj.value(ctx.cacheObjectContext(), false), ctx.shared()); } } @@ -541,7 +547,7 @@ protected final void prepareMarshalCacheObjects(@Nullable Collection() { @Override public void onMessage(ClusterNode node, GridDhtPartitionsSingleMessage msg) { processSinglePartitionUpdate(node, msg); } }); - cctx.io().addHandler(0, GridDhtPartitionsFullMessage.class, + cctx.io().addCacheHandler(0, GridDhtPartitionsFullMessage.class, new MessageHandler() { @Override public void onMessage(ClusterNode node, GridDhtPartitionsFullMessage msg) { processFullPartitionUpdate(node, msg); } }); - cctx.io().addHandler(0, GridDhtPartitionsSingleRequest.class, + cctx.io().addCacheHandler(0, GridDhtPartitionsSingleRequest.class, new MessageHandler() { @Override public void onMessage(ClusterNode node, GridDhtPartitionsSingleRequest msg) { processSinglePartitionRequest(node, msg); @@ -383,24 +382,28 @@ private GridDhtPartitionExchangeId initialExchangeId() { for (int cnt = 0; cnt < cctx.gridConfig().getRebalanceThreadPoolSize(); cnt++) { final int idx = cnt; - cctx.io().addOrderedHandler(rebalanceTopic(cnt), new CI2() { - @Override public void apply(final UUID id, final GridCacheMessage m) { + cctx.io().addOrderedCacheGroupHandler(rebalanceTopic(cnt), new CI2() { + @Override public void apply(final UUID id, final GridCacheGroupIdMessage m) { if (!enterBusy()) return; try { - GridCacheContext cacheCtx = cctx.cacheContext(m.cacheId); - - if (cacheCtx != null) { - if (m instanceof GridDhtPartitionSupplyMessage) - cacheCtx.preloader().handleSupplyMessage( - idx, id, (GridDhtPartitionSupplyMessage)m); - else if (m instanceof GridDhtPartitionDemandMessage) - cacheCtx.preloader().handleDemandMessage( - idx, id, (GridDhtPartitionDemandMessage)m); - else - U.error(log, "Unsupported message type: " + m.getClass().getName()); + CacheGroupContext grp = cctx.cache().cacheGroup(m.groupId()); + + if (grp != null) { + if (m instanceof GridDhtPartitionSupplyMessage) { + grp.preloader().handleSupplyMessage(idx, id, (GridDhtPartitionSupplyMessage) m); + + return; + } + else if (m instanceof GridDhtPartitionDemandMessage) { + grp.preloader().handleDemandMessage(idx, id, (GridDhtPartitionDemandMessage) m); + + return; + } } + + U.error(log, "Unsupported message type: " + m.getClass().getName()); } finally { leaveBusy(); @@ -418,14 +421,14 @@ else if (m instanceof GridDhtPartitionDemandMessage) try { fut.get(); - for (GridCacheContext cacheCtx : cctx.cacheContexts()) - cacheCtx.preloader().onInitialExchangeComplete(null); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) + grp.preloader().onInitialExchangeComplete(null); reconnectExchangeFut.onDone(); } catch (IgniteCheckedException e) { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) - cacheCtx.preloader().onInitialExchangeComplete(e); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) + grp.preloader().onInitialExchangeComplete(e); reconnectExchangeFut.onDone(e); } @@ -470,9 +473,9 @@ else if (m instanceof GridDhtPartitionDemandMessage) AffinityTopologyVersion nodeStartVer = new AffinityTopologyVersion(discoEvt.topologyVersion(), 0); - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (nodeStartVer.equals(cacheCtx.startTopologyVersion())) - cacheCtx.preloader().onInitialExchangeComplete(null); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (nodeStartVer.equals(grp.localStartVersion())) + grp.preloader().onInitialExchangeComplete(null); } if (log.isDebugEnabled()) @@ -492,9 +495,9 @@ public static Object rebalanceTopic(int idx) { @Override protected void onKernalStop0(boolean cancel) { cctx.gridEvents().removeDiscoveryEventListener(discoLsnr); - cctx.io().removeHandler(0, GridDhtPartitionsSingleMessage.class); - cctx.io().removeHandler(0, GridDhtPartitionsFullMessage.class); - cctx.io().removeHandler(0, GridDhtPartitionsSingleRequest.class); + cctx.io().removeHandler(false, 0, GridDhtPartitionsSingleMessage.class); + cctx.io().removeHandler(false, 0, GridDhtPartitionsFullMessage.class); + cctx.io().removeHandler(false, 0, GridDhtPartitionsSingleRequest.class); stopErr = cctx.kernalContext().clientDisconnected() ? new IgniteClientDisconnectedCheckedException(cctx.kernalContext().cluster().clientReconnectFuture(), @@ -514,7 +517,7 @@ public static Object rebalanceTopic(int idx) { if (!cctx.kernalContext().clientNode()) { for (int cnt = 0; cnt < cctx.gridConfig().getRebalanceThreadPoolSize(); cnt++) - cctx.io().removeOrderedHandler(rebalanceTopic(cnt)); + cctx.io().removeOrderedHandler(true, rebalanceTopic(cnt)); } U.cancel(exchWorker); @@ -549,22 +552,22 @@ public Object interruptLock() { } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param exchFut Exchange future. * @return Topology. */ - public GridDhtPartitionTopology clientTopology(int cacheId, GridDhtPartitionsExchangeFuture exchFut) { - GridClientPartitionTopology top = clientTops.get(cacheId); + public GridDhtPartitionTopology clientTopology(int grpId, GridDhtPartitionsExchangeFuture exchFut) { + GridClientPartitionTopology top = clientTops.get(grpId); if (top != null) return top; Object affKey = null; - DynamicCacheDescriptor desc = cctx.cache().cacheDescriptor(cacheId); + CacheGroupDescriptor grpDesc = cctx.cache().cacheGroupDescriptors().get(grpId); - if (desc != null) { - CacheConfiguration ccfg = desc.cacheConfiguration(); + if (grpDesc != null) { + CacheConfiguration ccfg = grpDesc.config(); AffinityFunction aff = ccfg.getAffinity(); @@ -574,8 +577,8 @@ public GridDhtPartitionTopology clientTopology(int cacheId, GridDhtPartitionsExc aff.partitions()); } - GridClientPartitionTopology old = clientTops.putIfAbsent(cacheId, - top = new GridClientPartitionTopology(cctx, cacheId, exchFut, affKey)); + GridClientPartitionTopology old = clientTops.putIfAbsent(grpId, + top = new GridClientPartitionTopology(cctx, grpId, exchFut, affKey)); return old != null ? old : top; } @@ -588,11 +591,11 @@ public Collection clientTopologies() { } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @return Client partition topology. */ - public GridClientPartitionTopology clearClientTopology(int cacheId) { - return clientTops.remove(cacheId); + public GridClientPartitionTopology clearClientTopology(int grpId) { + return clientTops.remove(grpId); } /** @@ -806,18 +809,12 @@ private void refreshPartitions() { // If this is the oldest node. if (oldest.id().equals(cctx.localNodeId())) { // Check rebalance state & send CacheAffinityChangeMessage if need. - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (!cacheCtx.isLocal()) { - if (cacheCtx == null) - continue; - - GridDhtPartitionTopology top = null; - - if (!cacheCtx.isLocal()) - top = cacheCtx.topology(); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (!grp.isLocal()) { + GridDhtPartitionTopology top = grp.topology(); if (top != null) - cctx.affinity().checkRebalanceState(top, cacheCtx.cacheId()); + cctx.affinity().checkRebalanceState(top, grp.groupId()); } } @@ -827,7 +824,7 @@ private void refreshPartitions() { AffinityTopologyVersion rmtTopVer = lastFut != null ? lastFut.topologyVersion() : AffinityTopologyVersion.NONE; - Collection rmts = CU.remoteNodes(cctx, AffinityTopologyVersion.NONE); + Collection rmts = CU.remoteNodes(cctx, rmtTopVer); if (log.isDebugEnabled()) log.debug("Refreshing partitions from oldest node: " + cctx.localNodeId()); @@ -845,9 +842,8 @@ private void refreshPartitions() { /** * @param nodes Nodes. - * @return {@code True} if message was sent, {@code false} if node left grid. */ - private boolean sendAllPartitions(Collection nodes) { + private void sendAllPartitions(Collection nodes) { GridDhtPartitionsFullMessage m = createPartitionsFullMessage(nodes, null, null, null, null, true); if (log.isDebugEnabled()) @@ -868,8 +864,6 @@ private boolean sendAllPartitions(Collection nodes) { U.warn(log, "Failed to send partitions full message [node=" + node + ", err=" + e + ']'); } } - - return true; } /** @@ -896,51 +890,48 @@ public GridDhtPartitionsFullMessage createPartitionsFullMessage(Collection> dupData = new HashMap<>(); - cctx.forAllCaches(new IgniteInClosure() { - @Override public void apply(GridCacheContext cacheCtx) { - if (!cacheCtx.isLocal()) { - boolean ready; - - if (exchId != null) { - AffinityTopologyVersion startTopVer = cacheCtx.startTopologyVersion(); - - ready = startTopVer.compareTo(exchId.topologyVersion()) <= 0; - } - else - ready = cacheCtx.started(); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (!grp.isLocal()) { + if (exchId != null) { + AffinityTopologyVersion startTopVer = grp.localStartVersion(); - if (ready) { - GridAffinityAssignmentCache affCache = cacheCtx.affinity().affinityCache(); + if (startTopVer.compareTo(exchId.topologyVersion()) > 0) + continue; + } - GridDhtPartitionFullMap locMap = cacheCtx.topology().partitionMap(true); + GridAffinityAssignmentCache affCache = grp.affinity(); - addFullPartitionsMap(m, - dupData, - compress, - cacheCtx.cacheId(), - locMap, - affCache.similarAffinityKey()); + GridDhtPartitionFullMap locMap = grp.topology().partitionMap(true); - if (exchId != null) - m.addPartitionUpdateCounters(cacheCtx.cacheId(), cacheCtx.topology().updateCounters(true)); - } + if (locMap != null) { + addFullPartitionsMap(m, + dupData, + compress, + grp.groupId(), + locMap, + affCache.similarAffinityKey()); } + + if (exchId != null) + m.addPartitionUpdateCounters(grp.groupId(), grp.topology().updateCounters(true)); } - }); + } // It is important that client topologies be added after contexts. for (GridClientPartitionTopology top : cctx.exchange().clientTopologies()) { GridDhtPartitionFullMap map = top.partitionMap(true); - addFullPartitionsMap(m, - dupData, - compress, - top.cacheId(), - map, - top.similarAffinityKey()); + if (map != null) { + addFullPartitionsMap(m, + dupData, + compress, + top.groupId(), + map, + top.similarAffinityKey()); + } if (exchId != null) - m.addPartitionUpdateCounters(top.cacheId(), top.updateCounters(true)); + m.addPartitionUpdateCounters(top.groupId(), top.updateCounters(true)); } return m; @@ -950,19 +941,21 @@ public GridDhtPartitionsFullMessage createPartitionsFullMessage(Collection> dupData, boolean compress, - Integer cacheId, + Integer grpId, GridDhtPartitionFullMap map, Object affKey) { + assert map != null; + Integer dupDataCache = null; - if (compress && affKey != null && !m.containsCache(cacheId)) { + if (compress && affKey != null && !m.containsGroup(grpId)) { T2 state0 = dupData.get(affKey); if (state0 != null && state0.get2().partitionStateEquals(map)) { @@ -978,10 +971,10 @@ private void addFullPartitionsMap(GridDhtPartitionsFullMessage m, dupDataCache = state0.get1(); } else - dupData.put(affKey, new T2<>(cacheId, map)); + dupData.put(affKey, new T2<>(grpId, map)); } - m.addFullPartitionsMap(cacheId, map, dupDataCache); + m.addFullPartitionsMap(grpId, map, dupDataCache); } /** @@ -1029,24 +1022,24 @@ public GridDhtPartitionsSingleMessage createPartitionsSingleMessage(ClusterNode Map>> dupData = new HashMap<>(); - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (!cacheCtx.isLocal()) { - GridDhtPartitionMap locMap = cacheCtx.topology().localPartitionMap(); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (!grp.isLocal()) { + GridDhtPartitionMap locMap = grp.topology().localPartitionMap(); addPartitionMap(m, dupData, true, - cacheCtx.cacheId(), + grp.groupId(), locMap, - cacheCtx.affinity().affinityCache().similarAffinityKey()); + grp.affinity().similarAffinityKey()); if (sndCounters) - m.partitionUpdateCounters(cacheCtx.cacheId(), cacheCtx.topology().updateCounters(true)); + m.partitionUpdateCounters(grp.groupId(), grp.topology().updateCounters(true)); } } for (GridClientPartitionTopology top : clientTops.values()) { - if (m.partitions() != null && m.partitions().containsKey(top.cacheId())) + if (m.partitions() != null && m.partitions().containsKey(top.groupId())) continue; GridDhtPartitionMap locMap = top.localPartitionMap(); @@ -1054,12 +1047,12 @@ public GridDhtPartitionsSingleMessage createPartitionsSingleMessage(ClusterNode addPartitionMap(m, dupData, true, - top.cacheId(), + top.groupId(), locMap, top.similarAffinityKey()); if (sndCounters) - m.partitionUpdateCounters(top.cacheId(), top.updateCounters(true)); + m.partitionUpdateCounters(top.groupId(), top.updateCounters(true)); } return m; @@ -1257,22 +1250,19 @@ private void processFullPartitionUpdate(ClusterNode node, GridDhtPartitionsFullM boolean updated = false; for (Map.Entry entry : msg.partitions().entrySet()) { - Integer cacheId = entry.getKey(); - - GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + Integer grpId = entry.getKey(); - if (cacheCtx != null && !cacheCtx.started()) - continue; // Can safely ignore background exchange. + CacheGroupContext grp = cctx.cache().cacheGroup(grpId); GridDhtPartitionTopology top = null; - if (cacheCtx == null) - top = clientTops.get(cacheId); - else if (!cacheCtx.isLocal()) - top = cacheCtx.topology(); + if (grp == null) + top = clientTops.get(grpId); + else if (!grp.isLocal()) + top = grp.topology(); if (top != null) - updated |= top.update(null, entry.getValue(), null, msg.partsToReload(cctx.localNodeId(), cacheId)) != null; + updated |= top.update(null, entry.getValue(), null, msg.partsToReload(cctx.localNodeId(), grpId)) != null; } if (!cctx.kernalContext().clientNode() && updated) @@ -1280,9 +1270,10 @@ else if (!cacheCtx.isLocal()) boolean hasMovingParts = false; - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (!cacheCtx.isLocal() && cacheCtx.started() && cacheCtx.topology().hasMovingPartitions()) { + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (!grp.isLocal() && grp.topology().hasMovingPartitions()) { hasMovingParts = true; + break; } } @@ -1315,25 +1306,25 @@ private void processSinglePartitionUpdate(final ClusterNode node, final GridDhtP boolean updated = false; for (Map.Entry entry : msg.partitions().entrySet()) { - Integer cacheId = entry.getKey(); + Integer grpId = entry.getKey(); - GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + CacheGroupContext grp = cctx.cache().cacheGroup(grpId); - if (cacheCtx != null && - cacheCtx.startTopologyVersion().compareTo(entry.getValue().topologyVersion()) > 0) + if (grp != null && + grp.localStartVersion().compareTo(entry.getValue().topologyVersion()) > 0) continue; GridDhtPartitionTopology top = null; - if (cacheCtx == null) - top = clientTops.get(cacheId); - else if (!cacheCtx.isLocal()) - top = cacheCtx.topology(); + if (grp == null) + top = clientTops.get(grpId); + else if (!grp.isLocal()) + top = grp.topology(); if (top != null) { updated |= top.update(null, entry.getValue()) != null; - cctx.affinity().checkRebalanceState(top, cacheId); + cctx.affinity().checkRebalanceState(top, grpId); } } @@ -1422,8 +1413,8 @@ public void dumpDebugInfo(@Nullable AffinityTopologyVersion exchTopVer) throws E dumpPendingObjects(exchTopVer); - for (GridCacheContext cacheCtx : cctx.cacheContexts()) - cacheCtx.preloader().dumpDebugInfo(); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) + grp.preloader().dumpDebugInfo(); cctx.affinity().dumpDebugInfo(); @@ -1586,21 +1577,19 @@ private void dumpPendingObjects(@Nullable AffinityTopologyVersion exchTopVer) { } } - for (GridCacheContext ctx : cctx.cacheContexts()) { - if (ctx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - GridCacheContext ctx0 = ctx.isNear() ? ctx.near().dht().context() : ctx; - - GridCachePreloader preloader = ctx0.preloader(); + GridCachePreloader preloader = grp.preloader(); if (preloader != null) preloader.dumpDebugInfo(); - GridCacheAffinityManager affMgr = ctx0.affinity(); + GridAffinityAssignmentCache aff = grp.affinity(); - if (affMgr != null) - affMgr.dumpDebugInfo(); + if (aff != null) + aff.dumpDebugInfo(); } } @@ -1743,8 +1732,11 @@ void dumpExchangeDebugInfo() { try { boolean preloadFinished = true; - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - preloadFinished &= cacheCtx.preloader() != null && cacheCtx.preloader().syncFuture().isDone(); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) + continue; + + preloadFinished &= grp.preloader() != null && grp.preloader().syncFuture().isDone(); if (!preloadFinished) break; @@ -1851,11 +1843,11 @@ void dumpExchangeDebugInfo() { boolean changed = false; - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - changed |= cacheCtx.topology().afterExchange(exchFut); + changed |= grp.topology().afterExchange(exchFut); } if (!cctx.kernalContext().clientNode() && changed && !hasPendingExchange()) @@ -1875,16 +1867,16 @@ void dumpExchangeDebugInfo() { if (!exchFut.skipPreload() && cctx.kernalContext().state().active()) { assignsMap = new HashMap<>(); - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - long delay = cacheCtx.config().getRebalanceDelay(); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + long delay = grp.config().getRebalanceDelay(); GridDhtPreloaderAssignments assigns = null; // Don't delay for dummy reassigns to avoid infinite recursion. if (delay == 0 || forcePreload) - assigns = cacheCtx.preloader().assign(exchFut); + assigns = grp.preloader().assign(exchFut); - assignsMap.put(cacheCtx.cacheId(), assigns); + assignsMap.put(grp.groupId(), assigns); } } } @@ -1899,16 +1891,16 @@ void dumpExchangeDebugInfo() { NavigableMap> orderMap = new TreeMap<>(); for (Map.Entry e : assignsMap.entrySet()) { - int cacheId = e.getKey(); + int grpId = e.getKey(); - GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + CacheGroupContext grp = cctx.cache().cacheGroup(grpId); - int order = cacheCtx.config().getRebalanceOrder(); + int order = grp.config().getRebalanceOrder(); if (orderMap.get(order) == null) orderMap.put(order, new ArrayList(size)); - orderMap.get(order).add(cacheId); + orderMap.get(order).add(grpId); } Runnable r = null; @@ -1918,35 +1910,27 @@ void dumpExchangeDebugInfo() { boolean assignsCancelled = false; for (Integer order : orderMap.descendingKeySet()) { - for (Integer cacheId : orderMap.get(order)) { - GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + for (Integer grpId : orderMap.get(order)) { + CacheGroupContext grp = cctx.cache().cacheGroup(grpId); - GridDhtPreloaderAssignments assigns = assignsMap.get(cacheId); + GridDhtPreloaderAssignments assigns = assignsMap.get(grpId); if (assigns != null) assignsCancelled |= assigns.cancelled(); - List waitList = new ArrayList<>(size - 1); - - for (List cIds : orderMap.headMap(order).values()) { - for (Integer cId : cIds) - waitList.add(cctx.cacheContext(cId).name()); - } - // Cancels previous rebalance future (in case it's not done yet). // Sends previous rebalance stopped event (if necessary). // Creates new rebalance future. // Sends current rebalance started event (if necessary). // Finishes cache sync future (on empty assignments). - Runnable cur = cacheCtx.preloader().addAssignments(assigns, + Runnable cur = grp.preloader().addAssignments(assigns, forcePreload, - waitList, cnt, r, exchFut.forcedRebalanceFuture()); if (cur != null) { - rebList.add(U.maskName(cacheCtx.name())); + rebList.add(grp.cacheOrGroupName()); r = cur; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePreloader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePreloader.java index 5ae68e8b31485..0ac0272179454 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePreloader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePreloader.java @@ -22,6 +22,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtFuture; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicAbstractUpdateRequest; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage; @@ -44,18 +45,6 @@ public interface GridCachePreloader { */ public void start() throws IgniteCheckedException; - /** - * Stops preloading. - */ - public void stop(); - - /** - * Kernal start callback. - * - * @throws IgniteCheckedException If failed. - */ - public void onKernalStart() throws IgniteCheckedException; - /** * Kernal stop callback. */ @@ -90,7 +79,6 @@ public interface GridCachePreloader { */ public Runnable addAssignments(GridDhtPreloaderAssignments assignments, boolean forcePreload, - Collection caches, int cnt, Runnable next, @Nullable GridFutureAdapter forcedRebFut); @@ -136,20 +124,25 @@ public Runnable addAssignments(GridDhtPreloaderAssignments assignments, /** * Requests that preloader sends the request for the key. * + * @param cctx Cache context. * @param keys Keys to request. * @param topVer Topology version, {@code -1} if not required. * @return Future to complete when all keys are preloaded. */ - public IgniteInternalFuture request(Collection keys, AffinityTopologyVersion topVer); + public GridDhtFuture request(GridCacheContext cctx, + Collection keys, + AffinityTopologyVersion topVer); /** * Requests that preloader sends the request for the key. * + * @param cctx Cache context. * @param req Message with keys to request. * @param topVer Topology version, {@code -1} if not required. * @return Future to complete when all keys are preloaded. */ - public IgniteInternalFuture request(GridNearAtomicAbstractUpdateRequest req, + public GridDhtFuture request(GridCacheContext cctx, + GridNearAtomicAbstractUpdateRequest req, AffinityTopologyVersion topVer); /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePreloaderAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePreloaderAdapter.java index 47c37f56974fe..98874e42530bb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePreloaderAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePreloaderAdapter.java @@ -21,9 +21,9 @@ import java.util.UUID; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; -import org.apache.ignite.cache.affinity.AffinityFunction; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtFuture; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicAbstractUpdateRequest; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage; @@ -39,15 +39,15 @@ * Adapter for preloading which always assumes that preloading finished. */ public class GridCachePreloaderAdapter implements GridCachePreloader { - /** Cache context. */ - protected final GridCacheContext cctx; + /** */ + protected final CacheGroupContext grp; + + /** */ + protected final GridCacheSharedContext ctx; /** Logger. */ protected final IgniteLogger log; - /** Affinity. */ - protected final AffinityFunction aff; - /** Start future (always completed by default). */ private final IgniteInternalFuture finFut; @@ -55,15 +55,16 @@ public class GridCachePreloaderAdapter implements GridCachePreloader { protected IgnitePredicate preloadPred; /** - * @param cctx Cache context. + * @param grp Cache group. */ - public GridCachePreloaderAdapter(GridCacheContext cctx) { - assert cctx != null; + public GridCachePreloaderAdapter(CacheGroupContext grp) { + assert grp != null; - this.cctx = cctx; + this.grp = grp; - log = cctx.logger(getClass()); - aff = cctx.config().getAffinity(); + ctx = grp.shared(); + + log = ctx.logger(getClass()); finFut = new GridFinishedFuture(); } @@ -73,16 +74,6 @@ public GridCachePreloaderAdapter(GridCacheContext cctx) { // No-op. } - /** {@inheritDoc} */ - @Override public void stop() { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void onKernalStart() throws IgniteCheckedException { - // No-op. - } - /** {@inheritDoc} */ @Override public void onKernalStop() { // No-op. @@ -130,7 +121,7 @@ public GridCachePreloaderAdapter(GridCacheContext cctx) { /** {@inheritDoc} */ @Override public void unwindUndeploys() { - cctx.deploy().unwind(cctx); + grp.unwindUndeploys(); } /** {@inheritDoc} */ @@ -144,15 +135,15 @@ public GridCachePreloaderAdapter(GridCacheContext cctx) { } /** {@inheritDoc} */ - @Override public IgniteInternalFuture request(Collection keys, + @Override public GridDhtFuture request(GridCacheContext ctx, Collection keys, AffinityTopologyVersion topVer) { - return new GridFinishedFuture<>(); + return null; } /** {@inheritDoc} */ - @Override public IgniteInternalFuture request(GridNearAtomicAbstractUpdateRequest req, + @Override public GridDhtFuture request(GridCacheContext ctx, GridNearAtomicAbstractUpdateRequest req, AffinityTopologyVersion topVer) { - return new GridFinishedFuture<>(); + return null; } /** {@inheritDoc} */ @@ -168,7 +159,6 @@ public GridCachePreloaderAdapter(GridCacheContext cctx) { /** {@inheritDoc} */ @Override public Runnable addAssignments(GridDhtPreloaderAssignments assignments, boolean forcePreload, - Collection caches, int cnt, Runnable next, @Nullable GridFutureAdapter forcedRebFut) { 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 bf4691ba160d5..45e6a8bb766b4 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 @@ -74,6 +74,7 @@ import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; import org.apache.ignite.internal.processors.GridProcessorAdapter; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager; @@ -175,6 +176,9 @@ public class GridCacheProcessor extends GridProcessorAdapter { /** Shared cache context. */ private GridCacheSharedContext sharedCtx; + /** */ + private final ConcurrentMap cacheGrps = new ConcurrentHashMap<>(); + /** */ private final Map> caches; @@ -526,7 +530,7 @@ else if (cc.getRebalanceMode() == SYNC) { */ private List dhtManagers(GridCacheContext ctx) { return F.asList(ctx.store(), ctx.events(), ctx.evicts(), ctx.queries(), ctx.continuousQueries(), - ctx.dr(), ctx.offheap()); + ctx.dr()); } /** @@ -538,7 +542,7 @@ private Collection dhtExcludes(GridCacheContext ctx) { if (ctx.config().getCacheMode() == LOCAL || !isNearEnabled(ctx)) return Collections.emptyList(); else - return F.asList(ctx.queries(), ctx.continuousQueries(), ctx.store(), ctx.offheap()); + return F.asList(ctx.queries(), ctx.continuousQueries(), ctx.store()); } /** @@ -552,7 +556,6 @@ private void prepare(CacheConfiguration cfg, Collection objs) throws Ign prepare(cfg, cfg.getAffinityMapper(), false); prepare(cfg, cfg.getEvictionFilter(), false); prepare(cfg, cfg.getInterceptor(), false); - prepare(cfg, cfg.getTopologyValidator(), false); NearCacheConfiguration nearCfg = cfg.getNearConfiguration(); @@ -590,7 +593,6 @@ private void cleanup(GridCacheContext cctx) { cleanup(cfg, cfg.getAffinityMapper(), false); cleanup(cfg, cfg.getEvictionFilter(), false); cleanup(cfg, cfg.getInterceptor(), false); - cleanup(cfg, cfg.getTopologyValidator(), false); cleanup(cfg, cctx.store().configuredStore(), false); if (!CU.isUtilityCache(cfg.getName()) && !CU.isSystemCache(cfg.getName())) { @@ -606,6 +608,16 @@ private void cleanup(GridCacheContext cctx) { cctx.cleanup(); } + /** + * @param grp Cache group. + */ + private void cleanup(CacheGroupContext grp) { + CacheConfiguration cfg = grp.config(); + + for (Object obj : grp.configuredUserObjects()) + cleanup(cfg, obj, false); + } + /** * @param cfg Cache configuration. * @param rsrc Resource. @@ -720,10 +732,10 @@ else if (internalCaches.contains(cfg.getName())) else stopSeq.addFirst(cfg.getName()); - caches.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cfg, cacheType, sql, (byte)0)); + caches.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cfg, cacheType, sql, 0)); } else - templates.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cfg, CacheType.USER, false, (byte)0)); + templates.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cfg, CacheType.USER, false, 0)); } /** @@ -760,23 +772,21 @@ private void addCacheOnJoinFromPersistentStore( assert !ctx.config().isDaemon(); if (sharedCtx.pageStore() != null && sharedCtx.database().persistenceEnabled()) { - Set savedCacheNames = sharedCtx.pageStore().savedCacheNames(); + Map ccfgs = sharedCtx.pageStore().readCacheConfigurations(); - savedCacheNames.removeAll(caches.keySet()); + for (String cache : caches.keySet()) + ccfgs.remove(cache); - savedCacheNames.removeAll(internalCaches); + for (String cache : internalCaches) + ccfgs.remove(cache); - if (!F.isEmpty(savedCacheNames)) { + if (!F.isEmpty(ccfgs)) { if (log.isInfoEnabled()) - log.info("Register persistent caches: " + savedCacheNames); - - for (String name : savedCacheNames) { - CacheConfiguration cfg = sharedCtx.pageStore().readConfiguration(name); + log.info("Register persistent caches: " + ccfgs.keySet()); - // TODO IGNITE-5306 - set correct SQL flag below. - if (cfg != null) - addCacheOnJoin(cfg, false, caches, templates); - } + // TODO IGNITE-5306 - set correct SQL flag below. + for (CacheConfiguration ccfg : ccfgs.values()) + addCacheOnJoin(ccfg, false, caches, templates); } } } @@ -800,6 +810,21 @@ private void initializeInternalCacheNames() { internalCaches.add(CU.ATOMICS_CACHE_NAME); } + /** + * @param grpId Group ID. + * @return Cache group. + */ + @Nullable public CacheGroupContext cacheGroup(int grpId) { + return cacheGrps.get(grpId); + } + + /** + * @return Cache groups. + */ + public Collection cacheGroups() { + return cacheGrps.values(); + } + /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { @@ -824,14 +849,13 @@ private void initializeInternalCacheNames() { for (CacheConfiguration conf : ctx.config().getCacheConfiguration()) { assert conf.getName() != null; - for (DynamicCacheDescriptor desc : cacheDescriptors()) { + for (DynamicCacheDescriptor desc : cacheDescriptors().values()) { CacheConfiguration c = desc.cacheConfiguration(); - IgnitePredicate filter = c.getNodeFilter(); + IgnitePredicate filter = desc.groupDescriptor().config().getNodeFilter(); if (c.getName().equals(conf.getName()) && ((desc.receivedOnDiscovery() && CU.affinityNode(locNode, filter)) || CU.isSystemCache(c.getName()))) { - tmpCacheCfg.add(c); break; @@ -968,6 +992,9 @@ public void stopCaches(boolean cancel){ stopCache(cache, cancel, false); } + for (CacheGroupContext grp : cacheGrps.values()) + stopCacheGroup(grp.groupId()); + cachesInfo.clearCaches(); } @@ -990,6 +1017,9 @@ public void blockGateways() { // No new caches should be added after this point. exch.onKernalStop(cancel); + for (CacheGroupContext grp : cacheGrps.values()) + grp.onKernalStop(); + onKernalStopCaches(cancel); cancelFutures(); @@ -1009,11 +1039,13 @@ public void blockGateways() { * @param cancel Cancel. */ public void onKernalStopCaches(boolean cancel){ - for (GridCacheAdapter cache : caches.values()) { - GridCacheAffinityManager aff = cache.context().affinity(); + IgniteCheckedException affErr = + new IgniteCheckedException("Failed to wait for topology update, node is stopping."); - if (aff != null) - aff.cancelFutures(); + for (CacheGroupContext grp : cacheGrps.values()) { + GridAffinityAssignmentCache aff = grp.affinity(); + + aff.cancelFutures(affErr); } for (String cacheName : stopSeq) { @@ -1049,6 +1081,9 @@ public void onKernalStopCaches(boolean cancel){ for (IgniteInternalFuture fut : pendingTemplateFuts.values()) ((GridFutureAdapter)fut).onDone(err); + for (CacheGroupContext grp : cacheGrps.values()) + grp.onDisconnected(reconnectFut); + for (GridCacheAdapter cache : caches.values()) { GridCacheContext cctx = cache.context(); @@ -1068,37 +1103,35 @@ public void onKernalStopCaches(boolean cancel){ cachesInfo.onDisconnect(); } - /** {@inheritDoc} */ - @Override public IgniteInternalFuture onReconnected(boolean clusterRestarted) throws IgniteCheckedException { - List reconnected = new ArrayList<>(caches.size()); - - GridCompoundFuture stopFut = null; + /** + * @param cctx Cache context. + * @param stoppedCaches List where stopped cache should be added. + */ + private void stopCacheOnReconnect(GridCacheContext cctx, List stoppedCaches) { + cctx.gate().reconnected(true); - Set stoppedCaches = cachesInfo.onReconnected(); + sharedCtx.removeCacheContext(cctx); - for (final GridCacheAdapter cache : caches.values()) { - boolean stopped = stoppedCaches.contains(cache.name()); + caches.remove(cctx.name()); + jCacheProxies.remove(cctx.name()); - if (stopped) { - cache.context().gate().reconnected(true); + stoppedCaches.add(cctx.cache()); + } - sharedCtx.removeCacheContext(cache.ctx); + /** {@inheritDoc} */ + @Override public IgniteInternalFuture onReconnected(boolean clusterRestarted) throws IgniteCheckedException { + List reconnected = new ArrayList<>(caches.size()); - caches.remove(cache.name()); - jCacheProxies.remove(cache.name()); + ClusterCachesReconnectResult reconnectRes = cachesInfo.onReconnected(); - IgniteInternalFuture fut = ctx.closure().runLocalSafe(new Runnable() { - @Override public void run() { - onKernalStop(cache, true); - stopCache(cache, true, false); - } - }); + final List stoppedCaches = new ArrayList<>(); - if (stopFut == null) - stopFut = new GridCompoundFuture<>(); + for (final GridCacheAdapter cache : caches.values()) { + boolean stopped = reconnectRes.stoppedCacheGroups().contains(cache.context().groupId()) + || reconnectRes.stoppedCaches().contains(cache.name()); - stopFut.add((IgniteInternalFuture)fut); - } + if (stopped) + stopCacheOnReconnect(cache.context(), stoppedCaches); else { cache.onReconnected(); @@ -1110,7 +1143,7 @@ public void onKernalStopCaches(boolean cancel){ DynamicCacheDescriptor desc = cacheDescriptor(cctx.name()); - assert desc != null; + assert desc != null : cctx.name(); ctx.query().onCacheStop0(cctx.name()); ctx.query().onCacheStart0(cctx, desc.schema()); @@ -1118,13 +1151,37 @@ public void onKernalStopCaches(boolean cancel){ } } + final Set stoppedGrps = reconnectRes.stoppedCacheGroups(); + + for (CacheGroupContext grp : cacheGrps.values()) { + if (stoppedGrps.contains(grp.groupId())) + cacheGrps.remove(grp.groupId()); + else + grp.onReconnected(); + } + sharedCtx.onReconnected(); for (GridCacheAdapter cache : reconnected) cache.context().gate().reconnected(false); - if (stopFut != null) - stopFut.markInitialized(); + IgniteInternalFuture stopFut = null; + + if (!stoppedCaches.isEmpty()) { + stopFut = ctx.closure().runLocalSafe(new Runnable() { + @Override public void run() { + for (GridCacheAdapter cache : stoppedCaches) { + CacheGroupContext grp = cache.context().group(); + + onKernalStop(cache, true); + stopCache(cache, true, false); + + if (!grp.hasCaches()) + stopCacheGroup(grp); + } + } + }); + } return stopFut; } @@ -1138,11 +1195,6 @@ public void onKernalStopCaches(boolean cancel){ private void startCache(GridCacheAdapter cache, QuerySchema schema) throws IgniteCheckedException { GridCacheContext cacheCtx = cache.context(); - ctx.continuous().onCacheStart(cacheCtx); - - if (sharedCtx.pageStore() != null && !ctx.clientNode()) - sharedCtx.pageStore().initializeForCache(cacheCtx.config()); - CacheConfiguration cfg = cacheCtx.config(); // Intentionally compare Boolean references using '!=' below to check if the flag has been explicitly set. @@ -1173,18 +1225,22 @@ private void startCache(GridCacheAdapter cache, QuerySchema schema) throws log.debug("Started DHT cache: " + dhtCtx.cache().name()); } + ctx.continuous().onCacheStart(cacheCtx); + cacheCtx.cache().start(); ctx.query().onCacheStart(cacheCtx, schema); cacheCtx.onStarted(); - if (log.isInfoEnabled()) - log.info("Started cache [name=" + U.maskName(cfg.getName()) + + + if (log.isInfoEnabled()) { + log.info("Started cache [name=" + cfg.getName() + + (cfg.getGroupName() != null ? ", group=" + cfg.getGroupName() : "") + ", memoryPolicyName=" + cfg.getMemoryPolicyName() + ", mode=" + cfg.getCacheMode() + - ", atomicity=" + cfg.getAtomicityMode() + ']' - ); + ", atomicity=" + cfg.getAtomicityMode() + ']'); +} } /** @@ -1248,10 +1304,16 @@ private void stopCache(GridCacheAdapter cache, boolean cancel, boolean des ctx.kernalContext().cache().context().snapshot().onCacheStop(ctx); - U.stopLifecycleAware(log, lifecycleAwares(cache.configuration(), ctx.store().configuredStore())); + ctx.group().stopCache(ctx, destroy); - if (log.isInfoEnabled()) - log.info("Stopped cache: " + cache.name()); + U.stopLifecycleAware(log, lifecycleAwares(ctx.group(), cache.configuration(), ctx.store().configuredStore())); + + if (log.isInfoEnabled()) { + if (ctx.group().sharedGroup()) + log.info("Stopped cache [cacheName=" + cache.name() + ", group=" + ctx.group().name() + ']'); + else + log.info("Stopped cache [cacheName=" + cache.name() + ']'); + } cleanup(ctx); } @@ -1340,6 +1402,7 @@ private void onKernalStop(GridCacheAdapter cache, boolean cancel) { /** * @param cfg Cache configuration to use to create cache. + * @param grp Cache group. * @param pluginMgr Cache plugin manager. * @param desc Cache descriptor. * @param locStartTopVer Current topology version. @@ -1350,6 +1413,7 @@ private void onKernalStop(GridCacheAdapter cache, boolean cancel) { * @throws IgniteCheckedException If failed to create cache. */ private GridCacheContext createCache(CacheConfiguration cfg, + CacheGroupContext grp, @Nullable CachePluginManager pluginMgr, DynamicCacheDescriptor desc, AffinityTopologyVersion locStartTopVer, @@ -1394,7 +1458,7 @@ private GridCacheContext createCache(CacheConfiguration cfg, prepare(cfg, toPrepare); - U.startLifecycleAware(lifecycleAwares(cfg, cfgStore)); + U.startLifecycleAware(lifecycleAwares(grp, cfg, cfgStore)); boolean nearEnabled = GridCacheUtils.isNearEnabled(cfg); @@ -1410,46 +1474,17 @@ private GridCacheContext createCache(CacheConfiguration cfg, GridCacheDrManager drMgr = pluginMgr.createComponent(GridCacheDrManager.class); CacheStoreManager storeMgr = pluginMgr.createComponent(CacheStoreManager.class); - IgniteCacheOffheapManager offheapMgr; - - if (ctx.config().getPersistentStoreConfiguration() != null) { - ClassLoader clsLdr = U.gridClassLoader(); - - try { - offheapMgr = (IgniteCacheOffheapManager) clsLdr - .loadClass("org.apache.ignite.internal.processors.cache.database.GridCacheOffheapManager") - .getConstructor() - .newInstance(); - } - catch (Exception e) { - throw new IgniteCheckedException("Failed to initialize offheap manager", e); - } - } - else - offheapMgr = new IgniteCacheOffheapManagerImpl(); - - storeMgr.initialize(cfgStore, sesHolders); - String memPlcName = cfg.getMemoryPolicyName(); - - MemoryPolicy memPlc = sharedCtx.database().memoryPolicy(memPlcName); - FreeList freeList = sharedCtx.database().freeList(memPlcName); - ReuseList reuseList = sharedCtx.database().reuseList(memPlcName); - GridCacheContext cacheCtx = new GridCacheContext( ctx, sharedCtx, cfg, + grp, desc.cacheType(), locStartTopVer, - desc.receivedFrom(), affNode, updatesAllowed, - memPlc, - freeList, - reuseList, - /* * Managers in starting order! * =========================== @@ -1462,7 +1497,6 @@ private GridCacheContext createCache(CacheConfiguration cfg, dataStructuresMgr, ttlMgr, drMgr, - offheapMgr, rslvrMgr, pluginMgr, affMgr @@ -1518,14 +1552,14 @@ private GridCacheContext createCache(CacheConfiguration cfg, case TRANSACTIONAL: { cache = cacheCtx.affinityNode() ? new GridDhtColocatedCache(cacheCtx) : - new GridDhtColocatedCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx)); + new GridDhtColocatedCache(cacheCtx, new GridNoStorageCacheMap()); break; } case ATOMIC: { cache = cacheCtx.affinityNode() ? new GridDhtAtomicCache(cacheCtx) : - new GridDhtAtomicCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx)); + new GridDhtAtomicCache(cacheCtx, new GridNoStorageCacheMap()); break; } @@ -1574,15 +1608,11 @@ private GridCacheContext createCache(CacheConfiguration cfg, ctx, sharedCtx, cfg, + grp, desc.cacheType(), locStartTopVer, - desc.receivedFrom(), affNode, true, - memPlc, - freeList, - reuseList, - /* * Managers in starting order! * =========================== @@ -1595,7 +1625,6 @@ private GridCacheContext createCache(CacheConfiguration cfg, dataStructuresMgr, ttlMgr, drMgr, - offheapMgr, rslvrMgr, pluginMgr, affMgr @@ -1613,7 +1642,7 @@ private GridCacheContext createCache(CacheConfiguration cfg, GridDhtCache dhtCache = cacheCtx.affinityNode() ? new GridDhtCache(cacheCtx) : - new GridDhtCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx)); + new GridDhtCache(cacheCtx, new GridNoStorageCacheMap()); dhtCache.near(near); @@ -1630,7 +1659,7 @@ private GridCacheContext createCache(CacheConfiguration cfg, GridDhtAtomicCache dhtCache = cacheCtx.affinityNode() ? new GridDhtAtomicCache(cacheCtx) : - new GridDhtAtomicCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx)); + new GridDhtAtomicCache(cacheCtx, new GridNoStorageCacheMap()); dhtCache.near(near); @@ -1663,11 +1692,12 @@ private GridCacheContext createCache(CacheConfiguration cfg, * @return Collection of started cache names. */ public Collection cacheNames() { - return F.viewReadOnly(cacheDescriptors(), new IgniteClosure() { - @Override public String apply(DynamicCacheDescriptor desc) { - return desc.cacheConfiguration().getName(); - } - }); + return F.viewReadOnly(cacheDescriptors().values(), + new IgniteClosure() { + @Override public String apply(DynamicCacheDescriptor desc) { + return desc.cacheConfiguration().getName(); + } + }); } /** @@ -1712,7 +1742,7 @@ public Collection cacheNames() { * @return Collection of currently started public cache names */ public Collection publicCacheNames() { - return F.viewReadOnly(cacheDescriptors(), + return F.viewReadOnly(cacheDescriptors().values(), new IgniteClosure() { @Override public String apply(DynamicCacheDescriptor desc) { return desc.cacheConfiguration().getName(); @@ -1751,6 +1781,7 @@ void prepareCacheStart(DynamicCacheDescriptor cacheDesc, AffinityTopologyVersion exchTopVer) throws IgniteCheckedException { prepareCacheStart( + cacheDesc.groupDescriptor(), cacheDesc.cacheConfiguration(), nearCfg, cacheDesc, @@ -1771,6 +1802,7 @@ public void startCachesOnLocalJoin(AffinityTopologyVersion exchTopVer) throws Ig DynamicCacheDescriptor desc = t.get1(); prepareCacheStart( + desc.groupDescriptor(), desc.cacheConfiguration(), t.get2(), desc, @@ -1795,10 +1827,11 @@ public Collection startReceivedCaches(UUID nodeId, Affin if (started != null) { for (DynamicCacheDescriptor desc : started) { - IgnitePredicate filter = desc.cacheConfiguration().getNodeFilter(); + IgnitePredicate filter = desc.groupDescriptor().config().getNodeFilter(); if (CU.affinityNode(ctx.discovery().localNode(), filter)) { prepareCacheStart( + desc.groupDescriptor(), desc.cacheConfiguration(), null, desc, @@ -1813,6 +1846,7 @@ public Collection startReceivedCaches(UUID nodeId, Affin } /** + * @param grpDesc Cache group descriptor. * @param startCfg Start configuration. * @param reqNearCfg Near configuration if specified for client cache start request. * @param desc Cache descriptor. @@ -1821,6 +1855,7 @@ public Collection startReceivedCaches(UUID nodeId, Affin * @throws IgniteCheckedException If failed. */ private void prepareCacheStart( + CacheGroupDescriptor grpDesc, CacheConfiguration startCfg, @Nullable NearCacheConfiguration reqNearCfg, DynamicCacheDescriptor desc, @@ -1844,7 +1879,7 @@ private void prepareCacheStart( ccfg.setNearConfiguration(null); } - else if (CU.affinityNode(ctx.discovery().localNode(), ccfg.getNodeFilter())) + else if (CU.affinityNode(ctx.discovery().localNode(), grpDesc.config().getNodeFilter())) affNode = true; else { affNode = false; @@ -1852,7 +1887,40 @@ else if (CU.affinityNode(ctx.discovery().localNode(), ccfg.getNodeFilter())) ccfg.setNearConfiguration(reqNearCfg); } + if (sharedCtx.pageStore() != null && affNode) + sharedCtx.pageStore().initializeForCache(grpDesc, startCfg); + + String grpName = startCfg.getGroupName(); + + CacheGroupContext grp = null; + + if (grpName != null) { + for (CacheGroupContext grp0 : cacheGrps.values()) { + if (grp0.sharedGroup() && grpName.equals(grp0.name())) { + grp = grp0; + + break; + } + } + + if (grp == null) { + grp = startCacheGroup(grpDesc, + desc.cacheType(), + affNode, + cacheObjCtx, + exchTopVer); + } + } + else { + grp = startCacheGroup(grpDesc, + desc.cacheType(), + affNode, + cacheObjCtx, + exchTopVer); + } + GridCacheContext cacheCtx = createCache(ccfg, + grp, null, desc, exchTopVer, @@ -1870,12 +1938,64 @@ else if (CU.affinityNode(ctx.discovery().localNode(), ccfg.getNodeFilter())) startCache(cache, schema != null ? schema : new QuerySchema()); + grp.onCacheStarted(cacheCtx); + onKernalStart(cache); if (proxyRestart) proxy.onRestarted(cacheCtx, cache); } + /** + * @param desc Group descriptor. + * @param cacheType Cache type. + * @param affNode Affinity node flag. + * @param cacheObjCtx Cache object context. + * @param exchTopVer Current topology version. + * @return Started cache group. + * @throws IgniteCheckedException If failed. + */ + private CacheGroupContext startCacheGroup( + CacheGroupDescriptor desc, + CacheType cacheType, + boolean affNode, + CacheObjectContext cacheObjCtx, + AffinityTopologyVersion exchTopVer) + throws IgniteCheckedException { + CacheConfiguration cfg = new CacheConfiguration(desc.config()); + + String memPlcName = cfg.getMemoryPolicyName(); + + MemoryPolicy memPlc = sharedCtx.database().memoryPolicy(memPlcName); + FreeList freeList = sharedCtx.database().freeList(memPlcName); + ReuseList reuseList = sharedCtx.database().reuseList(memPlcName); + + CacheGroupContext grp = new CacheGroupContext(sharedCtx, + desc.groupId(), + desc.receivedFrom(), + cacheType, + cfg, + affNode, + memPlc, + cacheObjCtx, + freeList, + reuseList, + exchTopVer); + + for (Object obj : grp.configuredUserObjects()) + prepare(cfg, obj, false); + + U.startLifecycleAware(grp.configuredUserObjects()); + + grp.start(); + + CacheGroupContext old = cacheGrps.put(desc.groupId(), grp); + + assert old == null : old.name(); + + return grp; + } + /** * @param req Stop request. */ @@ -1958,8 +2078,8 @@ void forceCloseCache( Throwable err ) { ExchangeActions actions = new ExchangeActions(){ - @Override List closeRequests(UUID nodeId) { - return Collections.singletonList(act.request()); + @Override List closeRequests(UUID nodeId) { + return Collections.singletonList(act); } }; @@ -1992,11 +2112,12 @@ public void onExchangeDone( } if (exchActions != null && (err == null || forceClose)) { - Collection> stopped = null; + Collection> stoppedGrps = null; - GridCacheContext stopCtx = null; - boolean destroy = false; for (ExchangeActions.ActionData action : exchActions.cacheStopRequests()) { + GridCacheContext stopCtx; + boolean destroy; + stopGateway(action.request()); sharedCtx.database().checkpointReadLock(); @@ -2009,16 +2130,19 @@ public void onExchangeDone( sharedCtx.database().checkpointReadUnlock(); } - if (stopCtx != null) { - if (stopped == null) - stopped = new ArrayList<>(); + if (stopCtx != null && !stopCtx.group().hasCaches()) { + if (stoppedGrps == null) + stoppedGrps = new ArrayList<>(); - stopped.add(F.t(stopCtx, destroy)); + stoppedGrps.add(F.t(stopCtx.group(), destroy)); } } - for (DynamicCacheChangeRequest req : exchActions.closeRequests(ctx.localNodeId())) { - String cacheName = req.cacheName(); + for (CacheGroupDescriptor grpDesc : exchActions.cacheGroupsToStop()) + stopCacheGroup(grpDesc.groupId()); + + for (ExchangeActions.ActionData req : exchActions.closeRequests(ctx.localNodeId())) { + String cacheName = req.request().cacheName(); IgniteCacheProxy proxy = jCacheProxies.remove(cacheName); @@ -2031,7 +2155,7 @@ public void onExchangeDone( jCacheProxies.putIfAbsent(cacheName, new IgniteCacheProxy(cache.context(), cache, null, false)); } else { - if (req.restart()) + if (req.request().restart()) proxy.restart(); proxy.context().gate().onStopped(); @@ -2039,8 +2163,14 @@ public void onExchangeDone( sharedCtx.database().checkpointReadLock(); try { - stopCtx = prepareCacheStop(req, forceClose); - destroy = req.destroy(); + GridCacheContext stopCtx = prepareCacheStop(req.request(), forceClose); + + if (stopCtx != null && !stopCtx.group().hasCaches()) { + assert !stopCtx.group().affinityNode() : stopCtx.name(); + + stopCacheGroup(stopCtx.groupId()); + } + } finally { sharedCtx.database().checkpointReadUnlock(); @@ -2048,23 +2178,36 @@ public void onExchangeDone( } } - if (stopCtx != null) { - if (stopped == null) - stopped = new ArrayList<>(); - - stopped.add(F.t(stopCtx, destroy)); - } - if (forceClose) - completeCacheStartFuture(req, false, err); - + completeCacheStartFuture(req.request(), false, err); } - if (stopped != null && !sharedCtx.kernalContext().clientNode()) - sharedCtx.database().onCachesStopped(stopped); + if (stoppedGrps != null && !sharedCtx.kernalContext().clientNode()) + sharedCtx.database().onCacheGroupsStopped(stoppedGrps); } } + /** + * @param grpId Group ID. + */ + private void stopCacheGroup(int grpId) { + CacheGroupContext grp = cacheGrps.remove(grpId); + + if (grp != null) + stopCacheGroup(grp); + } + + /** + * @param grp Cache group. + */ + private void stopCacheGroup(CacheGroupContext grp) { + grp.stopGroup(); + + U.stopLifecycleAware(log, grp.configuredUserObjects()); + + cleanup(grp); + } + /** * @param cacheName Cache name. * @param deploymentId Future deployment ID. @@ -2607,17 +2750,13 @@ public Collection startAllCachesRequests() throws Ign if (!ctx.config().isDaemon() && sharedCtx.pageStore() != null && sharedCtx.database().persistenceEnabled()) { - Set savedCacheNames = sharedCtx.pageStore().savedCacheNames(); + Map savedCaches = sharedCtx.pageStore().readCacheConfigurations(); - for (String name : savedCacheNames) { - CacheConfiguration cfg = sharedCtx.pageStore().readConfiguration(name); - - if (cfg != null) - reqs.add(createRequest(cfg, false)); - } + for (CacheConfiguration cfg : savedCaches.values()) + reqs.add(createRequest(cfg, false)); for (CacheConfiguration cfg : ctx.config().getCacheConfiguration()) { - if (!savedCacheNames.contains(cfg.getName())) + if (!savedCaches.containsKey(cfg.getName())) reqs.add(createRequest(cfg, true)); } } @@ -2716,6 +2855,16 @@ private Collection initiateCacheChanges( } } } + if (req.start() && req.startCacheConfiguration() != null) { + CacheConfiguration ccfg = req.startCacheConfiguration(); + + try { + cachesInfo.validateStartCacheConfiguration(ccfg); + } + catch (IgniteCheckedException e) { + fut.onDone(e); + } + } if (fut.isDone()) continue; @@ -2831,7 +2980,7 @@ private int validatePreloadOrder(CacheConfiguration[] cfgs) throws IgniteChecked } else if (rebalanceOrder < 0) throw new IgniteCheckedException("Rebalance order cannot be negative for cache (fix configuration and restart " + - "the node) [cacheName=" + U.maskName(cfg.getName()) + ", rebalanceOrder=" + rebalanceOrder + ']'); + "the node) [cacheName=" + cfg.getName() + ", rebalanceOrder=" + rebalanceOrder + ']'); } return maxOrder; @@ -2848,7 +2997,7 @@ else if (rebalanceOrder < 0) */ @Nullable private IgniteNodeValidationResult validateHashIdResolvers(ClusterNode node) { if (!node.isClient()) { - for (DynamicCacheDescriptor desc : cacheDescriptors()) { + for (DynamicCacheDescriptor desc : cacheDescriptors().values()) { CacheConfiguration cfg = desc.cacheConfiguration(); if (cfg.getAffinity() instanceof RendezvousAffinityFunction) { @@ -2862,11 +3011,11 @@ else if (rebalanceOrder < 0) if (nodeHashObj.hashCode() == topNodeHashObj.hashCode()) { String errMsg = "Failed to add node to topology because it has the same hash code for " + "partitioned affinity as one of existing nodes [cacheName=" + - U.maskName(cfg.getName()) + ", existingNodeId=" + topNode.id() + ']'; + cfg.getName() + ", existingNodeId=" + topNode.id() + ']'; String sndMsg = "Failed to add node to topology because it has the same hash code for " + "partitioned affinity as one of existing nodes [cacheName=" + - U.maskName(cfg.getName()) + ", existingNodeId=" + topNode.id() + ']'; + cfg.getName() + ", existingNodeId=" + topNode.id() + ']'; return new IgniteNodeValidationResult(topNode.id(), errMsg, sndMsg); } @@ -3125,8 +3274,15 @@ public DynamicCacheDescriptor cacheDescriptor(String name) { /** * @return Cache descriptors. */ - public Collection cacheDescriptors() { - return cachesInfo.registeredCaches().values(); + public Map cacheDescriptors() { + return cachesInfo.registeredCaches(); + } + + /** + * @return Cache group descriptors. + */ + public Map cacheGroupDescriptors() { + return cachesInfo.registeredCacheGroups(); } /** @@ -3134,7 +3290,7 @@ public Collection cacheDescriptors() { * @return Cache descriptor. */ @Nullable public DynamicCacheDescriptor cacheDescriptor(int cacheId) { - for (DynamicCacheDescriptor cacheDesc : cacheDescriptors()) { + for (DynamicCacheDescriptor cacheDesc : cacheDescriptors().values()) { CacheConfiguration ccfg = cacheDesc.cacheConfiguration(); assert ccfg != null : cacheDesc; @@ -3428,19 +3584,21 @@ private void unregisterMbean(Object o, @Nullable String cacheName, boolean near) } /** + * @param grp Cache group. * @param ccfg Cache configuration. * @param objs Extra components. * @return Components provided in cache configuration which can implement {@link LifecycleAware} interface. */ - private Iterable lifecycleAwares(CacheConfiguration ccfg, Object... objs) { + private Iterable lifecycleAwares(CacheGroupContext grp, CacheConfiguration ccfg, Object... objs) { Collection ret = new ArrayList<>(7 + objs.length); - ret.add(ccfg.getAffinity()); + if (grp.affinityFunction() != ccfg.getAffinity()) + ret.add(ccfg.getAffinity()); + ret.add(ccfg.getAffinityMapper()); ret.add(ccfg.getEvictionFilter()); ret.add(ccfg.getEvictionPolicy()); ret.add(ccfg.getInterceptor()); - ret.add(ccfg.getTopologyValidator()); NearCacheConfiguration nearCfg = ccfg.getNearConfiguration(); @@ -3811,12 +3969,12 @@ private class RemovedItemsCleanupTask implements GridTimeoutObject { ctx.closure().runLocalSafe(new Runnable() { @Override public void run() { try { - for (GridCacheContext cacheCtx : sharedCtx.cacheContexts()) { - if (!cacheCtx.isLocal() && cacheCtx.affinityNode()) { + for (CacheGroupContext grp : sharedCtx.cache().cacheGroups()) { + if (!grp.isLocal() && grp.affinityNode()) { GridDhtPartitionTopology top = null; try { - top = cacheCtx.topology(); + top = grp.topology(); } catch (IllegalStateException ignore) { // Cache stopped. 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 04f5b857e8f5b..be1ab3d4c93e5 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 @@ -415,7 +415,7 @@ public void addCacheContext(GridCacheContext cacheCtx) throws IgniteCheckedExcep /** * @param cacheCtx Cache context to remove. */ - public void removeCacheContext(GridCacheContext cacheCtx) { + void removeCacheContext(GridCacheContext cacheCtx) { int cacheId = cacheCtx.cacheId(); ctxMap.remove(cacheId, cacheCtx); @@ -426,7 +426,7 @@ public void removeCacheContext(GridCacheContext cacheCtx) { locStoreCnt.decrementAndGet(); // Safely clean up the message listeners. - ioMgr.removeHandlers(cacheId); + ioMgr.removeCacheHandlers(cacheId); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java index 614b3e3b197a3..e7e6aecff2767 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java @@ -38,7 +38,13 @@ */ public class GridCacheTtlManager extends GridCacheManagerAdapter { /** Entries pending removal. */ - private GridConcurrentSkipListSetEx pendingEntries; + private GridConcurrentSkipListSetEx pendingEntries; + + /** */ + private boolean eagerTtlEnabled; + + /** */ + private GridCacheContext dhtCtx; /** */ private final IgniteInClosure2X expireC = @@ -70,6 +76,8 @@ public class GridCacheTtlManager extends GridCacheManagerAdapter { /** {@inheritDoc} */ @Override protected void start0() throws IgniteCheckedException { + dhtCtx = cctx.isNear() ? cctx.near().dht().context() : cctx; + boolean cleanupDisabled = cctx.kernalContext().isDaemon() || !cctx.config().isEagerTtl() || CU.isAtomicsCache(cctx.name()) || @@ -79,11 +87,20 @@ public class GridCacheTtlManager extends GridCacheManagerAdapter { if (cleanupDisabled) return; + eagerTtlEnabled = true; + cctx.shared().ttl().register(this); pendingEntries = (!cctx.isLocal() && cctx.config().getNearConfiguration() != null) ? new GridConcurrentSkipListSetEx() : null; } + /** + * @return {@code True} if eager ttl is enabled for cache. + */ + public boolean eagerTtlEnabled() { + return eagerTtlEnabled; + } + /** {@inheritDoc} */ @Override protected void onKernalStop0(boolean cancel) { if (pendingEntries != null) @@ -153,7 +170,6 @@ public boolean expire(int amount) { try { if (pendingEntries != null) { - //todo may be not only for near? may be for local too. GridNearCacheAdapter nearCache = cctx.near(); GridCacheVersion obsoleteVer = null; @@ -178,7 +194,7 @@ public boolean expire(int amount) { } } - boolean more = cctx.offheap().expire(expireC, amount); + boolean more = cctx.offheap().expire(dhtCtx, expireC, amount); if (more) return true; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java index 4dc5f8eef7f9e..0b11900234fc8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java @@ -467,7 +467,7 @@ public static Collection remoteNodes(final GridCacheSharedContext c * @return All nodes on which cache with the same name is started. */ public static Collection affinityNodes(final GridCacheContext ctx) { - return ctx.discovery().cacheAffinityNodes(ctx.cacheId(), AffinityTopologyVersion.NONE); + return ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), AffinityTopologyVersion.NONE); } /** @@ -478,7 +478,7 @@ public static Collection affinityNodes(final GridCacheContext ctx) * @return Affinity nodes. */ public static Collection affinityNodes(GridCacheContext ctx, AffinityTopologyVersion topOrder) { - return ctx.discovery().cacheAffinityNodes(ctx.cacheId(), topOrder); + return ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), topOrder); } /** @@ -989,6 +989,44 @@ public static void checkAttributeMismatch(IgniteLogger log, String cfgName, UUID } } } + /** + * @param cfg1 Existing configuration. + * @param cfg2 Cache configuration to start. + * @param attrName Short attribute name for error message. + * @param attrMsg Full attribute name for error message. + * @param val1 Attribute value in existing configuration. + * @param val2 Attribute value in starting configuration. + * @param fail If true throws IgniteCheckedException in case of attribute values mismatch, otherwise logs warning. + * @throws IgniteCheckedException If validation failed. + */ + public static void validateCacheGroupsAttributesMismatch(IgniteLogger log, + CacheConfiguration cfg1, + CacheConfiguration cfg2, + String attrName, + String attrMsg, + Object val1, + Object val2, + boolean fail) throws IgniteCheckedException { + if (F.eq(val1, val2)) + return; + + if (fail) { + throw new IgniteCheckedException(attrMsg + " mismatch for caches related to the same group " + + "[groupName=" + cfg1.getGroupName() + + ", existingCache=" + cfg1.getName() + + ", existing" + capitalize(attrName) + "=" + val1 + + ", startingCache=" + cfg2.getName() + + ", starting" + capitalize(attrName) + "=" + val2 + ']'); + } + else { + U.warn(log, attrMsg + " mismatch for caches related to the same group " + + "[groupName=" + cfg1.getGroupName() + + ", existingCache=" + cfg1.getName() + + ", existing" + capitalize(attrName) + "=" + val1 + + ", startingCache=" + cfg2.getName() + + ", starting" + capitalize(attrName) + "=" + val2 + ']'); + } + } /** * @param str String. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java index 0d04ccb8fd11a..e49be4934eeb9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridChangeGlobalStateMessageResponse.java @@ -59,6 +59,16 @@ public GridChangeGlobalStateMessageResponse(UUID requestId, Throwable err) { this.err = err; } + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return false; + } + + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + /** * */ @@ -106,13 +116,13 @@ public Throwable getError() { } switch (writer.state()) { - case 3: + case 2: if (!writer.writeByteArray("errBytes", errBytes)) return false; writer.incrementState(); - case 4: + case 3: if (!writer.writeUuid("requestId", requestId)) return false; @@ -134,7 +144,7 @@ public Throwable getError() { return false; switch (reader.state()) { - case 3: + case 2: errBytes = reader.readByteArray("errBytes"); if (!reader.isLastRead()) @@ -142,7 +152,7 @@ public Throwable getError() { reader.incrementState(); - case 4: + case 3: requestId = reader.readUuid("requestId"); if (!reader.isLastRead()) @@ -162,7 +172,7 @@ public Throwable getError() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 5; + return 4; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridNoStorageCacheMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridNoStorageCacheMap.java index 5e52c8bc2acc5..77a9ba43d799b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridNoStorageCacheMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridNoStorageCacheMap.java @@ -22,30 +22,19 @@ import java.util.Set; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; -import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException; import org.jetbrains.annotations.Nullable; /** * Empty cache map that will never store any entries. */ public class GridNoStorageCacheMap implements GridCacheConcurrentMap { - /** Context. */ - private final GridCacheContext ctx; - - /** - * @param ctx Cache context. - */ - public GridNoStorageCacheMap(GridCacheContext ctx) { - this.ctx = ctx; - } - /** {@inheritDoc} */ - @Nullable @Override public GridCacheMapEntry getEntry(KeyCacheObject key) { + @Nullable @Override public GridCacheMapEntry getEntry(GridCacheContext ctx, KeyCacheObject key) { return null; } /** {@inheritDoc} */ - @Override public GridCacheMapEntry putEntryIfObsoleteOrAbsent(AffinityTopologyVersion topVer, + @Override public GridCacheMapEntry putEntryIfObsoleteOrAbsent(GridCacheContext ctx, AffinityTopologyVersion topVer, KeyCacheObject key, boolean create, boolean touch) { @@ -66,32 +55,27 @@ public GridNoStorageCacheMap(GridCacheContext ctx) { } /** {@inheritDoc} */ - @Override public int publicSize() { + @Override public int publicSize(int cacheId) { return 0; } /** {@inheritDoc} */ - @Override public void incrementPublicSize(GridCacheEntryEx e) { + @Override public void incrementPublicSize(CacheMapHolder hld, GridCacheEntryEx e) { // No-op. } /** {@inheritDoc} */ - @Override public void decrementPublicSize(GridCacheEntryEx e) { + @Override public void decrementPublicSize(CacheMapHolder hld, GridCacheEntryEx e) { // No-op. } /** {@inheritDoc} */ - @Override public Iterable entries(CacheEntryPredicate... filter) { - return Collections.emptySet(); - } - - /** {@inheritDoc} */ - @Override public Iterable allEntries(CacheEntryPredicate... filter) { + @Override public Iterable entries(int cacheId, CacheEntryPredicate... filter) { return Collections.emptySet(); } /** {@inheritDoc} */ - @Override public Set entrySet(CacheEntryPredicate... filter) { + @Override public Set entrySet(int cacheId, CacheEntryPredicate... filter) { return Collections.emptySet(); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java index 5bcefda8d94e7..8951396f1133a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.processors.cache; +import java.util.Map; import javax.cache.Cache; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; @@ -38,7 +39,36 @@ * */ @SuppressWarnings("WeakerAccess") -public interface IgniteCacheOffheapManager extends GridCacheManager { +public interface IgniteCacheOffheapManager { + /** + * @param ctx Context. + * @param grp Cache group. + * @throws IgniteCheckedException If failed. + */ + public void start(GridCacheSharedContext ctx, CacheGroupContext grp) throws IgniteCheckedException;; + + /** + * @param cctx Cache context. + * @throws IgniteCheckedException If failed. + */ + public void onCacheStarted(GridCacheContext cctx) throws IgniteCheckedException; + + /** + * + */ + public void onKernalStop(); + + /** + * @param cacheId Cache ID. + * @param destroy Destroy data flag. + */ + public void stopCache(int cacheId, boolean destroy); + + /** + * + */ + public void stop(); + /** * Partition counter update callback. May be overridden by plugin-provided subclasses. * @@ -71,11 +101,12 @@ public interface IgniteCacheOffheapManager extends GridCacheManager { @Nullable public CacheDataRow read(GridCacheMapEntry entry) throws IgniteCheckedException; /** + * @param cctx Cache context. * @param key Key. * @return Cached row, if available, null otherwise. * @throws IgniteCheckedException If failed. */ - @Nullable public CacheDataRow read(KeyCacheObject key) throws IgniteCheckedException; + @Nullable public CacheDataRow read(GridCacheContext cctx, KeyCacheObject key) throws IgniteCheckedException; /** * @param p Partition. @@ -97,6 +128,7 @@ public interface IgniteCacheOffheapManager extends GridCacheManager { /** * @param store Data store. + * @throws IgniteCheckedException If failed. */ public void destroyCacheDataStore(CacheDataStore store) throws IgniteCheckedException; @@ -106,10 +138,12 @@ public interface IgniteCacheOffheapManager extends GridCacheManager { public boolean containsKey(GridCacheMapEntry entry); /** + * @param cctx Cache context. * @param c Closure. * @throws IgniteCheckedException If failed. */ - public boolean expire(IgniteInClosure2X c, int amount) throws IgniteCheckedException; + public boolean expire(GridCacheContext cctx, IgniteInClosure2X c, int amount) + throws IgniteCheckedException; /** * Gets the number of entries pending expire. @@ -120,15 +154,17 @@ public interface IgniteCacheOffheapManager extends GridCacheManager { public long expiredSize() throws IgniteCheckedException; /** + * @param cctx Cache context. * @param key Key. * @param part Partition. * @param c Tree update closure. * @throws IgniteCheckedException If failed. */ - public void invoke(KeyCacheObject key, GridDhtLocalPartition part, OffheapInvokeClosure c) + public void invoke(GridCacheContext cctx, KeyCacheObject key, GridDhtLocalPartition part, OffheapInvokeClosure c) throws IgniteCheckedException; /** + * @param cctx Cache context. * @param key Key. * @param val Value. * @param ver Version. @@ -138,6 +174,7 @@ public void invoke(KeyCacheObject key, GridDhtLocalPartition part, OffheapInvoke * @throws IgniteCheckedException If failed. */ public void update( + GridCacheContext cctx, KeyCacheObject key, CacheObject val, GridCacheVersion ver, @@ -147,22 +184,26 @@ public void update( ) throws IgniteCheckedException; /** + * @param cctx Cache context. * @param key Key. * @param part Partition. * @throws IgniteCheckedException If failed. */ public void updateIndexes( + GridCacheContext cctx, KeyCacheObject key, GridDhtLocalPartition part ) throws IgniteCheckedException; /** + * @param cctx Cache context. * @param key Key. * @param partId Partition number. * @param part Partition. * @throws IgniteCheckedException If failed. */ public void remove( + GridCacheContext cctx, KeyCacheObject key, int partId, GridDhtLocalPartition part @@ -175,24 +216,37 @@ public void remove( public int onUndeploy(ClassLoader ldr); /** + * @param cacheId Cache ID. * @param primary Primary entries flag. * @param backup Backup entries flag. * @param topVer Topology version. * @return Rows iterator. * @throws IgniteCheckedException If failed. */ - public GridIterator iterator(boolean primary, boolean backup, final AffinityTopologyVersion topVer) + public GridIterator cacheIterator(int cacheId, + boolean primary, + boolean backup, + final AffinityTopologyVersion topVer) throws IgniteCheckedException; /** + * @param cacheId Cache ID. * @param part Partition. * @return Partition data iterator. * @throws IgniteCheckedException If failed. */ - public GridIterator iterator(final int part) throws IgniteCheckedException; + public GridIterator cachePartitionIterator(int cacheId, final int part) throws IgniteCheckedException; + + /** + * @param part Partition number. + * @return Iterator for given partition. + * @throws IgniteCheckedException If failed. + */ + public GridIterator partitionIterator(final int part) throws IgniteCheckedException; /** * @param part Partition. + * @param topVer Topology version. * @param partCntr Partition counter to get historical data if available. * @return Partition data iterator. * @throws IgniteCheckedException If failed. @@ -201,6 +255,7 @@ public IgniteRebalanceIterator rebalanceIterator(int part, AffinityTopologyVersi throws IgniteCheckedException; /** + * @param cctx Cache context. * @param primary Primary entries flag. * @param backup Backup entries flag. * @param topVer Topology version. @@ -208,40 +263,47 @@ public IgniteRebalanceIterator rebalanceIterator(int part, AffinityTopologyVersi * @return Entries iterator. * @throws IgniteCheckedException If failed. */ - public GridCloseableIterator> entriesIterator(final boolean primary, + public GridCloseableIterator> cacheEntriesIterator( + GridCacheContext cctx, + final boolean primary, final boolean backup, final AffinityTopologyVersion topVer, final boolean keepBinary) throws IgniteCheckedException; /** + * @param cacheId Cache ID. * @param part Partition. * @return Iterator. * @throws IgniteCheckedException If failed. */ - public GridCloseableIterator keysIterator(final int part) throws IgniteCheckedException; + public GridCloseableIterator cacheKeysIterator(int cacheId, final int part) + throws IgniteCheckedException; /** + * @param cacheId Cache ID. * @param primary Primary entries flag. * @param backup Backup entries flag. * @param topVer Topology version. * @return Entries count. * @throws IgniteCheckedException If failed. */ - public long entriesCount(boolean primary, boolean backup, AffinityTopologyVersion topVer) + public long cacheEntriesCount(int cacheId, boolean primary, boolean backup, AffinityTopologyVersion topVer) throws IgniteCheckedException; /** * Clears offheap entries. * + * @param cctx Cache context. * @param readers {@code True} to clear readers. */ - public void clear(boolean readers); + public void clearCache(GridCacheContext cctx, boolean readers); /** + * @param cacheId Cache ID. * @param part Partition. * @return Number of entries in given partition. */ - public long entriesCount(int part); + public long cacheEntriesCount(int cacheId, int part); /** * @return Offheap allocated size. @@ -254,28 +316,38 @@ public long entriesCount(boolean primary, boolean backup, AffinityTopologyVersio public GridAtomicLong globalRemoveId(); /** + * @param cacheId Cache ID. * @param idxName Index name. * @return Root page for index tree. * @throws IgniteCheckedException If failed. */ - public RootPage rootPageForIndex(String idxName) throws IgniteCheckedException; + public RootPage rootPageForIndex(int cacheId, String idxName) throws IgniteCheckedException; /** + * @param cacheId Cache ID. * @param idxName Index name. * @throws IgniteCheckedException If failed. */ - public void dropRootPageForIndex(String idxName) throws IgniteCheckedException; + public void dropRootPageForIndex(int cacheId, String idxName) throws IgniteCheckedException; /** + * @param idxName Index name. * @return Reuse list for index tree. + * @throws IgniteCheckedException If failed. */ public ReuseList reuseListForIndex(String idxName) throws IgniteCheckedException; /** - * + * @param cacheId Cache ID. + * @return Number of entries. + */ + public long cacheEntriesCount(int cacheId); + + /** + * @param part Partition. * @return Number of entries. */ - public long entriesCount(); + public int totalPartitionEntriesCount(int part); /** * @@ -304,13 +376,25 @@ interface CacheDataStore { /** * @param size Size to init. * @param updCntr Update counter to init. + * @param cacheSizes Cache sizes if store belongs to group containing multiple caches. */ - void init(long size, long updCntr); + void init(long size, long updCntr, @Nullable Map cacheSizes); /** + * @param cacheId Cache ID. * @return Size. */ - int size(); + int cacheSize(int cacheId); + + /** + * @return Cache sizes if store belongs to group containing multiple caches. + */ + Map cacheSizes(); + + /** + * @return Total size. + */ + int fullSize(); /** * @return Update counter. @@ -333,6 +417,7 @@ interface CacheDataStore { public Long initialUpdateCounter(); /** + * @param cctx Cache context. * @param key Key. * @param val Value. * @param ver Version. @@ -341,13 +426,16 @@ interface CacheDataStore { * @return New row. * @throws IgniteCheckedException If failed. */ - CacheDataRow createRow(KeyCacheObject key, + CacheDataRow createRow( + GridCacheContext cctx, + KeyCacheObject key, CacheObject val, GridCacheVersion ver, long expireTime, @Nullable CacheDataRow oldRow) throws IgniteCheckedException; /** + * @param cctx Cache context. * @param key Key. * @param val Value. * @param ver Version. @@ -355,38 +443,44 @@ CacheDataRow createRow(KeyCacheObject key, * @param oldRow Old row if available. * @throws IgniteCheckedException If failed. */ - void update(KeyCacheObject key, + void update( + GridCacheContext cctx, + KeyCacheObject key, CacheObject val, GridCacheVersion ver, long expireTime, @Nullable CacheDataRow oldRow) throws IgniteCheckedException; /** + * @param cctx Cache context. * @param key Key. * @throws IgniteCheckedException If failed. */ - void updateIndexes(KeyCacheObject key) throws IgniteCheckedException; + void updateIndexes(GridCacheContext cctx, KeyCacheObject key) throws IgniteCheckedException; /** + * @param cctx Cache context. * @param key Key. * @param c Closure. * @throws IgniteCheckedException If failed. */ - public void invoke(KeyCacheObject key, OffheapInvokeClosure c) throws IgniteCheckedException; + public void invoke(GridCacheContext cctx, KeyCacheObject key, OffheapInvokeClosure c) throws IgniteCheckedException; /** + * @param cctx Cache context. * @param key Key. * @param partId Partition number. * @throws IgniteCheckedException If failed. */ - public void remove(KeyCacheObject key, int partId) throws IgniteCheckedException; + public void remove(GridCacheContext cctx, KeyCacheObject key, int partId) throws IgniteCheckedException; /** + * @param cctx Cache context. * @param key Key. * @return Data row. * @throws IgniteCheckedException If failed. */ - public CacheDataRow find(KeyCacheObject key) throws IgniteCheckedException; + public CacheDataRow find(GridCacheContext cctx, KeyCacheObject key) throws IgniteCheckedException; /** * @return Data cursor. @@ -395,14 +489,33 @@ void update(KeyCacheObject key, public GridCursor cursor() throws IgniteCheckedException; /** + * @param cacheId Cache ID. + * @return Data cursor. + * @throws IgniteCheckedException If failed. + */ + public GridCursor cursor(int cacheId) throws IgniteCheckedException; + + /** + * @param cacheId Cache ID. * @param lower Lower bound. * @param upper Upper bound. * @return Data cursor. * @throws IgniteCheckedException If failed. */ - public GridCursor cursor(KeyCacheObject lower, + public GridCursor cursor(int cacheId, KeyCacheObject lower, KeyCacheObject upper) throws IgniteCheckedException; + /** + * @param cacheId Cache ID. + * @param lower Lower bound. + * @param upper Upper bound. + * @param x Implementation specific argument, {@code null} always means that we need to return full detached data row. + * @return Data cursor. + * @throws IgniteCheckedException If failed. + */ + public GridCursor cursor(int cacheId, KeyCacheObject lower, + KeyCacheObject upper, Object x) throws IgniteCheckedException; + /** * Destroys the tree associated with the store. * @@ -410,6 +523,14 @@ public GridCursor cursor(KeyCacheObject lower, */ public void destroy() throws IgniteCheckedException; + /** + * Clears all the records associated with logical cache with given ID. + * + * @param cacheId Cache ID. + * @throws IgniteCheckedException If failed. + */ + public void clear(int cacheId) throws IgniteCheckedException; + /** * @return Row store. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index 947421b16eda7..ae47443a3b294 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -18,7 +18,10 @@ package org.apache.ignite.internal.processors.cache; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; +import java.util.NoSuchElementException; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -27,8 +30,7 @@ import javax.cache.Cache; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; -import org.apache.ignite.cluster.ClusterNode; -import org.apache.ignite.configuration.DataPageEvictionMode; +import org.apache.ignite.IgniteLogger; import org.apache.ignite.internal.NodeStoppingException; import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.pagemem.PageMemory; @@ -50,10 +52,8 @@ import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; -import org.apache.ignite.internal.processors.cache.local.GridLocalCache; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; -import org.apache.ignite.internal.processors.query.QueryUtils; import org.apache.ignite.internal.util.GridAtomicLong; import org.apache.ignite.internal.util.GridCloseableIteratorAdapter; import org.apache.ignite.internal.util.GridEmptyCloseableIterator; @@ -81,12 +81,21 @@ * */ @SuppressWarnings("PublicInnerClass") -public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter implements IgniteCacheOffheapManager { +public class IgniteCacheOffheapManagerImpl implements IgniteCacheOffheapManager { /** */ - private CacheDataStore locCacheDataStore; + private static final int UNDEFINED_CACHE_ID = 0; + + /** */ + protected GridCacheSharedContext ctx; + + /** */ + protected CacheGroupContext grp; + + /** */ + protected IgniteLogger log; /** */ - private boolean indexingEnabled; + private CacheDataStore locCacheDataStore; /** */ protected final ConcurrentMap partDataStores = new ConcurrentHashMap<>(); @@ -97,9 +106,6 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple /** */ private volatile boolean hasPendingEntries; - /** */ - private static final PendingRow START_PENDING_ROW = new PendingRow(Long.MIN_VALUE, 0); - /** */ private final GridAtomicLong globalRmvId = new GridAtomicLong(U.currentTimeMillis() * 1000_000); @@ -118,79 +124,102 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple } /** {@inheritDoc} */ - @Override protected void start0() throws IgniteCheckedException { - super.start0(); + @Override public void start(GridCacheSharedContext ctx, CacheGroupContext grp) throws IgniteCheckedException { + this.ctx = ctx; + this.grp = grp; + this.log = ctx.logger(getClass()); - indexingEnabled = QueryUtils.isEnabled(cctx.config()); + updateValSizeThreshold = ctx.database().pageSize() / 2; - updateValSizeThreshold = cctx.shared().database().pageSize() / 2; - - if (cctx.affinityNode()) { - cctx.shared().database().checkpointReadLock(); + if (grp.affinityNode()) { + ctx.database().checkpointReadLock(); try { initDataStructures(); - if (cctx.isLocal()) { - assert cctx.cache() instanceof GridLocalCache : cctx.cache(); - + if (grp.isLocal()) locCacheDataStore = createCacheDataStore(0); - } } finally { - cctx.shared().database().checkpointReadUnlock(); + ctx.database().checkpointReadUnlock(); } } } - /** - * @throws IgniteCheckedException If failed. - */ - protected void initDataStructures() throws IgniteCheckedException { - if (cctx.shared().ttl().eagerTtlEnabled()) { + /** {@inheritDoc} */ + public void onCacheStarted(GridCacheContext cctx) throws IgniteCheckedException{ + if (cctx.affinityNode() && cctx.ttl().eagerTtlEnabled() && pendingEntries == null) { String name = "PendingEntries"; long rootPage = allocateForTree(); - pendingEntries = new PendingEntriesTree(cctx, + pendingEntries = new PendingEntriesTree( + grp, name, - cctx.memoryPolicy().pageMemory(), + grp.memoryPolicy().pageMemory(), rootPage, - cctx.reuseList(), + grp.reuseList(), true); } } - /** {@inheritDoc} */ - @Override protected void stop0(final boolean cancel, final boolean destroy) { - super.stop0(cancel, destroy); + /** + * @throws IgniteCheckedException If failed. + */ + protected void initDataStructures() throws IgniteCheckedException { + // No-op. + } - if (cctx.affinityNode()) - destroyCacheDataStructures(); + /** {@inheritDoc} */ + @Override public void stopCache(int cacheId, final boolean destroy) { + if (destroy && grp.affinityNode()) + removeCacheData(cacheId); } /** {@inheritDoc} */ - @Override protected void onKernalStop0(boolean cancel) { - super.onKernalStop0(cancel); + @Override public void stop() { + try { + for (CacheDataStore store : cacheDataStores()) + destroyCacheDataStore(store); + + if (pendingEntries != null) + pendingEntries.destroy(); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e.getMessage(), e); + } + } + /** {@inheritDoc} */ + @Override public void onKernalStop() { busyLock.block(); } /** * */ - protected void destroyCacheDataStructures() { - assert cctx.affinityNode(); + private void removeCacheData(int cacheId) { + assert grp.affinityNode(); try { - if (locCacheDataStore != null) - locCacheDataStore.destroy(); + if (grp.sharedGroup()) { + assert cacheId != UNDEFINED_CACHE_ID; - if (pendingEntries != null) - pendingEntries.destroy(); + for (CacheDataStore store : cacheDataStores()) + store.clear(cacheId); - for (CacheDataStore store : partDataStores.values()) - destroyCacheDataStore(store); + if (pendingEntries != null) { + PendingRow row = new PendingRow(cacheId); + + GridCursor cursor = pendingEntries.find(row, row, PendingEntriesTree.WITHOUT_KEY); + + while (cursor.next()) { + boolean res = pendingEntries.removex(cursor.get()); + + assert res; + } + } + } } catch (IgniteCheckedException e) { throw new IgniteException(e.getMessage(), e); @@ -202,7 +231,7 @@ protected void destroyCacheDataStructures() { * @return Data store for given entry. */ public CacheDataStore dataStore(GridDhtLocalPartition part) { - if (cctx.isLocal()) + if (grp.isLocal()) return locCacheDataStore; else { assert part != null; @@ -212,76 +241,66 @@ public CacheDataStore dataStore(GridDhtLocalPartition part) { } /** {@inheritDoc} */ - @Override public long entriesCount() { - if (cctx.isLocal()) - return locCacheDataStore.size(); - + @Override public long cacheEntriesCount(int cacheId) { long size = 0; - for (CacheDataStore store : partDataStores.values()) - size += store.size(); + for (CacheDataStore store : cacheDataStores()) + size += store.cacheSize(cacheId); return size; } + /** {@inheritDoc} */ + @Override public int totalPartitionEntriesCount(int p) { + if (grp.isLocal()) + return locCacheDataStore.fullSize(); + else { + GridDhtLocalPartition part = grp.topology().localPartition(p, AffinityTopologyVersion.NONE, false, true); + + return part != null ? part.dataStore().fullSize() : 0; + } + } + /** * @param p Partition. * @return Partition data. */ @Nullable private CacheDataStore partitionData(int p) { - if (cctx.isLocal()) + if (grp.isLocal()) return locCacheDataStore; else { - GridDhtLocalPartition part = cctx.topology().localPartition(p, AffinityTopologyVersion.NONE, false, true); + GridDhtLocalPartition part = grp.topology().localPartition(p, AffinityTopologyVersion.NONE, false, true); return part != null ? part.dataStore() : null; } } /** {@inheritDoc} */ - @Override public long entriesCount( + @Override public long cacheEntriesCount( + int cacheId, boolean primary, boolean backup, AffinityTopologyVersion topVer ) throws IgniteCheckedException { - if (cctx.isLocal()) - return entriesCount(0); + if (grp.isLocal()) + return cacheEntriesCount(cacheId, 0); else { - ClusterNode locNode = cctx.localNode(); - long cnt = 0; - for (GridDhtLocalPartition locPart : cctx.topology().currentLocalPartitions()) { - if (primary) { - if (cctx.affinity().primaryByPartition(locNode, locPart.id(), topVer)) { - cnt += locPart.dataStore().size(); + Iterator it = cacheData(primary, backup, topVer); - continue; - } - } - - if (backup) { - if (cctx.affinity().backupByPartition(locNode, locPart.id(), topVer)) - cnt += locPart.dataStore().size(); - } - } + while (it.hasNext()) + cnt += it.next().cacheSize(cacheId); return cnt; } } /** {@inheritDoc} */ - @Override public long entriesCount(int part) { - if (cctx.isLocal()) { - assert part == 0; - - return locCacheDataStore.size(); - } - else { - GridDhtLocalPartition locPart = cctx.topology().localPartition(part, AffinityTopologyVersion.NONE, false); + @Override public long cacheEntriesCount(int cacheId, int part) { + CacheDataStore store = partitionData(part); - return locPart == null ? 0 : locPart.dataStore().size(); - } + return store == null ? 0 : store.cacheSize(cacheId); } /** @@ -293,10 +312,10 @@ public CacheDataStore dataStore(GridDhtLocalPartition part) { private Iterator cacheData(boolean primary, boolean backup, AffinityTopologyVersion topVer) { assert primary || backup; - if (cctx.isLocal()) - return Collections.singleton(locCacheDataStore).iterator(); + if (grp.isLocal()) + return singletonIterator(locCacheDataStore); else { - final Iterator it = cctx.topology().currentLocalPartitions().iterator(); + final Iterator it = grp.topology().currentLocalPartitions().iterator(); if (primary && backup) { return F.iterator(it, new IgniteClosure() { @@ -306,8 +325,8 @@ private Iterator cacheData(boolean primary, boolean backup, Affi }, true); } - final Set parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer) : - cctx.affinity().backupPartitions(cctx.localNodeId(), topVer); + final Set parts = primary ? grp.affinity().primaryPartitions(ctx.localNodeId(), topVer) : + grp.affinity().backupPartitions(ctx.localNodeId(), topVer); return F.iterator(it, new IgniteClosure() { @Override public CacheDataStore apply(GridDhtLocalPartition part) { @@ -323,15 +342,18 @@ private Iterator cacheData(boolean primary, boolean backup, Affi } /** {@inheritDoc} */ - @Override public void invoke(KeyCacheObject key, + @Override public void invoke( + GridCacheContext cctx, + KeyCacheObject key, GridDhtLocalPartition part, OffheapInvokeClosure c) throws IgniteCheckedException { - dataStore(part).invoke(key, c); + dataStore(part).invoke(cctx, key, c); } /** {@inheritDoc} */ @Override public void update( + GridCacheContext cctx, KeyCacheObject key, CacheObject val, GridCacheVersion ver, @@ -341,21 +363,23 @@ private Iterator cacheData(boolean primary, boolean backup, Affi ) throws IgniteCheckedException { assert expireTime >= 0; - dataStore(part).update(key, val, ver, expireTime, oldRow); + dataStore(part).update(cctx, key, val, ver, expireTime, oldRow); } /** {@inheritDoc} */ - @Override public void updateIndexes(KeyCacheObject key, GridDhtLocalPartition part) throws IgniteCheckedException { - dataStore(part).updateIndexes(key); + @Override public void updateIndexes(GridCacheContext cctx, KeyCacheObject key, GridDhtLocalPartition part) + throws IgniteCheckedException { + dataStore(part).updateIndexes(cctx, key); } /** {@inheritDoc} */ @Override public void remove( + GridCacheContext cctx, KeyCacheObject key, int partId, GridDhtLocalPartition part ) throws IgniteCheckedException { - dataStore(part).remove(key, partId); + dataStore(part).remove(cctx, key, partId); } /** {@inheritDoc} */ @@ -364,21 +388,21 @@ private Iterator cacheData(boolean primary, boolean backup, Affi throws IgniteCheckedException { KeyCacheObject key = entry.key(); - assert cctx.isLocal() || entry.localPartition() != null : entry; + assert grp.isLocal() || entry.localPartition() != null : entry; - return dataStore(entry.localPartition()).find(key); + return dataStore(entry.localPartition()).find(entry.context(), key); } /** {@inheritDoc} */ - @Nullable @Override public CacheDataRow read(KeyCacheObject key) throws IgniteCheckedException { + @Nullable @Override public CacheDataRow read(GridCacheContext cctx, KeyCacheObject key) throws IgniteCheckedException { CacheDataRow row; if (cctx.isLocal()) - row = locCacheDataStore.find(key); + row = locCacheDataStore.find(cctx, key); else { GridDhtLocalPartition part = cctx.topology().localPartition(cctx.affinity().partition(key), null, false); - row = part != null ? dataStore(part).find(key) : null; + row = part != null ? dataStore(part).find(cctx, key) : null; } assert row == null || row.value() != null : row; @@ -419,10 +443,10 @@ private Iterator cacheData(boolean primary, boolean backup, Affi * @param readers {@code True} to clear readers. */ @SuppressWarnings("unchecked") - @Override public void clear(boolean readers) { + @Override public void clearCache(GridCacheContext cctx, boolean readers) { GridCacheVersion obsoleteVer = null; - GridIterator it = rowsIterator(true, true, null); + GridIterator it = iterator(cctx.cacheId(), cacheDataStores().iterator()); while (it.hasNext()) { cctx.shared().database().checkpointReadLock(); @@ -432,7 +456,7 @@ private Iterator cacheData(boolean primary, boolean backup, Affi try { if (obsoleteVer == null) - obsoleteVer = cctx.versions().next(); + obsoleteVer = ctx.versions().next(); GridCacheEntryEx entry = cctx.cache().entryEx(key); @@ -471,11 +495,13 @@ private Iterator cacheData(boolean primary, boolean backup, Affi * @throws IgniteCheckedException If failed. */ @SuppressWarnings("unchecked") - @Override public GridCloseableIterator> entriesIterator(final boolean primary, + @Override public GridCloseableIterator> cacheEntriesIterator( + final GridCacheContext cctx, + final boolean primary, final boolean backup, final AffinityTopologyVersion topVer, final boolean keepBinary) throws IgniteCheckedException { - final Iterator it = rowsIterator(primary, backup, topVer); + final Iterator it = cacheIterator(cctx.cacheId(), primary, backup, topVer); return new GridCloseableIteratorAdapter>() { /** */ @@ -516,13 +542,14 @@ private Iterator cacheData(boolean primary, boolean backup, Affi } /** {@inheritDoc} */ - @Override public GridCloseableIterator keysIterator(final int part) throws IgniteCheckedException { + @Override public GridCloseableIterator cacheKeysIterator(int cacheId, final int part) throws IgniteCheckedException { CacheDataStore data = partitionData(part); if (data == null) return new GridEmptyCloseableIterator<>(); - final GridCursor cur = data.cursor(); + final GridCursor cur = + data.cursor(cacheId, null, null, CacheDataRowAdapter.RowData.KEY_ONLY); return new GridCloseableIteratorAdapter() { /** */ @@ -552,21 +579,41 @@ private Iterator cacheData(boolean primary, boolean backup, Affi } /** {@inheritDoc} */ - @Override public GridIterator iterator(boolean primary, boolean backups, + @Override public GridIterator cacheIterator( + int cacheId, + boolean primary, + boolean backups, final AffinityTopologyVersion topVer) throws IgniteCheckedException { - return rowsIterator(primary, backups, topVer); + return iterator(cacheId, cacheData(primary, backups, topVer)); + } + + /** {@inheritDoc} */ + @Override public GridIterator cachePartitionIterator(int cacheId, int part) throws IgniteCheckedException { + CacheDataStore data = partitionData(part); + + if (data == null) + return new GridEmptyCloseableIterator<>(); + + return iterator(cacheId, singletonIterator(data)); + } + + /** {@inheritDoc} */ + @Override public GridIterator partitionIterator(int part) throws IgniteCheckedException { + CacheDataStore data = partitionData(part); + + if (data == null) + return new GridEmptyCloseableIterator<>(); + + return iterator(UNDEFINED_CACHE_ID, singletonIterator(data)); } /** - * @param primary Primary entries flag. - * @param backups Backup entries flag. - * @param topVer Topology version. - * @return Iterator. + * @param cacheId Cache ID. + * @param dataIt Data store iterator. + * @return Rows iterator */ - private GridIterator rowsIterator(boolean primary, boolean backups, AffinityTopologyVersion topVer) { - final Iterator dataIt = cacheData(primary, backups, topVer); - + private GridIterator iterator(final int cacheId, final Iterator dataIt) { return new GridCloseableIteratorAdapter() { /** */ private GridCursor cur; @@ -595,7 +642,7 @@ private GridIterator rowsIterator(boolean primary, boolean backups CacheDataStore ds = dataIt.next(); curPart = ds.partId(); - cur = ds.cursor(); + cur = cacheId == UNDEFINED_CACHE_ID ? ds.cursor() : ds.cursor(cacheId); } else break; @@ -616,35 +663,34 @@ private GridIterator rowsIterator(boolean primary, boolean backups }; } - /** {@inheritDoc} */ - @Override public GridIterator iterator(int part) throws IgniteCheckedException { - CacheDataStore data = partitionData(part); - - if (data == null) - return new GridEmptyCloseableIterator<>(); - - final GridCursor cur = data.cursor(); - - return new GridCloseableIteratorAdapter() { + /** + * @param item Item. + * @return Single item iterator. + */ + private Iterator singletonIterator(final T item) { + return new Iterator() { /** */ - private CacheDataRow next; - - @Override protected CacheDataRow onNext() { - CacheDataRow res = next; - - next = null; + private boolean hasNext = true; - return res; + /** {@inheritDoc} */ + @Override public boolean hasNext() { + return hasNext; } - @Override protected boolean onHasNext() throws IgniteCheckedException { - if (next != null) - return true; + /** {@inheritDoc} */ + @Override public T next() { + if (hasNext) { + hasNext = false; - if (cur.next()) - next = cur.get(); + return item; + } - return next != null; + throw new NoSuchElementException(); + } + + /** {@inheritDoc} */ + @Override public void remove() { + throw new UnsupportedOperationException(); } }; } @@ -654,37 +700,37 @@ private GridIterator rowsIterator(boolean primary, boolean backups * @throws IgniteCheckedException If failed. */ private long allocateForTree() throws IgniteCheckedException { - ReuseList reuseList = cctx.reuseList(); + ReuseList reuseList = grp.reuseList(); long pageId; if (reuseList == null || (pageId = reuseList.takeRecycledPage()) == 0L) - pageId = cctx.memoryPolicy().pageMemory().allocatePage(cctx.cacheId(), INDEX_PARTITION, FLAG_IDX); + pageId = grp.memoryPolicy().pageMemory().allocatePage(grp.groupId(), INDEX_PARTITION, FLAG_IDX); return pageId; } /** {@inheritDoc} */ - @Override public RootPage rootPageForIndex(String idxName) throws IgniteCheckedException { + @Override public RootPage rootPageForIndex(int cacheId, String idxName) throws IgniteCheckedException { long pageId = allocateForTree(); - return new RootPage(new FullPageId(pageId, cctx.cacheId()), true); + return new RootPage(new FullPageId(pageId, grp.groupId()), true); } /** {@inheritDoc} */ - @Override public void dropRootPageForIndex(String idxName) throws IgniteCheckedException { + @Override public void dropRootPageForIndex(int cacheId, String idxName) throws IgniteCheckedException { // No-op. } /** {@inheritDoc} */ @Override public ReuseList reuseListForIndex(String idxName) { - return cctx.reuseList(); + return grp.reuseList(); } /** {@inheritDoc} */ @Override public IgniteRebalanceIterator rebalanceIterator(int part, AffinityTopologyVersion topVer, Long partCntr) throws IgniteCheckedException { - final GridIterator it = iterator(part); + final GridIterator it = partitionIterator(part); return new IgniteRebalanceIterator() { @Override public boolean historical() { @@ -758,14 +804,15 @@ protected CacheDataStore createCacheDataStore0(int p) throws IgniteCheckedException { final long rootPage = allocateForTree(); - CacheDataRowStore rowStore = new CacheDataRowStore(cctx, cctx.freeList(), p); + CacheDataRowStore rowStore = new CacheDataRowStore(grp, grp.freeList(), p); String idxName = treeName(p); - CacheDataTree dataTree = new CacheDataTree(idxName, - cctx.reuseList(), + CacheDataTree dataTree = new CacheDataTree( + grp, + idxName, + grp.reuseList(), rowStore, - cctx, rootPage, true); @@ -774,7 +821,7 @@ protected CacheDataStore createCacheDataStore0(int p) /** {@inheritDoc} */ @Override public Iterable cacheDataStores() { - if (cctx.isLocal()) + if (grp.isLocal()) return Collections.singleton(locCacheDataStore); return new Iterable() { @@ -823,9 +870,12 @@ protected final String treeName(int p) { /** {@inheritDoc} */ @Override public boolean expire( + GridCacheContext cctx, IgniteInClosure2X c, int amount ) throws IgniteCheckedException { + assert !cctx.isNear() : cctx.name(); + if (hasPendingEntries && pendingEntries != null) { cctx.shared().database().checkpointReadLock(); @@ -834,7 +884,12 @@ protected final String treeName(int p) { long now = U.currentTimeMillis(); - GridCursor cur = pendingEntries.find(START_PENDING_ROW, new PendingRow(now, 0)); + GridCursor cur; + + if (grp.sharedGroup()) + cur = pendingEntries.find(new PendingRow(cctx.cacheId()), new PendingRow(cctx.cacheId(), now, 0)); + else + cur = pendingEntries.find(null, new PendingRow(UNDEFINED_CACHE_ID, now, 0)); int cleared = 0; @@ -847,9 +902,9 @@ protected final String treeName(int p) { if (row.key.partition() == -1) row.key.partition(cctx.affinity().partition(row.key));assert row.key != null && row.link != 0 && row.expireTime != 0 : row; - if (pendingEntries.remove(row) != null) { + if (pendingEntries.removex(row)) { if (obsoleteVer == null) - obsoleteVer = cctx.versions().next(); + obsoleteVer = ctx.versions().next(); c.apply(cctx.cache().entryEx(row.key), obsoleteVer); } @@ -890,7 +945,10 @@ protected class CacheDataStoreImpl implements CacheDataStore { protected final AtomicLong cntr = new AtomicLong(); /** Partition size. */ - protected final AtomicLong storageSize = new AtomicLong(); + private final AtomicLong storageSize = new AtomicLong(); + + /** */ + private final ConcurrentMap cacheSizes = new ConcurrentHashMap<>(); /** Initialized update counter. */ protected Long initCntr = 0L; @@ -913,13 +971,73 @@ public CacheDataStoreImpl( this.dataTree = dataTree; } + /** + * @param cacheId Cache ID. + */ + void incrementSize(int cacheId) { + storageSize.incrementAndGet(); + + if (grp.sharedGroup()) { + AtomicLong size = cacheSizes.get(cacheId); + + if (size == null) { + AtomicLong old = cacheSizes.putIfAbsent(cacheId, size = new AtomicLong()); + + if (old != null) + size = old; + } + + size.incrementAndGet(); + } + } + + /** + * @param cacheId Cache ID. + */ + void decrementSize(int cacheId) { + storageSize.decrementAndGet(); + + if (grp.sharedGroup()) { + AtomicLong size = cacheSizes.get(cacheId); + + if (size == null) + return; + + size.decrementAndGet(); + } + } + /** {@inheritDoc} */ @Override public int partId() { return partId; } /** {@inheritDoc} */ - @Override public int size() { + @Override public int cacheSize(int cacheId) { + if (grp.sharedGroup()) { + AtomicLong size = cacheSizes.get(cacheId); + + return size != null ? (int)size.get() : 0; + } + + return (int)storageSize.get(); + } + + /** {@inheritDoc} */ + @Override public Map cacheSizes() { + if (!grp.sharedGroup()) + return null; + + Map res = new HashMap<>(); + + for (Map.Entry e : cacheSizes.entrySet()) + res.put(e.getKey(), e.getValue().longValue()); + + return res; + } + + /** {@inheritDoc} */ + @Override public int fullSize() { return (int)storageSize.get(); } @@ -949,12 +1067,13 @@ public CacheDataStoreImpl( } /** + * @param cctx Cache context. * @param oldRow Old row. * @param dataRow New row. * @return {@code True} if it is possible to update old row data. * @throws IgniteCheckedException If failed. */ - private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) + private boolean canUpdateOldRow(GridCacheContext cctx, @Nullable CacheDataRow oldRow, DataRow dataRow) throws IgniteCheckedException { if (oldRow == null || cctx.queries().enabled()) return false; @@ -975,13 +1094,15 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) } /** {@inheritDoc} */ - @Override public void invoke(KeyCacheObject key, OffheapInvokeClosure c) + @Override public void invoke(GridCacheContext cctx, KeyCacheObject key, OffheapInvokeClosure c) throws IgniteCheckedException { if (!busyLock.enterBusy()) throw new NodeStoppingException("Operation has been cancelled (node is stopping)."); try { - dataTree.invoke(new SearchRow(key), CacheDataRowAdapter.RowData.NO_KEY, c); + int cacheId = grp.sharedGroup() ? cctx.cacheId() : UNDEFINED_CACHE_ID; + + dataTree.invoke(new SearchRow(cacheId, key), CacheDataRowAdapter.RowData.NO_KEY, c); switch (c.operationType()) { case PUT: { @@ -989,7 +1110,7 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) CacheDataRow oldRow = c.oldRow(); - finishUpdate(c.newRow(), oldRow); + finishUpdate(cctx, c.newRow(), oldRow); break; } @@ -997,7 +1118,7 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) case REMOVE: { CacheDataRow oldRow = c.oldRow(); - finishRemove(key, oldRow); + finishRemove(cctx, key, oldRow); break; } @@ -1015,18 +1136,19 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) } /** {@inheritDoc} */ - @Override public CacheDataRow createRow(KeyCacheObject key, + @Override public CacheDataRow createRow( + GridCacheContext cctx, + KeyCacheObject key, CacheObject val, GridCacheVersion ver, long expireTime, @Nullable CacheDataRow oldRow) throws IgniteCheckedException { - int cacheId = cctx.memoryPolicy().config().getPageEvictionMode() == DataPageEvictionMode.DISABLED ? - 0 : cctx.cacheId(); + int cacheId = grp.storeCacheIdInDataPage() ? cctx.cacheId() : UNDEFINED_CACHE_ID; DataRow dataRow = new DataRow(key, val, ver, partId, expireTime, cacheId); - if (canUpdateOldRow(oldRow, dataRow) && rowStore.updateRow(oldRow.link(), dataRow)) + if (canUpdateOldRow(cctx, oldRow, dataRow) && rowStore.updateRow(oldRow.link(), dataRow)) dataRow.link(oldRow.link()); else { CacheObjectContext coCtx = cctx.cacheObjectContext(); @@ -1039,12 +1161,15 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) assert dataRow.link() != 0 : dataRow; + if (grp.sharedGroup() && dataRow.cacheId() == UNDEFINED_CACHE_ID) + dataRow.cacheId(cctx.cacheId()); + return dataRow; } /** {@inheritDoc} */ - @Override public void update( - KeyCacheObject key, + @Override public void update(GridCacheContext cctx,KeyCacheObject key, + CacheObject val, GridCacheVersion ver, long expireTime, @@ -1056,8 +1181,9 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) throw new NodeStoppingException("Operation has been cancelled (node is stopping)."); try { - int cacheId = cctx.memoryPolicy().config().getPageEvictionMode() != DataPageEvictionMode.DISABLED ? - cctx.cacheId() : 0; + int cacheId = grp.storeCacheIdInDataPage() ? cctx.cacheId() : UNDEFINED_CACHE_ID; + + assert oldRow == null || oldRow.cacheId() == cacheId : oldRow; DataRow dataRow = new DataRow(key, val, ver, partId, expireTime, cacheId); @@ -1069,7 +1195,7 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) CacheDataRow old; - if (canUpdateOldRow(oldRow, dataRow) && rowStore.updateRow(oldRow.link(), dataRow)) { + if (canUpdateOldRow(cctx, oldRow, dataRow) && rowStore.updateRow(oldRow.link(), dataRow)) { old = oldRow; dataRow.link(oldRow.link()); @@ -1079,6 +1205,9 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) assert dataRow.link() != 0 : dataRow; + if (grp.sharedGroup() && dataRow.cacheId() == UNDEFINED_CACHE_ID) + dataRow.cacheId(cctx.cacheId()); + if (oldRow != null) { old = oldRow; @@ -1088,7 +1217,7 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) old = dataTree.put(dataRow); } - finishUpdate(dataRow, old); + finishUpdate(cctx, dataRow, old); } finally { busyLock.leaveBusy(); @@ -1096,13 +1225,15 @@ private boolean canUpdateOldRow(@Nullable CacheDataRow oldRow, DataRow dataRow) } /** + * @param cctx Cache context. * @param newRow New row. * @param oldRow Old row if available. * @throws IgniteCheckedException If failed. */ - private void finishUpdate(CacheDataRow newRow, @Nullable CacheDataRow oldRow) throws IgniteCheckedException { + private void finishUpdate(GridCacheContext cctx, CacheDataRow newRow, @Nullable CacheDataRow oldRow) + throws IgniteCheckedException { if (oldRow == null) - storageSize.incrementAndGet(); + incrementSize(cctx.cacheId()); KeyCacheObject key = newRow.key(); @@ -1110,6 +1241,8 @@ private void finishUpdate(CacheDataRow newRow, @Nullable CacheDataRow oldRow) th GridCacheQueryManager qryMgr = cctx.queries(); + int cacheId = grp.sharedGroup() ? cctx.cacheId() : UNDEFINED_CACHE_ID; + if (qryMgr.enabled()) { if (oldRow != null) { qryMgr.store(key, @@ -1136,51 +1269,55 @@ private void finishUpdate(CacheDataRow newRow, @Nullable CacheDataRow oldRow) th assert oldRow.link() != 0 : oldRow; if (pendingEntries != null && oldRow.expireTime() != 0) - pendingEntries.removex(new PendingRow(oldRow.expireTime(), oldRow.link())); + pendingEntries.removex(new PendingRow(cacheId, oldRow.expireTime(), oldRow.link())); if (newRow.link() != oldRow.link()) rowStore.removeRow(oldRow.link()); } if (pendingEntries != null && expireTime != 0) { - pendingEntries.putx(new PendingRow(expireTime, newRow.link())); + pendingEntries.putx(new PendingRow(cacheId, expireTime, newRow.link())); hasPendingEntries = true; } - updateIgfsMetrics(key, (oldRow != null ? oldRow.value() : null), newRow.value()); + updateIgfsMetrics(cctx, key, (oldRow != null ? oldRow.value() : null), newRow.value()); } /** {@inheritDoc} */ - @Override public void updateIndexes(KeyCacheObject key) throws IgniteCheckedException { - if (indexingEnabled) { - CacheDataRow row = dataTree.findOne(new SearchRow(key)); + @Override public void updateIndexes(GridCacheContext cctx, KeyCacheObject key) throws IgniteCheckedException { + int cacheId = grp.sharedGroup() ? cctx.cacheId() : UNDEFINED_CACHE_ID; + + CacheDataRow row = dataTree.findOne(new SearchRow(cacheId, key), CacheDataRowAdapter.RowData.NO_KEY); + + if (row != null) { + row.key(key); GridCacheQueryManager qryMgr = cctx.queries(); - if (row != null) { - qryMgr.store( - key, - partId, - null, - null, - row.value(), - row.version(), - row.expireTime(), - row.link()); - } + qryMgr.store( + key, + partId, + null, + null, + row.value(), + row.version(), + row.expireTime(), + row.link()); } } /** {@inheritDoc} */ - @Override public void remove(KeyCacheObject key, int partId) throws IgniteCheckedException { + @Override public void remove(GridCacheContext cctx, KeyCacheObject key, int partId) throws IgniteCheckedException { if (!busyLock.enterBusy()) throw new NodeStoppingException("Operation has been cancelled (node is stopping)."); try { - CacheDataRow oldRow = dataTree.remove(new SearchRow(key)); + int cacheId = grp.sharedGroup() ? cctx.cacheId() : UNDEFINED_CACHE_ID; + + CacheDataRow oldRow = dataTree.remove(new SearchRow(cacheId, key)); - finishRemove(key, oldRow); + finishRemove(cctx, key, oldRow); } finally { busyLock.leaveBusy(); @@ -1188,21 +1325,26 @@ private void finishUpdate(CacheDataRow newRow, @Nullable CacheDataRow oldRow) th } /** + * @param cctx Cache context. * @param key Key. * @param oldRow Removed row. * @throws IgniteCheckedException If failed. */ - private void finishRemove(KeyCacheObject key, @Nullable CacheDataRow oldRow) throws IgniteCheckedException { + private void finishRemove(GridCacheContext cctx, KeyCacheObject key, @Nullable CacheDataRow oldRow) throws IgniteCheckedException { CacheObject val = null; GridCacheVersion ver = null; if (oldRow != null) { + int cacheId = grp.sharedGroup() ? cctx.cacheId() : UNDEFINED_CACHE_ID; + assert oldRow.link() != 0 : oldRow; + assert cacheId == UNDEFINED_CACHE_ID || oldRow.cacheId() == cacheId : + "Incorrect cache ID [expected=" + cacheId + ", actual=" + oldRow.cacheId() + "]."; if (pendingEntries != null && oldRow.expireTime() != 0) - pendingEntries.removex(new PendingRow(oldRow.expireTime(), oldRow.link())); + pendingEntries.removex(new PendingRow(cacheId, oldRow.expireTime(), oldRow.link())); - storageSize.decrementAndGet(); + decrementSize(cctx.cacheId()); val = oldRow.value(); @@ -1217,19 +1359,21 @@ private void finishRemove(KeyCacheObject key, @Nullable CacheDataRow oldRow) thr if (oldRow != null) rowStore.removeRow(oldRow.link()); - updateIgfsMetrics(key, (oldRow != null ? oldRow.value() : null), null); + updateIgfsMetrics(cctx, key, (oldRow != null ? oldRow.value() : null), null); } /** {@inheritDoc} */ - @Override public CacheDataRow find(KeyCacheObject key) throws IgniteCheckedException { + @Override public CacheDataRow find(GridCacheContext cctx, KeyCacheObject key) throws IgniteCheckedException { key.valueBytes(cctx.cacheObjectContext()); - CacheDataRow row = dataTree.findOne(new SearchRow(key), CacheDataRowAdapter.RowData.NO_KEY); + int cacheId = grp.sharedGroup() ? cctx.cacheId() : UNDEFINED_CACHE_ID; + + CacheDataRow row = dataTree.findOne(new SearchRow(cacheId, key), CacheDataRowAdapter.RowData.NO_KEY); if (row != null) { row.key(key); - cctx.memoryPolicy().evictionTracker().touchPage(row.link()); + grp.memoryPolicy().evictionTracker().touchPage(row.link()); } return row; @@ -1240,19 +1384,36 @@ private void finishRemove(KeyCacheObject key, @Nullable CacheDataRow oldRow) thr return dataTree.find(null, null); } + /** {@inheritDoc} + * @param cacheId*/ + @Override public GridCursor cursor(int cacheId) throws IgniteCheckedException { + return cursor(cacheId, null, null); + } + /** {@inheritDoc} */ - @Override public GridCursor cursor(KeyCacheObject lower, + @Override public GridCursor cursor(int cacheId, KeyCacheObject lower, KeyCacheObject upper) throws IgniteCheckedException { - SearchRow lowerRow = null; - SearchRow upperRow = null; + return cursor(cacheId, lower, upper, null); + } - if (lower != null) - lowerRow = new SearchRow(lower); + /** {@inheritDoc} */ + @Override public GridCursor cursor(int cacheId, KeyCacheObject lower, + KeyCacheObject upper, Object x) throws IgniteCheckedException { + SearchRow lowerRow; + SearchRow upperRow; + + if (grp.sharedGroup()) { + assert cacheId != UNDEFINED_CACHE_ID; - if (upper != null) - upperRow = new SearchRow(upper); + lowerRow = lower != null ? new SearchRow(cacheId, lower) : new SearchRow(cacheId); + upperRow = upper != null ? new SearchRow(cacheId, upper) : new SearchRow(cacheId); + } + else { + lowerRow = lower != null ? new SearchRow(UNDEFINED_CACHE_ID, lower) : null; + upperRow = upper != null ? new SearchRow(UNDEFINED_CACHE_ID, upper) : null; + } - return dataTree.find(lowerRow, upperRow); + return dataTree.find(lowerRow, upperRow, x); } /** {@inheritDoc} */ @@ -1281,6 +1442,46 @@ private void finishRemove(KeyCacheObject key, @Nullable CacheDataRow oldRow) thr throw new IgniteCheckedException("Fail destroy store", exception.get()); } + /** {@inheritDoc} */ + @Override public void clear(int cacheId) throws IgniteCheckedException { + assert cacheId != UNDEFINED_CACHE_ID; + + if (cacheSize(cacheId) == 0) + return; + + Exception ex = null; + + GridCursor cur = + cursor(cacheId, null, null, CacheDataRowAdapter.RowData.KEY_ONLY); + + while (cur.next()) { + CacheDataRow row = cur.get(); + + assert row.link() != 0 : row; + + try { + boolean res = dataTree.removex(row); + + assert res : row; + + rowStore.removeRow(row.link()); + + decrementSize(cacheId); + } + catch (IgniteCheckedException e) { + U.error(log, "Fail remove row [link=" + row.link() + "]"); + + if (ex == null) + ex = e; + else + ex.addSuppressed(e); + } + } + + if (ex != null) + throw new IgniteCheckedException("Fail destroy store", ex); + } + /** {@inheritDoc} */ @Override public RowStore rowStore() { return rowStore; @@ -1307,18 +1508,26 @@ private void finishRemove(KeyCacheObject key, @Nullable CacheDataRow oldRow) thr } /** {@inheritDoc} */ - @Override public void init(long size, long updCntr) { + @Override public void init(long size, long updCntr, @Nullable Map cacheSizes) { initCntr = updCntr; storageSize.set(size); cntr.set(updCntr); + + if (cacheSizes != null) { + for (Map.Entry e : cacheSizes.entrySet()) + this.cacheSizes.put(e.getKey(), new AtomicLong(e.getValue())); + } } /** + * @param cctx Cache context. * @param key Key. * @param oldVal Old value. * @param newVal New value. + * @throws IgniteCheckedException If failed. */ private void updateIgfsMetrics( + GridCacheContext cctx, KeyCacheObject key, CacheObject oldVal, CacheObject newVal @@ -1326,11 +1535,11 @@ private void updateIgfsMetrics( // In case we deal with IGFS cache, count updated data if (cctx.cache().isIgfsDataCache() && !cctx.isNear() && - cctx.kernalContext() + ctx.kernalContext() .igfsHelper() .isIgfsBlockKey(key.value(cctx.cacheObjectContext(), false))) { - int oldSize = valueLength(oldVal); - int newSize = valueLength(newVal); + int oldSize = valueLength(cctx, oldVal); + int newSize = valueLength(cctx, newVal); int delta = newSize - oldSize; @@ -1342,10 +1551,11 @@ private void updateIgfsMetrics( /** * Isolated method to get length of IGFS block. * + * @param cctx Cache context. * @param val Value. * @return Length of value. */ - private int valueLength(@Nullable CacheObject val) { + private int valueLength(GridCacheContext cctx, @Nullable CacheObject val) { if (val == null) return 0; @@ -1368,13 +1578,28 @@ private static class SearchRow implements CacheSearchRow { /** */ private final int hash; + /** */ + private final int cacheId; + /** + * @param cacheId Cache ID. * @param key Key. */ - SearchRow(KeyCacheObject key) { + SearchRow(int cacheId, KeyCacheObject key) { this.key = key; + this.hash = key.hashCode(); + this.cacheId = cacheId; + } - hash = key.hashCode(); + /** + * Instantiates a new fake search row as a logic cache based bound. + * + * @param cacheId Cache ID. + */ + SearchRow(int cacheId) { + this.key = null; + this.hash = 0; + this.cacheId = cacheId; } /** {@inheritDoc} */ @@ -1391,6 +1616,11 @@ private static class SearchRow implements CacheSearchRow { @Override public int hash() { return hash; } + + /** {@inheritDoc} */ + @Override public int cacheId() { + return cacheId; + } } /** @@ -1406,6 +1636,7 @@ private class DataRow extends CacheDataRowAdapter { /** * @param hash Hash code. * @param link Link. + * @param part Partition. * @param rowData Required row data. */ DataRow(int hash, long link, int part, CacheDataRowAdapter.RowData rowData) { @@ -1417,7 +1648,7 @@ private class DataRow extends CacheDataRowAdapter { try { // We can not init data row lazily because underlying buffer can be concurrently cleared. - initFromLink(cctx, rowData); + initFromLink(grp, rowData); } catch (IgniteCheckedException e) { throw new IgniteException(e); @@ -1433,6 +1664,7 @@ private class DataRow extends CacheDataRowAdapter { * @param ver Version. * @param part Partition. * @param expireTime Expire time. + * @param cacheId Cache ID. */ DataRow(KeyCacheObject key, CacheObject val, GridCacheVersion ver, int part, long expireTime, int cacheId) { super(0); @@ -1460,6 +1692,13 @@ private class DataRow extends CacheDataRowAdapter { @Override public void link(long link) { this.link = link; } + + /** + * @param cacheId Cache ID. + */ + void cacheId(int cacheId) { + this.cacheId = cacheId; + } } /** @@ -1470,54 +1709,80 @@ protected static class CacheDataTree extends BPlusTree io, long pageAddr, int idx, CacheSearchRow row) + @Override protected int compare(BPlusIO iox, long pageAddr, int idx, CacheSearchRow row) throws IgniteCheckedException { - int hash = ((RowLinkIO)io).getHash(pageAddr, idx); + RowLinkIO io = (RowLinkIO)iox; + + int cmp; + + if (grp.sharedGroup()) { + assert row.cacheId() != UNDEFINED_CACHE_ID : "Cache ID is not provided: " + row; + + int cacheId = io.getCacheId(pageAddr, idx); + + assert cacheId != UNDEFINED_CACHE_ID : "Cache ID is not stored"; + + cmp = Integer.compare(cacheId, row.cacheId()); + + if (cmp != 0) + return cmp; + + if (row.key() == null) { + assert row.getClass() == SearchRow.class : row; - int cmp = Integer.compare(hash, row.hash()); + // A search row with a cache ID only is used as a cache bound. + // The found position will be shifted until the exact cache bound is found; + // See for details: + // o.a.i.i.p.c.database.tree.BPlusTree.ForwardCursor.findLowerBound() + // o.a.i.i.p.c.database.tree.BPlusTree.ForwardCursor.findUpperBound() + return cmp; + } + } + + cmp = Integer.compare(io.getHash(pageAddr, idx), row.hash()); if (cmp != 0) return cmp; - long link = ((RowLinkIO)io).getLink(pageAddr, idx); + long link = io.getLink(pageAddr, idx); assert row.key() != null : row; @@ -1527,14 +1792,15 @@ public CacheDataTree( /** {@inheritDoc} */ @Override protected CacheDataRow getRow(BPlusIO io, long pageAddr, int idx, Object flags) throws IgniteCheckedException { - int hash = ((RowLinkIO)io).getHash(pageAddr, idx); long link = ((RowLinkIO)io).getLink(pageAddr, idx); + int hash = ((RowLinkIO)io).getHash(pageAddr, idx); + int cacheId = ((RowLinkIO)io).getCacheId(pageAddr, idx); CacheDataRowAdapter.RowData x = flags != null ? (CacheDataRowAdapter.RowData)flags : CacheDataRowAdapter.RowData.FULL; - return rowStore.dataRow(hash, link, x); + return rowStore.dataRow(cacheId, hash, link, x); } /** @@ -1544,7 +1810,7 @@ public CacheDataTree( * @throws IgniteCheckedException If failed. */ private int compareKeys(KeyCacheObject key, final long link) throws IgniteCheckedException { - byte[] bytes = key.valueBytes(cctx.cacheObjectContext()); + byte[] bytes = key.valueBytes(grp.cacheObjectContext()); final long pageId = pageId(link); final long page = acquirePage(pageId); @@ -1563,7 +1829,7 @@ private int compareKeys(KeyCacheObject key, final long link) throws IgniteChecke if (data.nextLink() == 0) { long addr = pageAddr + data.offset(); - if (cctx.memoryPolicy().config().getPageEvictionMode() != DataPageEvictionMode.DISABLED) + if (grp.storeCacheIdInDataPage()) addr += 4; // Skip cache id. final int len = PageUtils.getInt(addr, 0); @@ -1610,10 +1876,10 @@ private int compareKeys(KeyCacheObject key, final long link) throws IgniteChecke // TODO GG-11768. CacheDataRowAdapter other = new CacheDataRowAdapter(link); - other.initFromLink(cctx, CacheDataRowAdapter.RowData.KEY_ONLY); + other.initFromLink(grp, CacheDataRowAdapter.RowData.KEY_ONLY); - byte[] bytes1 = other.key().valueBytes(cctx.cacheObjectContext()); - byte[] bytes2 = key.valueBytes(cctx.cacheObjectContext()); + byte[] bytes1 = other.key().valueBytes(grp.cacheObjectContext()); + byte[] bytes2 = key.valueBytes(grp.cacheObjectContext()); int lenCmp = Integer.compare(bytes1.length, bytes2.length); @@ -1655,48 +1921,50 @@ protected class CacheDataRowStore extends RowStore { private final int partId; /** - * @param cctx Cache context. + * @param grp Cache group. * @param freeList Free list. + * @param partId Partition number. */ - public CacheDataRowStore(GridCacheContext cctx, FreeList freeList, int partId) { - super(cctx, freeList); + public CacheDataRowStore(CacheGroupContext grp, FreeList freeList, int partId) { + super(grp, freeList); this.partId = partId; } /** + * @param cacheId Cache ID. * @param hash Hash code. * @param link Link. * @return Search row. */ - private CacheSearchRow keySearchRow(int hash, long link) { - return new DataRow(hash, link, partId, CacheDataRowAdapter.RowData.KEY_ONLY); + private CacheSearchRow keySearchRow(int cacheId, int hash, long link) { + DataRow dataRow = new DataRow(hash, link, partId, CacheDataRowAdapter.RowData.KEY_ONLY); + + if (dataRow.cacheId() == UNDEFINED_CACHE_ID && grp.sharedGroup()) + dataRow.cacheId(cacheId); + + return dataRow; } /** + * @param cacheId Cache ID. * @param hash Hash code. * @param link Link. * @param rowData Required row data. * @return Data row. */ - private CacheDataRow dataRow(int hash, long link, CacheDataRowAdapter.RowData rowData) { - return new DataRow(hash, link, partId, rowData); + private CacheDataRow dataRow(int cacheId, int hash, long link, CacheDataRowAdapter.RowData rowData) { + DataRow dataRow = new DataRow(hash, link, partId, rowData); + + if (dataRow.cacheId() == UNDEFINED_CACHE_ID && grp.sharedGroup()) + dataRow.cacheId(cacheId); + + return dataRow; } } /** - * @param pageAddr Page address. - * @param off Offset. - * @param link Link. - * @param hash Hash. - */ - private static void store0(long pageAddr, int off, long link, int hash) { - PageUtils.putLong(pageAddr, off, link); - PageUtils.putInt(pageAddr, off + 8, hash); - } - - /** - * + * */ private interface RowLinkIO { /** @@ -1712,37 +1980,50 @@ private interface RowLinkIO { * @return Key hash code. */ public int getHash(long pageAddr, int idx); + + /** + * @param pageAddr Page address. + * @param idx Index. + * @return Cache ID or {@code 0} if cache ID is not defined. + */ + public int getCacheId(long pageAddr, int idx); } /** * */ - public static final class DataInnerIO extends BPlusInnerIO implements RowLinkIO { - /** */ - public static final IOVersions VERSIONS = new IOVersions<>( - new DataInnerIO(1) - ); - + private static abstract class AbstractDataInnerIO extends BPlusInnerIO implements RowLinkIO { /** + * @param type Page type. * @param ver Page format version. + * @param canGetRow If we can get full row from this page. + * @param itemSize Single item size on page. */ - DataInnerIO(int ver) { - super(T_DATA_REF_INNER, ver, true, 12); + protected AbstractDataInnerIO(int type, int ver, boolean canGetRow, int itemSize) { + super(type, ver, canGetRow, itemSize); } /** {@inheritDoc} */ @Override public void storeByOffset(long pageAddr, int off, CacheSearchRow row) { assert row.link() != 0; - store0(pageAddr, off, row.link(), row.hash()); + PageUtils.putLong(pageAddr, off, row.link()); + PageUtils.putInt(pageAddr, off + 8, row.hash()); + + if (storeCacheId()) { + assert row.cacheId() != UNDEFINED_CACHE_ID : row; + + PageUtils.putInt(pageAddr, off + 12, row.cacheId()); + } } /** {@inheritDoc} */ @Override public CacheSearchRow getLookupRow(BPlusTree tree, long pageAddr, int idx) { + int cacheId = getCacheId(pageAddr, idx); int hash = getHash(pageAddr, idx); long link = getLink(pageAddr, idx); - return ((CacheDataTree)tree).rowStore.keySearchRow(hash, link); + return ((CacheDataTree)tree).rowStore.keySearchRow(cacheId, hash, link); } /** {@inheritDoc} */ @@ -1750,8 +2031,18 @@ public static final class DataInnerIO extends BPlusInnerIO imple int srcIdx) { int hash = ((RowLinkIO)srcIo).getHash(srcPageAddr, srcIdx); long link = ((RowLinkIO)srcIo).getLink(srcPageAddr, srcIdx); + int off = offset(dstIdx); + + PageUtils.putLong(dstPageAddr, off, link); + PageUtils.putInt(dstPageAddr, off + 8, hash); + + if (storeCacheId()) { + int cacheId = ((RowLinkIO)srcIo).getCacheId(srcPageAddr, srcIdx); + + assert cacheId != UNDEFINED_CACHE_ID; - store0(dstPageAddr, offset(dstIdx), link, hash); + PageUtils.putInt(dstPageAddr, off + 12, cacheId); + } } /** {@inheritDoc} */ @@ -1773,43 +2064,66 @@ public static final class DataInnerIO extends BPlusInnerIO imple for (int i = 0; i < cnt; i++) c.apply(new CacheDataRowAdapter(getLink(pageAddr, i))); } + + /** + * @return {@code True} if cache ID has to be stored. + */ + protected abstract boolean storeCacheId(); } /** * */ - public static final class DataLeafIO extends BPlusLeafIO implements RowLinkIO { - /** */ - public static final IOVersions VERSIONS = new IOVersions<>( - new DataLeafIO(1) - ); - + private static abstract class AbstractDataLeafIO extends BPlusLeafIO implements RowLinkIO { /** + * @param type Page type. * @param ver Page format version. + * @param itemSize Single item size on page. */ - DataLeafIO(int ver) { - super(T_DATA_REF_LEAF, ver, 12); + protected AbstractDataLeafIO(int type, int ver, int itemSize) { + super(type, ver, itemSize); } /** {@inheritDoc} */ @Override public void storeByOffset(long pageAddr, int off, CacheSearchRow row) { assert row.link() != 0; - store0(pageAddr, off, row.link(), row.hash()); + PageUtils.putLong(pageAddr, off, row.link()); + PageUtils.putInt(pageAddr, off + 8, row.hash()); + + if (storeCacheId()) { + assert row.cacheId() != UNDEFINED_CACHE_ID; + + PageUtils.putInt(pageAddr, off + 12, row.cacheId()); + } } /** {@inheritDoc} */ @Override public void store(long dstPageAddr, int dstIdx, BPlusIO srcIo, long srcPageAddr, int srcIdx) { - store0(dstPageAddr, offset(dstIdx), getLink(srcPageAddr, srcIdx), getHash(srcPageAddr, srcIdx)); + int hash = ((RowLinkIO)srcIo).getHash(srcPageAddr, srcIdx); + long link = ((RowLinkIO)srcIo).getLink(srcPageAddr, srcIdx); + int off = offset(dstIdx); + + PageUtils.putLong(dstPageAddr, off, link); + PageUtils.putInt(dstPageAddr, off + 8, hash); + + if (storeCacheId()) { + int cacheId = ((RowLinkIO)srcIo).getCacheId(srcPageAddr, srcIdx); + + assert cacheId != UNDEFINED_CACHE_ID; + + PageUtils.putInt(dstPageAddr, off + 12, cacheId); + } } /** {@inheritDoc} */ @Override public CacheSearchRow getLookupRow(BPlusTree tree, long buf, int idx) { + int cacheId = getCacheId(buf, idx); int hash = getHash(buf, idx); long link = getLink(buf, idx); - return ((CacheDataTree)tree).rowStore.keySearchRow(hash, link); + return ((CacheDataTree)tree).rowStore.keySearchRow(cacheId, hash, link); } /** {@inheritDoc} */ @@ -1831,6 +2145,119 @@ public static final class DataLeafIO extends BPlusLeafIO impleme for (int i = 0; i < cnt; i++) c.apply(new CacheDataRowAdapter(getLink(pageAddr, i))); } + + /** + * @return {@code True} if cache ID has to be stored. + */ + protected abstract boolean storeCacheId(); + } + + /** + * + */ + public static final class DataInnerIO extends AbstractDataInnerIO { + /** */ + public static final IOVersions VERSIONS = new IOVersions<>( + new DataInnerIO(1) + ); + + /** + * @param ver Page format version. + */ + DataInnerIO(int ver) { + super(T_DATA_REF_INNER, ver, true, 12); + } + + /** {@inheritDoc} */ + @Override public int getCacheId(long pageAddr, int idx) { + return UNDEFINED_CACHE_ID; + } + + /** {@inheritDoc} */ + @Override protected boolean storeCacheId() { + return false; + } + } + + /** + * + */ + public static final class DataLeafIO extends AbstractDataLeafIO { + /** */ + public static final IOVersions VERSIONS = new IOVersions<>( + new DataLeafIO(1) + ); + + /** + * @param ver Page format version. + */ + DataLeafIO(int ver) { + super(T_DATA_REF_LEAF, ver, 12); + } + + /** {@inheritDoc} */ + @Override public int getCacheId(long pageAddr, int idx) { + return UNDEFINED_CACHE_ID; + } + + /** {@inheritDoc} */ + @Override protected boolean storeCacheId() { + return false; + } + } + + /** + * + */ + public static final class CacheIdAwareDataInnerIO extends AbstractDataInnerIO { + /** */ + public static final IOVersions VERSIONS = new IOVersions<>( + new CacheIdAwareDataInnerIO(1) + ); + + /** + * @param ver Page format version. + */ + CacheIdAwareDataInnerIO(int ver) { + super(T_CACHE_ID_AWARE_DATA_REF_INNER, ver, true, 16); + } + + /** {@inheritDoc} */ + @Override public int getCacheId(long pageAddr, int idx) { + return PageUtils.getInt(pageAddr, offset(idx) + 12); + } + + /** {@inheritDoc} */ + @Override protected boolean storeCacheId() { + return true; + } + } + + /** + * + */ + public static final class CacheIdAwareDataLeafIO extends AbstractDataLeafIO { + /** */ + public static final IOVersions VERSIONS = new IOVersions<>( + new CacheIdAwareDataLeafIO(1) + ); + + /** + * @param ver Page format version. + */ + CacheIdAwareDataLeafIO(int ver) { + super(T_CACHE_ID_AWARE_DATA_REF_LEAF, ver, 16); + } + + /** {@inheritDoc} */ + @Override public int getCacheId(long pageAddr, int idx) { + return PageUtils.getInt(pageAddr, offset(idx) + 12); + } + + /** {@inheritDoc} */ + @Override protected boolean storeCacheId() { + return true; + } } /** @@ -1843,38 +2270,47 @@ private static class PendingRow { /** Link. */ private long link; + /** Cache ID. */ + private int cacheId; + /** */ private KeyCacheObject key; /** + * Creates a new instance which represents an upper or lower bound + * inside a logical cache. + * + * @param cacheId Cache ID. + */ + public PendingRow(int cacheId) { + this.cacheId = cacheId; + } + + /** + * @param cacheId Cache ID. * @param expireTime Expire time. * @param link Link */ - PendingRow(long expireTime, long link) { + PendingRow(int cacheId, long expireTime, long link) { assert expireTime != 0; + this.cacheId = cacheId; this.expireTime = expireTime; this.link = link; } /** - * @param cctx Context. - * @param expireTime Expire time. - * @param link Link. + * @param grp Cache group. * @return Row. * @throws IgniteCheckedException If failed. */ - static PendingRow createRowWithKey(GridCacheContext cctx, long expireTime, long link) - throws IgniteCheckedException { - PendingRow row = new PendingRow(expireTime, link); - + PendingRow initKey(CacheGroupContext grp) throws IgniteCheckedException { CacheDataRowAdapter rowData = new CacheDataRowAdapter(link); + rowData.initFromLink(grp, CacheDataRowAdapter.RowData.KEY_ONLY); - rowData.initFromLink(cctx, CacheDataRowAdapter.RowData.KEY_ONLY); + key = rowData.key(); - row.key = rowData.key(); - - return row; + return this; } /** {@inheritDoc} */ @@ -1888,10 +2324,13 @@ static PendingRow createRowWithKey(GridCacheContext cctx, long expireTime, long */ protected static class PendingEntriesTree extends BPlusTree { /** */ - private final GridCacheContext cctx; + private final static Object WITHOUT_KEY = new Object(); + + /** */ + private final CacheGroupContext grp; /** - * @param cctx Cache context. + * @param grp Cache group. * @param name Tree name. * @param pageMem Page memory. * @param metaPageId Meta page ID. @@ -1900,7 +2339,7 @@ protected static class PendingEntriesTree extends BPlusTree io, long pageAddr, int idx, PendingRow row) + @Override protected int compare(BPlusIO iox, long pageAddr, int idx, PendingRow row) throws IgniteCheckedException { - long expireTime = ((PendingRowIO)io).getExpireTime(pageAddr, idx); + PendingRowIO io = (PendingRowIO)iox; - int cmp = Long.compare(expireTime, row.expireTime); + int cmp; + + if (grp.sharedGroup()) { + assert row.cacheId != UNDEFINED_CACHE_ID : "Cache ID is not provided!"; + assert io.getCacheId(pageAddr, idx) != UNDEFINED_CACHE_ID : "Cache ID is not stored!"; + + cmp = Integer.compare(io.getCacheId(pageAddr, idx), row.cacheId); + + if (cmp != 0) + return cmp; + + if(cmp == 0 && row.expireTime == 0 && row.link == 0) { + // A search row with a cach ID only is used as a cache bound. + // The found position will be shifted until the exact cache bound is found; + // See for details: + // o.a.i.i.p.c.database.tree.BPlusTree.ForwardCursor.findLowerBound() + // o.a.i.i.p.c.database.tree.BPlusTree.ForwardCursor.findUpperBound() + return cmp; + } + } + + long expireTime = io.getExpireTime(pageAddr, idx); + + cmp = Long.compare(expireTime, row.expireTime); if (cmp != 0) return cmp; @@ -1935,15 +2397,17 @@ public PendingEntriesTree( if (row.link == 0L) return 0; - long link = ((PendingRowIO)io).getLink(pageAddr, idx); + long link = io.getLink(pageAddr, idx); return Long.compare(link, row.link); } /** {@inheritDoc} */ - @Override protected PendingRow getRow(BPlusIO io, long pageAddr, int idx, Object ignore) + @Override protected PendingRow getRow(BPlusIO io, long pageAddr, int idx, Object flag) throws IgniteCheckedException { - return io.getLookupRow(this, pageAddr, idx); + PendingRow row = io.getLookupRow(this, pageAddr, idx); + + return flag == WITHOUT_KEY ? row : row.initKey(grp); } } @@ -1964,22 +2428,27 @@ private interface PendingRowIO { * @return Link. */ long getLink(long pageAddr, int idx); + + /** + * @param pageAddr Page address. + * @param idx Index. + * @return Cache ID or {@code 0} if Cache ID is not defined. + */ + int getCacheId(long pageAddr, int idx); } /** * */ - public static class PendingEntryInnerIO extends BPlusInnerIO implements PendingRowIO { - /** */ - public static final IOVersions VERSIONS = new IOVersions<>( - new PendingEntryInnerIO(1) - ); - + private static abstract class AbstractPendingEntryInnerIO extends BPlusInnerIO implements PendingRowIO { /** + * @param type Page type. * @param ver Page format version. + * @param canGetRow If we can get full row from this page. + * @param itemSize Single item size on page. */ - PendingEntryInnerIO(int ver) { - super(T_PENDING_REF_INNER, ver, true, 8 + 8); + protected AbstractPendingEntryInnerIO(int type, int ver, boolean canGetRow, int itemSize) { + super(type, ver, canGetRow, itemSize); } /** {@inheritDoc} */ @@ -1989,6 +2458,12 @@ public static class PendingEntryInnerIO extends BPlusInnerIO impleme PageUtils.putLong(pageAddr, off, row.expireTime); PageUtils.putLong(pageAddr, off + 8, row.link); + + if (storeCacheId()) { + assert row.cacheId != UNDEFINED_CACHE_ID; + + PageUtils.putInt(pageAddr, off + 16, row.cacheId); + } } /** {@inheritDoc} */ @@ -2004,14 +2479,20 @@ public static class PendingEntryInnerIO extends BPlusInnerIO impleme PageUtils.putLong(dstPageAddr, dstOff, expireTime); PageUtils.putLong(dstPageAddr, dstOff + 8, link); + + if (storeCacheId()) { + int cacheId = ((PendingRowIO)srcIo).getCacheId(srcPageAddr, srcIdx); + + assert cacheId != UNDEFINED_CACHE_ID; + + PageUtils.putInt(dstPageAddr, dstOff + 16, cacheId); + } } /** {@inheritDoc} */ @Override public PendingRow getLookupRow(BPlusTree tree, long pageAddr, int idx) throws IgniteCheckedException { - return PendingRow.createRowWithKey(((PendingEntriesTree)tree).cctx, - getExpireTime(pageAddr, idx), - getLink(pageAddr, idx)); + return new PendingRow(getCacheId(pageAddr, idx), getExpireTime(pageAddr, idx), getLink(pageAddr, idx)); } /** {@inheritDoc} */ @@ -2023,22 +2504,24 @@ public static class PendingEntryInnerIO extends BPlusInnerIO impleme @Override public long getLink(long pageAddr, int idx) { return PageUtils.getLong(pageAddr, offset(idx) + 8); } + + /** + * @return {@code True} if cache ID has to be stored. + */ + protected abstract boolean storeCacheId(); } /** * */ - public static class PendingEntryLeafIO extends BPlusLeafIO implements PendingRowIO { - /** */ - public static final IOVersions VERSIONS = new IOVersions<>( - new PendingEntryLeafIO(1) - ); - + private static abstract class AbstractPendingEntryLeafIO extends BPlusLeafIO implements PendingRowIO { /** + * @param type Page type. * @param ver Page format version. + * @param itemSize Single item size on page. */ - PendingEntryLeafIO(int ver) { - super(T_PENDING_REF_LEAF, ver, 8 + 8); + protected AbstractPendingEntryLeafIO(int type, int ver, int itemSize) { + super(type, ver, itemSize); } /** {@inheritDoc} */ @@ -2048,6 +2531,12 @@ public static class PendingEntryLeafIO extends BPlusLeafIO implement PageUtils.putLong(pageAddr, off, row.expireTime); PageUtils.putLong(pageAddr, off + 8, row.link); + + if (storeCacheId()) { + assert row.cacheId != UNDEFINED_CACHE_ID; + + PageUtils.putInt(pageAddr, off + 16, row.cacheId); + } } /** {@inheritDoc} */ @@ -2063,14 +2552,20 @@ public static class PendingEntryLeafIO extends BPlusLeafIO implement PageUtils.putLong(dstPageAddr, dstOff, expireTime); PageUtils.putLong(dstPageAddr, dstOff + 8, link); + + if (storeCacheId()) { + int cacheId = ((PendingRowIO)srcIo).getCacheId(srcPageAddr, srcIdx); + + assert cacheId != UNDEFINED_CACHE_ID; + + PageUtils.putInt(dstPageAddr, dstOff + 16, cacheId); + } } /** {@inheritDoc} */ @Override public PendingRow getLookupRow(BPlusTree tree, long pageAddr, int idx) throws IgniteCheckedException { - return PendingRow.createRowWithKey(((PendingEntriesTree)tree).cctx, - getExpireTime(pageAddr, idx), - getLink(pageAddr, idx)); + return new PendingRow(getCacheId(pageAddr, idx), getExpireTime(pageAddr, idx), getLink(pageAddr, idx)); } /** {@inheritDoc} */ @@ -2082,5 +2577,118 @@ public static class PendingEntryLeafIO extends BPlusLeafIO implement @Override public long getLink(long pageAddr, int idx) { return PageUtils.getLong(pageAddr, offset(idx) + 8); } + + /** + * @return {@code True} if cache ID has to be stored. + */ + protected abstract boolean storeCacheId(); + } + + /** + * + */ + public static final class PendingEntryInnerIO extends AbstractPendingEntryInnerIO { + /** */ + public static final IOVersions VERSIONS = new IOVersions<>( + new PendingEntryInnerIO(1) + ); + + /** + * @param ver Page format version. + */ + PendingEntryInnerIO(int ver) { + super(T_PENDING_REF_INNER, ver, true, 16); + } + + /** {@inheritDoc} */ + @Override public int getCacheId(long pageAddr, int idx) { + return UNDEFINED_CACHE_ID; + } + + /** {@inheritDoc} */ + @Override protected boolean storeCacheId() { + return false; + } + } + + /** + * + */ + public static final class PendingEntryLeafIO extends AbstractPendingEntryLeafIO { + /** */ + public static final IOVersions VERSIONS = new IOVersions<>( + new PendingEntryLeafIO(1) + ); + + /** + * @param ver Page format version. + */ + PendingEntryLeafIO(int ver) { + super(T_PENDING_REF_LEAF, ver, 16); + } + + /** {@inheritDoc} */ + @Override public int getCacheId(long pageAddr, int idx) { + return UNDEFINED_CACHE_ID; + } + + /** {@inheritDoc} */ + @Override protected boolean storeCacheId() { + return false; + } + } + + /** + * + */ + public static final class CacheIdAwarePendingEntryInnerIO extends AbstractPendingEntryInnerIO { + /** */ + public static final IOVersions VERSIONS = new IOVersions<>( + new CacheIdAwarePendingEntryInnerIO(1) + ); + + /** + * @param ver Page format version. + */ + CacheIdAwarePendingEntryInnerIO(int ver) { + super(T_CACHE_ID_AWARE_PENDING_REF_INNER, ver, true, 20); + } + + /** {@inheritDoc} */ + @Override public int getCacheId(long pageAddr, int idx) { + return PageUtils.getInt(pageAddr, offset(idx) + 16); + } + + /** {@inheritDoc} */ + @Override protected boolean storeCacheId() { + return true; + } + } + + /** + * + */ + public static final class CacheIdAwarePendingEntryLeafIO extends AbstractPendingEntryLeafIO { + /** */ + public static final IOVersions VERSIONS = new IOVersions<>( + new CacheIdAwarePendingEntryLeafIO(1) + ); + + /** + * @param ver Page format version. + */ + CacheIdAwarePendingEntryLeafIO(int ver) { + super(T_CACHE_ID_AWARE_PENDING_REF_LEAF, ver, 20); + } + + /** {@inheritDoc} */ + @Override public int getCacheId(long pageAddr, int idx) { + return PageUtils.getInt(pageAddr, offset(idx) + 16); + } + + /** {@inheritDoc} */ + @Override protected boolean storeCacheId() { + return true; + } } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java index 41b32819e7ef7..1cdeb3f41f6de 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java @@ -63,12 +63,7 @@ public GridCacheAffinityImpl(GridCacheContext cctx) { /** {@inheritDoc} */ @Override public int partitions() { - CacheConfiguration ccfg = cctx.config(); - - if (ccfg == null) - throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name()); - - return ccfg.getAffinity().partitions(); + return cctx.group().affinityFunction().partitions(); } /** {@inheritDoc} */ @@ -196,7 +191,7 @@ public GridCacheAffinityImpl(GridCacheContext cctx) { int nodesCnt; if (!cctx.isLocal()) - nodesCnt = cctx.discovery().cacheAffinityNodes(cctx.cacheId(), topVer).size(); + nodesCnt = cctx.discovery().cacheGroupAffinityNodes(cctx.groupId(), topVer).size(); else nodesCnt = 1; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRow.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRow.java index e0076d5ff37ac..cc26b21e358e3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRow.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRow.java @@ -35,11 +35,6 @@ public interface CacheDataRow extends CacheSearchRow { */ public GridCacheVersion version(); - /** - * @return Cache id. Stored only if memory policy with configured per-page eviction is used. - */ - public int cacheId(); - /** * @return Expire time. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java index 955ca69985c6e..a25d7942559b2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java @@ -19,13 +19,12 @@ import java.nio.ByteBuffer; import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.configuration.DataPageEvictionMode; import org.apache.ignite.internal.pagemem.PageIdUtils; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.PageUtils; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.CacheObjectContext; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.IncompleteCacheObject; import org.apache.ignite.internal.processors.cache.IncompleteObject; @@ -94,25 +93,26 @@ public CacheDataRowAdapter(KeyCacheObject key, CacheObject val, GridCacheVersion /** * Read row from data pages. * - * @param cctx Cache context. + * @param grp Cache group. * @param rowData Required row data. * @throws IgniteCheckedException If failed. */ - public final void initFromLink(GridCacheContext cctx, RowData rowData) throws IgniteCheckedException { - initFromLink(cctx, cctx.shared(), cctx.memoryPolicy().pageMemory(), rowData); + public final void initFromLink(CacheGroupContext grp, RowData rowData) throws IgniteCheckedException { + initFromLink(grp, grp.shared(), grp.memoryPolicy().pageMemory(), rowData); } /** * Read row from data pages. * Can be called with cctx == null, if cache instance is unknown, but its ID is stored in the data row. * - * @param cctx Cctx. + * @param grp Cache group. * @param sharedCtx Shared context. * @param pageMem Page memory. * @param rowData Row data. + * @throws IgniteCheckedException If failed. */ public final void initFromLink( - @Nullable GridCacheContext cctx, + @Nullable CacheGroupContext grp, GridCacheSharedContext sharedCtx, PageMemory pageMem, RowData rowData) @@ -120,14 +120,9 @@ public final void initFromLink( assert link != 0 : "link"; assert key == null : "key"; - CacheObjectContext coctx = null; - - if (cctx != null) { - cacheId = cctx.memoryPolicy().config().getPageEvictionMode() == DataPageEvictionMode.DISABLED ? - cctx.cacheId() : 0; // Force cacheId reading for evictable memory policies. + CacheObjectContext coctx = grp != null ? grp.cacheObjectContext() : null; - coctx = cctx.cacheObjectContext(); - } + boolean readCacheId = grp == null || grp.storeCacheIdInDataPage(); long nextLink = link; IncompleteObject incomplete = null; @@ -135,10 +130,16 @@ public final void initFromLink( do { final long pageId = pageId(nextLink); - final long page = pageMem.acquirePage(cacheId, pageId); + + // Group is null if try evict page, with persistence evictions should be disabled. + assert grp != null || !sharedCtx.database().persistenceEnabled(); + + int grpId = grp != null ? grp.groupId() : 0; + + final long page = pageMem.acquirePage(grpId, pageId); try { - long pageAddr = pageMem.readLock(cacheId, pageId, page); // Non-empty data page must not be recycled. + long pageAddr = pageMem.readLock(grpId, pageId, page); // Non-empty data page must not be recycled. assert pageAddr != 0L : nextLink; @@ -154,7 +155,7 @@ public final void initFromLink( if (first) { if (nextLink == 0) { // Fast path for a single page row. - readFullRow(sharedCtx, coctx, pageAddr + data.offset(), rowData); + readFullRow(sharedCtx, coctx, pageAddr + data.offset(), rowData, readCacheId); return; } @@ -169,17 +170,17 @@ public final void initFromLink( boolean keyOnly = rowData == RowData.KEY_ONLY; - incomplete = readFragment(sharedCtx, coctx, buf, keyOnly, incomplete); + incomplete = readFragment(sharedCtx, coctx, buf, keyOnly, readCacheId, incomplete); if (keyOnly && key != null) return; } finally { - pageMem.readUnlock(cacheId, pageId, page); + pageMem.readUnlock(grpId, pageId, page); } } finally { - pageMem.releasePage(cacheId, pageId, page); + pageMem.releasePage(grpId, pageId, page); } } while(nextLink != 0); @@ -188,9 +189,11 @@ public final void initFromLink( } /** + * @param sharedCtx Cache shared context. * @param coctx Cache object context. * @param buf Buffer. * @param keyOnly {@code true} If need to read only key object. + * @param readCacheId {@code true} If need to read cache ID. * @param incomplete Incomplete object. * @throws IgniteCheckedException If failed. * @return Read object. @@ -200,9 +203,10 @@ private IncompleteObject readFragment( CacheObjectContext coctx, ByteBuffer buf, boolean keyOnly, + boolean readCacheId, IncompleteObject incomplete ) throws IgniteCheckedException { - if (cacheId == 0) { + if (readCacheId && cacheId == 0) { incomplete = readIncompleteCacheId(buf, incomplete); if (cacheId == 0) @@ -211,8 +215,13 @@ private IncompleteObject readFragment( incomplete = null; } - if (coctx == null) + if (coctx == null) { + // coctx can be null only when grp is null too, this means that + // we are in process of eviction and cacheId is mandatory part of data. + assert cacheId != 0; + coctx = sharedCtx.cacheContext(cacheId).cacheObjectContext(); + } // Read key. if (key == null) { @@ -251,20 +260,23 @@ private IncompleteObject readFragment( } /** + * @param sharedCtx Cache shared context. * @param coctx Cache object context. * @param addr Address. * @param rowData Required row data. + * @param readCacheId {@code true} If need to read cache ID. * @throws IgniteCheckedException If failed. */ private void readFullRow( GridCacheSharedContext sharedCtx, CacheObjectContext coctx, long addr, - RowData rowData) + RowData rowData, + boolean readCacheId) throws IgniteCheckedException { int off = 0; - if (cacheId == 0) { + if (readCacheId) { cacheId = PageUtils.getInt(addr, off); off += 4; @@ -328,6 +340,8 @@ private IncompleteObject readIncompleteCacheId( if (remaining >= size) { cacheId = buf.getInt(); + assert cacheId != 0; + return null; } @@ -342,6 +356,8 @@ private IncompleteObject readIncompleteCacheId( timeBuf.order(buf.order()); cacheId = timeBuf.getInt(); + + assert cacheId != 0; } return incomplete; @@ -401,7 +417,6 @@ private IncompleteCacheObject readIncompleteValue( * @param buf Buffer. * @param incomplete Incomplete object. * @return Incomplete object. - * @throws IgniteCheckedException If failed. */ private IncompleteObject readIncompleteExpireTime( ByteBuffer buf, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheSearchRow.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheSearchRow.java index d51cf0ec0d90f..6e429c48fef12 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheSearchRow.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheSearchRow.java @@ -37,4 +37,9 @@ public interface CacheSearchRow { * @return Key hash code. */ public int hash(); + + /** + * @return Cache ID or {@code 0} if cache ID is not defined. + */ + public int cacheId(); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index fd5e2a2668589..19c25aa11d08d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -39,6 +39,7 @@ import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; @@ -730,9 +731,9 @@ public void beforeExchange(GridDhtPartitionsExchangeFuture discoEvt) throws Igni } /** - * @param stoppedCtxs A collection of tuples (cache context, destroy flag). + * @param stoppedGrps A collection of tuples (cache group, destroy flag). */ - public void onCachesStopped(Collection> stoppedCtxs) { + public void onCacheGroupsStopped(Collection> stoppedGrps) { // No-op. } @@ -768,12 +769,12 @@ public void releaseHistoryForExchange() { /** * Reserve update history for preloading. - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param partId Partition Id. * @param cntr Update counter. * @return True if successfully reserved. */ - public boolean reserveHistoryForPreloading(int cacheId, int partId, long cntr) { + public boolean reserveHistoryForPreloading(int grpId, int partId, long cntr) { return false; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java index 5b87cf764d3ef..91957dbcc9a9e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java @@ -64,49 +64,49 @@ public boolean onMarkCheckPointBegin( * */ public void restoreState() throws IgniteCheckedException { - + // No-op. } /** * */ public void onCheckPointBegin() { - + // No-op. } /** * */ public void beforeCheckpointPageWritten() { - + // No-op. } /** * */ public void afterCheckpointPageWritten() { - + // No-op. } /** * @param fullId Full id. */ public void beforePageWrite(FullPageId fullId) { - + // No-op. } /** * @param fullId Full id. */ public void onPageWrite(FullPageId fullId, ByteBuffer tmpWriteBuf) { - + // No-op. } /** * @param cctx Cctx. */ public void onCacheStop(GridCacheContext cctx) { - + // No-op. } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetaStore.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetaStore.java index 91fed4c0c01b8..c21b8183400c5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetaStore.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetaStore.java @@ -29,7 +29,7 @@ public interface MetaStore { * @param idxName Index name. * @return {@link RootPage} that keeps pageId, allocated flag that shows whether the page * was newly allocated, and rootId that is counter which increments each time new page allocated. - * @throws IgniteCheckedException + * @throws IgniteCheckedException If failed. */ public RootPage getOrAllocateForTree(String idxName) throws IgniteCheckedException; @@ -38,14 +38,14 @@ public interface MetaStore { * * @param idxName Index name. * @return Root ID or -1 if no page was removed. - * @throws IgniteCheckedException + * @throws IgniteCheckedException If failed. */ public RootPage dropRootPage(String idxName) throws IgniteCheckedException; /** * Destroy this meta store. * - * @throws IgniteCheckedException + * @throws IgniteCheckedException If failed. */ public void destroy() throws IgniteCheckedException; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java index ca4ad05535fd3..139bf7333dddb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java @@ -53,8 +53,8 @@ public class MetadataStorage implements MetaStore { /** Meta page reuse tree. */ private final ReuseList reuseList; - /** Cache ID. */ - private final int cacheId; + /** Cache group ID. */ + private final int grpId; /** */ private final int allocPartId; @@ -70,7 +70,7 @@ public MetadataStorage( final PageMemory pageMem, final IgniteWriteAheadLogManager wal, final AtomicLong globalRmvId, - final int cacheId, + final int grpId, final int allocPartId, final byte allocSpace, final ReuseList reuseList, @@ -79,12 +79,12 @@ public MetadataStorage( ) { try { this.pageMem = pageMem; - this.cacheId = cacheId; + this.grpId = grpId; this.allocPartId = allocPartId; this.allocSpace = allocSpace; this.reuseList = reuseList; - metaTree = new MetaTree(cacheId, allocPartId, allocSpace, pageMem, wal, globalRmvId, rootPageId, + metaTree = new MetaTree(grpId, allocPartId, allocSpace, pageMem, wal, globalRmvId, rootPageId, reuseList, MetaStoreInnerIO.VERSIONS, MetaStoreLeafIO.VERSIONS, initNew); } catch (IgniteCheckedException e) { @@ -111,14 +111,14 @@ public MetadataStorage( if (reuseList != null) pageId = reuseList.takeRecycledPage(); - pageId = pageId == 0 ? pageMem.allocatePage(cacheId, allocPartId, allocSpace) : pageId; + pageId = pageId == 0 ? pageMem.allocatePage(grpId, allocPartId, allocSpace) : pageId; tree.put(new IndexItem(idxNameBytes, pageId)); - return new RootPage(new FullPageId(pageId, cacheId), true); + return new RootPage(new FullPageId(pageId, grpId), true); } else { - final FullPageId pageId = new FullPageId(row.pageId, cacheId); + final FullPageId pageId = new FullPageId(row.pageId, grpId); return new RootPage(pageId, false); } @@ -134,10 +134,10 @@ public MetadataStorage( if (row != null) { if (reuseList == null) - pageMem.freePage(cacheId, row.pageId); + pageMem.freePage(grpId, row.pageId); } - return row != null ? new RootPage(new FullPageId(row.pageId, cacheId), false) : null; + return row != null ? new RootPage(new FullPageId(row.pageId, grpId), false) : null; } /** {@inheritDoc} */ @@ -288,7 +288,7 @@ private static void storeRow( PageUtils.putByte(dstPageAddr, dstOff, len); dstOff++; - PageHandler.copyMemory(srcPageAddr, srcOff, dstPageAddr, dstOff, len); + PageHandler.copyMemory(srcPageAddr, dstPageAddr, srcOff, dstOff, len); srcOff += len; dstOff += len; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java index 563902b714b8c..d707869001557 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java @@ -19,8 +19,9 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheObjectContext; -import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.database.freelist.FreeList; /** @@ -31,27 +32,29 @@ public class RowStore { private final FreeList freeList; /** */ - protected final PageMemory pageMem; + private final GridCacheSharedContext ctx; /** */ - protected final GridCacheContext cctx; + protected final PageMemory pageMem; /** */ protected final CacheObjectContext coctx; + + /** - * @param cctx Cache context. + * @param grp Cache group. * @param freeList Free list. */ - public RowStore(GridCacheContext cctx, FreeList freeList) { - assert cctx != null; + public RowStore(CacheGroupContext grp, FreeList freeList) { + assert grp != null; assert freeList != null; - this.cctx = cctx; this.freeList = freeList; - coctx = cctx.cacheObjectContext(); - pageMem = cctx.memoryPolicy().pageMemory(); + ctx = grp.shared(); + coctx = grp.cacheObjectContext(); + pageMem = grp.memoryPolicy().pageMemory(); } /** @@ -60,13 +63,13 @@ public RowStore(GridCacheContext cctx, FreeList freeList) { */ public void removeRow(long link) throws IgniteCheckedException { assert link != 0; - cctx.shared().database().checkpointReadLock(); + ctx.database().checkpointReadLock(); try { freeList.removeDataRowByLink(link); } finally { - cctx.shared().database().checkpointReadUnlock(); + ctx.database().checkpointReadUnlock(); } } @@ -75,13 +78,13 @@ public void removeRow(long link) throws IgniteCheckedException { * @throws IgniteCheckedException If failed. */ public void addRow(CacheDataRow row) throws IgniteCheckedException { - cctx.shared().database().checkpointReadLock(); + ctx.database().checkpointReadLock(); try { freeList.insertDataRow(row); } finally { - cctx.shared().database().checkpointReadUnlock(); + ctx.database().checkpointReadUnlock(); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java index 2465d3fe7e1c3..d92f8119b2bff 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java @@ -884,11 +884,12 @@ private long getFirstPageId(long metaId, long metaPage, int lvl) { /** * @param upper Upper bound. + * @param x Implementation specific argument, {@code null} always means that we need to return full detached data row. * @return Cursor. * @throws IgniteCheckedException If failed. */ - private GridCursor findLowerUnbounded(L upper) throws IgniteCheckedException { - ForwardCursor cursor = new ForwardCursor(null, upper); + private GridCursor findLowerUnbounded(L upper, Object x) throws IgniteCheckedException { + ForwardCursor cursor = new ForwardCursor(null, upper, x); long firstPageId; @@ -933,14 +934,25 @@ private void checkDestroyed() { * @return Cursor. * @throws IgniteCheckedException If failed. */ - @Override public final GridCursor find(L lower, L upper) throws IgniteCheckedException { + @Override public GridCursor find(L lower, L upper) throws IgniteCheckedException { + return find(lower, upper, null); + } + + /** + * @param lower Lower bound inclusive or {@code null} if unbounded. + * @param upper Upper bound inclusive or {@code null} if unbounded. + * @param x Implementation specific argument, {@code null} always means that we need to return full detached data row. + * @return Cursor. + * @throws IgniteCheckedException If failed. + */ + public final GridCursor find(L lower, L upper, Object x) throws IgniteCheckedException { checkDestroyed(); try { if (lower == null) - return findLowerUnbounded(upper); + return findLowerUnbounded(upper, x); - ForwardCursor cursor = new ForwardCursor(lower, upper); + ForwardCursor cursor = new ForwardCursor(lower, upper, x); cursor.find(); @@ -4392,6 +4404,9 @@ private final class ForwardCursor implements GridCursor { /** */ private final L upperBound; + /** */ + private final Object x; + /** * @param lowerBound Lower bound. * @param upperBound Upper bound. @@ -4399,6 +4414,18 @@ private final class ForwardCursor implements GridCursor { ForwardCursor(L lowerBound, L upperBound) { this.lowerBound = lowerBound; this.upperBound = upperBound; + this.x = null; + } + + /** + * @param lowerBound Lower bound. + * @param upperBound Upper bound. + * @param x Implementation specific argument, {@code null} always means that we need to return full detached data row. + */ + ForwardCursor(L lowerBound, L upperBound, Object x) { + this.lowerBound = lowerBound; + this.upperBound = upperBound; + this.x = x; } /** @@ -4515,7 +4542,7 @@ private boolean fillFromBuffer(long pageAddr, BPlusIO io, int startIdx, int c rows = (T[])new Object[cnt]; for (int i = 0; i < cnt; i++) { - T r = getRow(io, pageAddr, startIdx + i); + T r = getRow(io, pageAddr, startIdx + i, x); rows = GridArrays.set(rows, i, r); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java index 2586696c07dcc..e40ed11168f20 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java @@ -157,6 +157,21 @@ public abstract class PageIO { /** */ public static final short T_PAGE_UPDATE_TRACKING = 15; + /** */ + public static final short T_CACHE_ID_AWARE_DATA_REF_INNER = 16; + + /** */ + public static final short T_CACHE_ID_AWARE_DATA_REF_LEAF = 17; + + /** */ + public static final short T_CACHE_ID_AWARE_PENDING_REF_INNER = 18; + + /** */ + public static final short T_CACHE_ID_AWARE_PENDING_REF_LEAF = 19; + + /** */ + public static final short T_PART_CNTRS = 20; + /** Index for payload == 1. */ public static final short T_H2_EX_REF_LEAF_START = 10000; @@ -430,6 +445,9 @@ public static Q getPageIO(int type, int ver) throws IgniteChe case T_PART_META: return (Q)PagePartitionMetaIO.VERSIONS.forVersion(ver); + case T_PART_CNTRS: + return (Q)PagePartitionCountersIO.VERSIONS.forVersion(ver); + case T_PAGE_UPDATE_TRACKING: return (Q)TrackingPageIO.VERSIONS.forVersion(ver); @@ -484,6 +502,12 @@ public static > Q getBPlusIO(int type, int ver) throws Igni case T_DATA_REF_LEAF: return (Q)IgniteCacheOffheapManagerImpl.DataLeafIO.VERSIONS.forVersion(ver); + case T_CACHE_ID_AWARE_DATA_REF_INNER: + return (Q)IgniteCacheOffheapManagerImpl.CacheIdAwareDataInnerIO.VERSIONS.forVersion(ver); + + case T_CACHE_ID_AWARE_DATA_REF_LEAF: + return (Q)IgniteCacheOffheapManagerImpl.CacheIdAwareDataLeafIO.VERSIONS.forVersion(ver); + case T_METASTORE_INNER: return (Q)MetadataStorage.MetaStoreInnerIO.VERSIONS.forVersion(ver); @@ -496,6 +520,12 @@ public static > Q getBPlusIO(int type, int ver) throws Igni case T_PENDING_REF_LEAF: return (Q)IgniteCacheOffheapManagerImpl.PendingEntryLeafIO.VERSIONS.forVersion(ver); + case T_CACHE_ID_AWARE_PENDING_REF_INNER: + return (Q) IgniteCacheOffheapManagerImpl.CacheIdAwarePendingEntryInnerIO.VERSIONS.forVersion(ver); + + case T_CACHE_ID_AWARE_PENDING_REF_LEAF: + return (Q)IgniteCacheOffheapManagerImpl.CacheIdAwarePendingEntryLeafIO.VERSIONS.forVersion(ver); + default: // For tests. if (innerTestIO != null && innerTestIO.getType() == type && innerTestIO.getVersion() == ver) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionCountersIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionCountersIO.java new file mode 100644 index 0000000000000..015b8ff9e57a3 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionCountersIO.java @@ -0,0 +1,175 @@ +/* + * 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.database.tree.io; + +import java.util.Map; +import org.apache.ignite.internal.pagemem.PageUtils; + +/** + * + */ +public class PagePartitionCountersIO extends PageIO { + /** */ + private static final int CNT_OFF = COMMON_HEADER_END; + + /** */ + private static final int LAST_FLAG_OFF = CNT_OFF + 2; + + /** */ + private static final int NEXT_COUNTERS_PAGE_OFF = LAST_FLAG_OFF + 1; + + /** */ + private static final int ITEMS_OFF = NEXT_COUNTERS_PAGE_OFF + 8; + + /** */ + private static final int ITEM_SIZE = 12; + + /** */ + private static final byte LAST_FLAG = 0b1; + + /** */ + public static final IOVersions VERSIONS = new IOVersions<>( + new PagePartitionCountersIO(1) + ); + + /** + * @param ver Page format version. + */ + public PagePartitionCountersIO(int ver) { + super(T_PART_CNTRS, ver); + } + + /** {@inheritDoc} */ + @Override public void initNewPage(long pageAddr, long pageId, int pageSize) { + super.initNewPage(pageAddr, pageId, pageSize); + + setCount(pageAddr, 0); + setNextCountersPageId(pageAddr, 0); + } + + /** + * @param pageAddr Page address. + * @return Next counters page ID or {@code 0} if it does not exist. + */ + public long getNextCountersPageId(long pageAddr) { + return PageUtils.getLong(pageAddr, NEXT_COUNTERS_PAGE_OFF); + } + + /** + * @param pageAddr Page address. + * @param partMetaPageId Next counters page ID. + */ + public void setNextCountersPageId(long pageAddr, long partMetaPageId) { + PageUtils.putLong(pageAddr, NEXT_COUNTERS_PAGE_OFF, partMetaPageId); + } + + /** + * @param pageSize Page size. + * @param pageAddr Page address. + * @param cacheSizes Serialized cache size items (pairs of cache ID and its size). + * @return Number of written pairs. + */ + public int writeCacheSizes(int pageSize, long pageAddr, byte[] cacheSizes, int itemsOff) { + assert cacheSizes != null; + assert cacheSizes.length % ITEM_SIZE == 0 : cacheSizes.length; + + int cap = getCapacity(pageSize); + + int items = (cacheSizes.length / ITEM_SIZE) - itemsOff; + int write = Math.min(cap, items); + + if (write > 0) + // This can happen in case there are no items in a given partition for all caches in the group. + PageUtils.putBytes(pageAddr, ITEMS_OFF, cacheSizes, itemsOff * ITEM_SIZE, write * ITEM_SIZE); + + setCount(pageAddr, write); + + setLastFlag(pageAddr, write == items); + + return write; + } + + /** + * @param pageAddr Page address. + * @param res Result map of cache sizes. + * @return {@code True} if the map was fully read. + */ + public boolean readCacheSizes(long pageAddr, Map res) { + int cnt = getCount(pageAddr); + + assert cnt >= 0 && cnt <= Short.MAX_VALUE : cnt; + + if (cnt == 0) + return true; + + int off = ITEMS_OFF; + + for (int i = 0; i < cnt; i++) { + int cacheId = PageUtils.getInt(pageAddr, off); + off += 4; + + assert cacheId != 0; + + long cacheSize = PageUtils.getLong(pageAddr, off); + off += 8; + + assert cacheSize > 0 : cacheSize; + + Long old = res.put(cacheId, cacheSize); + + assert old == null; + } + + return getLastFlag(pageAddr); + } + + private boolean getLastFlag(long pageAddr) { + return PageUtils.getByte(pageAddr, LAST_FLAG_OFF) == LAST_FLAG; + } + + private void setLastFlag(long pageAddr, boolean last) { + PageUtils.putByte(pageAddr, LAST_FLAG_OFF, last ? LAST_FLAG : ~LAST_FLAG); + } + + /** + * @param pageAddr Page address. + * @return Stored items count. + */ + private int getCount(long pageAddr) { + return PageUtils.getShort(pageAddr, CNT_OFF); + } + + /** + * @param pageAddr Page address. + * @param cnt Stored items count. + */ + private void setCount(long pageAddr, int cnt) { + assert cnt >= 0 && cnt <= Short.MAX_VALUE : cnt; + + PageUtils.putShort(pageAddr, CNT_OFF, (short)cnt); + } + + /** + * @param pageSize Page size. + * @return Maximum number of items which can be stored in buffer. + */ + private int getCapacity(int pageSize) { + return (pageSize - ITEMS_OFF) / ITEM_SIZE; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java index aca0725ccafca..67cc5a394516d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java @@ -36,6 +36,9 @@ public class PagePartitionMetaIO extends PageMetaIO { /** */ private static final int PARTITION_STATE_OFF = GLOBAL_RMV_ID_OFF + 8; + /** */ + private static final int NEXT_PART_META_PAGE_OFF = PARTITION_STATE_OFF + 1; + /** */ public static final IOVersions VERSIONS = new IOVersions<>( new PagePartitionMetaIO(1) @@ -49,6 +52,7 @@ public class PagePartitionMetaIO extends PageMetaIO { setUpdateCounter(pageAddr, 0); setGlobalRemoveId(pageAddr, 0); setPartitionState(pageAddr, (byte)-1); + setCountersPageId(pageAddr, 0); } /** @@ -120,4 +124,20 @@ public byte getPartitionState(long pageAddr) { public void setPartitionState(long pageAddr, byte state) { PageUtils.putByte(pageAddr, PARTITION_STATE_OFF, state); } + + /** + * @param pageAddr Page address. + * @return Next meta partial page ID or {@code 0} if it does not exist. + */ + public long getCountersPageId(long pageAddr) { + return PageUtils.getLong(pageAddr, NEXT_PART_META_PAGE_OFF); + } + + /** + * @param pageAddr Page address. + * @param metaPageId Next partial meta page ID. + */ + public void setCountersPageId(long pageAddr, long metaPageId) { + PageUtils.putLong(pageAddr, NEXT_PART_META_PAGE_OFF, metaPageId); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java index 5d1885ea00195..c092132192c74 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java @@ -24,7 +24,7 @@ import org.apache.ignite.internal.GridDirectCollection; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; @@ -38,7 +38,7 @@ /** * */ -public class GridCacheTtlUpdateRequest extends GridCacheMessage { +public class GridCacheTtlUpdateRequest extends GridCacheIdMessage { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java index 630c79f9be78a..fc209aaa956f0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java @@ -24,7 +24,7 @@ import org.apache.ignite.internal.GridDirectCollection; import org.apache.ignite.internal.GridDirectTransient; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.processors.cache.version.GridCacheVersionable; import org.apache.ignite.internal.util.tostring.GridToStringExclude; @@ -37,7 +37,7 @@ /** * Base for all messages in replicated cache. */ -public abstract class GridDistributedBaseMessage extends GridCacheMessage implements GridCacheDeployable, +public abstract class GridDistributedBaseMessage extends GridCacheIdMessage implements GridCacheDeployable, GridCacheVersionable { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java index c966877358cb0..dc9e4ecc3a772 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java @@ -79,10 +79,9 @@ protected GridDistributedCacheAdapter() { /** * @param ctx Cache registry. - * @param startSize Start size. */ - protected GridDistributedCacheAdapter(GridCacheContext ctx, int startSize) { - super(ctx, startSize); + protected GridDistributedCacheAdapter(GridCacheContext ctx) { + super(ctx); } /** @@ -279,11 +278,11 @@ private void removeAllAsync( IgniteCacheOffheapManager offheap = ctx.offheap(); if (modes.offheap) - size += offheap.entriesCount(modes.primary, modes.backup, topVer); + size += offheap.cacheEntriesCount(ctx.cacheId(), modes.primary, modes.backup, topVer); else if (modes.heap) { for (GridDhtLocalPartition locPart : ctx.topology().currentLocalPartitions()) { if ((modes.primary && locPart.primary(topVer)) || (modes.backup && locPart.backup(topVer))) - size += locPart.publicSize(); + size += locPart.publicSize(ctx.cacheId()); } } } @@ -308,7 +307,7 @@ else if (modes.heap) { if (ctx.affinity().primaryByPartition(ctx.localNode(), part, topVer) && modes.primary || ctx.affinity().backupByPartition(ctx.localNode(), part, topVer) && modes.backup) - size += offheap.entriesCount(part); + size += offheap.cacheEntriesCount(ctx.cacheId(), part); } return size; @@ -460,7 +459,7 @@ private GlobalRemoveAllJob( return false; try { - GridCloseableIterator iter = dht.context().offheap().keysIterator(part); + GridCloseableIterator iter = dht.context().offheap().cacheKeysIterator(ctx.cacheId(), part); if (iter != null) { try { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishResponse.java index 561c292cd8034..c36e6336d4f7c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishResponse.java @@ -70,6 +70,16 @@ public GridDistributedTxFinishResponse(int part, GridCacheVersion txId, IgniteUu this.futId = futId; } + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return false; + } + /** {@inheritDoc} */ @Override public final int partition() { return part; @@ -135,25 +145,25 @@ public IgniteUuid futureId() { } switch (writer.state()) { - case 3: + case 2: if (!writer.writeByte("flags", flags)) return false; writer.incrementState(); - case 4: + case 3: if (!writer.writeIgniteUuid("futId", futId)) return false; writer.incrementState(); - case 5: + case 4: if (!writer.writeInt("part", part)) return false; writer.incrementState(); - case 6: + case 5: if (!writer.writeMessage("txId", txId)) return false; @@ -175,7 +185,7 @@ public IgniteUuid futureId() { return false; switch (reader.state()) { - case 3: + case 2: flags = reader.readByte("flags"); if (!reader.isLastRead()) @@ -183,7 +193,7 @@ public IgniteUuid futureId() { reader.incrementState(); - case 4: + case 3: futId = reader.readIgniteUuid("futId"); if (!reader.isLastRead()) @@ -191,7 +201,7 @@ public IgniteUuid futureId() { reader.incrementState(); - case 5: + case 4: part = reader.readInt("part"); if (!reader.isLastRead()) @@ -199,7 +209,7 @@ public IgniteUuid futureId() { reader.incrementState(); - case 6: + case 5: txId = reader.readMessage("txId"); if (!reader.isLastRead()) @@ -219,7 +229,7 @@ public IgniteUuid futureId() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 7; + return 6; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java index 714d7810999a0..5e3020daf8f25 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java @@ -594,6 +594,8 @@ else if (conflictCtx.isMerge()) { dhtVer, txEntry.updateCounter()); else { + assert val != null : txEntry; + cached.innerSet(this, eventNodeId(), nodeId, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedConcurrentMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedConcurrentMap.java index 76c7a15c2ae71..3b41ffa067fe0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedConcurrentMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedConcurrentMap.java @@ -25,7 +25,7 @@ import java.util.Set; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; -import org.apache.ignite.internal.processors.cache.CacheObject; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; @@ -38,24 +38,25 @@ * An implementation of GridCacheConcurrentMap that will delegate all method calls to corresponding local partition. */ public class GridCachePartitionedConcurrentMap implements GridCacheConcurrentMap { - /** Context. */ - private final GridCacheContext ctx; + /** Cache group. */ + private final CacheGroupContext grp; /** - * Constructor. - * @param ctx Context. + * @param grp Cache group. */ - public GridCachePartitionedConcurrentMap(GridCacheContext ctx) { - this.ctx = ctx; + GridCachePartitionedConcurrentMap(CacheGroupContext grp) { + this.grp = grp; } /** + * @param cctx Cache context. * @param key Key. * @param topVer Topology version. * @param create Create flag. * @return Local partition. */ @Nullable private GridDhtLocalPartition localPartition( + GridCacheContext cctx, KeyCacheObject key, AffinityTopologyVersion topVer, boolean create @@ -63,33 +64,33 @@ public GridCachePartitionedConcurrentMap(GridCacheContext ctx) { int p = key.partition(); if (p == -1) - p = ctx.affinity().partition(key); + p = cctx.affinity().partition(key); - return ctx.topology().localPartition(p, topVer, create); + return grp.topology().localPartition(p, topVer, create); } /** {@inheritDoc} */ - @Nullable @Override public GridCacheMapEntry getEntry(KeyCacheObject key) { - GridDhtLocalPartition part = localPartition(key, AffinityTopologyVersion.NONE, false); + @Nullable @Override public GridCacheMapEntry getEntry(GridCacheContext ctx, KeyCacheObject key) { + GridDhtLocalPartition part = localPartition(ctx, key, AffinityTopologyVersion.NONE, false); if (part == null) return null; - return part.getEntry(key); + return part.getEntry(ctx, key); } /** {@inheritDoc} */ - @Override public GridCacheMapEntry putEntryIfObsoleteOrAbsent(AffinityTopologyVersion topVer, + @Override public GridCacheMapEntry putEntryIfObsoleteOrAbsent(GridCacheContext ctx, AffinityTopologyVersion topVer, KeyCacheObject key, boolean create, boolean touch) { while (true) { - GridDhtLocalPartition part = localPartition(key, topVer, create); + GridDhtLocalPartition part = localPartition(ctx, key, topVer, create); if (part == null) return null; - GridCacheMapEntry res = part.putEntryIfObsoleteOrAbsent(topVer, key, create, touch); + GridCacheMapEntry res = part.putEntryIfObsoleteOrAbsent(ctx, topVer, key, create, touch); if (res != null || !create) return res; @@ -102,35 +103,35 @@ public GridCachePartitionedConcurrentMap(GridCacheContext ctx) { @Override public int internalSize() { int size = 0; - for (GridDhtLocalPartition part : ctx.topology().currentLocalPartitions()) + for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) size += part.internalSize(); return size; } /** {@inheritDoc} */ - @Override public int publicSize() { + @Override public int publicSize(int cacheId) { int size = 0; - for (GridDhtLocalPartition part : ctx.topology().currentLocalPartitions()) - size += part.publicSize(); + for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) + size += part.publicSize(cacheId); return size; } /** {@inheritDoc} */ - @Override public void incrementPublicSize(GridCacheEntryEx e) { - localPartition(e.key(), AffinityTopologyVersion.NONE, true).incrementPublicSize(e); + @Override public void incrementPublicSize(CacheMapHolder hld, GridCacheEntryEx e) { + localPartition(e.context(), e.key(), AffinityTopologyVersion.NONE, true).incrementPublicSize(hld, e); } /** {@inheritDoc} */ - @Override public void decrementPublicSize(GridCacheEntryEx e) { - localPartition(e.key(), AffinityTopologyVersion.NONE, true).decrementPublicSize(e); + @Override public void decrementPublicSize(CacheMapHolder hld, GridCacheEntryEx e) { + localPartition(e.context(), e.key(), AffinityTopologyVersion.NONE, true).decrementPublicSize(hld, e); } /** {@inheritDoc} */ @Override public boolean removeEntry(GridCacheEntryEx entry) { - GridDhtLocalPartition part = localPartition(entry.key(), AffinityTopologyVersion.NONE, false); + GridDhtLocalPartition part = localPartition(entry.context(), entry.key(), AffinityTopologyVersion.NONE, false); if (part == null) return false; @@ -139,12 +140,12 @@ public GridCachePartitionedConcurrentMap(GridCacheContext ctx) { } /** {@inheritDoc} */ - @Override public Iterable entries(final CacheEntryPredicate... filter) { + @Override public Iterable entries(final int cacheId, final CacheEntryPredicate... filter) { return new Iterable() { @Override public Iterator iterator() { return new PartitionedIterator() { @Override protected Iterator iterator(GridDhtLocalPartition part) { - return part.entries(filter).iterator(); + return part.entries(cacheId, filter).iterator(); } }; } @@ -152,23 +153,10 @@ public GridCachePartitionedConcurrentMap(GridCacheContext ctx) { } /** {@inheritDoc} */ - @Override public Iterable allEntries(final CacheEntryPredicate... filter) { - return new Iterable() { - @Override public Iterator iterator() { - return new PartitionedIterator() { - @Override protected Iterator iterator(GridDhtLocalPartition part) { - return part.allEntries(filter).iterator(); - } - }; - } - }; - } - - /** {@inheritDoc} */ - @Override public Set entrySet(final CacheEntryPredicate... filter) { + @Override public Set entrySet(final int cacheId, final CacheEntryPredicate... filter) { return new PartitionedSet() { @Override protected Set set(GridDhtLocalPartition part) { - return part.entrySet(filter); + return part.entrySet(cacheId, filter); } }; } @@ -178,7 +166,7 @@ public GridCachePartitionedConcurrentMap(GridCacheContext ctx) { */ private abstract class PartitionedIterator implements Iterator { /** Partitions iterator. */ - private Iterator partsIter = ctx.topology().currentLocalPartitions().iterator(); + private Iterator partsIter = grp.topology().currentLocalPartitions().iterator(); /** Current partition iterator. */ private Iterator currIter = partsIter.hasNext() ? iterator(partsIter.next()) : @@ -242,7 +230,7 @@ private abstract class PartitionedSet extends AbstractSet { @Override public int size() { int size = 0; - for (GridDhtLocalPartition part : ctx.topology().currentLocalPartitions()) + for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) size += set(part).size(); return size; @@ -250,7 +238,7 @@ private abstract class PartitionedSet extends AbstractSet { /** {@inheritDoc} */ @Override public boolean contains(Object o) { - for (GridDhtLocalPartition part : ctx.topology().currentLocalPartitions()) { + for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) { if (set(part).contains(o)) return true; } 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 1482137aa36af..cace4e81cec85 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 @@ -73,7 +73,7 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology { private GridCacheSharedContext cctx; /** Cache ID. */ - private int cacheId; + private int grpId; /** Logger. */ private final IgniteLogger log; @@ -113,18 +113,18 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology { /** * @param cctx Context. - * @param cacheId Cache ID. + * @param grpId Group ID. * @param exchFut Exchange ID. * @param similarAffKey Key to find caches with similar affinity. */ public GridClientPartitionTopology( GridCacheSharedContext cctx, - int cacheId, + int grpId, GridDhtPartitionsExchangeFuture exchFut, Object similarAffKey ) { this.cctx = cctx; - this.cacheId = cacheId; + this.grpId = grpId; this.similarAffKey = similarAffKey; topVer = exchFut.topologyVersion(); @@ -168,8 +168,8 @@ private String mapString(GridDhtPartitionMap map) { } /** {@inheritDoc} */ - @Override public int cacheId() { - return cacheId; + @Override public int groupId() { + return grpId; } /** {@inheritDoc} */ @@ -283,7 +283,7 @@ private void beforeExchange0(ClusterNode loc, GridDhtPartitionsExchangeFuture ex long updateSeq = this.updateSeq.incrementAndGet(); // If this is the oldest node. - if (oldest.id().equals(loc.id()) || exchFut.dynamicCacheStarted(cacheId)) { + if (oldest.id().equals(loc.id()) || exchFut.dynamicCacheGroupStarted(grpId)) { if (node2part == null) { node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq); @@ -361,8 +361,8 @@ else if (!node2part.nodeId().equals(loc.id())) { } /** {@inheritDoc} */ - @Override public GridDhtLocalPartition localPartition(Object key, boolean create) { - return localPartition(1, AffinityTopologyVersion.NONE, create); + @Override public GridDhtLocalPartition localPartition(int p) { + return localPartition(p, AffinityTopologyVersion.NONE, false); } /** {@inheritDoc} */ @@ -550,7 +550,10 @@ public long lastUpdateSequence() { lock.readLock().lock(); try { - assert node2part != null && node2part.valid() : "Invalid node2part [node2part: " + node2part + + if (stopping || node2part == null) + return null; + + assert node2part.valid() : "Invalid node2part [node2part: " + node2part + ", locNodeId=" + cctx.localNodeId() + ", igniteInstanceName=" + cctx.igniteInstanceName() + ']'; @@ -1035,7 +1038,7 @@ else if (owners.contains(e.getKey())) /** {@inheritDoc} */ @Override public void printMemoryStats(int threshold) { X.println(">>> Cache partition topology stats [igniteInstanceName=" + cctx.igniteInstanceName() + - ", cacheId=" + cacheId + ']'); + ", grpId=" + grpId + ']'); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentRequest.java index f80adc5890212..d9d642a3b9a94 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentRequest.java @@ -19,7 +19,7 @@ import java.nio.ByteBuffer; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheGroupIdMessage; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.plugin.extensions.communication.MessageReader; import org.apache.ignite.plugin.extensions.communication.MessageWriter; @@ -27,7 +27,7 @@ /** * Affinity assignment request. */ -public class GridDhtAffinityAssignmentRequest extends GridCacheMessage { +public class GridDhtAffinityAssignmentRequest extends GridCacheGroupIdMessage { /** */ private static final long serialVersionUID = 0L; @@ -46,17 +46,17 @@ public GridDhtAffinityAssignmentRequest() { /** * @param futId Future ID. - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param topVer Topology version. */ public GridDhtAffinityAssignmentRequest( long futId, - int cacheId, + int grpId, AffinityTopologyVersion topVer) { assert topVer != null; this.futId = futId; - this.cacheId = cacheId; + this.grpId = grpId; this.topVer = topVer; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentResponse.java index 5d82171cddcd9..4df3fc16898a2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentResponse.java @@ -27,20 +27,18 @@ import org.apache.ignite.internal.GridDirectTransient; import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheGroupIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.plugin.extensions.communication.MessageReader; import org.apache.ignite.plugin.extensions.communication.MessageWriter; -import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode; import org.jetbrains.annotations.NotNull; /** * Affinity assignment response. */ -public class GridDhtAffinityAssignmentResponse extends GridCacheMessage { +public class GridDhtAffinityAssignmentResponse extends GridCacheGroupIdMessage { /** */ private static final long serialVersionUID = 0L; @@ -73,17 +71,17 @@ public GridDhtAffinityAssignmentResponse() { /** * @param futId Future ID. - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param topVer Topology version. * @param affAssignment Affinity assignment. */ public GridDhtAffinityAssignmentResponse( long futId, - int cacheId, + int grpId, @NotNull AffinityTopologyVersion topVer, List> affAssignment) { this.futId = futId; - this.cacheId = cacheId; + this.grpId = grpId; this.topVer = topVer; affAssignmentIds = ids(affAssignment); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java index 20d1722fccc5e..8746320afae14 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java @@ -33,7 +33,7 @@ import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.managers.discovery.DiscoCache; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -74,27 +74,27 @@ public class GridDhtAssignmentFetchFuture extends GridFutureAdapter availableNodes = discoCache.cacheAffinityNodes(cacheDesc.cacheId()); + Collection availableNodes = discoCache.cacheGroupAffinityNodes(grpDesc.groupId()); LinkedList tmp = new LinkedList<>(); @@ -112,10 +112,10 @@ public GridDhtAssignmentFetchFuture( } /** - * @return Cache ID. + * @return Cache group ID. */ - public int cacheId() { - return cacheId; + public int groupId() { + return grpId; } /** @@ -195,7 +195,7 @@ private void requestFromNextNode() { ", node=" + node + ']'); ctx.io().send(node, - new GridDhtAffinityAssignmentRequest(id, cacheId, topVer), + new GridDhtAffinityAssignmentRequest(id, grpId, topVer), AFFINITY_POOL); // Close window for listener notification. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java index 10caf073edfb5..2ac1ba663c2aa 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java @@ -18,7 +18,6 @@ package org.apache.ignite.internal.processors.cache.distributed.dht; import java.io.Externalizable; -import java.util.AbstractSet; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -26,7 +25,6 @@ import java.util.List; import java.util.Map; import java.util.NoSuchElementException; -import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentMap; import javax.cache.Cache; @@ -34,13 +32,15 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.events.DiscoveryEvent; +import org.apache.ignite.events.Event; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.NodeStoppingException; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; +import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.CacheOperationContext; -import org.apache.ignite.internal.processors.cache.CachePeekModes; import org.apache.ignite.internal.processors.cache.EntryGetResult; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheClearAllRunnable; @@ -59,7 +59,9 @@ import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtDetachedCacheEntry; -import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysFuture; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse; import org.apache.ignite.internal.processors.cache.distributed.near.CacheVersionedValue; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest; @@ -70,7 +72,6 @@ import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter; import org.apache.ignite.internal.util.future.GridCompoundFuture; import org.apache.ignite.internal.util.future.GridFutureAdapter; -import org.apache.ignite.internal.util.lang.GridIteratorAdapter; import org.apache.ignite.internal.util.typedef.CI1; import org.apache.ignite.internal.util.typedef.CI2; import org.apache.ignite.internal.util.typedef.CI3; @@ -78,6 +79,7 @@ import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiInClosure; import org.apache.ignite.lang.IgniteBiPredicate; import org.apache.ignite.lang.IgniteBiTuple; import org.apache.ignite.lang.IgniteUuid; @@ -86,8 +88,11 @@ import org.jetbrains.annotations.Nullable; import org.jsr166.ConcurrentHashMap8; +import static org.apache.ignite.events.EventType.EVT_NODE_FAILED; +import static org.apache.ignite.events.EventType.EVT_NODE_LEFT; import static org.apache.ignite.internal.processors.dr.GridDrType.DR_LOAD; import static org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE; +import static org.apache.ignite.internal.util.GridConcurrentFactory.newMap; /** * DHT cache adapter. @@ -96,18 +101,36 @@ public abstract class GridDhtCacheAdapter extends GridDistributedCacheAdap /** */ private static final long serialVersionUID = 0L; - /** Topology. */ - private GridDhtPartitionTopologyImpl top; - - /** Preloader. */ - protected GridCachePreloader preldr; - /** Multi tx future holder. */ private ThreadLocal> multiTxHolder = new ThreadLocal<>(); /** Multi tx futures. */ private ConcurrentMap multiTxFuts = new ConcurrentHashMap8<>(); + /** Force key futures. */ + private final ConcurrentMap> forceKeyFuts = newMap(); + + /** */ + private volatile boolean stopping; + + /** Discovery listener. */ + private final GridLocalEventListener discoLsnr = new GridLocalEventListener() { + @Override public void onEvent(Event evt) { + DiscoveryEvent e = (DiscoveryEvent)evt; + + ClusterNode loc = ctx.localNode(); + + assert e.type() == EVT_NODE_LEFT || e.type() == EVT_NODE_FAILED : e; + + final ClusterNode n = e.eventNode(); + + assert !loc.id().equals(n.id()); + + for (GridDhtForceKeysFuture f : forceKeyFuts.values()) + f.onDiscoveryEvent(e); + } + }; + /** * Empty constructor required for {@link Externalizable}. */ @@ -115,6 +138,176 @@ protected GridDhtCacheAdapter() { // No-op. } + /** + * Adds future to future map. + * + * @param fut Future to add. + * @return {@code False} if node cache is stopping and future was completed with error. + */ + public boolean addFuture(GridDhtForceKeysFuture fut) { + forceKeyFuts.put(fut.futureId(), fut); + + if (stopping) { + fut.onDone(stopError()); + + return false; + } + + return true; + } + + /** + * Removes future from future map. + * + * @param fut Future to remove. + */ + public void removeFuture(GridDhtForceKeysFuture fut) { + forceKeyFuts.remove(fut.futureId(), fut); + } + + /** + * @param node Node. + * @param msg Message. + */ + protected final void processForceKeyResponse(ClusterNode node, GridDhtForceKeysResponse msg) { + GridDhtForceKeysFuture f = forceKeyFuts.get(msg.futureId()); + + if (f != null) + f.onResult(msg); + else if (log.isDebugEnabled()) + log.debug("Receive force key response for unknown future (is it duplicate?) [nodeId=" + node.id() + + ", res=" + msg + ']'); + } + /** + * @param node Node originated request. + * @param msg Force keys message. + */ + protected final void processForceKeysRequest(final ClusterNode node, final GridDhtForceKeysRequest msg) { + IgniteInternalFuture fut = ctx.mvcc().finishKeys(msg.keys(), msg.cacheId(), msg.topologyVersion()); + + if (fut.isDone()) + processForceKeysRequest0(node, msg); + else + fut.listen(new CI1>() { + @Override public void apply(IgniteInternalFuture t) { + processForceKeysRequest0(node, msg); + } + }); + } + + /** + * @param node Node originated request. + * @param msg Force keys message. + */ + private void processForceKeysRequest0(ClusterNode node, GridDhtForceKeysRequest msg) { + try { + ClusterNode loc = ctx.localNode(); + + GridDhtForceKeysResponse res = new GridDhtForceKeysResponse( + ctx.cacheId(), + msg.futureId(), + msg.miniId(), + ctx.deploymentEnabled()); + + GridDhtPartitionTopology top = ctx.topology(); + + for (KeyCacheObject k : msg.keys()) { + int p = ctx.affinity().partition(k); + + GridDhtLocalPartition locPart = top.localPartition(p, AffinityTopologyVersion.NONE, false); + + // If this node is no longer an owner. + if (locPart == null && !top.owners(p).contains(loc)) { + res.addMissed(k); + + continue; + } + + GridCacheEntryEx entry; + + while (true) { + try { + entry = ctx.dht().entryEx(k); + + entry.unswap(); + + GridCacheEntryInfo info = entry.info(); + + if (info == null) { + assert entry.obsolete() : entry; + + continue; + } + + if (!info.isNew()) + res.addInfo(info); + + ctx.evicts().touch(entry, msg.topologyVersion()); + + break; + } + catch (GridCacheEntryRemovedException ignore) { + if (log.isDebugEnabled()) + log.debug("Got removed entry: " + k); + } + catch (GridDhtInvalidPartitionException ignore) { + if (log.isDebugEnabled()) + log.debug("Local node is no longer an owner: " + p); + + res.addMissed(k); + + break; + } + } + } + + if (log.isDebugEnabled()) + log.debug("Sending force key response [node=" + node.id() + ", res=" + res + ']'); + + ctx.io().send(node, res, ctx.ioPolicy()); + } + catch (ClusterTopologyCheckedException ignore) { + if (log.isDebugEnabled()) + log.debug("Received force key request form failed node (will ignore) [nodeId=" + node.id() + + ", req=" + msg + ']'); + } + catch (IgniteCheckedException e) { + U.error(log, "Failed to reply to force key request [nodeId=" + node.id() + ", req=" + msg + ']', e); + } + } + + /** + * + */ + public void dumpDebugInfo() { + if (!forceKeyFuts.isEmpty()) { + U.warn(log, "Pending force key futures [cache=" + ctx.name() + "]:"); + + for (GridDhtForceKeysFuture fut : forceKeyFuts.values()) + U.warn(log, ">>> " + fut); + } + } + + @Override public void onKernalStop() { + super.onKernalStop(); + + stopping = true; + + IgniteCheckedException err = stopError(); + + for (GridDhtForceKeysFuture fut : forceKeyFuts.values()) + fut.onDone(err); + + ctx.gridEvents().removeLocalEventListener(discoLsnr); + } + + /** + * @return Node stop exception. + */ + private IgniteCheckedException stopError() { + return new NodeStoppingException("Operation has been cancelled (cache or node is stopping)."); + } + /** * @param nodeId Sender node ID. * @param res Near get response. @@ -160,7 +353,7 @@ protected void processNearSingleGetResponse(UUID nodeId, GridNearSingleGetRespon * @param ctx Context. */ protected GridDhtCacheAdapter(GridCacheContext ctx) { - this(ctx, new GridCachePartitionedConcurrentMap(ctx)); + this(ctx, new GridCachePartitionedConcurrentMap(ctx.group())); } /** @@ -173,84 +366,22 @@ protected GridDhtCacheAdapter(GridCacheContext ctx, GridCacheConcurrentMap super(ctx, map); } - /** {@inheritDoc} */ - @Override protected void init() { - super.init(); - - top = new GridDhtPartitionTopologyImpl(ctx, entryFactory()); - } - /** {@inheritDoc} */ @Override public void start() throws IgniteCheckedException { - super.start(); - - ctx.io().addHandler(ctx.cacheId(), GridCacheTtlUpdateRequest.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridCacheTtlUpdateRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheTtlUpdateRequest req) { processTtlUpdateRequest(req); } }); - } - - /** {@inheritDoc} */ - @Override public void stop() { - super.stop(); - - if (preldr != null) - preldr.stop(); - - // Clean up to help GC. - preldr = null; - top = null; - } - /** {@inheritDoc} */ - @Override public void onReconnected() { - super.onReconnected(); - - ctx.affinity().onReconnected(); - - top.onReconnected(); - - if (preldr != null) - preldr.onReconnected(); - } - - /** {@inheritDoc} */ - @Override public void onKernalStart() throws IgniteCheckedException { - super.onKernalStart(); - - if (preldr != null) - preldr.onKernalStart(); - } - - /** {@inheritDoc} */ - @Override public void onKernalStop() { - super.onKernalStop(); - - if (preldr != null) - preldr.onKernalStop(); + ctx.gridEvents().addLocalEventListener(discoLsnr, EVT_NODE_LEFT, EVT_NODE_FAILED); } /** {@inheritDoc} */ @Override public void printMemoryStats() { super.printMemoryStats(); - top.printMemoryStats(1024); - } - - /** - * @return Cache map entry factory. - */ - @Override protected GridCacheMapEntryFactory entryFactory() { - return new GridCacheMapEntryFactory() { - @Override public GridCacheMapEntry create( - GridCacheContext ctx, - AffinityTopologyVersion topVer, - KeyCacheObject key - ) { - return new GridDhtCacheEntry(ctx, topVer, key); - } - }; + ctx.group().topology().printMemoryStats(1024); } /** @@ -262,21 +393,12 @@ protected GridDhtCacheAdapter(GridCacheContext ctx, GridCacheConcurrentMap * @return Partition topology. */ public GridDhtPartitionTopology topology() { - return top; + return ctx.group().topology(); } /** {@inheritDoc} */ @Override public GridCachePreloader preloader() { - return preldr; - } - - /** - * @return DHT preloader. - */ - public GridDhtPreloader dhtPreloader() { - assert preldr instanceof GridDhtPreloader; - - return (GridDhtPreloader)preldr; + return ctx.group().preloader(); } /** @@ -300,6 +422,8 @@ public AffinityTopologyVersion beginMultiUpdate() throws IgniteCheckedException if (tup != null) throw new IgniteCheckedException("Nested multi-update locks are not supported"); + GridDhtPartitionTopology top = ctx.group().topology(); + top.readLock(); GridDhtTopologyFuture topFut; @@ -342,7 +466,7 @@ public void endMultiUpdate() throws IgniteCheckedException { if (tup == null) throw new IgniteCheckedException("Multi-update was not started or released twice."); - top.readLock(); + ctx.group().topology().readLock(); try { IgniteUuid lockId = tup.get1(); @@ -355,7 +479,7 @@ public void endMultiUpdate() throws IgniteCheckedException { multiFut.onDone(lockId); } finally { - top.readUnlock(); + ctx.group().topology().readUnlock(); } } @@ -516,7 +640,7 @@ private void loadEntry(KeyCacheObject key, return; try { - GridDhtLocalPartition part = top.localPartition(ctx.affinity().partition(key), + GridDhtLocalPartition part = ctx.group().topology().localPartition(ctx.affinity().partition(key), AffinityTopologyVersion.NONE, true); // Reserve to make sure that partition does not get unloaded. @@ -576,7 +700,7 @@ else if (log.isDebugEnabled()) long sum = 0; for (GridDhtLocalPartition p : topology().currentLocalPartitions()) - sum += p.dataStore().size(); + sum += p.dataStore().cacheSize(ctx.cacheId()); return sum; } @@ -594,7 +718,7 @@ else if (log.isDebugEnabled()) for (GridDhtLocalPartition p : topology().currentLocalPartitions()) { if (p.primary(topVer)) - sum += p.dataStore().size(); + sum += p.dataStore().cacheSize(ctx.cacheId()); } return sum; @@ -809,7 +933,7 @@ else if (req.needVersion()) res = new GridNearSingleGetResponse(ctx.cacheId(), req.futureId(), - req.topologyVersion(), + null, res0, false, req.addDeploymentInfo()); @@ -818,9 +942,9 @@ else if (req.needVersion()) res.setContainsValue(); } else { - AffinityTopologyVersion topVer = ctx.shared().exchange().readyAffinityVersion(); + AffinityTopologyVersion topVer = ctx.shared().exchange().lastTopologyFuture().topologyVersion(); - assert topVer.compareTo(req.topologyVersion()) >= 0 : "Wrong ready topology version for " + + assert topVer.compareTo(req.topologyVersion()) > 0 : "Wrong ready topology version for " + "invalid partitions response [topVer=" + topVer + ", req=" + req + ']'; res = new GridNearSingleGetResponse(ctx.cacheId(), @@ -908,9 +1032,7 @@ protected void processNearGetRequest(final UUID nodeId, final GridNearGetRequest } if (!F.isEmpty(fut.invalidPartitions())) - res.invalidPartitions(fut.invalidPartitions(), ctx.shared().exchange().readyAffinityVersion()); - else - res.invalidPartitions(fut.invalidPartitions(), req.topologyVersion()); + res.invalidPartitions(fut.invalidPartitions(), ctx.shared().exchange().lastTopologyFuture().topologyVersion()); try { ctx.io().send(nodeId, res, ctx.ioPolicy()); @@ -1096,7 +1218,7 @@ private void updateTtl(GridCacheAdapter cache, false); if (part != null) - part.onDeferredDelete(entry.key(), ver); + part.onDeferredDelete(entry.context().cacheId(), entry.key(), ver); } /** @@ -1108,8 +1230,8 @@ protected final boolean needRemap(AffinityTopologyVersion expVer, AffinityTopolo if (expVer.equals(curVer)) return false; - Collection cacheNodes0 = ctx.discovery().cacheAffinityNodes(ctx.cacheId(), expVer); - Collection cacheNodes1 = ctx.discovery().cacheAffinityNodes(ctx.cacheId(), curVer); + Collection cacheNodes0 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), expVer); + Collection cacheNodes1 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), curVer); if (!cacheNodes0.equals(cacheNodes1) || ctx.affinity().affinityTopologyVersion().compareTo(curVer) < 0) return true; @@ -1147,7 +1269,7 @@ public Iterator> localEntriesIterator(final boolean primary, * @param topVer Specified affinity topology version. * @return Local entries iterator. */ - public Iterator> localEntriesIterator(final boolean primary, + private Iterator> localEntriesIterator(final boolean primary, final boolean backup, final boolean keepBinary, final AffinityTopologyVersion topVer) { @@ -1161,7 +1283,7 @@ public Iterator> localEntriesIterator(final boolean primary, * @param topVer Specified affinity topology version. * @return Local entries iterator. */ - public Iterator localEntriesIteratorEx(final boolean primary, + private Iterator localEntriesIteratorEx(final boolean primary, final boolean backup, final AffinityTopologyVersion topVer) { assert primary || backup; @@ -1208,7 +1330,7 @@ private void advance() { GridDhtLocalPartition part = partIt.next(); if (primary == part.primary(topVer)) { - curIt = part.entries().iterator(); + curIt = part.entries(ctx.cacheId()).iterator(); break; } @@ -1253,4 +1375,35 @@ private AffinityTopologyVersion topologyVersion() { return topVer; } } + + /** + * + */ + protected abstract class MessageHandler implements IgniteBiInClosure { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public void apply(UUID nodeId, M msg) { + ClusterNode node = ctx.node(nodeId); + + if (node == null) { + if (log.isDebugEnabled()) + log.debug("Received message from failed node [node=" + nodeId + ", msg=" + msg + ']'); + + return; + } + + if (log.isDebugEnabled()) + log.debug("Received message from node [node=" + nodeId + ", msg=" + msg + ']'); + + onMessage(node, msg); + } + + /** + * @param node Node. + * @param msg Message. + */ + protected abstract void onMessage(ClusterNode node, M msg); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java index 8c0b0c2866c0d..ebb2cfcfd2b92 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java @@ -93,8 +93,10 @@ public GridDhtCacheEntry( } /** {@inheritDoc} */ - @Override protected long nextPartCounter() { - return locPart.nextUpdateCounter(); + @Override protected long nextPartitionCounter(AffinityTopologyVersion topVer, + boolean primary, + @Nullable Long primaryCntr) { + return locPart.nextUpdateCounter(cctx.cacheId(), topVer, primary, primaryCntr); } /** {@inheritDoc} */ @@ -139,7 +141,7 @@ public GridDhtCacheEntry( assert !Thread.holdsLock(this); // Remove this entry from partition mapping. - cctx.dht().topology().onRemoved(this); + cctx.topology().onRemoved(this); } /** @@ -715,8 +717,8 @@ public synchronized void removeMapping(GridCacheVersion ver, ClusterNode mappedN /** * @return Cache name. */ - protected String cacheName() { - return cctx.dht().near().name(); + protected final String cacheName() { + return cctx.name(); } /** {@inheritDoc} */ @@ -726,12 +728,12 @@ protected String cacheName() { /** {@inheritDoc} */ @Override protected void incrementMapPublicSize() { - locPart.incrementPublicSize(this); + locPart.incrementPublicSize(null, this); } /** {@inheritDoc} */ @Override protected void decrementMapPublicSize() { - locPart.decrementPublicSize(this); + locPart.decrementPublicSize(null, this); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java index 458bc4a5d44bf..49922fe542cc1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java @@ -166,7 +166,7 @@ public GridDhtGetFuture( * Initializes future. */ void init() { - GridDhtFuture fut = cctx.dht().dhtPreloader().request(keys.keySet(), topVer); + GridDhtFuture fut = cctx.group().preloader().request(cctx, keys.keySet(), topVer); if (fut != null) { if (!F.isEmpty(fut.invalidPartitions())) { @@ -292,9 +292,11 @@ else if (mappedKeys != null) */ private boolean map(KeyCacheObject key) { try { + int keyPart = cctx.affinity().partition(key); + GridDhtLocalPartition part = topVer.topologyVersion() > 0 ? - cache().topology().localPartition(cctx.affinity().partition(key), topVer, true) : - cache().topology().localPartition(key, false); + cache().topology().localPartition(keyPart, topVer, true) : + cache().topology().localPartition(keyPart); if (part == null) return false; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java index 9a7cfdcb4bb19..1a81f6ea87729 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java @@ -87,8 +87,8 @@ public final class GridDhtGetSingleFuture extends GridFutureAdapter retries; + /** Retry because ownership changed. */ + private Integer retry; /** Subject ID. */ private UUID subjId; @@ -194,17 +194,21 @@ public GridCacheVersion version() { * */ private void map() { - if (cctx.dht().dhtPreloader().needForceKeys()) { - GridDhtFuture fut = cctx.dht().dhtPreloader().request( + if (cctx.group().preloader().needForceKeys()) { + GridDhtFuture fut = cctx.group().preloader().request( + cctx, Collections.singleton(key), topVer); if (fut != null) { if (!F.isEmpty(fut.invalidPartitions())) { - if (retries == null) - retries = new HashSet<>(); + assert fut.invalidPartitions().size() == 1 : fut.invalidPartitions(); - retries.addAll(fut.invalidPartitions()); + retry = F.first(fut.invalidPartitions()); + + onDone((GridCacheEntryInfo)null); + + return; } fut.listen( @@ -239,17 +243,14 @@ private void map() { * */ private void map0() { - // Assign keys to primary nodes. - int part = cctx.affinity().partition(key); + assert retry == null : retry; - if (retries == null || !retries.contains(part)) { - if (!map(key)) { - retries = Collections.singleton(part); + if (!map(key)) { + retry = cctx.affinity().partition(key); - onDone((GridCacheEntryInfo)null); + onDone((GridCacheEntryInfo)null); - return; - } + return; } getAsync(); @@ -257,7 +258,7 @@ private void map0() { /** {@inheritDoc} */ @Override public Collection invalidPartitions() { - return retries == null ? Collections.emptyList() : retries; + return retry == null ? Collections.emptyList() : Collections.singletonList(retry); } /** @@ -266,9 +267,11 @@ private void map0() { */ private boolean map(KeyCacheObject key) { try { + int keyPart = cctx.affinity().partition(key); + GridDhtLocalPartition part = topVer.topologyVersion() > 0 ? - cache().topology().localPartition(cctx.affinity().partition(key), topVer, true) : - cache().topology().localPartition(key, false); + cache().topology().localPartition(keyPart, topVer, true) : + cache().topology().localPartition(keyPart); if (part == null) return false; 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 a35c1683c787f..a53e8642bd1e6 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 @@ -19,7 +19,10 @@ import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -30,31 +33,33 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.NodeStoppingException; import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMapImpl; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.database.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader; import org.apache.ignite.internal.processors.cache.extras.GridCacheObsoleteEntryExtras; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; -import org.apache.ignite.internal.processors.query.QueryUtils; import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.lang.GridIterator; import org.apache.ignite.internal.util.tostring.GridToStringExclude; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jsr166.ConcurrentHashMap8; import org.jsr166.ConcurrentLinkedDeque8; import static org.apache.ignite.IgniteSystemProperties.IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE; @@ -71,6 +76,17 @@ * Key partition. */ public class GridDhtLocalPartition extends GridCacheConcurrentMapImpl implements Comparable, GridReservable { + /** */ + private static final GridCacheMapEntryFactory ENTRY_FACTORY = new GridCacheMapEntryFactory() { + @Override public GridCacheMapEntry create( + GridCacheContext ctx, + AffinityTopologyVersion topVer, + KeyCacheObject key + ) { + return new GridDhtCacheEntry(ctx, topVer, key); + } + }; + /** Maximum size for delete queue. */ public static final int MAX_DELETE_QUEUE_SIZE = Integer.getInteger(IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE, 200_000); @@ -101,29 +117,48 @@ public class GridDhtLocalPartition extends GridCacheConcurrentMapImpl implements @GridToStringExclude private final GridFutureAdapter rent; - /** Context. */ - private final GridCacheContext cctx; + /** */ + @GridToStringExclude + private final GridCacheSharedContext ctx; + + /** */ + @GridToStringExclude + private final CacheGroupContext grp; /** Create time. */ @GridToStringExclude private final long createTime = U.currentTimeMillis(); /** Eviction history. */ + @GridToStringExclude private final Map evictHist = new HashMap<>(); /** Lock. */ + @GridToStringExclude private final ReentrantLock lock = new ReentrantLock(); + /** */ + @GridToStringExclude + private final ConcurrentMap cacheMaps; + + /** */ + @GridToStringExclude + private final CacheMapHolder singleCacheEntryMap; + /** Remove queue. */ + @GridToStringExclude private final ConcurrentLinkedDeque8 rmvQueue = new ConcurrentLinkedDeque8<>(); /** Group reservations. */ + @GridToStringExclude private final CopyOnWriteArrayList reservations = new CopyOnWriteArrayList<>(); /** */ + @GridToStringExclude private final CacheDataStore store; /** Partition updates. */ + @GridToStringExclude private final ConcurrentNavigableMap updates = new ConcurrentSkipListMap<>(); /** Last applied update. */ @@ -137,21 +172,30 @@ public class GridDhtLocalPartition extends GridCacheConcurrentMapImpl implements private boolean reload; /** - * @param cctx Context. + * @param ctx Context. + * @param grp Cache group. * @param id Partition ID. - * @param entryFactory Entry factory. */ - @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor") GridDhtLocalPartition( - GridCacheContext cctx, - int id, - GridCacheMapEntryFactory entryFactory - ) { - super(cctx, entryFactory, Math.max(10, GridCacheAdapter.DFLT_START_CACHE_SIZE / cctx.affinity().partitions())); + @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor") + GridDhtLocalPartition(GridCacheSharedContext ctx, + CacheGroupContext grp, + int id) { + super(ENTRY_FACTORY); this.id = id; - this.cctx = cctx; + this.ctx = ctx; + this.grp = grp; - log = U.logger(cctx.kernalContext(), logRef, this); + log = U.logger(ctx.kernalContext(), logRef, this); + + if (grp.sharedGroup()) { + singleCacheEntryMap = null; + cacheMaps = new ConcurrentHashMap<>(); + } + else { + singleCacheEntryMap = new CacheMapHolder(grp.singleCacheContext(), createEntriesMap()); + cacheMaps = null; + } rent = new GridFutureAdapter() { @Override public String toString() { @@ -159,15 +203,15 @@ public class GridDhtLocalPartition extends GridCacheConcurrentMapImpl implements } }; - int delQueueSize = CU.isSystemCache(cctx.name()) ? 100 : - Math.max(MAX_DELETE_QUEUE_SIZE / cctx.affinity().partitions(), 20); + int delQueueSize = grp.systemCache() ? 100 : + Math.max(MAX_DELETE_QUEUE_SIZE / grp.affinity().partitions(), 20); rmvQueueMaxSize = U.ceilPow2(delQueueSize); rmvdEntryTtl = Long.getLong(IGNITE_CACHE_REMOVED_ENTRIES_TTL, 10_000); try { - store = cctx.offheap().createCacheDataStore(id); + store = grp.offheap().createCacheDataStore(id); } catch (IgniteCheckedException e) { // TODO ignite-db @@ -175,6 +219,62 @@ public class GridDhtLocalPartition extends GridCacheConcurrentMapImpl implements } } + /** + * @return Entries map. + */ + private ConcurrentMap createEntriesMap() { + return new ConcurrentHashMap8<>(Math.max(10, GridCacheAdapter.DFLT_START_CACHE_SIZE / grp.affinity().partitions()), + 0.75f, + Runtime.getRuntime().availableProcessors() * 2); + } + + /** {@inheritDoc} */ + @Override public int internalSize() { + if (grp.sharedGroup()) { + int size = 0; + + for (CacheMapHolder hld : cacheMaps.values()) + size += hld.map.size(); + + return size; + } + + return singleCacheEntryMap.map.size(); + } + + /** {@inheritDoc} */ + @Override protected CacheMapHolder entriesMap(GridCacheContext cctx) { + if (grp.sharedGroup()) + return cacheMapHolder(cctx); + + return singleCacheEntryMap; + } + + /** {@inheritDoc} */ + @Nullable @Override protected CacheMapHolder entriesMapIfExists(Integer cacheId) { + return grp.sharedGroup() ? cacheMaps.get(cacheId) : singleCacheEntryMap; + } + + /** + * @param cctx Cache context. + * @return Map holder. + */ + private CacheMapHolder cacheMapHolder(GridCacheContext cctx) { + assert grp.sharedGroup(); + + CacheMapHolder hld = cacheMaps.get(cctx.cacheIdBoxed()); + + if (hld != null) + return hld; + + CacheMapHolder old = cacheMaps.putIfAbsent(cctx.cacheIdBoxed(), hld = new CacheMapHolder(cctx, createEntriesMap())); + + if (old != null) + hld = old; + + return hld; + } + /** * @return Data store. */ @@ -242,10 +342,10 @@ public int reservations() { * @return {@code True} if partition is empty. */ public boolean isEmpty() { - if (cctx.allowFastEviction()) + if (grp.allowFastEviction()) return internalSize() == 0; - return store.size() == 0 && internalSize() == 0; + return store.fullSize() == 0 && internalSize() == 0; } /** @@ -308,6 +408,20 @@ void onRemoved(GridDhtCacheEntry entry) { tryEvictAsync(false); } + /** + * @param cacheId Cache ID. + * @param key Key. + * @param ver Version. + */ + private void removeVersionedEntry(int cacheId, KeyCacheObject key, GridCacheVersion ver) { + CacheMapHolder hld = grp.sharedGroup() ? cacheMaps.get(cacheId) : singleCacheEntryMap; + + GridCacheMapEntry entry = hld != null ? hld.map.get(key) : null; + + if (entry != null && entry.markObsoleteVersion(ver)) + removeEntry(entry); + } + /** * */ @@ -316,10 +430,10 @@ public void cleanupRemoveQueue() { RemovedEntryHolder item = rmvQueue.pollFirst(); if (item != null) - cctx.dht().removeVersionedEntry(item.key(), item.version()); + removeVersionedEntry(item.cacheId(), item.key(), item.version()); } - if (!cctx.isDrEnabled()) { + if (!grp.isDrEnabled()) { RemovedEntryHolder item = rmvQueue.peekFirst(); while (item != null && item.expireTime() < U.currentTimeMillis()) { @@ -328,7 +442,7 @@ public void cleanupRemoveQueue() { if (item == null) break; - cctx.dht().removeVersionedEntry(item.key(), item.version()); + removeVersionedEntry(item.cacheId(), item.key(), item.version()); item = rmvQueue.peekFirst(); } @@ -336,13 +450,14 @@ public void cleanupRemoveQueue() { } /** + * @param cacheId cacheId Cache ID. * @param key Removed key. * @param ver Removed version. */ - public void onDeferredDelete(KeyCacheObject key, GridCacheVersion ver) { + public void onDeferredDelete(int cacheId, KeyCacheObject key, GridCacheVersion ver) { cleanupRemoveQueue(); - rmvQueue.add(new RemovedEntryHolder(key, ver, rmvdEntryTtl)); + rmvQueue.add(new RemovedEntryHolder(cacheId, key, ver, rmvdEntryTtl)); } /** @@ -434,7 +549,10 @@ public boolean preloadingPermitted(KeyCacheObject key, GridCacheVersion ver) { } /** {@inheritDoc} */ - @Override protected void release(int sizeChange, GridCacheEntryEx e) { + @Override protected void release(int sizeChange, CacheMapHolder hld, GridCacheEntryEx e) { + if (grp.sharedGroup() && sizeChange != 0) + hld.size.addAndGet(sizeChange); + release0(sizeChange); } @@ -482,16 +600,16 @@ public void restoreState(GridDhtPartitionState stateToRestore) { * @return {@code true} if cas succeeds. */ private boolean casState(long state, GridDhtPartitionState toState) { - if (cctx.shared().database().persistenceEnabled()) { + if (ctx.database().persistenceEnabled()) { synchronized (this) { boolean update = this.state.compareAndSet(state, setPartState(state, toState)); if (update) try { - cctx.shared().wal().log(new PartitionMetaStateRecord(cctx.cacheId(), id, toState, updateCounter())); + ctx.wal().log(new PartitionMetaStateRecord(grp.groupId(), id, toState, updateCounter())); } catch (IgniteCheckedException e) { - log.error("Error while writing to log", e); + U.error(log, "Error while writing to log", e); } return update; @@ -624,7 +742,7 @@ void tryEvictAsync(boolean updateSeq) { GridDhtPartitionState partState = getPartState(state); - if (isEmpty() && !QueryUtils.isEnabled(cctx.config()) && getSize(state) == 0 && + if (isEmpty() && !grp.queriesEnabled() && getSize(state) == 0 && partState == RENTING && getReservations(state) == 0 && !groupReserved() && casState(state, EVICTED)) { if (log.isDebugEnabled()) @@ -634,7 +752,7 @@ void tryEvictAsync(boolean updateSeq) { finishDestroy(updateSeq); } else if (partState == RENTING || shouldBeRenting()) - cctx.preloader().evictPartitionAsync(this); + grp.preloader().evictPartitionAsync(this); } /** @@ -710,18 +828,13 @@ private void finishDestroy(boolean updateSeq) { assert state() == EVICTED : this; assert evictGuard.get() == -1; - if (cctx.isDrEnabled()) - cctx.dr().partitionEvicted(id); - - cctx.continuousQueries().onPartitionEvicted(id); - - cctx.dataStructures().onPartitionEvicted(id); + grp.onPartitionEvicted(id); destroyCacheDataStore(); rent.onDone(); - ((GridDhtPreloader)cctx.preloader()).onPartitionEvicted(this, updateSeq); + ((GridDhtPreloader)grp.preloader()).onPartitionEvicted(this, updateSeq); clearDeferredDeletes(); } @@ -759,7 +872,7 @@ public void tryEvict() throws NodeStoppingException { */ private void destroyCacheDataStore() { try { - cctx.offheap().destroyCacheDataStore(dataStore()); + grp.offheap().destroyCacheDataStore(dataStore()); } catch (IgniteCheckedException e) { log.error("Unable to destroy cache data store on partition eviction [id=" + id + "]", e); @@ -778,7 +891,9 @@ void onUnlock() { * @return {@code True} if local node is primary for this partition. */ public boolean primary(AffinityTopologyVersion topVer) { - return cctx.affinity().primaryByPartition(cctx.localNode(), id, topVer); + List nodes = grp.affinity().cachedAffinity(topVer).get(id); + + return !nodes.isEmpty() && ctx.localNode().equals(nodes.get(0)); } /** @@ -786,14 +901,23 @@ public boolean primary(AffinityTopologyVersion topVer) { * @return {@code True} if local node is backup for this partition. */ public boolean backup(AffinityTopologyVersion topVer) { - return cctx.affinity().backupByPartition(cctx.localNode(), id, topVer); + List nodes = grp.affinity().cachedAffinity(topVer).get(id); + + return nodes.indexOf(ctx.localNode()) > 0; } /** + * @param cacheId ID of cache initiated counter update. + * @param topVer Topology version for current operation. * @return Next update index. */ - public long nextUpdateCounter() { - return store.nextUpdateCounter(); + long nextUpdateCounter(int cacheId, AffinityTopologyVersion topVer, boolean primary, @Nullable Long primaryCntr) { + long nextCntr = store.nextUpdateCounter(); + + if (grp.sharedGroup()) + grp.onPartitionCounterUpdate(cacheId, id, primaryCntr != null ? primaryCntr : nextCntr, topVer, primary); + + return nextCntr; } /** @@ -830,40 +954,128 @@ public void initialUpdateCounter(long val) { * @throws NodeStoppingException If node stopping. */ public void clearAll() throws NodeStoppingException { - GridCacheVersion clearVer = cctx.versions().next(); + GridCacheVersion clearVer = ctx.versions().next(); + + GridCacheObsoleteEntryExtras extras = new GridCacheObsoleteEntryExtras(clearVer); + + boolean rec = grp.eventRecordable(EVT_CACHE_REBALANCE_OBJECT_UNLOADED); - boolean rec = cctx.events().isRecordable(EVT_CACHE_REBALANCE_OBJECT_UNLOADED); + if (grp.sharedGroup()) { + for (CacheMapHolder hld : cacheMaps.values()) + clear(hld.map, extras, rec); + } + else + clear(singleCacheEntryMap.map, extras, rec); - Iterator it = allEntries().iterator(); + if (!grp.allowFastEviction()) { + CacheMapHolder hld = grp.sharedGroup() ? null : singleCacheEntryMap; - GridCacheObsoleteEntryExtras extras = new GridCacheObsoleteEntryExtras(clearVer); + try { + GridIterator it0 = grp.offheap().partitionIterator(id); + + while (it0.hasNext()) { + ctx.database().checkpointReadLock(); + + try { + CacheDataRow row = it0.next(); + + if (grp.sharedGroup() && (hld == null || hld.cctx.cacheId() != row.cacheId())) { + hld = cacheMaps.get(row.cacheId()); + + if (hld == null) + continue; + } + + assert hld != null; + + GridCacheMapEntry cached = putEntryIfObsoleteOrAbsent( + hld, + hld.cctx, + grp.affinity().lastVersion(), + row.key(), + true, + false); + + ctx.database().checkpointReadLock(); + + try {if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry)cached).clearInternal(clearVer, extras)) { + if (rec) { + hld.cctx.events().addEvent(cached.partition(), + cached.key(), + ctx.localNodeId(), + (IgniteUuid)null, + null, + EVT_CACHE_REBALANCE_OBJECT_UNLOADED, + null, + false, + cached.rawGet(), + cached.hasValue(), + null, + null, + null, + false);} + } + } + finally { + ctx.database().checkpointReadUnlock(); + } + } + catch (GridDhtInvalidPartitionException e) { + assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']'; + + break; // Partition is already concurrently cleared and evicted. + } + finally { + ctx.database().checkpointReadUnlock(); + } + } + } + catch (NodeStoppingException e) { + if (log.isDebugEnabled()) + log.debug("Failed to get iterator for evicted partition: " + id); + + rent.onDone(e); + + throw e; + } + catch (IgniteCheckedException e) { + U.error(log, "Failed to get iterator for evicted partition: " + id, e); + } + } + } + + /** + * @param map Map to clear. + * @param extras Obsolete extras. + * @param evt Unload event flag. + * @throws NodeStoppingException + */ + private void clear(ConcurrentMap map, + GridCacheObsoleteEntryExtras extras, + boolean evt) throws NodeStoppingException { + Iterator it = map.values().iterator(); while (it.hasNext()) { GridCacheMapEntry cached = null; - cctx.shared().database().checkpointReadLock(); + ctx.database().checkpointReadLock(); try { cached = it.next(); - if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry)cached).clearInternal(clearVer, extras)) { + if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry)cached).clearInternal(extras.obsoleteVersion(), extras)) { removeEntry(cached); if (!cached.isInternal()) { - if (rec) { - cctx.events().addEvent(cached.partition(), + if (evt) { + grp.addCacheEvent(cached.partition(), cached.key(), - cctx.localNodeId(), - (IgniteUuid)null, - null, + ctx.localNodeId(), EVT_CACHE_REBALANCE_OBJECT_UNLOADED, null, false, cached.rawGet(), cached.hasValue(), - null, - null, - null, false); } } @@ -886,66 +1098,7 @@ public void clearAll() throws NodeStoppingException { U.error(log, "Failed to clear cache entry for evicted partition: " + cached, e); } finally { - cctx.shared().database().checkpointReadUnlock(); - } - } - - if (!cctx.allowFastEviction()) { - try { - GridIterator it0 = cctx.offheap().iterator(id); - - while (it0.hasNext()) { - try { - CacheDataRow row = it0.next(); - - GridCacheMapEntry cached = putEntryIfObsoleteOrAbsent(cctx.affinity().affinityTopologyVersion(), - row.key(), - true, - false); - - cctx.shared().database().checkpointReadLock(); - - try { - if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry)cached).clearInternal(clearVer, extras)) { - if (rec) { - cctx.events().addEvent(cached.partition(), - cached.key(), - cctx.localNodeId(), - (IgniteUuid)null, - null, - EVT_CACHE_REBALANCE_OBJECT_UNLOADED, - null, - false, - cached.rawGet(), - cached.hasValue(), - null, - null, - null, - false); - } - } - } - finally { - cctx.shared().database().checkpointReadUnlock(); - } - } - catch (GridDhtInvalidPartitionException e) { - assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']'; - - break; // Partition is already concurrently cleared and evicted. - } - } - } - catch (NodeStoppingException e) { - if (log.isDebugEnabled()) - log.debug("Failed to get iterator for evicted partition: " + id); - - rent.onDone(e); - - throw e; - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to get iterator for evicted partition: " + id, e); + ctx.database().checkpointReadUnlock(); } } } @@ -955,7 +1108,7 @@ public void clearAll() throws NodeStoppingException { */ private void clearDeferredDeletes() { for (RemovedEntryHolder e : rmvQueue) - cctx.dht().removeVersionedEntry(e.key(), e.version()); + removeVersionedEntry(e.cacheId(), e.key(), e.version()); } /** {@inheritDoc} */ @@ -980,6 +1133,7 @@ private void clearDeferredDeletes() { /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDhtLocalPartition.class, this, + "grp", grp.cacheOrGroupName(), "state", state(), "reservations", reservations(), "empty", isEmpty(), @@ -987,12 +1141,25 @@ private void clearDeferredDeletes() { } /** {@inheritDoc} */ - @Override public int publicSize() { + @Override public int publicSize(int cacheId) { + if (grp.sharedGroup()) { + CacheMapHolder hld = cacheMaps.get(cacheId); + + return hld != null ? hld.size.get() : 0; + } + return getSize(state.get()); } /** {@inheritDoc} */ - @Override public void incrementPublicSize(GridCacheEntryEx e) { + @Override public void incrementPublicSize(@Nullable CacheMapHolder hld, GridCacheEntryEx e) { + if (grp.sharedGroup()) { + if (hld == null) + hld = cacheMapHolder(e.context()); + + hld.size.incrementAndGet(); + } + while (true) { long state = this.state.get(); @@ -1002,7 +1169,14 @@ private void clearDeferredDeletes() { } /** {@inheritDoc} */ - @Override public void decrementPublicSize(GridCacheEntryEx e) { + @Override public void decrementPublicSize(@Nullable CacheMapHolder hld, GridCacheEntryEx e) { + if (grp.sharedGroup()) { + if (hld == null) + hld = cacheMapHolder(e.context()); + + hld.size.decrementAndGet(); + } + while (true) { long state = this.state.get(); @@ -1013,6 +1187,22 @@ private void clearDeferredDeletes() { } } + /** + * @param cacheId Cache ID. + */ + void onCacheStopped(int cacheId) { + assert grp.sharedGroup() : grp.cacheOrGroupName(); + + for (Iterator it = rmvQueue.iterator(); it.hasNext();) { + RemovedEntryHolder e = it.next(); + + if (e.cacheId() == cacheId) + it.remove(); + } + + cacheMaps.remove(cacheId); + } + /** * @param state Composite state. * @return Partition state. @@ -1068,6 +1258,9 @@ private static long setSize(long state, int size) { * Removed entry holder. */ private static class RemovedEntryHolder { + /** */ + private final int cacheId; + /** Cache key */ private final KeyCacheObject key; @@ -1078,17 +1271,26 @@ private static class RemovedEntryHolder { private final long expireTime; /** + * @param cacheId Cache ID. * @param key Key. * @param ver Entry version. * @param ttl TTL. */ - private RemovedEntryHolder(KeyCacheObject key, GridCacheVersion ver, long ttl) { + private RemovedEntryHolder(int cacheId, KeyCacheObject key, GridCacheVersion ver, long ttl) { + this.cacheId = cacheId; this.key = key; this.ver = ver; expireTime = U.currentTimeMillis() + ttl; } + /** + * @return Cache ID. + */ + int cacheId() { + return cacheId; + } + /** * @return Key. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java index ea6ca060f50e7..87abd6c2ce994 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java @@ -174,7 +174,7 @@ public Collection preloadEntries() { } if (preloadEntries != null) - marshalInfos(preloadEntries, cctx); + marshalInfos(preloadEntries, cctx.shared(), cctx.cacheObjectContext()); } /** {@inheritDoc} */ 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 c6715e5005414..4e0608dce2683 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 @@ -88,9 +88,9 @@ public void updateTopologyVersion( public boolean stopping(); /** - * @return Cache ID. + * @return Cache group ID. */ - public int cacheId(); + public int groupId(); /** * Pre-initializes this topology. @@ -146,13 +146,12 @@ public void beforeExchange(GridDhtPartitionsExchangeFuture exchFut, boolean affR public void releasePartitions(int... parts); /** - * @param key Cache key. - * @param create If {@code true}, then partition will be created if it's not there. + * @param part Partition number. * @return Local partition. * @throws GridDhtInvalidPartitionException If partition is evicted or absent and * does not belong to this node. */ - @Nullable public GridDhtLocalPartition localPartition(Object key, boolean create) + @Nullable public GridDhtLocalPartition localPartition(int part) throws GridDhtInvalidPartitionException; /** 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 ec9dbbf7cdc33..791bac0ff60a2 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 @@ -40,9 +40,9 @@ import org.apache.ignite.internal.managers.discovery.DiscoCache; import org.apache.ignite.internal.processors.affinity.AffinityAssignment; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.ClusterState; -import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap; @@ -68,7 +68,8 @@ /** * Partition topology. */ -@GridToStringExclude class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology { +@GridToStringExclude +public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology { /** If true, then check consistency. */ private static final boolean CONSISTENCY_CHECK = false; @@ -78,8 +79,11 @@ /** */ private static final Long ZERO = 0L; - /** Context. */ - private final GridCacheContext cctx; + /** */ + private final GridCacheSharedContext ctx; + + /** */ + private final CacheGroupContext grp; /** Logger. */ private final IgniteLogger log; @@ -114,9 +118,6 @@ /** Lock. */ private final StripedCompositeReadWriteLock lock = new StripedCompositeReadWriteLock(16); - /** */ - private final GridCacheMapEntryFactory entryFactory; - /** Partition update counter. */ private Map> cntrMap = new HashMap<>(); @@ -127,25 +128,27 @@ private volatile boolean treatAllPartAsLoc; /** - * @param cctx Context. - * @param entryFactory Entry factory. + * @param ctx Cache shared context. + * @param grp Cache group. */ - GridDhtPartitionTopologyImpl(GridCacheContext cctx, GridCacheMapEntryFactory entryFactory) { - assert cctx != null; + public GridDhtPartitionTopologyImpl(GridCacheSharedContext ctx, + CacheGroupContext grp) { + assert ctx != null; + assert grp != null; - this.cctx = cctx; - this.entryFactory = entryFactory; + this.ctx = ctx; + this.grp = grp; - log = cctx.logger(getClass()); + log = ctx.logger(getClass()); - locParts = new AtomicReferenceArray<>(cctx.config().getAffinity().partitions()); + locParts = new AtomicReferenceArray<>(grp.affinityFunction().partitions()); - part2node = new HashMap<>(cctx.config().getAffinity().partitions(), 1.0f); + part2node = new HashMap<>(grp.affinityFunction().partitions(), 1.0f); } /** {@inheritDoc} */ - @Override public int cacheId() { - return cctx.cacheId(); + @Override public int groupId() { + return grp.groupId(); } /** @@ -169,7 +172,7 @@ public void onReconnected() { topVer = AffinityTopologyVersion.NONE; - discoCache = cctx.discovery().discoCache(); + discoCache = ctx.discovery().discoCache(); } finally { lock.writeLock().unlock(); @@ -240,7 +243,7 @@ private String mapString(GridDhtPartitionMap map) { AffinityTopologyVersion topVer = this.topVer; assert topVer.topologyVersion() > 0 : "Invalid topology version [topVer=" + topVer + - ", cacheName=" + cctx.name() + ']'; + ", group=" + grp.cacheOrGroupName() + ']'; return topVer; } @@ -282,7 +285,7 @@ private String mapString(GridDhtPartitionMap map) { * @param updateSeq Update sequence. */ private void initPartitions0(GridDhtPartitionsExchangeFuture exchFut, long updateSeq) { - ClusterNode loc = cctx.localNode(); + ClusterNode loc = ctx.localNode(); ClusterNode oldest = discoCache.oldestAliveServerNodeWithCache(); @@ -290,23 +293,23 @@ private void initPartitions0(GridDhtPartitionsExchangeFuture exchFut, long updat assert topVer.equals(exchFut.topologyVersion()) : "Invalid topology [topVer=" + topVer + - ", cache=" + cctx.name() + + ", grp=" + grp.cacheOrGroupName() + ", futVer=" + exchFut.topologyVersion() + ", fut=" + exchFut + ']'; - assert cctx.affinity().affinityTopologyVersion().equals(exchFut.topologyVersion()) : - "Invalid affinity [topVer=" + cctx.affinity().affinityTopologyVersion() + - ", cache=" + cctx.name() + + assert grp.affinity().lastVersion().equals(exchFut.topologyVersion()) : + "Invalid affinity [topVer=" + grp.affinity().lastVersion() + + ", grp=" + grp.cacheOrGroupName() + ", futVer=" + exchFut.topologyVersion() + ", fut=" + exchFut + ']'; - List> aff = cctx.affinity().assignments(exchFut.topologyVersion()); + List> aff = grp.affinity().assignments(exchFut.topologyVersion()); - int num = cctx.affinity().partitions(); + int num = grp.affinity().partitions(); - if (cctx.rebalanceEnabled()) { - boolean added = exchFut.cacheAddedOnExchange(cctx.cacheId(), cctx.receivedFrom()); + if (grp.rebalanceEnabled()) { + boolean added = exchFut.cacheGroupAddedOnExchange(grp.groupId(), grp.receivedFrom()); - boolean first = (loc.equals(oldest) && loc.id().equals(exchId.nodeId()) && exchId.isJoined()) || added; + boolean first = added || (loc.equals(oldest) && loc.id().equals(exchId.nodeId()) && exchId.isJoined()); if (first) { assert exchId.isJoined() || added; @@ -317,7 +320,7 @@ private void initPartitions0(GridDhtPartitionsExchangeFuture exchFut, long updat boolean owned = locPart.own(); - assert owned : "Failed to own partition for oldest node [cacheName" + cctx.name() + + assert owned : "Failed to own partition for oldest node [grp=" + grp.cacheOrGroupName() + ", part=" + locPart + ']'; if (log.isDebugEnabled()) @@ -376,7 +379,7 @@ else if (belongs) { * @param updateSeq Update sequence. */ private void createPartitions(List> aff, long updateSeq) { - int num = cctx.affinity().partitions(); + int num = grp.affinity().partitions(); for (int p = 0; p < num; p++) { if (node2part != null && node2part.valid()) { @@ -398,24 +401,23 @@ else if (localNode(p, aff)) /** {@inheritDoc} */ @Override public void beforeExchange(GridDhtPartitionsExchangeFuture exchFut, boolean affReady) throws IgniteCheckedException { - DiscoveryEvent discoEvt = exchFut.discoveryEvent(); ClusterState newState = exchFut.newClusterState(); treatAllPartAsLoc = (newState != null && newState == ClusterState.ACTIVE) - || (cctx.kernalContext().state().active() + || (ctx.kernalContext().state().active() && discoEvt.type() == EventType.EVT_NODE_JOINED && discoEvt.eventNode().isLocal() - && !cctx.kernalContext().clientNode() + && !ctx.kernalContext().clientNode() ); - ClusterNode loc = cctx.localNode(); + ClusterNode loc = ctx.localNode(); - cctx.shared().database().checkpointReadLock(); + ctx.database().checkpointReadLock(); try { - synchronized (cctx.shared().exchange().interruptLock()) { + synchronized (ctx.exchange().interruptLock()) { if (Thread.currentThread().isInterrupted()) throw new IgniteInterruptedCheckedException("Thread is interrupted: " + Thread.currentThread()); @@ -443,7 +445,7 @@ else if (localNode(p, aff)) cntrMap.clear(); // If this is the oldest node. - if (oldest != null && (loc.equals(oldest) || exchFut.cacheAddedOnExchange(cctx.cacheId(), cctx.receivedFrom()))) { + if (oldest != null && (loc.equals(oldest) || exchFut.cacheGroupAddedOnExchange(grp.groupId(), grp.receivedFrom()))) { if (node2part == null) { node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq); @@ -470,7 +472,7 @@ else if (!node2part.nodeId().equals(loc.id())) { if (affReady) initPartitions0(exchFut, updateSeq); else { - List> aff = cctx.affinity().idealAssignment(); + List> aff = grp.affinity().idealAssignment(); createPartitions(aff, updateSeq); } @@ -487,23 +489,32 @@ else if (!node2part.nodeId().equals(loc.id())) { } } finally { - cctx.shared().database().checkpointReadUnlock(); + ctx.database().checkpointReadUnlock(); } } + /** + * @param p Partition number. + * @param topVer Topology version. + * @return {@code True} if given partition belongs to local node. + */ + private boolean partitionLocalNode(int p, AffinityTopologyVersion topVer) { + return grp.affinity().nodes(p, topVer).contains(ctx.localNode()); + } + /** {@inheritDoc} */ @Override public boolean afterExchange(GridDhtPartitionsExchangeFuture exchFut) throws IgniteCheckedException { treatAllPartAsLoc = false; boolean changed = false; - int num = cctx.affinity().partitions(); + int num = grp.affinity().partitions(); AffinityTopologyVersion topVer = exchFut.topologyVersion(); - assert cctx.affinity().affinityTopologyVersion().equals(topVer) : "Affinity is not initialized " + + assert grp.affinity().lastVersion().equals(topVer) : "Affinity is not initialized " + "[topVer=" + topVer + - ", affVer=" + cctx.affinity().affinityTopologyVersion() + + ", affVer=" + grp.affinity().lastVersion() + ", fut=" + exchFut + ']'; lock.writeLock().lock(); @@ -524,7 +535,7 @@ else if (!node2part.nodeId().equals(loc.id())) { for (int p = 0; p < num; p++) { GridDhtLocalPartition locPart = localPartition0(p, topVer, false, false, false); - if (cctx.affinity().partitionLocalNode(p, topVer)) { + if (partitionLocalNode(p, topVer)) { // This partition will be created during next topology event, // which obviously has not happened at this point. if (locPart == null) { @@ -537,26 +548,28 @@ else if (!node2part.nodeId().equals(loc.id())) { GridDhtPartitionState state = locPart.state(); if (state == MOVING) { - if (cctx.rebalanceEnabled()) { + if (grp.rebalanceEnabled()) { Collection owners = owners(p); // If there are no other owners, then become an owner. if (F.isEmpty(owners)) { boolean owned = locPart.own(); - assert owned : "Failed to own partition [cacheName" + cctx.name() + ", locPart=" + + assert owned : "Failed to own partition [grp=" + grp.cacheOrGroupName() + ", locPart=" + locPart + ']'; updateSeq = updateLocal(p, locPart.state(), updateSeq); changed = true; - if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_PART_DATA_LOST)) { + if (grp.eventRecordable(EVT_CACHE_REBALANCE_PART_DATA_LOST)) { DiscoveryEvent discoEvt = exchFut.discoveryEvent(); - cctx.events().addPreloadEvent(p, - EVT_CACHE_REBALANCE_PART_DATA_LOST, discoEvt.eventNode(), - discoEvt.type(), discoEvt.timestamp()); + grp.addRebalanceEvent(p, + EVT_CACHE_REBALANCE_PART_DATA_LOST, + discoEvt.eventNode(), + discoEvt.type(), + discoEvt.timestamp()); } if (log.isDebugEnabled()) @@ -574,7 +587,7 @@ else if (log.isDebugEnabled()) if (locPart != null) { GridDhtPartitionState state = locPart.state(); - if (state == MOVING && cctx.kernalContext().state().active()) { + if (state == MOVING && ctx.kernalContext().state().active()) { locPart.rent(false); updateSeq = updateLocal(p, locPart.state(), updateSeq); @@ -588,7 +601,7 @@ else if (log.isDebugEnabled()) } } - updateRebalanceVersion(cctx.affinity().assignments(topVer)); + updateRebalanceVersion(grp.affinity().assignments(topVer)); consistencyCheck(); } @@ -622,11 +635,11 @@ private GridDhtLocalPartition createPartition(int p) { GridDhtLocalPartition loc = locParts.get(p); if (loc == null || loc.state() == EVICTED) { - locParts.set(p, loc = new GridDhtLocalPartition(cctx, p, entryFactory)); + locParts.set(p, loc = new GridDhtLocalPartition(ctx, grp, p)); - if (cctx.shared().pageStore() != null) { + if (ctx.pageStore() != null) { try { - cctx.shared().pageStore().onPartitionCreated(cctx.cacheId(), p); + ctx.pageStore().onPartitionCreated(grp.groupId(), p); } catch (IgniteCheckedException e) { // TODO ignite-db @@ -672,7 +685,7 @@ private GridDhtLocalPartition localPartition0(int p, state = loc != null ? loc.state() : null; - boolean belongs = cctx.affinity().partitionLocalNode(p, topVer); + boolean belongs = partitionLocalNode(p, topVer); if (loc != null && state == EVICTED) { locParts.set(p, loc = null); @@ -692,7 +705,7 @@ else if (loc != null && state == RENTING && !showRenting) "local node (often may be caused by inconsistent 'key.hashCode()' implementation) " + "[part=" + p + ", topVer=" + topVer + ", this.topVer=" + this.topVer + ']'); - locParts.set(p, loc = new GridDhtLocalPartition(cctx, p, entryFactory)); + locParts.set(p, loc = new GridDhtLocalPartition(ctx, grp, p)); if (updateSeq) this.updateSeq.incrementAndGet(); @@ -707,9 +720,10 @@ else if (loc != null && state == RENTING && !showRenting) lock.writeLock().unlock(); } - if (created && cctx.shared().pageStore() != null) { + if (created && ctx.pageStore() != null) { try { - cctx.shared().pageStore().onPartitionCreated(cctx.cacheId(), p); + // TODO IGNITE-5075. + ctx.pageStore().onPartitionCreated(grp.groupId(), p); } catch (IgniteCheckedException e) { // TODO ignite-db @@ -734,8 +748,8 @@ else if (loc != null && state == RENTING && !showRenting) } /** {@inheritDoc} */ - @Override public GridDhtLocalPartition localPartition(Object key, boolean create) { - return localPartition(cctx.affinity().partition(key), AffinityTopologyVersion.NONE, create); + @Override public GridDhtLocalPartition localPartition(int part) { + return locParts.get(part); } /** {@inheritDoc} */ @@ -791,7 +805,7 @@ else if (loc != null && state == RENTING && !showRenting) map.put(i, part.state()); } - return new GridDhtPartitionMap(cctx.nodeId(), + return new GridDhtPartitionMap(ctx.localNodeId(), updateSeq.get(), topVer, Collections.unmodifiableMap(map), @@ -831,7 +845,7 @@ else if (loc != null && state == RENTING && !showRenting) /** {@inheritDoc} */ @Override public List nodes(int p, AffinityTopologyVersion topVer) { - AffinityAssignment affAssignment = cctx.affinity().assignment(topVer); + AffinityAssignment affAssignment = grp.affinity().cachedAffinity(topVer); List affNodes = affAssignment.get(p); @@ -854,8 +868,8 @@ else if (loc != null && state == RENTING && !showRenting) try { assert node2part != null && node2part.valid() : "Invalid node-to-partitions map [topVer1=" + topVer + ", topVer2=" + this.topVer + - ", node=" + cctx.igniteInstanceName() + - ", cache=" + cctx.name() + + ", node=" + ctx.igniteInstanceName() + + ", grp=" + grp.cacheOrGroupName() + ", node2part=" + node2part + ']'; List nodes = null; @@ -867,7 +881,7 @@ else if (loc != null && state == RENTING && !showRenting) HashSet affIds = affAssignment.getIds(p); if (!affIds.contains(nodeId) && hasState(p, nodeId, OWNING, MOVING)) { - ClusterNode n = cctx.discovery().node(nodeId); + ClusterNode n = ctx.discovery().node(nodeId); if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) { if (nodes == null) { @@ -900,7 +914,9 @@ private List nodes(int p, AffinityTopologyVersion topVer, GridDhtPartitionState state, GridDhtPartitionState... states) { - Collection allIds = topVer.topologyVersion() > 0 ? F.nodeIds(discoCache.cacheAffinityNodes(cctx.cacheId())) : null; + Collection allIds = topVer.topologyVersion() > 0 ? + F.nodeIds(discoCache.cacheGroupAffinityNodes(grp.groupId())) : + null; lock.readLock().lock(); @@ -908,7 +924,7 @@ private List nodes(int p, assert node2part != null && node2part.valid() : "Invalid node-to-partitions map [topVer=" + topVer + ", allIds=" + allIds + ", node2part=" + node2part + - ", cache=" + cctx.name() + ']'; + ", grp=" + grp.cacheOrGroupName() + ']'; Collection nodeIds = part2node.get(p); @@ -925,7 +941,7 @@ private List nodes(int p, continue; if (hasState(p, id, state, states)) { - ClusterNode n = cctx.discovery().node(id); + ClusterNode n = ctx.discovery().node(id); if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) nodes.add(n); @@ -941,7 +957,7 @@ private List nodes(int p, /** {@inheritDoc} */ @Override public List owners(int p, AffinityTopologyVersion topVer) { - if (!cctx.rebalanceEnabled()) + if (!grp.rebalanceEnabled()) return ownersAndMoving(p, topVer); return nodes(p, topVer, OWNING); @@ -954,7 +970,7 @@ private List nodes(int p, /** {@inheritDoc} */ @Override public List moving(int p) { - if (!cctx.rebalanceEnabled()) + if (!grp.rebalanceEnabled()) return ownersAndMoving(p, AffinityTopologyVersion.NONE); return nodes(p, AffinityTopologyVersion.NONE, MOVING); @@ -979,12 +995,14 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) lock.readLock().lock(); try { - assert node2part != null && node2part.valid() : "Invalid node2part [node2part: " + node2part + - ", cache=" + cctx.name() + - ", started=" + cctx.started() + + if (node2part == null || stopping) + return null; + + assert node2part.valid() : "Invalid node2part [node2part=" + node2part + + ", grp=" + grp.cacheOrGroupName() + ", stopping=" + stopping + - ", locNodeId=" + cctx.localNode().id() + - ", locName=" + cctx.igniteInstanceName() + ']'; + ", locNodeId=" + ctx.localNode().id() + + ", locName=" + ctx.igniteInstanceName() + ']'; GridDhtPartitionFullMap m = node2part; @@ -1067,7 +1085,7 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) // then we keep the newer value. if (newPart != null && (newPart.updateSequence() < part.updateSequence() || - (cctx.startTopologyVersion().compareTo(newPart.topologyVersion()) > 0)) + (grp.localStartVersion().compareTo(newPart.topologyVersion()) > 0)) ) { if (log.isDebugEnabled()) log.debug("Overriding partition map in full update map [exchId=" + exchId + ", curPart=" + @@ -1081,7 +1099,7 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) for (Iterator it = partMap.keySet().iterator(); it.hasNext(); ) { UUID nodeId = it.next(); - if (!cctx.discovery().alive(nodeId)) { + if (!ctx.discovery().alive(nodeId)) { if (log.isDebugEnabled()) log.debug("Removing left node from full map update [nodeId=" + nodeId + ", partMap=" + partMap + ']'); @@ -1115,11 +1133,11 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) boolean changed = false; - AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); + AffinityTopologyVersion affVer = grp.affinity().lastVersion(); - GridDhtPartitionMap nodeMap = partMap.get(cctx.localNodeId()); + GridDhtPartitionMap nodeMap = partMap.get(ctx.localNodeId()); - if (nodeMap != null && cctx.shared().database().persistenceEnabled()) { + if (nodeMap != null && ctx.database().persistenceEnabled()) { for (Map.Entry e : nodeMap.entrySet()) { int p = e.getKey(); GridDhtPartitionState state = e.getValue(); @@ -1188,7 +1206,7 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { long updateSeq = this.updateSeq.incrementAndGet(); if (!affVer.equals(AffinityTopologyVersion.NONE) && affVer.compareTo(topVer) >= 0) { - List> aff = cctx.affinity().assignments(topVer); + List> aff = grp.affinity().assignments(topVer); changed |= checkEvictions(updateSeq, aff); @@ -1201,7 +1219,7 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { log.debug("Partition map after full update: " + fullMapString()); if (changed) - cctx.shared().exchange().scheduleResendPartitions(); + ctx.exchange().scheduleResendPartitions(); return changed ? localPartitionMap() : null; } @@ -1254,7 +1272,7 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { if (log.isDebugEnabled()) log.debug("Updating single partition map [exchId=" + exchId + ", parts=" + mapString(parts) + ']'); - if (!cctx.discovery().alive(parts.nodeId())) { + if (!ctx.discovery().alive(parts.nodeId())) { if (log.isDebugEnabled()) log.debug("Received partition update for non-existing node (will ignore) [exchId=" + exchId + ", parts=" + parts + ']'); @@ -1334,10 +1352,10 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { } } - AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); + AffinityTopologyVersion affVer = grp.affinity().lastVersion(); if (!affVer.equals(AffinityTopologyVersion.NONE) && affVer.compareTo(topVer) >= 0) { - List> aff = cctx.affinity().assignments(topVer); + List> aff = grp.affinity().assignments(topVer); changed |= checkEvictions(updateSeq, aff); @@ -1350,7 +1368,7 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { log.debug("Partition map after single update: " + fullMapString()); if (changed) - cctx.shared().exchange().scheduleResendPartitions(); + ctx.exchange().scheduleResendPartitions(); return changed ? localPartitionMap() : null; } @@ -1364,7 +1382,7 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { lock.writeLock().lock(); try { - int parts = cctx.affinity().partitions(); + int parts = grp.affinity().partitions(); Collection lost = null; @@ -1398,7 +1416,7 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { boolean changed = false; if (lost != null) { - PartitionLossPolicy plc = cctx.config().getPartitionLossPolicy(); + PartitionLossPolicy plc = grp.config().getPartitionLossPolicy(); assert plc != null; @@ -1430,13 +1448,17 @@ else if (plc != PartitionLossPolicy.IGNORE) { } } - if (cctx.events().isRecordable(EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST)) - cctx.events().addPreloadEvent(part, EVT_CACHE_REBALANCE_PART_DATA_LOST, - discoEvt.eventNode(), discoEvt.type(), discoEvt.timestamp()); + if (grp.eventRecordable(EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST)) { + grp.addRebalanceEvent(part, + EVT_CACHE_REBALANCE_PART_DATA_LOST, + discoEvt.eventNode(), + discoEvt.type(), + discoEvt.timestamp()); + } } if (plc != PartitionLossPolicy.IGNORE) - cctx.needsRecovery(true); + grp.needsRecovery(true); } return changed; @@ -1451,7 +1473,7 @@ else if (plc != PartitionLossPolicy.IGNORE) { lock.writeLock().lock(); try { - int parts = cctx.affinity().partitions(); + int parts = grp.affinity().partitions(); long updSeq = updateSeq.incrementAndGet(); for (int part = 0; part < parts; part++) { @@ -1490,9 +1512,9 @@ else if (plc != PartitionLossPolicy.IGNORE) { } } - checkEvictions(updSeq, cctx.affinity().assignments(topVer)); + checkEvictions(updSeq, grp.affinity().assignments(topVer)); - cctx.needsRecovery(false); + grp.needsRecovery(false); } finally { lock.writeLock().unlock(); @@ -1506,7 +1528,7 @@ else if (plc != PartitionLossPolicy.IGNORE) { try { Collection res = null; - int parts = cctx.affinity().partitions(); + int parts = grp.affinity().partitions(); for (int part = 0; part < parts; part++) { Set nodeIds = part2node.get(part); @@ -1544,7 +1566,7 @@ else if (plc != PartitionLossPolicy.IGNORE) { GridDhtLocalPartition locPart = locParts.get(p); if (locPart != null) { - if (locPart.state() == OWNING && !owners.contains(cctx.localNodeId())) { + if (locPart.state() == OWNING && !owners.contains(ctx.localNodeId())) { if (haveHistory) locPart.moving(); else { @@ -1552,7 +1574,7 @@ else if (plc != PartitionLossPolicy.IGNORE) { locPart.reload(true); - result.add(cctx.localNodeId()); + result.add(ctx.localNodeId()); } } @@ -1588,12 +1610,12 @@ else if (plc != PartitionLossPolicy.IGNORE) { * @return {@code True} if state changed. */ private boolean checkEvictions(long updateSeq) { - AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion(); + AffinityTopologyVersion affVer = grp.affinity().lastVersion(); boolean changed = false; if (!affVer.equals(AffinityTopologyVersion.NONE) && affVer.compareTo(topVer) >= 0) { - List> aff = cctx.affinity().assignments(topVer); + List> aff = grp.affinity().assignments(topVer); changed = checkEvictions(updateSeq, aff); @@ -1625,12 +1647,12 @@ private boolean checkEvictions(long updateSeq) { * @return Checks if any of the local partitions need to be evicted. */ private boolean checkEvictions(long updateSeq, List> aff) { - if (!cctx.kernalContext().state().active()) + if (!ctx.kernalContext().state().active()) return false; boolean changed = false; - UUID locId = cctx.nodeId(); + UUID locId = ctx.localNodeId(); for (int p = 0; p < locParts.length(); p++) { GridDhtLocalPartition part = locParts.get(p); @@ -1643,7 +1665,7 @@ private boolean checkEvictions(long updateSeq, List> aff) { if (state.active()) { List affNodes = aff.get(p); - if (!affNodes.contains(cctx.localNode())) { + if (!affNodes.contains(ctx.localNode())) { List nodes = nodes(p, topVer, OWNING); Collection nodeIds = F.nodeIds(nodes); @@ -1710,10 +1732,10 @@ private boolean checkEvictions(long updateSeq, List> aff) { private long updateLocal(int p, GridDhtPartitionState state, long updateSeq) { ClusterNode oldest = discoCache.oldestAliveServerNodeWithCache(); - assert oldest != null || cctx.kernalContext().clientNode(); + assert oldest != null || ctx.kernalContext().clientNode(); // If this node became the oldest node. - if (cctx.localNode().equals(oldest)) { + if (ctx.localNode().equals(oldest)) { long seq = node2part.updateSequence(); if (seq != updateSeq) { @@ -1740,7 +1762,7 @@ private long updateLocal(int p, GridDhtPartitionState state, long updateSeq) { } if (node2part != null) { - UUID locNodeId = cctx.localNodeId(); + UUID locNodeId = ctx.localNodeId(); GridDhtPartitionMap map = node2part.get(locNodeId); @@ -1777,9 +1799,9 @@ private void removeNode(UUID nodeId) { ClusterNode oldest = discoCache.oldestAliveServerNode(); - assert oldest != null || cctx.kernalContext().clientNode(); + assert oldest != null || ctx.kernalContext().clientNode(); - ClusterNode loc = cctx.localNode(); + ClusterNode loc = ctx.localNode(); if (node2part != null) { if (loc.equals(oldest) && !node2part.nodeId().equals(loc.id())) { @@ -1927,11 +1949,10 @@ private void removeNode(UUID nodeId) { try { assert node2part != null && node2part.valid() : "Invalid node2part [node2part: " + node2part + - ", cache=" + cctx.name() + - ", started=" + cctx.started() + + ", grp=" + grp.cacheOrGroupName() + ", stopping=" + stopping + - ", locNodeId=" + cctx.localNode().id() + - ", locName=" + cctx.igniteInstanceName() + ']'; + ", locNodeId=" + ctx.localNodeId() + + ", locName=" + ctx.igniteInstanceName() + ']'; for (GridDhtPartitionMap map : node2part.values()) { if (map.hasMovingPartitions()) @@ -1945,10 +1966,25 @@ private void removeNode(UUID nodeId) { } } + /** + * @param cacheId Cache ID. + */ + public void onCacheStopped(int cacheId) { + if (!grp.sharedGroup()) + return; + + for (int i = 0; i < locParts.length(); i++) { + GridDhtLocalPartition part = locParts.get(i); + + if (part != null) + part.onCacheStopped(cacheId); + } + } + /** {@inheritDoc} */ @Override public void printMemoryStats(int threshold) { - X.println(">>> Cache partition topology stats [igniteInstanceName=" + cctx.igniteInstanceName() + - ", cache=" + cctx.name() + ']'); + X.println(">>> Cache partition topology stats [igniteInstanceName=" + ctx.igniteInstanceName() + + ", grp=" + grp.cacheOrGroupName() + ']'); lock.readLock().lock(); @@ -1959,7 +1995,7 @@ private void removeNode(UUID nodeId) { if (part == null) continue; - int size = part.dataStore().size(); + int size = part.dataStore().fullSize(); if (size >= threshold) X.println(">>> Local partition [part=" + part.id() + ", size=" + size + ']'); @@ -1976,7 +2012,7 @@ private void removeNode(UUID nodeId) { * @return {@code True} if given partition belongs to local node. */ private boolean localNode(int part, List> aff) { - return aff.get(part).contains(cctx.localNode()); + return aff.get(part).contains(ctx.localNode()); } /** @@ -1987,7 +2023,7 @@ private void updateRebalanceVersion(List> aff) { if (node2part == null || !node2part.valid()) return; - for (int i = 0; i < cctx.affinity().partitions(); i++) { + for (int i = 0; i < grp.affinity().partitions(); i++) { List affNodes = aff.get(i); // Topology doesn't contain server nodes (just clients). @@ -2003,7 +2039,7 @@ private void updateRebalanceVersion(List> aff) { rebalancedTopVer = topVer; if (log.isDebugEnabled()) - log.debug("Updated rebalanced version [cache=" + cctx.name() + ", ver=" + rebalancedTopVer + ']'); + log.debug("Updated rebalanced version [cache=" + grp.cacheOrGroupName() + ", ver=" + rebalancedTopVer + ']'); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java index c91eb7ae290a0..d607ff113dab2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java @@ -47,7 +47,8 @@ import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedLockCancelledException; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedUnlockRequest; -import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockRequest; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockResponse; @@ -118,51 +119,61 @@ protected GridDhtTransactionalCacheAdapter(GridCacheContext ctx, GridCache @Override public void start() throws IgniteCheckedException { super.start(); - preldr = new GridDhtPreloader(ctx); - - preldr.start(); - - ctx.io().addHandler(ctx.cacheId(), GridNearGetRequest.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridNearGetRequest req) { processNearGetRequest(nodeId, req); } }); - ctx.io().addHandler(ctx.cacheId(), GridNearSingleGetRequest.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridNearSingleGetRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridNearSingleGetRequest req) { processNearSingleGetRequest(nodeId, req); } }); - ctx.io().addHandler(ctx.cacheId(), GridNearLockRequest.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridNearLockRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridNearLockRequest req) { processNearLockRequest(nodeId, req); } }); - ctx.io().addHandler(ctx.cacheId(), GridDhtLockRequest.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridDhtLockRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridDhtLockRequest req) { processDhtLockRequest(nodeId, req); } }); - ctx.io().addHandler(ctx.cacheId(), GridDhtLockResponse.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridDhtLockResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridDhtLockResponse req) { processDhtLockResponse(nodeId, req); } }); - ctx.io().addHandler(ctx.cacheId(), GridNearUnlockRequest.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridNearUnlockRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridNearUnlockRequest req) { processNearUnlockRequest(nodeId, req); } }); - ctx.io().addHandler(ctx.cacheId(), GridDhtUnlockRequest.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridDhtUnlockRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridDhtUnlockRequest req) { processDhtUnlockRequest(nodeId, req); } }); + + ctx.io().addCacheHandler(ctx.cacheId(), GridDhtForceKeysRequest.class, + new MessageHandler() { + @Override public void onMessage(ClusterNode node, GridDhtForceKeysRequest msg) { + processForceKeysRequest(node, msg); + } + }); + + ctx.io().addCacheHandler(ctx.cacheId(), GridDhtForceKeysResponse.class, + new MessageHandler() { + @Override public void onMessage(ClusterNode node, GridDhtForceKeysResponse msg) { + processForceKeyResponse(node, msg); + } + }); } /** {@inheritDoc} */ @@ -382,7 +393,7 @@ private void processDhtLockRequest(final UUID nodeId, final GridDhtLockRequest r } IgniteInternalFuture keyFut = F.isEmpty(req.keys()) ? null : - ctx.dht().dhtPreloader().request(req.keys(), req.topologyVersion()); + ctx.group().preloader().request(ctx, req.keys(), req.topologyVersion()); if (keyFut == null || keyFut.isDone()) { if (keyFut != null) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java index d777a2201a149..6d717ebf904e6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java @@ -173,19 +173,19 @@ public GridCacheReturn returnValue() { } switch (writer.state()) { - case 7: + case 6: if (!writer.writeByteArray("checkCommittedErrBytes", checkCommittedErrBytes)) return false; writer.incrementState(); - case 8: + case 7: if (!writer.writeInt("miniId", miniId)) return false; writer.incrementState(); - case 9: + case 8: if (!writer.writeMessage("retVal", retVal)) return false; @@ -207,7 +207,7 @@ public GridCacheReturn returnValue() { return false; switch (reader.state()) { - case 7: + case 6: checkCommittedErrBytes = reader.readByteArray("checkCommittedErrBytes"); if (!reader.isLastRead()) @@ -215,7 +215,7 @@ public GridCacheReturn returnValue() { reader.incrementState(); - case 8: + case 7: miniId = reader.readInt("miniId"); if (!reader.isLastRead()) @@ -223,7 +223,7 @@ public GridCacheReturn returnValue() { reader.incrementState(); - case 9: + case 8: retVal = reader.readMessage("retVal"); if (!reader.isLastRead()) @@ -243,7 +243,7 @@ public GridCacheReturn returnValue() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 10; + return 9; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxOnePhaseCommitAckRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxOnePhaseCommitAckRequest.java index c48340865683c..67eacd3f8c5f8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxOnePhaseCommitAckRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxOnePhaseCommitAckRequest.java @@ -47,6 +47,16 @@ public GridDhtTxOnePhaseCommitAckRequest() { // No-op. } + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return false; + } + /** * * @param vers Near Tx xid Versions. @@ -87,7 +97,7 @@ public Collection versions() { } switch (writer.state()) { - case 3: + case 2: if (!writer.writeCollection("vers", vers, MessageCollectionItemType.MSG)) return false; @@ -109,7 +119,7 @@ public Collection versions() { return false; switch (reader.state()) { - case 3: + case 2: vers = reader.readCollection("vers", MessageCollectionItemType.MSG); if (!reader.isLastRead()) @@ -129,6 +139,6 @@ public Collection versions() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 4; + return 3; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java index e2b7803cad8ce..bd238d9b0c58c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java @@ -1086,7 +1086,9 @@ private IgniteInternalFuture forceRebalanceKeys(Map keys = entry.getValue(); - lastForceFut = cctx.cacheContext(cacheId).preloader().request(keys, tx.topologyVersion()); + GridCacheContext ctx = cctx.cacheContext(cacheId); + + lastForceFut = ctx.group().preloader().request(ctx, keys, tx.topologyVersion()); if (compFut != null && lastForceFut != null) compFut.add(lastForceFut); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java index 6452abc2b83ad..f29c507ea34ca 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java @@ -458,7 +458,7 @@ private boolean localGet(KeyCacheObject key, int part, Map locVals) { GridCacheVersion ver = null; if (readNoEntry) { - CacheDataRow row = cctx.offheap().read(key); + CacheDataRow row = cctx.offheap().read(cctx, key); if (row != null) { long expireTime = row.expireTime(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java index e5df64e7c8220..9811f8d5acf06 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java @@ -359,7 +359,7 @@ private boolean localGet(AffinityTopologyVersion topVer, int part) { boolean skipEntry = readNoEntry; if (readNoEntry) { - CacheDataRow row = cctx.offheap().read(key); + CacheDataRow row = cctx.offheap().read(cctx, key); if (row != null) { long expireTime = row.expireTime(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicAbstractUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicAbstractUpdateRequest.java index 579796d299ba4..d2dc817a99b10 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicAbstractUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicAbstractUpdateRequest.java @@ -27,7 +27,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; @@ -40,7 +40,7 @@ /** * */ -public abstract class GridDhtAtomicAbstractUpdateRequest extends GridCacheMessage implements GridCacheDeployable { +public abstract class GridDhtAtomicAbstractUpdateRequest extends GridCacheIdMessage implements GridCacheDeployable { /** Skip store flag bit mask. */ private static final int DHT_ATOMIC_SKIP_STORE_FLAG_MASK = 0x01; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index 0dafa2b5f4df1..2f99033807e5c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -70,7 +70,8 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; import org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedGetFuture; import org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture; -import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest; @@ -192,19 +193,6 @@ public GridDhtAtomicCache(GridCacheContext ctx, GridCacheConcurrentMap map return true; } - /** {@inheritDoc} */ - @Override protected GridCacheMapEntryFactory entryFactory() { - return new GridCacheMapEntryFactory() { - @Override public GridCacheMapEntry create( - GridCacheContext ctx, - AffinityTopologyVersion topVer, - KeyCacheObject key - ) { - return new GridDhtAtomicCacheEntry(ctx, topVer, key); - } - }; - } - /** {@inheritDoc} */ @Override protected void init() { super.init(); @@ -239,11 +227,7 @@ else if (res.error() != null) { metrics = m; - preldr = new GridDhtPreloader(ctx); - - preldr.start(); - - ctx.io().addHandler( + ctx.io().addCacheHandler( ctx.cacheId(), GridNearGetRequest.class, new CI2() { @@ -257,7 +241,7 @@ else if (res.error() != null) { } }); - ctx.io().addHandler( + ctx.io().addCacheHandler( ctx.cacheId(), GridNearSingleGetRequest.class, new CI2() { @@ -271,7 +255,7 @@ else if (res.error() != null) { } }); - ctx.io().addHandler( + ctx.io().addCacheHandler( ctx.cacheId(), GridNearAtomicAbstractUpdateRequest.class, new CI2() { @@ -290,7 +274,8 @@ else if (res.error() != null) { } }); - ctx.io().addHandler(ctx.cacheId(), + ctx.io().addCacheHandler( + ctx.cacheId(), GridNearAtomicUpdateResponse.class, new CI2() { @Override public void apply( @@ -308,7 +293,7 @@ else if (res.error() != null) { } }); - ctx.io().addHandler( + ctx.io().addCacheHandler( ctx.cacheId(), GridDhtAtomicAbstractUpdateRequest.class, new CI2() { @@ -327,7 +312,7 @@ else if (res.error() != null) { } }); - ctx.io().addHandler( + ctx.io().addCacheHandler( ctx.cacheId(), GridDhtAtomicUpdateResponse.class, new CI2() { @@ -346,7 +331,8 @@ else if (res.error() != null) { } }); - ctx.io().addHandler(ctx.cacheId(), + ctx.io().addCacheHandler( + ctx.cacheId(), GridDhtAtomicDeferredUpdateResponse.class, new CI2() { @Override public void apply( @@ -364,7 +350,8 @@ else if (res.error() != null) { } }); - ctx.io().addHandler(ctx.cacheId(), + ctx.io().addCacheHandler( + ctx.cacheId(), GridDhtAtomicNearResponse.class, new CI2() { @Override public void apply(UUID uuid, GridDhtAtomicNearResponse msg) { @@ -377,7 +364,8 @@ else if (res.error() != null) { } }); - ctx.io().addHandler(ctx.cacheId(), + ctx.io().addCacheHandler( + ctx.cacheId(), GridNearAtomicCheckUpdateRequest.class, new CI2() { @Override public void apply(UUID uuid, GridNearAtomicCheckUpdateRequest msg) { @@ -390,8 +378,26 @@ else if (res.error() != null) { } }); + ctx.io().addCacheHandler( + ctx.cacheId(), + GridDhtForceKeysRequest.class, + new MessageHandler() { + @Override public void onMessage(ClusterNode node, GridDhtForceKeysRequest msg) { + processForceKeysRequest(node, msg); + } + }); + + ctx.io().addCacheHandler( + ctx.cacheId(), + GridDhtForceKeysResponse.class, + new MessageHandler() { + @Override public void onMessage(ClusterNode node, GridDhtForceKeysResponse msg) { + processForceKeyResponse(node, msg); + } + }); + if (near == null) { - ctx.io().addHandler( + ctx.io().addCacheHandler( ctx.cacheId(), GridNearGetResponse.class, new CI2() { @@ -405,7 +411,7 @@ else if (res.error() != null) { } }); - ctx.io().addHandler( + ctx.io().addCacheHandler( ctx.cacheId(), GridNearSingleGetResponse.class, new CI2() { @@ -1486,7 +1492,7 @@ private IgniteInternalFuture> getAllAsync0(@Nullable Collection forceFut = preldr.request(req, req.topologyVersion()); + IgniteInternalFuture forceFut = ctx.group().preloader().request(ctx, req, req.topologyVersion()); if (forceFut == null || forceFut.isDone()) { try { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCacheEntry.java deleted file mode 100644 index b0c9a6485ff21..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCacheEntry.java +++ /dev/null @@ -1,53 +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.distributed.dht.atomic; - -import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; -import org.apache.ignite.internal.util.typedef.internal.CU; -import org.apache.ignite.internal.util.typedef.internal.S; - -/** - * DHT atomic cache entry. - */ -public class GridDhtAtomicCacheEntry extends GridDhtCacheEntry { - /** - * @param ctx Cache context. - * @param topVer Topology version at the time of creation (if negative, then latest topology is assumed). - * @param key Cache key. - */ - GridDhtAtomicCacheEntry( - GridCacheContext ctx, - AffinityTopologyVersion topVer, - KeyCacheObject key - ) { - super(ctx, topVer, key); - } - - /** {@inheritDoc} */ - @Override protected String cacheName() { - return CU.isNearEnabled(cctx) ? super.cacheName() : cctx.dht().name(); - } - - /** {@inheritDoc} */ - @Override public synchronized String toString() { - return S.toString(GridDhtAtomicCacheEntry.class, this, super.toString()); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java index 92ef1492e5e57..0c069da80082e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java @@ -22,7 +22,7 @@ import org.apache.ignite.IgniteLogger; import org.apache.ignite.internal.GridDirectTransient; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.timeout.GridTimeoutObject; import org.apache.ignite.internal.util.GridLongList; @@ -35,7 +35,7 @@ /** * Deferred dht atomic update response. */ -public class GridDhtAtomicDeferredUpdateResponse extends GridCacheMessage implements GridCacheDeployable { +public class GridDhtAtomicDeferredUpdateResponse extends GridCacheIdMessage implements GridCacheDeployable { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java index d6e2db052bb06..71d23216f0e2b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java @@ -20,7 +20,7 @@ import java.nio.ByteBuffer; import java.util.UUID; import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheReturn; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; @@ -36,7 +36,7 @@ /** * Message sent from DHT nodes to near node in FULL_SYNC mode. */ -public class GridDhtAtomicNearResponse extends GridCacheMessage { +public class GridDhtAtomicNearResponse extends GridCacheIdMessage { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java index 693d658823967..7b2547af56a80 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java @@ -19,7 +19,6 @@ import java.io.Externalizable; import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.apache.ignite.IgniteCheckedException; @@ -27,7 +26,7 @@ import org.apache.ignite.internal.GridDirectCollection; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -39,7 +38,7 @@ /** * DHT atomic cache backup update response. */ -public class GridDhtAtomicUpdateResponse extends GridCacheMessage implements GridCacheDeployable { +public class GridDhtAtomicUpdateResponse extends GridCacheIdMessage implements GridCacheDeployable { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateRequest.java index 4b3ea5bc896d3..bb47af46754c4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateRequest.java @@ -29,7 +29,7 @@ import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheOperation; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; @@ -44,7 +44,7 @@ /** * */ -public abstract class GridNearAtomicAbstractUpdateRequest extends GridCacheMessage implements GridCacheDeployable { +public abstract class GridNearAtomicAbstractUpdateRequest extends GridCacheIdMessage implements GridCacheDeployable { /** Message index. */ public static final int CACHE_MSG_IDX = nextIndexId(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicCheckUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicCheckUpdateRequest.java index 4b9109efa096d..96be0233c308a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicCheckUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicCheckUpdateRequest.java @@ -19,7 +19,7 @@ import java.nio.ByteBuffer; import org.apache.ignite.internal.GridDirectTransient; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.plugin.extensions.communication.MessageReader; import org.apache.ignite.plugin.extensions.communication.MessageWriter; @@ -27,7 +27,7 @@ /** * */ -public class GridNearAtomicCheckUpdateRequest extends GridCacheMessage { +public class GridNearAtomicCheckUpdateRequest extends GridCacheIdMessage { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java index 55953ea1344b1..5ba024f19994d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java @@ -30,7 +30,7 @@ import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheReturn; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; @@ -45,7 +45,7 @@ /** * DHT atomic cache near update response. */ -public class GridNearAtomicUpdateResponse extends GridCacheMessage implements GridCacheDeployable { +public class GridNearAtomicUpdateResponse extends GridCacheIdMessage implements GridCacheDeployable { /** */ private static final long serialVersionUID = 0L; 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 12a3912f84fb1..708df49dc9a2b 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 @@ -38,7 +38,6 @@ import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException; import org.apache.ignite.internal.processors.cache.GridCacheLockTimeoutException; -import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory; import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate; import org.apache.ignite.internal.processors.cache.GridCacheReturn; @@ -115,36 +114,23 @@ public GridDhtColocatedCache(GridCacheContext ctx, GridCacheConcurrentMap return true; } - /** {@inheritDoc} */ - @Override protected GridCacheMapEntryFactory entryFactory() { - return new GridCacheMapEntryFactory() { - @Override public GridCacheMapEntry create( - GridCacheContext ctx, - AffinityTopologyVersion topVer, - KeyCacheObject key - ) { - return new GridDhtColocatedCacheEntry(ctx, topVer, key); - } - }; - } - /** {@inheritDoc} */ @Override public void start() throws IgniteCheckedException { super.start(); - ctx.io().addHandler(ctx.cacheId(), GridNearGetResponse.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridNearGetResponse res) { processNearGetResponse(nodeId, res); } }); - ctx.io().addHandler(ctx.cacheId(), GridNearSingleGetResponse.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridNearSingleGetResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridNearSingleGetResponse res) { processNearSingleGetResponse(nodeId, res); } }); - ctx.io().addHandler(ctx.cacheId(), GridNearLockResponse.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridNearLockResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridNearLockResponse res) { processLockResponse(nodeId, res); } @@ -467,7 +453,7 @@ public final IgniteInternalFuture> loadAsync( for (KeyCacheObject key : keys) { if (readNoEntry) { - CacheDataRow row = ctx.offheap().read(key); + CacheDataRow row = ctx.offheap().read(ctx, key); if (row != null) { long expireTime = row.expireTime(); @@ -941,7 +927,7 @@ IgniteInternalFuture lockAllAsync( ) { assert keys != null; - IgniteInternalFuture keyFut = ctx.dht().dhtPreloader().request(keys, topVer); + IgniteInternalFuture keyFut = ctx.group().preloader().request(cacheCtx, keys, topVer); // Prevent embedded future creation if possible. if (keyFut == null || keyFut.isDone()) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCacheEntry.java deleted file mode 100644 index f7cc5a7e5e7dc..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCacheEntry.java +++ /dev/null @@ -1,52 +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.distributed.dht.colocated; - -import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; -import org.apache.ignite.internal.util.typedef.internal.S; - -/** - * Cache entry for colocated cache. - */ -public class GridDhtColocatedCacheEntry extends GridDhtCacheEntry { - /** - * @param ctx Cache context. - * @param topVer Topology version at the time of creation (if negative, then latest topology is assumed). - * @param key Cache key. - */ - GridDhtColocatedCacheEntry( - GridCacheContext ctx, - AffinityTopologyVersion topVer, - KeyCacheObject key - ) { - super(ctx, topVer, key); - } - - /** {@inheritDoc} */ - @Override protected String cacheName() { - return cctx.colocated().name(); - } - - /** {@inheritDoc} */ - @Override public synchronized String toString() { - return S.toString(GridDhtColocatedCacheEntry.class, this, super.toString()); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java index d72d8db51421a..763b43b6ab7f6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java @@ -102,9 +102,6 @@ public final class GridDhtForceKeysFuture extends GridCompoundFuture extends GridCompoundFuture cctx, AffinityTopologyVersion topVer, - Collection keys, - GridDhtPreloader preloader + Collection keys ) { assert topVer.topologyVersion() != 0 : topVer; assert !F.isEmpty(keys) : keys; + assert !cctx.isNear(); this.cctx = cctx; this.keys = keys; this.topVer = topVer; - this.preloader = preloader; top = cctx.dht().topology(); @@ -158,7 +153,7 @@ private boolean isMini(IgniteInternalFuture f) { @Override public boolean onDone(@Nullable Collection res, @Nullable Throwable err) { if (super.onDone(res, err)) { if (trackable) - preloader.remoteFuture(this); + cctx.dht().removeFuture(this); return true; } @@ -170,7 +165,7 @@ private boolean isMini(IgniteInternalFuture f) { * @param evt Discovery event. */ @SuppressWarnings( {"unchecked"}) - void onDiscoveryEvent(DiscoveryEvent evt) { + public void onDiscoveryEvent(DiscoveryEvent evt) { topCntr.incrementAndGet(); int type = evt.type(); @@ -244,7 +239,7 @@ private boolean map(Iterable keys, Collection exc) int curTopVer = topCntr.get(); - if (!preloader.addFuture(this)) { + if (!cctx.dht().addFuture(this)) { assert isDone() : this; return false; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java index d129ae87d35c5..124ae44ca5b30 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java @@ -25,7 +25,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -40,7 +40,7 @@ * Force keys request. This message is sent by node while preloading to force * another node to put given keys into the next batch of transmitting entries. */ -public class GridDhtForceKeysRequest extends GridCacheMessage implements GridCacheDeployable { +public class GridDhtForceKeysRequest extends GridCacheIdMessage implements GridCacheDeployable { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java index c4c57a78a79c3..977e9ba41eef2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java @@ -29,7 +29,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -43,7 +43,7 @@ /** * Force keys response. Contains absent keys. */ -public class GridDhtForceKeysResponse extends GridCacheMessage implements GridCacheDeployable { +public class GridDhtForceKeysResponse extends GridCacheIdMessage implements GridCacheDeployable { /** */ private static final long serialVersionUID = 0L; @@ -168,7 +168,7 @@ public void addInfo(GridCacheEntryInfo info) { if (infos != null) { for (GridCacheEntryInfo info : infos) - info.marshal(cctx); + info.marshal(cctx.cacheObjectContext()); } if (err != null && errBytes == null) @@ -186,7 +186,7 @@ public void addInfo(GridCacheEntryInfo info) { if (infos != null) { for (GridCacheEntryInfo info : infos) - info.unmarshal(cctx, ldr); + info.unmarshal(cctx.cacheObjectContext(), ldr); } if (errBytes != null && err == null) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java index ef6a3b9b3cd25..4a693bf8aca38 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java @@ -27,7 +27,7 @@ import org.apache.ignite.internal.GridDirectMap; import org.apache.ignite.internal.GridDirectTransient; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheGroupIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; @@ -39,7 +39,7 @@ /** * Partition demand request. */ -public class GridDhtPartitionDemandMessage extends GridCacheMessage { +public class GridDhtPartitionDemandMessage extends GridCacheGroupIdMessage { /** */ private static final long serialVersionUID = 0L; @@ -77,10 +77,10 @@ public class GridDhtPartitionDemandMessage extends GridCacheMessage { /** * @param updateSeq Update sequence for this node. * @param topVer Topology version. - * @param cacheId Cache ID. + * @param grpId Cache group ID. */ - GridDhtPartitionDemandMessage(long updateSeq, @NotNull AffinityTopologyVersion topVer, int cacheId) { - this.cacheId = cacheId; + GridDhtPartitionDemandMessage(long updateSeq, @NotNull AffinityTopologyVersion topVer, int grpId) { + this.grpId = grpId; this.updateSeq = updateSeq; this.topVer = topVer; } @@ -91,7 +91,7 @@ public class GridDhtPartitionDemandMessage extends GridCacheMessage { */ GridDhtPartitionDemandMessage(GridDhtPartitionDemandMessage cp, Collection parts, Map partsCntrs) { - cacheId = cp.cacheId; + grpId = cp.grpId; updateSeq = cp.updateSeq; topic = cp.topic; timeout = cp.timeout; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java index 3c04617ea4b98..cda24e5c5108f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java @@ -27,7 +27,6 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; @@ -38,13 +37,17 @@ import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; +import org.apache.ignite.internal.processors.affinity.AffinityAssignment; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; +import org.apache.ignite.internal.processors.cache.CacheMetricsImpl; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException; import org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; @@ -78,7 +81,10 @@ @SuppressWarnings("NonConstantFieldWithUpperCaseName") public class GridDhtPartitionDemander { /** */ - private final GridCacheContext cctx; + private final GridCacheSharedContext ctx; + + /** */ + private final CacheGroupContext grp; /** */ private final IgniteLogger log; @@ -104,30 +110,20 @@ public class GridDhtPartitionDemander { private final Map rebalanceTopics; /** - * Started event sent. - * Make sense for replicated cache only. + * @param grp Ccahe group. */ - private final AtomicBoolean startedEvtSent = new AtomicBoolean(); + public GridDhtPartitionDemander(CacheGroupContext grp) { + assert grp != null; - /** - * Stopped event sent. - * Make sense for replicated cache only. - */ - private final AtomicBoolean stoppedEvtSent = new AtomicBoolean(); + this.grp = grp; - /** - * @param cctx Cctx. - */ - public GridDhtPartitionDemander(GridCacheContext cctx) { - assert cctx != null; - - this.cctx = cctx; + ctx = grp.shared(); - log = cctx.logger(getClass()); + log = ctx.logger(getClass()); - boolean enabled = cctx.rebalanceEnabled() && !cctx.kernalContext().clientNode(); + boolean enabled = grp.rebalanceEnabled() && !ctx.kernalContext().clientNode(); - rebalanceFut = new RebalanceFuture();//Dummy. + rebalanceFut = new RebalanceFuture(); //Dummy. if (!enabled) { // Calling onDone() immediately since preloading is disabled. @@ -137,7 +133,7 @@ public GridDhtPartitionDemander(GridCacheContext cctx) { Map tops = new HashMap<>(); - for (int idx = 0; idx < cctx.gridConfig().getRebalanceThreadPoolSize(); idx++) + for (int idx = 0; idx < grp.shared().kernalContext().config().getRebalanceThreadPoolSize(); idx++) tops.put(idx, GridCachePartitionExchangeManager.rebalanceTopic(idx)); rebalanceTopics = tops; @@ -196,7 +192,7 @@ IgniteInternalFuture forceRebalance() { GridTimeoutObject obj = lastTimeoutObj.getAndSet(null); if (obj != null) - cctx.time().removeTimeoutObject(obj); + ctx.time().removeTimeoutObject(obj); final GridDhtPartitionsExchangeFuture exchFut = lastExchangeFut; @@ -208,7 +204,7 @@ IgniteInternalFuture forceRebalance() { exchFut.listen(new CI1>() { @Override public void apply(IgniteInternalFuture t) { - IgniteInternalFuture fut0 = cctx.shared().exchange().forceRebalance(exchFut); + IgniteInternalFuture fut0 = ctx.exchange().forceRebalance(exchFut); fut0.listen(new IgniteInClosure>() { @Override public void apply(IgniteInternalFuture future) { @@ -237,7 +233,7 @@ else if (log.isDebugEnabled()) */ private boolean topologyChanged(RebalanceFuture fut) { return - !cctx.affinity().affinityTopologyVersion().equals(fut.topologyVersion()) || // Topology already changed. + !grp.affinity().lastVersion().equals(fut.topologyVersion()) || // Topology already changed. fut != rebalanceFut; // Same topology, but dummy exchange forced because of missing partitions. } @@ -268,12 +264,12 @@ Runnable addAssignments(final GridDhtPreloaderAssignments assigns, assert force == (forcedRebFut != null); - long delay = cctx.config().getRebalanceDelay(); + long delay = grp.config().getRebalanceDelay(); if (delay == 0 || force) { final RebalanceFuture oldFut = rebalanceFut; - final RebalanceFuture fut = new RebalanceFuture(assigns, cctx, log, startedEvtSent, stoppedEvtSent, cnt); + final RebalanceFuture fut = new RebalanceFuture(grp, assigns, log, cnt); if (!oldFut.isInitial()) oldFut.cancel(); @@ -302,16 +298,18 @@ Runnable addAssignments(final GridDhtPreloaderAssignments assigns, fut.sendRebalanceStartedEvent(); - final boolean statsEnabled = cctx.config().isStatisticsEnabled(); + for (GridCacheContext cctx : grp.caches()) { + if (cctx.config().isStatisticsEnabled()) { + final CacheMetricsImpl metrics = cctx.cache().metrics0(); - if (statsEnabled) { - cctx.cache().metrics0().clearRebalanceCounters(); + metrics.clearRebalanceCounters(); - rebalanceFut.listen(new IgniteInClosure>() { - @Override public void apply(IgniteInternalFuture fut) { - cctx.cache().metrics0().clearRebalanceCounters(); - } - }); + rebalanceFut.listen(new IgniteInClosure>() { + @Override public void apply(IgniteInternalFuture fut) { + metrics.clearRebalanceCounters(); + } + }); + } } if (assigns.cancelled()) { // Pending exchange. @@ -331,7 +329,7 @@ Runnable addAssignments(final GridDhtPreloaderAssignments assigns, fut.onDone(true); - ((GridFutureAdapter)cctx.preloader().syncFuture()).onDone(); + ((GridFutureAdapter)grp.preloader().syncFuture()).onDone(); fut.sendRebalanceFinishedEvent(); @@ -362,7 +360,7 @@ else if (delay > 0) { GridTimeoutObject obj = lastTimeoutObj.get(); if (obj != null) - cctx.time().removeTimeoutObject(obj); + ctx.time().removeTimeoutObject(obj); final GridDhtPartitionsExchangeFuture exchFut = lastExchangeFut; @@ -372,7 +370,7 @@ else if (delay > 0) { @Override public void onTimeout() { exchFut.listen(new CI1>() { @Override public void apply(IgniteInternalFuture f) { - cctx.shared().exchange().forceRebalance(exchFut); + ctx.exchange().forceRebalance(exchFut); } }); } @@ -380,7 +378,7 @@ else if (delay > 0) { lastTimeoutObj.set(obj); - cctx.time().addTimeoutObject(obj); + ctx.time().addTimeoutObject(obj); } return null; @@ -389,7 +387,6 @@ else if (delay > 0) { /** * @param fut Rebalance future. * @param assigns Assignments. - * @throws IgniteCheckedException If failed. */ private void requestPartitions(final RebalanceFuture fut, GridDhtPreloaderAssignments assigns) { assert fut != null; @@ -411,17 +408,19 @@ private void requestPartitions(final RebalanceFuture fut, GridDhtPreloaderAssign Collection parts= e.getValue().partitions(); - assert parts != null : "Partitions are null [cache=" + cctx.name() + ", fromNode=" + nodeId + "]"; + assert parts != null : "Partitions are null [grp=" + grp.cacheOrGroupName() + ", fromNode=" + nodeId + "]"; fut.remaining.put(nodeId, new T2<>(U.currentTimeMillis(), parts)); } } + final CacheConfiguration cfg = grp.config(); + + int lsnrCnt = ctx.gridConfig().getRebalanceThreadPoolSize(); + for (Map.Entry e : assigns.entrySet()) { final ClusterNode node = e.getKey(); - final CacheConfiguration cfg = cctx.config(); - final Collection parts = fut.remaining.get(node.id()).get2(); GridDhtPartitionDemandMessage d = e.getValue(); @@ -430,8 +429,6 @@ private void requestPartitions(final RebalanceFuture fut, GridDhtPreloaderAssign ", fromNode=" + node.id() + ", partitionsCount=" + parts.size() + ", topology=" + fut.topologyVersion() + ", updateSeq=" + fut.updateSeq + "]"); - int lsnrCnt = cctx.gridConfig().getRebalanceThreadPoolSize(); - final List> sParts = new ArrayList<>(lsnrCnt); for (int cnt = 0; cnt < lsnrCnt; cnt++) @@ -451,16 +448,15 @@ private void requestPartitions(final RebalanceFuture fut, GridDhtPreloaderAssign initD.topic(rebalanceTopics.get(cnt)); initD.updateSequence(fut.updateSeq); - initD.timeout(cctx.config().getRebalanceTimeout()); + initD.timeout(cfg.getRebalanceTimeout()); final int finalCnt = cnt; - cctx.kernalContext().closure().runLocalSafe(new Runnable() { + ctx.kernalContext().closure().runLocalSafe(new Runnable() { @Override public void run() { try { if (!fut.isDone()) { - cctx.io().sendOrderedMessage(node, - rebalanceTopics.get(finalCnt), initD, cctx.ioPolicy(), initD.timeout()); + ctx.io().sendOrderedMessage(node, rebalanceTopics.get(finalCnt), initD, grp.ioPolicy(), initD.timeout()); // Cleanup required in case partitions demanded in parallel with cancellation. synchronized (fut) { @@ -507,11 +503,11 @@ private GridDhtPartitionDemandMessage createDemandMessage(GridDhtPartitionDemand for (Integer part : parts) { try { - if (cctx.shared().database().persistenceEnabled()) { + if (ctx.database().persistenceEnabled()) { if (partCntrs == null) partCntrs = new HashMap<>(parts.size(), 1.0f); - GridDhtLocalPartition p = cctx.topology().localPartition(part, old.topologyVersion(), false); + GridDhtLocalPartition p = grp.topology().localPartition(part, old.topologyVersion(), false); partCntrs.put(part, p.initialUpdateCounter()); } @@ -587,7 +583,7 @@ public void handleSupplyMessage( final RebalanceFuture fut = rebalanceFut; - ClusterNode node = cctx.node(id); + ClusterNode node = ctx.node(id); if (node == null) return; @@ -611,23 +607,42 @@ public void handleSupplyMessage( return; } - final GridDhtPartitionTopology top = cctx.dht().topology(); + final GridDhtPartitionTopology top = grp.topology(); + + if (grp.sharedGroup()) { + for (GridCacheContext cctx : grp.caches()) { + if (cctx.config().isStatisticsEnabled()) { + long keysCnt = supply.keysForCache(cctx.cacheId()); - final boolean statsEnabled = cctx.config().isStatisticsEnabled(); + if (keysCnt != -1) + cctx.cache().metrics0().onRebalancingKeysCountEstimateReceived(keysCnt); - if (statsEnabled) { - if (supply.estimatedKeysCount() != -1) - cctx.cache().metrics0().onRebalancingKeysCountEstimateReceived(supply.estimatedKeysCount()); + // Can not be calculated per cache. + cctx.cache().metrics0().onRebalanceBatchReceived(supply.messageSize()); + } + } + } + else { + GridCacheContext cctx = grp.singleCacheContext(); - cctx.cache().metrics0().onRebalanceBatchReceived(supply.messageSize()); + if (cctx.config().isStatisticsEnabled()) { + if (supply.estimatedKeysCount() != -1) + cctx.cache().metrics0().onRebalancingKeysCountEstimateReceived(supply.estimatedKeysCount()); + + cctx.cache().metrics0().onRebalanceBatchReceived(supply.messageSize()); + } } try { + AffinityAssignment aff = grp.affinity().cachedAffinity(topVer); + + GridCacheContext cctx = grp.sharedGroup() ? null : grp.singleCacheContext(); + // Preload. for (Map.Entry e : supply.infos().entrySet()) { int p = e.getKey(); - if (cctx.affinity().partitionLocalNode(p, topVer)) { + if (aff.get(p).contains(ctx.localNode())) { GridDhtLocalPartition part = top.localPartition(p, topVer, true); assert part != null; @@ -638,7 +653,7 @@ public void handleSupplyMessage( boolean reserved = part.reserve(); assert reserved : "Failed to reserve partition [igniteInstanceName=" + - cctx.igniteInstanceName() + ", cacheName=" + cctx.name() + ", part=" + part + ']'; + ctx.igniteInstanceName() + ", grp=" + grp.cacheOrGroupName() + ", part=" + part + ']'; part.lock(); @@ -662,7 +677,10 @@ public void handleSupplyMessage( break; } - if (statsEnabled) + if (grp.sharedGroup() && (cctx == null || cctx.cacheId() != entry.cacheId())) + cctx = ctx.cacheContext(entry.cacheId()); + + if(cctx != null && cctx.config().isStatisticsEnabled()) cctx.cache().metrics0().onRebalanceKeyReceived(); } @@ -700,7 +718,7 @@ public void handleSupplyMessage( // Only request partitions based on latest topology version. for (Integer miss : supply.missed()) { - if (cctx.affinity().partitionLocalNode(miss, topVer)) + if (aff.get(miss).contains(ctx.localNode())) fut.partitionMissed(id, miss); } @@ -708,16 +726,18 @@ public void handleSupplyMessage( fut.partitionDone(id, miss); GridDhtPartitionDemandMessage d = new GridDhtPartitionDemandMessage( - supply.updateSequence(), supply.topologyVersion(), cctx.cacheId()); + supply.updateSequence(), + supply.topologyVersion(), + grp.groupId()); - d.timeout(cctx.config().getRebalanceTimeout()); + d.timeout(grp.config().getRebalanceTimeout()); d.topic(rebalanceTopics.get(idx)); if (!topologyChanged(fut) && !fut.isDone()) { // Send demand message. - cctx.io().sendOrderedMessage(node, rebalanceTopics.get(idx), - d, cctx.ioPolicy(), cctx.config().getRebalanceTimeout()); + ctx.io().sendOrderedMessage(node, rebalanceTopics.get(idx), + d, grp.ioPolicy(), grp.config().getRebalanceTimeout()); } } catch (IgniteCheckedException e) { @@ -746,11 +766,15 @@ private boolean preloadEntry( GridCacheEntryInfo entry, AffinityTopologyVersion topVer ) throws IgniteCheckedException { + ctx.database().checkpointReadLock(); + try { GridCacheEntryEx cached = null; try { - cached = cctx.dht().entryEx(entry.key()); + GridCacheContext cctx = grp.sharedGroup() ? ctx.cacheContext(entry.cacheId()) : grp.singleCacheContext(); + + cached = cctx.dhtCache().entryEx(entry.key()); if (log.isDebugEnabled()) log.debug("Rebalancing key [key=" + entry.key() + ", part=" + p + ", node=" + pick.id() + ']'); @@ -808,7 +832,10 @@ else if (log.isDebugEnabled()) } catch (IgniteCheckedException e) { throw new IgniteCheckedException("Failed to cache rebalanced entry (will stop rebalancing) [local=" + - cctx.nodeId() + ", node=" + pick.id() + ", key=" + entry.key() + ", part=" + p + ']', e); + ctx.localNode() + ", node=" + pick.id() + ", key=" + entry.key() + ", part=" + p + ']', e); + } + finally { + ctx.database().checkpointReadUnlock(); } return true; @@ -824,16 +851,10 @@ else if (log.isDebugEnabled()) */ public static class RebalanceFuture extends GridFutureAdapter { /** */ - private static final long serialVersionUID = 1L; - - /** Should EVT_CACHE_REBALANCE_STARTED event be sent or not. */ - private final AtomicBoolean startedEvtSent; - - /** Should EVT_CACHE_REBALANCE_STOPPED event be sent or not. */ - private final AtomicBoolean stoppedEvtSent; + private final GridCacheSharedContext ctx; /** */ - private final GridCacheContext cctx; + private final CacheGroupContext grp; /** */ private final IgniteLogger log; @@ -855,42 +876,38 @@ public static class RebalanceFuture extends GridFutureAdapter { private final long updateSeq; /** + * @param grp Cache group. * @param assigns Assigns. - * @param cctx Context. * @param log Logger. - * @param startedEvtSent Start event sent flag. - * @param stoppedEvtSent Stop event sent flag. * @param updateSeq Update sequence. */ - RebalanceFuture(GridDhtPreloaderAssignments assigns, - GridCacheContext cctx, + RebalanceFuture( + CacheGroupContext grp, + GridDhtPreloaderAssignments assigns, IgniteLogger log, - AtomicBoolean startedEvtSent, - AtomicBoolean stoppedEvtSent, long updateSeq) { assert assigns != null; exchFut = assigns.exchangeFuture(); topVer = assigns.topologyVersion(); - this.cctx = cctx; + this.grp = grp; this.log = log; - this.startedEvtSent = startedEvtSent; - this.stoppedEvtSent = stoppedEvtSent; this.updateSeq = updateSeq; + + ctx= grp.shared(); } /** * Dummy future. Will be done by real one. */ - public RebalanceFuture() { - exchFut = null; - topVer = null; - cctx = null; - log = null; - startedEvtSent = null; - stoppedEvtSent = null; - updateSeq = -1; + RebalanceFuture() { + this.exchFut = null; + this.topVer = null; + this.ctx = null; + this.grp = null; + this.log = null; + this.updateSeq = -1; } /** @@ -927,7 +944,7 @@ private boolean isInitial() { U.log(log, "Cancelled rebalancing from all nodes [topology=" + topologyVersion() + ']'); - if (!cctx.kernalContext().isStopping()) { + if (!ctx.kernalContext().isStopping()) { for (UUID nodeId : remaining.keySet()) cleanupRemoteContexts(nodeId); } @@ -948,7 +965,7 @@ private void cancel(UUID nodeId) { if (isDone()) return; - U.log(log, ("Cancelled rebalancing [cache=" + cctx.name() + + U.log(log, ("Cancelled rebalancing [cache=" + grp.cacheOrGroupName() + ", fromNode=" + nodeId + ", topology=" + topologyVersion() + ", time=" + (U.currentTimeMillis() - remaining.get(nodeId).get1()) + " ms]")); @@ -983,22 +1000,24 @@ private void partitionMissed(UUID nodeId, int p) { * @param nodeId Node id. */ private void cleanupRemoteContexts(UUID nodeId) { - ClusterNode node = cctx.discovery().node(nodeId); + ClusterNode node = ctx.discovery().node(nodeId); if (node == null) return; GridDhtPartitionDemandMessage d = new GridDhtPartitionDemandMessage( - -1/* remove supply context signal */, this.topologyVersion(), cctx.cacheId()); + -1/* remove supply context signal */, + this.topologyVersion(), + grp.groupId()); - d.timeout(cctx.config().getRebalanceTimeout()); + d.timeout(grp.config().getRebalanceTimeout()); try { - for (int idx = 0; idx < cctx.gridConfig().getRebalanceThreadPoolSize(); idx++) { + for (int idx = 0; idx < ctx.gridConfig().getRebalanceThreadPoolSize(); idx++) { d.topic(GridCachePartitionExchangeManager.rebalanceTopic(idx)); - cctx.io().sendOrderedMessage(node, GridCachePartitionExchangeManager.rebalanceTopic(idx), - d, cctx.ioPolicy(), cctx.config().getRebalanceTimeout()); + ctx.io().sendOrderedMessage(node, GridCachePartitionExchangeManager.rebalanceTopic(idx), + d, grp.ioPolicy(), grp.config().getRebalanceTimeout()); } } catch (IgniteCheckedException ignored) { @@ -1016,20 +1035,19 @@ private void partitionDone(UUID nodeId, int p) { if (isDone()) return; - if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_PART_LOADED)) - preloadEvent(p, EVT_CACHE_REBALANCE_PART_LOADED, - exchFut.discoveryEvent()); + if (grp.eventRecordable(EVT_CACHE_REBALANCE_PART_LOADED)) + rebalanceEvent(p, EVT_CACHE_REBALANCE_PART_LOADED, exchFut.discoveryEvent()); T2> t = remaining.get(nodeId); - assert t != null : "Remaining not found [cache=" + cctx.name() + ", fromNode=" + nodeId + + assert t != null : "Remaining not found [grp=" + grp.name() + ", fromNode=" + nodeId + ", part=" + p + "]"; Collection parts = t.get2(); boolean rmvd = parts.remove(p); - assert rmvd : "Partition already done [cache=" + cctx.name() + ", fromNode=" + nodeId + + assert rmvd : "Partition already done [grp=" + grp.name() + ", fromNode=" + nodeId + ", part=" + p + ", left=" + parts + "]"; if (parts.isEmpty()) { @@ -1049,18 +1067,18 @@ private void partitionDone(UUID nodeId, int p) { * @param type Type. * @param discoEvt Discovery event. */ - private void preloadEvent(int part, int type, DiscoveryEvent discoEvt) { + private void rebalanceEvent(int part, int type, DiscoveryEvent discoEvt) { assert discoEvt != null; - cctx.events().addPreloadEvent(part, type, discoEvt.eventNode(), discoEvt.type(), discoEvt.timestamp()); + grp.addRebalanceEvent(part, type, discoEvt.eventNode(), discoEvt.type(), discoEvt.timestamp()); } /** * @param type Type. * @param discoEvt Discovery event. */ - private void preloadEvent(int type, DiscoveryEvent discoEvt) { - preloadEvent(-1, type, discoEvt); + private void rebalanceEvent(int type, DiscoveryEvent discoEvt) { + rebalanceEvent(-1, type, discoEvt); } /** @@ -1080,7 +1098,7 @@ private void checkIsDone(boolean cancelled) { if (log.isDebugEnabled()) log.debug("Completed rebalance future: " + this); - cctx.shared().exchange().scheduleResendPartitions(); + ctx.exchange().scheduleResendPartitions(); Collection m = new HashSet<>(); @@ -1094,13 +1112,13 @@ private void checkIsDone(boolean cancelled) { onDone(false); //Finished but has missed partitions, will force dummy exchange - cctx.shared().exchange().forceDummyExchange(true, exchFut); + ctx.exchange().forceDummyExchange(true, exchFut); return; } - if (!cancelled && !cctx.preloader().syncFuture().isDone()) - ((GridFutureAdapter)cctx.preloader().syncFuture()).onDone(); + if (!cancelled && !grp.preloader().syncFuture().isDone()) + ((GridFutureAdapter)grp.preloader().syncFuture()).onDone(); onDone(!cancelled); } @@ -1110,24 +1128,16 @@ private void checkIsDone(boolean cancelled) { * */ private void sendRebalanceStartedEvent() { - if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_STARTED) && - (!cctx.isReplicated() || !startedEvtSent.get())) { - preloadEvent(EVT_CACHE_REBALANCE_STARTED, exchFut.discoveryEvent()); - - startedEvtSent.set(true); - } + if (grp.eventRecordable(EVT_CACHE_REBALANCE_STARTED)) + rebalanceEvent(EVT_CACHE_REBALANCE_STARTED, exchFut.discoveryEvent()); } /** * */ private void sendRebalanceFinishedEvent() { - if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_STOPPED) && - (!cctx.isReplicated() || !stoppedEvtSent.get())) { - preloadEvent(EVT_CACHE_REBALANCE_STOPPED, exchFut.discoveryEvent()); - - stoppedEvtSent.set(true); - } + if (grp.eventRecordable(EVT_CACHE_REBALANCE_STOPPED)) + rebalanceEvent(EVT_CACHE_REBALANCE_STOPPED, exchFut.discoveryEvent()); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java index 0ff03f73590ca..467b9069352b3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.UUID; import org.apache.ignite.IgniteCheckedException; @@ -26,7 +27,7 @@ import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; import org.apache.ignite.internal.processors.cache.IgniteRebalanceIterator; import org.apache.ignite.internal.processors.cache.database.CacheDataRow; @@ -47,7 +48,7 @@ */ class GridDhtPartitionSupplier { /** */ - private final GridCacheContext cctx; + private final CacheGroupContext grp; /** */ private final IgniteLogger log; @@ -65,18 +66,18 @@ class GridDhtPartitionSupplier { private final Map, SupplyContext> scMap = new HashMap<>(); /** - * @param cctx Cache context. + * @param grp Cache group. */ - GridDhtPartitionSupplier(GridCacheContext cctx) { - assert cctx != null; + GridDhtPartitionSupplier(CacheGroupContext grp) { + assert grp != null; - this.cctx = cctx; + this.grp = grp; - log = cctx.logger(getClass()); + log = grp.shared().logger(getClass()); - top = cctx.dht().topology(); + top = grp.topology(); - depEnabled = cctx.gridDeploy().enabled(); + depEnabled = grp.shared().gridDeploy().enabled(); } /** @@ -171,7 +172,7 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage assert d != null; assert id != null; - AffinityTopologyVersion cutTop = cctx.affinity().affinityTopologyVersion(); + AffinityTopologyVersion cutTop = grp.affinity().lastVersion(); AffinityTopologyVersion demTop = d.topologyVersion(); T3 scId = new T3<>(id, idx, demTop); @@ -197,9 +198,12 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage ", from=" + id + ", idx=" + idx + "]"); GridDhtPartitionSupplyMessage s = new GridDhtPartitionSupplyMessage( - d.updateSequence(), cctx.cacheId(), d.topologyVersion(), cctx.deploymentEnabled()); + d.updateSequence(), + grp.groupId(), + d.topologyVersion(), + grp.deploymentEnabled()); - ClusterNode node = cctx.discovery().node(id); + ClusterNode node = grp.shared().discovery().node(id); if (node == null) return; // Context will be cleaned at topology change. @@ -225,7 +229,7 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage boolean newReq = true; - long maxBatchesCnt = cctx.config().getRebalanceBatchesPrefetchCount(); + long maxBatchesCnt = grp.config().getRebalanceBatchesPrefetchCount(); if (sctx != null) { phase = sctx.phase; @@ -234,7 +238,7 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage } else { if (log.isDebugEnabled()) - log.debug("Starting supplying rebalancing [cache=" + cctx.name() + + log.debug("Starting supplying rebalancing [cache=" + grp.cacheOrGroupName() + ", fromNode=" + node.id() + ", partitionsCount=" + d.partitions().size() + ", topology=" + d.topologyVersion() + ", updateSeq=" + d.updateSequence() + ", idx=" + idx + "]"); @@ -243,18 +247,19 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage Iterator partIt = sctx != null ? sctx.partIt : d.partitions().iterator(); if (sctx == null) { - long keysCnt = 0; - for (Integer part : d.partitions()) { GridDhtLocalPartition loc = top.localPartition(part, d.topologyVersion(), false); if (loc == null || loc.state() != OWNING) continue; - keysCnt += cctx.offheap().entriesCount(part); + if (grp.sharedGroup()) { + for (int cacheId : grp.cacheIds()) + s.addKeysForCache(cacheId, grp.offheap().cacheEntriesCount(cacheId, part)); + } + else + s.addEstimatedKeysCount(grp.offheap().totalPartitionEntriesCount(part)); } - - s.estimatedKeysCount(keysCnt); } while ((sctx != null && newReq) || partIt.hasNext()) { @@ -295,22 +300,24 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage IgniteRebalanceIterator iter; if (sctx == null || sctx.entryIt == null) { - iter = cctx.offheap().rebalanceIterator(part, d.topologyVersion(), + iter = grp.offheap().rebalanceIterator(part, d.topologyVersion(), d.isHistorical(part) ? d.partitionCounter(part) : null); if (!iter.historical()) { - assert !cctx.shared().database().persistenceEnabled() || !d.isHistorical(part); + assert !grp.shared().database().persistenceEnabled() || !d.isHistorical(part); s.clean(part); } else - assert cctx.shared().database().persistenceEnabled() && d.isHistorical(part); + assert grp.shared().database().persistenceEnabled() && d.isHistorical(part); } else iter = (IgniteRebalanceIterator)sctx.entryIt; while (iter.hasNext()) { - if (!cctx.affinity().partitionBelongs(node, part, d.topologyVersion())) { + List nodes = grp.affinity().cachedAffinity(d.topologyVersion()).get(part); + + if (!nodes.contains(node)) { // Demander no longer needs this partition, // so we send '-1' partition and move on. s.missed(part); @@ -334,7 +341,7 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage break; } - if (s.messageSize() >= cctx.config().getRebalanceBatchSize()) { + if (s.messageSize() >= grp.config().getRebalanceBatchSize()) { if (++bCnt >= maxBatchesCnt) { saveSupplyContext(scId, phase, @@ -356,9 +363,9 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage return; s = new GridDhtPartitionSupplyMessage(d.updateSequence(), - cctx.cacheId(), + grp.groupId(), d.topologyVersion(), - cctx.deploymentEnabled()); + grp.deploymentEnabled()); } } @@ -370,9 +377,10 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage info.expireTime(row.expireTime()); info.version(row.version()); info.value(row.value()); + info.cacheId(row.cacheId()); if (preloadPred == null || preloadPred.apply(info)) - s.addEntry0(part, info, cctx); + s.addEntry0(part, info, grp.shared(), grp.cacheObjectContext()); else { if (log.isDebugEnabled()) log.debug("Rebalance predicate evaluated to false (will not send " + @@ -421,7 +429,7 @@ public void handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage reply(node, d, s, scId); if (log.isDebugEnabled()) - log.debug("Finished supplying rebalancing [cache=" + cctx.name() + + log.debug("Finished supplying rebalancing [cache=" + grp.cacheOrGroupName() + ", fromNode=" + node.id() + ", topology=" + d.topologyVersion() + ", updateSeq=" + d.updateSequence() + ", idx=" + idx + "]"); @@ -448,16 +456,15 @@ private boolean reply(ClusterNode n, GridDhtPartitionSupplyMessage s, T3 scId) throws IgniteCheckedException { - try { if (log.isDebugEnabled()) log.debug("Replying to partition demand [node=" + n.id() + ", demand=" + d + ", supply=" + s + ']'); - cctx.io().sendOrderedMessage(n, d.topic(), s, cctx.ioPolicy(), d.timeout()); + grp.shared().io().sendOrderedMessage(n, d.topic(), s, grp.ioPolicy(), d.timeout()); // Throttle preloading. - if (cctx.config().getRebalanceThrottle() > 0) - U.sleep(cctx.config().getRebalanceThrottle()); + if (grp.config().getRebalanceThrottle() > 0) + U.sleep(grp.config().getRebalanceThrottle()); return true; } @@ -490,7 +497,7 @@ private void saveSupplyContext( AffinityTopologyVersion topVer, long updateSeq) { synchronized (scMap) { - if (cctx.affinity().affinityTopologyVersion().equals(topVer)) { + if (grp.affinity().lastVersion().equals(topVer)) { assert scMap.get(t) == null; scMap.put(t, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java index 1cb32e33b4f7e..ef14a90c0f85a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java @@ -28,13 +28,13 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.GridDirectCollection; import org.apache.ignite.internal.GridDirectMap; -import org.apache.ignite.internal.GridDirectTransient; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection; -import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; +import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheGroupIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; @@ -45,7 +45,7 @@ /** * Partition supply message. */ -public class GridDhtPartitionSupplyMessage extends GridCacheMessage implements GridCacheDeployable { +public class GridDhtPartitionSupplyMessage extends GridCacheGroupIdMessage implements GridCacheDeployable { /** */ private static final long serialVersionUID = 0L; @@ -79,17 +79,21 @@ public class GridDhtPartitionSupplyMessage extends GridCacheMessage implements G /** Estimated keys count. */ private long estimatedKeysCnt = -1; + /** Estimated keys count per cache in case the message is for shared group. */ + @GridDirectMap(keyType = int.class, valueType = long.class) + private Map keysPerCache; + /** * @param updateSeq Update sequence for this node. - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param topVer Topology version. * @param addDepInfo Deployment info flag. */ GridDhtPartitionSupplyMessage(long updateSeq, - int cacheId, + int grpId, AffinityTopologyVersion topVer, boolean addDepInfo) { - this.cacheId = cacheId; + this.grpId = grpId; this.updateSeq = updateSeq; this.topVer = topVer; this.addDepInfo = addDepInfo; @@ -206,18 +210,19 @@ int messageSize() { /** * @param p Partition. * @param info Entry to add. - * @param ctx Cache context. + * @param ctx Cache shared context. + * @param cacheObjCtx Cache object context. * @throws IgniteCheckedException If failed. */ - void addEntry0(int p, GridCacheEntryInfo info, GridCacheContext ctx) throws IgniteCheckedException { + void addEntry0(int p, GridCacheEntryInfo info, GridCacheSharedContext ctx, CacheObjectContext cacheObjCtx) throws IgniteCheckedException { assert info != null; assert info.key() != null : info; assert info.value() != null : info; // Need to call this method to initialize info properly. - marshalInfo(info, ctx); + marshalInfo(info, ctx, cacheObjCtx); - msgSize += info.marshalledSize(ctx); + msgSize += info.marshalledSize(cacheObjCtx); CacheEntryInfoCollection infoCol = infos().get(p); @@ -237,13 +242,13 @@ void addEntry0(int p, GridCacheEntryInfo info, GridCacheContext ctx) throws Igni @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { super.finishUnmarshal(ctx, ldr); - GridCacheContext cacheCtx = ctx.cacheContext(cacheId); + CacheGroupContext grp = ctx.cache().cacheGroup(grpId); for (CacheEntryInfoCollection col : infos().values()) { List entries = col.infos(); for (int i = 0; i < entries.size(); i++) - entries.get(i).unmarshal(cacheCtx, ldr); + entries.get(i).unmarshal(grp.cacheObjectContext(), ldr); } } @@ -281,46 +286,53 @@ public int size() { writer.incrementState(); case 4: - if (!writer.writeMap("infos", infos, MessageCollectionItemType.INT, MessageCollectionItemType.MSG)) + if (!writer.writeLong("estimatedKeysCnt", estimatedKeysCnt)) return false; writer.incrementState(); case 5: - if (!writer.writeCollection("last", last, MessageCollectionItemType.INT)) + if (!writer.writeMap("infos", infos, MessageCollectionItemType.INT, MessageCollectionItemType.MSG)) return false; writer.incrementState(); case 6: - if (!writer.writeCollection("missed", missed, MessageCollectionItemType.INT)) + if (!writer.writeMap("keysPerCache", keysPerCache, MessageCollectionItemType.INT, MessageCollectionItemType.LONG)) return false; writer.incrementState(); case 7: - if (!writer.writeMessage("topVer", topVer)) + if (!writer.writeCollection("last", last, MessageCollectionItemType.INT)) return false; writer.incrementState(); case 8: - if (!writer.writeLong("updateSeq", updateSeq)) + if (!writer.writeCollection("missed", missed, MessageCollectionItemType.INT)) return false; writer.incrementState(); case 9: - if (!writer.writeLong("estimatedKeysCnt", estimatedKeysCnt)) + if (!writer.writeInt("msgSize", msgSize)) return false; writer.incrementState(); case 10: - if (!writer.writeInt("msgSize", msgSize)) + if (!writer.writeMessage("topVer", topVer)) return false; writer.incrementState(); + + case 11: + if (!writer.writeLong("updateSeq", updateSeq)) + return false; + + writer.incrementState(); + } return true; @@ -346,7 +358,7 @@ public int size() { reader.incrementState(); case 4: - infos = reader.readMap("infos", MessageCollectionItemType.INT, MessageCollectionItemType.MSG, false); + estimatedKeysCnt = reader.readLong("estimatedKeysCnt"); if (!reader.isLastRead()) return false; @@ -354,7 +366,7 @@ public int size() { reader.incrementState(); case 5: - last = reader.readCollection("last", MessageCollectionItemType.INT); + infos = reader.readMap("infos", MessageCollectionItemType.INT, MessageCollectionItemType.MSG, false); if (!reader.isLastRead()) return false; @@ -362,7 +374,7 @@ public int size() { reader.incrementState(); case 6: - missed = reader.readCollection("missed", MessageCollectionItemType.INT); + keysPerCache = reader.readMap("keysPerCache", MessageCollectionItemType.INT, MessageCollectionItemType.LONG, false); if (!reader.isLastRead()) return false; @@ -370,7 +382,7 @@ public int size() { reader.incrementState(); case 7: - topVer = reader.readMessage("topVer"); + last = reader.readCollection("last", MessageCollectionItemType.INT); if (!reader.isLastRead()) return false; @@ -378,7 +390,7 @@ public int size() { reader.incrementState(); case 8: - updateSeq = reader.readLong("updateSeq"); + missed = reader.readCollection("missed", MessageCollectionItemType.INT); if (!reader.isLastRead()) return false; @@ -386,7 +398,7 @@ public int size() { reader.incrementState(); case 9: - estimatedKeysCnt = reader.readLong("estimatedKeysCnt"); + msgSize = reader.readInt("msgSize"); if (!reader.isLastRead()) return false; @@ -394,12 +406,21 @@ public int size() { reader.incrementState(); case 10: - msgSize = reader.readInt("msgSize"); + topVer = reader.readMessage("topVer"); if (!reader.isLastRead()) return false; reader.incrementState(); + + case 11: + updateSeq = reader.readLong("updateSeq"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + } return reader.afterMessageRead(GridDhtPartitionSupplyMessage.class); @@ -412,7 +433,7 @@ public int size() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 11; + return 12; } /** @@ -423,10 +444,43 @@ public long estimatedKeysCount() { } /** - * @param estimatedKeysCnt New estimated keys count. + * @param cnt Keys count to add. */ - public void estimatedKeysCount(long estimatedKeysCnt) { - this.estimatedKeysCnt = estimatedKeysCnt; + public void addEstimatedKeysCount(long cnt) { + this.estimatedKeysCnt += cnt; + } + + /** + * @return Estimated keys count for a given cache ID. + */ + public long keysForCache(int cacheId) { + if (this.keysPerCache == null) + return -1; + + Long cnt = this.keysPerCache.get(cacheId); + + return cnt != null ? cnt : 0; + } + + /** + * @param cacheId Cache ID. + * @param cnt Keys count. + */ + public void addKeysForCache(int cacheId, long cnt) { + assert cacheId != 0 && cnt >= 0; + + if (keysPerCache == null) + keysPerCache = new HashMap<>(); + + Long cnt0 = keysPerCache.get(cacheId); + + if (cnt0 == null) { + keysPerCache.put(cacheId, cnt); + + msgSize += 12; + } + else + keysPerCache.put(cacheId, cnt0 + cnt); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsAbstractMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsAbstractMessage.java index 74bbcb05ac1cd..441952d482351 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsAbstractMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsAbstractMessage.java @@ -64,6 +64,11 @@ protected GridDhtPartitionsAbstractMessage() { this.lastVer = lastVer; } + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return false; + } + /** {@inheritDoc} */ @Override public int partition() { return GridIoMessage.STRIPE_DISABLED_PART; @@ -87,10 +92,10 @@ protected GridDhtPartitionsAbstractMessage() { } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @return Parition update counters. */ - public abstract Map> partitionUpdateCounters(int cacheId); + public abstract Map> partitionUpdateCounters(int grpId); /** * @return Last used version among all nodes. @@ -113,6 +118,11 @@ protected final void compressed(boolean compressed) { flags = compressed ? (byte)(flags | COMPRESSED_FLAG_MASK) : (byte)(flags & ~COMPRESSED_FLAG_MASK); } + /** {@inheritDoc} */ + @Override public byte fieldsCount() { + return 5; + } + /** {@inheritDoc} */ @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) { writer.setBuffer(buf); @@ -128,19 +138,19 @@ protected final void compressed(boolean compressed) { } switch (writer.state()) { - case 3: + case 2: if (!writer.writeMessage("exchId", exchId)) return false; writer.incrementState(); - case 4: + case 3: if (!writer.writeByte("flags", flags)) return false; writer.incrementState(); - case 5: + case 4: if (!writer.writeMessage("lastVer", lastVer)) return false; @@ -162,7 +172,7 @@ protected final void compressed(boolean compressed) { return false; switch (reader.state()) { - case 3: + case 2: exchId = reader.readMessage("exchId"); if (!reader.isLastRead()) @@ -170,7 +180,7 @@ protected final void compressed(boolean compressed) { reader.incrementState(); - case 4: + case 3: flags = reader.readByte("flags"); if (!reader.isLastRead()) @@ -178,7 +188,7 @@ protected final void compressed(boolean compressed) { reader.incrementState(); - case 5: + case 4: lastVer = reader.readMessage("lastVer"); if (!reader.isLastRead()) 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 d3042e94ea9a9..88dc863c3a4d1 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 @@ -57,6 +57,8 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; import org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage; +import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheInvalidStateException; import org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask; import org.apache.ignite.internal.processors.cache.ClusterState; @@ -198,8 +200,8 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter cacheValidRes; + /** Cache groups validation results. */ + private volatile Map grpValidRes; /** Skip preload flag. */ private boolean skipPreload; @@ -237,6 +239,7 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter cacheNames = new HashSet<>(); + + Collection grpDescs = new ArrayList<>(); + + for (Integer grpId : op.cacheGroupIds()) { + CacheGroupContext cacheGrp = cctx.cache().cacheGroup(grpId); + + if (cacheGrp == null) + continue; + + grpDescs.add(cctx.cache().cacheGroupDescriptors().get(grpId)); + + for (Integer cacheId : cacheGrp.cacheIds()) + cacheNames.add(cctx.cacheContext(cacheId).name()); + } + List destroyRequests = getStopCacheRequests( - cctx.cache(), op.cacheNames(), cctx.localNodeId()); + cctx.cache(), cacheNames, cctx.localNodeId()); if (!F.isEmpty(destroyRequests)) { //Emulate destroy cache request for (DynamicCacheChangeRequest req : destroyRequests) { @@ -559,6 +596,9 @@ else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) { .cacheDescriptor(CU.cacheId(req.cacheName()))); } + for (CacheGroupDescriptor grpDesc : grpDescs) + exchActions.addCacheGroupToStop(grpDesc); + if (op.type() == SnapshotOperationType.RESTORE) cctx.cache().onCustomEvent(new DynamicCacheChangeBatch(destroyRequests), topVer); @@ -688,11 +728,11 @@ private void initTopologies() throws IgniteCheckedException { try { if (crd != null) { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - cacheCtx.topology().beforeExchange(this, !centralizedAff); + grp.topology().beforeExchange(this, !centralizedAff); } } } @@ -706,28 +746,28 @@ private void initTopologies() throws IgniteCheckedException { * @throws IgniteCheckedException If failed. */ private void updateTopologies(boolean crd) throws IgniteCheckedException { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - GridClientPartitionTopology clientTop = cctx.exchange().clearClientTopology(cacheCtx.cacheId()); + GridClientPartitionTopology clientTop = cctx.exchange().clearClientTopology(grp.groupId()); long updSeq = clientTop == null ? -1 : clientTop.lastUpdateSequence(); - GridDhtPartitionTopology top = cacheCtx.topology(); + GridDhtPartitionTopology top = grp.topology(); if (crd) { - boolean updateTop = exchId.topologyVersion().equals(cacheCtx.startTopologyVersion()); + boolean updateTop = exchId.topologyVersion().equals(grp.localStartVersion()); if (updateTop && clientTop != null) top.update(this, clientTop.partitionMap(true), clientTop.updateCounters(false), Collections.emptySet()); } - top.updateTopologyVersion(exchId, this, updSeq, stopping(cacheCtx.cacheId())); + top.updateTopologyVersion(exchId, this, updSeq, cacheGroupStopping(grp.groupId())); } for (GridClientPartitionTopology top : cctx.exchange().clientTopologies()) - top.updateTopologyVersion(exchId, this, -1, stopping(top.cacheId())); + top.updateTopologyVersion(exchId, this, -1, cacheGroupStopping(top.groupId())); } /** @@ -821,15 +861,19 @@ private void clientOnlyExchange() throws IgniteCheckedException { if (crd != null) { if (crd.isLocal()) { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - boolean updateTop = !cacheCtx.isLocal() && - exchId.topologyVersion().equals(cacheCtx.startTopologyVersion()); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + boolean updateTop = !grp.isLocal() && + exchId.topologyVersion().equals(grp.localStartVersion()); if (updateTop) { for (GridClientPartitionTopology top : cctx.exchange().clientTopologies()) { - if (top.cacheId() == cacheCtx.cacheId()) { - cacheCtx.topology().update(this, - top.partitionMap(true), + if (top.groupId() == grp.groupId()) { + GridDhtPartitionFullMap fullMap = top.partitionMap(true); + + assert fullMap != null; + + grp.topology().update(this, + fullMap, top.updateCounters(false), Collections.emptySet()); @@ -850,8 +894,8 @@ private void clientOnlyExchange() throws IgniteCheckedException { } else { if (centralizedAff) { // Last server node failed. - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - GridAffinityAssignmentCache aff = cacheCtx.affinity().affinityCache(); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + GridAffinityAssignmentCache aff = grp.affinity(); aff.initialize(topologyVersion(), aff.idealAssignment()); } @@ -869,11 +913,11 @@ private void distributedExchange() throws IgniteCheckedException { assert !cctx.kernalContext().clientNode(); - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - cacheCtx.preloader().onTopologyChanged(this); + grp.preloader().onTopologyChanged(this); } cctx.database().releaseHistoryForPreloading(); @@ -886,15 +930,20 @@ private void distributedExchange() throws IgniteCheckedException { boolean topChanged = discoEvt.type() != EVT_DISCOVERY_CUSTOM_EVT || affChangeMsg != null; for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal() || stopping(cacheCtx.cacheId())) + if (cacheCtx.isLocal() || cacheStopping(cacheCtx.cacheId())) continue; if (topChanged) { // Partition release future is done so we can flush the write-behind store. cacheCtx.store().forceFlush(); } + } + + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal() || cacheGroupStopping(grp.groupId())) + continue; - cacheCtx.topology().beforeExchange(this, !centralizedAff); + grp.topology().beforeExchange(this, !centralizedAff); } cctx.database().beforeExchange(this); @@ -1018,11 +1067,11 @@ private void waitPartitionRelease() throws IgniteCheckedException { * */ private void onLeft() { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - cacheCtx.preloader().unwindUndeploys(); + grp.preloader().unwindUndeploys(); } cctx.mvcc().removeExplicitNodeLocks(exchId.nodeId(), exchId.topologyVersion()); @@ -1034,17 +1083,17 @@ private void onLeft() { private void warnNoAffinityNodes() { List cachesWithoutNodes = null; - for (String name : cctx.cache().cacheNames()) { - if (discoCache.cacheAffinityNodes(name).isEmpty()) { + for (DynamicCacheDescriptor cacheDesc : cctx.cache().cacheDescriptors().values()) { + if (discoCache.cacheGroupAffinityNodes(cacheDesc.groupId()).isEmpty()) { if (cachesWithoutNodes == null) cachesWithoutNodes = new ArrayList<>(); - cachesWithoutNodes.add(name); + cachesWithoutNodes.add(cacheDesc.cacheName()); // Fire event even if there is no client cache started. if (cctx.gridEvents().isRecordable(EventType.EVT_CACHE_NODES_LEFT)) { Event evt = new CacheEvent( - name, + cacheDesc.cacheName(), cctx.localNode(), cctx.localNode(), "All server nodes have left the cluster.", @@ -1105,11 +1154,19 @@ private void dumpPendingObjects() { U.dumpThreads(log); } + /** + * @param grpId Cache group ID to check. + * @return {@code True} if cache group us stopping by this exchange. + */ + private boolean cacheGroupStopping(int grpId) { + return exchActions != null && exchActions.cacheGroupStopping(grpId); + } + /** * @param cacheId Cache ID to check. * @return {@code True} if cache is stopping by this exchange. */ - public boolean stopping(int cacheId) { + private boolean cacheStopping(int cacheId) { return exchActions != null && exchActions.cacheStopped(cacheId); } @@ -1235,18 +1292,20 @@ private boolean serverNodeDiscoveryEvent() { } if (err == null && realExchange) { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; try { if (centralizedAff) - cacheCtx.topology().initPartitions(this); + grp.topology().initPartitions(this); } catch (IgniteInterruptedCheckedException e) { U.error(log, "Failed to initialize partitions.", e); } + } + for (GridCacheContext cacheCtx : cctx.cacheContexts()) { GridCacheContext drCacheCtx = cacheCtx.isNear() ? cacheCtx.near().dht().context() : cacheCtx; if (drCacheCtx.isDrEnabled()) { @@ -1264,21 +1323,21 @@ private boolean serverNodeDiscoveryEvent() { discoEvt.type() == EVT_NODE_JOINED) detectLostPartitions(); - Map m = new HashMap<>(cctx.cacheContexts().size()); + Map m = new HashMap<>(cctx.cache().cacheGroups().size()); - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - Collection lostParts = cacheCtx.isLocal() ? - Collections.emptyList() : cacheCtx.topology().lostPartitions(); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + Collection lostParts = grp.isLocal() ? + Collections.emptyList() : grp.topology().lostPartitions(); boolean valid = true; - if (cacheCtx.config().getTopologyValidator() != null && !CU.isSystemCache(cacheCtx.name())) - valid = cacheCtx.config().getTopologyValidator().validate(discoEvt.topologyNodes()); + if (grp.topologyValidator() != null && !grp.systemCache()) + valid = grp.topologyValidator().validate(discoEvt.topologyNodes()); - m.put(cacheCtx.cacheId(), new CacheValidation(valid, lostParts)); + m.put(grp.groupId(), new CacheValidation(valid, lostParts)); } - cacheValidRes = m; + grpValidRes = m; } cctx.cache().onExchangeDone(exchId.topologyVersion(), exchActions, err, false); @@ -1329,8 +1388,8 @@ private boolean serverNodeDiscoveryEvent() { initFut.onDone(err == null); if (exchId.isLeft()) { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) - cacheCtx.config().getAffinity().removeNode(exchId.nodeId()); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) + grp.affinityFunction().removeNode(exchId.nodeId()); } exchActions = null; @@ -1379,16 +1438,18 @@ private StartSnapshotOperationAckDiscoveryMessage getSnapshotOperationMessage() return new CacheInvalidStateException( "Failed to perform cache operation (cluster is not activated): " + cctx.name()); - PartitionLossPolicy partLossPlc = cctx.config().getPartitionLossPolicy(); + CacheGroupContext grp = cctx.group(); - if (cctx.needsRecovery() && !recovery) { + PartitionLossPolicy partLossPlc = grp.config().getPartitionLossPolicy(); + + if (grp.needsRecovery() && !recovery) { if (!read && (partLossPlc == READ_ONLY_SAFE || partLossPlc == READ_ONLY_ALL)) return new IgniteCheckedException("Failed to write to cache (cache is moved to a read-only state): " + cctx.name()); } - if (cctx.needsRecovery() || cctx.config().getTopologyValidator() != null) { - CacheValidation validation = cacheValidRes.get(cctx.cacheId()); + if (grp.needsRecovery() || grp.topologyValidator() != null) { + CacheValidation validation = grpValidRes.get(grp.groupId()); if (validation == null) return null; @@ -1397,7 +1458,7 @@ private StartSnapshotOperationAckDiscoveryMessage getSnapshotOperationMessage() return new IgniteCheckedException("Failed to perform cache operation " + "(cache topology is not valid): " + cctx.name()); - if (recovery || !cctx.needsRecovery()) + if (recovery || !grp.needsRecovery()) return null; if (key != null) { @@ -1629,9 +1690,9 @@ private void assignPartitionStates(GridDhtPartitionTopology top) { Map minCntrs = new HashMap<>(); for (Map.Entry e : msgs.entrySet()) { - assert e.getValue().partitionUpdateCounters(top.cacheId()) != null; + assert e.getValue().partitionUpdateCounters(top.groupId()) != null; - for (Map.Entry> e0 : e.getValue().partitionUpdateCounters(top.cacheId()).entrySet()) { + for (Map.Entry> e0 : e.getValue().partitionUpdateCounters(top.groupId()).entrySet()) { int p = e0.getKey(); UUID uuid = e.getKey(); @@ -1702,7 +1763,7 @@ else if (cntr == maxCntr.cnt) Map> partHistReserved0 = partHistReserved; - Map localReserved = partHistReserved0 != null ? partHistReserved0.get(top.cacheId()) : null; + Map localReserved = partHistReserved0 != null ? partHistReserved0.get(top.groupId()) : null; Set haveHistory = new HashSet<>(); @@ -1723,7 +1784,7 @@ else if (cntr == maxCntr.cnt) if (localCntr != null && localCntr <= minCntr && maxCntrObj.nodes.contains(cctx.localNodeId())) { - partHistSuppliers.put(cctx.localNodeId(), top.cacheId(), p, minCntr); + partHistSuppliers.put(cctx.localNodeId(), top.groupId(), p, minCntr); haveHistory.add(p); @@ -1732,10 +1793,10 @@ else if (cntr == maxCntr.cnt) } for (Map.Entry e0 : msgs.entrySet()) { - Long histCntr = e0.getValue().partitionHistoryCounters(top.cacheId()).get(p); + Long histCntr = e0.getValue().partitionHistoryCounters(top.groupId()).get(p); if (histCntr != null && histCntr <= minCntr && maxCntrObj.nodes.contains(e0.getKey())) { - partHistSuppliers.put(e0.getKey(), top.cacheId(), p, minCntr); + partHistSuppliers.put(e0.getKey(), top.groupId(), p, minCntr); haveHistory.add(p); @@ -1756,7 +1817,7 @@ else if (cntr == maxCntr.cnt) Set nodesToReload = top.setOwners(p, e.getValue().nodes, haveHistory.contains(p), entryLeft == 0); for (UUID nodeId : nodesToReload) - partsToReload.put(nodeId, top.cacheId(), p); + partsToReload.put(nodeId, top.groupId(), p); } } @@ -1768,24 +1829,32 @@ private void detectLostPartitions() { if (Thread.currentThread().isInterrupted()) return; - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (!cacheCtx.isLocal()) - cacheCtx.topology().detectLostPartitions(discoEvt); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (!grp.isLocal()) + grp.topology().detectLostPartitions(discoEvt); } } } /** - * + * @param cacheNames Cache names. */ private void resetLostPartitions(Collection cacheNames) { synchronized (cctx.exchange().interruptLock()) { if (Thread.currentThread().isInterrupted()) return; - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (!cacheCtx.isLocal() && cacheNames.contains(cacheCtx.name())) - cacheCtx.topology().resetLostPartitions(); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) + continue; + + for (String cacheName : cacheNames) { + if (grp.hasCache(cacheName)) { + grp.topology().resetLostPartitions(); + + break; + } + } } } } @@ -1800,9 +1869,9 @@ private void onAllReceived() { assert partHistSuppliers.isEmpty(); if (!crd.equals(discoCache.serverNodes().get(0))) { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (!cacheCtx.isLocal()) - cacheCtx.topology().beforeExchange(this, !centralizedAff); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (!grp.isLocal()) + grp.topology().beforeExchange(this, !centralizedAff); } } @@ -1811,13 +1880,13 @@ private void onAllReceived() { GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage)msg; for (Map.Entry entry : msg0.partitions().entrySet()) { - Integer cacheId = entry.getKey(); - GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + Integer grpId = entry.getKey(); + CacheGroupContext grp = cctx.cache().cacheGroup(grpId); - GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() : - cctx.exchange().clientTopology(cacheId, this); + GridDhtPartitionTopology top = grp != null ? grp.topology() : + cctx.exchange().clientTopology(grpId, this); - Map> cntrs = msg0.partitionUpdateCounters(cacheId); + Map> cntrs = msg0.partitionUpdateCounters(grpId); if (cntrs != null) top.applyUpdateCounters(cntrs); @@ -1895,11 +1964,11 @@ else if (discoEvt.type() == EVT_NODE_LEFT || discoEvt.type() == EVT_NODE_FAILED) */ private void assignPartitionsStates() { if (cctx.database().persistenceEnabled()) { - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - assignPartitionStates(cacheCtx.topology()); + assignPartitionStates(grp.topology()); } } } @@ -2028,20 +2097,20 @@ private void updatePartitionFullMap(GridDhtPartitionsFullMessage msg) { partHistSuppliers.putAll(msg.partitionHistorySuppliers()); for (Map.Entry entry : msg.partitions().entrySet()) { - Integer cacheId = entry.getKey(); + Integer grpId = entry.getKey(); - Map> cntrMap = msg.partitionUpdateCounters(cacheId); + Map> cntrMap = msg.partitionUpdateCounters(grpId); - GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + CacheGroupContext grp = cctx.cache().cacheGroup(grpId); - if (cacheCtx != null) - cacheCtx.topology().update(this, entry.getValue(), cntrMap, - msg.partsToReload(cctx.localNodeId(), cacheId)); + if (grp != null) + grp.topology().update(this, entry.getValue(), cntrMap, + msg.partsToReload(cctx.localNodeId(), grpId)); else { ClusterNode oldest = cctx.discovery().oldestAliveCacheServerNode(AffinityTopologyVersion.NONE); if (oldest != null && oldest.isLocal()) - cctx.exchange().clientTopology(cacheId, this).update(this, entry.getValue(), cntrMap, Collections.emptySet()); + cctx.exchange().clientTopology(grpId, this).update(this, entry.getValue(), cntrMap, Collections.emptySet()); } } } @@ -2055,11 +2124,11 @@ private void updatePartitionSingleMap(ClusterNode node, GridDhtPartitionsSingleM msgs.put(node.id(), msg); for (Map.Entry entry : msg.partitions().entrySet()) { - Integer cacheId = entry.getKey(); - GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + Integer grpId = entry.getKey(); + CacheGroupContext grp = cctx.cache().cacheGroup(grpId); - GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() : - cctx.exchange().clientTopology(cacheId, this); + GridDhtPartitionTopology top = grp != null ? grp.topology() : + cctx.exchange().clientTopology(grpId, this); top.update(exchId, entry.getValue()); } @@ -2211,13 +2280,13 @@ public void onNodeLeft(final ClusterNode node) { List empty = Collections.emptyList(); - for (GridCacheContext cacheCtx : cctx.cacheContexts()) { - List> affAssignment = new ArrayList<>(cacheCtx.affinity().partitions()); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + List> affAssignment = new ArrayList<>(grp.affinity().partitions()); - for (int i = 0; i < cacheCtx.affinity().partitions(); i++) + for (int i = 0; i < grp.affinity().partitions(); i++) affAssignment.add(empty); - cacheCtx.affinity().affinityCache().initialize(topologyVersion(), affAssignment); + grp.affinity().initialize(topologyVersion(), affAssignment); } onDone(topologyVersion()); 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 94ad21ec5dc85..2f8a531400fe2 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 @@ -125,6 +125,11 @@ public GridDhtPartitionsFullMessage(@Nullable GridDhtPartitionExchangeId id, this.partsToReload = partsToReload; } + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + /** * @param compress {@code True} if it is possible to use compression for message. */ @@ -143,24 +148,26 @@ public Map partitions() { } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @return {@code True} if message contains full map for given cache. */ - public boolean containsCache(int cacheId) { - return parts != null && parts.containsKey(cacheId); + public boolean containsGroup(int grpId) { + return parts != null && parts.containsKey(grpId); } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param fullMap Full partitions map. * @param dupDataCache Optional ID of cache with the same partition state map. */ - public void addFullPartitionsMap(int cacheId, GridDhtPartitionFullMap fullMap, @Nullable Integer dupDataCache) { + public void addFullPartitionsMap(int grpId, GridDhtPartitionFullMap fullMap, @Nullable Integer dupDataCache) { + assert fullMap != null; + if (parts == null) parts = new HashMap<>(); - if (!parts.containsKey(cacheId)) { - parts.put(cacheId, fullMap); + if (!parts.containsKey(grpId)) { + parts.put(grpId, fullMap); if (dupDataCache != null) { assert compress; @@ -169,30 +176,29 @@ public void addFullPartitionsMap(int cacheId, GridDhtPartitionFullMap fullMap, @ if (dupPartsData == null) dupPartsData = new HashMap<>(); - dupPartsData.put(cacheId, dupDataCache); + dupPartsData.put(grpId, dupDataCache); } } } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param cntrMap Partition update counters. */ - public void addPartitionUpdateCounters(int cacheId, Map> cntrMap) { + public void addPartitionUpdateCounters(int grpId, Map> cntrMap) { if (partCntrs == null) partCntrs = new IgniteDhtPartitionCountersMap(); - partCntrs.putIfAbsent(cacheId, cntrMap); + partCntrs.putIfAbsent(grpId, cntrMap); } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @return Partition update counters. */ - @Override public Map> partitionUpdateCounters(int cacheId) { - if (partCntrs != null) { - return partCntrs.get(cacheId); - } + @Override public Map> partitionUpdateCounters(int grpId) { + if (partCntrs != null) + return partCntrs.get(grpId); return Collections.emptyMap(); } @@ -207,11 +213,11 @@ public IgniteDhtPartitionHistorySuppliersMap partitionHistorySuppliers() { return partHistSuppliers; } - public Set partsToReload(UUID nodeId, int cacheId) { + public Set partsToReload(UUID nodeId, int grpId) { if (partsToReload == null) return Collections.emptySet(); - return partsToReload.get(nodeId, cacheId); + return partsToReload.get(nodeId, grpId); } /** @@ -396,43 +402,43 @@ public void topologyVersion(AffinityTopologyVersion topVer) { } switch (writer.state()) { - case 6: + case 5: if (!writer.writeMap("dupPartsData", dupPartsData, MessageCollectionItemType.INT, MessageCollectionItemType.INT)) return false; writer.incrementState(); - case 7: + case 6: if (!writer.writeByteArray("exsBytes", exsBytes)) return false; writer.incrementState(); - case 8: + case 7: if (!writer.writeByteArray("partCntrsBytes", partCntrsBytes)) return false; writer.incrementState(); - case 9: + case 8: if (!writer.writeByteArray("partHistSuppliersBytes", partHistSuppliersBytes)) return false; writer.incrementState(); - case 10: + case 9: if (!writer.writeByteArray("partsBytes", partsBytes)) return false; writer.incrementState(); - case 11: + case 10: if (!writer.writeByteArray("partsToReloadBytes", partsToReloadBytes)) return false; writer.incrementState(); - case 12: + case 11: if (!writer.writeMessage("topVer", topVer)) return false; @@ -454,7 +460,7 @@ public void topologyVersion(AffinityTopologyVersion topVer) { return false; switch (reader.state()) { - case 6: + case 5: dupPartsData = reader.readMap("dupPartsData", MessageCollectionItemType.INT, MessageCollectionItemType.INT, false); if (!reader.isLastRead()) @@ -462,7 +468,7 @@ public void topologyVersion(AffinityTopologyVersion topVer) { reader.incrementState(); - case 7: + case 6: exsBytes = reader.readByteArray("exsBytes"); if (!reader.isLastRead()) @@ -470,7 +476,7 @@ public void topologyVersion(AffinityTopologyVersion topVer) { reader.incrementState(); - case 8: + case 7: partCntrsBytes = reader.readByteArray("partCntrsBytes"); if (!reader.isLastRead()) @@ -478,7 +484,7 @@ public void topologyVersion(AffinityTopologyVersion topVer) { reader.incrementState(); - case 9: + case 8: partHistSuppliersBytes = reader.readByteArray("partHistSuppliersBytes"); if (!reader.isLastRead()) @@ -486,7 +492,7 @@ public void topologyVersion(AffinityTopologyVersion topVer) { reader.incrementState(); - case 10: + case 9: partsBytes = reader.readByteArray("partsBytes"); if (!reader.isLastRead()) @@ -494,7 +500,7 @@ public void topologyVersion(AffinityTopologyVersion topVer) { reader.incrementState(); - case 11: + case 10: partsToReloadBytes = reader.readByteArray("partsToReloadBytes"); if (!reader.isLastRead()) @@ -502,7 +508,7 @@ public void topologyVersion(AffinityTopologyVersion topVer) { reader.incrementState(); - case 12: + case 11: topVer = reader.readMessage("topVer"); if (!reader.isLastRead()) @@ -520,11 +526,9 @@ public void topologyVersion(AffinityTopologyVersion topVer) { return 46; } - //todo - /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 13; + return 12; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java index 9222251821250..1e5ea142d375d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java @@ -111,6 +111,11 @@ public GridDhtPartitionsSingleMessage(GridDhtPartitionExchangeId exchId, this.compress = compress; } + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + /** * @return {@code True} if sent from client node. */ @@ -142,23 +147,23 @@ public void addLocalPartitionMap(int cacheId, GridDhtPartitionMap locMap, @Nulla } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param cntrMap Partition update counters. */ - public void partitionUpdateCounters(int cacheId, Map> cntrMap) { + public void partitionUpdateCounters(int grpId, Map> cntrMap) { if (partCntrs == null) partCntrs = new HashMap<>(); - partCntrs.put(cacheId, cntrMap); + partCntrs.put(grpId, cntrMap); } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @return Partition update counters. */ - @Override public Map> partitionUpdateCounters(int cacheId) { + @Override public Map> partitionUpdateCounters(int grpId) { if (partCntrs != null) { - Map> res = partCntrs.get(cacheId); + Map> res = partCntrs.get(grpId); return res != null ? res : Collections.>emptyMap(); } @@ -167,35 +172,34 @@ public void partitionUpdateCounters(int cacheId, Map> cn } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param cntrMap Partition history counters. */ - public void partitionHistoryCounters(int cacheId, Map cntrMap) { + public void partitionHistoryCounters(int grpId, Map cntrMap) { if (cntrMap.isEmpty()) return; if (partHistCntrs == null) partHistCntrs = new HashMap<>(); - partHistCntrs.put(cacheId, cntrMap); + partHistCntrs.put(grpId, cntrMap); } /** * @param cntrMap Partition history counters. */ - public void partitionHistoryCounters(Map> cntrMap) { - for (Map.Entry> e : cntrMap.entrySet()) { + void partitionHistoryCounters(Map> cntrMap) { + for (Map.Entry> e : cntrMap.entrySet()) partitionHistoryCounters(e.getKey(), e.getValue()); - } } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @return Partition history counters. */ - public Map partitionHistoryCounters(int cacheId) { + Map partitionHistoryCounters(int grpId) { if (partHistCntrs != null) { - Map res = partHistCntrs.get(cacheId); + Map res = partHistCntrs.get(grpId); return res != null ? res : Collections.emptyMap(); } @@ -351,37 +355,37 @@ public Exception getException() { } switch (writer.state()) { - case 6: + case 5: if (!writer.writeBoolean("client", client)) return false; writer.incrementState(); - case 7: + case 6: if (!writer.writeMap("dupPartsData", dupPartsData, MessageCollectionItemType.INT, MessageCollectionItemType.INT)) return false; writer.incrementState(); - case 8: + case 7: if (!writer.writeByteArray("exBytes", exBytes)) return false; writer.incrementState(); - case 9: + case 8: if (!writer.writeByteArray("partCntrsBytes", partCntrsBytes)) return false; writer.incrementState(); - case 10: + case 9: if (!writer.writeByteArray("partHistCntrsBytes", partHistCntrsBytes)) return false; writer.incrementState(); - case 11: + case 10: if (!writer.writeByteArray("partsBytes", partsBytes)) return false; @@ -403,7 +407,7 @@ public Exception getException() { return false; switch (reader.state()) { - case 6: + case 5: client = reader.readBoolean("client"); if (!reader.isLastRead()) @@ -411,7 +415,7 @@ public Exception getException() { reader.incrementState(); - case 7: + case 6: dupPartsData = reader.readMap("dupPartsData", MessageCollectionItemType.INT, MessageCollectionItemType.INT, false); if (!reader.isLastRead()) @@ -419,7 +423,7 @@ public Exception getException() { reader.incrementState(); - case 8: + case 7: exBytes = reader.readByteArray("exBytes"); if (!reader.isLastRead()) @@ -427,7 +431,7 @@ public Exception getException() { reader.incrementState(); - case 9: + case 8: partCntrsBytes = reader.readByteArray("partCntrsBytes"); if (!reader.isLastRead()) @@ -435,7 +439,7 @@ public Exception getException() { reader.incrementState(); - case 10: + case 9: partHistCntrsBytes = reader.readByteArray("partHistCntrsBytes"); if (!reader.isLastRead()) @@ -443,7 +447,7 @@ public Exception getException() { reader.incrementState(); - case 11: + case 10: partsBytes = reader.readByteArray("partsBytes"); if (!reader.isLastRead()) @@ -461,11 +465,9 @@ public Exception getException() { return 47; } - //todo add ex - /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 12; + return 11; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleRequest.java index b4ce9399ae02b..4b80ee05d00cc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleRequest.java @@ -47,6 +47,11 @@ public GridDhtPartitionsSingleRequest() { super(id, null); } + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + /** {@inheritDoc} */ @Override public Map> partitionUpdateCounters(int cacheId) { return Collections.emptyMap(); @@ -89,7 +94,7 @@ public GridDhtPartitionsSingleRequest() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 6; + return 5; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java index 957f93b0d37a7..82eafc18ce974 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java @@ -23,30 +23,22 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.events.DiscoveryEvent; -import org.apache.ignite.events.Event; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.NodeStoppingException; -import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; -import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener; import org.apache.ignite.internal.processors.affinity.AffinityAssignment; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; -import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException; import org.apache.ignite.internal.processors.cache.GridCachePreloaderAdapter; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentRequest; -import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentResponse; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtFuture; -import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; @@ -61,11 +53,8 @@ import org.apache.ignite.internal.util.typedef.internal.GPC; import org.apache.ignite.internal.util.typedef.internal.LT; import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.lang.IgniteBiInClosure; import org.apache.ignite.lang.IgnitePredicate; -import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; -import org.jsr166.ConcurrentLinkedDeque8; import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST; import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_UNLOADED; @@ -77,7 +66,6 @@ import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.MOVING; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.OWNING; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.RENTING; -import static org.apache.ignite.internal.util.GridConcurrentFactory.newMap; /** * DHT cache preloader. @@ -89,9 +77,6 @@ public class GridDhtPreloader extends GridCachePreloaderAdapter { /** */ private GridDhtPartitionTopology top; - /** Force key futures. */ - private final ConcurrentMap> forceKeyFuts = newMap(); - /** Partition suppliers. */ private GridDhtPartitionSupplier supplier; @@ -113,48 +98,16 @@ public class GridDhtPreloader extends GridCachePreloaderAdapter { /** */ private final AtomicInteger partsEvictOwning = new AtomicInteger(); - /** */ - private volatile boolean stopping; - /** */ private boolean stopped; - /** Discovery listener. */ - private final GridLocalEventListener discoLsnr = new GridLocalEventListener() { - @Override public void onEvent(Event evt) { - if (!enterBusy()) - return; - - DiscoveryEvent e = (DiscoveryEvent)evt; - - try { - ClusterNode loc = cctx.localNode(); - - assert e.type() == EVT_NODE_JOINED || e.type() == EVT_NODE_LEFT || e.type() == EVT_NODE_FAILED; - - final ClusterNode n = e.eventNode(); - - assert !loc.id().equals(n.id()); - - for (GridDhtForceKeysFuture f : forceKeyFuts.values()) - f.onDiscoveryEvent(e); - - assert e.type() != EVT_NODE_JOINED || n.order() > loc.order() : "Node joined with smaller-than-local " + - "order [newOrder=" + n.order() + ", locOrder=" + loc.order() + ']'; - } - finally { - leaveBusy(); - } - } - }; - /** - * @param cctx Cache context. + * @param grp Cache group. */ - public GridDhtPreloader(GridCacheContext cctx) { - super(cctx); + public GridDhtPreloader(CacheGroupContext grp) { + super(grp); - top = cctx.dht().topology(); + top = grp.topology(); startFut = new GridFutureAdapter<>(); } @@ -164,37 +117,10 @@ public GridDhtPreloader(GridCacheContext cctx) { if (log.isDebugEnabled()) log.debug("Starting DHT rebalancer..."); - cctx.io().addHandler(cctx.cacheId(), GridDhtForceKeysRequest.class, - new MessageHandler() { - @Override public void onMessage(ClusterNode node, GridDhtForceKeysRequest msg) { - processForceKeysRequest(node, msg); - } - }); - - cctx.io().addHandler(cctx.cacheId(), GridDhtForceKeysResponse.class, - new MessageHandler() { - @Override public void onMessage(ClusterNode node, GridDhtForceKeysResponse msg) { - processForceKeyResponse(node, msg); - } - }); - - if (!cctx.kernalContext().clientNode()) { - cctx.io().addHandler(cctx.cacheId(), GridDhtAffinityAssignmentRequest.class, - new MessageHandler() { - @Override protected void onMessage(ClusterNode node, GridDhtAffinityAssignmentRequest msg) { - processAffinityAssignmentRequest(node, msg); - } - }); - } - - cctx.shared().affinity().onCacheCreated(cctx); - - supplier = new GridDhtPartitionSupplier(cctx); - demander = new GridDhtPartitionDemander(cctx); + supplier = new GridDhtPartitionSupplier(grp); + demander = new GridDhtPartitionDemander(grp); demander.start(); - - cctx.events().addListener(discoLsnr, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED); } /** {@inheritDoc} */ @@ -213,10 +139,6 @@ public GridDhtPreloader(GridCacheContext cctx) { if (log.isDebugEnabled()) log.debug("DHT rebalancer onKernalStop callback."); - stopping = true; - - cctx.events().removeListener(discoLsnr); - // Acquire write busy lock. busyLock.writeLock().lock(); @@ -227,11 +149,6 @@ public GridDhtPreloader(GridCacheContext cctx) { if (demander != null) demander.stop(); - IgniteCheckedException err = stopError(); - - for (GridDhtForceKeysFuture fut : forceKeyFuts.values()) - fut.onDone(err); - top = null; stopped = true; @@ -266,25 +183,27 @@ private IgniteCheckedException stopError() { /** {@inheritDoc} */ @Override public GridDhtPreloaderAssignments assign(GridDhtPartitionsExchangeFuture exchFut) { // No assignments for disabled preloader. - GridDhtPartitionTopology top = cctx.dht().topology(); + GridDhtPartitionTopology top = grp.topology(); - if (!cctx.rebalanceEnabled() || !cctx.shared().kernalContext().state().active()) + if (!grp.rebalanceEnabled() || !grp.shared().kernalContext().state().active()) return new GridDhtPreloaderAssignments(exchFut, top.topologyVersion()); - int partCnt = cctx.affinity().partitions(); + int partCnt = grp.affinity().partitions(); assert exchFut.forcePreload() || exchFut.dummyReassign() || exchFut.exchangeId().topologyVersion().equals(top.topologyVersion()) : "Topology version mismatch [exchId=" + exchFut.exchangeId() + - ", cache=" + cctx.name() + + ", grp=" + grp.name() + ", topVer=" + top.topologyVersion() + ']'; GridDhtPreloaderAssignments assigns = new GridDhtPreloaderAssignments(exchFut, top.topologyVersion()); AffinityTopologyVersion topVer = assigns.topologyVersion(); + AffinityAssignment aff = grp.affinity().cachedAffinity(topVer); + for (int p = 0; p < partCnt; p++) { - if (cctx.shared().exchange().hasPendingExchange()) { + if (ctx.exchange().hasPendingExchange()) { if (log.isDebugEnabled()) log.debug("Skipping assignments creation, exchange worker has pending assignments: " + exchFut.exchangeId()); @@ -295,7 +214,7 @@ private IgniteCheckedException stopError() { } // If partition belongs to local node. - if (cctx.affinity().partitionLocalNode(p, topVer)) { + if (aff.get(p).contains(ctx.localNode())) { GridDhtLocalPartition part = top.localPartition(p, topVer, true, true); assert part != null; @@ -303,11 +222,11 @@ private IgniteCheckedException stopError() { ClusterNode histSupplier = null; - if (cctx.shared().database().persistenceEnabled()) { - UUID nodeId = exchFut.partitionHistorySupplier(cctx.cacheId(), p); + if (ctx.database().persistenceEnabled()) { + UUID nodeId = exchFut.partitionHistorySupplier(grp.groupId(), p); if (nodeId != null) - histSupplier = cctx.discovery().node(nodeId); + histSupplier = ctx.discovery().node(nodeId); } if (histSupplier != null) { @@ -318,7 +237,7 @@ private IgniteCheckedException stopError() { continue; // For. } - assert cctx.shared().database().persistenceEnabled(); + assert ctx.database().persistenceEnabled(); assert remoteOwners(p, topVer).contains(histSupplier) : remoteOwners(p, topVer); GridDhtPartitionDemandMessage msg = assigns.get(histSupplier); @@ -327,13 +246,13 @@ private IgniteCheckedException stopError() { assigns.put(histSupplier, msg = new GridDhtPartitionDemandMessage( top.updateSequence(), exchFut.exchangeId().topologyVersion(), - cctx.cacheId())); + grp.groupId())); } msg.addPartition(p, true); } else { - if (cctx.shared().database().persistenceEnabled()) { + if (ctx.database().persistenceEnabled()) { if (part.state() == RENTING || part.state() == EVICTED) { try { part.rent(false).get(); @@ -360,13 +279,13 @@ private IgniteCheckedException stopError() { if (picked.isEmpty()) { top.own(part); - if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_PART_DATA_LOST)) { + if (grp.eventRecordable(EVT_CACHE_REBALANCE_PART_DATA_LOST)) { DiscoveryEvent discoEvt = exchFut.discoveryEvent(); - cctx.events().addPreloadEvent(p, - EVT_CACHE_REBALANCE_PART_DATA_LOST, discoEvt.eventNode(), - discoEvt.type(), discoEvt.timestamp()); - } + grp.addRebalanceEvent(p, + EVT_CACHE_REBALANCE_PART_DATA_LOST, discoEvt.eventNode(), + discoEvt.type(), discoEvt.timestamp()); + } if (log.isDebugEnabled()) log.debug("Owning partition as there are no other owners: " + part); @@ -376,12 +295,12 @@ private IgniteCheckedException stopError() { GridDhtPartitionDemandMessage msg = assigns.get(n); - if (msg == null) { - assigns.put(n, msg = new GridDhtPartitionDemandMessage( - top.updateSequence(), - exchFut.exchangeId().topologyVersion(), - cctx.cacheId())); - } + if (msg == null) { + assigns.put(n, msg = new GridDhtPartitionDemandMessage( + top.updateSequence(), + exchFut.exchangeId().topologyVersion(), + grp.groupId())); + } msg.addPartition(p, false); } @@ -403,7 +322,7 @@ private IgniteCheckedException stopError() { * @return Picked owners. */ private Collection pickedOwners(int p, AffinityTopologyVersion topVer) { - Collection affNodes = cctx.affinity().nodesByPartition(p, topVer); + Collection affNodes = grp.affinity().cachedAffinity(topVer).get(p); int affCnt = affNodes.size(); @@ -429,7 +348,7 @@ private Collection pickedOwners(int p, AffinityTopologyVersion topV * @return Nodes owning this partition. */ private Collection remoteOwners(int p, AffinityTopologyVersion topVer) { - return F.view(cctx.dht().topology().owners(p, topVer), F.remoteNodes(cctx.nodeId())); + return F.view(grp.topology().owners(p, topVer), F.remoteNodes(ctx.localNodeId())); } /** {@inheritDoc} */ @@ -468,7 +387,6 @@ private Collection remoteOwners(int p, AffinityTopologyVersion topV /** {@inheritDoc} */ @Override public Runnable addAssignments(GridDhtPreloaderAssignments assignments, boolean forceRebalance, - Collection caches, int cnt, Runnable next, @Nullable GridFutureAdapter forcedRebFut) { @@ -484,12 +402,12 @@ private Collection remoteOwners(int p, AffinityTopologyVersion topV /** {@inheritDoc} */ @Override public IgniteInternalFuture syncFuture() { - return cctx.kernalContext().clientNode() ? startFut : demander.syncFuture(); + return ctx.kernalContext().clientNode() ? startFut : demander.syncFuture(); } /** {@inheritDoc} */ @Override public IgniteInternalFuture rebalanceFuture() { - return cctx.kernalContext().clientNode() ? new GridFinishedFuture<>(true) : demander.rebalanceFuture(); + return ctx.kernalContext().clientNode() ? new GridFinishedFuture<>(true) : demander.rebalanceFuture(); } /** @@ -515,171 +433,6 @@ private void leaveBusy() { busyLock.readLock().unlock(); } - /** - * @param node Node originated request. - * @param msg Force keys message. - */ - private void processForceKeysRequest(final ClusterNode node, final GridDhtForceKeysRequest msg) { - IgniteInternalFuture fut = cctx.mvcc().finishKeys(msg.keys(), msg.cacheId(), msg.topologyVersion()); - - if (fut.isDone()) - processForceKeysRequest0(node, msg); - else - fut.listen(new CI1>() { - @Override public void apply(IgniteInternalFuture t) { - processForceKeysRequest0(node, msg); - } - }); - } - - /** - * @param node Node originated request. - * @param msg Force keys message. - */ - private void processForceKeysRequest0(ClusterNode node, GridDhtForceKeysRequest msg) { - if (!enterBusy()) - return; - - try { - ClusterNode loc = cctx.localNode(); - - GridDhtForceKeysResponse res = new GridDhtForceKeysResponse( - cctx.cacheId(), - msg.futureId(), - msg.miniId(), - cctx.deploymentEnabled()); - - for (KeyCacheObject k : msg.keys()) { - int p = cctx.affinity().partition(k); - - GridDhtLocalPartition locPart = top.localPartition(p, AffinityTopologyVersion.NONE, false); - - // If this node is no longer an owner. - if (locPart == null && !top.owners(p).contains(loc)) { - res.addMissed(k); - - continue; - } - - GridCacheEntryEx entry = null; - - while (true) { - try { - entry = cctx.dht().entryEx(k); - - entry.unswap(); - - GridCacheEntryInfo info = entry.info(); - - if (info == null) { - assert entry.obsolete() : entry; - - continue; - } - - if (!info.isNew()) - res.addInfo(info); - - cctx.evicts().touch(entry, msg.topologyVersion()); - - break; - } - catch (GridCacheEntryRemovedException ignore) { - if (log.isDebugEnabled()) - log.debug("Got removed entry: " + k); - } - catch (GridDhtInvalidPartitionException ignore) { - if (log.isDebugEnabled()) - log.debug("Local node is no longer an owner: " + p); - - res.addMissed(k); - - break; - } - } - } - - if (log.isDebugEnabled()) - log.debug("Sending force key response [node=" + node.id() + ", res=" + res + ']'); - - cctx.io().send(node, res, cctx.ioPolicy()); - } - catch (ClusterTopologyCheckedException ignore) { - if (log.isDebugEnabled()) - log.debug("Received force key request form failed node (will ignore) [nodeId=" + node.id() + - ", req=" + msg + ']'); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to reply to force key request [nodeId=" + node.id() + ", req=" + msg + ']', e); - } - finally { - leaveBusy(); - } - } - - /** - * @param node Node. - * @param msg Message. - */ - private void processForceKeyResponse(ClusterNode node, GridDhtForceKeysResponse msg) { - if (!enterBusy()) - return; - - try { - GridDhtForceKeysFuture f = forceKeyFuts.get(msg.futureId()); - - if (f != null) - f.onResult(msg); - else if (log.isDebugEnabled()) - log.debug("Receive force key response for unknown future (is it duplicate?) [nodeId=" + node.id() + - ", res=" + msg + ']'); - } - finally { - leaveBusy(); - } - } - - /** - * @param node Node. - * @param req Request. - */ - private void processAffinityAssignmentRequest(final ClusterNode node, - final GridDhtAffinityAssignmentRequest req) { - final AffinityTopologyVersion topVer = req.topologyVersion(); - - if (log.isDebugEnabled()) - log.debug("Processing affinity assignment request [node=" + node + ", req=" + req + ']'); - - cctx.affinity().affinityReadyFuture(req.topologyVersion()).listen(new CI1>() { - @Override public void apply(IgniteInternalFuture fut) { - if (log.isDebugEnabled()) - log.debug("Affinity is ready for topology version, will send response [topVer=" + topVer + - ", node=" + node + ']'); - - AffinityAssignment assignment = cctx.affinity().assignment(topVer); - - GridDhtAffinityAssignmentResponse res = new GridDhtAffinityAssignmentResponse( - req.futureId(), - cctx.cacheId(), - topVer, - assignment.assignment()); - - if (cctx.affinity().affinityCache().centralizedAffinityFunction()) { - assert assignment.idealAssignment() != null; - - res.idealAffinityAssignment(assignment.idealAssignment()); - } - - try { - cctx.io().send(node, res, AFFINITY_POOL); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to send affinity assignment response to remote node [node=" + node + ']', e); - } - } - }); - } - /** * Resends partitions on partition evict within configured timeout. * @@ -693,11 +446,11 @@ public void onPartitionEvicted(GridDhtLocalPartition part, boolean updateSeq) { try { top.onEvicted(part, updateSeq); - if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_PART_UNLOADED)) - cctx.events().addUnloadEvent(part.id()); + if (grp.eventRecordable(EVT_CACHE_REBALANCE_PART_UNLOADED)) + grp.addUnloadEvent(part.id()); if (updateSeq) - cctx.shared().exchange().scheduleResendPartitions(); + ctx.exchange().scheduleResendPartitions(); } finally { leaveBusy(); @@ -706,7 +459,7 @@ public void onPartitionEvicted(GridDhtLocalPartition part, boolean updateSeq) { /** {@inheritDoc} */ @Override public boolean needForceKeys() { - if (cctx.rebalanceEnabled()) { + if (grp.rebalanceEnabled()) { IgniteInternalFuture rebalanceFut = rebalanceFuture(); if (rebalanceFut.isDone() && Boolean.TRUE.equals(rebalanceFut.result())) @@ -717,12 +470,13 @@ public void onPartitionEvicted(GridDhtLocalPartition part, boolean updateSeq) { } /** {@inheritDoc} */ - @Override public IgniteInternalFuture request(GridNearAtomicAbstractUpdateRequest req, + @Override public GridDhtFuture request(GridCacheContext cctx, + GridNearAtomicAbstractUpdateRequest req, AffinityTopologyVersion topVer) { if (!needForceKeys()) return null; - return request0(req.keys(), topVer); + return request0(cctx, req.keys(), topVer); } /** @@ -730,21 +484,27 @@ public void onPartitionEvicted(GridDhtLocalPartition part, boolean updateSeq) { * @return Future for request. */ @SuppressWarnings({"unchecked", "RedundantCast"}) - @Override public GridDhtFuture request(Collection keys, AffinityTopologyVersion topVer) { + @Override public GridDhtFuture request(GridCacheContext cctx, + Collection keys, + AffinityTopologyVersion topVer) { if (!needForceKeys()) return null; - return request0(keys, topVer); + return request0(cctx, keys, topVer); } /** + * @param cctx Cache context. * @param keys Keys to request. * @param topVer Topology version. * @return Future for request. */ @SuppressWarnings({"unchecked", "RedundantCast"}) - private GridDhtFuture request0(Collection keys, AffinityTopologyVersion topVer) { - final GridDhtForceKeysFuture fut = new GridDhtForceKeysFuture<>(cctx, topVer, keys, this); + private GridDhtFuture request0(GridCacheContext cctx, Collection keys, AffinityTopologyVersion topVer) { + if (cctx.isNear()) + cctx = cctx.near().dht().context(); + + final GridDhtForceKeysFuture fut = new GridDhtForceKeysFuture<>(cctx, topVer, keys); IgniteInternalFuture topReadyFut = cctx.affinity().affinityReadyFuturex(topVer); @@ -754,7 +514,7 @@ private GridDhtFuture request0(Collection keys, Affinity if (topReadyFut == null) startFut.listen(new CI1>() { @Override public void apply(IgniteInternalFuture syncFut) { - cctx.kernalContext().closure().runLocalSafe( + ctx.kernalContext().closure().runLocalSafe( new GridPlainRunnable() { @Override public void run() { fut.init(); @@ -791,46 +551,19 @@ private GridDhtFuture request0(Collection keys, Affinity demandLock.writeLock().lock(); try { - cctx.deploy().unwind(cctx); + grp.unwindUndeploys(); } finally { demandLock.writeLock().unlock(); } } - /** - * Adds future to future map. - * - * @param fut Future to add. - * @return {@code False} if node cache is stopping and future was completed with error. - */ - boolean addFuture(GridDhtForceKeysFuture fut) { - forceKeyFuts.put(fut.futureId(), fut); - - if (stopping) { - fut.onDone(stopError()); - - return false; - } - - return true; - } - - /** - * Removes future from future map. - * - * @param fut Future to remove. - */ - void remoteFuture(GridDhtForceKeysFuture fut) { - forceKeyFuts.remove(fut.futureId(), fut); - } - /** {@inheritDoc} */ @Override public void evictPartitionAsync(GridDhtLocalPartition part) { partsToEvict.putIfAbsent(part.id(), part); if (partsEvictOwning.get() == 0 && partsEvictOwning.compareAndSet(0, 1)) { - cctx.closures().callLocalSafe(new GPC() { + ctx.kernalContext().closure().callLocalSafe(new GPC() { @Override public Boolean call() { boolean locked = true; @@ -851,7 +584,7 @@ void remoteFuture(GridDhtForceKeysFuture fut) { partsToEvict.put(part.id(), part); } catch (Throwable ex) { - if (cctx.kernalContext().isStopping()) { + if (ctx.kernalContext().isStopping()) { LT.warn(log, ex, "Partition eviction failed (current node is stopping).", false, true); @@ -886,44 +619,6 @@ void remoteFuture(GridDhtForceKeysFuture fut) { /** {@inheritDoc} */ @Override public void dumpDebugInfo() { - if (!forceKeyFuts.isEmpty()) { - U.warn(log, "Pending force key futures [cache=" + cctx.name() + "]:"); - - for (GridDhtForceKeysFuture fut : forceKeyFuts.values()) - U.warn(log, ">>> " + fut); - } - supplier.dumpDebugInfo(); } - - /** - * - */ - private abstract class MessageHandler implements IgniteBiInClosure { - /** */ - private static final long serialVersionUID = 0L; - - /** {@inheritDoc} */ - @Override public void apply(UUID nodeId, M msg) { - ClusterNode node = cctx.node(nodeId); - - if (node == null) { - if (log.isDebugEnabled()) - log.debug("Received message from failed node [node=" + nodeId + ", msg=" + msg + ']'); - - return; - } - - if (log.isDebugEnabled()) - log.debug("Received message from node [node=" + nodeId + ", msg=" + msg + ']'); - - onMessage(node, msg); - } - - /** - * @param node Node. - * @param msg Message. - */ - protected abstract void onMessage(ClusterNode node, M msg); - } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java index 2d5c8a52da195..e6c5c10b3c4ff 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java @@ -103,7 +103,7 @@ public GridNearAtomicCache(GridCacheContext ctx) { @Override public void start() throws IgniteCheckedException { super.start(); - ctx.io().addHandler(ctx.cacheId(), GridNearGetResponse.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridNearGetResponse res) { processGetResponse(nodeId, res); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java index f8240f3d634c1..5b53935527a6b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java @@ -86,11 +86,23 @@ protected GridNearCacheAdapter() { * @param ctx Context. */ protected GridNearCacheAdapter(GridCacheContext ctx) { - super(ctx, ctx.config().getNearConfiguration().getNearStartSize()); + super(ctx); } /** {@inheritDoc} */ - @Override protected GridCacheMapEntryFactory entryFactory() { + @Override public void start() throws IgniteCheckedException { + if (map == null) { + map = new GridCacheLocalConcurrentMap( + ctx, + entryFactory(), + ctx.config().getNearConfiguration().getNearStartSize()); + } + } + + /** + * @return Entry factory. + */ + private GridCacheMapEntryFactory entryFactory() { return new GridCacheMapEntryFactory() { @Override public GridCacheMapEntry create( GridCacheContext ctx, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java index 757bfbd39e71e..6092511ab170c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java @@ -32,7 +32,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; @@ -50,7 +50,7 @@ /** * Get request. */ -public class GridNearGetRequest extends GridCacheMessage implements GridCacheDeployable, +public class GridNearGetRequest extends GridCacheIdMessage implements GridCacheDeployable, GridCacheVersionable { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java index 50af754c0b614..b4e4424862c54 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java @@ -28,7 +28,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.processors.cache.version.GridCacheVersionable; @@ -45,7 +45,7 @@ /** * Get response. */ -public class GridNearGetResponse extends GridCacheMessage implements GridCacheDeployable, +public class GridNearGetResponse extends GridCacheIdMessage implements GridCacheDeployable, GridCacheVersionable { /** */ private static final long serialVersionUID = 0L; 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 f4ce1ac2c938a..edddf7dd78a6b 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 @@ -58,6 +58,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.IgniteInClosure; import org.apache.ignite.transactions.TransactionDeadlockException; import org.apache.ignite.transactions.TransactionTimeoutException; import org.jetbrains.annotations.Nullable; @@ -159,12 +160,20 @@ void onError(Throwable e, boolean discoThread) { if (e instanceof IgniteTxRollbackCheckedException) { if (marked) { - try { - tx.rollback(); - } - catch (IgniteCheckedException ex) { - U.error(log, "Failed to automatically rollback transaction: " + tx, ex); - } + tx.rollbackAsync().listen(new IgniteInClosure>() { + @Override public void apply(IgniteInternalFuture fut) { + try { + fut.get(); + } + catch (IgniteCheckedException e) { + U.error(log, "Failed to automatically rollback transaction: " + tx, e); + } + + onComplete(); + } + }); + + return; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java index 0faa8ec1c57e3..00ff4bb60bf95 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java @@ -23,7 +23,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.typedef.internal.S; @@ -35,7 +35,7 @@ /** * */ -public class GridNearSingleGetRequest extends GridCacheMessage implements GridCacheDeployable { +public class GridNearSingleGetRequest extends GridCacheIdMessage implements GridCacheDeployable { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java index 554fca1a7e69f..2cb75c253e290 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java @@ -25,7 +25,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; @@ -37,7 +37,7 @@ /** * */ -public class GridNearSingleGetResponse extends GridCacheMessage implements GridCacheDeployable { +public class GridNearSingleGetResponse extends GridCacheIdMessage implements GridCacheDeployable { /** */ private static final long serialVersionUID = 0L; @@ -115,7 +115,7 @@ public void error(IgniteCheckedException err) { * @return Topology version. */ @Override public AffinityTopologyVersion topologyVersion() { - return topVer; + return topVer != null ? topVer : super.topologyVersion(); } /** 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 cc90be043c4c3..a691cbc0f4f43 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 @@ -87,13 +87,13 @@ public GridNearTransactionalCache(GridCacheContext ctx) { @Override public void start() throws IgniteCheckedException { super.start(); - ctx.io().addHandler(ctx.cacheId(), GridNearGetResponse.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridNearGetResponse res) { processGetResponse(nodeId, res); } }); - ctx.io().addHandler(ctx.cacheId(), GridNearLockResponse.class, new CI2() { + ctx.io().addCacheHandler(ctx.cacheId(), GridNearLockResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridNearLockResponse res) { processLockResponse(nodeId, res); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishResponse.java index e3dcbf832bd14..a1a2b5712fcdd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishResponse.java @@ -133,19 +133,19 @@ public long threadId() { } switch (writer.state()) { - case 7: + case 6: if (!writer.writeByteArray("errBytes", errBytes)) return false; writer.incrementState(); - case 8: + case 7: if (!writer.writeInt("miniId", miniId)) return false; writer.incrementState(); - case 9: + case 8: if (!writer.writeLong("nearThreadId", nearThreadId)) return false; @@ -167,7 +167,7 @@ public long threadId() { return false; switch (reader.state()) { - case 7: + case 6: errBytes = reader.readByteArray("errBytes"); if (!reader.isLastRead()) @@ -175,7 +175,7 @@ public long threadId() { reader.incrementState(); - case 8: + case 7: miniId = reader.readInt("miniId"); if (!reader.isLastRead()) @@ -183,7 +183,7 @@ public long threadId() { reader.incrementState(); - case 9: + case 8: nearThreadId = reader.readLong("nearThreadId"); if (!reader.isLastRead()) @@ -203,7 +203,7 @@ public long threadId() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 10; + return 9; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java index 8b538ee3dafc2..69d1260410f33 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java @@ -30,6 +30,7 @@ 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.GridCacheLocalConcurrentMap; import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory; import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate; @@ -65,9 +66,15 @@ public GridLocalCache() { * @param ctx Cache registry. */ public GridLocalCache(GridCacheContext ctx) { - super(ctx, DFLT_START_CACHE_SIZE); + super(ctx); - preldr = new GridCachePreloaderAdapter(ctx); + preldr = new GridCachePreloaderAdapter(ctx.group()); + } + + /** {@inheritDoc} */ + @Override public void start() throws IgniteCheckedException { + if (map == null) + map = new GridCacheLocalConcurrentMap(ctx, entryFactory(), DFLT_START_CACHE_SIZE); } /** {@inheritDoc} */ @@ -80,8 +87,10 @@ public GridLocalCache(GridCacheContext ctx) { return preldr; } - /** {@inheritDoc} */ - @Override protected GridCacheMapEntryFactory entryFactory() { + /** + * @return Entry factory. + */ + private GridCacheMapEntryFactory entryFactory() { return new GridCacheMapEntryFactory() { @Override public GridCacheMapEntry create( GridCacheContext ctx, @@ -97,7 +106,7 @@ public GridLocalCache(GridCacheContext ctx) { * @param key Key of entry. * @return Cache entry. */ - @Nullable GridLocalCacheEntry peekExx(KeyCacheObject key) { + @Nullable private GridLocalCacheEntry peekExx(KeyCacheObject key) { return (GridLocalCacheEntry)peekEx(key); } @@ -215,7 +224,7 @@ void onFutureDone(GridLocalLockFuture fut) { modes.backup = true; if (modes.offheap) - return ctx.offheap().entriesCount(); + return ctx.offheap().cacheEntriesCount(ctx.cacheId()); else if (modes.heap) return size(); else diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java index 56041eec9b3b3..384cd41cbc487 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java @@ -104,7 +104,7 @@ public GridLocalAtomicCache() { public GridLocalAtomicCache(GridCacheContext ctx) { super(ctx); - preldr = new GridCachePreloaderAdapter(ctx); + preldr = new GridCachePreloaderAdapter(ctx.group()); } /** {@inheritDoc} */ @@ -405,7 +405,7 @@ private Map getAllInternal(@Nullable Collection keys, boolean skipEntry = readNoEntry; if (readNoEntry) { - CacheDataRow row = ctx.offheap().read(cacheKey); + CacheDataRow row = ctx.offheap().read(ctx, cacheKey); if (row != null) { long expireTime = row.expireTime(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java index 06a3416e4812b..b112e1d3eb3b4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java @@ -104,7 +104,7 @@ public class GridCacheDistributedQueryManager extends GridCacheQueryManage assert cctx.config().getCacheMode() != LOCAL; - cctx.io().addHandler(cctx.cacheId(), GridCacheQueryRequest.class, new CI2() { + cctx.io().addCacheHandler(cctx.cacheId(), GridCacheQueryRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheQueryRequest req) { processQueryRequest(nodeId, req); } @@ -560,11 +560,11 @@ else if (!cancelled.contains(res.requestId())) final Object topic = topic(cctx.nodeId(), req.id()); - cctx.io().addOrderedHandler(topic, resHnd); + cctx.io().addOrderedCacheHandler(topic, resHnd); fut.listen(new CI1>() { @Override public void apply(IgniteInternalFuture fut) { - cctx.io().removeOrderedHandler(topic); + cctx.io().removeOrderedHandler(false, topic); } }); @@ -744,11 +744,11 @@ else if (!cancelled.contains(res.requestId())) final Object topic = topic(cctx.nodeId(), req.id()); - cctx.io().addOrderedHandler(topic, resHnd); + cctx.io().addOrderedCacheHandler(topic, resHnd); fut.listen(new CI1>() { @Override public void apply(IgniteInternalFuture fut) { - cctx.io().removeOrderedHandler(topic); + cctx.io().removeOrderedHandler(false, topic); } }); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java index 07545a588afc1..0c264dbd5ba59 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java @@ -863,12 +863,12 @@ private GridCloseableIterator> scanIterator(final GridCacheQ locPart = locPart0; - it = cctx.offheap().iterator(part); + it = cctx.offheap().cachePartitionIterator(cctx.cacheId(), part); } else { locPart = null; - it = cctx.offheap().iterator(true, backups, topVer); + it = cctx.offheap().cacheIterator(cctx.cacheId(), true, backups, topVer); } return new PeekValueExpiryAwareIterator(it, plc, topVer, keyValFilter, qry.keepBinary(), locNode) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java index 00ddff8acf426..9dc7817889806 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java @@ -25,6 +25,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -47,7 +48,7 @@ /** * Query request. */ -public class GridCacheQueryRequest extends GridCacheMessage implements GridCacheDeployable { +public class GridCacheQueryRequest extends GridCacheIdMessage implements GridCacheDeployable { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java index 4d8e6581712b7..521aacf76b9c4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java @@ -29,7 +29,7 @@ import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.query.GridQueryFieldMetadata; @@ -46,7 +46,7 @@ /** * Query request. */ -public class GridCacheQueryResponse extends GridCacheMessage implements GridCacheDeployable { +public class GridCacheQueryResponse extends GridCacheIdMessage implements GridCacheDeployable { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryBatchAck.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryBatchAck.java index 76147eecfab72..ef0157ee70caa 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryBatchAck.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryBatchAck.java @@ -21,7 +21,7 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.internal.GridDirectMap; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType; @@ -31,7 +31,7 @@ /** * Batch acknowledgement. */ -public class CacheContinuousQueryBatchAck extends GridCacheMessage { +public class CacheContinuousQueryBatchAck extends GridCacheIdMessage { /** */ private static final long serialVersionUID = 0L; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBuffer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBuffer.java index 336f6503d9093..7a7c04519238c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBuffer.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBuffer.java @@ -155,9 +155,12 @@ private Object process0(long cntr, CacheContinuousQueryEntry entry, boolean back batch = initBatch(entry.topologyVersion()); if (batch == null || cntr < batch.startCntr) { - if (backup) + if (backup) { backupQ.add(entry); + return null; + } + return entry; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java index e5347c845e3a6..2b696a5755faf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java @@ -487,6 +487,70 @@ public void keepBinary(boolean keepBinary) { onEntryUpdated(evt, primary, false, null); } + @Override public CounterSkipContext skipUpdateCounter(final GridCacheContext cctx, + @Nullable CounterSkipContext skipCtx, + int part, + long cntr, + AffinityTopologyVersion topVer, + boolean primary) { + if (skipCtx == null) + skipCtx = new CounterSkipContext(part, cntr, topVer); + + if (loc) { + assert !locCache; + + final Collection> evts = handleEvent(ctx, skipCtx.entry()); + + if (!evts.isEmpty()) { + if (asyncCb) { + ctx.asyncCallbackPool().execute(new Runnable() { + @Override public void run() { + locLsnr.onUpdated(evts); + } + }, part); + } + else + skipCtx.addProcessClosure(new Runnable() { + @Override public void run() { + locLsnr.onUpdated(evts); + } + }); + } + + return skipCtx; + } + + CacheContinuousQueryEventBuffer buf = partitionBuffer(cctx, part); + + final Object entryOrList = buf.processEntry(skipCtx.entry(), !primary); + + if (entryOrList != null) { + skipCtx.addProcessClosure(new Runnable() { + @Override public void run() { + try { + ctx.continuous().addNotification(nodeId, + routineId, + entryOrList, + topic, + false, + true); + } + catch (ClusterTopologyCheckedException ex) { + if (log.isDebugEnabled()) + log.debug("Failed to send event notification to node, node left cluster " + + "[node=" + nodeId + ", err=" + ex + ']'); + } + catch (IgniteCheckedException ex) { + U.error(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY), + "Failed to send event notification to node: " + nodeId, ex); + } + } + }); + } + + return skipCtx; + } + @Override public void onPartitionEvicted(int part) { entryBufs.remove(part); } @@ -1011,7 +1075,7 @@ private void sendBackupAcknowledge(final IgniteBiTuple, Set evt, boolean primary, */ public void skipUpdateEvent(CacheContinuousQueryEvent evt, AffinityTopologyVersion topVer, boolean primary); + /** + * For cache updates in shared cache group need notify others caches CQ listeners + * that generated counter should be skipped. + * + * @param cctx Cache context. + * @param skipCtx Context. + * @param part Partition. + * @param cntr Counter to skip. + * @param topVer Topology version. + * @return Context. + */ + @Nullable public CounterSkipContext skipUpdateCounter( + GridCacheContext cctx, + @Nullable CounterSkipContext skipCtx, + int part, + long cntr, + AffinityTopologyVersion topVer, + boolean primary); + /** * @param part Partition. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java index 1a655e9ce2e9f..f264056934ce5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java @@ -127,7 +127,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter { topicPrefix = "CONTINUOUS_QUERY" + (cctx.name() == null ? "" : "_" + cctx.name()); if (cctx.affinityNode()) { - cctx.io().addHandler(cctx.cacheId(), CacheContinuousQueryBatchAck.class, + cctx.io().addCacheHandler(cctx.cacheId(), CacheContinuousQueryBatchAck.class, new CI2() { @Override public void apply(UUID uuid, CacheContinuousQueryBatchAck msg) { CacheContinuousQueryListener lsnr = lsnrs.get(msg.routineId()); @@ -175,7 +175,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter { * @param primary Primary. * @param topVer Topology version. */ - public void skipUpdateEvent(Map lsnrs, + private void skipUpdateEvent(Map lsnrs, KeyCacheObject key, int partId, long updCntr, @@ -203,6 +203,24 @@ public void skipUpdateEvent(Map lsnrs, } } + /** + * @param skipCtx Context. + * @param part Partition number. + * @param cntr Update counter. + * @param topVer Topology version. + * @return Context. + */ + @Nullable public CounterSkipContext skipUpdateCounter(@Nullable CounterSkipContext skipCtx, + int part, + long cntr, + AffinityTopologyVersion topVer, + boolean primary) { + for (CacheContinuousQueryListener lsnr : lsnrs.values()) + skipCtx = lsnr.skipUpdateCounter(cctx, skipCtx, part, cntr, topVer, primary); + + return skipCtx; + } + /** * @param internal Internal entry flag (internal key or not user cache). * @param preload Whether update happened during preloading. @@ -633,7 +651,7 @@ private UUID executeQuery0(CacheEntryUpdatedListener locLsnr, hnd.localCache(cctx.isLocal()); IgnitePredicate pred = (loc || cctx.config().getCacheMode() == CacheMode.LOCAL) ? - F.nodeForNodeId(cctx.localNodeId()) : cctx.config().getNodeFilter(); + F.nodeForNodeId(cctx.localNodeId()) : cctx.group().nodeFilter(); assert pred != null : cctx.config(); @@ -658,7 +676,10 @@ private UUID executeQuery0(CacheEntryUpdatedListener locLsnr, } if (notifyExisting) { - final Iterator it = cctx.offheap().iterator(true, true, AffinityTopologyVersion.NONE); + final Iterator it = cctx.offheap().cacheIterator(cctx.cacheId(), + true, + true, + AffinityTopologyVersion.NONE); locLsnr.onUpdated(new Iterable() { @Override public Iterator iterator() { @@ -807,16 +828,24 @@ GridContinuousHandler.RegisterStatus registerListener(UUID lsnrId, intLsnrCnt.incrementAndGet(); } else { - added = lsnrs.putIfAbsent(lsnrId, lsnr) == null; + synchronized (this) { + if (lsnrCnt.get() == 0) { + if (cctx.group().sharedGroup() && !cctx.isLocal()) + cctx.group().addCacheWithContinuousQuery(cctx); + } - if (added) { - lsnrCnt.incrementAndGet(); + added = lsnrs.putIfAbsent(lsnrId, lsnr) == null; - lsnr.onExecution(); + if (added) + lsnrCnt.incrementAndGet(); } + + if (added) + lsnr.onExecution(); } - return added ? GridContinuousHandler.RegisterStatus.REGISTERED : GridContinuousHandler.RegisterStatus.NOT_REGISTERED; + return added ? GridContinuousHandler.RegisterStatus.REGISTERED : + GridContinuousHandler.RegisterStatus.NOT_REGISTERED; } /** @@ -834,11 +863,17 @@ void unregisterListener(boolean internal, UUID id) { } } else { - if ((lsnr = lsnrs.remove(id)) != null) { - lsnrCnt.decrementAndGet(); + synchronized (this) { + if ((lsnr = lsnrs.remove(id)) != null) { + int cnt = lsnrCnt.decrementAndGet(); - lsnr.onUnregister(); + if (cctx.group().sharedGroup() && cnt == 0 && !cctx.isLocal()) + cctx.group().removeCacheWithContinuousQuery(cctx); + } } + + if (lsnr != null) + lsnr.onUnregister(); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java new file mode 100644 index 0000000000000..23702bc9c98b3 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java @@ -0,0 +1,78 @@ +/* + * 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.query.continuous; + +import java.util.ArrayList; +import java.util.List; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class CounterSkipContext { + /** */ + private final CacheContinuousQueryEntry entry; + + /** */ + private List procC; + + /** + * @param part Partition. + * @param cntr Filtered counter. + * @param topVer Topology version. + */ + CounterSkipContext(int part, long cntr, AffinityTopologyVersion topVer) { + entry = new CacheContinuousQueryEntry(0, + null, + null, + null, + null, + false, + part, + cntr, + topVer, + (byte)0); + + entry.markFiltered(); + } + + /** + * @return Entry for filtered counter. + */ + CacheContinuousQueryEntry entry() { + return entry; + } + + /** + * @return Entries + */ + @Nullable public List processClosures() { + return procC; + } + + /** + * @param c Closure send + */ + void addProcessClosure(Runnable c) { + if (procC == null) + procC = new ArrayList<>(); + + procC.add(c); + } +} 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 5cba0cf7212d3..96af425932a55 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 @@ -1480,7 +1480,7 @@ else if (txEntry.hasOldValue()) if (modified) cacheVal = cacheCtx.toCacheObject(cacheCtx.unwrapTemporary(val)); - GridCacheOperation op = modified ? (val == null ? DELETE : UPDATE) : NOOP; + GridCacheOperation op = modified ? (cacheVal == null ? DELETE : UPDATE) : NOOP; if (op == NOOP) { ExpiryPolicy expiry = cacheCtx.expiryForTxEntry(txEntry); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java index 163ed992474a8..30aa335f4af95 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java @@ -565,7 +565,9 @@ public GridCacheEntryEx cached() { */ public void cached(GridCacheEntryEx entry) { assert entry == null || entry.context() == ctx : "Invalid entry assigned to tx entry [txEntry=" + this + - ", entry=" + entry + ", ctxNear=" + ctx.isNear() + ", ctxDht=" + ctx.isDht() + ']'; + ", entry=" + entry + + ", ctxNear=" + ctx.isNear() + + ", ctxDht=" + ctx.isDht() + ']'; this.entry = entry; } 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 a591517edda2e..ba3b2b6513eae 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 @@ -136,68 +136,68 @@ public IgniteTxHandler(GridCacheSharedContext ctx) { txPrepareMsgLog = ctx.logger(CU.TX_MSG_PREPARE_LOG_CATEGORY); txFinishMsgLog = ctx.logger(CU.TX_MSG_FINISH_LOG_CATEGORY); - ctx.io().addHandler(0, GridNearTxPrepareRequest.class, new CI2() { + ctx.io().addCacheHandler(0, GridNearTxPrepareRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheMessage msg) { processNearTxPrepareRequest(nodeId, (GridNearTxPrepareRequest)msg); } }); - ctx.io().addHandler(0, GridNearTxPrepareResponse.class, new CI2() { + ctx.io().addCacheHandler(0, GridNearTxPrepareResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheMessage msg) { processNearTxPrepareResponse(nodeId, (GridNearTxPrepareResponse)msg); } }); - ctx.io().addHandler(0, GridNearTxFinishRequest.class, new CI2() { + ctx.io().addCacheHandler(0, GridNearTxFinishRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheMessage msg) { processNearTxFinishRequest(nodeId, (GridNearTxFinishRequest)msg); } }); - ctx.io().addHandler(0, GridNearTxFinishResponse.class, new CI2() { + ctx.io().addCacheHandler(0, GridNearTxFinishResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheMessage msg) { processNearTxFinishResponse(nodeId, (GridNearTxFinishResponse)msg); } }); - ctx.io().addHandler(0, GridDhtTxPrepareRequest.class, new CI2() { + ctx.io().addCacheHandler(0, GridDhtTxPrepareRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheMessage msg) { processDhtTxPrepareRequest(nodeId, (GridDhtTxPrepareRequest)msg); } }); - ctx.io().addHandler(0, GridDhtTxPrepareResponse.class, new CI2() { + ctx.io().addCacheHandler(0, GridDhtTxPrepareResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheMessage msg) { processDhtTxPrepareResponse(nodeId, (GridDhtTxPrepareResponse)msg); } }); - ctx.io().addHandler(0, GridDhtTxFinishRequest.class, new CI2() { + ctx.io().addCacheHandler(0, GridDhtTxFinishRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheMessage msg) { processDhtTxFinishRequest(nodeId, (GridDhtTxFinishRequest)msg); } }); - ctx.io().addHandler(0, GridDhtTxOnePhaseCommitAckRequest.class, new CI2() { + ctx.io().addCacheHandler(0, GridDhtTxOnePhaseCommitAckRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheMessage msg) { processDhtTxOnePhaseCommitAckRequest(nodeId, (GridDhtTxOnePhaseCommitAckRequest)msg); } }); - ctx.io().addHandler(0, GridDhtTxFinishResponse.class, new CI2() { + ctx.io().addCacheHandler(0, GridDhtTxFinishResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheMessage msg) { processDhtTxFinishResponse(nodeId, (GridDhtTxFinishResponse)msg); } }); - ctx.io().addHandler(0, GridCacheTxRecoveryRequest.class, + ctx.io().addCacheHandler(0, GridCacheTxRecoveryRequest.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheTxRecoveryRequest req) { processCheckPreparedTxRequest(nodeId, req); } }); - ctx.io().addHandler(0, GridCacheTxRecoveryResponse.class, + ctx.io().addCacheHandler(0, GridCacheTxRecoveryResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridCacheTxRecoveryResponse res) { processCheckPreparedTxResponse(nodeId, res); @@ -506,8 +506,8 @@ private boolean needRemap(AffinityTopologyVersion expVer, for (IgniteTxEntry e : F.concat(false, req.reads(), req.writes())) { GridCacheContext ctx = e.context(); - Collection cacheNodes0 = ctx.discovery().cacheAffinityNodes(ctx.cacheId(), expVer); - Collection cacheNodes1 = ctx.discovery().cacheAffinityNodes(ctx.cacheId(), curVer); + Collection cacheNodes0 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), expVer); + Collection cacheNodes1 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), curVer); if (!cacheNodes0.equals(cacheNodes1) || ctx.affinity().affinityTopologyVersion().compareTo(curVer) < 0) return true; 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 5a708d7d82e0c..52a0f56773081 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 @@ -660,6 +660,8 @@ else if (conflictCtx.isUseNew()) { txEntry.updateCounter()))); if (op == CREATE || op == UPDATE) { + assert val != null : txEntry; + GridCacheUpdateTxResult updRes = cached.innerSet( this, eventNodeId(), diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java index d1d6afd92e76c..94fe00527a488 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java @@ -70,6 +70,16 @@ public TxLocksRequest(long futId, Set txKeys) { this.txKeys = txKeys; } + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return false; + } + /** * @return Future ID. */ @@ -139,13 +149,13 @@ public Collection txKeys() { } switch (writer.state()) { - case 3: + case 2: if (!writer.writeLong("futId", futId)) return false; writer.incrementState(); - case 4: + case 3: if (!writer.writeObjectArray("txKeysArr", txKeysArr, MessageCollectionItemType.MSG)) return false; @@ -167,7 +177,7 @@ public Collection txKeys() { return false; switch (reader.state()) { - case 3: + case 2: futId = reader.readLong("futId"); if (!reader.isLastRead()) @@ -175,7 +185,7 @@ public Collection txKeys() { reader.incrementState(); - case 4: + case 3: txKeysArr = reader.readObjectArray("txKeysArr", MessageCollectionItemType.MSG, IgniteTxKey.class); if (!reader.isLastRead()) @@ -195,7 +205,7 @@ public Collection txKeys() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 5; + return 4; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java index 7856eaab1918f..a5c8f0917da8c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java @@ -73,6 +73,16 @@ public TxLocksResponse() { // No-op. } + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return false; + } + /** * @return Future ID. */ @@ -229,25 +239,25 @@ public void addKey(IgniteTxKey key) { } switch (writer.state()) { - case 3: + case 2: if (!writer.writeLong("futId", futId)) return false; writer.incrementState(); - case 4: + case 3: if (!writer.writeObjectArray("locksArr", locksArr, MessageCollectionItemType.MSG)) return false; writer.incrementState(); - case 5: + case 4: if (!writer.writeObjectArray("nearTxKeysArr", nearTxKeysArr, MessageCollectionItemType.MSG)) return false; writer.incrementState(); - case 6: + case 5: if (!writer.writeObjectArray("txKeysArr", txKeysArr, MessageCollectionItemType.MSG)) return false; @@ -269,7 +279,7 @@ public void addKey(IgniteTxKey key) { return false; switch (reader.state()) { - case 3: + case 2: futId = reader.readLong("futId"); if (!reader.isLastRead()) @@ -277,7 +287,7 @@ public void addKey(IgniteTxKey key) { reader.incrementState(); - case 4: + case 3: locksArr = reader.readObjectArray("locksArr", MessageCollectionItemType.MSG, TxLockList.class); if (!reader.isLastRead()) @@ -285,7 +295,7 @@ public void addKey(IgniteTxKey key) { reader.incrementState(); - case 5: + case 4: nearTxKeysArr = reader.readObjectArray("nearTxKeysArr", MessageCollectionItemType.MSG, IgniteTxKey.class); if (!reader.isLastRead()) @@ -293,7 +303,7 @@ public void addKey(IgniteTxKey key) { reader.incrementState(); - case 6: + case 5: txKeysArr = reader.readObjectArray("txKeysArr", MessageCollectionItemType.MSG, IgniteTxKey.class); if (!reader.isLastRead()) @@ -313,7 +323,7 @@ public void addKey(IgniteTxKey key) { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 7; + return 6; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java index 05179af9237f4..730fab54d1f1c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java @@ -134,7 +134,7 @@ public GridClusterStateProcessor(GridKernalContext ctx) { cacheProc = ctx.cache(); sharedCtx = cacheProc.context(); - sharedCtx.io().addHandler(0, + sharedCtx.io().addCacheHandler(0, GridChangeGlobalStateMessageResponse.class, new CI2() { @Override public void apply(UUID nodeId, GridChangeGlobalStateMessageResponse msg) { @@ -194,7 +194,7 @@ public GridClusterStateProcessor(GridKernalContext ctx) { @Override public void stop(boolean cancel) throws IgniteCheckedException { super.stop(cancel); - sharedCtx.io().removeHandler(0, GridChangeGlobalStateMessageResponse.class); + sharedCtx.io().removeHandler(false, 0, GridChangeGlobalStateMessageResponse.class); ctx.event().removeLocalEventListener(lsr, EVT_NODE_LEFT, EVT_NODE_FAILED); IgniteCheckedException stopErr = new IgniteInterruptedCheckedException( @@ -452,16 +452,17 @@ private Exception onActivate(ChangeGlobalStateContext cgsCtx) { sharedCtx.database().initDataBase(); + // TODO IGNITE-5075 group descriptors. for (CacheConfiguration cfg : cfgs) { if (CU.isSystemCache(cfg.getName())) if (pageStore != null) - pageStore.initializeForCache(cfg); + pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cfg.getName()).groupDescriptor(), cfg); } for (CacheConfiguration cfg : cfgs) { if (!CU.isSystemCache(cfg.getName())) if (pageStore != null) - pageStore.initializeForCache(cfg); + pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cfg.getName()).groupDescriptor(), cfg); } sharedCtx.database().onActivate(ctx); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 3ff4f936ea901..faf8e1dd5f939 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -1507,7 +1507,7 @@ public IgniteInternalFuture rebuildIndexesFromHash(Collection cacheI * @param desc Type descriptor. * @return Future that will be completed when rebuilding of all indexes is finished. */ - private IgniteInternalFuture rebuildIndexesFromHash(@Nullable final String cacheName, +private IgniteInternalFuture rebuildIndexesFromHash(@Nullable final String cacheName, @Nullable final QueryTypeDescriptorImpl desc) { if (idx == null) return new GridFinishedFuture<>(new IgniteCheckedException("Indexing is disabled.")); @@ -1530,7 +1530,7 @@ private IgniteInternalFuture rebuildIndexesFromHash(@Nullable final Stri fut.onDone(e); } catch (Throwable e) { - U.error(log, "Failed to rebuild indexes for type [cacheName=" + cacheName + + U.error(log, "Failed to rebuild indexes for type [cache=" + cacheName + ", name=" + desc.name() + ']', e); fut.onDone(e); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java index 51648e5e9ec3b..0eac972f02718 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java @@ -17,6 +17,19 @@ package org.apache.ignite.internal.processors.query; +import java.lang.reflect.Method; +import java.math.BigDecimal; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.TimeUnit; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.cache.QueryEntity; @@ -30,32 +43,18 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper; import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; -import org.apache.ignite.internal.processors.query.schema.SchemaOperationException; import org.apache.ignite.internal.processors.query.property.QueryBinaryProperty; import org.apache.ignite.internal.processors.query.property.QueryClassProperty; import org.apache.ignite.internal.processors.query.property.QueryFieldAccessor; import org.apache.ignite.internal.processors.query.property.QueryMethodsAccessor; import org.apache.ignite.internal.processors.query.property.QueryPropertyAccessor; import org.apache.ignite.internal.processors.query.property.QueryReadOnlyMethodsAccessor; +import org.apache.ignite.internal.processors.query.schema.SchemaOperationException; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.A; import org.apache.ignite.internal.util.typedef.internal.U; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - import static org.apache.ignite.IgniteSystemProperties.IGNITE_INDEXING_DISCOVERY_HISTORY_SIZE; import static org.apache.ignite.IgniteSystemProperties.getInteger; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java index 69188c5938f1f..af65de0a4c605 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCachePartitionsTask.java @@ -124,7 +124,7 @@ else if (ca instanceof GridDhtCacheAdapter) for (GridDhtLocalPartition part : locParts) { int p = part.id(); - long sz = part.dataStore().size(); + long sz = part.dataStore().cacheSize(ca.context().cacheId()); // Pass NONE as topology version in order not to wait for topology version. if (part.primary(AffinityTopologyVersion.NONE)) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheAtomicSingleMessageCountSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheAtomicSingleMessageCountSelfTest.java index 5bd53bbfa584e..fdc98ff675e8e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheAtomicSingleMessageCountSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheAtomicSingleMessageCountSelfTest.java @@ -204,7 +204,7 @@ private static class TestCommunicationSpi extends TcpCommunicationSpi { throws IgniteSpiException { if (((GridIoMessage)msg).message() instanceof GridCacheMessage) { - int msgCacheId = ((GridCacheMessage)((GridIoMessage)msg).message()).cacheId(); + int msgCacheId = ((GridCacheIdMessage)((GridIoMessage)msg).message()).cacheId(); if (filterCacheId == null || filterCacheId == msgCacheId) { AtomicInteger cntr = cntMap.get(((GridIoMessage)msg).message().getClass()); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDeferredDeleteQueueTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDeferredDeleteQueueTest.java index 65037d8b299c2..18a35c65ed7a6 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDeferredDeleteQueueTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDeferredDeleteQueueTest.java @@ -116,7 +116,7 @@ private void testQueue(CacheAtomicityMode atomicityMode, boolean nearCache) thro for (GridDhtLocalPartition p : top.currentLocalPartitions()) { Collection rmvQueue = GridTestUtils.getFieldValue(p, "rmvQueue"); - if (!rmvQueue.isEmpty() || p.dataStore().size() != 0) + if (!rmvQueue.isEmpty() || p.dataStore().fullSize() != 0) return false; } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDhtLocalPartitionAfterRemoveSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDhtLocalPartitionAfterRemoveSelfTest.java index c060eb33cbc2c..726365624570d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDhtLocalPartitionAfterRemoveSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDhtLocalPartitionAfterRemoveSelfTest.java @@ -76,7 +76,7 @@ public void testMemoryUsage() throws Exception { cache = grid(g).cache(DEFAULT_CACHE_NAME); for (GridDhtLocalPartition p : dht(cache).topology().localPartitions()) { - int size = p.dataStore().size(); + int size = p.dataStore().fullSize(); assertTrue("Unexpected size: " + size, size <= 32); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java index 99e6afb6c6164..9f4fc8040599b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java @@ -285,30 +285,33 @@ private void checkFullMessage(String cache1, Map dupPartsData, GridDhtPartitionsFullMessage msg) { - Integer cacheId; - Integer dupCacheId; + int cache1Grp = groupIdForCache(ignite(0), cache1); + int cache2Grp = groupIdForCache(ignite(0), cache2); - if (dupPartsData.containsKey(CU.cacheId(cache1))) { - cacheId = CU.cacheId(cache1); - dupCacheId = CU.cacheId(cache2); + Integer grpId; + Integer dupGrpId; + + if (dupPartsData.containsKey(cache1Grp)) { + grpId = cache1Grp; + dupGrpId = cache2Grp; } else { - cacheId = CU.cacheId(cache2); - dupCacheId = CU.cacheId(cache1); + grpId = cache2Grp; + dupGrpId = cache1Grp; } - assertTrue(dupPartsData.containsKey(cacheId)); - assertEquals(dupCacheId, dupPartsData.get(cacheId)); - assertFalse(dupPartsData.containsKey(dupCacheId)); + assertTrue(dupPartsData.containsKey(grpId)); + assertEquals(dupGrpId, dupPartsData.get(grpId)); + assertFalse(dupPartsData.containsKey(dupGrpId)); Map parts = msg.partitions(); - GridDhtPartitionFullMap emptyFullMap = parts.get(cacheId); + GridDhtPartitionFullMap emptyFullMap = parts.get(grpId); for (GridDhtPartitionMap map : emptyFullMap.values()) assertEquals(0, map.map().size()); - GridDhtPartitionFullMap fullMap = parts.get(dupCacheId); + GridDhtPartitionFullMap fullMap = parts.get(dupGrpId); for (GridDhtPartitionMap map : fullMap.values()) assertFalse(map.map().isEmpty()); @@ -325,29 +328,32 @@ private void checkSingleMessage(String cache1, Map dupPartsData, GridDhtPartitionsSingleMessage msg) { - Integer cacheId; - Integer dupCacheId; + int cache1Grp = groupIdForCache(ignite(0), cache1); + int cache2Grp = groupIdForCache(ignite(0), cache2); + + Integer grpId; + Integer dupGrpId; - if (dupPartsData.containsKey(CU.cacheId(cache1))) { - cacheId = CU.cacheId(cache1); - dupCacheId = CU.cacheId(cache2); + if (dupPartsData.containsKey(cache1Grp)) { + grpId = cache1Grp; + dupGrpId = cache2Grp; } else { - cacheId = CU.cacheId(cache2); - dupCacheId = CU.cacheId(cache1); + grpId = cache2Grp; + dupGrpId = cache1Grp; } - assertTrue(dupPartsData.containsKey(cacheId)); - assertEquals(dupCacheId, dupPartsData.get(cacheId)); - assertFalse(dupPartsData.containsKey(dupCacheId)); + assertTrue(dupPartsData.containsKey(grpId)); + assertEquals(dupGrpId, dupPartsData.get(grpId)); + assertFalse(dupPartsData.containsKey(dupGrpId)); Map parts = msg.partitions(); - GridDhtPartitionMap emptyMap = parts.get(cacheId); + GridDhtPartitionMap emptyMap = parts.get(grpId); assertEquals(0, emptyMap.map().size()); - GridDhtPartitionMap map = parts.get(dupCacheId); + GridDhtPartitionMap map = parts.get(dupGrpId); assertFalse(map.map().isEmpty()); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupsMetricsRebalanceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupsMetricsRebalanceTest.java new file mode 100644 index 0000000000000..c15fa5f50df86 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupsMetricsRebalanceTest.java @@ -0,0 +1,140 @@ +/* + * 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 java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMetrics; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.events.Event; +import org.apache.ignite.events.EventType; +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; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class CacheGroupsMetricsRebalanceTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final String CACHE1 = "cache1"; + + /** */ + private static final String CACHE2 = "cache2"; + + /** */ + private static final String GROUP = "group1"; + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); + + CacheConfiguration cfg1 = new CacheConfiguration() + .setName(CACHE1) + .setGroupName(GROUP) + .setCacheMode(CacheMode.PARTITIONED) + .setAtomicityMode(CacheAtomicityMode.ATOMIC) + .setRebalanceMode(CacheRebalanceMode.ASYNC) + .setStatisticsEnabled(true); + + CacheConfiguration cfg2 = new CacheConfiguration(cfg1) + .setName(CACHE2); + + cfg.setCacheConfiguration(cfg1, cfg2); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testRebalance() throws Exception { + Ignite ignite = startGrids(4); + + IgniteCache cache1 = ignite.cache(CACHE1); + IgniteCache cache2 = ignite.cache(CACHE2); + + for (int i = 0; i < 10000; i++) { + cache1.put(i, CACHE1 + "-" + i); + + if (i % 2 == 0) + cache2.put(i, CACHE2 + "-" + i); + } + + final CountDownLatch l1 = new CountDownLatch(1); + final CountDownLatch l2 = new CountDownLatch(1); + + startGrid(4).events().localListen(new IgnitePredicate() { + @Override public boolean apply(Event evt) { + l1.countDown(); + + try { + assertTrue(l2.await(5, TimeUnit.SECONDS)); + } + catch (InterruptedException e) { + throw new AssertionError(); + } + + return false; + } + }, EventType.EVT_CACHE_REBALANCE_STOPPED); + + assertTrue(l1.await(5, TimeUnit.SECONDS)); + + ignite = ignite(4); + + CacheMetrics metrics1 = ignite.cache(CACHE1).localMetrics(); + CacheMetrics metrics2 = ignite.cache(CACHE2).localMetrics(); + + l2.countDown(); + + long rate1 = metrics1.getRebalancingKeysRate(); + long rate2 = metrics2.getRebalancingKeysRate(); + + assertTrue(rate1 > 0); + assertTrue(rate2 > 0); + + // rate1 has to be roughly twice more than rate2. + double ratio = ((double)rate2 / rate1) * 100; + + log.info("Ratio: " + ratio); + + assertTrue(ratio > 40 && ratio < 60); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheOffheapMapEntrySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheOffheapMapEntrySelfTest.java index 1886c76d70712..bdc5507953124 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheOffheapMapEntrySelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheOffheapMapEntrySelfTest.java @@ -22,8 +22,7 @@ import org.apache.ignite.cache.CacheMode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.IgniteKernal; -import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCacheEntry; -import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCacheEntry; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry; import org.apache.ignite.internal.processors.cache.local.GridLocalCacheEntry; @@ -97,9 +96,9 @@ public void testCacheMapEntry() throws Exception { checkCacheMapEntry(TRANSACTIONAL, PARTITIONED, GridNearCacheEntry.class); - checkCacheMapEntry(ATOMIC, REPLICATED, GridDhtAtomicCacheEntry.class); + checkCacheMapEntry(ATOMIC, REPLICATED, GridDhtCacheEntry.class); - checkCacheMapEntry(TRANSACTIONAL, REPLICATED, GridDhtColocatedCacheEntry.class); + checkCacheMapEntry(TRANSACTIONAL, REPLICATED, GridDhtCacheEntry.class); } /** @@ -135,7 +134,7 @@ private void checkCacheMapEntry(CacheAtomicityMode atomicityMode, assertNotNull(entry); - assertEquals(entry.getClass(), entryCls); + assertEquals(entryCls, entry.getClass()); } finally { jcache.destroy(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java index eefdf9d4bf99f..b0d9f0e135359 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java @@ -167,10 +167,16 @@ public void testAddedDeploymentInfo2() throws Exception { } } + /** + * @return Cache context. + */ protected GridCacheContext cacheContext() { return ((IgniteCacheProxy)grid(0).cache(DEFAULT_CACHE_NAME)).context(); } + /** + * @return IO manager. + */ protected GridCacheIoManager cacheIoManager() { return grid(0).context().cache().context().io(); } @@ -182,10 +188,22 @@ public static class TestMessage extends GridCacheMessage implements GridCacheDe /** */ public static final short DIRECT_TYPE = 302; + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return false; + } + + /** {@inheritDoc} */ @Override public short directType() { return DIRECT_TYPE; } + /** {@inheritDoc} */ @Override public byte fieldsCount() { return 3; } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLeakTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLeakTest.java index a13ad6444d31e..cff9745aac91c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLeakTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLeakTest.java @@ -24,6 +24,7 @@ import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.util.typedef.internal.CU; 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; @@ -128,7 +129,7 @@ private void checkLeak(CacheAtomicityMode mode) throws Exception { GridCacheConcurrentMap map = ((IgniteKernal)grid(g)).internalCache(CACHE_NAME).map(); info("Map size for cache [g=" + g + ", size=" + map.internalSize() + - ", pubSize=" + map.publicSize() + ']'); + ", pubSize=" + map.publicSize(CU.cacheId(CACHE_NAME)) + ']'); assertTrue("Wrong map size: " + map.internalSize(), map.internalSize() <= 8192); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOrderedPreloadingSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOrderedPreloadingSelfTest.java index 7562fe5d49028..bc4f2cb722fb7 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOrderedPreloadingSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOrderedPreloadingSelfTest.java @@ -68,8 +68,10 @@ public class GridCacheOrderedPreloadingSelfTest extends GridCommonAbstractTest { /** Caches rebalance finish times. */ private ConcurrentHashMap8> times; + /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTestsStarted(); + times = new ConcurrentHashMap8<>(); for (int i = 0; i < GRID_CNT; i++) @@ -93,8 +95,8 @@ public class GridCacheOrderedPreloadingSelfTest extends GridCommonAbstractTest { Map, int[]> listeners = new HashMap<>(); listeners.put(new IgnitePredicate() { - @Override public boolean apply(CacheRebalancingEvent event) { - times.get(gridIdx(event)).putIfAbsent(event.cacheName(), event.timestamp()); + @Override public boolean apply(CacheRebalancingEvent evt) { + times.get(gridIdx(evt)).putIfAbsent(evt.cacheName(), evt.timestamp()); return true; } }, new int[]{EventType.EVT_CACHE_REBALANCE_STOPPED}); @@ -194,7 +196,11 @@ private void checkPreloadOrder(CacheMode first, CacheMode second) throws Excepti } } - private int gridIdx(Event event) { - return getTestIgniteInstanceIndex((String)event.node().attributes().get(GRID_NAME_ATTR)); + /** + * @param evt Event. + * @return Index event node. + */ + private int gridIdx(Event evt) { + return getTestIgniteInstanceIndex((String)evt.node().attributes().get(GRID_NAME_ATTR)); } } \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManagerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManagerSelfTest.java index 18c0b32f053e1..52f19b78ca65a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManagerSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManagerSelfTest.java @@ -112,7 +112,8 @@ private void checkTtl(CacheMode mode) throws Exception { assertNull(g.cache(DEFAULT_CACHE_NAME).get(key)); if (!g.internalCache(DEFAULT_CACHE_NAME).context().deferredDelete()) - assertNull(g.internalCache(DEFAULT_CACHE_NAME).map().getEntry(g.internalCache(DEFAULT_CACHE_NAME).context().toCacheKeyObject(key))); + assertNull(g.internalCache(DEFAULT_CACHE_NAME).map().getEntry(g.internalCache(DEFAULT_CACHE_NAME).context(), + g.internalCache(DEFAULT_CACHE_NAME).context().toCacheKeyObject(key))); } }); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java new file mode 100644 index 0000000000000..ec96e4d270eef --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java @@ -0,0 +1,3765 @@ +/* + * 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 java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.atomic.AtomicReferenceArray; +import java.util.concurrent.locks.Lock; +import javax.cache.Cache; +import javax.cache.CacheException; +import javax.cache.configuration.Factory; +import javax.cache.event.CacheEntryEvent; +import javax.cache.event.CacheEntryUpdatedListener; +import javax.cache.integration.CacheLoaderException; +import javax.cache.integration.CacheWriterException; +import javax.cache.processor.EntryProcessorException; +import javax.cache.processor.MutableEntry; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.Ignition; +import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheEntryProcessor; +import org.apache.ignite.cache.CacheExistsException; +import org.apache.ignite.cache.CacheInterceptor; +import org.apache.ignite.cache.CacheInterceptorAdapter; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CachePeekMode; +import org.apache.ignite.cache.affinity.Affinity; +import org.apache.ignite.cache.affinity.AffinityKeyMapper; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.ContinuousQuery; +import org.apache.ignite.cache.query.QueryCursor; +import org.apache.ignite.cache.query.ScanQuery; +import org.apache.ignite.cache.store.CacheStore; +import org.apache.ignite.cache.store.CacheStoreAdapter; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.NearCacheConfiguration; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.binary.BinaryMarshaller; +import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; +import org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicyFactory; +import org.apache.ignite.internal.util.lang.GridAbsPredicate; +import org.apache.ignite.internal.util.lang.GridIterator; +import org.apache.ignite.internal.util.lang.GridPlainCallable; +import org.apache.ignite.internal.util.typedef.PA; +import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiPredicate; +import org.apache.ignite.lang.IgniteFuture; +import org.apache.ignite.lang.IgniteInClosure; +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 org.apache.ignite.transactions.Transaction; + +import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheMode.LOCAL; +import static org.apache.ignite.cache.CacheMode.PARTITIONED; +import static org.apache.ignite.cache.CacheMode.REPLICATED; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; +import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; +import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE; + +/** + * + */ +@SuppressWarnings("unchecked") +public class IgniteCacheGroupsTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final String GROUP1 = "grp1"; + + /** */ + private static final String GROUP2 = "grp2"; + + /** */ + private static final String CACHE1 = "cache1"; + + /** */ + private static final String CACHE2 = "cache2"; + + /** */ + private boolean client; + + /** */ + private CacheConfiguration[] ccfgs; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); + + cfg.setClientMode(client); + + if (ccfgs != null) { + cfg.setCacheConfiguration(ccfgs); + + ccfgs = null; + } + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return 10 * 60_000; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + super.afterTest(); + } + + /** + * @throws Exception If failed. + */ + public void testCloseCache1() throws Exception { + startGrid(0); + + client = true; + + Ignite client = startGrid(1); + + IgniteCache c1 = client.createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 0, false)); + + checkCacheGroup(0, GROUP1, true); + checkCacheGroup(0, GROUP1, true); + + checkCache(0, "c1", 10); + checkCache(1, "c1", 10); + + c1.close(); + + checkCacheGroup(0, GROUP1, true); + checkCacheGroup(1, GROUP1, false); + + checkCache(0, "c1", 10); + + assertNotNull(client.cache("c1")); + + checkCacheGroup(0, GROUP1, true); + checkCacheGroup(1, GROUP1, true); + + checkCache(0, "c1", 10); + checkCache(1, "c1", 10); + } + + /** + * @throws Exception If failed. + */ + public void testCreateDestroyCaches1() throws Exception { + createDestroyCaches(1); + } + + /** + * @throws Exception If failed. + */ + public void testCreateDestroyCaches2() throws Exception { + createDestroyCaches(5); + } + + /** + * @throws Exception If failed. + */ + public void testCreateCacheWithSameNameInAnotherGroup() throws Exception { + startGridsMultiThreaded(2); + + final Ignite ignite = ignite(0); + + ignite.createCache(cacheConfiguration(GROUP1, CACHE1, PARTITIONED, ATOMIC, 2, false)); + + GridTestUtils.assertThrows(null, new GridPlainCallable() { + @Override public Void call() throws Exception { + ignite(1).createCache(cacheConfiguration(GROUP2, CACHE1, PARTITIONED, ATOMIC, 2, false)); + return null; + } + }, CacheExistsException.class, "a cache with the same name is already started"); + } + + /** + * @throws Exception If failed. + */ + public void testCreateDestroyCachesAtomicPartitioned() throws Exception { + createDestroyCaches(PARTITIONED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testCreateDestroyCachesTxPartitioned() throws Exception { + createDestroyCaches(PARTITIONED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testCreateDestroyCachesAtomicReplicated() throws Exception { + createDestroyCaches(REPLICATED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testCreateDestroyCachesTxReplicated() throws Exception { + createDestroyCaches(REPLICATED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testScanQueryAtomicPartitioned() throws Exception { + scanQuery(PARTITIONED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testScanQueryTxPartitioned() throws Exception { + scanQuery(PARTITIONED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testScanQueryAtomicReplicated() throws Exception { + scanQuery(REPLICATED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testScanQueryTxReplicated() throws Exception { + scanQuery(REPLICATED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testScanQueryAtomicLocal() throws Exception { + scanQuery(LOCAL, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testScanQueryTxLocal() throws Exception { + scanQuery(LOCAL, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testEntriesTtlAtomicPartitioned() throws Exception { + entriesTtl(PARTITIONED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testEntriesTtlTxPartitioned() throws Exception { + entriesTtl(PARTITIONED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testEntriesTtlAtomicReplicated() throws Exception { + entriesTtl(REPLICATED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testEntriesTtlTxReplicated() throws Exception { + entriesTtl(REPLICATED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testEntriesTtlAtomicLocal() throws Exception { + entriesTtl(LOCAL, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testEntriesTtlTxLocal() throws Exception { + entriesTtl(LOCAL, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testCacheIteratorAtomicPartitioned() throws Exception { + cacheIterator(PARTITIONED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testCacheIteratorTxPartitioned() throws Exception { + cacheIterator(PARTITIONED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testCacheIteratorAtomicReplicated() throws Exception { + cacheIterator(REPLICATED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testCacheIteratorTxReplicated() throws Exception { + cacheIterator(REPLICATED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testCacheIteratorAtomicLocal() throws Exception { + cacheIterator(LOCAL, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testCacheIteratorTxLocal() throws Exception { + cacheIterator(LOCAL, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testScanQueryMultiplePartitionsAtomicPartitioned() throws Exception { + scanQueryMultiplePartitions(PARTITIONED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testScanQueryMultiplePartitionsTxPartitioned() throws Exception { + scanQueryMultiplePartitions(PARTITIONED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testScanQueryMultiplePartitionsAtomicReplicated() throws Exception { + scanQueryMultiplePartitions(REPLICATED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testScanQueryMultiplePartitionsTxReplicated() throws Exception { + scanQueryMultiplePartitions(REPLICATED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testContinuousQueryTxReplicated() throws Exception { + continuousQuery(REPLICATED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testContinuousQueryTxPartitioned() throws Exception { + continuousQuery(PARTITIONED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testContinuousQueryTxLocal() throws Exception { + continuousQuery(LOCAL, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testContinuousQueryAtomicReplicated() throws Exception { + continuousQuery(REPLICATED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testContinuousQueryAtomicPartitioned() throws Exception { + continuousQuery(PARTITIONED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testContinuousQueryAtomicLocal() throws Exception { + continuousQuery(LOCAL, ATOMIC); + } + + /** + * @param cacheMode Cache mode. + * @param atomicityMode Cache atomicity mode. + * @throws Exception If failed. + */ + private void scanQuery(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception { + int keys = 10_000; + + Integer[] data1 = generateData(keys); + Integer[] data2 = generateData(keys); + + boolean loc = cacheMode == LOCAL; + + if (loc) + startGrid(0); + else + startGridsMultiThreaded(4); + + Ignite srv0 = ignite(0); + + srv0.createCache(cacheConfiguration(GROUP1, CACHE1, cacheMode, atomicityMode, 2, false)); + srv0.createCache(cacheConfiguration(GROUP1, CACHE2, cacheMode, atomicityMode, 2, false)); + + IgniteCache cache1; + IgniteCache cache2; + + if (atomicityMode == TRANSACTIONAL) { + Ignite ignite = ignite(loc ? 0 : 1); + + cache1 = ignite.cache(CACHE1); + cache2 = ignite.cache(CACHE2); + + try (Transaction tx = ignite.transactions().txStart()) { + for (int i = 0; i < keys ; i++) { + cache1.put(i, data1[i]); + cache2.put(i, data2[i]); + } + + tx.commit(); + } + } + else { + // Async put ops. + int ldrs = 4; + + List> cls = new ArrayList<>(ldrs * 2); + + for (int i = 0; i < ldrs ; i++) { + cls.add(putOperation(loc ? 0 : 1, ldrs, i, CACHE1, data1)); + cls.add(putOperation(loc ? 0 : 2, ldrs, i, CACHE2, data2)); + } + + GridTestUtils.runMultiThreaded(cls, "loaders"); + } + + ScanQuery qry = new ScanQuery<>(); + + Set keysSet = sequence(keys); + + for (Cache.Entry entry : ignite(loc ? 0 : 3).cache(CACHE1).query(qry)) { + assertTrue(keysSet.remove(entry.getKey())); + assertEquals(data1[entry.getKey()], entry.getValue()); + } + + assertTrue(keysSet.isEmpty()); + + srv0.destroyCache(CACHE1); + + keysSet = sequence(keys); + + for (Cache.Entry entry : ignite(loc ? 0 : 3).cache(CACHE2).query(qry)) { + assertTrue(keysSet.remove(entry.getKey())); + assertEquals(data2[entry.getKey()], entry.getValue()); + } + + assertTrue(keysSet.isEmpty()); + } + + /** + * @param cacheMode Cache mode. + * @param atomicityMode Cache atomicity mode. + * @throws Exception If failed. + */ + private void continuousQuery(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception { + final int keys = 10_000; + + Integer[] data1 = generateData(keys); + Integer[] data2 = generateData(keys); + + boolean loc = cacheMode == LOCAL; + + if (loc) + startGrid(0); + else + startGridsMultiThreaded(4); + + Ignite srv0 = ignite(0); + + srv0.createCache(cacheConfiguration(GROUP1, CACHE1, cacheMode, atomicityMode, 2, false)); + srv0.createCache(cacheConfiguration(GROUP1, CACHE2, cacheMode, atomicityMode, 2, false)); + + final AtomicInteger cntr1 = new AtomicInteger(); + final AtomicInteger cntr2 = new AtomicInteger(); + + CacheEntryUpdatedListener lsnr1 = new CacheEntryUpdatedListener() { + @Override public void onUpdated( + Iterable> evts) { + for (CacheEntryEvent ignored : evts) + cntr1.incrementAndGet(); + } + }; + + CacheEntryUpdatedListener lsnr2 = new CacheEntryUpdatedListener() { + @Override public void onUpdated( + Iterable> evts) { + for (CacheEntryEvent ignored : evts) + cntr2.incrementAndGet(); + } + }; + + QueryCursor qry1 = ignite(loc ? 0 : 2).cache(CACHE1).query(new ContinuousQuery<>().setLocalListener(lsnr1)); + QueryCursor qry2 = ignite(loc ? 0 : 3).cache(CACHE2).query(new ContinuousQuery<>().setLocalListener(lsnr2)); + + if (atomicityMode == TRANSACTIONAL) { + Ignite ignite = ignite(loc ? 0 : 1); + + IgniteCache cache1 = ignite.cache(CACHE1); + IgniteCache cache2 = ignite.cache(CACHE2); + + try (Transaction tx = ignite.transactions().txStart()) { + for (int i = 0; i < keys ; i++) { + cache1.put(i, data1[i]); + cache2.put(i, data2[i]); + } + + tx.commit(); + } + } + else { + int ldrs = 4; + + List> cls = new ArrayList<>(ldrs * 2); + + for (int i = 0; i < ldrs ; i++) { + cls.add(putOperation(loc ? 0 : 1, ldrs, i, CACHE1, data1)); + cls.add(putOperation(loc ? 0 : 2, ldrs, i, CACHE2, data2)); + } + + GridTestUtils.runMultiThreaded(cls, "loaders"); + } + + GridTestUtils.waitForCondition(new PA() { + @Override public boolean apply() { + return cntr1.get() == keys && cntr2.get() == keys; + } + }, 2000); + + assertEquals(cntr1.get(), keys); + assertEquals(cntr2.get(), keys); + + qry1.close(); + + Map map = generateDataMap(10); + + srv0.cache(CACHE1).putAll(map); + srv0.cache(CACHE2).putAll(map); + + GridTestUtils.waitForCondition(new PA() { + @Override public boolean apply() { + return cntr2.get() == keys + 10; + } + }, 2000); + + assertEquals(keys + 10, cntr2.get()); + + assertEquals(keys, cntr1.get()); + + qry2.close(); + } + + /** + * @param cacheMode Cache mode. + * @param atomicityMode Cache atomicity mode. + * @throws Exception If failed. + */ + private void scanQueryMultiplePartitions(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception { + int keys = 10000; + + Integer[] data1 = generateData(keys); + Integer[] data2 = generateData(keys); + + startGridsMultiThreaded(4); + + Ignite srv0 = ignite(0); + + srv0.createCache( + cacheConfiguration(GROUP1, CACHE1, cacheMode, atomicityMode, 2, false) + .setAffinity(new RendezvousAffinityFunction().setPartitions(32))); + srv0.createCache( + cacheConfiguration(GROUP1, CACHE2, cacheMode, atomicityMode, 2, false) + .setAffinity(new RendezvousAffinityFunction().setPartitions(32))); + + awaitPartitionMapExchange(); + + IgniteCache cache1; + IgniteCache cache2; + + if (atomicityMode == TRANSACTIONAL) { + Ignite ignite = ignite(1); + + cache1 = ignite.cache(CACHE1); + cache2 = ignite.cache(CACHE2); + + try (Transaction tx = ignite.transactions().txStart()) { + for (int i = 0; i < keys ; i++) { + cache1.put(i, data1[i]); + cache2.put(i, data2[i]); + } + + tx.commit(); + } + } + else { + // Async put ops. + int ldrs = 4; + + List> cls = new ArrayList<>(ldrs * 2); + + for (int i = 0; i < ldrs ; i++) { + cls.add(putOperation(1, ldrs, i, CACHE1, data1)); + cls.add(putOperation(2, ldrs, i, CACHE2, data2)); + } + + GridTestUtils.runMultiThreaded(cls, "loaders"); + } + + + int p = ThreadLocalRandom.current().nextInt(32); + + ScanQuery qry = new ScanQuery().setPartition(p); + + Set keysSet = new TreeSet<>(); + + cache1 = ignite(3).cache(CACHE1); + + Affinity aff = affinity(cache1); + + for(int i = 0; i < keys; i++) { + if (aff.partition(i) == p) { + keysSet.add(i); + } + } + + for (Cache.Entry entry : cache1.query(qry)) { + assertTrue(keysSet.remove(entry.getKey())); + assertEquals(data1[entry.getKey()], entry.getValue()); + } + + assertTrue(keysSet.isEmpty()); + + srv0.destroyCache(CACHE1); + + keysSet = new TreeSet<>(); + + cache2 = ignite(3).cache(CACHE2); + + aff = affinity(cache2); + + for(int i = 0; i < keys; i++) { + if (aff.partition(i) == p) { + keysSet.add(i); + } + } + + for (Cache.Entry entry : cache2.query(qry)) { + assertTrue(keysSet.remove(entry.getKey())); + assertEquals(data2[entry.getKey()], entry.getValue()); + } + + assertTrue(keysSet.isEmpty()); + } + + /** + * @param cacheMode Cache mode. + * @param atomicityMode Cache atomicity mode. + * @throws Exception If failed. + */ + private void cacheIterator(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception { + int keys = 10000; + + Integer[] data1 = generateData(keys); + Integer[] data2 = generateData(keys); + + boolean local = cacheMode == LOCAL; + + if (local) + startGrid(0); + else + startGridsMultiThreaded(4); + + Ignite srv0 = ignite(0); + + srv0.createCache(cacheConfiguration(GROUP1, CACHE1, cacheMode, atomicityMode, 2, false)); + srv0.createCache(cacheConfiguration(GROUP1, CACHE2, cacheMode, atomicityMode, 2, false)); + + if(!local) + awaitPartitionMapExchange(); + + if (atomicityMode == TRANSACTIONAL) { + Ignite ignite = ignite(local ? 0 : 1); + + IgniteCache cache1 = ignite.cache(CACHE1); + IgniteCache cache2 = ignite.cache(CACHE2); + + try (Transaction tx = ignite.transactions().txStart()) { + for (int i = 0; i < keys ; i++) { + cache1.put(i, data1[i]); + cache2.put(i, data2[i]); + } + + tx.commit(); + } + } + else { + // Async put ops. + int ldrs = 4; + + List> cls = new ArrayList<>(ldrs * 2); + + for (int i = 0; i < ldrs ; i++) { + cls.add(putOperation(local ? 0 : 1, ldrs, i, CACHE1, data1)); + cls.add(putOperation(local ? 0 : 2, ldrs, i, CACHE2, data2)); + } + + GridTestUtils.runMultiThreaded(cls, "loaders"); + } + + + Set keysSet = sequence(keys); + + for (Cache.Entry entry : ignite(local ? 0 : 3).cache(CACHE1)) { + assertTrue(keysSet.remove(entry.getKey())); + assertEquals(data1[entry.getKey()], entry.getValue()); + } + + assertTrue(keysSet.isEmpty()); + + srv0.destroyCache(CACHE1); + + keysSet = sequence(keys); + + for (Cache.Entry entry : ignite(local ? 0 : 3).cache(CACHE2)) { + assertTrue(keysSet.remove(entry.getKey())); + assertEquals(data2[entry.getKey()], entry.getValue()); + } + + assertTrue(keysSet.isEmpty()); + } + + /** + * @throws Exception If failed. + */ + private void entriesTtl(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception { + int keys = 10000; + + final int ttl = 10000; + + Integer[] data1 = generateData(keys); + Integer[] data2 = generateData(keys); + + boolean local = cacheMode == LOCAL; + + if (local) + startGrid(0); + else + startGridsMultiThreaded(4); + + + Ignite srv0 = ignite(0); + + srv0.createCache( + cacheConfiguration(GROUP1, CACHE1, cacheMode, atomicityMode, 2, false) + // -1 = ETERNAL just created entries are not expiring + // -2 = NOT_CHANGED not to change ttl on entry update + .setExpiryPolicyFactory(new PlatformExpiryPolicyFactory(-1, -2, ttl)).setEagerTtl(true) + ); + + srv0.createCache(cacheConfiguration(GROUP1, CACHE2, cacheMode, atomicityMode, 2, false)); + + if (!local) + awaitPartitionMapExchange(); + + if (atomicityMode == TRANSACTIONAL) { + Ignite ignite = ignite(local ? 0 : 1); + + IgniteCache cache1 = ignite.cache(CACHE1); + IgniteCache cache2 = ignite.cache(CACHE2); + + try (Transaction tx = ignite.transactions().txStart()) { + for (int i = 0; i < keys ; i++) { + cache1.put(i, data1[i]); + cache2.put(i, data2[i]); + } + + tx.commit(); + } + } + else { + // async put ops + int ldrs = 4; + + List> cls = new ArrayList<>(ldrs * 2); + + for (int i = 0; i < ldrs ; i++) { + cls.add(putOperation(local ? 0 : 1, ldrs, i, CACHE1, data1)); + cls.add(putOperation(local ? 0 : 2, ldrs, i, CACHE2, data2)); + } + + GridTestUtils.runMultiThreaded(cls, "loaders"); + } + + checkData(local ? 0 : 3, CACHE1, data1); + checkData(local ? 0 : 3, CACHE2, data2); + + srv0.destroyCache(CACHE2); + + checkData(local ? 0 : 3, CACHE1, data1); + + // Wait for expiration + + Thread.sleep((long)(ttl * 1.2)); + + assertEquals(0, ignite(local ? 0 : 3).cache(CACHE1).size()); + } + + /** + * @param cacheMode Cache mode. + * @param atomicityMode Cache atomicity mode. + * @throws Exception If failed. + */ + private void createDestroyCaches(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception { + int keys = 10000; + + Integer[] data1 = generateData(keys); + Integer[] data2 = generateData(keys); + + startGridsMultiThreaded(4); + + Ignite srv0 = ignite(0); + + srv0.createCache(cacheConfiguration(GROUP1, CACHE1, cacheMode, atomicityMode, 2, false)); + srv0.createCache(cacheConfiguration(GROUP1, CACHE2, cacheMode, atomicityMode, 2, false)); + + awaitPartitionMapExchange(); + + if (atomicityMode == TRANSACTIONAL) { + Ignite ignite = ignite(1); + + IgniteCache cache1 = ignite.cache(CACHE1); + IgniteCache cache2 = ignite.cache(CACHE2); + + try (Transaction tx = ignite.transactions().txStart()) { + for (int i = 0; i < keys ; i++) { + cache1.put(i, data1[i]); + cache2.put(i, data2[i]); + } + + tx.commit(); + } + } + else { + int ldrs = 4; + + List> cls = new ArrayList<>(ldrs * 2); + + for (int i = 0; i < ldrs ; i++) { + cls.add(putOperation(1, ldrs, i, CACHE1, data1)); + cls.add(putOperation(2, ldrs, i, CACHE2, data2)); + } + + GridTestUtils.runMultiThreaded(cls, "loaders"); + } + + checkLocalData(3, CACHE1, data1); + checkLocalData(0, CACHE2, data2); + + checkData(0, CACHE1, data1); + checkData(3, CACHE2, data2); + + ignite(1).destroyCache(CACHE2); + + startGrid(5); + + awaitPartitionMapExchange(); + + checkData(5, CACHE1, data1); + checkLocalData(5, CACHE1, data1); + + ignite(1).destroyCache(CACHE1); + + checkCacheGroup(5, GROUP1, false); + } + + /** + * @param idx Node index. + * @param ldrs Loaders count. + * @param ldrIdx Loader index. + * @param cacheName Cache name. + * @param data Data. + * @return Callable for put operation. + */ + private Callable putOperation( + final int idx, + final int ldrs, + final int ldrIdx, + final String cacheName, + final Integer[] data) { + return new Callable() { + @Override public Void call() throws Exception { + IgniteCache cache = ignite(idx).cache(cacheName); + + for (int j = 0, size = data.length; j < size ; j++) { + if (j % ldrs == ldrIdx) + cache.put(j, data[j]); + } + + return null; + } + }; + } + + /** + * Creates an array of random integers. + * + * @param cnt Array length. + * @return Array of random integers. + */ + private Integer[] generateData(int cnt) { + Random rnd = ThreadLocalRandom.current(); + + Integer[] data = new Integer[cnt]; + + for (int i = 0; i < data.length; i++) + data[i] = rnd.nextInt(); + + return data; + } + + /** + * Creates a map with random integers. + * + * @param cnt Map size length. + * @return Map with random integers. + */ + private Map generateDataMap(int cnt) { + return generateDataMap(0, cnt); + } + + /** + * Creates a map with random integers. + * + * @param startKey Start key. + * @param cnt Map size length. + * @return Map with random integers. + */ + private Map generateDataMap(int startKey, int cnt) { + Random rnd = ThreadLocalRandom.current(); + + Map data = U.newHashMap(cnt); + + for (int i = 0; i < cnt; i++) + data.put(startKey++, rnd.nextInt()); + + return data; + } + + /** + * @param cnt Sequence length. + * @return Sequence of integers. + */ + private Set sequence(int cnt) { + Set res = new TreeSet<>(); + + for (int i = 0; i < cnt; i++) + res.add(i); + + return res; + } + + /** + * @param idx Node index. + * @param cacheName Cache name. + * @param data Expected data. + * @throws Exception If failed. + */ + private void checkData(int idx, String cacheName, Integer[] data) throws Exception { + Set keys = sequence(data.length); + + Set> entries = + ignite(idx).cache(cacheName).getAll(keys).entrySet(); + + for (Map.Entry entry : entries) { + assertTrue(keys.remove(entry.getKey())); + assertEquals(data[entry.getKey()], entry.getValue()); + } + + assertTrue(keys.isEmpty()); + } + + /** + * @param idx Node index. + * @param cacheName Cache name. + * @param data Expected data. + * @throws Exception If failed. + */ + private void checkLocalData(int idx, String cacheName, Integer[] data) throws Exception { + Ignite ignite = ignite(idx); + ClusterNode node = ignite.cluster().localNode(); + IgniteCache cache = ignite.cache(cacheName); + + Affinity aff = affinity(cache); + + Set localKeys = new TreeSet<>(); + + for (int key = 0; key < data.length; key++) { + if(aff.isPrimaryOrBackup(node, key)) + localKeys.add(key); + } + + Iterable> localEntries = cache.localEntries(CachePeekMode.OFFHEAP); + + for (Cache.Entry entry : localEntries) { + assertTrue(localKeys.remove(entry.getKey())); + assertEquals(data[entry.getKey()], entry.getValue()); + } + + assertTrue(localKeys.isEmpty()); + } + + /** + * @param srvs Number of server nodes. + * @throws Exception If failed. + */ + private void createDestroyCaches(int srvs) throws Exception { + startGridsMultiThreaded(srvs); + + checkCacheDiscoveryDataConsistent(); + + Ignite srv0 = ignite(0); + + for (int i = 0; i < srvs; i++) + checkCacheGroup(i, GROUP1, false); + + for (int iter = 0; iter < 3; iter++) { + log.info("Iteration: " + iter); + + srv0.createCache(cacheConfiguration(GROUP1, CACHE1, PARTITIONED, ATOMIC, 2, false)); + + checkCacheDiscoveryDataConsistent(); + + for (int i = 0; i < srvs; i++) { + checkCacheGroup(i, GROUP1, true); + + checkCache(i, CACHE1, 10); + } + + srv0.createCache(cacheConfiguration(GROUP1, CACHE2, PARTITIONED, ATOMIC, 2, false)); + + checkCacheDiscoveryDataConsistent(); + + for (int i = 0; i < srvs; i++) { + checkCacheGroup(i, GROUP1, true); + + checkCache(i, CACHE2, 10); + } + + srv0.destroyCache(CACHE1); + + checkCacheDiscoveryDataConsistent(); + + for (int i = 0; i < srvs; i++) { + checkCacheGroup(i, GROUP1, true); + + checkCache(i, CACHE2, 10); + } + + srv0.destroyCache(CACHE2); + + checkCacheDiscoveryDataConsistent(); + + for (int i = 0; i < srvs; i++) + checkCacheGroup(i, GROUP1, false); + } + } + + /** + * @param idx Node index. + * @param cacheName Cache name. + * @param ops Number of operations to execute. + */ + private void checkCache(int idx, String cacheName, int ops) { + IgniteCache cache = ignite(idx).cache(cacheName); + + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + for (int i = 0; i < ops; i++) { + Integer key = rnd.nextInt(); + + cache.put(key, i); + + assertEquals(i, cache.get(key)); + } + } + + /** + * @param cache3 {@code True} if add last cache. + * @return Cache configurations. + */ + private CacheConfiguration[] staticConfigurations1(boolean cache3) { + CacheConfiguration[] ccfgs = new CacheConfiguration[cache3 ? 3 : 2]; + + ccfgs[0] = cacheConfiguration(null, "cache1", PARTITIONED, ATOMIC, 2, false); + ccfgs[1] = cacheConfiguration(GROUP1, "cache2", PARTITIONED, ATOMIC, 2, false); + + if (cache3) + ccfgs[2] = cacheConfiguration(GROUP1, "cache3", PARTITIONED, ATOMIC, 2, false); + + return ccfgs; + } + + /** + * @throws Exception If failed. + */ + public void testDiscoveryDataConsistency1() throws Exception { + ccfgs = staticConfigurations1(true); + Ignite srv0 = startGrid(0); + + ccfgs = staticConfigurations1(true); + startGrid(1); + + checkCacheDiscoveryDataConsistent(); + + ccfgs = null; + startGrid(2); + + checkCacheDiscoveryDataConsistent(); + + srv0.createCache(cacheConfiguration(null, "cache4", PARTITIONED, ATOMIC, 2, false)); + + checkCacheDiscoveryDataConsistent(); + + ccfgs = staticConfigurations1(true); + startGrid(3); + + checkCacheDiscoveryDataConsistent(); + + srv0.createCache(cacheConfiguration(GROUP1, "cache5", PARTITIONED, ATOMIC, 2, false)); + + ccfgs = staticConfigurations1(true); + startGrid(4); + + checkCacheDiscoveryDataConsistent(); + + for (int i = 0; i < 5; i++) + checkCacheGroup(i, GROUP1, true); + + srv0.destroyCache("cache1"); + srv0.destroyCache("cache2"); + srv0.destroyCache("cache3"); + + checkCacheDiscoveryDataConsistent(); + + ccfgs = staticConfigurations1(true); + startGrid(5); + + checkCacheDiscoveryDataConsistent(); + + for (int i = 0; i < 6; i++) + checkCacheGroup(i, GROUP1, true); + + srv0.destroyCache("cache1"); + srv0.destroyCache("cache2"); + srv0.destroyCache("cache3"); + srv0.destroyCache("cache4"); + srv0.destroyCache("cache5"); + + ccfgs = staticConfigurations1(true); + startGrid(6); + + checkCacheDiscoveryDataConsistent(); + + srv0.createCache(cacheConfiguration(null, "cache4", PARTITIONED, ATOMIC, 2, false)); + srv0.createCache(cacheConfiguration(GROUP1, "cache5", PARTITIONED, ATOMIC, 2, false)); + + checkCacheDiscoveryDataConsistent(); + + ccfgs = staticConfigurations1(false); + startGrid(7); + + checkCacheDiscoveryDataConsistent(); + + awaitPartitionMapExchange(); + } + + /** + * @param cnt Caches number. + * @param grp Cache groups. + * @param baseName Caches name prefix. + * @return Cache configurations. + */ + private CacheConfiguration[] cacheConfigurations(int cnt, String grp, String baseName) { + CacheConfiguration[] ccfgs = new CacheConfiguration[cnt]; + + for (int i = 0; i < cnt; i++) { + ccfgs[i] = cacheConfiguration(grp, + baseName + i, PARTITIONED, + i % 2 == 0 ? TRANSACTIONAL : ATOMIC, + 2, + false).setAffinity(new RendezvousAffinityFunction(false, 256)); + } + + return ccfgs; + } + + /** + * @throws Exception If failed. + */ + public void testStartManyCaches() throws Exception { + final int CACHES = 5_000; + + final int NODES = 4; + + for (int i = 0; i < NODES; i++) { + ccfgs = cacheConfigurations(CACHES, GROUP1, "testCache1-"); + + client = i == NODES - 1; + + startGrid(i); + } + + Ignite client = ignite(NODES - 1); + + client.createCaches(Arrays.asList(cacheConfigurations(CACHES, GROUP2, "testCache2-"))); + + checkCacheDiscoveryDataConsistent(); + + for (int i = 0; i < NODES; i++) { + for (int c = 0; c < CACHES; c++) { + if (c % 100 == 0) + log.info("Check node: " + i); + + checkCache(i, "testCache1-" + c, 1); + checkCache(i, "testCache2-" + c, 1); + } + } + + log.info("Stop nodes."); + + GridTestUtils.runMultiThreaded(new IgniteInClosure() { + @Override public void apply(Integer idx) { + stopGrid(idx); + } + }, NODES, "stopThread"); + } + + /** + * @throws Exception If failed. + */ + public void testRebalance1() throws Exception { + Ignite srv0 = startGrid(0); + + IgniteCache srv0Cache1 = + srv0.createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 2, false)); + IgniteCache srv0Cache2 = + srv0.createCache(cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 2, false)); + IgniteCache srv0Cache3 = + srv0.createCache(cacheConfiguration(GROUP2, "c3", PARTITIONED, TRANSACTIONAL, 2, false)); + IgniteCache srv0Cache4 = + srv0.createCache(cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 2, false)); + + final int ITEMS = 1_000; + + for (int i = 0; i < ITEMS; i++) { + srv0Cache1.put(new Key1(i), i); + + srv0Cache3.put(new Key1(i), i); + srv0Cache4.put(new Key1(i), -i); + } + + assertEquals(ITEMS, srv0Cache1.size()); + assertEquals(ITEMS, srv0Cache1.localSize()); + assertEquals(0, srv0Cache2.size()); + assertEquals(ITEMS, srv0Cache3.size()); + assertEquals(ITEMS, srv0Cache4.localSize()); + + startGrid(1); + + awaitPartitionMapExchange(); + + for (int i = 0; i < 2; i++) { + Ignite node = ignite(i); + + IgniteCache cache1 = node.cache("c1"); + IgniteCache cache2 = node.cache("c2"); + IgniteCache cache3 = node.cache("c3"); + IgniteCache cache4 = node.cache("c4"); + + assertEquals(ITEMS * 2, cache1.size(CachePeekMode.ALL)); + assertEquals(ITEMS, cache1.localSize(CachePeekMode.ALL)); + assertEquals(0, cache2.size(CachePeekMode.ALL)); + assertEquals(0, cache2.localSize(CachePeekMode.ALL)); + + assertEquals(ITEMS * 2, cache3.size(CachePeekMode.ALL)); + assertEquals(ITEMS, cache3.localSize(CachePeekMode.ALL)); + + assertEquals(ITEMS * 2, cache4.size(CachePeekMode.ALL)); + assertEquals(ITEMS, cache4.localSize(CachePeekMode.ALL)); + + for (int k = 0; k < ITEMS; k++) { + assertEquals(i, cache1.localPeek(new Key1(i))); + assertNull(cache2.localPeek(new Key1(i))); + assertEquals(i, cache3.localPeek(new Key1(i))); + assertEquals(-i, cache4.localPeek(new Key1(i))); + } + } + + for (int i = 0; i < ITEMS * 2; i++) + srv0Cache2.put(new Key1(i), i + 1); + + Ignite srv2 = startGrid(2); + + awaitPartitionMapExchange(); + + for (int i = 0; i < 3; i++) { + Ignite node = ignite(i); + + IgniteCache cache1 = node.cache("c1"); + IgniteCache cache2 = node.cache("c2"); + IgniteCache cache3 = node.cache("c3"); + IgniteCache cache4 = node.cache("c4"); + + assertEquals(ITEMS * 3, cache1.size(CachePeekMode.ALL)); + assertEquals(ITEMS, cache1.localSize(CachePeekMode.ALL)); + assertEquals(ITEMS * 6, cache2.size(CachePeekMode.ALL)); + assertEquals(ITEMS * 2, cache2.localSize(CachePeekMode.ALL)); + assertEquals(ITEMS, cache3.localSize(CachePeekMode.ALL)); + assertEquals(ITEMS, cache4.localSize(CachePeekMode.ALL)); + } + + IgniteCache srv2Cache1 = srv2.cache("c1"); + IgniteCache srv2Cache2 = srv2.cache("c2"); + + for (int i = 0; i < ITEMS; i++) + assertEquals(i, srv2Cache1.localPeek(new Key1(i))); + + for (int i = 0; i < ITEMS * 2; i++) + assertEquals(i + 1, srv2Cache2.localPeek(new Key1(i))); + } + + /** + * @throws Exception If failed. + */ + public void testRebalance2() throws Exception { + Ignite srv0 = startGrid(0); + + IgniteCache srv0Cache1 = + srv0.createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 0, false)); + IgniteCache srv0Cache2 = + srv0.createCache(cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 0, false)); + + Affinity aff = srv0.affinity("c1"); + + final int ITEMS = 2_000; + + Map c1Data = new HashMap<>(); + Map c2Data = new HashMap<>(); + + for (int i = 0; i < ITEMS; i++) { + srv0Cache1.put(i, i); + c1Data.put(i, i); + + if (i % 2 == 0) { + srv0Cache2.put(i, i); + c2Data.put(i, i); + } + } + + assertEquals(ITEMS, srv0Cache1.size()); + assertEquals(ITEMS / 2, srv0Cache2.size()); + + Ignite srv1 = startGrid(1); + + awaitPartitionMapExchange(); + + assertEquals(ITEMS, srv0Cache1.size()); + assertEquals(ITEMS / 2, srv0Cache2.size()); + + checkCacheData(c1Data, "c1"); + checkCacheData(c2Data, "c2"); + + Set srv1Parts = new HashSet<>(); + + for (Integer p : aff.primaryPartitions(srv1.cluster().localNode())) + srv1Parts.add(p); + + CacheGroupContext grpSrv0 = cacheGroup(srv0, GROUP1); + CacheGroupContext grpSrv1 = cacheGroup(srv1, GROUP1); + + for (int p = 0; p < aff.partitions(); p++) { + if (srv1Parts.contains(p)) { + GridIterator it = grpSrv0.offheap().partitionIterator(p); + assertFalse(it.hasNext()); + + it = grpSrv1.offheap().partitionIterator(p); + assertTrue(it.hasNext()); + } + else { + GridIterator it = grpSrv0.offheap().partitionIterator(p); + assertTrue(it.hasNext()); + + it = grpSrv1.offheap().partitionIterator(p); + assertFalse(it.hasNext()); + } + } + + c1Data = new HashMap<>(); + c2Data = new HashMap<>(); + + for (int i = 0; i < ITEMS; i++) { + srv0Cache1.put(i, i + 1); + c1Data.put(i, i + 1); + + if (i % 2 == 0) { + srv0Cache2.put(i, i + 1); + c2Data.put(i, i + 1); + } + } + + checkCacheData(c1Data, "c1"); + checkCacheData(c2Data, "c2"); + } + + /** + * @throws Exception If failed. + */ + public void testNoKeyIntersectTx() throws Exception { + testNoKeyIntersect(TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testNoKeyIntersectAtomic() throws Exception { + testNoKeyIntersect(ATOMIC); + } + + /** + * @param atomicityMode Atomicity mode. + * @throws Exception If failed. + */ + private void testNoKeyIntersect(CacheAtomicityMode atomicityMode) throws Exception { + startGrid(0); + + testNoKeyIntersect(atomicityMode, false); + + testNoKeyIntersect(atomicityMode, true); + + startGridsMultiThreaded(1, 4); + + testNoKeyIntersect(atomicityMode, false); + + testNoKeyIntersect(atomicityMode, true); + } + + /** + * @param keys Keys. + * @param rnd Random. + * @return Added key. + */ + private Integer addKey(Set keys, ThreadLocalRandom rnd) { + for (;;) { + Integer key = rnd.nextInt(100_000); + + if (keys.add(key)) + return key; + } + } + + /** + * @param atomicityMode Cache atomicity mode. + * @param heapCache On heap cache flag. + * @throws Exception If failed. + */ + private void testNoKeyIntersect(CacheAtomicityMode atomicityMode, boolean heapCache) throws Exception { + Ignite srv0 = ignite(0); + + try { + IgniteCache cache1 = srv0. + createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, atomicityMode, 1, heapCache)); + + Set keys = new LinkedHashSet<>(30); + + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + for (int i = 0; i < 10; i++) { + Integer key = addKey(keys, rnd); + + cache1.put(key, key); + cache1.put(new Key1(key), new Value1(key)); + cache1.put(new Key2(key), new Value2(key)); + } + + assertEquals(30, cache1.size()); + + IgniteCache cache2 = srv0. + createCache(cacheConfiguration(GROUP1, "c2", PARTITIONED, atomicityMode, 1, heapCache)); + + assertEquals(30, cache1.size()); + assertEquals(0 , cache2.size()); + + for (Integer key : keys) { + assertNull(cache2.get(key)); + assertNull(cache2.get(new Key1(key))); + assertNull(cache2.get(new Key2(key))); + + cache2.put(key, key + 1); + cache2.put(new Key1(key), new Value1(key + 1)); + cache2.put(new Key2(key), new Value2(key + 1)); + } + + assertEquals(30, cache1.size()); + assertEquals(30, cache2.size()); + + for (int i = 0; i < 10; i++) { + Integer key = addKey(keys, rnd); + + cache2.put(key, key + 1); + cache2.put(new Key1(key), new Value1(key + 1)); + cache2.put(new Key2(key), new Value2(key + 1)); + } + + assertEquals(30, cache1.size()); + assertEquals(60, cache2.size()); + + int i = 0; + + for (Integer key : keys) { + if (i++ < 10) { + assertEquals(key, cache1.get(key)); + assertEquals(new Value1(key), cache1.get(new Key1(key))); + assertEquals(new Value2(key), cache1.get(new Key2(key))); + } + else { + assertNull(cache1.get(key)); + assertNull(cache1.get(new Key1(key))); + assertNull(cache1.get(new Key2(key))); + } + + assertEquals(key + 1, cache2.get(key)); + assertEquals(new Value1(key + 1), cache2.get(new Key1(key))); + assertEquals(new Value2(key + 1), cache2.get(new Key2(key))); + } + + IgniteCache cache3 = srv0. + createCache(cacheConfiguration(GROUP1, "c3", PARTITIONED, atomicityMode, 1, heapCache)); + + assertEquals(30, cache1.size()); + assertEquals(60, cache2.size()); + assertEquals(0, cache3.size()); + + for (Integer key : keys) { + assertNull(cache3.get(key)); + assertNull(cache3.get(new Key1(key))); + assertNull(cache3.get(new Key2(key))); + } + + for (Integer key : keys) { + cache3.put(key, key); + cache3.put(new Key1(key), new Value1(key)); + cache3.put(new Key2(key), new Value2(key)); + } + + i = 0; + + for (Integer key : keys) { + if (i++ < 10) { + assertEquals(key, cache1.get(key)); + assertEquals(new Value1(key), cache1.get(new Key1(key))); + assertEquals(new Value2(key), cache1.get(new Key2(key))); + } + else { + assertNull(cache1.get(key)); + assertNull(cache1.get(new Key1(key))); + assertNull(cache1.get(new Key2(key))); + } + + assertEquals(key + 1, cache2.get(key)); + assertEquals(new Value1(key + 1), cache2.get(new Key1(key))); + assertEquals(new Value2(key + 1), cache2.get(new Key2(key))); + + assertEquals(key, cache3.get(key)); + assertEquals(new Value1(key), cache3.get(new Key1(key))); + assertEquals(new Value2(key), cache3.get(new Key2(key))); + } + + i = 0; + + for (Integer key : keys) { + if (i++ == 3) + break; + + cache1.remove(key); + cache1.remove(new Key1(key)); + cache1.remove(new Key2(key)); + + assertNull(cache1.get(key)); + assertNull(cache1.get(new Key1(key))); + assertNull(cache1.get(new Key2(key))); + + assertEquals(key + 1, cache2.get(key)); + assertEquals(new Value1(key + 1), cache2.get(new Key1(key))); + assertEquals(new Value2(key + 1), cache2.get(new Key2(key))); + + assertEquals(key, cache3.get(key)); + assertEquals(new Value1(key), cache3.get(new Key1(key))); + assertEquals(new Value2(key), cache3.get(new Key2(key))); + } + + cache1.removeAll(); + + for (Integer key : keys) { + assertNull(cache1.get(key)); + assertNull(cache1.get(new Key1(key))); + assertNull(cache1.get(new Key2(key))); + + assertEquals(key + 1, cache2.get(key)); + assertEquals(new Value1(key + 1), cache2.get(new Key1(key))); + assertEquals(new Value2(key + 1), cache2.get(new Key2(key))); + + assertEquals(key, cache3.get(key)); + assertEquals(new Value1(key), cache3.get(new Key1(key))); + assertEquals(new Value2(key), cache3.get(new Key2(key))); + } + + cache2.removeAll(); + + for (Integer key : keys) { + assertNull(cache1.get(key)); + assertNull(cache1.get(new Key1(key))); + assertNull(cache1.get(new Key2(key))); + + assertNull(cache2.get(key)); + assertNull(cache2.get(new Key1(key))); + assertNull(cache2.get(new Key2(key))); + + assertEquals(key, cache3.get(key)); + assertEquals(new Value1(key), cache3.get(new Key1(key))); + assertEquals(new Value2(key), cache3.get(new Key2(key))); + } + + if (atomicityMode == TRANSACTIONAL) + testNoKeyIntersectTxLocks(cache1, cache2); + } + finally { + srv0.destroyCaches(Arrays.asList("c1", "c2", "c3")); + } + } + + /** + * @param cache1 Cache1. + * @param cache2 Cache2. + * @throws Exception If failed. + */ + private void testNoKeyIntersectTxLocks(final IgniteCache cache1, final IgniteCache cache2) throws Exception { + final Ignite node = (Ignite)cache1.unwrap(Ignite.class); + + for (int i = 0; i < 5; i++) { + final Integer key = ThreadLocalRandom.current().nextInt(1000); + + Lock lock = cache1.lock(key); + + lock.lock(); + + try { + IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable() { + @Override public Object call() throws Exception { + Lock lock1 = cache1.lock(key); + + assertFalse(lock1.tryLock()); + + Lock lock2 = cache2.lock(key); + + assertTrue(lock2.tryLock()); + + lock2.unlock(); + + return null; + } + }, "lockThread"); + + fut.get(10_000); + } + finally { + lock.unlock(); + } + + try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { + cache1.put(key, 1); + + IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable() { + @Override public Object call() throws Exception { + try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { + cache2.put(key, 2); + + tx.commit(); + } + + assertEquals(2, cache2.get(key)); + + return null; + } + }, "txThread"); + + fut.get(10_000); + + tx.commit(); + } + + assertEquals(1, cache1.get(key)); + assertEquals(2, cache2.get(key)); + + try (Transaction tx = node.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) { + Integer val = (Integer)cache1.get(key); + + cache1.put(key, val + 10); + + IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable() { + @Override public Object call() throws Exception { + try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { + cache2.put(key, 3); + + tx.commit(); + } + + assertEquals(3, cache2.get(key)); + + return null; + } + }, "txThread"); + + fut.get(10_000); + + tx.commit(); + } + + assertEquals(11, cache1.get(key)); + assertEquals(3, cache2.get(key)); + } + } + + /** + * @throws Exception If failed. + */ + public void testCacheApiTxPartitioned() throws Exception { + cacheApiTest(PARTITIONED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testCacheApiTxReplicated() throws Exception { + cacheApiTest(REPLICATED, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testCacheApiAtomicPartitioned() throws Exception { + cacheApiTest(PARTITIONED, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testCacheApiAtomicReplicated() throws Exception { + cacheApiTest(REPLICATED, ATOMIC); + } + + /** + * @param cacheMode Cache mode. + * @param atomicityMode Atomicity mode. + * @throws Exception If failed. + */ + private void cacheApiTest(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception { + startGridsMultiThreaded(4); + + client = true; + + startGrid(4); + + int[] backups = cacheMode == REPLICATED ? new int[]{Integer.MAX_VALUE} : new int[]{0, 1, 2, 3}; + + for (int backups0 : backups) + cacheApiTest(cacheMode, atomicityMode, backups0, false, false, false); + + int backups0 = cacheMode == REPLICATED ? Integer.MAX_VALUE : + backups[ThreadLocalRandom.current().nextInt(backups.length)]; + + cacheApiTest(cacheMode, atomicityMode, backups0, true, false, false); + + if (cacheMode == PARTITIONED) { + // Here the f variable is used as a bit set where 2 last bits + // determine whether a near cache is used on server/client side. + // The case without near cache is already tested at this point. + for (int f : new int[]{1, 2, 3}) { + cacheApiTest(cacheMode, atomicityMode, backups0, false, nearSrv(f), nearClient(f)); + cacheApiTest(cacheMode, atomicityMode, backups0, true, nearSrv(f), nearClient(f)); + } + } + } + + /** + * @param flag Flag. + * @return {@code True} if near cache should be used on a client side. + */ + private boolean nearClient(int flag) { + return (flag & 0b01) == 0b01; + } + + /** + * @param flag Flag. + * @return {@code True} if near cache should be used on a server side. + */ + private boolean nearSrv(int flag) { + return (flag & 0b10) == 0b10; + } + + /** + * @param cacheMode Cache mode. + * @param atomicityMode Atomicity mode. + * @param backups Number of backups. + * @param heapCache On heap cache flag. + * @param nearSrv {@code True} if near cache should be used on a server side. + * @param nearClient {@code True} if near cache should be used on a client side. + * @throws Exception If failed. + */ + private void cacheApiTest(CacheMode cacheMode, + CacheAtomicityMode atomicityMode, + int backups, + boolean heapCache, + boolean nearSrv, + boolean nearClient) throws Exception { + Ignite srv0 = ignite(0); + + NearCacheConfiguration nearCfg = nearSrv ? new NearCacheConfiguration() : null; + + srv0.createCache(cacheConfiguration(GROUP1, "cache-0", cacheMode, atomicityMode, backups, heapCache) + .setNearConfiguration(nearCfg)); + + srv0.createCache(cacheConfiguration(GROUP1, "cache-1", cacheMode, atomicityMode, backups, heapCache)); + + srv0.createCache(cacheConfiguration(GROUP2, "cache-2", cacheMode, atomicityMode, backups, heapCache) + .setNearConfiguration(nearCfg)); + + srv0.createCache(cacheConfiguration(null, "cache-3", cacheMode, atomicityMode, backups, heapCache)); + + if (nearClient) { + Ignite clientNode = ignite(4); + + clientNode.createNearCache("cache-0", new NearCacheConfiguration()); + clientNode.createNearCache("cache-2", new NearCacheConfiguration()); + } + + try { + for (final Ignite node : Ignition.allGrids()) { + List> ops = new ArrayList<>(); + + for (int i = 0; i < 4; i++) + ops.add(testSet(node.cache("cache-" + i), cacheMode, atomicityMode, backups, heapCache, node)); + + // Async operations. + GridTestUtils.runMultiThreaded(ops, "cacheApiTest"); + } + } + finally { + for (int i = 0; i < 4; i++) + srv0.destroyCache("cache-" + i); + } + } + + /** + * @param cache Cache. + * @param cacheMode Cache mode. + * @param atomicityMode Atomicity mode. + * @param backups Number of backups. + * @param heapCache On heap cache flag. + * @param node Ignite node. + * @return Callable for the test operations. + */ + private Callable testSet( + final IgniteCache cache, + final CacheMode cacheMode, + final CacheAtomicityMode atomicityMode, + final int backups, + final boolean heapCache, + final Ignite node) { + return new Callable() { + @Override public Void call() throws Exception { + log.info("Test cache [node=" + node.name() + + ", cache=" + cache.getName() + + ", mode=" + cacheMode + + ", atomicity=" + atomicityMode + + ", backups=" + backups + + ", heapCache=" + heapCache + + ']'); + + cacheApiTest(cache); + + return null; + } + }; + } + + /** + * @param cache Cache. + * @throws Exception If failed. + */ + private void cacheApiTest(IgniteCache cache) throws Exception { + cachePutAllGetAll(cache); + + cachePutRemove(cache); + + cachePutGet(cache); + + cachePutGetAndPut(cache); + + cacheQuery(cache); + + cacheInvokeAll(cache); + + cacheInvoke(cache); + + cacheDataStreamer(cache); + } + + /** + * @param cache Cache. + */ + private void tearDown(IgniteCache cache) { + cache.clear(); + cache.removeAll(); + } + + /** + * @param cache Cache. + * @throws Exception If failed. + */ + private void cacheDataStreamer(final IgniteCache cache) throws Exception { + final int keys = 1000; + final int loaders = 4; + + final Integer[] data = generateData(keys * loaders); + + // Stream through a client node. + Ignite clientNode = ignite(4); + + List> cls = new ArrayList<>(loaders); + + for (final int i : sequence(loaders)) { + final IgniteDataStreamer ldr = clientNode.dataStreamer(cache.getName()); + + ldr.autoFlushFrequency(0); + + cls.add(new Callable() { + @Override public Void call() throws Exception { + List futs = new ArrayList<>(keys); + + for (int j = 0, size = keys * loaders; j < size; j++) { + if (j % loaders == i) + futs.add(ldr.addData(j, data[j])); + + if(j % (100 * loaders) == 0) + ldr.flush(); + } + + ldr.flush(); + + for (IgniteFuture fut : futs) + fut.get(); + + return null; + } + }); + } + + GridTestUtils.runMultiThreaded(cls, "loaders"); + + Set keysSet = sequence(data.length); + + for (Cache.Entry entry : (IgniteCache)cache) { + assertTrue(keysSet.remove(entry.getKey())); + assertEquals(data[entry.getKey()], entry.getValue()); + } + + assertTrue(keysSet.isEmpty()); + + tearDown(cache); + } + + /** + * @param cache Cache. + */ + private void cachePutAllGetAll(IgniteCache cache) { + Map data = generateDataMap(1000); + + cache.putAll(data); + + Map data0 = cache.getAll(data.keySet()); + + assertEquals(data.size(), data0.size()); + + for (Map.Entry entry : data.entrySet()) { + assertEquals(entry.getValue(), data0.get(entry.getKey())); + } + + tearDown(cache); + } + + /** + * @param cache Cache. + */ + private void cachePutRemove(IgniteCache cache) { + Random rnd = ThreadLocalRandom.current(); + + Integer key = rnd.nextInt(); + Integer val = rnd.nextInt(); + + cache.put(key, val); + + assertTrue(cache.remove(key)); + + assertNull(cache.get(key)); + + tearDown(cache); + } + + /** + * @param cache Cache. + */ + private void cachePutGet(IgniteCache cache) { + Random rnd = ThreadLocalRandom.current(); + + Integer key = rnd.nextInt(); + Integer val = rnd.nextInt(); + + cache.put(key, val); + + Object val0 = cache.get(key); + + assertEquals(val, val0); + + tearDown(cache); + } + + /** + * @param cache Cache. + */ + private void cachePutGetAndPut(IgniteCache cache) { + Random rnd = ThreadLocalRandom.current(); + + Integer key = rnd.nextInt(); + Integer val1 = rnd.nextInt(); + Integer val2 = rnd.nextInt(); + + cache.put(key, val1); + + Object val0 = cache.getAndPut(key, val2); + + assertEquals(val1, val0); + + val0 = cache.get(key); + + assertEquals(val2, val0); + + tearDown(cache); + } + + /** + * @param cache Cache. + */ + private void cacheQuery(IgniteCache cache) { + Map data = generateDataMap(1000); + + cache.putAll(data); + + ScanQuery qry = new ScanQuery<>(new IgniteBiPredicate() { + @Override public boolean apply(Integer key, Integer val) { + return key % 2 == 0; + } + }); + + List> all = cache.query(qry).getAll(); + + assertEquals(all.size(), data.size() / 2); + + for (Cache.Entry entry : all) { + assertEquals(0, entry.getKey() % 2); + assertEquals(entry.getValue(), data.get(entry.getKey())); + } + + tearDown(cache); + } + + /** + * @param cache Cache. + */ + private void cacheInvokeAll(IgniteCache cache) { + int keys = 1000; + Map data = generateDataMap(keys); + + cache.putAll(data); + + Random rnd = ThreadLocalRandom.current(); + + int one = rnd.nextInt(); + int two = rnd.nextInt(); + + Map> res = cache.invokeAll(data.keySet(), new CacheEntryProcessor() { + @Override public Integer process(MutableEntry entry, Object... arguments) throws EntryProcessorException { + Object expected = ((Map)arguments[0]).get(entry.getKey()); + + assertEquals(expected, entry.getValue()); + + // Some calculation. + return (Integer)arguments[1] + (Integer)arguments[2]; + } + }, data, one, two); + + assertEquals(keys, res.size()); + assertEquals(one + two, (Object)res.get(0).get()); + + tearDown(cache); + } + + /** + * @param cache Cache. + */ + private void cacheInvoke(IgniteCache cache) { + Random rnd = ThreadLocalRandom.current(); + + Integer key = rnd.nextInt(); + Integer val = rnd.nextInt(); + + cache.put(key, val); + + int one = rnd.nextInt(); + int two = rnd.nextInt(); + + Object res = cache.invoke(key, new CacheEntryProcessor() { + @Override public Integer process(MutableEntry entry, Object... arguments) throws EntryProcessorException { + assertEquals(arguments[0], entry.getValue()); + + // Some calculation. + return (Integer)arguments[1] + (Integer)arguments[2]; + } + }, val, one, two); + + assertEquals(one + two, res); + + tearDown(cache); + } + + /** + * @throws Exception If failed. + */ + public void testConcurrentOperationsSameKeys() throws Exception { + final int SRVS = 4; + final int CLIENTS = 4; + final int NODES = SRVS + CLIENTS; + + startGrid(0); + + Ignite srv0 = startGridsMultiThreaded(1, SRVS - 1); + + client = true; + + startGridsMultiThreaded(SRVS, CLIENTS); + + srv0.createCache(cacheConfiguration(GROUP1, "a0", PARTITIONED, ATOMIC, 1, false)); + srv0.createCache(cacheConfiguration(GROUP1, "a1", PARTITIONED, ATOMIC, 1, false)); + srv0.createCache(cacheConfiguration(GROUP1, "t0", PARTITIONED, TRANSACTIONAL, 1, false)); + srv0.createCache(cacheConfiguration(GROUP1, "t1", PARTITIONED, TRANSACTIONAL, 1, false)); + + final List keys = new ArrayList<>(); + + for (int i = 0; i < 50; i++) + keys.add(i); + + final AtomicBoolean err = new AtomicBoolean(); + + final AtomicBoolean stop = new AtomicBoolean(); + + IgniteInternalFuture fut1 = updateFuture(NODES, "a0", keys, false, stop, err); + IgniteInternalFuture fut2 = updateFuture(NODES, "a1", keys, true, stop, err); + IgniteInternalFuture fut3 = updateFuture(NODES, "t0", keys, false, stop, err); + IgniteInternalFuture fut4 = updateFuture(NODES, "t1", keys, true, stop, err); + + try { + for (int i = 0; i < 15 && !stop.get(); i++) + U.sleep(1_000); + } + finally { + stop.set(true); + } + + fut1.get(); + fut2.get(); + fut3.get(); + fut4.get(); + + assertFalse("Unexpected error, see log for details", err.get()); + } + + /** + * @param nodes Total number of nodes. + * @param cacheName Cache name. + * @param keys Keys to update. + * @param reverse {@code True} if update in reverse order. + * @param stop Stop flag. + * @param err Error flag. + * @return Update future. + */ + private IgniteInternalFuture updateFuture(final int nodes, + final String cacheName, + final List keys, + final boolean reverse, + final AtomicBoolean stop, + final AtomicBoolean err) { + final AtomicInteger idx = new AtomicInteger(); + + return GridTestUtils.runMultiThreadedAsync(new Callable() { + @Override public Void call() throws Exception { + try { + Ignite node = ignite(idx.getAndIncrement() % nodes); + + log.info("Start thread [node=" + node.name() + ']'); + + IgniteCache cache = node.cache(cacheName); + + Map map = new LinkedHashMap<>(); + + if (reverse) { + for (int i = keys.size() - 1; i >= 0; i--) + map.put(keys.get(i), 2); + } + else { + for (Integer key : keys) + map.put(key, 1); + } + + while (!stop.get()) + cache.putAll(map); + } + catch (Exception e) { + err.set(true); + + log.error("Unexpected error: " + e, e); + + stop.set(true); + } + + return null; + } + }, nodes * 2, "update-" + cacheName + "-" + reverse); + } + + /** + * @throws Exception If failed. + */ + public void testConcurrentOperationsAndCacheDestroy() throws Exception { + final int SRVS = 4; + final int CLIENTS = 4; + final int NODES = SRVS + CLIENTS; + + startGrid(0); + + Ignite srv0 = startGridsMultiThreaded(1, SRVS - 1); + + client = true; + + startGridsMultiThreaded(SRVS, CLIENTS); + + final int CACHES = 8; + + final int grp1Backups = ThreadLocalRandom.current().nextInt(3); + final int grp2Backups = ThreadLocalRandom.current().nextInt(3); + + log.info("Start test [grp1Backups=" + grp1Backups + ", grp2Backups=" + grp2Backups + ']'); + + for (int i = 0; i < CACHES; i++) { + srv0.createCache( + cacheConfiguration(GROUP1, GROUP1 + "-" + i, PARTITIONED, ATOMIC, grp1Backups, i % 2 == 0)); + + srv0.createCache( + cacheConfiguration(GROUP2, GROUP2 + "-" + i, PARTITIONED, TRANSACTIONAL, grp2Backups, i % 2 == 0)); + } + + final AtomicInteger idx = new AtomicInteger(); + + final AtomicBoolean err = new AtomicBoolean(); + + final AtomicBoolean stop = new AtomicBoolean(); + + IgniteInternalFuture opFut = GridTestUtils.runMultiThreadedAsync(new Runnable() { + @Override public void run() { + try { + Ignite node = ignite(idx.getAndIncrement() % NODES); + + log.info("Start thread [node=" + node.name() + ']'); + + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + while (!stop.get()) { + String grp = rnd.nextBoolean() ? GROUP1 : GROUP2; + int cacheIdx = rnd.nextInt(CACHES); + + IgniteCache cache = node.cache(grp + "-" + cacheIdx); + + for (int i = 0; i < 10; i++) + cacheOperation(rnd, cache); + } + } + catch (Exception e) { + err.set(true); + + log.error("Unexpected error(1): " + e, e); + + stop.set(true); + } + } + }, (SRVS + CLIENTS) * 2, "op-thread"); + + IgniteInternalFuture cacheFut = GridTestUtils.runAsync(new Runnable() { + @Override public void run() { + try { + int cntr = 0; + + while (!stop.get()) { + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + String grp; + int backups; + + if (rnd.nextBoolean()) { + grp = GROUP1; + backups = grp1Backups; + } + else { + grp = GROUP2; + backups = grp2Backups; + } + + Ignite node = ignite(rnd.nextInt(NODES)); + + log.info("Create cache [node=" + node.name() + ", grp=" + grp + ']'); + + IgniteCache cache = node.createCache(cacheConfiguration(grp, "tmpCache-" + cntr++, + PARTITIONED, + rnd.nextBoolean() ? ATOMIC : TRANSACTIONAL, + backups, + rnd.nextBoolean())); + + for (int i = 0; i < 10; i++) + cacheOperation(rnd, cache); + + log.info("Destroy cache [node=" + node.name() + ", grp=" + grp + ']'); + + node.destroyCache(cache.getName()); + } + } + catch (Exception e) { + err.set(true); + + log.error("Unexpected error(2): " + e, e); + + stop.set(true); + } + } + }, "cache-destroy-thread"); + + try { + for (int i = 0; i < 30 && !stop.get(); i++) + U.sleep(1_000); + } + finally { + stop.set(true); + } + + opFut.get(); + cacheFut.get(); + + assertFalse("Unexpected error, see log for details", err.get()); + } + + /** + * @throws Exception If failed. + */ + public void testStaticConfigurationsValidation() throws Exception { + ccfgs = new CacheConfiguration[2]; + + ccfgs[0] = new CacheConfiguration(CACHE1); + ccfgs[0].setGroupName(GROUP1); + ccfgs[0].setAffinity(new RendezvousAffinityFunction(false, 1024)); + + ccfgs[1] = new CacheConfiguration(CACHE2); + ccfgs[1].setGroupName(GROUP1); + ccfgs[1].setAffinity(new RendezvousAffinityFunction(false, 512)); + + try { + startGrid(0); + + fail(); + } + catch (IgniteCheckedException ignore) { + // Expected exception. + } + + ccfgs = new CacheConfiguration[3]; + + ccfgs[0] = new CacheConfiguration(CACHE1); + ccfgs[0].setGroupName(GROUP1); + ccfgs[0].setAffinity(new RendezvousAffinityFunction(false, 16)); + + ccfgs[1] = new CacheConfiguration(CACHE2); + ccfgs[1].setGroupName(GROUP2); + ccfgs[1].setAffinity(new RendezvousAffinityFunction(false, 512)); + + ccfgs[2] = new CacheConfiguration("cache3"); + ccfgs[2].setGroupName(GROUP1); + ccfgs[2].setAffinity(new RendezvousAffinityFunction(false, 16)); + + startGrid(0); + } + + /** + * @throws Exception If failed. + */ + public void testCacheIdConflict() throws Exception { + ccfgs = new CacheConfiguration[]{new CacheConfiguration("AaAaAa"), new CacheConfiguration("AaAaBB")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(0); + + return null; + } + }, IgniteCheckedException.class, null); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration("AaAaAa")}; + + startGrid(0); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration("AaAaBB")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(1); + + return null; + } + }, IgniteCheckedException.class, null); + + assertFalse(ignite(0).cacheNames().contains("AaAaBB")); + + final Ignite ignite1 = startGrid(1); + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + ignite1.createCache(new CacheConfiguration("AaAaBB")); + + return null; + } + }, CacheException.class, null); + + assertFalse(ignite(0).cacheNames().contains("AaAaBB")); + } + + /** + * @throws Exception If failed. + */ + public void testCacheGroupIdConflict1() throws Exception { + ccfgs = new CacheConfiguration[]{new CacheConfiguration(CACHE1).setGroupName("AaAaAa"), + new CacheConfiguration(CACHE2).setGroupName("AaAaBB")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(0); + + return null; + } + }, IgniteCheckedException.class, null); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration(CACHE1).setGroupName("AaAaAa")}; + + startGrid(0); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration(CACHE2).setGroupName("AaAaBB")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(1); + + return null; + } + }, IgniteCheckedException.class, null); + + assertFalse(ignite(0).cacheNames().contains(CACHE2)); + + final Ignite ignite1 = startGrid(1); + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + ignite1.createCache(new CacheConfiguration(CACHE2).setGroupName("AaAaBB")); + + return null; + } + }, CacheException.class, null); + + assertFalse(ignite(0).cacheNames().contains(CACHE2)); + } + + /** + * @throws Exception If failed. + */ + public void testCacheGroupIdConflict2() throws Exception { + ccfgs = new CacheConfiguration[]{new CacheConfiguration("AaAaAa"), + new CacheConfiguration(CACHE2).setGroupName("AaAaBB")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(0); + + return null; + } + }, IgniteCheckedException.class, null); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration("AaAaAa")}; + + startGrid(0); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration(CACHE2).setGroupName("AaAaBB")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(1); + + return null; + } + }, IgniteCheckedException.class, null); + + assertFalse(ignite(0).cacheNames().contains(CACHE2)); + + final Ignite ignite1 = startGrid(1); + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + ignite1.createCache(new CacheConfiguration(CACHE2).setGroupName("AaAaBB")); + + return null; + } + }, CacheException.class, null); + + assertFalse(ignite(0).cacheNames().contains(CACHE2)); + } + + /** + * @throws Exception If failed. + */ + public void testCacheGroupIdConflict3() throws Exception { + ccfgs = new CacheConfiguration[]{new CacheConfiguration(CACHE2).setGroupName("AaAaBB"), + new CacheConfiguration("AaAaAa")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(0); + + return null; + } + }, IgniteCheckedException.class, null); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration(CACHE2).setGroupName("AaAaBB")}; + + startGrid(0); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration("AaAaAa")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(1); + + return null; + } + }, IgniteCheckedException.class, null); + + assertFalse(ignite(0).cacheNames().contains("AaAaAa")); + + final Ignite ignite1 = startGrid(1); + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + ignite1.createCache(new CacheConfiguration("AaAaAa")); + + return null; + } + }, CacheException.class, null); + + assertFalse(ignite(0).cacheNames().contains("AaAaAa")); + } + + /** + * @throws Exception If failed. + */ + public void testCacheGroupNameConflict1() throws Exception { + ccfgs = new CacheConfiguration[]{new CacheConfiguration("cache1"), new CacheConfiguration("cache2").setGroupName("cache1")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(0); + + return null; + } + }, IgniteCheckedException.class, null); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration("cache1")}; + + startGrid(0); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration("cache2").setGroupName("cache1")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(1); + + return null; + } + }, IgniteCheckedException.class, null); + + assertFalse(ignite(0).cacheNames().contains("cache2")); + + final Ignite ignite1 = startGrid(1); + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + ignite1.createCache(new CacheConfiguration("cache2").setGroupName("cache1")); + + return null; + } + }, CacheException.class, null); + + assertFalse(ignite(0).cacheNames().contains("cache2")); + } + + /** + * @throws Exception If failed. + */ + public void testCacheGroupNameConflict2() throws Exception { + ccfgs = new CacheConfiguration[]{new CacheConfiguration("cache2").setGroupName("cache1"), new CacheConfiguration("cache1")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(0); + + return null; + } + }, IgniteCheckedException.class, null); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration("cache2").setGroupName("cache1")}; + + startGrid(0); + + ccfgs = new CacheConfiguration[]{new CacheConfiguration("cache1")}; + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + startGrid(1); + + return null; + } + }, IgniteCheckedException.class, null); + + assertFalse(ignite(0).cacheNames().contains("cache1")); + + final Ignite ignite1 = startGrid(1); + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + ignite1.createCache(new CacheConfiguration("cache1")); + + return null; + } + }, CacheException.class, null); + + assertFalse(ignite(0).cacheNames().contains("cache1")); + } + + /** + * @throws Exception If failed. + */ + public void testConfigurationConsistencyValidation() throws Exception { + startGrids(2); + + client = true; + + startGrid(2); + + ignite(0).createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1, false)); + + for (int i = 0; i < 3; i++) { + try { + ignite(i).createCache(cacheConfiguration(GROUP1, "c2", REPLICATED, ATOMIC, Integer.MAX_VALUE, false)); + + fail(); + } + catch (CacheException e) { + assertTrue("Unexpected message: " + e.getMessage(), + e.getMessage().contains("Cache mode mismatch for caches related to the same group [groupName=grp1")); + } + + try { + ignite(i).createCache(cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 2, false)); + + fail(); + } + catch (CacheException e) { + assertTrue("Unexpected message: " + e.getMessage(), + e.getMessage().contains("Backups mismatch for caches related to the same group [groupName=grp1")); + } + } + } + + /** + * @return Cache configurations. + */ + private CacheConfiguration[] interceptorConfigurations() { + CacheConfiguration[] ccfgs = new CacheConfiguration[6]; + + ccfgs[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 2, false).setInterceptor(new Interceptor1()); + ccfgs[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 2, false).setInterceptor(new Interceptor2()); + ccfgs[2] = cacheConfiguration(GROUP1, "c3", PARTITIONED, TRANSACTIONAL, 2, false).setInterceptor(new Interceptor1()); + ccfgs[3] = cacheConfiguration(GROUP1, "c4", PARTITIONED, TRANSACTIONAL, 2, false).setInterceptor(new Interceptor2()); + ccfgs[4] = cacheConfiguration(GROUP1, "c5", PARTITIONED, ATOMIC, 2, false); + ccfgs[5] = cacheConfiguration(GROUP1, "c6", PARTITIONED, TRANSACTIONAL, 2, false); + + return ccfgs; + } + + /** + * Tests caches in the same group with different {@link CacheInterceptor}s. + * + * @throws Exception If failed. + */ + public void testInterceptors() throws Exception { + for (int i = 0; i < 4; i++) { + ccfgs = interceptorConfigurations(); + + startGrid(i); + } + + Ignite node = ignite(0); + + checkInterceptorPut(node.cache("c1"), "v1"); + checkInterceptorPut(node.cache("c2"), "v2"); + checkInterceptorPut(node.cache("c3"), "v1"); + checkInterceptorPut(node.cache("c4"), "v2"); + + checkCache(0, "c5", 10); + checkCache(0, "c6", 10); + } + + /** + * @param cache Cache. + * @param expVal Expected value. + */ + private void checkInterceptorPut(IgniteCache cache, String expVal) { + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + for (int i = 0; i < 10; i++) { + Integer key = rnd.nextInt(); + + cache.put(key, i); + + assertEquals(expVal, cache.get(key)); + } + } + + /** + * @return Cache configurations. + */ + private CacheConfiguration[] cacheStoreConfigurations() { + CacheConfiguration[] ccfgs = new CacheConfiguration[6]; + + ccfgs[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 2, false). + setCacheStoreFactory(new StoreFactory1()).setReadThrough(true).setWriteThrough(true); + + ccfgs[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 2, false). + setCacheStoreFactory(new StoreFactory2()).setReadThrough(true).setWriteThrough(true); + + ccfgs[2] = cacheConfiguration(GROUP1, "c3", PARTITIONED, TRANSACTIONAL, 2, false). + setCacheStoreFactory(new StoreFactory1()).setReadThrough(true).setWriteThrough(true); + + ccfgs[3] = cacheConfiguration(GROUP1, "c4", PARTITIONED, TRANSACTIONAL, 2, false). + setCacheStoreFactory(new StoreFactory2()).setReadThrough(true).setWriteThrough(true); + + ccfgs[4] = cacheConfiguration(GROUP1, "c5", PARTITIONED, ATOMIC, 2, false); + ccfgs[5] = cacheConfiguration(GROUP1, "c6", PARTITIONED, TRANSACTIONAL, 2, false); + + return ccfgs; + } + + /** + * Tests caches in the same group with different {@link CacheStore}s. + * + * @throws Exception If failed. + */ + public void testCacheStores() throws Exception { + for (int i = 0; i < 4; i++) { + ccfgs = cacheStoreConfigurations(); + + startGrid(i); + } + + Ignite node = ignite(0); + + checkStorePut(node.cache("c1"), Store1.map); + assertTrue(Store2.map.isEmpty()); + + checkStorePut(node.cache("c3"), Store1.map); + assertTrue(Store2.map.isEmpty()); + + Store1.map.clear(); + + checkStorePut(node.cache("c2"), Store2.map); + assertTrue(Store1.map.isEmpty()); + + checkStorePut(node.cache("c4"), Store2.map); + assertTrue(Store1.map.isEmpty()); + + Store2.map.clear(); + + checkCache(0, "c5", 10); + checkCache(0, "c6", 10); + + assertTrue(Store1.map.isEmpty()); + assertTrue(Store2.map.isEmpty()); + } + + /** + * @param cache Cache. + * @param storeMap Cache store data. + */ + private void checkStorePut(IgniteCache cache, ConcurrentHashMap storeMap) { + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + for (int i = 0; i < 10; i++) { + Integer key = rnd.nextInt(); + + storeMap.put(key, i); + + assertEquals(i, cache.get(key)); + + cache.put(key, 10_000); + + assertEquals(10_000, cache.get(key)); + assertEquals(10_000, storeMap.get(key)); + } + } + + /** + * @return Cache configurations. + */ + private CacheConfiguration[] mapperConfigurations() { + CacheConfiguration[] ccfgs = new CacheConfiguration[6]; + + ccfgs[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 2, false).setAffinityMapper(new Mapper1()); + ccfgs[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 2, false).setAffinityMapper(new Mapper2()); + ccfgs[2] = cacheConfiguration(GROUP1, "c3", PARTITIONED, TRANSACTIONAL, 2, false).setAffinityMapper(new Mapper1()); + ccfgs[3] = cacheConfiguration(GROUP1, "c4", PARTITIONED, TRANSACTIONAL, 2, false).setAffinityMapper(new Mapper2()); + ccfgs[4] = cacheConfiguration(GROUP1, "c5", PARTITIONED, ATOMIC, 2, false); + ccfgs[5] = cacheConfiguration(GROUP1, "c6", PARTITIONED, TRANSACTIONAL, 2, false); + + return ccfgs; + } + + /** + * @throws Exception If failed. + */ + public void testAffinityMappers() throws Exception { + for (int i = 0; i < 4; i++) { + ccfgs = mapperConfigurations(); + + startGrid(i); + } + + for (int i = 0; i < 4; i++) + checkAffinityMappers(ignite(i)); + + client = true; + + startGrid(4); + + checkAffinityMappers(ignite(4)); + + for (int i = 0; i < 5; i++) { + checkCache(i, "c1", 10); + checkCache(i, "c2", 10); + checkCache(i, "c3", 10); + checkCache(i, "c4", 10); + checkCache(i, "c5", 10); + checkCache(i, "c6", 10); + } + } + + /** + * @param node Node. + */ + private void checkAffinityMappers(Ignite node) { + Affinity aff1 = node.affinity("c1"); + Affinity aff2 = node.affinity("c2"); + Affinity aff3 = node.affinity("c3"); + Affinity aff4 = node.affinity("c4"); + Affinity aff5 = node.affinity("c5"); + Affinity aff6 = node.affinity("c6"); + + RendezvousAffinityFunction func = new RendezvousAffinityFunction(); + + for (int i = 0; i < 100; i++) { + MapperTestKey1 k = new MapperTestKey1(i, i + 10); + + assertEquals(i, aff1.partition(k)); + assertEquals(i, aff3.partition(k)); + assertEquals(i + 10, aff2.partition(k)); + assertEquals(i + 10, aff4.partition(k)); + + int part; + + if (node.configuration().getMarshaller() instanceof BinaryMarshaller) + part = func.partition(node.binary().toBinary(k)); + else + part = func.partition(k); + + assertEquals(part, aff5.partition(k)); + assertEquals(part, aff6.partition(k)); + } + } + + /** + * @throws Exception If failed. + */ + public void testContinuousQueriesMultipleGroups1() throws Exception { + continuousQueriesMultipleGroups(1); + } + + /** + * @throws Exception If failed. + */ + public void testContinuousQueriesMultipleGroups2() throws Exception { + continuousQueriesMultipleGroups(4); + } + + /** + * @param srvs Number of server nodes. + * @throws Exception If failed. + */ + private void continuousQueriesMultipleGroups(int srvs) throws Exception { + Ignite srv0 = startGrids(srvs); + + client = true; + + Ignite client = startGrid(srvs); + + client.createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1, false)); + client.createCache(cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1, false)); + client.createCache(cacheConfiguration(GROUP1, "c3", PARTITIONED, ATOMIC, 1, false)); + + client.createCache(cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1, false)); + client.createCache(cacheConfiguration(GROUP2, "c5", PARTITIONED, ATOMIC, 1, false)); + client.createCache(cacheConfiguration(GROUP2, "c6", PARTITIONED, TRANSACTIONAL, 1, false)); + + client.createCache(cacheConfiguration(null, "c7", PARTITIONED, ATOMIC, 1, false)); + client.createCache(cacheConfiguration(null, "c8", PARTITIONED, TRANSACTIONAL, 1, false)); + + String[] cacheNames = {"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8"}; + + AtomicInteger c1 = registerListener(client, "c1"); + + for (String cache : cacheNames) + srv0.cache(cache).put(1, 1); + + waitForEvents(c1, 1); + + for (String cache : cacheNames) + srv0.cache(cache).put(1, 1); + + waitForEvents(c1, 1); + } + + /** + * @throws Exception If failed. + */ + public void testCacheIdSort() throws Exception { + Ignite node = startGrid(0); + + final List caches = new ArrayList<>(3); + + caches.add(node.createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1, false) + .setAffinity(new RendezvousAffinityFunction(false, 8)))); + caches.add(node.createCache(cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 1, false) + .setAffinity(new RendezvousAffinityFunction(false, 8)))); + caches.add(node.createCache(cacheConfiguration(GROUP1, "c3", PARTITIONED, ATOMIC, 1, false) + .setAffinity(new RendezvousAffinityFunction(false, 8)))); + + Affinity aff = node.affinity("c1"); + + final List keys = new ArrayList<>(); + + for (int i = 0; i < 1_000_000; i++) { + if (aff.partition(i) == 0) { + keys.add(i); + + if (keys.size() >= 10_000) + break; + } + } + + assertEquals(10_000, keys.size()); + + final long stopTime = System.currentTimeMillis() + 10_000; + + GridTestUtils.runMultiThreaded(new Callable() { + @Override public Void call() throws Exception { + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + while (System.currentTimeMillis() < stopTime) { + for (int i = 0; i < 100; i++) { + IgniteCache cache = caches.get(rnd.nextInt(3)); + + Integer key = keys.get(rnd.nextInt(10_000)); + + if (rnd.nextFloat() > 0.8f) + cache.remove(key); + else + cache.put(key, key); + } + } + + return null; + } + }, 5, "update-thread"); + + CacheGroupContext grp = cacheGroup(node, GROUP1); + + Integer cacheId = null; + + GridIterator it = grp.offheap().partitionIterator(0); + + int c = 0; + + while (it.hasNext()) { + CacheDataRow row = it.next(); + + if (cacheId == null || cacheId != row.cacheId()) { + cacheId = row.cacheId(); + + c++; + } + } + + assertEquals(3, c); + } + + /** + * @throws Exception If failed. + */ + public void testRestartsAndCacheCreateDestroy() throws Exception { + final int SRVS = 5; + + startGrids(SRVS); + + client = true; + + final Ignite clientNode = startGrid(SRVS); + + client = false; + + final int CACHES = 10; + + final AtomicReferenceArray caches = new AtomicReferenceArray<>(CACHES); + + for (int i = 0; i < 10; i++) { + CacheAtomicityMode atomicityMode = i % 2 == 0 ? ATOMIC : TRANSACTIONAL; + + caches.set(i, + clientNode.createCache(cacheConfiguration(GROUP1, "c" + i, PARTITIONED, atomicityMode, 0, false))); + } + + final AtomicBoolean stop = new AtomicBoolean(); + final AtomicInteger cacheCntr = new AtomicInteger(); + + try { + for (int i = 0; i < 10; i++) { + stop.set(false); + + final AtomicReference err = new AtomicReference<>(); + + log.info("Iteration: " + i); + + IgniteInternalFuture restartFut = GridTestUtils.runAsync(new Runnable() { + @Override public void run() { + try { + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + while (!stop.get()) { + int node = rnd.nextInt(SRVS); + + log.info("Stop node: " + node); + + stopGrid(node); + + U.sleep(500); + + log.info("Start node: " + node); + + startGrid(node); + + try { + if (rnd.nextBoolean()) + awaitPartitionMapExchange(); + } + catch (Exception ignore) { + // No-op. + } + } + } + catch (Exception e){ + log.error("Unexpected error: " + e, e); + + err.set(e); + + stop.set(true); + } + } + }); + + IgniteInternalFuture cacheFut = GridTestUtils.runAsync(new Runnable() { + @Override public void run() { + try { + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + while (!stop.get()) { + int idx = rnd.nextInt(CACHES); + + IgniteCache cache = caches.get(idx); + + if (cache != null && caches.compareAndSet(idx, cache, null)) { + log.info("Destroy cache: " + cache.getName()); + + clientNode.destroyCache(cache.getName()); + + CacheAtomicityMode atomicityMode = rnd.nextBoolean() ? ATOMIC : TRANSACTIONAL; + + String name = "newName-" + cacheCntr.incrementAndGet(); + + cache = clientNode.createCache( + cacheConfiguration(GROUP1, name, PARTITIONED, atomicityMode, 0, false)); + + caches.set(idx, cache); + } + } + } + catch (Exception e){ + log.error("Unexpected error: " + e, e); + + err.set(e); + + stop.set(true); + } + } + }); + + IgniteInternalFuture opFut = GridTestUtils.runMultiThreadedAsync(new Runnable() { + @Override public void run() { + try { + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + while (!stop.get()) { + int idx = rnd.nextInt(CACHES); + + IgniteCache cache = caches.get(idx); + + if (cache != null && caches.compareAndSet(idx, cache, null)) { + for (int i = 0; i < 10; i++) + cacheOperation(rnd, cache); + + caches.set(idx, cache); + } + } + } + catch (Exception e) { + err.set(e); + + log.error("Unexpected error: " + e, e); + + stop.set(true); + } + } + }, 8, "op-thread"); + + Thread.sleep(10_000); + + stop.set(true); + + restartFut.get(); + cacheFut.get(); + opFut.get(); + + assertNull("Unexpected error during test, see log for details", err.get()); + + awaitPartitionMapExchange(); + + Set cacheIds = new HashSet<>(); + + for (int c = 0; c < CACHES; c++) { + IgniteCache cache = caches.get(c); + + assertNotNull(cache); + + assertTrue(cacheIds.add(CU.cacheId(cache.getName()))); + } + + for (int n = 0; n < SRVS; n++) { + CacheGroupContext grp = cacheGroup(ignite(n), GROUP1); + + assertNotNull(grp); + + for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) { + Map cachesMap = GridTestUtils.getFieldValue(part, "cacheMaps"); + + assertTrue(cachesMap.size() <= cacheIds.size()); + + for (Integer cacheId : cachesMap.keySet()) + assertTrue(cachesMap.containsKey(cacheId)); + } + } + } + } + finally { + stop.set(true); + } + } + + /** + * @param cntr Counter. + * @param expEvts Expected events number. + * @throws Exception If failed. + */ + private void waitForEvents(final AtomicInteger cntr, final int expEvts) throws Exception { + GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + if (cntr.get() < expEvts) + log.info("Wait for events [rcvd=" + cntr.get() + ", exp=" + expEvts + ']'); + + return false; + } + }, 5000); + + assertEquals(expEvts, cntr.get()); + assertTrue(cntr.compareAndSet(expEvts, 0)); + } + + /** + * @param node Node. + * @param cacheName Cache name. + * @return Received events counter. + */ + private AtomicInteger registerListener(Ignite node, String cacheName) { + ContinuousQuery qry = new ContinuousQuery(); + + final AtomicInteger cntr = new AtomicInteger(); + + qry.setLocalListener(new CacheEntryUpdatedListener() { + @Override public void onUpdated(Iterable iterable) { + for (Object evt : iterable) + cntr.incrementAndGet(); + } + }); + + node.cache(cacheName).query(qry); + + return cntr; + } + + /** + * + */ + static class Mapper1 implements AffinityKeyMapper { + /** {@inheritDoc} */ + @Override public Object affinityKey(Object key) { + if (key instanceof MapperTestKey1) + return ((MapperTestKey1)key).p1; + else if (key instanceof BinaryObject) + ((BinaryObject) key).field("p1"); + + return key; + } + + /** {@inheritDoc} */ + @Override public void reset() { + // No-op. + } + } + + /** + * + */ + static class Mapper2 implements AffinityKeyMapper { + /** {@inheritDoc} */ + @Override public Object affinityKey(Object key) { + if (key instanceof MapperTestKey1) + return ((MapperTestKey1)key).p2; + else if (key instanceof BinaryObject) + ((BinaryObject) key).field("p2"); + + return key; + } + + /** {@inheritDoc} */ + @Override public void reset() { + // No-op. + } + } + + /** + * + */ + static class MapperTestKey1 { + /** */ + final int p1; + + /** */ + final int p2; + + /** + * @param p1 Field1. + * @param p2 Field2. + */ + public MapperTestKey1(int p1, int p2) { + this.p1 = p1; + this.p2 = p2; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + MapperTestKey1 testKey1 = (MapperTestKey1)o; + + return p1 == testKey1.p1 && p2 == testKey1.p2; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int res = p1; + res = 31 * res + p2; + return res; + } + } + + /** + * + */ + static class Interceptor1 extends CacheInterceptorAdapter { + /** {@inheritDoc} */ + @Override public Object onBeforePut(Cache.Entry entry, Object newVal) { + return "v1"; + } + } + + /** + * + */ + static class Interceptor2 extends CacheInterceptorAdapter { + /** {@inheritDoc} */ + @Override public Object onBeforePut(Cache.Entry entry, Object newVal) { + return "v2"; + } + } + + /** + * + */ + static class StoreFactory1 implements Factory { + /** {@inheritDoc} */ + @Override public CacheStore create() { + return new Store1(); + } + } + + /** + * + */ + static class Store1 extends CacheStoreAdapter { + /** */ + static ConcurrentHashMap map = new ConcurrentHashMap<>(); + + /** {@inheritDoc} */ + @Override public Object load(Object key) throws CacheLoaderException { + return map.get(key); + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry entry) throws CacheWriterException { + map.put(entry.getKey(), entry.getValue()); + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) throws CacheWriterException { + map.remove(key); + } + } + + /** + * + */ + static class StoreFactory2 implements Factory { + /** {@inheritDoc} */ + @Override public CacheStore create() { + return new Store2(); + } + } + + /** + * + */ + static class Store2 extends CacheStoreAdapter { + /** */ + static ConcurrentHashMap map = new ConcurrentHashMap<>(); + + /** {@inheritDoc} */ + @Override public Object load(Object key) throws CacheLoaderException { + return map.get(key); + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry entry) throws CacheWriterException { + map.put(entry.getKey(), entry.getValue()); + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) throws CacheWriterException { + map.remove(key); + } + } + + /** + * @param rnd Random. + * @param cache Cache. + */ + private void cacheOperation(ThreadLocalRandom rnd, IgniteCache cache) { + final int KEYS = 10_000; + + Integer key = rnd.nextInt(KEYS); + + switch (rnd.nextInt(6)) { + case 0: + cache.put(key, 1); + + break; + + case 1: + cache.get(key); + + break; + + case 2: + cache.remove(key); + + break; + + case 3: + cache.localPeek(key); + + break; + + case 4: + Set keys = new HashSet<>(); + + for (int i = 0; i < 5; i++) + keys.add(rnd.nextInt(KEYS)); + + cache.getAll(keys); + + break; + + case 5: + Map map = new TreeMap<>(); + + for (int i = 0; i < 5; i++) + map.put(rnd.nextInt(KEYS), i); + + cache.putAll(map); + + break; + } + } + + /** + * + */ + static class Key1 implements Serializable { + /** */ + private int id; + + /** + * @param id ID. + */ + Key1(int id) { + this.id = id; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + Key1 key = (Key1)o; + + return id == key.id; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return id; + } + } + + /** + * + */ + static class Key2 implements Serializable { + /** */ + private int id; + + /** + * @param id ID. + */ + Key2(int id) { + this.id = id; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + Key2 key = (Key2)o; + + return id == key.id; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return id; + } + } + + /** + * + */ + static class Value1 implements Serializable { + /** */ + private int val; + + /** + * @param val Value. + */ + public Value1(int val) { + this.val = val; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + Value1 val1 = (Value1)o; + + return val == val1.val; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return val; + } + } + + /** + * + */ + static class Value2 implements Serializable { + /** */ + private int val; + + /** + * @param val Value. + */ + public Value2(int val) { + this.val = val; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + Value2 val2 = (Value2)o; + + return val == val2.val; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return val; + } + } + + /** + * @param grpName Cache group name. + * @param name Cache name. + * @param cacheMode Cache mode. + * @param atomicityMode Atomicity mode. + * @param backups Backups number. + * @param heapCache On heap cache flag. + * @return Cache configuration. + */ + private CacheConfiguration cacheConfiguration( + String grpName, + String name, + CacheMode cacheMode, + CacheAtomicityMode atomicityMode, + int backups, + boolean heapCache + ) { + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setName(name); + ccfg.setGroupName(grpName); + ccfg.setAtomicityMode(atomicityMode); + ccfg.setBackups(backups); + ccfg.setCacheMode(cacheMode); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setOnheapCacheEnabled(heapCache); + + return ccfg; + } + + /** + * @param idx Node index. + * @param grpName Cache group name. + * @param expGrp {@code True} if cache group should be created. + * @throws IgniteCheckedException If failed. + */ + private void checkCacheGroup(int idx, final String grpName, final boolean expGrp) throws IgniteCheckedException { + final IgniteKernal node = (IgniteKernal)ignite(idx); + + assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + return expGrp == (cacheGroup(node, grpName) != null); + } + }, 1000)); + + assertNotNull(node.context().cache().cache(CU.UTILITY_CACHE_NAME)); + } + + /** + * @param node Node. + * @param grpName Cache group name. + * @return Cache group. + */ + private CacheGroupContext cacheGroup(Ignite node, String grpName) { + for (CacheGroupContext grp : ((IgniteKernal)node).context().cache().cacheGroups()) { + if (grpName.equals(grp.name())) + return grp; + } + + return null; + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java index 81c07994d5abb..7725b1943d08a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java @@ -1022,7 +1022,7 @@ private T2 offheapKeysCount(int nodeIdx, int part) throws Igni // Swap and offheap are disabled for near cache. IgniteCacheOffheapManager offheapManager = ctx.isNear() ? ctx.near().dht().context().offheap() : ctx.offheap(); //First count entries... - int cnt = (int)offheapManager.entriesCount(part); + int cnt = (int)offheapManager.cacheEntriesCount(ctx.cacheId(), part); GridCacheAffinityManager affinity = ctx.affinity(); AffinityTopologyVersion topVer = affinity.affinityTopologyVersion(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStartTest.java index eb8077fe5b8d1..c889c31ac7b4a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStartTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStartTest.java @@ -18,9 +18,9 @@ package org.apache.ignite.internal.processors.cache; import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.util.lang.GridAbsPredicate; import org.apache.ignite.internal.util.typedef.internal.CU; @@ -176,8 +176,9 @@ private CacheConfiguration cacheConfiguration(String cacheName) { * @param idx Node index. * @param cacheName Cache name. * @param expCache {@code True} if cache should be created. + * @throws IgniteCheckedException If failed. */ - private void checkCache(int idx, final String cacheName, final boolean expCache) throws IgniteInterruptedCheckedException { + private void checkCache(int idx, final String cacheName, final boolean expCache) throws IgniteCheckedException { final IgniteKernal node = (IgniteKernal)ignite(idx); assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteOnePhaseCommitInvokeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteOnePhaseCommitInvokeTest.java index a5cb3f2ef35a0..bccebaa0ab505 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteOnePhaseCommitInvokeTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteOnePhaseCommitInvokeTest.java @@ -127,10 +127,12 @@ private void onePhaseInvoke(final boolean withOldVal, final Ignite clientNode = startGrid(1); + final int grpId = groupIdForCache(srv0, CACHE_NAME); + TestRecordingCommunicationSpi.spi(srv0).blockMessages(new IgniteBiPredicate() { @Override public boolean apply(ClusterNode node, Message msg) { return msg instanceof GridDhtPartitionSupplyMessage && - ((GridDhtPartitionSupplyMessage)msg).cacheId() == CU.cacheId(CACHE_NAME); + ((GridDhtPartitionSupplyMessage)msg).groupId() == grpId; } }); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorGridSplitCacheTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorGridSplitCacheTest.java index 057b0d62fc287..2e551f946ed85 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorGridSplitCacheTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorGridSplitCacheTest.java @@ -202,6 +202,8 @@ private void clearAll() { /** * Resolves split by client node join. + * + * @throws Exception If failed. */ private void resolveSplit() throws Exception { startGrid(RESOLVER_GRID_IDX); @@ -305,6 +307,7 @@ private boolean hasSplit(Collection nodes) { return true; } + /** {@inheritDoc} */ @Override public void start() throws IgniteException { if (ignite.cluster().localNode().isClient()) return; @@ -327,12 +330,15 @@ private boolean hasSplit(Collection nodes) { /** * @param node Node. + * @return {@code True} if this is marker node. */ private boolean isMarkerNode(ClusterNode node) { return node.isClient() && node.attribute(ACTIVATOR_NODE_ATTR) != null; } - @Override public void stop() throws IgniteException { + /** {@inheritDoc} */ + @Override public void stop() { + // No-op. } } } \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxStoreExceptionAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxStoreExceptionAbstractSelfTest.java index 872fe7797bcc7..863ab38ad74ea 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxStoreExceptionAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxStoreExceptionAbstractSelfTest.java @@ -370,7 +370,7 @@ private void checkValue(final Integer key, boolean putBefore) throws Exception { GridCacheAdapter cache = grid.internalCache(DEFAULT_CACHE_NAME); - GridCacheMapEntry entry = cache.map().getEntry(cache.context().toCacheKeyObject(key)); + GridCacheMapEntry entry = cache.map().getEntry(cache.context(), cache.context().toCacheKeyObject(key)); log.info("Entry: " + entry); @@ -383,7 +383,7 @@ private void checkValue(final Integer key, boolean putBefore) throws Exception { } if (cache.isNear()) { - entry = ((GridNearCacheAdapter)cache).dht().map().getEntry(cache.context().toCacheKeyObject(key)); + entry = ((GridNearCacheAdapter)cache).dht().map().getEntry(cache.context(), cache.context().toCacheKeyObject(key)); log.info("Dht entry: " + entry); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java index 06d62e404225f..5dace92d028c4 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java @@ -175,7 +175,7 @@ private CacheConfiguration createCacheConfig() { for (int i = 0; i < gridCount(); i++) { GridCacheAdapter c = ((IgniteKernal)grid(i)).internalCache(DEFAULT_CACHE_NAME); - for (GridCacheEntryEx e : c.map().entries()) { + for (GridCacheEntryEx e : c.map().entries(c.context().cacheId())) { Object key = e.key().value(c.context().cacheObjectContext(), false); Object val = CU.value(e.rawGet(), c.context(), false); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheQueueCleanupSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheQueueCleanupSelfTest.java index 654e729e8975c..75183b0c36609 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheQueueCleanupSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheQueueCleanupSelfTest.java @@ -21,9 +21,11 @@ import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteQueue; import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CachePeekMode; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.CollectionConfiguration; import org.apache.ignite.internal.IgniteInternalFuture; @@ -177,20 +179,15 @@ public void testCleanup() throws Exception { // Check that items of removed queue are removed, items of new queue not. assertTrue(GridTestUtils.waitForCondition(new PAX() { @SuppressWarnings("WhileLoopReplaceableByForEach") - @Override public boolean applyx() { + @Override public boolean applyx() throws IgniteCheckedException { int cnt = 0; for (int i = 0; i < gridCount(); i++) { GridCacheAdapter cache = - ((IgniteKernal)grid(i)).context().cache().internalCache(queueCacheName); - - Iterator entries = cache.map().entries().iterator(); + grid(i).context().cache().internalCache(queueCacheName); - while (entries.hasNext()) { + for (Object e : cache.localEntries(new CachePeekMode[]{CachePeekMode.ALL})) cnt++; - - entries.next(); - } } if (cnt > 501) { // 500 items + header. diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetAbstractSelfTest.java index 517a7ad1abecc..53c1eb759050b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetAbstractSelfTest.java @@ -34,14 +34,14 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteSet; import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CachePeekMode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.CollectionConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; -import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager; import org.apache.ignite.internal.util.lang.GridAbsPredicate; import org.apache.ignite.internal.util.typedef.internal.U; @@ -804,17 +804,12 @@ private void testCleanup(boolean collocated) throws Exception { GridCacheContext cctx = GridTestUtils.getFieldValue(set0, "cctx"); for (int i = 0; i < gridCount(); i++) { - Iterator entries = - (grid(i)).context().cache().internalCache(cctx.name()).map().entries().iterator(); + GridCacheAdapter cache = grid(i).context().cache().internalCache(cctx.name()); - while (entries.hasNext()) { - GridCacheEntryEx entry = entries.next(); + for (Object e : cache.localEntries(new CachePeekMode[]{CachePeekMode.ALL})) { + cnt++; - if (entry.hasValue()) { - cnt++; - - log.info("Unexpected entry: " + entry); - } + log.info("Unexpected entry: " + e); } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetFailoverAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetFailoverAbstractSelfTest.java index 1e11c06963957..f8af2a24e5205 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetFailoverAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetFailoverAbstractSelfTest.java @@ -29,6 +29,7 @@ import org.apache.ignite.IgniteSet; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.internal.processors.datastructures.SetItemKey; @@ -174,8 +175,9 @@ public void testNodeRestart() throws Exception { Set setIds = new HashSet<>(); for (int i = 0; i < gridCount(); i++) { - Iterator entries = - grid(i).context().cache().internalCache(DEFAULT_CACHE_NAME).map().entries().iterator(); + GridCacheAdapter cache = grid(i).context().cache().internalCache(DEFAULT_CACHE_NAME); + + Iterator entries = cache.map().entries(cache.context().cacheId()).iterator(); while (entries.hasNext()) { GridCacheEntryEx entry = entries.next(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedQueueNoBackupsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedQueueNoBackupsTest.java index 67b7f8fcee13d..aa075c0a9eb16 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedQueueNoBackupsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedQueueNoBackupsTest.java @@ -24,6 +24,7 @@ import org.apache.ignite.cache.CacheMode; import org.apache.ignite.configuration.CollectionConfiguration; import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.testframework.GridTestUtils; @@ -72,8 +73,9 @@ public void testCollocation() throws Exception { for (int i = 0; i < gridCount(); i++) { IgniteKernal grid = (IgniteKernal)grid(i); - Iterator entries = - grid.context().cache().internalCache(cctx.name()).map().entries().iterator(); + GridCacheAdapter cache = grid.context().cache().internalCache(cctx.name()); + + Iterator entries = cache.map().entries(cache.context().cacheId()).iterator(); if (entries.hasNext()) { if (setNodeId == null) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedSetNoBackupsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedSetNoBackupsSelfTest.java index a73aa4a89c239..4daaeca01d243 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedSetNoBackupsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedSetNoBackupsSelfTest.java @@ -22,6 +22,7 @@ import java.util.UUID; import org.apache.ignite.configuration.CollectionConfiguration; import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.testframework.GridTestUtils; @@ -57,8 +58,9 @@ public void testCollocation() throws Exception { for (int i = 0; i < gridCount(); i++) { IgniteKernal grid = (IgniteKernal)grid(i); - Iterator entries = - grid.context().cache().internalCache(cctx.name()).map().entries().iterator(); + GridCacheAdapter cache = grid.context().cache().internalCache(cctx.name()); + + Iterator entries = cache.map().entries(cache.context().cacheId()).iterator(); if (entries.hasNext()) { if (setNodeId == null) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheDiscoveryDataConcurrentJoinTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheDiscoveryDataConcurrentJoinTest.java index a80830af924c1..4cf89b2521031 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheDiscoveryDataConcurrentJoinTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheDiscoveryDataConcurrentJoinTest.java @@ -57,6 +57,9 @@ public class CacheDiscoveryDataConcurrentJoinTest extends GridCommonAbstractTest /** */ private ThreadLocal staticCaches = new ThreadLocal<>(); + /** */ + private boolean withCacheGrp; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); @@ -158,10 +161,21 @@ public void testConcurrentJoin() throws Exception { } } + checkCacheDiscoveryDataConsistent(); + stopAllGrids(); } } + /** + * @throws Exception If failed. + */ + public void testConcurrentJoinCacheWithGroup() throws Exception { + withCacheGrp = true; + + testConcurrentJoin(); + } + /** * @param caches Number of caches. * @return Cache configurations. @@ -186,6 +200,9 @@ private CacheConfiguration cacheConfiguration(String cacheName) { ccfg.setAtomicityMode(TRANSACTIONAL); ccfg.setAffinity(new RendezvousAffinityFunction(false, 16)); + if (withCacheGrp) + ccfg.setGroupName("group1"); + return ccfg; } /** diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGroupsPreloadTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGroupsPreloadTest.java new file mode 100644 index 0000000000000..88596380c2aca --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGroupsPreloadTest.java @@ -0,0 +1,194 @@ +/* + * 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 org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +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.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class CacheGroupsPreloadTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final String CACHE1 = "cache1"; + + /** */ + private static final String CACHE2 = "cache2"; + + /** */ + private static final String GROUP1 = "group1"; + + /** */ + private static final String GROUP2 = "group2"; + + /** */ + private CacheAtomicityMode atomicityMode = CacheAtomicityMode.ATOMIC; + + /** */ + private CacheMode cacheMode = CacheMode.PARTITIONED; + + /** */ + private boolean sameGrp = true; + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); + + CacheConfiguration cfg1 = defaultCacheConfiguration() + .setName(CACHE1) + .setGroupName(GROUP1) + .setCacheMode(cacheMode) + .setAtomicityMode(atomicityMode) + .setBackups(1); + + CacheConfiguration cfg2 = new CacheConfiguration(cfg1) + .setName(CACHE2); + + if (!sameGrp) + cfg2.setGroupName(GROUP2); + + cfg.setCacheConfiguration(cfg1, cfg2); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testCachePreload1() throws Exception { + cachePreloadTest(); + } + + /** + * @throws Exception If failed. + */ + public void testCachePreload2() throws Exception { + atomicityMode = CacheAtomicityMode.TRANSACTIONAL; + + cachePreloadTest(); + } + + /** + * @throws Exception If failed. + */ + public void testCachePreload3() throws Exception { + cacheMode = CacheMode.REPLICATED; + + cachePreloadTest(); + } + + /** + * @throws Exception If failed. + */ + public void testCachePreload4() throws Exception { + cacheMode = CacheMode.REPLICATED; + atomicityMode = CacheAtomicityMode.TRANSACTIONAL; + + cachePreloadTest(); + } + + /** + * @throws Exception If failed. + */ + public void testCachePreload5() throws Exception { + sameGrp = false; + + cachePreloadTest(); + } + + /** + * @throws Exception If failed. + */ + public void testCachePreload6() throws Exception { + sameGrp = false; + atomicityMode = CacheAtomicityMode.TRANSACTIONAL; + + cachePreloadTest(); + } + + /** + * @throws Exception If failed. + */ + public void testCachePreload7() throws Exception { + sameGrp = false; + cacheMode = CacheMode.REPLICATED; + + cachePreloadTest(); + } + + /** + * @throws Exception If failed. + */ + public void testCachePreload8() throws Exception { + sameGrp = false; + cacheMode = CacheMode.REPLICATED; + atomicityMode = CacheAtomicityMode.TRANSACTIONAL; + + cachePreloadTest(); + } + + /** + * @throws Exception If failed. + */ + private void cachePreloadTest() throws Exception { + IgniteCache cache = startGrid(0).cache(CACHE1); + + for (int i = 0; i < 1000; i++) + cache.put(i, CACHE1 + "-" + i); + + cache = startGrid(1).cache(CACHE1); + + for (int i = 0; i < 1000; i++) + assertEquals(CACHE1 + "-" + i, cache.get(i)); + + cache = ignite(1).cache(CACHE2); + + for (int i = 0; i < 1000; i++) + cache.put(i, CACHE2 + "-" + i); + + cache = startGrid(2).cache(CACHE1); + + for (int i = 0; i < 1000; i++) + assertEquals(CACHE1 + "-" + i, cache.get(i)); + + cache = ignite(2).cache(CACHE2); + + for (int i = 0; i < 1000; i++) + assertEquals(CACHE2 + "-" + i, cache.get(i)); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLateAffinityAssignmentTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLateAffinityAssignmentTest.java index bc435e2383918..20cef30d73cb3 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLateAffinityAssignmentTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLateAffinityAssignmentTest.java @@ -2008,12 +2008,14 @@ private List> affinity(Ignite node, AffinityTopologyVersion to * @param cacheName Cache name. */ private void blockSupplySend(TestRecordingCommunicationSpi spi, final String cacheName) { + final int grpId = groupIdForCache(spi.ignite(), cacheName); + spi.blockMessages(new IgniteBiPredicate() { @Override public boolean apply(ClusterNode node, Message msg) { if (!msg.getClass().equals(GridDhtPartitionSupplyMessage.class)) return false; - return ((GridDhtPartitionSupplyMessage)msg).cacheId() == CU.cacheId(cacheName); + return ((GridDhtPartitionSupplyMessage)msg).groupId() == grpId; } }); } @@ -2420,7 +2422,7 @@ private boolean calculateAffinity(long topVer, Collection allNodes = ctx.discovery().cacheNodes(topVer0); - for (DynamicCacheDescriptor cacheDesc : ctx.cache().cacheDescriptors()) { + for (DynamicCacheDescriptor cacheDesc : ctx.cache().cacheDescriptors().values()) { if (assignments.get(cacheDesc.cacheId()) != null) continue; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePartitionLossPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePartitionLossPolicySelfTest.java index 5bbeef96f48d3..47fefe5ca8e67 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePartitionLossPolicySelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePartitionLossPolicySelfTest.java @@ -19,7 +19,6 @@ import java.util.Collection; import java.util.Collections; -import java.util.UUID; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import javax.cache.CacheException; @@ -42,7 +41,6 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import org.apache.ignite.util.TestTcpCommunicationSpi; import static org.apache.ignite.cache.CacheMode.PARTITIONED; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; @@ -67,23 +65,8 @@ public class IgniteCachePartitionLossPolicySelfTest extends GridCommonAbstractTe @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - disco.setIpFinder(ipFinder); - cfg.setDiscoverySpi(disco); + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); - if (gridName.matches(".*\\d")) { - String idStr = UUID.randomUUID().toString(); - - char[] chars = idStr.toCharArray(); - - chars[chars.length - 3] = '0'; - chars[chars.length - 2] = '0'; - chars[chars.length - 1] = gridName.charAt(gridName.length() - 1); - - cfg.setNodeId(UUID.fromString(new String(chars))); - } - - cfg.setCommunicationSpi(new TestTcpCommunicationSpi()); cfg.setClientMode(client); CacheConfiguration cacheCfg = new CacheConfiguration<>(CACHE_NAME); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheReadFromBackupTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheReadFromBackupTest.java index 1433daa31fd18..9907937da6dd9 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheReadFromBackupTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheReadFromBackupTest.java @@ -41,7 +41,6 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.lang.IgniteBiPredicate; import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; @@ -196,12 +195,14 @@ public void testGetFromPrimaryPreloadInProgress() throws Exception { TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)ignite.configuration().getCommunicationSpi(); + final int grpId = groupIdForCache(ignite, ccfg.getName()); + spi.blockMessages(new IgniteBiPredicate() { @Override public boolean apply(ClusterNode node, Message msg) { if (!msg.getClass().equals(GridDhtPartitionSupplyMessage.class)) return false; - return ((GridDhtPartitionSupplyMessage)msg).cacheId() == CU.cacheId(ccfg.getName()); + return ((GridDhtPartitionSupplyMessage)msg).groupId() == grpId; } }); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledMultiNodeWithGroupFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledMultiNodeWithGroupFullApiSelfTest.java new file mode 100644 index 0000000000000..3eafe686234bf --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledMultiNodeWithGroupFullApiSelfTest.java @@ -0,0 +1,35 @@ +/* + * 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.dht; + +import org.apache.ignite.configuration.CacheConfiguration; + +/** + * + */ +public class GridCachePartitionedNearDisabledMultiNodeWithGroupFullApiSelfTest + extends GridCachePartitionedNearDisabledMultiNodeFullApiSelfTest { + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { + CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName); + + ccfg.setGroupName("group1"); + + return ccfg; + } +} \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheAtomicProtocolTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheAtomicProtocolTest.java index 888fae385aeb1..749ebe8ad9f1f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheAtomicProtocolTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheAtomicProtocolTest.java @@ -34,12 +34,11 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.TestRecordingCommunicationSpi; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; +import org.apache.ignite.internal.processors.cache.GridCacheGroupIdMessage; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage; import org.apache.ignite.internal.util.lang.GridAbsPredicate; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.G; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiPredicate; import org.apache.ignite.lang.IgniteFuture; @@ -100,11 +99,13 @@ public class IgniteCacheAtomicProtocolTest extends GridCommonAbstractTest { * */ private void blockRebalance() { + final int grpId = groupIdForCache(ignite(0), TEST_CACHE); + for (Ignite node : G.allGrids()) { testSpi(node).blockMessages(new IgniteBiPredicate() { @Override public boolean apply(ClusterNode node, Message msg) { return (msg instanceof GridDhtPartitionSupplyMessage) - && ((GridCacheMessage)msg).cacheId() == CU.cacheId(TEST_CACHE); + && ((GridCacheGroupIdMessage)msg).groupId() == grpId; } }); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicMultiNodeWithGroupFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicMultiNodeWithGroupFullApiSelfTest.java new file mode 100644 index 0000000000000..30337d96393d1 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicMultiNodeWithGroupFullApiSelfTest.java @@ -0,0 +1,34 @@ +/* + * 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.near; + +import org.apache.ignite.configuration.CacheConfiguration; + +/** + * + */ +public class GridCacheAtomicMultiNodeWithGroupFullApiSelfTest extends GridCacheAtomicMultiNodeFullApiSelfTest { + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { + CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName); + + ccfg.setGroupName("group1"); + + return ccfg; + } +} \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearEnabledMultiNodeWithGroupFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearEnabledMultiNodeWithGroupFullApiSelfTest.java new file mode 100644 index 0000000000000..f57d81a9a8be1 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearEnabledMultiNodeWithGroupFullApiSelfTest.java @@ -0,0 +1,35 @@ +/* + * 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.near; + +import org.apache.ignite.configuration.CacheConfiguration; + +/** + * + */ +public class GridCacheAtomicNearEnabledMultiNodeWithGroupFullApiSelfTest extends + GridCacheAtomicNearEnabledMultiNodeFullApiSelfTest { + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { + CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName); + + ccfg.setGroupName("group1"); + + return ccfg; + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearReadersSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearReadersSelfTest.java index 40a3af2069a98..cbb2032302ee2 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearReadersSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearReadersSelfTest.java @@ -253,11 +253,12 @@ public void testTwoNodesTwoKeysOneBackup() throws Exception { awaitPartitionMapExchange(); - GridCacheContext ctx = ((IgniteKernal) g1).internalCache(DEFAULT_CACHE_NAME).context(); + GridCacheContext ctx = ((IgniteKernal)g1).internalCache(DEFAULT_CACHE_NAME).context(); List cacheKeys = F.asList(ctx.toCacheKeyObject(1), ctx.toCacheKeyObject(2)); IgniteInternalFuture f1 = ((IgniteKernal)g1).internalCache(DEFAULT_CACHE_NAME).preloader().request( + ctx, cacheKeys, new AffinityTopologyVersion(2)); @@ -266,6 +267,7 @@ public void testTwoNodesTwoKeysOneBackup() throws Exception { IgniteInternalFuture f2 = ((IgniteKernal)g2).internalCache(DEFAULT_CACHE_NAME).preloader().request( + ((IgniteKernal)g2).internalCache(DEFAULT_CACHE_NAME).context(), cacheKeys, new AffinityTopologyVersion(2)); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeWithGroupFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeWithGroupFullApiSelfTest.java new file mode 100644 index 0000000000000..542628afaab11 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeWithGroupFullApiSelfTest.java @@ -0,0 +1,34 @@ +/* + * 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.near; + +import org.apache.ignite.configuration.CacheConfiguration; + +/** + * + */ +public class GridCachePartitionedMultiNodeWithGroupFullApiSelfTest extends GridCachePartitionedMultiNodeFullApiSelfTest { + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { + CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName); + + ccfg.setGroupName("group1"); + + return ccfg; + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java index 346f908fb54fc..e90b7e18ebdac 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java @@ -268,7 +268,8 @@ public void testIntegrity() throws Exception { break; } - assert evts != null && evts.size() == 2 : "Wrong events received: " + evts; + assertNotNull(evts); + assertEquals("Wrong events received: " + evts, 2, evts.size()); Iterator iter = evts.iterator(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheClientNearCacheExpiryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheClientNearCacheExpiryTest.java index f7164a01aca75..3417ba8513a34 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheClientNearCacheExpiryTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheClientNearCacheExpiryTest.java @@ -28,8 +28,7 @@ import org.apache.ignite.configuration.NearCacheConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; -import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap; -import org.apache.ignite.internal.processors.cache.GridCacheProxyImpl; +import org.apache.ignite.internal.processors.cache.GridCacheLocalConcurrentMap; import org.apache.ignite.internal.processors.cache.IgniteCacheAbstractTest; import org.apache.ignite.internal.processors.cache.IgniteCacheProxy; import org.apache.ignite.internal.util.typedef.internal.U; @@ -84,6 +83,13 @@ public class IgniteCacheClientNearCacheExpiryTest extends IgniteCacheAbstractTes public void testExpirationOnClient() throws Exception { Ignite ignite = grid(NODES - 1); + // Check size of near entries via reflection because entries is filtered for size() API call. + IgniteEx igniteEx = (IgniteEx)ignite; + + GridCacheAdapter internalCache = igniteEx.context().cache().internalCache(DEFAULT_CACHE_NAME); + + GridCacheLocalConcurrentMap map = GridTestUtils.getFieldValue(internalCache, GridCacheAdapter.class, "map"); + assertTrue(ignite.configuration().isClientMode()); IgniteCache cache = ignite.cache(DEFAULT_CACHE_NAME); @@ -103,17 +109,11 @@ public void testExpirationOnClient() throws Exception { assertEquals(i, cacheWithExpiry.localPeek(i)); } + assertEquals(KEYS_COUNT * 2, map.publicSize(internalCache.context().cacheId())); U.sleep(1000); - // Check size of near entries via reflection because entries is filtered for size() API call. - IgniteEx igniteEx = (IgniteEx)ignite; - GridCacheConcurrentMap map = GridTestUtils.getFieldValue( - ((GridCacheProxyImpl)igniteEx.cachex(DEFAULT_CACHE_NAME)).delegate(), - GridCacheAdapter.class, - "map"); - - assertEquals(KEYS_COUNT, map.publicSize()); + assertEquals(KEYS_COUNT, map.publicSize(internalCache.context().cacheId())); assertEquals(KEYS_COUNT, cache.size()); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java index 9d21823b6d372..227fe1ffc0e3d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java @@ -82,6 +82,6 @@ public void testDeferredDeleteTtl() throws Exception { CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext(); for (int i = 0; i < 100; i++) - assertNull(cacheAdapter.map().getEntry(cacheObjects.toCacheKeyObject(cacheObjCtx, null, i, true))); + assertNull(cacheAdapter.map().getEntry(cacheAdapter.context(), cacheObjects.toCacheKeyObject(cacheObjCtx, null, i, true))); } } \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheJdbcBlobStoreNodeRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheJdbcBlobStoreNodeRestartTest.java index 1c29098918a81..83ddf6703d7d9 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheJdbcBlobStoreNodeRestartTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheJdbcBlobStoreNodeRestartTest.java @@ -23,6 +23,9 @@ import org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore; import org.apache.ignite.configuration.NearCacheConfiguration; +/** + * + */ public class IgniteCacheJdbcBlobStoreNodeRestartTest extends IgniteCacheStoreNodeRestartAbstractTest { /** {@inheritDoc} */ @Override protected CacheStore getStore() { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalAtomicWithGroupFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalAtomicWithGroupFullApiSelfTest.java new file mode 100644 index 0000000000000..4597a750c4563 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalAtomicWithGroupFullApiSelfTest.java @@ -0,0 +1,34 @@ +/* + * 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.local; + +import org.apache.ignite.configuration.CacheConfiguration; + +/** + * + */ +public class GridCacheLocalAtomicWithGroupFullApiSelfTest extends GridCacheLocalAtomicFullApiSelfTest { + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { + CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName); + + ccfg.setGroupName("group1"); + + return ccfg; + } +} \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalFullApiSelfTest.java index 0c7a2172dd622..8cb9369e2f7b9 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalFullApiSelfTest.java @@ -22,7 +22,6 @@ import org.apache.ignite.IgniteCache; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.cluster.ClusterNode; -import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.processors.cache.GridCacheAbstractFullApiSelfTest; import org.apache.ignite.internal.util.typedef.F; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalWithGroupFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalWithGroupFullApiSelfTest.java new file mode 100644 index 0000000000000..867a2decbd259 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalWithGroupFullApiSelfTest.java @@ -0,0 +1,34 @@ +/* + * 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.local; + +import org.apache.ignite.configuration.CacheConfiguration; + +/** + * + */ +public class GridCacheLocalWithGroupFullApiSelfTest extends GridCacheLocalFullApiSelfTest { + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { + CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName); + + ccfg.setGroupName("group1"); + + return ccfg; + } +} \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryConcurrentPartitionUpdateTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryConcurrentPartitionUpdateTest.java index 9c7c8364213e5..6c74f7901cd8e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryConcurrentPartitionUpdateTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryConcurrentPartitionUpdateTest.java @@ -35,6 +35,7 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.util.lang.GridAbsPredicate; +import org.apache.ignite.internal.util.typedef.T2; 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.TcpDiscoveryIpFinder; @@ -78,52 +79,74 @@ public class CacheContinuousQueryConcurrentPartitionUpdateTest extends GridCommo * @throws Exception If failed. */ public void testConcurrentUpdatePartitionAtomic() throws Exception { - concurrentUpdatePartition(ATOMIC); + concurrentUpdatePartition(ATOMIC, false); } /** * @throws Exception If failed. */ public void testConcurrentUpdatePartitionTx() throws Exception { - concurrentUpdatePartition(TRANSACTIONAL); + concurrentUpdatePartition(TRANSACTIONAL, false); + } + + /** + * @throws Exception If failed. + */ + public void testConcurrentUpdatePartitionAtomicCacheGroup() throws Exception { + concurrentUpdatePartition(ATOMIC, true); + } + + /** + * @throws Exception If failed. + */ + public void testConcurrentUpdatePartitionTxCacheGroup() throws Exception { + concurrentUpdatePartition(TRANSACTIONAL, true); } /** * @param atomicityMode Cache atomicity mode. + * @param cacheGrp {@code True} if test cache multiple caches in the same group. * @throws Exception If failed. */ - private void concurrentUpdatePartition(CacheAtomicityMode atomicityMode) throws Exception { + private void concurrentUpdatePartition(CacheAtomicityMode atomicityMode, boolean cacheGrp) throws Exception { Ignite srv = startGrid(0); client = true; Ignite client = startGrid(1); - CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME); + List cntrs = new ArrayList<>(); + List caches = new ArrayList<>(); - ccfg.setWriteSynchronizationMode(FULL_SYNC); - ccfg.setAtomicityMode(atomicityMode); + if (cacheGrp) { + for (int i = 0; i < 3; i++) { + CacheConfiguration ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME + i); - IgniteCache clientCache = client.createCache(ccfg); + ccfg.setGroupName("testGroup"); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setAtomicityMode(atomicityMode); - final AtomicInteger evtCnt = new AtomicInteger(); + IgniteCache cache = client.createCache(ccfg); - ContinuousQuery qry = new ContinuousQuery<>(); - - qry.setLocalListener(new CacheEntryUpdatedListener() { - @Override public void onUpdated(Iterable> evts) { - for (CacheEntryEvent evt : evts) { - assertNotNull(evt.getKey()); - assertNotNull(evt.getValue()); + caches.add(cache.getName()); - evtCnt.incrementAndGet(); - } + cntrs.add(startListener(cache).get1()); } - }); + } + else { + CacheConfiguration ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); - clientCache.query(qry); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setAtomicityMode(atomicityMode); - Affinity aff = srv.affinity(DEFAULT_CACHE_NAME); + IgniteCache cache = client.createCache(ccfg); + + caches.add(cache.getName()); + + cntrs.add(startListener(cache).get1()); + } + + Affinity aff = srv.affinity(caches.get(0)); final List keys = new ArrayList<>(); @@ -143,7 +166,10 @@ private void concurrentUpdatePartition(CacheAtomicityMode atomicityMode) throws final int THREADS = 10; final int UPDATES = 1000; - final IgniteCache srvCache = srv.cache(DEFAULT_CACHE_NAME); + final List> srvCaches = new ArrayList<>(); + + for (String cacheName : caches) + srvCaches.add(srv.cache(cacheName)); for (int i = 0; i < 15; i++) { log.info("Iteration: " + i); @@ -152,60 +178,124 @@ private void concurrentUpdatePartition(CacheAtomicityMode atomicityMode) throws @Override public Void call() throws Exception { ThreadLocalRandom rnd = ThreadLocalRandom.current(); - for (int i = 0; i < UPDATES; i++) - srvCache.put(keys.get(rnd.nextInt(KEYS)), i); + for (int i = 0; i < UPDATES; i++) { + for (int c = 0; c < srvCaches.size(); c++) + srvCaches.get(c).put(keys.get(rnd.nextInt(KEYS)), i); + } return null; } }, THREADS, "update"); - GridTestUtils.waitForCondition(new GridAbsPredicate() { - @Override public boolean apply() { - log.info("Events: " + evtCnt.get()); + for (final AtomicInteger evtCnt : cntrs) { + GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + log.info("Events: " + evtCnt.get()); - return evtCnt.get() >= THREADS * UPDATES; - } - }, 5000); + return evtCnt.get() >= THREADS * UPDATES; + } + }, 5000); - assertEquals(THREADS * UPDATES, evtCnt.get()); + assertEquals(THREADS * UPDATES, evtCnt.get()); - evtCnt.set(0); + evtCnt.set(0); + } } } + /** + * @param cache Cache. + * @return Event counter. + */ + private T2 startListener(IgniteCache cache) { + final AtomicInteger evtCnt = new AtomicInteger(); + + ContinuousQuery qry = new ContinuousQuery<>(); + + qry.setLocalListener(new CacheEntryUpdatedListener() { + @Override public void onUpdated(Iterable> evts) { + for (CacheEntryEvent evt : evts) { + assertNotNull(evt.getKey()); + assertNotNull(evt.getValue()); + + if ((Integer)evt.getValue() >= 0) + evtCnt.incrementAndGet(); + } + } + }); + + QueryCursor cur = cache.query(qry); + + return new T2<>(evtCnt, cur); + } + /** * @throws Exception If failed. */ public void testConcurrentUpdatesAndQueryStartAtomic() throws Exception { - concurrentUpdatesAndQueryStart(ATOMIC); + concurrentUpdatesAndQueryStart(ATOMIC, false); } /** * @throws Exception If failed. */ public void testConcurrentUpdatesAndQueryStartTx() throws Exception { - concurrentUpdatesAndQueryStart(TRANSACTIONAL); + concurrentUpdatesAndQueryStart(TRANSACTIONAL, false); + } + + /** + * @throws Exception If failed. + */ + public void _testConcurrentUpdatesAndQueryStartAtomicCacheGroup() throws Exception { + concurrentUpdatesAndQueryStart(ATOMIC, true); + } + + /** + * @throws Exception If failed. + */ + public void _testConcurrentUpdatesAndQueryStartTxCacheGroup() throws Exception { + concurrentUpdatesAndQueryStart(TRANSACTIONAL, true); } /** * @param atomicityMode Cache atomicity mode. + * @param cacheGrp {@code True} if test cache multiple caches in the same group. * @throws Exception If failed. */ - private void concurrentUpdatesAndQueryStart(CacheAtomicityMode atomicityMode) throws Exception { + private void concurrentUpdatesAndQueryStart(CacheAtomicityMode atomicityMode, boolean cacheGrp) throws Exception { Ignite srv = startGrid(0); client = true; Ignite client = startGrid(1); - CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME); + List caches = new ArrayList<>(); + + if (cacheGrp) { + for (int i = 0; i < 3; i++) { + CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME + i); - ccfg.setWriteSynchronizationMode(FULL_SYNC); - ccfg.setAtomicityMode(atomicityMode); + ccfg.setGroupName("testGroup"); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setAtomicityMode(atomicityMode); - IgniteCache clientCache = client.createCache(ccfg); + IgniteCache cache = client.createCache(ccfg); - Affinity aff = srv.affinity(DEFAULT_CACHE_NAME); + caches.add(cache.getName()); + } + } + else { + CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME); + + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setAtomicityMode(atomicityMode); + + IgniteCache cache = client.createCache(ccfg); + + caches.add(cache.getName()); + } + + Affinity aff = srv.affinity(caches.get(0)); final List keys = new ArrayList<>(); @@ -225,38 +315,27 @@ private void concurrentUpdatesAndQueryStart(CacheAtomicityMode atomicityMode) th final int THREADS = 10; final int UPDATES = 1000; - for (int i = 0; i < 5; i++) { - log.info("Iteration: " + i); - - ContinuousQuery qry = new ContinuousQuery<>(); - - final AtomicInteger evtCnt = new AtomicInteger(); - - qry.setLocalListener(new CacheEntryUpdatedListener() { - @Override public void onUpdated(Iterable> evts) { - for (CacheEntryEvent evt : evts) { - assertNotNull(evt.getKey()); - assertNotNull(evt.getValue()); + final List> srvCaches = new ArrayList<>(); - if ((Integer)evt.getValue() >= 0) - evtCnt.incrementAndGet(); - } - } - }); - - QueryCursor cur; + for (String cacheName : caches) + srvCaches.add(srv.cache(cacheName)); - final IgniteCache srvCache = srv.cache(DEFAULT_CACHE_NAME); + for (int i = 0; i < 5; i++) { + log.info("Iteration: " + i); final AtomicBoolean stop = new AtomicBoolean(); + List > qrys = new ArrayList<>(); + try { IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable() { @Override public Void call() throws Exception { ThreadLocalRandom rnd = ThreadLocalRandom.current(); - while (!stop.get()) - srvCache.put(keys.get(rnd.nextInt(KEYS)), rnd.nextInt(100) - 200); + while (!stop.get()) { + for (IgniteCache srvCache : srvCaches) + srvCache.put(keys.get(rnd.nextInt(KEYS)), rnd.nextInt(100) - 200); + } return null; } @@ -264,7 +343,8 @@ private void concurrentUpdatesAndQueryStart(CacheAtomicityMode atomicityMode) th U.sleep(1000); - cur = clientCache.query(qry); + for (String cache : caches) + qrys.add(startListener(client.cache(cache))); U.sleep(1000); @@ -280,25 +360,30 @@ private void concurrentUpdatesAndQueryStart(CacheAtomicityMode atomicityMode) th @Override public Void call() throws Exception { ThreadLocalRandom rnd = ThreadLocalRandom.current(); - for (int i = 0; i < UPDATES; i++) - srvCache.put(keys.get(rnd.nextInt(KEYS)), i); + for (int i = 0; i < UPDATES; i++) { + for (IgniteCache srvCache : srvCaches) + srvCache.put(keys.get(rnd.nextInt(KEYS)), i); + } return null; } }, THREADS, "update"); + for (T2 qry : qrys) { + final AtomicInteger evtCnt = qry.get1(); - GridTestUtils.waitForCondition(new GridAbsPredicate() { - @Override public boolean apply() { - log.info("Events: " + evtCnt.get()); + GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + log.info("Events: " + evtCnt.get()); - return evtCnt.get() >= THREADS * UPDATES; - } - }, 5000); + return evtCnt.get() >= THREADS * UPDATES; + } + }, 5000); - assertEquals(THREADS * UPDATES, evtCnt.get()); + assertEquals(THREADS * UPDATES, qry.get1().get()); - cur.close(); + qry.get2().close(); + } } } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java index 2fb7fcbbdd9d3..54791d7a0345e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java @@ -2243,13 +2243,11 @@ private boolean checkEvents(boolean logAll, * @throws Exception If failed. */ public void testNoEventLossOnTopologyChange() throws Exception { - final int stableNodeCnt = 1; - final int batchLoadSize = 2000; final int restartCycles = 5; - Ignite qryClient = startGridsMultiThreaded(stableNodeCnt); + Ignite qryClient = startGrid(0); final CacheEventListener4 lsnr = new CacheEventListener4(atomicityMode() == CacheAtomicityMode.ATOMIC); @@ -2282,7 +2280,7 @@ public void testNoEventLossOnTopologyChange() throws Exception { log.info("Batch loaded. Iteration: " + iteration); - final long expCnt = putCnt * stableNodeCnt + ignoredDupEvts; + final long expCnt = putCnt + ignoredDupEvts; GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { @@ -2316,7 +2314,6 @@ public void testNoEventLossOnTopologyChange() throws Exception { String msg = sb.toString(); // In atomic mode CQ can receive duplicate update events if update retried after fails. - // E.g. topology change if (atomicityMode() == CacheAtomicityMode.ATOMIC && msg.isEmpty() && cnt > expCnt) ignoredDupEvts += cnt - expCnt; else diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxOptimisticDeadlockDetectionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxOptimisticDeadlockDetectionTest.java index b48c4ba6ad584..15735760eb627 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxOptimisticDeadlockDetectionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxOptimisticDeadlockDetectionTest.java @@ -399,7 +399,7 @@ private void doTestDeadlock( KeyCacheObject keyCacheObj = intCache.context().toCacheKeyObject(key0); - GridCacheMapEntry entry = map.getEntry(keyCacheObj); + GridCacheMapEntry entry = map.getEntry(intCache.context(), keyCacheObj); if (entry != null) assertNull("Entry still has locks " + entry, entry.mvccAllLocal()); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java index bc297a2c0ccc5..61f71251feb2b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java @@ -408,7 +408,7 @@ private void doTestDeadlock( KeyCacheObject keyCacheObj = intCache.context().toCacheKeyObject(key0); - GridCacheMapEntry entry = map.getEntry(keyCacheObj); + GridCacheMapEntry entry = map.getEntry(intCache.context(), keyCacheObj); if (entry != null) assertNull("Entry still has locks " + entry, entry.mvccAllLocal()); diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java index f12537b2eef94..310082da5b40a 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java @@ -81,14 +81,11 @@ public GridCacheTestContext(GridTestKernalContext ctx) throws Exception { null ), defaultCacheConfiguration(), + null, CacheType.USER, AffinityTopologyVersion.ZERO, - UUID.randomUUID(), true, true, - null, - null, - null, new GridCacheEventManager(), new CacheOsStoreManager(null, new CacheConfiguration()), new GridCacheEvictionManager(), @@ -97,7 +94,6 @@ public GridCacheTestContext(GridTestKernalContext ctx) throws Exception { new CacheDataStructuresManager(), new GridCacheTtlManager(), new GridOsCacheDrManager(), - null, new CacheOsConflictResolutionManager(), new CachePluginManager(ctx, new CacheConfiguration()), new GridCacheAffinityManager() diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/GridCacheMessageSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/GridCacheMessageSelfTest.java index 25ff2fd26b807..4a6b765323667 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/GridCacheMessageSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/GridCacheMessageSelfTest.java @@ -215,6 +215,16 @@ public void add(TestMessage1 entry) { entries.add(entry); } + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return false; + } + /** {@inheritDoc} */ @Override public boolean addDeploymentInfo() { return false; @@ -310,6 +320,16 @@ public void init(Message msg, String body) { this.body = body; } + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return false; + } + /** {@inheritDoc} */ @Override public boolean addDeploymentInfo() { return false; @@ -433,6 +453,16 @@ public void init(Message mes, UUID nodeId, int id, String body) { this.body = body; } + /** {@inheritDoc} */ + @Override public int handlerId() { + return 0; + } + + /** {@inheritDoc} */ + @Override public boolean cacheGroupMessage() { + return false; + } + /** {@inheritDoc} */ @Override public boolean addDeploymentInfo() { return false; diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java index 46d97a04fe73b..cbcbaee53d47d 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java @@ -101,6 +101,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static org.springframework.util.FileSystemUtils.deleteRecursively; + /** * Utility class for tests. */ @@ -1876,4 +1878,11 @@ public static String randomString(Random rnd, int maxLen) { return b.toString(); } + + /** + * @throws Exception If failed. + */ + public static void deleteDbFiles() throws Exception { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } } diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java index 281901a93731e..9d0af5d88d055 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java @@ -68,6 +68,7 @@ import org.apache.ignite.internal.binary.BinaryEnumCache; import org.apache.ignite.internal.binary.BinaryMarshaller; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.resource.GridSpringResourceContext; import org.apache.ignite.internal.util.GridClassLoaderCache; import org.apache.ignite.internal.util.GridTestClockTimer; @@ -2101,6 +2102,22 @@ public static void doSleep(long millis) { } } + /** + * @param node Node. + * @param cacheName Cache name. + * @return Cache group ID for given cache name. + */ + protected final int groupIdForCache(Ignite node, String cacheName) { + for (CacheGroupContext grp : ((IgniteKernal)node).context().cache().cacheGroups()) { + if (grp.hasCache(cacheName)) + return grp.groupId(); + } + + fail("Failed to find group for cache: " + cacheName); + + return 0; + } + /** * */ 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 4bd2372a49b5c..625fb7d6d8d58 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 @@ -65,6 +65,8 @@ import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl; +import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheExplicitLockSpan; @@ -1731,4 +1733,66 @@ private Map completedTxsMap(Ignite ignite) { return U.field(tm, "completedVersHashMap"); } + + /** + * + */ + protected final void checkCacheDiscoveryDataConsistent() { + Map cacheGrps = null; + Map caches = null; + + for (Ignite node : G.allGrids()) { + Map cacheGrps0 = + ((IgniteKernal)node).context().cache().cacheGroupDescriptors(); + Map caches0 = + ((IgniteKernal)node).context().cache().cacheDescriptors(); + + assertNotNull(cacheGrps0); + assertNotNull(caches0); + + if (cacheGrps == null) { + cacheGrps = cacheGrps0; + caches = caches0; + } + else { + assertEquals(cacheGrps.size(), cacheGrps0.size()); + + for (Map.Entry e : cacheGrps.entrySet()) { + CacheGroupDescriptor desc = e.getValue(); + CacheGroupDescriptor desc0 = cacheGrps0.get(e.getKey()); + + assertNotNull(desc0); + checkGroupDescriptorsData(desc, desc0); + } + + for (Map.Entry e : caches.entrySet()) { + DynamicCacheDescriptor desc = e.getValue(); + DynamicCacheDescriptor desc0 = caches.get(e.getKey()); + + assertNotNull(desc0); + assertEquals(desc.deploymentId(), desc0.deploymentId()); + assertEquals(desc.receivedFrom(), desc0.receivedFrom()); + assertEquals(desc.startTopologyVersion(), desc0.startTopologyVersion()); + assertEquals(desc.cacheConfiguration().getName(), desc0.cacheConfiguration().getName()); + assertEquals(desc.cacheConfiguration().getGroupName(), desc0.cacheConfiguration().getGroupName()); + checkGroupDescriptorsData(desc.groupDescriptor(), desc0.groupDescriptor()); + } + } + } + } + + /** + * @param desc First descriptor. + * @param desc0 Second descriptor. + */ + private void checkGroupDescriptorsData(CacheGroupDescriptor desc, CacheGroupDescriptor desc0) { + assertEquals(desc.groupName(), desc0.groupName()); + assertEquals(desc.sharedGroup(), desc0.sharedGroup()); + assertEquals(desc.deploymentId(), desc0.deploymentId()); + assertEquals(desc.receivedFrom(), desc0.receivedFrom()); + assertEquals(desc.startTopologyVersion(), desc0.startTopologyVersion()); + assertEquals(desc.config().getName(), desc0.config().getName()); + assertEquals(desc.config().getGroupName(), desc0.config().getGroupName()); + assertEquals(desc.caches(), desc0.caches()); + } } diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java index 710b2a1cfe015..11a4a107e86d2 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java @@ -28,6 +28,7 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedNearDisabledFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedNearDisabledMultiNodeFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedNearDisabledMultiNodeP2PDisabledFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedNearDisabledMultiNodeWithGroupFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedNearDisabledOnheapFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedNearDisabledOnheapMultiNodeFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.CachePartitionedMultiNodeLongTxTimeoutFullApiTest; @@ -38,7 +39,9 @@ import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicLateAffDisabledMultiNodeFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicMultiNodeFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicMultiNodeP2PDisabledFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicMultiNodeWithGroupFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearEnabledMultiNodeFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearEnabledMultiNodeWithGroupFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearOnlyMultiNodeP2PDisabledFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicOnheapFullApiSelfTest; @@ -58,6 +61,7 @@ import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedMultiNodeCounterSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedMultiNodeFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedMultiNodeP2PDisabledFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedMultiNodeWithGroupFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedNearOnlyNoPrimaryFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedOnheapFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedOnheapMultiNodeFullApiSelfTest; @@ -71,8 +75,10 @@ import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedMultiNodeP2PDisabledFullApiSelfTest; import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedNearOnlyMultiNodeFullApiSelfTest; import org.apache.ignite.internal.processors.cache.local.GridCacheLocalAtomicFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.local.GridCacheLocalAtomicWithGroupFullApiSelfTest; import org.apache.ignite.internal.processors.cache.local.GridCacheLocalFullApiMultithreadedSelfTest; import org.apache.ignite.internal.processors.cache.local.GridCacheLocalFullApiSelfTest; +import org.apache.ignite.internal.processors.cache.local.GridCacheLocalWithGroupFullApiSelfTest; /** * Test suite for cache API. @@ -161,6 +167,13 @@ public static TestSuite suite() throws Exception { // Other. suite.addTestSuite(GridCacheClearSelfTest.class); + suite.addTestSuite(GridCacheLocalWithGroupFullApiSelfTest.class); + suite.addTestSuite(GridCacheLocalAtomicWithGroupFullApiSelfTest.class); + suite.addTestSuite(GridCacheAtomicMultiNodeWithGroupFullApiSelfTest.class); + suite.addTestSuite(GridCacheAtomicNearEnabledMultiNodeWithGroupFullApiSelfTest.class); + suite.addTestSuite(GridCachePartitionedMultiNodeWithGroupFullApiSelfTest.class); + suite.addTestSuite(GridCachePartitionedNearDisabledMultiNodeWithGroupFullApiSelfTest.class); + return suite; } } diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java index ebcf1df5ff7b5..d3471ca9fdff4 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java @@ -18,6 +18,7 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; +import org.apache.ignite.internal.processors.cache.CacheGroupsMetricsRebalanceTest; import org.apache.ignite.internal.processors.cache.CacheMetricsForClusterGroupSelfTest; import org.apache.ignite.internal.processors.cache.OffheapCacheMetricsForClusterGroupSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicPartitionedMetricsSelfTest; @@ -57,6 +58,8 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(GridCacheAtomicPartitionedTckMetricsSelfTestImpl.class); suite.addTestSuite(GridCacheAtomicLocalTckMetricsSelfTestImpl.class); + suite.addTestSuite(CacheGroupsMetricsRebalanceTest.class); + // Cluster wide metrics. suite.addTestSuite(CacheMetricsForClusterGroupSelfTest.class); suite.addTestSuite(OffheapCacheMetricsForClusterGroupSelfTest.class); diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java index 222ac30c783aa..feb2cdf5c03d9 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java @@ -32,9 +32,11 @@ import org.apache.ignite.internal.processors.cache.GridCacheValueConsistencyTransactionalSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheVersionSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheVersionTopologyChangeTest; +import org.apache.ignite.internal.processors.cache.IgniteCacheGroupsTest; import org.apache.ignite.internal.processors.cache.IgniteCacheInterceptorSelfTestSuite; import org.apache.ignite.internal.processors.cache.IgniteCacheScanPredicateDeploymentSelfTest; import org.apache.ignite.internal.processors.cache.distributed.CacheAsyncOperationsTest; +import org.apache.ignite.internal.processors.cache.distributed.CacheGroupsPreloadTest; import org.apache.ignite.internal.processors.cache.distributed.GridCacheMixedModeSelfTest; import org.apache.ignite.internal.processors.cache.distributed.IgniteTxGetAfterStopTest; import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheDaemonNodePartitionedSelfTest; @@ -195,6 +197,8 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(CacheAsyncOperationsTest.class); + suite.addTestSuite(IgniteCacheGroupsTest.class); + return suite; } } diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java index 23f844517db7c..1b35acbc92c0c 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java @@ -88,6 +88,7 @@ import org.apache.ignite.internal.processors.cache.distributed.CacheAtomicPrimarySyncBackPressureTest; import org.apache.ignite.internal.processors.cache.distributed.CacheDiscoveryDataConcurrentJoinTest; import org.apache.ignite.internal.processors.cache.distributed.CacheGetFutureHangsSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.CacheGroupsPreloadTest; import org.apache.ignite.internal.processors.cache.distributed.CacheNoValueClassOnServerNodeTest; import org.apache.ignite.internal.processors.cache.distributed.CacheStartOnJoinTest; import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheCreatePutMultiNodeSelfTest; @@ -305,6 +306,7 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(GridCacheDhtTxPreloadSelfTest.class); suite.addTestSuite(GridCacheNearTxPreloadSelfTest.class); suite.addTestSuite(GridReplicatedTxPreloadTest.class); + suite.addTestSuite(CacheGroupsPreloadTest.class); suite.addTestSuite(IgniteDynamicCacheFilterTest.class); diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index 63e56ca987a8f..41176e1ed5bd0 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -1734,7 +1734,7 @@ private void cleanupStatementCache() { IgniteCacheOffheapManager offheapMgr = cctx.isNear() ? cctx.near().dht().context().offheap() : cctx.offheap(); for (int p = 0; p < cctx.affinity().partitions(); p++) { - try (GridCloseableIterator keyIter = offheapMgr.keysIterator(p)) { + try (GridCloseableIterator keyIter = offheapMgr.cacheKeysIterator(cctx.cacheId(), p)) { while (keyIter.hasNext()) { cctx.shared().database().checkpointReadLock(); @@ -2283,5 +2283,4 @@ public void awaitForReadyTopologyVersion(AffinityTopologyVersion topVer) throws private interface ClIter extends AutoCloseable, Iterator { // No-op. } - } diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java index 7caf3541ba25f..0440615a9fe26 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java @@ -108,7 +108,7 @@ public H2PkHashIndex( List> cursors = new ArrayList<>(); for (IgniteCacheOffheapManager.CacheDataStore store : cctx.offheap().cacheDataStores()) - cursors.add(store.cursor(lowerObj, upperObj)); + cursors.add(store.cursor(cctx.cacheId(), lowerObj, upperObj)); return new H2Cursor(new CompositeGridCursor<>(cursors.iterator()), p); } @@ -126,7 +126,7 @@ public H2PkHashIndex( @Override public GridH2Row findOne(GridH2Row row) { try { for (IgniteCacheOffheapManager.CacheDataStore store : cctx.offheap().cacheDataStores()) { - CacheDataRow found = store.find(row.key); + CacheDataRow found = store.find(cctx, row.key); if (found != null) tbl.rowDescriptor().createRow(row.key(), row.partition(), row.value(), row.version(), 0); diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java index 2024c362ab06a..86b27492af624 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java @@ -59,7 +59,7 @@ public GridH2Row getRow(long link) throws IgniteCheckedException { final CacheDataRowAdapter rowBuilder = new CacheDataRowAdapter(link); - rowBuilder.initFromLink(cctx, CacheDataRowAdapter.RowData.FULL); + rowBuilder.initFromLink(cctx.group(), CacheDataRowAdapter.RowData.FULL); GridH2Row row; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java index f6737173f05b5..f2b8badfef85e 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java @@ -63,7 +63,7 @@ public abstract class H2Tree extends BPlusTree { /** * @param name Tree name. * @param reuseList Reuse list. - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param pageMem Page memory. * @param wal Write ahead log manager. * @param rowStore Row data store. @@ -74,7 +74,7 @@ public abstract class H2Tree extends BPlusTree { protected H2Tree( String name, ReuseList reuseList, - int cacheId, + int grpId, PageMemory pageMem, IgniteWriteAheadLogManager wal, AtomicLong globalRmvId, @@ -85,7 +85,7 @@ protected H2Tree( List inlineIdxs, int inlineSize ) throws IgniteCheckedException { - super(name, cacheId, pageMem, wal, globalRmvId, metaPageId, reuseList); + super(name, grpId, pageMem, wal, globalRmvId, metaPageId, reuseList); if (!initNew) { // Page is ready - read inline size from it. diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java index c1c1d9c05d4ee..b84daf11462c2 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java @@ -24,7 +24,6 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; import org.apache.ignite.internal.processors.cache.database.RootPage; import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; @@ -100,8 +99,6 @@ public H2TreeIndex( name = BPlusTree.treeName(name, "H2Tree"); if (cctx.affinityNode()) { - IgniteCacheDatabaseSharedManager dbMgr = cctx.shared().database(); - inlineIdxs = getAvailableInlineColumns(cols); segments = new H2Tree[segmentsCnt]; @@ -110,8 +107,9 @@ public H2TreeIndex( RootPage page = getMetaPage(name, i); segments[i] = new H2Tree( - name,cctx.offheap().reuseListForIndex(name), - cctx.cacheId(), + name, + cctx.offheap().reuseListForIndex(name), + cctx.groupId(), cctx.memoryPolicy().pageMemory(), cctx.shared().wal(), cctx.offheap().globalRemoveId(), @@ -326,10 +324,12 @@ private List getAvailableInlineColumns(IndexColumn[] cols) { @Override public void destroy() { try { if (cctx.affinityNode()) { - for (H2Tree tree : segments) { + for (int i = 0; i < segments.length; i++) { + H2Tree tree = segments[i]; + tree.destroy(); - cctx.offheap().dropRootPageForIndex(tree.getName()); + dropMetaPage(tree.getName(), i); } } } @@ -413,10 +413,20 @@ private int computeInlineSize(List inlineIdxs, int cfgInlineS /** * @param name Name. + * @param segIdx Segment index. * @return RootPage for meta page. * @throws IgniteCheckedException If failed. */ private RootPage getMetaPage(String name, int segIdx) throws IgniteCheckedException { - return cctx.offheap().rootPageForIndex(name + "%" + segIdx); + return cctx.offheap().rootPageForIndex(cctx.cacheId(), name + "%" + segIdx); + } + + /** + * @param name Name. + * @param segIdx Segment index. + * @throws IgniteCheckedException If failed. + */ + private void dropMetaPage(String name, int segIdx) throws IgniteCheckedException { + cctx.offheap().dropRootPageForIndex(cctx.cacheId(), name + "%" + segIdx); } } diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java index 2d12635bdff00..c1cbada049903 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java @@ -1026,12 +1026,12 @@ private Collection replicatedUnstableDataNodes(List cacheI } /** - * @param cacheName Cache name. + * @param grpId Cache group ID. * @param topVer Topology version. * @return Collection of data nodes. */ - private Collection dataNodes(String cacheName, AffinityTopologyVersion topVer) { - Collection res = ctx.discovery().cacheAffinityNodes(cacheName, topVer); + private Collection dataNodes(int grpId, AffinityTopologyVersion topVer) { + Collection res = ctx.discovery().cacheGroupAffinityNodes(grpId, topVer); return res != null ? res : Collections.emptySet(); } @@ -1047,7 +1047,7 @@ private Set replicatedUnstableDataNodes(GridCacheContext cctx) String cacheName = cctx.name(); - Set dataNodes = new HashSet<>(dataNodes(cacheName, NONE)); + Set dataNodes = new HashSet<>(dataNodes(cctx.groupId(), NONE)); if (dataNodes.isEmpty()) throw new CacheException("Failed to find data nodes for cache: " + cacheName); @@ -1110,7 +1110,7 @@ private Map partitionedUnstableDataNodes(List ca continue; } - else if (!F.isEmpty(dataNodes(cctx.name(), NONE))) + else if (!F.isEmpty(dataNodes(cctx.groupId(), NONE))) return null; // Retry. throw new CacheException("Failed to find data nodes [cache=" + cctx.name() + ", part=" + p + "]"); @@ -1139,7 +1139,7 @@ else if (!F.isEmpty(dataNodes(cctx.name(), NONE))) continue; // Skip unmapped partitions. if (F.isEmpty(owners)) { - if (!F.isEmpty(dataNodes(extraCctx.name(), NONE))) + if (!F.isEmpty(dataNodes(extraCctx.groupId(), NONE))) return null; // Retry. throw new CacheException("Failed to find data nodes [cache=" + extraCctx.name() + diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsSqlTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsSqlTest.java new file mode 100644 index 0000000000000..b53844985fde2 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsSqlTest.java @@ -0,0 +1,317 @@ +/* + * 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 java.io.Serializable; +import java.util.List; +import java.util.concurrent.Callable; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.QueryIndex; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.binary.AffinityKey; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.S; +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 org.apache.ignite.transactions.Transaction; + +import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheMode.PARTITIONED; +import static org.apache.ignite.cache.CacheMode.REPLICATED; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; + +/** + * + */ +public class IgniteCacheGroupsSqlTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final String GROUP1 = "grp1"; + + /** */ + private static final String GROUP2 = "grp2"; + + /** */ + private boolean client; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); + + cfg.setClientMode(client); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + startGridsMultiThreaded(3); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + super.afterTest(); + } + + /** + * @throws Exception If failed. + */ + public void testSqlQuery() throws Exception { + Ignite node = ignite(0); + + IgniteCache c1 = node.createCache(personCacheConfiguration(GROUP1, "c1")); + IgniteCache c2 = node.createCache(personCacheConfiguration(GROUP1, "c2")); + + SqlFieldsQuery qry = new SqlFieldsQuery("select name from Person where name=?"); + qry.setArgs("p1"); + + assertEquals(0, c1.query(qry).getAll().size()); + assertEquals(0, c2.query(qry).getAll().size()); + + c1.put(1, new Person("p1")); + + assertEquals(1, c1.query(qry).getAll().size()); + assertEquals(0, c2.query(qry).getAll().size()); + + c2.put(2, new Person("p1")); + + assertEquals(1, c1.query(qry).getAll().size()); + assertEquals(1, c2.query(qry).getAll().size()); + } + + /** + * @throws Exception If failed. + */ + public void testJoinQuery1() throws Exception { + joinQuery(GROUP1, GROUP2, REPLICATED, PARTITIONED, TRANSACTIONAL, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testJoinQuery2() throws Exception { + GridTestUtils.assertThrows(log, new Callable() { + @Override public Void call() throws Exception { + joinQuery(GROUP1, GROUP1, REPLICATED, PARTITIONED, TRANSACTIONAL, TRANSACTIONAL); + return null; + } + }, IgniteCheckedException.class, "Cache mode mismatch for caches related to the same group"); + } + + /** + * @throws Exception If failed. + */ + public void testJoinQuery3() throws Exception { + joinQuery(GROUP1, GROUP1, PARTITIONED, PARTITIONED, TRANSACTIONAL, ATOMIC); + } + + /** + * @throws Exception If failed. + */ + public void testJoinQuery4() throws Exception { + joinQuery(GROUP1, GROUP1, REPLICATED, REPLICATED, ATOMIC, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testJoinQuery5() throws Exception { + joinQuery(GROUP1, null, REPLICATED, PARTITIONED, TRANSACTIONAL, TRANSACTIONAL); + } + + /** + * @throws Exception If failed. + */ + public void testJoinQuery6() throws Exception { + joinQuery(GROUP1, null, PARTITIONED, PARTITIONED, TRANSACTIONAL, ATOMIC); + } + + /** + * @param grp1 First cache group. + * @param grp2 Second cache group. + * @param cm1 First cache mode. + * @param cm2 Second cache mode. + * @param cam1 First cache atomicity mode. + * @param cam2 Second cache atomicity mode. + * @throws Exception If failed. + */ + private void joinQuery(String grp1, String grp2, CacheMode cm1, + CacheMode cm2, CacheAtomicityMode cam1, CacheAtomicityMode cam2) throws Exception { + int keys = 1000; + int accsPerPerson = 4; + + Ignite srv0 = ignite(0); + + IgniteCache pers = srv0.createCache(personCacheConfiguration(grp1, "pers") + .setAffinity(new RendezvousAffinityFunction().setPartitions(10)) + .setCacheMode(cm1) + .setAtomicityMode(cam1)); + + IgniteCache acc = srv0.createCache(accountCacheConfiguration(grp2, "acc") + .setAffinity(new RendezvousAffinityFunction().setPartitions(10)) + .setCacheMode(cm2) + .setAtomicityMode(cam2)); + + try(Transaction tx = cam1 == TRANSACTIONAL || cam2 == TRANSACTIONAL ? srv0.transactions().txStart() : null) { + for (int i = 0; i < keys; i++) { + + int pKey = i - (i % accsPerPerson); + + if (i % accsPerPerson == 0) + pers.put(pKey, new Person("pers-" + pKey)); + + + acc.put(new AffinityKey(i, pKey), new Account(pKey, "acc-" + i)); + } + + if (tx != null) + tx.commit(); + } + + Ignite node = ignite(2); + + SqlFieldsQuery qry = new SqlFieldsQuery( + "select p._key as p_key, p.name, a._key as a_key, a.personId, a.attr \n" + + "from \"pers\".Person p inner join \"acc\".Account a \n" + + "on (p._key = a.personId)"); + + IgniteCache cache = node.cache("acc"); + + List> res = cache.query(qry).getAll(); + + assertEquals(keys, res.size()); + + for (List row : res) + assertEquals(row.get(0), row.get(3)); + } + + /** + * @param grpName Group name. + * @param cacheName Cache name. + * @return Person cache configuration. + */ + private CacheConfiguration personCacheConfiguration(String grpName, String cacheName) { + QueryEntity entity = new QueryEntity(); + + entity.setKeyType(Integer.class.getName()); + entity.setValueType(Person.class.getName()); + entity.addQueryField("name", String.class.getName(), null); + + return cacheConfiguration(grpName, cacheName, entity); + } + + /** + * @param grpName Group name. + * @param cacheName Cache name. + * @return Account cache configuration. + */ + private CacheConfiguration accountCacheConfiguration(String grpName, String cacheName) { + QueryEntity entity = new QueryEntity(); + + entity.setKeyType(AffinityKey.class.getName()); + entity.setValueType(Account.class.getName()); + entity.addQueryField("personId", Integer.class.getName(), null); + entity.addQueryField("attr", String.class.getName(), null); + entity.setIndexes(F.asList(new QueryIndex("personId"))); + + return cacheConfiguration(grpName, cacheName, entity); + } + + /** + * @param grpName Group name. + * @param cacheName Cache name. + * @param queryEntity Query entity. + * @return Cache configuration. + */ + private CacheConfiguration cacheConfiguration(String grpName, String cacheName, QueryEntity queryEntity) { + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setGroupName(grpName); + ccfg.setName(cacheName); + + ccfg.setQueryEntities(F.asList(queryEntity)); + + return ccfg; + } + + /** + * + */ + private static class Person implements Serializable { + /** */ + String name; + + /** + * @param name Name. + */ + public Person(String name) { + this.name = name; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(Person.class, this); + } + } + + /** + * + */ + private static class Account implements Serializable { + /** */ + Integer personId; + + /** */ + String attr; + + /** + * @param personId Person ID. + * @param attr Attribute (some data). + */ + public Account(Integer personId, String attr) { + this.personId = personId; + this.attr = attr; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(Account.class, this); + } + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoClassQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoClassQuerySelfTest.java index e0148b32a5ce0..770770e9a41f3 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoClassQuerySelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoClassQuerySelfTest.java @@ -20,13 +20,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; -import org.apache.ignite.Ignite; -import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.QueryEntity; import org.apache.ignite.cache.QueryIndex; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.configuration.NearCacheConfiguration; import org.apache.ignite.internal.binary.BinaryMarshaller; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; @@ -44,23 +41,6 @@ public class IgniteCacheNoClassQuerySelfTest extends GridCommonAbstractTest { /** */ private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); - /** */ - protected Ignite ignite; - - /** - * @return Atomicity mode. - */ - protected CacheAtomicityMode atomicityMode() { - return TRANSACTIONAL; - } - - /** - * @return Distribution. - */ - protected NearCacheConfiguration nearCacheConfiguration() { - return new NearCacheConfiguration(); - } - /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { @@ -118,5 +98,8 @@ public void testNoClass() throws Exception { catch (Exception e) { assertTrue(e.getMessage().contains("default marshaller")); } + finally { + stopAllGrids(); + } } } diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java index 0f4a418e941da..794ec4dcf5447 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java @@ -30,6 +30,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheOffheapIndexGetSelfTest; import org.apache.ignite.internal.processors.cache.GridIndexingWithNoopSwapSelfTest; import org.apache.ignite.internal.processors.cache.IgniteCacheConfigurationPrimitiveTypesSelfTest; +import org.apache.ignite.internal.processors.cache.IgniteCacheGroupsSqlTest; import org.apache.ignite.internal.processors.cache.IgniteCacheStarvationOnRebalanceTest; import org.apache.ignite.internal.processors.cache.IgniteClientReconnectQueriesTest; import org.apache.ignite.internal.processors.cache.ttl.CacheTtlAtomicLocalSelfTest; @@ -72,6 +73,8 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(ClientReconnectAfterClusterRestartTest.class); + suite.addTestSuite(IgniteCacheGroupsSqlTest.class); + return suite; } } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 0f75b0ddb8339..1b3645116b3c4 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -94,6 +94,7 @@ import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.ClusterState; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; @@ -214,7 +215,7 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan private volatile GridFutureAdapter enableChangeApplied; /** */ - public ReentrantReadWriteLock checkpointLock = new ReentrantReadWriteLock(); + private ReentrantReadWriteLock checkpointLock = new ReentrantReadWriteLock(); /** */ private long checkpointFreq; @@ -409,25 +410,25 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { if (!reconnect && !cctx.kernalContext().clientNode() && cctx.kernalContext().state().active()) { Collection cacheNames = new HashSet<>(); - for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) + // TODO IGNITE-5075 group descriptors. + for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) { if (CU.isSystemCache(ccfg.getName())) { - storeMgr.initializeForCache(ccfg); + storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), ccfg); cacheNames.add(ccfg.getName()); } + } for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) if (!CU.isSystemCache(ccfg.getName())) { - storeMgr.initializeForCache(ccfg); + storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), ccfg); cacheNames.add(ccfg.getName()); } - for (String name : cctx.pageStore().savedCacheNames()) { - CacheConfiguration ccfg = cctx.pageStore().readConfiguration(name); - - if (ccfg != null && !cacheNames.contains(name)) - storeMgr.initializeForCache(ccfg); + for (CacheConfiguration ccfg : cctx.pageStore().readCacheConfigurations().values()) { + if (!cacheNames.contains(ccfg.getName())) + storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), ccfg); } readCheckpointAndRestoreMemory(); @@ -548,7 +549,7 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { } /** {@inheritDoc} */ - protected long[] calculateFragmentSizes(int concLvl, long cacheSize) { + private long[] calculateFragmentSizes(int concLvl, long cacheSize) { if (concLvl < 2) concLvl = Runtime.getRuntime().availableProcessors(); @@ -599,7 +600,7 @@ protected long[] calculateFragmentSizes(int concLvl, long cacheSize) { FullPageId fullId, PageMemoryEx pageMem ) throws IgniteCheckedException { - snapshotMgr.onChangeTrackerPage(page,fullId,pageMem); + snapshotMgr.onChangeTrackerPage(page, fullId, pageMem); } }, this @@ -688,7 +689,7 @@ private void shutdownCheckpointer(boolean cancel) { if (cctx.kernalContext().query().moduleEnabled()) { for (GridCacheContext cacheCtx : (Collection)cctx.cacheContexts()) { if (cacheCtx.startTopologyVersion().equals(fut.topologyVersion()) && - !cctx.pageStore().hasIndexStore(cacheCtx.cacheId()) && cacheCtx.affinityNode()) { + !cctx.pageStore().hasIndexStore(cacheCtx.groupId()) && cacheCtx.affinityNode()) { final int cacheId = cacheCtx.cacheId(); final IgniteInternalFuture rebuildFut = cctx.kernalContext().query() @@ -717,7 +718,8 @@ private void shutdownCheckpointer(boolean cancel) { } /** {@inheritDoc} */ - @Override public void onCachesStopped(Collection> stoppedCtxs) { + @Override public void onCacheGroupsStopped( + Collection> stoppedGrps) { try { waitForCheckpoint("caches stop"); } @@ -727,30 +729,30 @@ private void shutdownCheckpointer(boolean cancel) { Map> destroyed = new HashMap<>(); - for (IgniteBiTuple tup : stoppedCtxs) { + for (IgniteBiTuple tup : stoppedGrps) { PageMemoryEx pageMem = (PageMemoryEx)tup.get1().memoryPolicy().pageMemory(); - Collection cacheIds = destroyed.get(pageMem); + Collection grpIds = destroyed.get(pageMem); - if (cacheIds == null) { - cacheIds = new HashSet<>(); + if (grpIds == null) { + grpIds = new HashSet<>(); - destroyed.put(pageMem, cacheIds); + destroyed.put(pageMem, grpIds); } - cacheIds.add(tup.get1().cacheId()); + grpIds.add(tup.get1().groupId()); - pageMem.onCacheDestroyed(tup.get1().cacheId()); + pageMem.onCacheGroupDestroyed(tup.get1().groupId()); } Collection> clearFuts = new ArrayList<>(destroyed.size()); for (Map.Entry> entry : destroyed.entrySet()) { - final Collection cacheIds = entry.getValue(); + final Collection grpIds = entry.getValue(); clearFuts.add(entry.getKey().clearAsync(new P3() { - @Override public boolean apply(Integer cacheId, Long pageId, Integer tag) { - return cacheIds.contains(cacheId); + @Override public boolean apply(Integer grpId, Long pageId, Integer tag) { + return grpIds.contains(grpId); } }, false)); } @@ -764,15 +766,17 @@ private void shutdownCheckpointer(boolean cancel) { } if (cctx.pageStore() != null) { - for (IgniteBiTuple tup : stoppedCtxs) { - GridCacheContext cacheCtx = tup.get1(); + for (IgniteBiTuple tup : stoppedGrps) { + CacheGroupContext grp = tup.get1(); - try { - cctx.pageStore().shutdownForCache(cacheCtx, tup.get2()); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to gracefully clean page store resources for destroyed cache " + - "[cache=" + cacheCtx.name() + "]", e); + if (grp.affinityNode()) { + try { + cctx.pageStore().shutdownForCacheGroup(grp, tup.get2()); + } + catch (IgniteCheckedException e) { + U.error(log, "Failed to gracefully clean page store resources for destroyed cache " + + "[cache=" + grp.cacheOrGroupName() + "]", e); + } } } } @@ -849,15 +853,17 @@ private boolean safeToUpdatePageMemories() { checkpointLock.readLock().unlock(); if (checkpointer != null) { - Collection cacheCtxs = context().cacheContexts(); + Collection memPlcs = context().database().memoryPolicies(); - for (GridCacheContext cacheCtx : cacheCtxs) { - PageMemoryEx mem = (PageMemoryEx) cacheCtx.memoryPolicy().pageMemory(); + if (memPlcs != null) { + for (MemoryPolicy memPlc : memPlcs) { + PageMemoryEx mem = (PageMemoryEx)memPlc.pageMemory(); - if (mem != null && !mem.safeToUpdate()) { - checkpointer.wakeupForCheckpoint(0, "too many dirty pages"); + if (mem != null && !mem.safeToUpdate()) { + checkpointer.wakeupForCheckpoint(0, "too many dirty pages"); - break; + break; + } } } } @@ -869,7 +875,7 @@ private boolean safeToUpdatePageMemories() { /** * @throws IgniteCheckedException If failed to restore database status from WAL. */ - public void restoreState() throws IgniteCheckedException { + private void restoreState() throws IgniteCheckedException { try { CheckpointStatus status = readCheckpointStatus(); @@ -899,27 +905,27 @@ public void restoreState() throws IgniteCheckedException { reservedForExchange = new HashMap<>(); - for (GridCacheContext cacheCtx : (Collection)cctx.cacheContexts()) { - if (cacheCtx.isLocal()) + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) continue; - for (GridDhtLocalPartition part : cacheCtx.topology().currentLocalPartitions()) { - if (part.state() != GridDhtPartitionState.OWNING || part.dataStore().size() <= walRebalanceThreshold) + for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) { + if (part.state() != GridDhtPartitionState.OWNING || part.dataStore().fullSize() <= walRebalanceThreshold) continue; - CheckpointEntry cpEntry = searchCheckpointEntry(cacheCtx, part.id(), null); + CheckpointEntry cpEntry = searchCheckpointEntry(grp.groupId(), part.id(), null); try { if (cpEntry != null && cctx.wal().reserve(cpEntry.cpMark)) { - Map> cacheMap = reservedForExchange.get(cacheCtx.cacheId()); + Map> cacheMap = reservedForExchange.get(grp.groupId()); if (cacheMap == null) { cacheMap = new HashMap<>(); - reservedForExchange.put(cacheCtx.cacheId(), cacheMap); + reservedForExchange.put(grp.groupId(), cacheMap); } - cacheMap.put(part.id(), new T2<>(cpEntry.partitionCounter(cacheCtx.cacheId(), part.id()), cpEntry.cpMark)); + cacheMap.put(part.id(), new T2<>(cpEntry.partitionCounter(grp.groupId(), part.id()), cpEntry.cpMark)); } } catch (IgniteCheckedException ex) { @@ -962,8 +968,8 @@ public void restoreState() throws IgniteCheckedException { } /** {@inheritDoc} */ - @Override public boolean reserveHistoryForPreloading(int cacheId, int partId, long cntr) { - CheckpointEntry cpEntry = searchCheckpointEntry(cctx.cacheContext(cacheId), partId, cntr); + @Override public boolean reserveHistoryForPreloading(int grpId, int partId, long cntr) { + CheckpointEntry cpEntry = searchCheckpointEntry(grpId, partId, cntr); if (cpEntry == null) return false; @@ -985,7 +991,7 @@ public void restoreState() throws IgniteCheckedException { } if (reserved) - reservedForPreloading.put(new T2<>(cacheId, partId), new T2<>(cntr, ptr)); + reservedForPreloading.put(new T2<>(grpId, partId), new T2<>(cntr, ptr)); return reserved; } @@ -1049,31 +1055,18 @@ public Map, T2> reservedForPreloading() { fut2.get(); } - /** - * Schedules partition destroy during next checkpoint. This method must be called inside checkpoint read lock. - * - * @param cacheCtx Cache context. - * @param partId Partition ID. - */ - public void schedulePartitionDestroy(GridCacheContext cacheCtx, int partId) { - Checkpointer cp = checkpointer; - - if (cp != null) - cp.schedulePartitionDestroy(cacheCtx, partId); - } - /** * Cancels partition destroy if it has not begun yet. Otherwise, will wait for cleanup to finish. * - * @param cacheCtx Cache context. + * @param grpId Cache group ID. * @param partId Partition ID. */ - public void cancelOrWaitPartitionDestroy(GridCacheContext cacheCtx, int partId) + void cancelOrWaitPartitionDestroy(int grpId, int partId) throws IgniteCheckedException { Checkpointer cp = checkpointer; if (cp != null) - cp.cancelOrWaitPartitionDestroy(cacheCtx, partId); + cp.cancelOrWaitPartitionDestroy(grpId, partId); } @@ -1081,13 +1074,13 @@ public void cancelOrWaitPartitionDestroy(GridCacheContext cacheCtx, int pa /** * Tries to search for a WAL pointer for the given partition counter start. * - * @param cacheCtx Cache context. + * @param grpId Cache group ID. * @param part Partition ID. * @param partCntrSince Partition counter or {@code null} to search for minimal counter. * @return Checkpoint entry or {@code null} if failed to search. */ - @Nullable public WALPointer searchPartitionCounter(GridCacheContext cacheCtx, int part, @Nullable Long partCntrSince) { - CheckpointEntry entry = searchCheckpointEntry(cacheCtx, part, partCntrSince); + @Nullable public WALPointer searchPartitionCounter(int grpId, int part, @Nullable Long partCntrSince) { + CheckpointEntry entry = searchCheckpointEntry(grpId, part, partCntrSince); if (entry == null) return null; @@ -1098,12 +1091,12 @@ public void cancelOrWaitPartitionDestroy(GridCacheContext cacheCtx, int pa /** * Tries to search for a WAL pointer for the given partition counter start. * - * @param cacheCtx Cache context. + * @param grpId Cache group ID. * @param part Partition ID. * @param partCntrSince Partition counter or {@code null} to search for minimal counter. * @return Checkpoint entry or {@code null} if failed to search. */ - @Nullable private CheckpointEntry searchCheckpointEntry(GridCacheContext cacheCtx, int part, @Nullable Long partCntrSince) { + @Nullable private CheckpointEntry searchCheckpointEntry(int grpId, int part, @Nullable Long partCntrSince) { boolean hasGap = false; CheckpointEntry first = null; @@ -1111,7 +1104,7 @@ public void cancelOrWaitPartitionDestroy(GridCacheContext cacheCtx, int pa try { CheckpointEntry entry = checkpointHist.entry(cpTs); - Long foundCntr = entry.partitionCounter(cacheCtx.cacheId(), part); + Long foundCntr = entry.partitionCounter(grpId, part); if (foundCntr != null) { if (partCntrSince == null) { @@ -1323,7 +1316,7 @@ else if (!F.eq(cpRec.checkpointId(), status.cpEndId)) int cacheId = pageRec.fullPageId().cacheId(); long pageId = pageRec.fullPageId().pageId(); - PageMemoryEx pageMem = getPageMemoryForCacheId(cacheId); + PageMemoryEx pageMem = getPageMemoryForCacheGroup(cacheId); long page = pageMem.acquirePage(cacheId, pageId, true); @@ -1353,7 +1346,7 @@ else if (!F.eq(cpRec.checkpointId(), status.cpEndId)) final int cId = destroyRec.cacheId(); final int pId = destroyRec.partitionId(); - PageMemoryEx pageMem = getPageMemoryForCacheId(cId); + PageMemoryEx pageMem = getPageMemoryForCacheGroup(cId); pageMem.clearAsync(new P3() { @Override public boolean apply(Integer cacheId, Long pageId, Integer tag) { @@ -1371,7 +1364,7 @@ else if (!F.eq(cpRec.checkpointId(), status.cpEndId)) int cacheId = r.cacheId(); long pageId = r.pageId(); - PageMemoryEx pageMem = getPageMemoryForCacheId(cacheId); + PageMemoryEx pageMem = getPageMemoryForCacheGroup(cacheId); // Here we do not require tag check because we may be applying memory changes after // several repetitive restarts and the same pages may have changed several times. @@ -1416,20 +1409,21 @@ else if (!F.eq(cpRec.checkpointId(), status.cpEndId)) /** * Obtains PageMemory reference from cache descriptor instead of cache context. * - * @param cacheId Cache id. + * @param grpId Cache group id. * @return PageMemoryEx instance. * @throws IgniteCheckedException if no MemoryPolicy is configured for a name obtained from cache descriptor. */ - private PageMemoryEx getPageMemoryForCacheId(int cacheId) throws IgniteCheckedException { + private PageMemoryEx getPageMemoryForCacheGroup(int grpId) throws IgniteCheckedException { + // TODO IGNITE-5075: cache descriptor can be removed. GridCacheSharedContext sharedCtx = context(); String memPlcName = sharedCtx .cache() - .cacheDescriptor(cacheId) - .cacheConfiguration() + .cacheGroupDescriptors().get(grpId) + .config() .getMemoryPolicyName(); - return (PageMemoryEx) sharedCtx.database().memoryPolicy(memPlcName).pageMemory(); + return (PageMemoryEx)sharedCtx.database().memoryPolicy(memPlcName).pageMemory(); } /** @@ -1502,35 +1496,31 @@ private void applyLastUpdates(CheckpointStatus status) throws IgniteCheckedExcep private void restorePartitionState( Map, T2> partStates ) throws IgniteCheckedException { - Collection cacheContexts = cctx.cacheContexts(); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + int grpId = grp.groupId(); - for (GridCacheContext context : cacheContexts) { - int cacheId = context.cacheId(); + PageMemoryEx pageMem = (PageMemoryEx)grp.memoryPolicy().pageMemory(); - GridCacheContext cacheCtx = cctx.cacheContext(cacheId); + for (int i = 0; i < grp.affinity().partitions(); i++) { + if (storeMgr.exists(grpId, i)) { + storeMgr.ensure(grpId, i); - PageMemoryEx pageMem = (PageMemoryEx)cacheCtx.memoryPolicy().pageMemory(); - - for (int i = 0; i < context.affinity().partitions(); i++) { - if (storeMgr.exists(cacheId, i)) { - storeMgr.ensure(cacheId, i); - - if (storeMgr.pages(cacheId, i) <= 1) + if (storeMgr.pages(grpId, i) <= 1) continue; - long partMetaId = pageMem.partitionMetaPageId(cacheId, i); - long partMetaPage = pageMem.acquirePage(cacheId, partMetaId); + long partMetaId = pageMem.partitionMetaPageId(grpId, i); + long partMetaPage = pageMem.acquirePage(grpId, partMetaId); try { - long pageAddr = pageMem.writeLock(cacheId, partMetaId, partMetaPage); + long pageAddr = pageMem.writeLock(grpId, partMetaId, partMetaPage); boolean changed = false; try { PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.forPage(pageAddr); - T2 fromWal = partStates.get(new T2<>(cacheId, i)); + T2 fromWal = partStates.get(new T2<>(grpId, i)); - GridDhtLocalPartition part = context.topology() + GridDhtLocalPartition part = grp.topology() .localPartition(i, AffinityTopologyVersion.NONE, true); assert part != null; @@ -1543,7 +1533,7 @@ private void restorePartitionState( changed = updateState(part, stateId); if (stateId == GridDhtPartitionState.OWNING.ordinal()) { - cacheCtx.offheap().onPartitionInitialCounterUpdated(i, fromWal.get2()); + grp.offheap().onPartitionInitialCounterUpdated(i, fromWal.get2()); if (part.initialUpdateCounter() < fromWal.get2()) { part.initialUpdateCounter(fromWal.get2()); @@ -1556,11 +1546,11 @@ private void restorePartitionState( changed = updateState(part, (int)io.getPartitionState(pageAddr)); } finally { - pageMem.writeUnlock(cacheId, partMetaId, partMetaPage, null, changed); + pageMem.writeUnlock(grpId, partMetaId, partMetaPage, null, changed); } } finally { - pageMem.releasePage(cacheId, partMetaId, partMetaPage); + pageMem.releasePage(grpId, partMetaId, partMetaPage); } } } @@ -1598,6 +1588,7 @@ private void applyUpdate(GridCacheContext cacheCtx, DataEntry dataEntry) throws case CREATE: case UPDATE: cacheCtx.offheap().update( + cacheCtx, dataEntry.key(), dataEntry.value(), dataEntry.writeVersion(), @@ -1611,7 +1602,7 @@ private void applyUpdate(GridCacheContext cacheCtx, DataEntry dataEntry) throws break; case DELETE: - cacheCtx.offheap().remove(dataEntry.key(), dataEntry.partitionId(), locPart); + cacheCtx.offheap().remove(cacheCtx, dataEntry.key(), dataEntry.partitionId(), locPart); if (dataEntry.partitionCounter() != 0) cacheCtx.offheap().onPartitionInitialCounterUpdated(dataEntry.partitionId(), dataEntry.partitionCounter()); @@ -1744,7 +1735,7 @@ private CheckpointEntry writeCheckpointEntry( ch.force(true); return type == CheckpointEntryType.START ? - new CheckpointEntry(cpTs, ptr, cpId, rec.cacheStates()) : null; + new CheckpointEntry(cpTs, ptr, cpId, rec.cacheGroupStates()) : null; } catch (IOException e) { throw new IgniteCheckedException(e); @@ -1771,28 +1762,29 @@ private void finishDestroyPartitionsAsync(final Collection pageMemSet = new HashSet<>(); for (PartitionDestroyRequest req : reqs) { - Collection partIds = filterMap.get(req.cacheId); + Collection partIds = filterMap.get(req.grpId); if (partIds == null) { partIds = new HashSet<>(); - filterMap.put(req.cacheId, partIds); + filterMap.put(req.grpId, partIds); } partIds.add(req.partId); - pageMemSet.add((PageMemoryEx)cctx.cacheContext(req.cacheId).memoryPolicy().pageMemory()); + // TODO IGNITE-5075. + pageMemSet.add((PageMemoryEx)cctx.cache().cacheGroup(req.grpId).memoryPolicy().pageMemory()); } for (PageMemoryEx pageMem : pageMemSet) { IgniteInternalFuture clearFut = pageMem.clearAsync(new P3() { - @Override public boolean apply(Integer cacheId, Long pageId, Integer tag) { - assert cacheId != null; + @Override public boolean apply(Integer grpId, Long pageId, Integer tag) { + assert grpId != null; assert pageId != null; int partId = PageIdUtils.partId(pageId); - Collection parts = filterMap.get(cacheId); + Collection parts = filterMap.get(grpId); return parts != null && parts.contains(partId); } @@ -1805,7 +1797,7 @@ private void finishDestroyPartitionsAsync(final Collection cacheCtx, int partId) { + private void schedulePartitionDestroy(CacheGroupContext grp, int partId) { synchronized (this) { - scheduledCp.destroyQueue.addDestroyRequest(cacheCtx, partId); + scheduledCp.destroyQueue.addDestroyRequest(grp, partId); } wakeupForCheckpoint(partDestroyCheckpointDelay, "partition destroy"); } /** - * @param cacheCtx Cache context. + * @param grpId Cache group ID. * @param partId Partition ID. */ - private void cancelOrWaitPartitionDestroy(GridCacheContext cacheCtx, int partId) + private void cancelOrWaitPartitionDestroy(int grpId, int partId) throws IgniteCheckedException { CheckpointProgress cur = curCpProgress; PartitionDestroyRequest req; if (cur != null) { - req = cur.destroyQueue.cancelDestroy(cacheCtx.cacheId(), partId); + req = cur.destroyQueue.cancelDestroy(grpId, partId); if (req != null) req.waitCompleted(); } synchronized (this) { - req = scheduledCp.destroyQueue.cancelDestroy(cacheCtx.cacheId(), partId); + req = scheduledCp.destroyQueue.cancelDestroy(grpId, partId); } if (req != null) @@ -2060,7 +2052,7 @@ private void doCheckpoint() { if (req != null) { // Log destroy record before actual partition clear. - lastPtr = cctx.wal().log(new PartitionDestroyRecord(req.cacheId, req.partId)); + lastPtr = cctx.wal().log(new PartitionDestroyRecord(req.grpId, req.partId)); if (reqs == null) reqs = new ArrayList<>(); @@ -2178,18 +2170,16 @@ private Checkpoint markCheckpointBegin() throws IgniteCheckedException { for (DbCheckpointListener lsnr : lsnrs) lsnr.onCheckpointBegin(ctx0); - Collection cacheCtxs = ((GridCacheSharedContext)cctx).cacheContexts(); + for (CacheGroupContext grp : cctx.cache().cacheGroups()) { + if (grp.isLocal()) + continue; - for (GridCacheContext cacheCtx : cacheCtxs) { CacheState state = new CacheState(); - if (cacheCtx.isLocal()) - continue; - - for (GridDhtLocalPartition part : cacheCtx.topology().currentLocalPartitions()) - state.addPartitionState(part.id(), part.dataStore().size(), part.lastAppliedUpdate()); + for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) + state.addPartitionState(part.id(), part.dataStore().fullSize(), part.lastAppliedUpdate()); - cpRec.addCacheState(cacheCtx.cacheId(), state); + cpRec.addCacheGroupState(grp.groupId(), state); } if (curr.nextSnapshot) @@ -2359,14 +2349,14 @@ private WriteCheckpointPages( snapshotMgr.beforePageWrite(fullId); - int cacheId = fullId.cacheId(); + int grpId = fullId.cacheId(); - GridCacheContext cacheCtx = context().cacheContext(cacheId); + CacheGroupContext grp = context().cache().cacheGroup(grpId); - if (cacheCtx == null) + if (grp == null) continue; - PageMemoryEx pageMem = (PageMemoryEx) cacheCtx.memoryPolicy().pageMemory(); + PageMemoryEx pageMem = (PageMemoryEx)grp.memoryPolicy().pageMemory(); Integer tag = pageMem.getForCheckpoint(fullId, tmpWriteBuf); @@ -2385,7 +2375,7 @@ private WriteCheckpointPages( PageIO.setCrc(writeAddr, 0); - PageStore store = storeMgr.writeInternal(cacheId, fullId.pageId(), tmpWriteBuf, tag); + PageStore store = storeMgr.writeInternal(grpId, fullId.pageId(), tmpWriteBuf, tag); updStores.add(store); } @@ -2685,15 +2675,15 @@ private int onCheckpointFinished() { try { entry.initIfNeeded(cctx); - if (entry.cacheStates == null) + if (entry.cacheGrpStates == null) continue; - CacheState cacheState = entry.cacheStates.get(cacheId); + CacheState grpState = entry.cacheGrpStates.get(cacheId); - if (cacheState == null) + if (grpState == null) continue; - CacheState.PartitionState partState = cacheState.partitions().get(partId); + CacheState.PartitionState partState = grpState.partitions().get(partId); if (partState != null) { if (cctx.wal().reserve(entry.checkpointMark())) @@ -2734,7 +2724,7 @@ private static class CheckpointEntry { private UUID cpId; /** Cache states. Initialized lazily. */ - private Map cacheStates; + private Map cacheGrpStates; /** Initialization exception. */ private IgniteCheckedException initEx; @@ -2760,13 +2750,13 @@ private CheckpointEntry(long cpTs, WALPointer cpMark) { * @param cpTs Checkpoint timestamp. * @param cpMark Checkpoint mark pointer. * @param cpId Checkpoint ID. - * @param cacheStates Cache states. + * @param cacheGrpStates Cache groups states. */ - private CheckpointEntry(long cpTs, WALPointer cpMark, UUID cpId, Map cacheStates) { + private CheckpointEntry(long cpTs, WALPointer cpMark, UUID cpId, Map cacheGrpStates) { this.cpTs = cpTs; this.cpMark = cpMark; this.cpId = cpId; - this.cacheStates = cacheStates; + this.cacheGrpStates = cacheGrpStates; initGuard = 1; initLatch = new CountDownLatch(0); @@ -2808,17 +2798,17 @@ private String endFile() { } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param part Partition ID. * @return Partition counter or {@code null} if not found. */ - private Long partitionCounter(int cacheId, int part) { + private Long partitionCounter(int grpId, int part) { assert initGuard != 0; - if (initEx != null || cacheStates == null) + if (initEx != null || cacheGrpStates == null) return null; - CacheState state = cacheStates.get(cacheId); + CacheState state = cacheGrpStates.get(grpId); if (state != null) { CacheState.PartitionState partState = state.partitions().get(part); @@ -2841,7 +2831,7 @@ private void initIfNeeded(GridCacheSharedContext cctx) throws IgniteCheckedExcep CheckpointRecord rec = (CheckpointRecord)tup.get2(); cpId = rec.checkpointId(); - cacheStates = rec.cacheStates(); + cacheGrpStates = rec.cacheGroupStates(); } else initEx = new IgniteCheckedException("Failed to find checkpoint record at " + @@ -2874,16 +2864,16 @@ private static class PartitionDestroyQueue { new ConcurrentHashMap<>(); /** - * @param cacheCtx Cache context. + * @param grp Cache group. * @param partId Partition ID to destroy. */ - private void addDestroyRequest(GridCacheContext cacheCtx, int partId) { - PartitionDestroyRequest req = new PartitionDestroyRequest(cacheCtx, partId); + private void addDestroyRequest(CacheGroupContext grp, int partId) { + PartitionDestroyRequest req = new PartitionDestroyRequest(grp, partId); - PartitionDestroyRequest old = pendingReqs.putIfAbsent(new T2<>(cacheCtx.cacheId(), partId), req); + PartitionDestroyRequest old = pendingReqs.putIfAbsent(new T2<>(grp.groupId(), partId), req); assert old == null : "Must wait for old destroy request to finish before adding a new one " + - "[cacheId=" + cacheCtx.cacheId() + ", cacheName=" + cacheCtx.name() + ", partId=" + partId + ']'; + "[grpId=" + grp.groupId() + ", name=" + grp.cacheOrGroupName() + ", partId=" + partId + ']'; } /** @@ -2913,10 +2903,10 @@ private PartitionDestroyRequest cancelDestroy(int cacheId, int partId) { */ private static class PartitionDestroyRequest { /** */ - private int cacheId; + private int grpId; /** */ - private String cacheName; + private String name; /** */ private int partId; @@ -2931,13 +2921,13 @@ private static class PartitionDestroyRequest { private GridFutureAdapter destroyFut; /** - * @param cacheCtx Cache context. + * @param grp Cache group. * @param partId Partition ID. */ - private PartitionDestroyRequest(GridCacheContext cacheCtx, int partId) { - cacheId = cacheCtx.cacheId(); - cacheName = cacheCtx.name(); - allowFastEviction = cacheCtx.allowFastEviction(); + private PartitionDestroyRequest(CacheGroupContext grp, int partId) { + grpId = grp.groupId(); + name = grp.cacheOrGroupName(); + allowFastEviction = grp.allowFastEviction(); this.partId = partId; } @@ -3005,7 +2995,7 @@ private void waitCompleted() throws IgniteCheckedException { /** {@inheritDoc} */ @Override public String toString() { - return "PartitionDestroyRequest [cacheId=" + cacheId + ", cacheName=" + cacheName + + return "PartitionDestroyRequest [grpId=" + grpId + ", name=" + name + ", partId=" + partId + ']'; } } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java index 9bced4282b47c..3904205be9e17 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java @@ -17,9 +17,11 @@ package org.apache.ignite.internal.processors.cache.database; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.ignite.IgniteCheckedException; @@ -39,6 +41,7 @@ import org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl; @@ -48,6 +51,7 @@ import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; +import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionCountersIO; import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionMetaIO; import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseListImpl; @@ -56,6 +60,7 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.util.GridUnsafe; import org.apache.ignite.internal.util.lang.GridCursor; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.T2; @@ -80,60 +85,70 @@ public class GridCacheOffheapManager extends IgniteCacheOffheapManagerImpl imple RootPage reuseListRoot = metas.reuseListRoot; - reuseList = new ReuseListImpl(cctx.cacheId(), - cctx.name(), - cctx.memoryPolicy().pageMemory(), - cctx.shared().wal(), + reuseList = new ReuseListImpl(grp.groupId(), + grp.cacheOrGroupName(), + grp.memoryPolicy().pageMemory(), + ctx.wal(), reuseListRoot.pageId().pageId(), reuseListRoot.isAllocated()); RootPage metastoreRoot = metas.treeRoot; - metaStore = new MetadataStorage(cctx.memoryPolicy().pageMemory(), - cctx.shared().wal(), + metaStore = new MetadataStorage(grp.memoryPolicy().pageMemory(), + ctx.wal(), globalRemoveId(), - cctx.cacheId(), + grp.groupId(), PageIdAllocator.INDEX_PARTITION, PageIdAllocator.FLAG_IDX, reuseList, metastoreRoot.pageId().pageId(), metastoreRoot.isAllocated()); - if (cctx.shared().ttl().eagerTtlEnabled()) { - final String name = "PendingEntries"; + ((GridCacheDatabaseSharedManager)ctx.database()).addCheckpointListener(this); + } - RootPage pendingRootPage = metaStore.getOrAllocateForTree(name); + /** {@inheritDoc} */ + @Override public void onCacheStarted(GridCacheContext cctx) throws IgniteCheckedException { + if (cctx.affinityNode() && cctx.ttl().eagerTtlEnabled() && pendingEntries == null) { + ctx.database().checkpointReadLock(); - pendingEntries = new PendingEntriesTree( - cctx, - name, - cctx.memoryPolicy().pageMemory(), - pendingRootPage.pageId().pageId(), - reuseList, - pendingRootPage.isAllocated() - ); + try { + final String name = "PendingEntries"; + + RootPage pendingRootPage = metaStore.getOrAllocateForTree(name); + + pendingEntries = new PendingEntriesTree( + grp, + name, + grp.memoryPolicy().pageMemory(), + pendingRootPage.pageId().pageId(), + reuseList, + pendingRootPage.isAllocated() + ); + } + finally { + ctx.database().checkpointReadUnlock(); + } } - - ((GridCacheDatabaseSharedManager)cctx.shared().database()).addCheckpointListener(this); } /** {@inheritDoc} */ @Override protected CacheDataStore createCacheDataStore0(final int p) throws IgniteCheckedException { - GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)cctx.shared().database(); + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)ctx.database(); - if (!cctx.allowFastEviction()) - dbMgr.cancelOrWaitPartitionDestroy(cctx, p); + if (!grp.allowFastEviction()) + dbMgr.cancelOrWaitPartitionDestroy(grp.groupId(), p); - boolean exists = cctx.shared().pageStore() != null - && cctx.shared().pageStore().exists(cctx.cacheId(), p); + boolean exists = ctx.pageStore() != null + && ctx.pageStore().exists(grp.groupId(), p); return new GridCacheDataStore(p, exists); } /** {@inheritDoc} */ @Override public void onCheckpointBegin(Context ctx) throws IgniteCheckedException { - assert cctx.memoryPolicy().pageMemory() instanceof PageMemoryEx; + assert grp.memoryPolicy().pageMemory() instanceof PageMemoryEx; reuseList.saveMetadata(); @@ -167,11 +182,11 @@ private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean sav freeList.saveMetadata(); long updCntr = store.updateCounter(); - int size = store.size(); + int size = store.fullSize(); long rmvId = globalRemoveId().get(); - PageMemoryEx pageMem = (PageMemoryEx)cctx.memoryPolicy().pageMemory(); - IgniteWriteAheadLogManager wal = cctx.shared().wal(); + PageMemoryEx pageMem = (PageMemoryEx)grp.memoryPolicy().pageMemory(); + IgniteWriteAheadLogManager wal = this.ctx.wal(); if (size > 0 || updCntr > 0) { int state = -1; @@ -180,7 +195,7 @@ private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean sav state = GridDhtPartitionState.EVICTED.ordinal(); else { // localPartition will not acquire writeLock here because create=false. - GridDhtLocalPartition part = cctx.topology().localPartition(store.partId(), + GridDhtLocalPartition part = grp.topology().localPartition(store.partId(), AffinityTopologyVersion.NONE, false); if (part != null && part.state() != GridDhtPartitionState.EVICTED) @@ -191,12 +206,12 @@ private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean sav if (state == -1) return false; - int cacheId = cctx.cacheId(); - long partMetaId = pageMem.partitionMetaPageId(cacheId, store.partId()); - long partMetaPage = pageMem.acquirePage(cacheId, partMetaId); + int grpId = grp.groupId(); + long partMetaId = pageMem.partitionMetaPageId(grpId, store.partId()); + long partMetaPage = pageMem.acquirePage(grpId, partMetaId); try { - long pageAddr = pageMem.writeLock(cacheId, partMetaId, partMetaPage); + long pageAddr = pageMem.writeLock(grpId, partMetaId, partMetaPage); try { PagePartitionMetaIO io = PageIO.getPageIO(pageAddr); @@ -207,69 +222,132 @@ private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean sav io.setPartitionState(pageAddr, (byte)state); - int pageCount; + long cntrsPageId; + + if (grp.sharedGroup()) { + cntrsPageId = io.getCountersPageId(pageAddr); + + byte[] data = serializeCacheSizes(store.cacheSizes()); + + int items = data.length / 12; + int written = 0; + int pageSize = pageMem.pageSize(); + + boolean init = cntrsPageId == 0; + + if (init) { + cntrsPageId = pageMem.allocatePage(grpId, store.partId(), PageIdAllocator.FLAG_DATA); + io.setCountersPageId(pageAddr, cntrsPageId); + } + + long nextId = cntrsPageId; + + while (written != items) { + final long curId = nextId; + final long curPage = pageMem.acquirePage(grpId, curId); + + try { + final long curAddr = pageMem.writeLock(grpId, curId, curPage); + + assert curAddr != 0; + + try { + PagePartitionCountersIO partMetaIo; + + if (init) { + partMetaIo = PagePartitionCountersIO.VERSIONS.latest(); + partMetaIo.initNewPage(curAddr, curId, pageSize); + } + else + partMetaIo = PageIO.getPageIO(curAddr); + + written += partMetaIo.writeCacheSizes(pageSize, curAddr, data, written); + + nextId = partMetaIo.getNextCountersPageId(curAddr); + + if(written != items && (init = nextId == 0)) { + //allocate new counters page + nextId = pageMem.allocatePage(grpId, store.partId(), PageIdAllocator.FLAG_DATA); + partMetaIo.setNextCountersPageId(curAddr, nextId); + } + } + finally { + // Write full page + pageMem.writeUnlock(grpId, curId, curPage, Boolean.TRUE, true); + } + } + finally { + pageMem.releasePage(grpId, curId, curPage); + } + } + } + else + cntrsPageId = 0L; + + int pageCnt; if (beforeSnapshot) { - pageCount = cctx.shared().pageStore().pages(cctx.cacheId(), store.partId()); - io.setCandidatePageCount(pageAddr, pageCount); + pageCnt = this.ctx.pageStore().pages(grpId, store.partId()); + io.setCandidatePageCount(pageAddr, pageCnt); if (saveMeta) { - long metaPageId = pageMem.metaPageId(cctx.cacheId()); - long metaPage = pageMem.acquirePage(cctx.cacheId(), metaPageId); + long metaPageId = pageMem.metaPageId(grpId); + long metaPage = pageMem.acquirePage(grpId, metaPageId); try { - long metaPageAddr = pageMem.writeLock(cctx.cacheId(), metaPageId, metaPage); + long metaPageAddr = pageMem.writeLock(grpId, metaPageId, metaPage); try { long nextSnapshotTag = io.getNextSnapshotTag(metaPageAddr); io.setNextSnapshotTag(metaPageAddr, nextSnapshotTag + 1); - if (PageHandler.isWalDeltaRecordNeeded(pageMem, cctx.cacheId(), metaPageId, + if (PageHandler.isWalDeltaRecordNeeded(pageMem, grpId, metaPageId, metaPage, wal, null)) - wal.log(new MetaPageUpdateNextSnapshotId(cctx.cacheId(), metaPageId, + wal.log(new MetaPageUpdateNextSnapshotId(grpId, metaPageId, nextSnapshotTag + 1)); - addPartition(ctx.partitionStatMap(), metaPageAddr, io, cctx.cacheId(), PageIdAllocator.INDEX_PARTITION, - cctx.kernalContext().cache().context().pageStore().pages(cacheId, PageIdAllocator.INDEX_PARTITION)); + addPartition(ctx.partitionStatMap(), metaPageAddr, io, grpId, PageIdAllocator.INDEX_PARTITION, + this.ctx.kernalContext().cache().context().pageStore().pages(grpId, PageIdAllocator.INDEX_PARTITION)); } finally { - pageMem.writeUnlock(cctx.cacheId(), metaPageId, metaPage, null, true); + pageMem.writeUnlock(grpId, metaPageId, metaPage, null, true); } } finally { - pageMem.releasePage(cctx.cacheId(), metaPageId, metaPage); + pageMem.releasePage(grpId, metaPageId, metaPage); } wasSaveToMeta = true; } - GridDhtPartitionMap partMap = cctx.topology().localPartitionMap(); + GridDhtPartitionMap partMap = grp.topology().localPartitionMap(); if (partMap.containsKey(store.partId()) && partMap.get(store.partId()) == GridDhtPartitionState.OWNING) - addPartition(ctx.partitionStatMap(), pageAddr, io, cctx.cacheId(), store.partId(), - cctx.kernalContext().cache().context().pageStore().pages(cctx.cacheId(), store.partId())); + addPartition(ctx.partitionStatMap(), pageAddr, io, grpId, store.partId(), + this.ctx.pageStore().pages(grpId, store.partId())); } else - pageCount = io.getCandidatePageCount(pageAddr); + pageCnt = io.getCandidatePageCount(pageAddr); - if (PageHandler.isWalDeltaRecordNeeded(pageMem, cacheId, partMetaId, partMetaPage, wal, null)) + if (PageHandler.isWalDeltaRecordNeeded(pageMem, grpId, partMetaId, partMetaPage, wal, null)) wal.log(new MetaPageUpdatePartitionDataRecord( - cacheId, + grpId, partMetaId, updCntr, rmvId, size, + cntrsPageId, (byte)state, - pageCount + pageCnt )); } finally { - pageMem.writeUnlock(cacheId, partMetaId, partMetaPage, null, true); + pageMem.writeUnlock(grpId, partMetaId, partMetaPage, null, true); } } finally { - pageMem.releasePage(cacheId, partMetaId, partMetaPage); + pageMem.releasePage(grpId, partMetaId, partMetaPage); } } } @@ -277,6 +355,23 @@ private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean sav return wasSaveToMeta; } + /** + * @param cacheSizes Cache sizes. + * @return Serialized cache sizes + */ + private byte[] serializeCacheSizes(Map cacheSizes) { + // Item size = 4 bytes (cache ID) + 8 bytes (cache size) = 12 bytes + byte[] data = new byte[cacheSizes.size() * 12]; + long off = GridUnsafe.BYTE_ARR_OFF; + + for (Map.Entry entry : cacheSizes.entrySet()) { + GridUnsafe.putInt(data, off, entry.getKey()); off += 4; + GridUnsafe.putLong(data, off, entry.getValue()); off += 8; + } + + return data; + } + /** * @param map Map to add values to. * @param pageAddr page address @@ -304,23 +399,23 @@ private static void addPartition( /** {@inheritDoc} */ @Override protected void destroyCacheDataStore0(CacheDataStore store) throws IgniteCheckedException { - cctx.shared().database().checkpointReadLock(); + ctx.database().checkpointReadLock(); try { int p = store.partId(); saveStoreMetadata(store, null, false, true); - PageMemoryEx pageMemory = (PageMemoryEx)cctx.memoryPolicy().pageMemory(); + PageMemoryEx pageMemory = (PageMemoryEx)grp.memoryPolicy().pageMemory(); - int tag = pageMemory.invalidate(cctx.cacheId(), p); + int tag = pageMemory.invalidate(grp.groupId(), p); - cctx.shared().wal().log(new PartitionDestroyRecord(cctx.cacheId(), p)); + ctx.wal().log(new PartitionDestroyRecord(grp.groupId(), p)); - cctx.shared().pageStore().onPartitionDestroyed(cctx.cacheId(), p, tag); + ctx.pageStore().onPartitionDestroyed(grp.groupId(), p, tag); } finally { - cctx.shared().database().checkpointReadUnlock(); + ctx.database().checkpointReadUnlock(); } } @@ -354,12 +449,18 @@ private static void addPartition( } /** {@inheritDoc} */ - @Override public RootPage rootPageForIndex(String idxName) throws IgniteCheckedException { + @Override public RootPage rootPageForIndex(int cacheId, String idxName) throws IgniteCheckedException { + if (grp.sharedGroup()) + idxName = Integer.toString(cacheId) + "_" + idxName; + return metaStore.getOrAllocateForTree(idxName); } /** {@inheritDoc} */ - @Override public void dropRootPageForIndex(String idxName) throws IgniteCheckedException { + @Override public void dropRootPageForIndex(int cacheId, String idxName) throws IgniteCheckedException { + if (grp.sharedGroup()) + idxName = Integer.toString(cacheId) + "_" + idxName; + metaStore.dropRootPage(idxName); } @@ -369,10 +470,9 @@ private static void addPartition( } /** {@inheritDoc} */ - @Override protected void destroyCacheDataStructures() { - assert cctx.affinityNode(); - - ((GridCacheDatabaseSharedManager)cctx.shared().database()).removeCheckpointListener(this); + @Override public void stop() { + if (grp.affinityNode()) + ((GridCacheDatabaseSharedManager)ctx.database()).removeCheckpointListener(this); } /** @@ -380,14 +480,15 @@ private static void addPartition( * @throws IgniteCheckedException If failed. */ private Metas getOrAllocateCacheMetas() throws IgniteCheckedException { - PageMemoryEx pageMem = (PageMemoryEx) cctx.memoryPolicy().pageMemory(); - IgniteWriteAheadLogManager wal = cctx.shared().wal(); + PageMemoryEx pageMem = (PageMemoryEx)grp.memoryPolicy().pageMemory(); + IgniteWriteAheadLogManager wal = ctx.wal(); + + int grpId = grp.groupId(); + long metaId = pageMem.metaPageId(grpId); + long metaPage = pageMem.acquirePage(grpId, metaId); - int cacheId = cctx.cacheId(); - long metaId = pageMem.metaPageId(cacheId); - long metaPage = pageMem.acquirePage(cacheId, metaId); try { - final long pageAddr = pageMem.writeLock(cacheId, metaId, metaPage); + final long pageAddr = pageMem.writeLock(grpId, metaId, metaPage); boolean allocated = false; @@ -399,15 +500,15 @@ private Metas getOrAllocateCacheMetas() throws IgniteCheckedException { pageIO.initNewPage(pageAddr, metaId, pageMem.pageSize()); - metastoreRoot = pageMem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX); - reuseListRoot = pageMem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX); + metastoreRoot = pageMem.allocatePage(grpId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX); + reuseListRoot = pageMem.allocatePage(grpId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX); pageIO.setTreeRoot(pageAddr, metastoreRoot); pageIO.setReuseListRoot(pageAddr, reuseListRoot); - if (PageHandler.isWalDeltaRecordNeeded(pageMem, cacheId, metaId, metaPage, wal, null)) + if (PageHandler.isWalDeltaRecordNeeded(pageMem, grpId, metaId, metaPage, wal, null)) wal.log(new MetaPageInitRecord( - cacheId, + grpId, metaId, pageIO.getType(), pageIO.getVersion(), @@ -427,15 +528,15 @@ private Metas getOrAllocateCacheMetas() throws IgniteCheckedException { } return new Metas( - new RootPage(new FullPageId(metastoreRoot, cacheId), allocated), - new RootPage(new FullPageId(reuseListRoot, cacheId), allocated)); + new RootPage(new FullPageId(metastoreRoot, grpId), allocated), + new RootPage(new FullPageId(reuseListRoot, grpId), allocated)); } finally { - pageMem.writeUnlock(cacheId, metaId, metaPage, null, allocated); + pageMem.writeUnlock(grpId, metaId, metaPage, null, allocated); } } finally { - pageMem.releasePage(cacheId, metaId, metaPage); + pageMem.releasePage(grpId, metaId, metaPage); } } @@ -445,10 +546,10 @@ private Metas getOrAllocateCacheMetas() throws IgniteCheckedException { if (partCntrSince == null) return super.rebalanceIterator(part, topVer, partCntrSince); - GridCacheDatabaseSharedManager database = (GridCacheDatabaseSharedManager)cctx.shared().database(); + GridCacheDatabaseSharedManager database = (GridCacheDatabaseSharedManager)ctx.database(); try { - WALPointer startPtr = database.searchPartitionCounter(cctx, part, partCntrSince); + WALPointer startPtr = database.searchPartitionCounter(grp.groupId(), part, partCntrSince); if (startPtr == null) { assert false : "partCntr=" + partCntrSince + ", reservations=" + S.toString(Map.class, database.reservedForPreloading()); @@ -456,9 +557,9 @@ private Metas getOrAllocateCacheMetas() throws IgniteCheckedException { return super.rebalanceIterator(part, topVer, partCntrSince); } - WALIterator it = cctx.shared().wal().replay(startPtr); + WALIterator it = ctx.wal().replay(startPtr); - return new RebalanceIteratorAdapter(cctx, it, part); + return new RebalanceIteratorAdapter(grp, it, part); } catch (IgniteCheckedException e) { U.warn(log, "Failed to create WAL-based rebalance iterator (a full partition will transferred to a " + @@ -475,14 +576,14 @@ private static class RebalanceIteratorAdapter implements IgniteRebalanceIterator /** Serial version uid. */ private static final long serialVersionUID = 0L; - /** Cache context. */ - private GridCacheContext cctx; + /** Cache group caches. */ + private final Set cacheGrpCaches; /** WAL iterator. */ - private WALIterator walIt; + private final WALIterator walIt; /** Partition to scan. */ - private int part; + private final int part; /** */ private Iterator entryIt; @@ -491,12 +592,12 @@ private static class RebalanceIteratorAdapter implements IgniteRebalanceIterator private CacheDataRow next; /** - * @param cctx Cache context. + * @param grp Cache group. * @param walIt WAL iterator. * @param part Partition ID. */ - private RebalanceIteratorAdapter(GridCacheContext cctx, WALIterator walIt, int part) { - this.cctx = cctx; + private RebalanceIteratorAdapter(CacheGroupContext grp, WALIterator walIt, int part) { + this.cacheGrpCaches = grp.cacheIds(); this.walIt = walIt; this.part = part; @@ -571,8 +672,7 @@ private void advance() { while (entryIt.hasNext()) { DataEntry entry = entryIt.next(); - if (entry.cacheId() == cctx.cacheId() && - entry.partitionId() == part) { + if (entry.partitionId() == part && cacheGrpCaches.contains(entry.cacheId())) { next = new DataEntryRow(entry); @@ -745,7 +845,7 @@ private CacheDataStore init0(boolean checkExists) throws IgniteCheckedException return null; } - IgniteCacheDatabaseSharedManager dbMgr = cctx.shared().database(); + IgniteCacheDatabaseSharedManager dbMgr = ctx.database(); dbMgr.checkpointReadLock(); @@ -756,12 +856,12 @@ private CacheDataStore init0(boolean checkExists) throws IgniteCheckedException RootPage reuseRoot = metas.reuseListRoot; freeList = new FreeListImpl( - cctx.cacheId(), - cctx.name() + "-" + partId, - (MemoryMetricsImpl)cctx.memoryPolicy().memoryMetrics(), - cctx.memoryPolicy(), + grp.groupId(), + grp.cacheOrGroupName() + "-" + partId, + grp.memoryPolicy().memoryMetrics(), + grp.memoryPolicy(), null, - cctx.shared().wal(), + ctx.wal(), reuseRoot.pageId().pageId(), reuseRoot.isAllocated()) { @Override protected long allocatePageNoReuse() throws IgniteCheckedException { @@ -769,15 +869,15 @@ private CacheDataStore init0(boolean checkExists) throws IgniteCheckedException } }; - CacheDataRowStore rowStore = new CacheDataRowStore(cctx, freeList, partId); + CacheDataRowStore rowStore = new CacheDataRowStore(grp, freeList, partId); RootPage treeRoot = metas.treeRoot; CacheDataTree dataTree = new CacheDataTree( + grp, name, freeList, rowStore, - cctx, treeRoot.pageId().pageId(), treeRoot.isAllocated()) { @Override protected long allocatePageNoReuse() throws IgniteCheckedException { @@ -785,31 +885,72 @@ private CacheDataStore init0(boolean checkExists) throws IgniteCheckedException } }; - PageMemoryEx pageMem = (PageMemoryEx)cctx.memoryPolicy().pageMemory(); + PageMemoryEx pageMem = (PageMemoryEx)grp.memoryPolicy().pageMemory(); delegate0 = new CacheDataStoreImpl(partId, name, rowStore, dataTree); - int cacheId = cctx.cacheId(); - long partMetaId = pageMem.partitionMetaPageId(cacheId, partId); - long partMetaPage = pageMem.acquirePage(cacheId, partMetaId); + int grpId = grp.groupId(); + long partMetaId = pageMem.partitionMetaPageId(grpId, partId); + long partMetaPage = pageMem.acquirePage(grpId, partMetaId); + try { - long pageAddr = pageMem.readLock(cacheId, partMetaId, partMetaPage); + long pageAddr = pageMem.readLock(grpId, partMetaId, partMetaPage); try { if (PageIO.getType(pageAddr) != 0) { PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.latest(); - delegate0.init(io.getSize(pageAddr), io.getUpdateCounter(pageAddr)); + Map cacheSizes = null; + + if (grp.sharedGroup()) { + long cntrsPageId = io.getCountersPageId(pageAddr); + + if (cntrsPageId != 0L) { + cacheSizes = new HashMap<>(); + + long nextId = cntrsPageId; + + while (true){ + final long curId = nextId; + final long curPage = pageMem.acquirePage(grpId, curId); + + try { + final long curAddr = pageMem.readLock(grpId, curId, curPage); + + assert curAddr != 0; - cctx.offheap().globalRemoveId().setIfGreater(io.getGlobalRemoveId(pageAddr)); + try { + PagePartitionCountersIO cntrsIO = PageIO.getPageIO(curAddr); + + if (cntrsIO.readCacheSizes(curAddr, cacheSizes)) + break; + + nextId = cntrsIO.getNextCountersPageId(curAddr); + + assert nextId != 0; + } + finally { + pageMem.readUnlock(grpId, curId, curPage); + } + } + finally { + pageMem.releasePage(grpId, curId, curPage); + } + } + } + } + + delegate0.init(io.getSize(pageAddr), io.getUpdateCounter(pageAddr), cacheSizes); + + globalRemoveId().setIfGreater(io.getGlobalRemoveId(pageAddr)); } } finally { - pageMem.readUnlock(cacheId, partMetaId, partMetaPage); + pageMem.readUnlock(grpId, partMetaId, partMetaPage); } } finally { - pageMem.releasePage(cacheId, partMetaId, partMetaPage); + pageMem.releasePage(grpId, partMetaId, partMetaPage); } delegate = delegate0; @@ -838,15 +979,15 @@ private CacheDataStore init0(boolean checkExists) throws IgniteCheckedException * @return Partition metas. */ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { - PageMemoryEx pageMem = (PageMemoryEx)cctx.memoryPolicy().pageMemory(); - IgniteWriteAheadLogManager wal = cctx.shared().wal(); + PageMemoryEx pageMem = (PageMemoryEx)grp.memoryPolicy().pageMemory(); + IgniteWriteAheadLogManager wal = ctx.wal(); - int cacheId = cctx.cacheId(); - long partMetaId = pageMem.partitionMetaPageId(cacheId, partId); - long partMetaPage = pageMem.acquirePage(cacheId, partMetaId); + int grpId = grp.groupId(); + long partMetaId = pageMem.partitionMetaPageId(grpId, partId); + long partMetaPage = pageMem.acquirePage(grpId, partMetaId); try { boolean allocated = false; - long pageAddr = pageMem.writeLock(cacheId, partMetaId, partMetaPage); + long pageAddr = pageMem.writeLock(grpId, partMetaId, partMetaPage); try { long treeRoot, reuseListRoot; @@ -857,8 +998,8 @@ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { io.initNewPage(pageAddr, partMetaId, pageMem.pageSize()); - treeRoot = pageMem.allocatePage(cacheId, partId, PageMemory.FLAG_DATA); - reuseListRoot = pageMem.allocatePage(cacheId, partId, PageMemory.FLAG_DATA); + treeRoot = pageMem.allocatePage(grpId, partId, PageMemory.FLAG_DATA); + reuseListRoot = pageMem.allocatePage(grpId, partId, PageMemory.FLAG_DATA); assert PageIdUtils.flag(treeRoot) == PageMemory.FLAG_DATA; assert PageIdUtils.flag(reuseListRoot) == PageMemory.FLAG_DATA; @@ -866,9 +1007,9 @@ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { io.setTreeRoot(pageAddr, treeRoot); io.setReuseListRoot(pageAddr, reuseListRoot); - if (PageHandler.isWalDeltaRecordNeeded(pageMem, cacheId, partMetaId, partMetaPage, wal, null)) + if (PageHandler.isWalDeltaRecordNeeded(pageMem, grpId, partMetaId, partMetaPage, wal, null)) wal.log(new MetaPageInitRecord( - cctx.cacheId(), + grpId, partMetaId, io.getType(), io.getVersion(), @@ -885,21 +1026,21 @@ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { reuseListRoot = io.getReuseListRoot(pageAddr); assert PageIdUtils.flag(treeRoot) == PageMemory.FLAG_DATA : - U.hexLong(treeRoot) + ", part=" + partId + ", cacheId=" + cacheId; + U.hexLong(treeRoot) + ", part=" + partId + ", grpId=" + grpId; assert PageIdUtils.flag(reuseListRoot) == PageMemory.FLAG_DATA : - U.hexLong(reuseListRoot) + ", part=" + partId + ", cacheId=" + cacheId; + U.hexLong(reuseListRoot) + ", part=" + partId + ", grpId=" + grpId; } return new Metas( - new RootPage(new FullPageId(treeRoot, cacheId), allocated), - new RootPage(new FullPageId(reuseListRoot, cacheId), allocated)); + new RootPage(new FullPageId(treeRoot, grpId), allocated), + new RootPage(new FullPageId(reuseListRoot, grpId), allocated)); } finally { - pageMem.writeUnlock(cacheId, partMetaId, partMetaPage, null, allocated); + pageMem.writeUnlock(grpId, partMetaId, partMetaPage, null, allocated); } } finally { - pageMem.releasePage(cacheId, partMetaId, partMetaPage); + pageMem.releasePage(grpId, partMetaId, partMetaPage); } } @@ -921,11 +1062,35 @@ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { } /** {@inheritDoc} */ - @Override public int size() { + @Override public int fullSize() { + try { + CacheDataStore delegate0 = init0(true); + + return delegate0 == null ? 0 : delegate0.fullSize(); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + } + + /** {@inheritDoc} */ + @Override public int cacheSize(int cacheId) { + try { + CacheDataStore delegate0 = init0(true); + + return delegate0 == null ? 0 : delegate0.cacheSize(cacheId); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + } + + /** {@inheritDoc} */ + @Override public Map cacheSizes() { try { CacheDataStore delegate0 = init0(true); - return delegate0 == null ? 0 : delegate0.size(); + return delegate0 == null ? null : delegate0.cacheSizes(); } catch (IgniteCheckedException e) { throw new IgniteException(e); @@ -945,7 +1110,7 @@ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { } /** {@inheritDoc} */ - @Override public void init(long size, long updCntr) { + @Override public void init(long size, long updCntr, @Nullable Map cacheSizes) { throw new IllegalStateException("Should be never called."); } @@ -1001,6 +1166,7 @@ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { /** {@inheritDoc} */ @Override public void update( + GridCacheContext cctx, KeyCacheObject key, CacheObject val, GridCacheVersion ver, @@ -1009,47 +1175,51 @@ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { ) throws IgniteCheckedException { CacheDataStore delegate = init0(false); - delegate.update(key, val, ver, expireTime, oldRow); + delegate.update(cctx, key, val, ver, expireTime, oldRow); } /** {@inheritDoc} */ - @Override public void updateIndexes(KeyCacheObject key) throws IgniteCheckedException { + @Override public void updateIndexes(GridCacheContext cctx, KeyCacheObject key) throws IgniteCheckedException { CacheDataStore delegate = init0(false); - delegate.updateIndexes(key); + delegate.updateIndexes(cctx, key); } /** {@inheritDoc} */ - @Override public CacheDataRow createRow(KeyCacheObject key, + @Override public CacheDataRow createRow( + GridCacheContext cctx, + KeyCacheObject key, CacheObject val, GridCacheVersion ver, long expireTime, @Nullable CacheDataRow oldRow) throws IgniteCheckedException { CacheDataStore delegate = init0(false); - return delegate.createRow(key, val, ver, expireTime, oldRow); + return delegate.createRow(cctx, key, val, ver, expireTime, oldRow); } /** {@inheritDoc} */ - @Override public void invoke(KeyCacheObject key, OffheapInvokeClosure c) throws IgniteCheckedException { + @Override public void invoke(GridCacheContext cctx, KeyCacheObject key, OffheapInvokeClosure c) + throws IgniteCheckedException { CacheDataStore delegate = init0(false); - delegate.invoke(key, c); + delegate.invoke(cctx, key, c); } /** {@inheritDoc} */ - @Override public void remove(KeyCacheObject key, int partId) throws IgniteCheckedException { + @Override public void remove(GridCacheContext cctx, KeyCacheObject key, int partId) + throws IgniteCheckedException { CacheDataStore delegate = init0(false); - delegate.remove(key, partId); + delegate.remove(cctx, key, partId); } /** {@inheritDoc} */ - @Override public CacheDataRow find(KeyCacheObject key) throws IgniteCheckedException { + @Override public CacheDataRow find(GridCacheContext cctx, KeyCacheObject key) throws IgniteCheckedException { CacheDataStore delegate = init0(true); if (delegate != null) - return delegate.find(key); + return delegate.find(cctx, key); return null; } @@ -1065,12 +1235,28 @@ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { } /** {@inheritDoc} */ - @Override public GridCursor cursor(KeyCacheObject lower, + @Override public GridCursor cursor( + int cacheId, + KeyCacheObject lower, KeyCacheObject upper) throws IgniteCheckedException { CacheDataStore delegate = init0(true); if (delegate != null) - return delegate.cursor(lower, upper); + return delegate.cursor(cacheId, lower, upper); + + return EMPTY_CURSOR; + } + + /** {@inheritDoc} */ + @Override public GridCursor cursor(int cacheId, + KeyCacheObject lower, + KeyCacheObject upper, + Object x) + throws IgniteCheckedException { + CacheDataStore delegate = init0(true); + + if (delegate != null) + return delegate.cursor(cacheId, lower, upper, x); return EMPTY_CURSOR; } @@ -1079,6 +1265,24 @@ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { @Override public void destroy() throws IgniteCheckedException { // No need to destroy delegate. } + + /** {@inheritDoc} */ + @Override public GridCursor cursor(int cacheId) throws IgniteCheckedException { + CacheDataStore delegate = init0(true); + + if (delegate != null) + return delegate.cursor(cacheId); + + return EMPTY_CURSOR; + } + + /** {@inheritDoc} */ + @Override public void clear(int cacheId) throws IgniteCheckedException { + CacheDataStore delegate = init0(true); + + if (delegate != null) + delegate.clear(cacheId); + } } /** diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java index c233b1ea41543..1343589172bce 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java @@ -29,7 +29,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; -import java.util.HashSet; +import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -43,10 +43,10 @@ import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; import org.apache.ignite.internal.pagemem.store.PageStore; -import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; +import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.marshaller.Marshaller; import org.apache.ignite.marshaller.jdk.JdkMarshaller; @@ -71,6 +71,9 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen /** */ public static final String CACHE_DIR_PREFIX = "cache-"; + /** */ + public static final String CACHE_GRP_DIR_PREFIX = "cacheGroup-"; + /** */ public static final String CACHE_CONF_FILENAME = "conf.dat"; @@ -93,7 +96,7 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen private final long metaPageId = PageIdUtils.pageId(-1, PageMemory.FLAG_IDX, 0); /** */ - private final Set cachesWithoutIdx = Collections.newSetFromMap(new ConcurrentHashMap()); + private final Set grpsWithoutIdx = Collections.newSetFromMap(new ConcurrentHashMap()); /** * @param ctx Kernal context. @@ -189,25 +192,59 @@ public FilePageStoreManager(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void initializeForCache(CacheConfiguration ccfg) throws IgniteCheckedException { - int cacheId = CU.cacheId(ccfg.getName()); + @Override public void initializeForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) + throws IgniteCheckedException { + int grpId = grpDesc.groupId(); - if (!idxCacheStores.containsKey(cacheId)) { - CacheStoreHolder holder = initForCache(ccfg); + if (!idxCacheStores.containsKey(grpId)) { + CacheStoreHolder holder = initForCache(grpDesc, ccfg); - CacheStoreHolder old = idxCacheStores.put(cacheId, holder); + CacheStoreHolder old = idxCacheStores.put(grpId, holder); assert old == null : "Non-null old store holder for cache: " + ccfg.getName(); } + + storeCacheConfiguration(grpDesc, ccfg); + } + + /** + * @param grpDesc Cache group descriptor. + * @param ccfg Cache configuration. + * @throws IgniteCheckedException If failed. + */ + private void storeCacheConfiguration(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) + throws IgniteCheckedException { + File cacheWorkDir = cacheWorkDirectory(grpDesc, ccfg); + File file; + + assert cacheWorkDir.exists() : "Work directory does not exist: " + cacheWorkDir; + + if (grpDesc.sharedGroup()) + file = new File(cacheWorkDir, ccfg.getName() + CACHE_CONF_FILENAME); + else + file = new File(cacheWorkDir, CACHE_CONF_FILENAME); + + if (!file.exists() || file.length() == 0) { + try { + file.createNewFile(); + + try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(file))) { + marshaller.marshal(ccfg, stream); + } + } + catch (IOException ex) { + throw new IgniteCheckedException("Failed to persist cache configuration: " + ccfg.getName(), ex); + } + } } /** {@inheritDoc} */ - @Override public void shutdownForCache(GridCacheContext cacheCtx, boolean destroy) throws IgniteCheckedException { - cachesWithoutIdx.remove(cacheCtx.cacheId()); + @Override public void shutdownForCacheGroup(CacheGroupContext grp, boolean destroy) throws IgniteCheckedException { + grpsWithoutIdx.remove(grp.groupId()); - CacheStoreHolder old = idxCacheStores.remove(cacheCtx.cacheId()); + CacheStoreHolder old = idxCacheStores.remove(grp.groupId()); - assert old != null : "Missing cache store holder [cache=" + cacheCtx.name() + + assert old != null : "Missing cache store holder [cache=" + grp.cacheOrGroupName() + ", locNodeId=" + cctx.localNodeId() + ", gridName=" + cctx.igniteInstanceName() + ']'; IgniteCheckedException ex = shutdown(old, /*clean files if destroy*/destroy, null); @@ -217,17 +254,17 @@ public FilePageStoreManager(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void onPartitionCreated(int cacheId, int partId) throws IgniteCheckedException { + @Override public void onPartitionCreated(int grpId, int partId) throws IgniteCheckedException { // No-op. } /** {@inheritDoc} */ - @Override public void onPartitionDestroyed(int cacheId, int partId, int tag) throws IgniteCheckedException { + @Override public void onPartitionDestroyed(int grpId, int partId, int tag) throws IgniteCheckedException { assert partId <= PageIdAllocator.MAX_PARTITION_ID; - PageStore store = getStore(cacheId, partId); + PageStore store = getStore(grpId, partId); - assert store instanceof FilePageStore; + assert store instanceof FilePageStore : store; ((FilePageStore)store).truncate(tag); } @@ -253,8 +290,8 @@ public void read(int cacheId, long pageId, ByteBuffer pageBuf, boolean keepCrc) } /** {@inheritDoc} */ - @Override public boolean exists(int cacheId, int partId) throws IgniteCheckedException { - PageStore store = getStore(cacheId, partId); + @Override public boolean exists(int grpId, int partId) throws IgniteCheckedException { + PageStore store = getStore(grpId, partId); return store.exists(); } @@ -296,12 +333,31 @@ public PageStore writeInternal(int cacheId, long pageId, ByteBuffer pageBuf, int } /** + * @param grpDesc Cache group descriptor. + * @param ccfg Cache configuration. + * @return Cache work directory. + */ + private File cacheWorkDirectory(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) { + String dirName; + + if (grpDesc.sharedGroup()) + dirName = CACHE_GRP_DIR_PREFIX + ccfg.getGroupName(); + else + dirName = CACHE_DIR_PREFIX + ccfg.getName(); + + return new File(storeWorkDir, dirName); + } + + /** + * @param grpDesc Cache group descriptor. * @param ccfg Cache configuration. * @return Cache store holder. * @throws IgniteCheckedException If failed. */ - private CacheStoreHolder initForCache(CacheConfiguration ccfg) throws IgniteCheckedException { - File cacheWorkDir = new File(storeWorkDir, CACHE_DIR_PREFIX + ccfg.getName()); + private CacheStoreHolder initForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) throws IgniteCheckedException { + assert !grpDesc.sharedGroup() || ccfg.getGroupName() != null : ccfg.getName(); + + File cacheWorkDir = cacheWorkDirectory(grpDesc, ccfg); boolean dirExisted = false; @@ -358,32 +414,17 @@ private CacheStoreHolder initForCache(CacheConfiguration ccfg) throws IgniteChec dirExisted = true; } - File file = new File(cacheWorkDir, CACHE_CONF_FILENAME); - - if (!file.exists() || file.length() == 0) { - try { - file.createNewFile(); - - try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(file))) { - marshaller.marshal(ccfg, stream); - } - } - catch (IOException ex) { - throw new IgniteCheckedException("Failed to persist cache configuration: " + ccfg.getName(), ex); - } - } - File idxFile = new File(cacheWorkDir, INDEX_FILE_NAME); if (dirExisted && !idxFile.exists()) - cachesWithoutIdx.add(CU.cacheId(ccfg.getName())); + grpsWithoutIdx.add(grpDesc.groupId()); FilePageStore idxStore = new FilePageStore( PageMemory.FLAG_IDX, idxFile, cctx.kernalContext().config().getMemoryConfiguration()); - FilePageStore[] partStores = new FilePageStore[ccfg.getAffinity().partitions()]; + FilePageStore[] partStores = new FilePageStore[grpDesc.config().getAffinity().partitions()]; for (int partId = 0; partId < partStores.length; partId++) { FilePageStore partStore = new FilePageStore( @@ -432,52 +473,74 @@ private CacheStoreHolder initForCache(CacheConfiguration ccfg) throws IgniteChec } /** {@inheritDoc} */ - @Override public Set savedCacheNames() { + @Override public Map readCacheConfigurations() throws IgniteCheckedException { if (cctx.kernalContext().clientNode()) - return Collections.emptySet(); + return Collections.emptyMap(); File[] files = storeWorkDir.listFiles(); if (files == null) - return Collections.emptySet(); + return Collections.emptyMap(); - Set cacheNames = new HashSet<>(); + Map ccfgs = new HashMap<>(); for (File file : files) { - if (file.isDirectory() && file.getName().startsWith(CACHE_DIR_PREFIX)) { - File conf = new File(file, CACHE_CONF_FILENAME); - if (conf.exists() && conf.length() > 0) { - String name = file.getName().substring(CACHE_DIR_PREFIX.length()); + if (file.isDirectory()) { + if (file.getName().startsWith(CACHE_DIR_PREFIX)) { + File conf = new File(file, CACHE_CONF_FILENAME); - // TODO remove when fixed null cache names. - if ("null".equals(name)) - name = null; + if (conf.exists() && conf.length() > 0) { + CacheConfiguration ccfg = readCacheConfig(conf); - cacheNames.add(name); + ccfgs.put(ccfg.getName(), ccfg); + } } + else if (file.getName().startsWith(CACHE_GRP_DIR_PREFIX)) + readCacheGroupCaches(file, ccfgs); } } - return cacheNames; + return ccfgs; } - /** {@inheritDoc} */ - @Override public CacheConfiguration readConfiguration(String cacheName) { - File file = new File(storeWorkDir, CACHE_DIR_PREFIX + cacheName); + /** + * @param grpDir Group directory. + * @param ccfgs Cache configurations. + * @throws IgniteCheckedException If failed. + */ + private void readCacheGroupCaches(File grpDir, Map ccfgs) throws IgniteCheckedException { + File[] files = grpDir.listFiles(); - assert file.exists() && file.isDirectory(); + if (files == null) + return; - try (InputStream stream = new BufferedInputStream(new FileInputStream(new File(file, CACHE_CONF_FILENAME)))) { + for (File file : files) { + if (!file.isDirectory() && file.getName().endsWith(CACHE_CONF_FILENAME) && file.length() > 0) { + CacheConfiguration ccfg = readCacheConfig(file); + + ccfgs.put(ccfg.getName(), ccfg); + } + } + } + + /** + * @param conf File with stored configuration. + * @return Cache configuration. + * @throws IgniteCheckedException If failed. + */ + private CacheConfiguration readCacheConfig(File conf) throws IgniteCheckedException { + try (InputStream stream = new BufferedInputStream(new FileInputStream(conf))) { return marshaller.unmarshal(stream, U.resolveClassLoader(igniteCfg)); } - catch (IOException | IgniteCheckedException e) { - throw new IllegalStateException("Failed to read cache configuration from disk for cache: " + cacheName, e); + catch (IOException e) { + throw new IgniteCheckedException("Failed to read cache configuration from disk for cache: " + + conf.getAbsolutePath(), e); } } /** {@inheritDoc} */ - @Override public boolean hasIndexStore(int cacheId) { - return !cachesWithoutIdx.contains(cacheId); + @Override public boolean hasIndexStore(int grpId) { + return !grpsWithoutIdx.contains(grpId); } /** @@ -488,11 +551,14 @@ public File workDir() { } /** - * @param cacheName Cache name. + * @param ccfg Cache configuration. * @return Store dir for given cache. */ - public File cacheWorkDir(String cacheName) { - return new File(storeWorkDir, "cache-" + cacheName); + public File cacheWorkDir(CacheConfiguration ccfg) { + String dirName = ccfg.getGroupName() == null ? + CACHE_DIR_PREFIX + ccfg.getName() : CACHE_GRP_DIR_PREFIX + ccfg.getGroupName(); + + return new File(storeWorkDir, dirName); } /** @@ -547,19 +613,19 @@ private IgniteCheckedException shutdown(FilePageStore store, boolean cleanFile, } /** - * @param cacheId Cache ID. + * @param grpId Cache group ID. * @param partId Partition ID. * @return Page store for the corresponding parameters. * @throws IgniteCheckedException If cache or partition with the given ID was not created. * * Note: visible for testing. */ - public PageStore getStore(int cacheId, int partId) throws IgniteCheckedException { - CacheStoreHolder holder = idxCacheStores.get(cacheId); + public PageStore getStore(int grpId, int partId) throws IgniteCheckedException { + CacheStoreHolder holder = idxCacheStores.get(grpId); if (holder == null) throw new IgniteCheckedException("Failed to get page store for the given cache ID " + - "(cache has not been started): " + cacheId); + "(cache has not been started): " + grpId); if (partId == PageIdAllocator.INDEX_PARTITION) return holder.idxStore; @@ -571,7 +637,7 @@ public PageStore getStore(int cacheId, int partId) throws IgniteCheckedException if (store == null) throw new IgniteCheckedException("Failed to get page store for the given partition ID " + - "(partition has not been created) [cacheId=" + cacheId + ", partId=" + partId + ']'); + "(partition has not been created) [grpId=" + grpId + ", partId=" + partId + ']'); return store; } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java index e8ae554643ef8..ef84d83a685bf 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java @@ -131,16 +131,16 @@ void writeUnlock(int cacheId, long pageId, long page, Boolean walPlc, public int invalidate(int cacheId, int partId); /** - * Clears internal metadata of destroyed cache. + * Clears internal metadata of destroyed cache group. * - * @param cacheId Cache ID. + * @param grpId Cache group ID. */ - public void onCacheDestroyed(int cacheId); + public void onCacheGroupDestroyed(int grpId); /** * Asynchronously clears pages satisfying the given predicate. * - * @param pred Predicate for cacheId, pageId and partition tag. + * @param pred Predicate for cache group id, pageId and partition tag. * @param cleanDirty Flag indicating that dirty pages collection should be cleaned. * @return Future that will be completed when all pages are cleared. */ diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java index c05af572e122a..f807229c91253 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java @@ -960,12 +960,12 @@ private void copyInBuffer(long absPtr, ByteBuffer tmpBuf) { } /** {@inheritDoc} */ - @Override public void onCacheDestroyed(int cacheId) { + @Override public void onCacheGroupDestroyed(int grpId) { for (Segment seg : segments) { seg.writeLock().lock(); try { - seg.resetPartTags(cacheId); + seg.resetPartTags(grpId); } finally { seg.writeLock().unlock(); @@ -1892,9 +1892,9 @@ else if (tag == Integer.MAX_VALUE) { } /** - * @param cacheId Cache id. + * @param grpId Cache group id. */ - private void resetPartTags(int cacheId) { + private void resetPartTags(int grpId) { assert getWriteHoldCount() > 0; Iterator> iter = partTagMap.keySet().iterator(); @@ -1902,7 +1902,7 @@ private void resetPartTags(int cacheId) { while (iter.hasNext()) { T2 t = iter.next(); - if (t.get1() == cacheId) + if (t.get1() == grpId) iter.remove(); } } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java index f67f617ef68a9..4f532aef3f552 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java @@ -197,6 +197,7 @@ public RecordV1Serializer(GridCacheSharedContext cctx) { buf.putLong(partDataRec.updateCounter()); buf.putLong(partDataRec.globalRemoveId()); buf.putInt(partDataRec.partitionSize()); + buf.putLong(partDataRec.countersPageId()); buf.put(partDataRec.state()); buf.putInt(partDataRec.allocatedIndexCandidate()); @@ -222,7 +223,7 @@ public RecordV1Serializer(GridCacheSharedContext cctx) { buf.putInt(walPtr.length()); } - putCacheStates(buf, cpRec.cacheStates()); + putCacheStates(buf, cpRec.cacheGroupStates()); buf.put(cpRec.end() ? (byte)1 : 0); @@ -730,7 +731,7 @@ private WALRecord readRecord(ByteBufferBackedDataInput in) throws IOException, I CheckpointRecord cpRec = new CheckpointRecord(new UUID(msb, lsb), walPtr, end); - cpRec.cacheStates(states); + cpRec.cacheGroupStates(states); res = cpRec; @@ -756,10 +757,11 @@ private WALRecord readRecord(ByteBufferBackedDataInput in) throws IOException, I long updCntr = in.readLong(); long rmvId = in.readLong(); int partSize = in.readInt(); + long countersPageId = in.readLong(); byte state = in.readByte(); int allocatedIdxCandidate = in.readInt(); - res = new MetaPageUpdatePartitionDataRecord(cacheId, pageId, updCntr, rmvId, partSize, state, allocatedIdxCandidate); + res = new MetaPageUpdatePartitionDataRecord(cacheId, pageId, updCntr, rmvId, partSize, countersPageId, state, allocatedIdxCandidate); break; @@ -1234,7 +1236,7 @@ assert record instanceof PageSnapshot; assert cpRec.checkpointMark() == null || cpRec.checkpointMark() instanceof FileWALPointer : "Invalid WAL record: " + cpRec; - int cacheStatesSize = cacheStatesSize(cpRec.cacheStates()); + int cacheStatesSize = cacheStatesSize(cpRec.cacheGroupStates()); FileWALPointer walPtr = (FileWALPointer)cpRec.checkpointMark(); @@ -1244,7 +1246,7 @@ assert record instanceof PageSnapshot; return 1 + /*cache ID*/4 + /*page ID*/8 + /*ioType*/2 + /*ioVer*/2 + /*tree root*/8 + /*reuse root*/8 + /*CRC*/4; case PARTITION_META_PAGE_UPDATE_COUNTERS: - return 1 + /*cache ID*/4 + /*page ID*/8 + /*upd cntr*/8 + /*rmv id*/8 + /*part size*/4 + /*state*/ 1 + return 1 + /*cache ID*/4 + /*page ID*/8 + /*upd cntr*/8 + /*rmv id*/8 + /*part size*/4 + /*counters page id*/8 + /*state*/ 1 + /*allocatedIdxCandidate*/ 4 + /*CRC*/4; case MEMORY_RECOVERY: diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheGroupsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheGroupsTest.java new file mode 100644 index 0000000000000..7a6b34c179fc5 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheGroupsTest.java @@ -0,0 +1,516 @@ +/* + * 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.cache.database; +import java.io.Serializable; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; +import javax.cache.Cache; +import javax.cache.expiry.ExpiryPolicy; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.query.SqlQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.internal.S; +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.CacheMode.PARTITIONED; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; + +/** + * + */ +public class IgnitePersistentStoreCacheGroupsTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final String GROUP1 = "grp1"; + + /** */ + private static final String GROUP2 = "grp2"; + + /** */ + private CacheConfiguration[] ccfgs; + + /** */ + private boolean activeOnStart = true; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + + GridTestUtils.deleteDbFiles(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + GridTestUtils.deleteDbFiles(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setConsistentId(gridName); + + cfg.setActiveOnStart(activeOnStart); + + MemoryConfiguration memCfg = new MemoryConfiguration(); + memCfg.setPageSize(1024); + memCfg.setDefaultMemoryPolicySize(10 * 1024 * 1024); + + cfg.setMemoryConfiguration(memCfg); + + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + + cfg.setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(false)); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER); + + if (ccfgs != null) { + cfg.setCacheConfiguration(ccfgs); + + ccfgs = null; + } + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + GridTestUtils.deleteDbFiles(); + + super.afterTest(); + } + + /** + * @throws Exception If failed. + */ + public void testClusterRestartStaticCaches1() throws Exception { + clusterRestart(1, true); + } + + /** + * @throws Exception If failed. + */ + public void testClusterRestartStaticCaches2() throws Exception { + clusterRestart(3, true); + } + + /** + * @throws Exception If failed. + */ + public void testClusterRestartDynamicCaches1() throws Exception { + clusterRestart(1, false); + } + + /** + * @throws Exception If failed. + */ + public void testClusterRestartDynamicCaches2() throws Exception { + clusterRestart(3, false); + } + + /** + * @throws Exception If failed. + */ + @SuppressWarnings("unchecked") + public void testClusterRestartCachesWithH2Indexes() throws Exception { + CacheConfiguration[] ccfgs1 = new CacheConfiguration[5]; + + // Several caches with the same indexed type (and index names). + ccfgs1[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1). + setIndexedTypes(Integer.class, Person.class); + ccfgs1[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1). + setIndexedTypes(Integer.class, Person.class); + ccfgs1[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1). + setIndexedTypes(Integer.class, Person.class); + ccfgs1[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1). + setIndexedTypes(Integer.class, Person.class); + ccfgs1[4] = cacheConfiguration(null, "c5", PARTITIONED, ATOMIC, 1). + setIndexedTypes(Integer.class, Person.class); + + String[] caches = {"c1", "c2", "c3", "c4", "c5"}; + + startGrids(3); + + Ignite node = ignite(0); + + node.createCaches(Arrays.asList(ccfgs1)); + + putPersons(caches, node); + + checkPersons(caches, node); + checkPersonsQuery(caches, node); + + stopAllGrids(); + + startGrids(3); + + awaitPartitionMapExchange(); + + node = ignite(0); + + checkPersons(caches, node); + checkPersonsQuery(caches, node); + + Random rnd = ThreadLocalRandom.current(); + + int idx = rnd.nextInt(caches.length); + + String cacheName = caches[idx]; + CacheConfiguration cacheCfg = ccfgs1[idx]; + + node.destroyCache(cacheName); + + node.createCache(cacheCfg); + + putPersons(new String[]{cacheName}, node); + + checkPersons(caches, node); + checkPersonsQuery(caches, node); + } + + /** + * @throws Exception If failed. + */ + public void _testExpiryPolicy() throws Exception { + long ttl = 10000; + + activeOnStart = false; + + CacheConfiguration[] ccfgs1 = new CacheConfiguration[5]; + + ccfgs1[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1); + ccfgs1[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1); + ccfgs1[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1); + ccfgs1[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1); + ccfgs1[4] = cacheConfiguration(null, "c5", PARTITIONED, ATOMIC, 1); + + String[] caches = {"c1", "c2", "c3", "c4", "c5"}; + + startGrids(3); + + Ignite node = ignite(0); + + node.active(true); + + node.createCaches(Arrays.asList(ccfgs1)); + + ExpiryPolicy plc = new PlatformExpiryPolicy(ttl, -2, -2); + + for (String cacheName : caches) { + IgniteCache cache = node.cache(cacheName).withExpiryPolicy(plc); + + for (int i = 0; i < 10; i++) + cache.put(i, cacheName + i); + } + + long deadline = System.currentTimeMillis() + (long)(ttl * 1.2); + + stopAllGrids(); + + startGrids(3); + + node = ignite(0); + + node.active(true); + + for (String cacheName : caches) { + IgniteCache cache = node.cache(cacheName); + + for (int i = 0; i < 10; i++) + assertEquals(cacheName + i, cache.get(i)); + + assertEquals(10, cache.size()); + } + + // Wait for expiration. + Thread.sleep(Math.max(deadline - System.currentTimeMillis(), 0)); + + for (String cacheName : caches) { + IgniteCache cache = node.cache(cacheName); + + assertEquals(0, cache.size()); + } + } + + /** + * @throws Exception If failed. + */ + public void testCreateDropCache() throws Exception { + ccfgs = new CacheConfiguration[]{cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1) + .setIndexedTypes(Integer.class, Person.class)}; + + Ignite ignite = startGrid(); + + ignite.cache("c1").destroy(); + + stopGrid(); + } + + /** + * @throws Exception If failed. + */ + public void testCreateDropCache1() throws Exception { + CacheConfiguration ccfg1 = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1); + + CacheConfiguration ccfg2 = cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 1); + + Ignite ignite = startGrid(); + + ignite.createCaches(Arrays.asList(ccfg1, ccfg2)); + + + ignite.cache("c1").destroy(); + + ignite.cache("c2").destroy(); + + ignite.createCache(ccfg1); + ignite.createCache(ccfg2); + + stopGrid(); + } + + /** + * @throws Exception If failed. + */ + public void testCreateDropCache2() throws Exception { + CacheConfiguration ccfg1 = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1) + .setIndexedTypes(Integer.class, Person.class); + + CacheConfiguration ccfg2 = cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 1) + .setIndexedTypes(Integer.class, Person.class); + + Ignite ignite = startGrid(); + + ignite.createCaches(Arrays.asList(ccfg1, ccfg2)); + + ignite.cache("c1").destroy(); + + ignite.createCache(ccfg1); + + stopGrid(); + } + + /** + * @param caches Cache names to put data into. + * @param node Ignite node. + */ + private void putPersons(String[] caches, Ignite node) { + for (String cacheName : caches) { + IgniteCache cache = node.cache(cacheName); + + for (int i = 0; i < 10; i++) + cache.put(i, new Person("" + i, cacheName)); + } + } + + /** + * @param caches Cache names to invoke a query against to. + * @param node Ignite node. + */ + private void checkPersons(String[] caches, Ignite node) { + for (String cacheName : caches) { + IgniteCache cache = node.cache(cacheName); + + for (int i = 0; i < 10; i++) + assertEquals(new Person("" + i, cacheName), cache.get(i)); + + assertEquals(10, cache.size()); + } + } + + /** + * @param caches Cache names to invoke a query against to. + * @param node Ignite node. + */ + private void checkPersonsQuery(String[] caches, Ignite node) { + SqlQuery qry = new SqlQuery<>( + Person.class, "SELECT p.* FROM Person p WHERE p.lname=? ORDER BY p.fname"); + + for (String cacheName : caches) { + IgniteCache cache = node.cache(cacheName); + + List> persons = cache.query(qry.setArgs(cacheName)).getAll(); + + for (int i = 0; i < 10; i++) + assertEquals(new Person("" + i, cacheName), persons.get(i).getValue()); + + assertEquals(10, persons.size()); + } + } + + /** + * @param nodes Nodes number. + * @param staticCaches {@code True} if caches should be statically configured. + * @throws Exception If failed. + */ + private void clusterRestart(int nodes, boolean staticCaches) throws Exception { + CacheConfiguration[] ccfgs = new CacheConfiguration[5]; + + ccfgs[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1); + ccfgs[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1); + ccfgs[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1); + ccfgs[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1); + ccfgs[4] = cacheConfiguration(null, "c5", PARTITIONED, ATOMIC, 1); + + String[] caches = {"c1", "c2", "c3", "c4", "c5"}; + + for (int i = 0; i < nodes; i++) { + if (staticCaches) + this.ccfgs = ccfgs; + + startGrid(i); + } + + Ignite node = ignite(0); + + if (!staticCaches) + node.createCaches(Arrays.asList(ccfgs)); + + for (String cacheName : caches) { + IgniteCache cache = node.cache(cacheName); + + for (int i = 0; i < 10; i++) { + cache.put(i, cacheName + i); + + assertEquals(cacheName + i, cache.get(i)); + } + + assertEquals(10, cache.size()); + } + + stopAllGrids(); + + node = startGrids(nodes); + + awaitPartitionMapExchange(); + + for (String cacheName : caches) { + IgniteCache cache = node.cache(cacheName); + + for (int i = 0; i < 10; i++) + assertEquals(cacheName + i, cache.get(i)); + + assertEquals(10, cache.size()); + } + } + + /** + * @param grpName Cache group name. + * @param name Cache name. + * @param cacheMode Cache mode. + * @param atomicityMode Atomicity mode. + * @param backups Backups number. + * @return Cache configuration. + */ + private CacheConfiguration cacheConfiguration( + String grpName, + String name, + CacheMode cacheMode, + CacheAtomicityMode atomicityMode, + int backups + ) { + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setName(name); + ccfg.setGroupName(grpName); + ccfg.setAtomicityMode(atomicityMode); + ccfg.setBackups(backups); + ccfg.setCacheMode(cacheMode); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + + return ccfg; + } + + /** + * + */ + static class Person implements Serializable { + /** */ + @GridToStringInclude + @QuerySqlField(index = true, groups = "full_name") + String fName; + + /** */ + @GridToStringInclude + @QuerySqlField(index = true, groups = "full_name") + String lName; + + /** + * @param fName First name. + * @param lName Last name. + */ + public Person(String fName, String lName) { + this.fName = fName; + this.lName = lName; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(Person.class, this); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Person person = (Person)o; + return Objects.equals(fName, person.fName) && + Objects.equals(lName, person.lName); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return Objects.hash(fName, lName); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDataStructuresTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDataStructuresTest.java new file mode 100644 index 0000000000000..0183779ef94b4 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDataStructuresTest.java @@ -0,0 +1,205 @@ +/* + * 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.cache.database; + +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteAtomicLong; +import org.apache.ignite.IgniteAtomicSequence; +import org.apache.ignite.IgniteQueue; +import org.apache.ignite.IgniteSet; +import org.apache.ignite.configuration.CollectionConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +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; + +/** + * + */ +public class IgnitePersistentStoreDataStructuresTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); + + MemoryConfiguration dbCfg = new MemoryConfiguration(); + + MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); + + memPlcCfg.setName("dfltMemPlc"); + memPlcCfg.setInitialSize(200 * 1024 * 1024); + memPlcCfg.setMaxSize(200 * 1024 * 1024); + + dbCfg.setMemoryPolicies(memPlcCfg); + dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + + cfg.setMemoryConfiguration(dbCfg); + + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + + cfg.setActiveOnStart(false); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + + GridTestUtils.deleteDbFiles(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + GridTestUtils.deleteDbFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + + /** + * @throws Exception If failed. + */ + public void testQueue() throws Exception { + Ignite ignite = startGrids(4); + + ignite.active(true); + + IgniteQueue queue = ignite.queue("testQueue", 100, new CollectionConfiguration()); + + for (int i = 0; i < 100; i++) + queue.offer(i); + + stopAllGrids(); + + ignite = startGrids(4); + + ignite.active(true); + + queue = ignite.queue("testQueue", 0, null); + + for (int i = 0; i < 100; i++) + assertEquals(i, queue.poll()); + } + + /** + * @throws Exception If failed. + */ + public void testAtomic() throws Exception { + Ignite ignite = startGrids(4); + + ignite.active(true); + + IgniteAtomicLong atomicLong = ignite.atomicLong("testLong", 0, true); + + for (int i = 0; i < 100; i++) + atomicLong.incrementAndGet(); + + stopAllGrids(); + + ignite = startGrids(4); + + ignite.active(true); + + atomicLong = ignite.atomicLong("testLong", 0, false); + + for (int i = 100; i != 0; ) + assertEquals(i--, atomicLong.getAndDecrement()); + } + + /** + * @throws Exception If failed. + */ + public void testSequence() throws Exception { + Ignite ignite = startGrids(4); + + ignite.active(true); + + IgniteAtomicSequence sequence = ignite.atomicSequence("testSequence", 0, true); + + int i = 0; + + while (i < 1000) { + sequence.incrementAndGet(); + + i++; + } + + stopAllGrids(); + + ignite = startGrids(4); + + ignite.active(true); + + sequence = ignite.atomicSequence("testSequence", 0, false); + + assertTrue(sequence.incrementAndGet() > i); + } + + /** + * @throws Exception If failed. + */ + public void testSet() throws Exception { + Ignite ignite = startGrids(4); + + ignite.active(true); + + IgniteSet set = ignite.set("testSet", new CollectionConfiguration()); + + for (int i = 0; i < 100; i++) + set.add(i); + + stopAllGrids(); + + ignite = startGrids(4); + + ignite.active(true); + + set = ignite.set("testSet", null); + + assertFalse(set.add(99)); + + for (int i = 0; i < 100; i++) + assertTrue(set.contains(i)); + + assertEquals(100, set.size()); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java index 46ac5d24d3f75..a2eb3d446c9a2 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java @@ -132,8 +132,6 @@ public IgnitePersistentStoreMultiNodePutGetRestartSelfTest() { * @throws Exception if failed. */ public void testPutGetSimple() throws Exception { - - info(">>> Will use path: " + allocPath); startGrids(GRID_CNT); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java new file mode 100644 index 0000000000000..665b9afb7fd0f --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java @@ -0,0 +1,42 @@ +/* + * 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.cache.database; + +import org.apache.ignite.cache.affinity.AffinityFunction; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; + +/** + * + */ +public class IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest + extends IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest { + /** {@inheritDoc} */ + @Override protected void configure(IgniteConfiguration cfg) { + super.configure(cfg); + + for (CacheConfiguration ccfg : cfg.getCacheConfiguration()) { + AffinityFunction aff = ccfg.getAffinity(); + + int parts = aff != null ? aff.partitions() : RendezvousAffinityFunction.DFLT_PARTITION_COUNT; + + ccfg.setGroupName("testGroup-parts" + parts); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java index 9d5fe69b22dba..783faf8a33221 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java @@ -19,7 +19,7 @@ import java.nio.ByteBuffer; import java.util.Collections; -import java.util.Set; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; @@ -29,7 +29,8 @@ import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.pagemem.PageIdUtils; import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; -import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; +import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.lang.IgniteFuture; @@ -52,17 +53,17 @@ public class NoOpPageStoreManager implements IgnitePageStoreManager { } /** {@inheritDoc} */ - @Override public void initializeForCache(CacheConfiguration ccfg) throws IgniteCheckedException { + @Override public void initializeForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) throws IgniteCheckedException { // No-op. } /** {@inheritDoc} */ - @Override public void shutdownForCache(GridCacheContext cacheCtx, boolean destroy) throws IgniteCheckedException { + @Override public void shutdownForCacheGroup(CacheGroupContext grp, boolean destroy) throws IgniteCheckedException { // No-op. } /** {@inheritDoc} */ - @Override public void onPartitionCreated(int cacheId, int partId) throws IgniteCheckedException { + @Override public void onPartitionCreated(int grpId, int partId) throws IgniteCheckedException { // No-op. } @@ -170,17 +171,12 @@ public class NoOpPageStoreManager implements IgnitePageStoreManager { } /** {@inheritDoc} */ - @Override public Set savedCacheNames() { - return Collections.emptySet(); + @Override public Map readCacheConfigurations() throws IgniteCheckedException { + return Collections.emptyMap(); } /** {@inheritDoc} */ - @Override public CacheConfiguration readConfiguration(String cacheName) { - return null; - } - - /** {@inheritDoc} */ - @Override public boolean hasIndexStore(int cacheId) { + @Override public boolean hasIndexStore(int grpId) { return false; } diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java index c3e5a703253cb..d38d403c1b05c 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java @@ -18,9 +18,11 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; +import org.apache.ignite.cache.database.IgnitePersistentStoreCacheGroupsTest; import org.apache.ignite.cache.database.IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest; import org.apache.ignite.cache.database.IgnitePersistentStoreDynamicCacheTest; import org.apache.ignite.cache.database.IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest; import org.apache.ignite.cache.database.IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest; import org.apache.ignite.cache.database.db.IgniteDbMultiNodePutGetRestartSelfTest; import org.apache.ignite.cache.database.db.IgniteDbPageEvictionSelfTest; @@ -80,11 +82,14 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(IgniteDbMultiNodePutGetRestartSelfTest.class); suite.addTestSuite(IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.class); suite.addTestSuite(IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.class); + suite.addTestSuite(IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.class); suite.addTestSuite(IgniteDbPageEvictionSelfTest.class); suite.addTestSuite(IgnitePersistentStoreDynamicCacheTest.class); suite.addTestSuite(IgniteWalDirectoriesConfigurationTest.class); suite.addTestSuite(IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.class); + suite.addTestSuite(IgnitePersistentStoreCacheGroupsTest.class); + return suite; } } diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java index 223c3cb28cb9f..2db7ff7b4ec72 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java @@ -19,10 +19,11 @@ import junit.framework.TestSuite; import org.apache.ignite.cache.database.IgnitePersistentStoreAtomicCacheRebalancingTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreTxCacheRebalancingTest; import org.apache.ignite.cache.database.IgnitePersistentStoreContinuousRestartSelfTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreDataStructuresTest; import org.apache.ignite.cache.database.IgnitePersistentStorePageSizesTest; import org.apache.ignite.cache.database.IgnitePersistentStoreRecoveryAfterFileCorruptionTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreTxCacheRebalancingTest; import org.apache.ignite.cache.database.db.DbPageEvictionDuringPartitionClearSelfTest; import org.apache.ignite.cache.database.db.IgniteDbWholeClusterRestartSelfTest; import org.apache.ignite.cache.database.db.RebalancingOnNotStableTopologyTest; @@ -70,6 +71,8 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(IgnitePersistentStoreContinuousRestartSelfTest.class); + suite.addTestSuite(IgnitePersistentStoreDataStructuresTest.class); + return suite; } } diff --git a/modules/yardstick/pom.xml b/modules/yardstick/pom.xml index f496e02344a0e..6e8bf9b65a067 100644 --- a/modules/yardstick/pom.xml +++ b/modules/yardstick/pom.xml @@ -60,6 +60,12 @@ ${project.version} + + org.apache.ignite + ignite-pds + ${project.version} + + org.apache.ignite ignite-log4j diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java index 11f94729478b7..602b2278497c5 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java @@ -20,12 +20,15 @@ import com.beust.jcommander.Parameter; import org.apache.ignite.cache.CacheWriteSynchronizationMode; import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; import org.apache.ignite.internal.util.tostring.GridToStringBuilder; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionIsolation; import java.util.ArrayList; import java.util.List; +import org.jetbrains.annotations.Nullable; /** * Input arguments for Ignite benchmarks. @@ -82,7 +85,8 @@ public class IgniteBenchmarkArguments { /** */ @Parameter(names = {"-r", "--range"}, description = "Key range") - public int range = 1_000_000; + @GridToStringInclude + private int range = 1_000_000; /** */ @Parameter(names = {"-sf", "--scaleFactor"}, description = "Scale factor") @@ -194,6 +198,25 @@ public class IgniteBenchmarkArguments { @Parameter(names = {"-ps", "--pageSize"}, description = "Page size") private int pageSize = MemoryConfiguration.DFLT_PAGE_SIZE; + /** */ + @Parameter(names = {"-cg", "--cacheGrp"}, description = "Cache group for caches") + private String cacheGrp; + + /** */ + @Parameter(names = {"-cc", "--cachesCnt"}, description = "Number of caches to create") + private int cachesCnt = 1; + + /** */ + @Parameter(names = {"-pds", "--persistentStore"}, description = "Persistent store flag") + private boolean persistentStoreEnabled; + + /** + * @return {@code True} if need set {@link PersistentStoreConfiguration}. + */ + public boolean persistentStoreEnabled() { + return persistentStoreEnabled; + } + /** * @return List of enabled load test operations. */ @@ -474,6 +497,20 @@ public boolean cleanWorkDirectory() { return cleanWorkDirectory; } + /** + * @return Name of cache group to be set for caches. + */ + @Nullable public String cacheGroup() { + return cacheGrp; + } + + /** + * @return Number of caches to create. + */ + public int cachesCount() { + return cachesCnt; + } + /** * @return Description. */ diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java index 6e25fc4a8a1fa..35fa9490b200f 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteNode.java @@ -25,11 +25,13 @@ import org.apache.ignite.IgniteSpring; import org.apache.ignite.Ignition; import org.apache.ignite.cache.eviction.lru.LruEvictionPolicy; +import org.apache.ignite.configuration.BinaryConfiguration; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.ConnectorConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.NearCacheConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; import org.apache.ignite.configuration.TransactionConfiguration; import org.apache.ignite.internal.util.IgniteUtils; import org.apache.ignite.internal.util.typedef.internal.U; @@ -112,6 +114,9 @@ public IgniteNode(boolean clientMode, Ignite ignite) { cc.setNearConfiguration(nearCfg); } + if (args.cacheGroup() != null) + cc.setGroupName(args.cacheGroup()); + cc.setWriteSynchronizationMode(args.syncMode()); cc.setBackups(args.backups()); @@ -152,15 +157,23 @@ public IgniteNode(boolean clientMode, Ignite ignite) { c.setCommunicationSpi(commSpi); if (args.getPageSize() != MemoryConfiguration.DFLT_PAGE_SIZE) { - MemoryConfiguration dbCfg = c.getMemoryConfiguration(); + MemoryConfiguration memCfg = c.getMemoryConfiguration(); - if (dbCfg == null) { - dbCfg = new MemoryConfiguration(); + if (memCfg == null) { + memCfg = new MemoryConfiguration(); - c.setMemoryConfiguration(dbCfg); + c.setMemoryConfiguration(memCfg); } - dbCfg.setPageSize(args.getPageSize()); + memCfg.setPageSize(args.getPageSize()); + } + + if (args.persistentStoreEnabled()) { + PersistentStoreConfiguration pcCfg = new PersistentStoreConfiguration(); + + c.setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(false)); + + c.setPersistentStoreConfiguration(pcCfg); } ignite = IgniteSpring.start(c, appCtx); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheAbstractBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheAbstractBenchmark.java index da5cb1d40ef74..28aa5a295533f 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheAbstractBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheAbstractBenchmark.java @@ -19,21 +19,30 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicInteger; import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; import org.apache.ignite.cache.affinity.Affinity; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.jdk.JdkMarshaller; import org.apache.ignite.yardstick.IgniteAbstractBenchmark; +import org.apache.ignite.yardstick.cache.model.SampleValue; import org.yardstickframework.BenchmarkConfiguration; import org.yardstickframework.BenchmarkUtils; +import static org.yardstickframework.BenchmarkUtils.println; + /** * Abstract class for Ignite benchmarks which use cache. */ @@ -41,22 +50,97 @@ public abstract class IgniteCacheAbstractBenchmark extends IgniteAbstractB /** Cache. */ protected IgniteCache cache; + /** */ + protected List testCaches; + /** */ private ThreadLocal threadRange = new ThreadLocal<>(); /** */ private AtomicInteger threadIdx = new AtomicInteger(); + /** */ + private int caches; + + /** */ + private final AtomicInteger opCacheIdx = new AtomicInteger(); + + /** */ + private final ThreadLocal> opCache = new ThreadLocal<>(); + + /** + * @return Cache for benchmark operation. + */ + protected final IgniteCache cacheForOperation() { + return cacheForOperation(false); + } + + /** + * @param perThread If {@code true} then cache is selected once and set in thread local. + * @return Cache for benchmark operation. + */ + protected final IgniteCache cacheForOperation(boolean perThread) { + if (caches > 1) { + if (perThread) { + IgniteCache cache = opCache.get(); + + if (cache == null) { + cache = testCaches.get(opCacheIdx.getAndIncrement() % caches); + + opCache.set(cache); + + BenchmarkUtils.println(cfg, "Initialized cache for thread [cache=" + cache.getName() + ']'); + } + + return cache; + } + else + return testCaches.get(ThreadLocalRandom.current().nextInt(caches)); + } + + return cache; + } + /** {@inheritDoc} */ @Override public void setUp(BenchmarkConfiguration cfg) throws Exception { super.setUp(cfg); cache = cache(); + CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); + + String grpName = ccfg.getGroupName(); + BenchmarkUtils.println(cfg, "Benchmark setUp [name=" + getClass().getSimpleName() + ", cacheName="+ cache.getName() + + ", cacheGroup="+ grpName + ", cacheCfg=" + cache.getConfiguration(CacheConfiguration.class) + ']'); + caches = args.cachesCount(); + + if (caches > 1) { + List toCreate = new ArrayList<>(); + + for (int i = 0; i < caches - 1; i++) { + JdkMarshaller marsh = new JdkMarshaller(); + + CacheConfiguration ccfg0 = marsh.unmarshal(marsh.marshal(ccfg), null); + + ccfg0.setName(cache.getName() + "-" + i); + + toCreate.add(ccfg0); + } + + Collection caches = ignite().getOrCreateCaches(toCreate); + + testCaches = new ArrayList<>(caches); + + testCaches.add(cache); + + BenchmarkUtils.println(cfg, "Created additional caches [caches=" + testCaches.size() + + ", grp=" + grpName + ']'); + } + if (args.printPartitionStatistics()) { Map, List>> parts = new HashMap<>(); @@ -103,6 +187,80 @@ public abstract class IgniteCacheAbstractBenchmark extends IgniteAbstractB } } + /** + * @throws Exception If failed. + */ + protected final void loadCachesData() throws Exception { + List caches = testCaches != null ? testCaches : Collections.singletonList(cache); + + if (caches.size() > 1) { + ExecutorService executor = Executors.newFixedThreadPool(10); + + try { + List> futs = new ArrayList<>(); + + for (final IgniteCache cache : caches) { + futs.add(executor.submit(new Runnable() { + @Override public void run() { + loadCacheData0(cache.getName()); + } + })); + } + + for (Future fut : futs) + fut.get(); + } + finally { + executor.shutdown(); + } + } + else + loadCacheData(caches.get(0).getName()); + } + + /** + * @param cacheName Cache name. + * @param cnt Number of entries to load. + */ + protected final void loadSampleValues(String cacheName, int cnt) { + try (IgniteDataStreamer dataLdr = ignite().dataStreamer(cacheName)) { + for (int i = 0; i < cnt; i++) { + dataLdr.addData(i, new SampleValue(i)); + + if (i % 100000 == 0) { + if (Thread.currentThread().isInterrupted()) + break; + + println("Loaded entries [cache=" + cacheName + ", cnt=" + i + ']'); + } + } + } + + println("Load entries done [cache=" + cacheName + ", cnt=" + cnt + ']'); + } + + /** + * @param cacheName Cache name. + */ + private void loadCacheData0(String cacheName) { + println(cfg, "Loading data for cache: " + cacheName); + + long start = System.nanoTime(); + + loadCacheData(cacheName); + + long time = ((System.nanoTime() - start) / 1_000_000); + + println(cfg, "Finished populating data [cache=" + cacheName + ", time=" + time + "ms]"); + } + + /** + * @param cacheName Cache name. + */ + protected void loadCacheData(String cacheName) { + throw new IllegalStateException("Not implemented for " + getClass().getSimpleName()); + } + /** * @return Range. */ diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAllBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAllBenchmark.java index 2f76b7cd30344..f563ec85bf908 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAllBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAllBenchmark.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.Set; +import org.apache.ignite.IgniteCache; import org.apache.ignite.internal.util.typedef.internal.U; /** @@ -35,6 +36,8 @@ public class IgniteGetAllBenchmark extends IgniteGetBenchmark { keys.add(key); } + IgniteCache cache = cacheForOperation(); + cache.getAll(keys); return true; diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAllPutAllTxBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAllPutAllTxBenchmark.java index a8f6d7b7e1e89..d984e644bad7e 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAllPutAllTxBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAllPutAllTxBenchmark.java @@ -55,6 +55,8 @@ public class IgniteGetAllPutAllTxBenchmark extends IgniteCacheAbstractBenchmark< vals.put(key, key); } + IgniteCache cache = cacheForOperation(); + cache.getAll(vals.keySet()); cache.putAll(vals); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAndPutBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAndPutBenchmark.java index 8d15e5eca16da..f943f1656f371 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAndPutBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAndPutBenchmark.java @@ -29,6 +29,8 @@ public class IgniteGetAndPutBenchmark extends IgniteCacheAbstractBenchmark ctx) throws Exception { int key = nextRandom(args.range()); + IgniteCache cache = cacheForOperation(); + cache.getAndPut(key, new SampleValue(key)); return true; diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAndPutTxBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAndPutTxBenchmark.java index 0a3794c79b0ed..4a1af43ff37af 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAndPutTxBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetAndPutTxBenchmark.java @@ -49,6 +49,8 @@ public class IgniteGetAndPutTxBenchmark extends IgniteCacheAbstractBenchmark cache = cacheForOperation(); + cache.getAndPut(key, new SampleValue(key)); return null; diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetBenchmark.java index 6154ba4542aaf..96a99ffbe0c87 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetBenchmark.java @@ -19,19 +19,12 @@ import java.util.Map; import org.apache.ignite.IgniteCache; -import org.apache.ignite.IgniteDataStreamer; -import org.apache.ignite.yardstick.cache.model.SampleValue; import org.yardstickframework.BenchmarkConfiguration; -import static org.yardstickframework.BenchmarkUtils.println; - /** * Ignite benchmark that performs get operations. */ public class IgniteGetBenchmark extends IgniteCacheAbstractBenchmark { - /** */ - private static final String CACHE_NAME = "atomic"; - /** {@inheritDoc} */ @Override public void setUp(BenchmarkConfiguration cfg) throws Exception { super.setUp(cfg); @@ -40,32 +33,20 @@ public class IgniteGetBenchmark extends IgniteCacheAbstractBenchmark dataLdr = ignite().dataStreamer(cacheName)) { - for (int i = 0; i < args.preloadAmount(); i++) { - dataLdr.addData(i, new SampleValue(i)); - - if (i % 100000 == 0) { - if (Thread.currentThread().isInterrupted()) - break; - - println("Loaded entries: " + i); - } - } - } + loadCachesData(); + } - println(cfg, "Finished populating query data in " + ((System.nanoTime() - start) / 1_000_000) + " ms."); + /** {@inheritDoc} */ + @Override protected void loadCacheData(String cacheName) { + loadSampleValues(cacheName, args.preloadAmount()); } /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { int key = nextRandom(args.range()); + IgniteCache cache = cacheForOperation(); + cache.get(key); return true; @@ -73,6 +54,6 @@ public class IgniteGetBenchmark extends IgniteCacheAbstractBenchmark cache() { - return ignite().cache(CACHE_NAME); + return ignite().cache("atomic"); } } diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetEntriesPutAllTxBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetEntriesPutAllTxBenchmark.java index 501e12d7b5b8c..fd61d5fa7dac0 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetEntriesPutAllTxBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteGetEntriesPutAllTxBenchmark.java @@ -47,6 +47,8 @@ public class IgniteGetEntriesPutAllTxBenchmark extends IgniteCacheAbstractBenchm doInTransaction(txs, args.txConcurrency(), args.txIsolation(), new Callable() { @Override public Void call() throws Exception { + IgniteCache cache = cacheForOperation(); + SortedMap vals = new TreeMap<>(); for (int i = 0; i < args.batch(); i++) { diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeBenchmark.java index a1e80f0f0123c..fa29cc41dba30 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeBenchmark.java @@ -31,6 +31,8 @@ public class IgniteInvokeBenchmark extends IgniteCacheAbstractBenchmark ctx) throws Exception { int key = nextRandom(args.range()); + IgniteCache cache = cacheForOperation(); + cache.invoke(key, new SetValueEntryProcessor(new SampleValue(key))); return true; diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeTxBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeTxBenchmark.java index 64dc6b8bdd363..c30ff29139dd0 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeTxBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeTxBenchmark.java @@ -49,6 +49,8 @@ public class IgniteInvokeTxBenchmark extends IgniteInvokeBenchmark { @Override public Void call() throws Exception { int key = nextRandom(args.range()); + IgniteCache cache = cacheForOperation(); + cache.invoke(key, new SetValueEntryProcessor(new SampleValue(key))); return null; diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeWithInjectionBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeWithInjectionBenchmark.java index ef9d17bd5bcbd..93704cc4f0ad2 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeWithInjectionBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteInvokeWithInjectionBenchmark.java @@ -34,6 +34,8 @@ public class IgniteInvokeWithInjectionBenchmark extends IgniteCacheAbstractBench @Override public boolean test(Map ctx) throws Exception { int key = nextRandom(args.range()); + IgniteCache cache = cacheForOperation(); + cache.invoke(key, new SetValueEntryProcessor(new SampleValue(key))); return true; diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllBenchmark.java index 33aa2059bbc8f..dc210293d1405 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllBenchmark.java @@ -131,6 +131,8 @@ public class IgnitePutAllBenchmark extends IgniteCacheAbstractBenchmark cache = cacheForOperation(); + cache.putAll(vals); return true; diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllSerializableTxBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllSerializableTxBenchmark.java index 200400e112829..089ee7a21ab57 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllSerializableTxBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllSerializableTxBenchmark.java @@ -54,6 +54,8 @@ public class IgnitePutAllSerializableTxBenchmark extends IgniteCacheAbstractBenc vals.put(key, key); } + IgniteCache cache = cacheForOperation(); + while (true) { try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { cache.putAll(vals); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutBenchmark.java index 69db87f99a0a7..ebee87ccd9a62 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutBenchmark.java @@ -29,6 +29,8 @@ public class IgnitePutBenchmark extends IgniteCacheAbstractBenchmark ctx) throws Exception { int key = nextRandom(args.range()); + IgniteCache cache = cacheForOperation(); + cache.put(key, new SampleValue(key)); return true; diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetBatchBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetBatchBenchmark.java index a9f59d44b11fc..95268964f16a2 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetBatchBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetBatchBenchmark.java @@ -30,6 +30,8 @@ public class IgnitePutGetBatchBenchmark extends IgniteCacheAbstractBenchmark { /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + Set keys = new TreeSet<>(); while (keys.size() < args.batch()) diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetBenchmark.java index 42f308cb122cb..cc29e47a35971 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetBenchmark.java @@ -29,6 +29,8 @@ public class IgnitePutGetBenchmark extends IgniteCacheAbstractBenchmark ctx) throws Exception { int key = nextRandom(args.range()); + IgniteCache cache = cacheForOperation(); + Object val = cache.get(key); if (val != null) diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetEntryBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetEntryBenchmark.java index 1289fa1fedac5..eb49b574334a7 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetEntryBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetEntryBenchmark.java @@ -28,6 +28,8 @@ public class IgnitePutGetEntryBenchmark extends IgniteCacheAbstractBenchmark { /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + int key = nextRandom(args.range()); CacheEntry val = cache.getEntry(key); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetEntryTxBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetEntryTxBenchmark.java index 6e58b41953913..5b3500962c12a 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetEntryTxBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetEntryTxBenchmark.java @@ -45,6 +45,8 @@ public class IgnitePutGetEntryTxBenchmark extends IgniteCacheAbstractBenchmark() { @Override public Void call() throws Exception { + IgniteCache cache = cacheForOperation(); + int key = nextRandom(0, args.range() / 2); CacheEntry val = cache.getEntry(key); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxBatchBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxBatchBenchmark.java index 7ac818039e8c4..954f93fa3e533 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxBatchBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxBatchBenchmark.java @@ -47,6 +47,8 @@ public class IgnitePutGetTxBatchBenchmark extends IgniteCacheAbstractBenchmark() { @Override public Void call() throws Exception { + IgniteCache cache = cacheForOperation(); + Set keys = new TreeSet<>(); while (keys.size() < args.batch()) diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxBenchmark.java index 3235721d5701e..6b11ef836ee47 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxBenchmark.java @@ -44,6 +44,8 @@ public class IgnitePutGetTxBenchmark extends IgniteCacheAbstractBenchmark() { @Override public Void call() throws Exception { + IgniteCache cache = cacheForOperation(); + int key = nextRandom(0, args.range() / 2); Object val = cache.get(key); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIfAbsentIndexedValue1Benchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIfAbsentIndexedValue1Benchmark.java index aea909a3cf822..8430b1232b0c3 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIfAbsentIndexedValue1Benchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIfAbsentIndexedValue1Benchmark.java @@ -31,6 +31,8 @@ public class IgnitePutIfAbsentIndexedValue1Benchmark extends IgniteCacheAbstract /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + int key = insCnt.getAndIncrement(); cache.putIfAbsent(key, new Person1(key)); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue1Benchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue1Benchmark.java index 6f060157ad7e4..af206fe1a51a0 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue1Benchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue1Benchmark.java @@ -27,6 +27,8 @@ public class IgnitePutIndexedValue1Benchmark extends IgniteCacheAbstractBenchmark { /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + int key = nextRandom(args.range()); cache.put(key, new Person1(key)); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue2Benchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue2Benchmark.java index 01121631f8e88..7c62714522d44 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue2Benchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue2Benchmark.java @@ -27,6 +27,8 @@ public class IgnitePutIndexedValue2Benchmark extends IgniteCacheAbstractBenchmark { /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + int key = nextRandom(args.range()); cache.put(key, new Person2(key)); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue8Benchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue8Benchmark.java index dae32b40c0f36..a34e386284404 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue8Benchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutIndexedValue8Benchmark.java @@ -27,6 +27,8 @@ public class IgnitePutIndexedValue8Benchmark extends IgniteCacheAbstractBenchmark { /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + int key = nextRandom(args.range()); cache.put(key, new Person8(key)); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutRandomValueSizeBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutRandomValueSizeBenchmark.java index 180b50ef4744d..db631aba8ce5d 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutRandomValueSizeBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutRandomValueSizeBenchmark.java @@ -26,6 +26,8 @@ public class IgnitePutRandomValueSizeBenchmark extends IgniteCacheAbstractBenchmark { /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + int key = nextRandom(args.range()); int size = 64 + nextRandom(64); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutRemoveBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutRemoveBenchmark.java index 7ea3d9150f61e..564bff586e725 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutRemoveBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutRemoveBenchmark.java @@ -27,6 +27,8 @@ public class IgnitePutRemoveBenchmark extends IgniteCacheAbstractBenchmark { /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + int key = nextRandom(args.range()); cache.put(key, new SampleValue(key)); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxBenchmark.java index 15b7cd6eaf527..0a8a470579de4 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxBenchmark.java @@ -47,6 +47,8 @@ public class IgnitePutTxBenchmark extends IgniteCacheAbstractBenchmark() { @Override public Void call() throws Exception { + IgniteCache cache = cacheForOperation(); + int key = nextRandom(args.range()); cache.put(key, new SampleValue(key)); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxImplicitBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxImplicitBenchmark.java index 89d87a8d33b23..d1070fbd42e3f 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxImplicitBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxImplicitBenchmark.java @@ -37,6 +37,8 @@ public class IgnitePutTxImplicitBenchmark extends IgniteCacheAbstractBenchmark ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + int key = nextRandom(args.range()); // Implicit transaction is used. diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxPrimaryOnlyBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxPrimaryOnlyBenchmark.java index 21275ebec8462..5e79acdeb7902 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxPrimaryOnlyBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxPrimaryOnlyBenchmark.java @@ -39,6 +39,8 @@ public class IgnitePutTxPrimaryOnlyBenchmark extends IgniteCacheAbstractBenchmar /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + int key; Affinity aff = ignite().affinity("tx"); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxSkipLocalBackupBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxSkipLocalBackupBenchmark.java index 63934e6b631af..29d565a3951a0 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxSkipLocalBackupBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxSkipLocalBackupBenchmark.java @@ -39,6 +39,8 @@ public class IgnitePutTxSkipLocalBackupBenchmark extends IgniteCacheAbstractBenc /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + int key; Affinity aff = ignite().affinity("tx"); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutValue8Benchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutValue8Benchmark.java index 6a3d492b08506..e4ac2e24590c6 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutValue8Benchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutValue8Benchmark.java @@ -28,6 +28,8 @@ public class IgnitePutValue8Benchmark extends IgniteCacheAbstractBenchmark { /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { + IgniteCache cache = cacheForOperation(); + int key = nextRandom(args.range()); cache.put(key, new Person8(key)); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteReplaceIndexedValue1Benchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteReplaceIndexedValue1Benchmark.java index cc50c8452ca1a..70b94ab3a21d8 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteReplaceIndexedValue1Benchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteReplaceIndexedValue1Benchmark.java @@ -66,6 +66,8 @@ public class IgniteReplaceIndexedValue1Benchmark extends IgniteCacheAbstractBenc @Override public boolean test(Map ctx) throws Exception { ThreadLocalRandom rnd = ThreadLocalRandom.current(); + IgniteCache cache = cacheForOperation(); + cache.replace(rnd.nextInt(args.range()), new Person1(rnd.nextInt(args.range()))); return true; diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteScanQueryBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteScanQueryBenchmark.java new file mode 100644 index 0000000000000..eda4ff6412528 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteScanQueryBenchmark.java @@ -0,0 +1,88 @@ +/* + * 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.yardstick.cache; + +import java.util.List; +import java.util.Map; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.query.ScanQuery; +import org.apache.ignite.lang.IgniteBiPredicate; +import org.yardstickframework.BenchmarkConfiguration; + +/** + * + */ +public class IgniteScanQueryBenchmark extends IgniteCacheAbstractBenchmark { + /** {@inheritDoc} */ + @Override public void setUp(BenchmarkConfiguration cfg) throws Exception { + super.setUp(cfg); + + loadCachesData(); + } + + /** {@inheritDoc} */ + @Override protected void loadCacheData(String cacheName) { + loadSampleValues(cacheName, args.range()); + } + + /** {@inheritDoc} */ + @Override public boolean test(Map ctx) throws Exception { + int key = nextRandom(args.range()); + + ScanQuery qry = new ScanQuery<>(); + + qry.setFilter(new KeyFilter(key)); + + IgniteCache cache = cacheForOperation().withKeepBinary(); + + List> res = cache.query(qry).getAll(); + + if (res.size() != 1) + throw new Exception("Invalid result size: " + res.size()); + + if (res.get(0).getKey() != key) + throw new Exception("Invalid entry found [key=" + key + ", entryKey=" + res.get(0).getKey() + ']'); + + return true; + } + + /** {@inheritDoc} */ + @Override protected IgniteCache cache() { + return ignite().cache("atomic"); + } + + /** + * + */ + static class KeyFilter implements IgniteBiPredicate { + /** */ + private final Integer key; + + /** + * @param key Key to find. + */ + public KeyFilter(Integer key) { + this.key = key; + } + + /** {@inheritDoc} */ + @Override public boolean apply(Integer key, Object val) { + return this.key.equals(key); + } + } +} diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryBenchmark.java index 8e31455bd5703..732cb71cb1253 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryBenchmark.java @@ -37,20 +37,22 @@ public class IgniteSqlQueryBenchmark extends IgniteCacheAbstractBenchmark dataLdr = ignite().dataStreamer(cacheName)) { + for (int i = 0; i < args.range(); i++) { + if (i % 100 == 0 && Thread.currentThread().isInterrupted()) + break; - try (IgniteDataStreamer dataLdr = ignite().dataStreamer(cache.getName())) { - for (int i = 0; i < args.range() && !Thread.currentThread().isInterrupted(); i++) { dataLdr.addData(i, new Person(i, "firstName" + i, "lastName" + i, i * 1000)); if (i % 100000 == 0) println(cfg, "Populated persons: " + i); } } - - println(cfg, "Finished populating query data in " + ((System.nanoTime() - start) / 1_000_000) + " ms."); } /** {@inheritDoc} */ @@ -79,6 +81,8 @@ public class IgniteSqlQueryBenchmark extends IgniteCacheAbstractBenchmark> executeQuery(double minSalary, double maxSalary) throws Exception { + IgniteCache cache = cacheForOperation(true); + SqlQuery qry = new SqlQuery(Person.class, "salary >= ? and salary <= ?"); qry.setArgs(minSalary, maxSalary); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBenchmark.java index c5fdeb24af0f4..8f4829d7f8a5f 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBenchmark.java @@ -47,14 +47,23 @@ public class IgniteSqlQueryDistributedJoinBenchmark extends IgniteCacheAbstractB println(cfg, "Populating query data..."); - long start = System.nanoTime(); - range = args.range(); if (range <= 0) throw new IllegalArgumentException(); - try (IgniteDataStreamer dataLdr = ignite().dataStreamer(cache.getName())) { + println(cfg, "Populating join query data [orgCnt=" + range + + ", personCnt=" + range + + ", broadcastJoin=" + broadcast + "]"); + + loadCachesData(); + + executeQueryJoin(0, broadcast, true); + } + + /** {@inheritDoc} */ + @Override protected void loadCacheData(String cacheName) { + try (IgniteDataStreamer dataLdr = ignite().dataStreamer(cacheName)) { for (int orgId = 0; orgId < range; orgId++) { dataLdr.addData(orgId, new Organization(orgId, "org" + orgId)); @@ -73,13 +82,6 @@ public class IgniteSqlQueryDistributedJoinBenchmark extends IgniteCacheAbstractB dataLdr.close(); } - - println(cfg, "Finished populating join query [orgCnt=" + range + - ", personCnt=" + range + - ", broadcastJoin=" + broadcast + - ", time=" + ((System.nanoTime() - start) / 1_000_000) + "ms]"); - - executeQueryJoin(0, broadcast, true); } /** @@ -141,6 +143,8 @@ private Collection> executeQueryJoin(int orgId, boolean broadcast, boole qry.setDistributedJoins(true); qry.setArgs(orgId); + IgniteCache cache = cacheForOperation(true); + if (planOnly) { String plan = (String)cache.query(qry).getAll().get(0).get(0); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryJoinBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryJoinBenchmark.java index 1f8006d337fad..116080333cc1a 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryJoinBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryJoinBenchmark.java @@ -40,9 +40,15 @@ public class IgniteSqlQueryJoinBenchmark extends IgniteCacheAbstractBenchmark dataLdr = ignite().dataStreamer(cache.getName())) { + try (IgniteDataStreamer dataLdr = ignite().dataStreamer(cacheName)) { final int orgRange = args.range() / 10; // Populate organizations. @@ -61,8 +67,6 @@ public class IgniteSqlQueryJoinBenchmark extends IgniteCacheAbstractBenchmark> executeQueryJoin(double minSalary, double maxSalary) throws Exception { + IgniteCache cache = cacheForOperation(true); + SqlFieldsQuery qry = new SqlFieldsQuery( "select p.id, p.orgId, p.firstName, p.lastName, p.salary, o.name " + "from Person p " + diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryPutBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryPutBenchmark.java index dfa4cbc6a4dad..a67f0dcad57cd 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryPutBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryPutBenchmark.java @@ -25,7 +25,6 @@ import org.apache.ignite.IgniteCache; import org.apache.ignite.cache.query.SqlQuery; import org.apache.ignite.yardstick.cache.model.Person; -import org.yardstickframework.BenchmarkConfiguration; import static org.yardstickframework.BenchmarkUtils.println; @@ -39,15 +38,12 @@ public class IgniteSqlQueryPutBenchmark extends IgniteCacheAbstractBenchmark ctx) throws Exception { ThreadLocalRandom rnd = ThreadLocalRandom.current(); + IgniteCache cache = cacheForOperation(true); + if (rnd.nextBoolean()) { double salary = rnd.nextDouble() * args.range() * 1000; diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryPutSeparatedBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryPutSeparatedBenchmark.java index b74978e8e3a53..2ba06cfbae293 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryPutSeparatedBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryPutSeparatedBenchmark.java @@ -55,6 +55,8 @@ public class IgniteSqlQueryPutSeparatedBenchmark extends IgniteCacheAbstractBenc } } else { + IgniteCache cache = cacheForOperation(true); + int i = rnd.nextInt(args.range()); cache.put(i, new Person(i, "firstName" + i, "lastName" + i, i * 1000)); @@ -70,6 +72,8 @@ public class IgniteSqlQueryPutSeparatedBenchmark extends IgniteCacheAbstractBenc * @throws Exception If failed. */ private Collection> executeQuery(double minSalary, double maxSalary) throws Exception { + IgniteCache cache = cacheForOperation(true); + SqlQuery qry = new SqlQuery(Person.class, "salary >= ? and salary <= ?"); qry.setArgs(minSalary, maxSalary); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/jdbc/JdbcPutGetBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/jdbc/JdbcPutGetBenchmark.java index 8ee76794b7537..a68b2b251698e 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/jdbc/JdbcPutGetBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/jdbc/JdbcPutGetBenchmark.java @@ -28,8 +28,8 @@ public class JdbcPutGetBenchmark extends JdbcAbstractBenchmark { /** {@inheritDoc} */ @Override public boolean test(Map ctx) throws Exception { - int newKey = nextRandom(args.range); - int newVal = nextRandom(args.range); + int newKey = nextRandom(args.range()); + int newVal = nextRandom(args.range()); try (PreparedStatement stmt = createUpsertStatement(conn.get(), newKey, newVal)) { if (stmt.executeUpdate() <= 0) diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/load/IgniteCacheRandomOperationBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/load/IgniteCacheRandomOperationBenchmark.java index 4010f5e7012df..681ba3496d0e0 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/load/IgniteCacheRandomOperationBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/load/IgniteCacheRandomOperationBenchmark.java @@ -31,6 +31,9 @@ import java.util.TreeSet; import java.util.UUID; import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicLong; import javax.cache.CacheException; @@ -267,7 +270,7 @@ private void searchCache() throws Exception { keys.add(keyCls); else throw new IgniteException("Class is unknown for the load test. Make sure you " + - "specified its full name [clsName=" + queryEntity.getKeyType() + ']'); + "specified its full name [cache=" + cacheName + ", clsName=" + queryEntity.getKeyType() + ']'); } if (queryEntity.getValueType() != null) { @@ -277,7 +280,7 @@ private void searchCache() throws Exception { values.add(valCls); else throw new IgniteException("Class is unknown for the load test. Make sure you " + - "specified its full name [clsName=" + queryEntity.getKeyType() + ']'); + "specified its full name [cache=" + cacheName + ", clsName=" + queryEntity.getValueType() + ']'); configureCacheSqlDescriptor(cacheName, queryEntity, valCls); } @@ -448,25 +451,36 @@ private void preLoading() throws Exception { startPreloadLogging(args.preloadLogsInterval()); - Thread[] threads = new Thread[availableCaches.size()]; + ExecutorService executor = Executors.newFixedThreadPool(10); - for (int i = 0; i < availableCaches.size(); i++) { - final String cacheName = availableCaches.get(i).getName(); + try { + List> futs = new ArrayList<>(); + + final Thread thread = Thread.currentThread(); + + for (int i = 0; i < availableCaches.size(); i++) { + final String cacheName = availableCaches.get(i).getName(); - threads[i] = new Thread() { - @Override public void run() { - try (IgniteDataStreamer dataLdr = ignite().dataStreamer(cacheName)) { - for (int i = 0; i < args.preloadAmount() && !isInterrupted(); i++) - dataLdr.addData(createRandomKey(i, cacheName), createRandomValue(i, cacheName)); + futs.add(executor.submit(new Runnable() { + @Override public void run() { + try (IgniteDataStreamer dataLdr = ignite().dataStreamer(cacheName)) { + for (int i = 0; i < args.preloadAmount(); i++) { + if (i % 100 == 0 && thread.isInterrupted()) + break; + + dataLdr.addData(createRandomKey(i, cacheName), createRandomValue(i, cacheName)); + } + } } - } - }; + })); + } - threads[i].start(); + for (Future fut : futs) + fut.get(); + } + finally { + executor.shutdown(); } - - for (Thread thread : threads) - thread.join(); stopPreloadLogging(); } diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/load/model/ModelUtil.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/load/model/ModelUtil.java index 9268cdd1973a3..667e8c9379439 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/load/model/ModelUtil.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/load/model/ModelUtil.java @@ -38,6 +38,7 @@ public class ModelUtil { * Classes of keys. */ private static Class[] keyClasses = { + Integer.class, Double.class, Identifier.class, Mark.class, @@ -104,7 +105,7 @@ public static boolean canCreateInstance(Class clazz) { * @return object from model */ public static Object create(Class c, int id) { - Object res = null; + Object res; switch (c.getSimpleName()) { case "Double": @@ -150,6 +151,9 @@ public static Object create(Class c, int id) { break; case "String": res = String.valueOf(id); + break; + default: + throw new IllegalArgumentException("Unsupported class: " + c.getSimpleName()); } return res; From e1c328e468c94d268c754a3153c7bc2584279d0d Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Mon, 5 Jun 2017 11:16:31 +0300 Subject: [PATCH 230/311] IGNITE-5322 - Improved WAL record/iterator structure --- .../wal/record/StoreOperationRecord.java | 118 ------------- .../pagemem/wal/record/WALRecord.java | 12 +- .../GridCacheDatabaseSharedManager.java | 6 +- .../cache/database/wal/FileWALPointer.java | 17 +- .../wal/FileWriteAheadLogManager.java | 130 ++++++++------ .../cache/database/wal/RecordSerializer.java | 3 +- .../wal/serializer/RecordV1Serializer.java | 162 +++++++++--------- .../db/file/IgniteWalRecoverySelfTest.java | 2 +- 8 files changed, 183 insertions(+), 267 deletions(-) delete mode 100644 modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/StoreOperationRecord.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/StoreOperationRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/StoreOperationRecord.java deleted file mode 100644 index a82f604f07878..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/StoreOperationRecord.java +++ /dev/null @@ -1,118 +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.pagemem.wal.record; - -/** - * - */ -public class StoreOperationRecord extends WALRecord { - /** - * Store operation type. - */ - public enum StoreOperationType { - /** */ - ENTRY_CREATE, - - /** */ - INDEX_PUT, - - /** */ - INDEX_REMOVE; - - /** */ - private static final StoreOperationType[] VALS = StoreOperationType.values(); - - /** */ - public static StoreOperationType fromOrdinal(int ord) { - return ord < 0 || ord >= VALS.length ? null : VALS[ord]; - } - } - - /** */ - private StoreOperationType opType; - - /** */ - private int cacheId; - - /** */ - private long link; - - /** */ - private int idxId; - - /** {@inheritDoc} */ - @Override public RecordType type() { - return RecordType.STORE_OPERATION_RECORD; - } - - /** - * @return Cache ID. - */ - public int cacheId() { - return cacheId; - } - - /** - * @return Link to data. - */ - public long link() { - return link; - } - - /** - * @return Index ID. - */ - public int indexId() { - return idxId; - } - - /** - * @return Operation type. - */ - public StoreOperationType operationType() { - return opType; - } - - /** - * @param opType Operation type. - */ - public void operationType(StoreOperationType opType) { - this.opType = opType; - } - - /** - * @param cacheId Cache ID. - */ - public void cacheId(int cacheId) { - this.cacheId = cacheId; - } - - /** - * @param link Link. - */ - public void link(long link) { - this.link = link; - } - - /** - * @param idxId Index ID. - */ - public void indexId(int idxId) { - this.idxId = idxId; - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/WALRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/WALRecord.java index 142f0ee188152..b76bcc6e9e718 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/WALRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/WALRecord.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.pagemem.wal.record; +import org.apache.ignite.internal.pagemem.wal.WALPointer; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.internal.S; @@ -37,9 +38,6 @@ public enum RecordType { /** */ DATA_RECORD, - /** */ - STORE_OPERATION_RECORD, - /** */ CHECKPOINT_RECORD, @@ -186,7 +184,7 @@ public static RecordType fromOrdinal(int ord) { private WALRecord prev; /** */ - private long pos; + private WALPointer pos; /** * @param chainSize Chain size in bytes. @@ -219,15 +217,15 @@ public void previous(WALRecord prev) { /** * @return Position in file. */ - public long position() { + public WALPointer position() { return pos; } /** * @param pos Position in file. */ - public void position(long pos) { - assert pos >= 0: pos; + public void position(WALPointer pos) { + assert pos != null; this.pos = pos; } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 1b3645116b3c4..b5d52f09a3b94 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -1225,7 +1225,7 @@ else if (type == CheckpointEntryType.END && ts > lastEndTs) { } } - ByteBuffer buf = ByteBuffer.allocate(16); + ByteBuffer buf = ByteBuffer.allocate(20); buf.order(ByteOrder.nativeOrder()); if (startFile != null) @@ -1253,7 +1253,7 @@ private WALPointer readPointer(File cpMarkerFile, ByteBuffer buf) throws IgniteC buf.flip(); - return new FileWALPointer(buf.getInt(), buf.getInt(), buf.getInt()); + return new FileWALPointer(buf.getLong(), buf.getInt(), buf.getInt()); } catch (IOException e) { throw new IgniteCheckedException("Failed to read checkpoint pointer from marker file: " + @@ -1719,7 +1719,7 @@ private CheckpointEntry writeCheckpointEntry( tmpWriteBuf.rewind(); - tmpWriteBuf.putInt(filePtr.index()); + tmpWriteBuf.putLong(filePtr.index()); tmpWriteBuf.putInt(filePtr.fileOffset()); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java index 1102054b5f8f2..36df2e7223d5a 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java @@ -25,7 +25,7 @@ */ public class FileWALPointer implements WALPointer, Comparable { /** */ - private final int idx; + private final long idx; /** */ private final int fileOffset; @@ -37,7 +37,7 @@ public class FileWALPointer implements WALPointer, Comparable { * @param idx File timestamp index. * @param fileOffset Offset in file, from the beginning. */ - public FileWALPointer(int idx, int fileOffset, int len) { + public FileWALPointer(long idx, int fileOffset, int len) { this.idx = idx; this.fileOffset = fileOffset; this.len = len; @@ -46,7 +46,7 @@ public FileWALPointer(int idx, int fileOffset, int len) { /** * @return Timestamp index. */ - public int index() { + public long index() { return idx; } @@ -64,6 +64,13 @@ public int length() { return len; } + /** + * @param len Record length. + */ + public void length(int len) { + this.len = len; + } + /** {@inheritDoc} */ @Override public WALPointer next() { if (len == 0) @@ -89,7 +96,7 @@ public int length() { /** {@inheritDoc} */ @Override public int hashCode() { - int result = idx; + int result = (int)(idx ^ (idx >>> 32)); result = 31 * result + fileOffset; @@ -98,7 +105,7 @@ public int length() { /** {@inheritDoc} */ @Override public int compareTo(FileWALPointer o) { - int res = Integer.compare(idx, o.idx); + int res = Long.compare(idx, o.idx); return res == 0 ? Integer.compare(fileOffset, o.fileOffset) : res; } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java index f8b18efbba49e..4b7930855d36f 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -192,7 +192,6 @@ public FileWriteAheadLogManager(GridKernalContext ctx) { assert dbCfg != null : "WAL should not be created if persistence is disabled."; this.dbCfg = dbCfg; - this.igCfg = igCfg; maxWalSegmentSize = dbCfg.getWalSegmentSize(); @@ -443,7 +442,7 @@ protected String consistentId() { archiver0.release(((FileWALPointer)start).index()); } - private boolean hasIndex(int absIdx) { + private boolean hasIndex(long absIdx) { String name = FileDescriptor.fileName(absIdx, serializer.version()); boolean inArchive = new File(walArchiveDir, name).exists(); @@ -509,7 +508,7 @@ private boolean hasIndex(int absIdx) { * @param consId Local node consistent ID. * @param msg File description to print out on successful initialization. * @return Initialized directory. - * @throws IgniteCheckedException + * @throws IgniteCheckedException If failed to initialize directory. */ private File initDirectory(String cfg, String defDir, String consId, String msg) throws IgniteCheckedException { File dir; @@ -568,11 +567,11 @@ private FileWriteHandle rollOver(FileWriteHandle cur) throws StorageException, I * @throws IgniteCheckedException If failed to initialize WAL write handle. */ private FileWriteHandle restoreWriteHandle(FileWALPointer lastReadPtr) throws IgniteCheckedException { - int absIdx = lastReadPtr == null ? 0 : lastReadPtr.index(); + long absIdx = lastReadPtr == null ? 0 : lastReadPtr.index(); archiver.currentWalIndex(absIdx); - int segNo = absIdx % dbCfg.getWalSegments(); + long segNo = absIdx % dbCfg.getWalSegments(); File curFile = new File(walWorkDir, FileDescriptor.fileName(segNo, serializer.version())); @@ -625,7 +624,7 @@ private FileWriteHandle restoreWriteHandle(FileWALPointer lastReadPtr) throws Ig * @throws StorageException If IO exception occurred. * @throws IgniteCheckedException If failed. */ - private FileWriteHandle initNextWriteHandle(int curIdx) throws StorageException, IgniteCheckedException { + private FileWriteHandle initNextWriteHandle(long curIdx) throws StorageException, IgniteCheckedException { try { File nextFile = pollNextFile(curIdx); @@ -756,11 +755,11 @@ private void createFile(File file) throws IgniteCheckedException { * @return File ready for use as new WAL segment. * @throws IgniteCheckedException If failed. */ - private File pollNextFile(int curIdx) throws IgniteCheckedException { + private File pollNextFile(long curIdx) throws IgniteCheckedException { // Signal to archiver that we are done with the segment and it can be archived. - int absNextIdx = archiver.nextAbsoluteSegmentIndex(curIdx); + long absNextIdx = archiver.nextAbsoluteSegmentIndex(curIdx); - int segmentIdx = absNextIdx % dbCfg.getWalSegments(); + long segmentIdx = absNextIdx % dbCfg.getWalSegments(); return new File(walWorkDir, FileDescriptor.fileName(segmentIdx, serializer.version())); } @@ -827,22 +826,22 @@ private class FileArchiver extends Thread { * Absolute current segment index WAL Manger writes to. Guarded by this. * Incremented during rollover. Also may be directly set if WAL is resuming logging after start. */ - private int curAbsWalIdx = -1; + private long curAbsWalIdx = -1; /** Last archived file index (absolute, 0-based). Guarded by this. */ - private int lastAbsArchivedIdx = -1; + private long lastAbsArchivedIdx = -1; /** current thread stopping advice */ private volatile boolean stopped; /** */ - private NavigableMap reserved = new TreeMap<>(); + private NavigableMap reserved = new TreeMap<>(); /** * Maps absolute segment index to locks counter. Lock on segment protects from archiving segment and may * come from {@link RecordsIterator} during WAL replay. Map itself is guarded by this. */ - private Map locked = new HashMap<>(); + private Map locked = new HashMap<>(); /** * @@ -869,7 +868,7 @@ private void shutdown() throws IgniteInterruptedCheckedException { /** * @param curAbsWalIdx Current absolute WAL segment index. */ - private void currentWalIndex(int curAbsWalIdx) { + private void currentWalIndex(long curAbsWalIdx) { synchronized (this) { this.curAbsWalIdx = curAbsWalIdx; @@ -880,7 +879,7 @@ private void currentWalIndex(int curAbsWalIdx) { /** * @param absIdx Index for reservation. */ - private synchronized void reserve(int absIdx) { + private synchronized void reserve(long absIdx) { Integer cur = reserved.get(absIdx); if (cur == null) @@ -893,14 +892,14 @@ private synchronized void reserve(int absIdx) { * @param absIdx Index for reservation. * @return {@code True} if index is reserved. */ - private synchronized boolean reserved(int absIdx) { + private synchronized boolean reserved(long absIdx) { return locked.containsKey(absIdx) || reserved.floorKey(absIdx) != null; } /** * @param absIdx Reserved index. */ - private synchronized void release(int absIdx) { + private synchronized void release(long absIdx) { Integer cur = reserved.get(absIdx); assert cur != null && cur >= 1 : cur; @@ -937,7 +936,7 @@ private synchronized void release(int absIdx) { } while (!Thread.currentThread().isInterrupted() && !stopped) { - int toArchive; + long toArchive; synchronized (this) { assert lastAbsArchivedIdx <= curAbsWalIdx : "lastArchived=" + lastAbsArchivedIdx + @@ -991,7 +990,7 @@ private synchronized void release(int absIdx) { * @return Next index (curIdx+1) when it is ready to be written. * @throws IgniteCheckedException If failed (if interrupted or if exception occurred in the archiver thread). */ - private int nextAbsoluteSegmentIndex(int curIdx) throws IgniteCheckedException { + private long nextAbsoluteSegmentIndex(long curIdx) throws IgniteCheckedException { try { synchronized (this) { if (cleanException != null) @@ -1022,7 +1021,7 @@ private int nextAbsoluteSegmentIndex(int curIdx) throws IgniteCheckedException { * @return {@code True} if can read, {@code false} if work segment */ @SuppressWarnings("NonPrivateFieldAccessedInSynchronizedContext") - private boolean checkCanReadArchiveOrReserveWorkSegment(int absIdx) { + private boolean checkCanReadArchiveOrReserveWorkSegment(long absIdx) { synchronized (this) { if (lastAbsArchivedIdx >= absIdx) return true; @@ -1044,7 +1043,7 @@ private boolean checkCanReadArchiveOrReserveWorkSegment(int absIdx) { * @param absIdx Segment absolute index. */ @SuppressWarnings("NonPrivateFieldAccessedInSynchronizedContext") - private void releaseWorkSegment(int absIdx) { + private void releaseWorkSegment(long absIdx) { synchronized (this) { Integer cur = locked.get(absIdx); @@ -1070,8 +1069,8 @@ private void releaseWorkSegment(int absIdx) { /** * @param absIdx Absolute index to archive. */ - private File archiveSegment(int absIdx) throws IgniteCheckedException { - int segIdx = absIdx % dbCfg.getWalSegments(); + private File archiveSegment(long absIdx) throws IgniteCheckedException { + long segIdx = absIdx % dbCfg.getWalSegments(); File origFile = new File(walWorkDir, FileDescriptor.fileName(segIdx, serializer.version())); @@ -1187,7 +1186,7 @@ private static class FileDescriptor implements Comparable { protected final File file; /** Absolute WAL segment file index */ - protected final int idx; + protected final long idx; /** */ protected final int ver; @@ -1203,7 +1202,7 @@ private FileDescriptor(File file) { * @param file File. * @param idx Absolute WAL segment file index. */ - private FileDescriptor(File file, Integer idx) { + private FileDescriptor(File file, Long idx) { this.file = file; String fileName = file.getName(); @@ -1218,7 +1217,7 @@ private FileDescriptor(File file, Integer idx) { int end = fileName.length() - WAL_SEGMENT_FILE_EXT.length(); if (idx == null) - this.idx = Integer.parseInt(fileName.substring(0, v)); + this.idx = Long.parseLong(fileName.substring(0, v)); else this.idx = idx; @@ -1280,7 +1279,7 @@ private static String segmentNumber(long segment) { /** {@inheritDoc} */ @Override public int hashCode() { - return idx; + return (int)(idx ^ (idx >>> 32)); } } @@ -1295,7 +1294,7 @@ private abstract static class FileHandle { protected FileChannel ch; /** */ - protected final int idx; + protected final long idx; /** */ protected String gridName; @@ -1304,7 +1303,7 @@ private abstract static class FileHandle { * @param file File. * @param idx Index. */ - private FileHandle(RandomAccessFile file, int idx, String gridName) { + private FileHandle(RandomAccessFile file, long idx, String gridName) { this.file = file; this.idx = idx; this.gridName = gridName; @@ -1333,7 +1332,7 @@ private static class ReadFileHandle extends FileHandle { */ private ReadFileHandle( RandomAccessFile file, - int idx, + long idx, String gridName, RecordSerializer ser, FileInput in @@ -1413,7 +1412,7 @@ private class FileWriteHandle extends FileHandle { */ private FileWriteHandle( RandomAccessFile file, - int idx, + long idx, String gridName, long pos, long maxSegmentSize, @@ -1428,7 +1427,7 @@ private FileWriteHandle( this.maxSegmentSize = maxSegmentSize; this.serializer = serializer; - head.set(new FakeRecord(pos)); + head.set(new FakeRecord(new FileWALPointer(idx, (int)pos, 0))); written = pos; lastFsyncPos = pos; } @@ -1469,10 +1468,13 @@ private FileWriteHandle( rec.chainSize(newChainSize); rec.previous(h); - rec.position(nextPos); + + FileWALPointer ptr = new FileWALPointer(idx, (int)nextPos, rec.size()); + + rec.position(ptr); if (head.compareAndSet(h, rec)) - return new FileWALPointer(idx, (int)rec.position(), rec.size()); + return ptr; } } @@ -1481,7 +1483,7 @@ private FileWriteHandle( * @return Position for the next record. */ private long nextPosition(WALRecord rec) { - return rec.position() + rec.size(); + return recordOffset(rec) + rec.size(); } /** @@ -1501,7 +1503,7 @@ private void flushOrWait(FileWALPointer ptr) throws IgniteCheckedException { expWritten = ptr.fileOffset(); } else // We read head position before the flush because otherwise we can get wrong position. - expWritten = head.get().position(); + expWritten = recordOffset(head.get()); if (flush(ptr)) return; @@ -1565,7 +1567,7 @@ private boolean flush(FileWALPointer ptr) throws IgniteCheckedException, Storage * @return Chain begin position. */ private long chainBeginPosition(WALRecord h) { - return h.position() + h.size() - h.chainSize(); + return recordOffset(h) + h.size() - h.chainSize(); } /** @@ -1583,7 +1585,7 @@ private boolean flush(WALRecord expHead) throws StorageException, IgniteCheckedE // Fail-fast before CAS. checkEnvironment(); - if (!head.compareAndSet(expHead, new FakeRecord(nextPosition(expHead)))) + if (!head.compareAndSet(expHead, new FakeRecord(new FileWALPointer(idx, (int)nextPosition(expHead), 0)))) return false; // At this point we grabbed the piece of WAL chain. @@ -1658,7 +1660,7 @@ private long fillBuffer(ByteBuffer buf, WALRecord head) throws IgniteCheckedExce buf.rewind(); buf.limit(limit); - return head.position(); + return recordOffset(head); } /** @@ -1950,6 +1952,20 @@ private String safePosition() { } } + /** + * Gets WAL record offset relative to the WAL segment file beginning. + * + * @param rec WAL record. + * @return File offset. + */ + private static int recordOffset(WALRecord rec) { + FileWALPointer ptr = (FileWALPointer)rec.position(); + + assert ptr != null; + + return ptr.fileOffset(); + } + /** * Fake record is zero-sized record, which is not stored into file. * Fake record is used for storing position in file {@link WALRecord#position()}. @@ -1959,7 +1975,7 @@ private static final class FakeRecord extends WALRecord { /** * @param pos Position. */ - FakeRecord(long pos) { + FakeRecord(FileWALPointer pos) { position(pos); } @@ -2009,7 +2025,7 @@ public static class RecordsIterator extends GridCloseableIteratorAdapter curRec; /** */ - private int curIdx = -1; + private long curIdx = -1; /** */ private ReadFileHandle curHandle; @@ -2115,7 +2131,7 @@ private void init() throws IgniteCheckedException { } if (curIdx == -1) { - int lastArchived = descs[descs.length - 1].idx; + long lastArchived = descs[descs.length - 1].idx; if (lastArchived > start.index()) throw new IgniteCheckedException("WAL history is corrupted (segment is missing): " + start); @@ -2159,9 +2175,9 @@ private void advance() throws IgniteCheckedException { } /** - * @throws IgniteCheckedException If failed. + * */ - private void advanceRecord() throws IgniteCheckedException { + private void advanceRecord() { try { ReadFileHandle hnd = curHandle; @@ -2170,15 +2186,21 @@ private void advanceRecord() throws IgniteCheckedException { int pos = (int)hnd.in.position(); - WALRecord rec = ser.readRecord(hnd.in); + FileWALPointer ptr = new FileWALPointer(hnd.idx, pos, 0); - WALPointer ptr = new FileWALPointer(hnd.idx, pos, rec.size()); + WALRecord rec = ser.readRecord(hnd.in, ptr); - curRec = new IgniteBiTuple<>(ptr, rec); + ptr.length(rec.size()); + + curRec = new IgniteBiTuple(ptr, rec); } } catch (IOException | IgniteCheckedException e) { - // TODO: verify that wrapped IntegrityException is acceptable in this case. + if (!(e instanceof SegmentEofException)) { + if (log.isInfoEnabled()) + log.info("Stopping WAL iteration due to an exception: " + e.getMessage()); + } + curRec = null; } } @@ -2213,7 +2235,7 @@ private void advanceSegment() throws IgniteCheckedException { FileDescriptor.fileName(curIdx, serializer.version()))); } else { - int workIdx = curIdx % dbCfg.getWalSegments(); + long workIdx = curIdx % dbCfg.getWalSegments(); fd = new FileDescriptor( new File(walWorkDir, FileDescriptor.fileName(workIdx, serializer.version())), @@ -2257,9 +2279,11 @@ private ReadFileHandle initReadHandle(FileDescriptor desc, FileWALPointer start) try { RecordSerializer ser = forVersion(cctx, desc.ver); - FileInput in = new FileInput(rf.getChannel(), buf); + FileChannel channel = rf.getChannel(); + FileInput in = new FileInput(channel, buf); - WALRecord rec = ser.readRecord(in); + WALRecord rec = ser.readRecord(in, + new FileWALPointer(desc.idx, (int)channel.position(), 0)); if (rec == null) return null; @@ -2314,14 +2338,14 @@ private ReadFileHandle initReadHandle(FileDescriptor desc, FileWALPointer start) * archived yet. In this case the corresponding work segment is reserved (will not be deleted until * release). */ - private boolean canReadArchiveOrReserveWork(int absIdx) { + private boolean canReadArchiveOrReserveWork(long absIdx) { return archiver != null && archiver.checkCanReadArchiveOrReserveWorkSegment(absIdx); } /** * @param absIdx Absolute index to release. */ - private void releaseWorkSegment(int absIdx) { + private void releaseWorkSegment(long absIdx) { if (archiver != null) archiver.releaseWorkSegment(absIdx); } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java index e3a972a9d6967..c929789e7d657 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.pagemem.wal.WALPointer; import org.apache.ignite.internal.pagemem.wal.record.WALRecord; /** @@ -47,5 +48,5 @@ public interface RecordSerializer { * @param in Data input to read data from. * @return Read entry. */ - public WALRecord readRecord(FileInput in) throws IOException, IgniteCheckedException; + public WALRecord readRecord(FileInput in, WALPointer expPtr) throws IOException, IgniteCheckedException; } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java index 4f532aef3f552..1c56338687a9a 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java @@ -30,6 +30,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.wal.WALPointer; import org.apache.ignite.internal.pagemem.wal.record.CacheState; import org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord; import org.apache.ignite.internal.pagemem.wal.record.DataEntry; @@ -37,8 +38,6 @@ import org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry; import org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord; import org.apache.ignite.internal.pagemem.wal.record.PageSnapshot; -import org.apache.ignite.internal.pagemem.wal.record.StoreOperationRecord; -import org.apache.ignite.internal.pagemem.wal.record.StoreOperationRecord.StoreOperationType; import org.apache.ignite.internal.pagemem.wal.record.WALRecord; import org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType; import org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertFragmentRecord; @@ -97,6 +96,7 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor; +import org.apache.ignite.internal.util.typedef.F; import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC; @@ -140,6 +140,8 @@ public RecordV1Serializer(GridCacheSharedContext cctx) { buf.put((byte)(record.type().ordinal() + 1)); + putPosition(buf, (FileWALPointer)record.position()); + switch (record.type()) { case PAGE_RECORD: PageSnapshot snap = (PageSnapshot)record; @@ -150,16 +152,6 @@ public RecordV1Serializer(GridCacheSharedContext cctx) { break; - case STORE_OPERATION_RECORD: - StoreOperationRecord storeRec = (StoreOperationRecord)record; - - buf.put((byte)storeRec.operationType().ordinal()); - buf.putInt(storeRec.cacheId()); - buf.putLong(storeRec.link()); - buf.putInt(storeRec.indexId()); - - break; - case MEMORY_RECOVERY: MemoryRecoveryRecord memoryRecoveryRecord = (MemoryRecoveryRecord)record; @@ -218,7 +210,7 @@ public RecordV1Serializer(GridCacheSharedContext cctx) { buf.put(walPtr == null ? (byte)0 : 1); if (walPtr != null) { - buf.putInt(walPtr.index()); + buf.putLong(walPtr.index()); buf.putInt(walPtr.fileOffset()); buf.putInt(walPtr.length()); } @@ -652,13 +644,13 @@ public RecordV1Serializer(GridCacheSharedContext cctx) { } /** {@inheritDoc} */ - @Override public WALRecord readRecord(FileInput in0) throws IOException, IgniteCheckedException { + @Override public WALRecord readRecord(FileInput in0, WALPointer expPtr) throws IOException, IgniteCheckedException { long startPos = -1; try (FileInput.Crc32CheckingFileInput in = in0.startRead(skipCrc)) { startPos = in0.position(); - WALRecord res = readRecord(in); + WALRecord res = readRecord(in, expPtr); assert res != null; @@ -677,12 +669,18 @@ public RecordV1Serializer(GridCacheSharedContext cctx) { /** * @param in In. */ - private WALRecord readRecord(ByteBufferBackedDataInput in) throws IOException, IgniteCheckedException { + private WALRecord readRecord(ByteBufferBackedDataInput in, WALPointer expPtr) throws IOException, IgniteCheckedException { int type = in.readUnsignedByte(); if (type == 0) throw new SegmentEofException("Reached logical end of the segment", null); + FileWALPointer ptr = readPosition(in); + + if (!F.eq(ptr, expPtr)) + throw new SegmentEofException("WAL segment rollover detected (will end iteration) [expPtr=" + expPtr + + ", readPtr=" + ptr + ']', null); + RecordType recType = RecordType.fromOrdinal(type - 1); if (recType == null) @@ -703,18 +701,6 @@ private WALRecord readRecord(ByteBufferBackedDataInput in) throws IOException, I break; - case STORE_OPERATION_RECORD: - StoreOperationRecord storeRec = new StoreOperationRecord(); - - storeRec.operationType(StoreOperationType.fromOrdinal(in.readByte() & 0xFF)); - storeRec.cacheId(in.readInt()); - storeRec.link(in.readLong()); - storeRec.indexId(in.readInt()); - - res = storeRec; - - break; - case CHECKPOINT_RECORD: long msb = in.readLong(); long lsb = in.readLong(); @@ -1219,16 +1205,15 @@ private WALRecord readRecord(ByteBufferBackedDataInput in) throws IOException, I /** {@inheritDoc} */ @SuppressWarnings("CastConflictsWithInstanceof") @Override public int size(WALRecord record) throws IgniteCheckedException { + int commonFields = /* Type */1 + /* Pointer */12 + /*CRC*/4; + switch (record.type()) { case PAGE_RECORD: assert record instanceof PageSnapshot; PageSnapshot pageRec = (PageSnapshot)record; - return pageRec.pageData().length + 12 + 1 + 4; - - case STORE_OPERATION_RECORD: - return 18 + 4; + return commonFields + pageRec.pageData().length + 12; case CHECKPOINT_RECORD: CheckpointRecord cpRec = (CheckpointRecord)record; @@ -1240,153 +1225,173 @@ assert record instanceof PageSnapshot; FileWALPointer walPtr = (FileWALPointer)cpRec.checkpointMark(); - return 19 + cacheStatesSize + (walPtr == null ? 0 : 12) + 4; + return commonFields + 18 + cacheStatesSize + (walPtr == null ? 0 : 16); case META_PAGE_INIT: - return 1 + /*cache ID*/4 + /*page ID*/8 + /*ioType*/2 + /*ioVer*/2 + /*tree root*/8 + /*reuse root*/8 + /*CRC*/4; + return commonFields + /*cache ID*/4 + /*page ID*/8 + /*ioType*/2 + /*ioVer*/2 + /*tree root*/8 + /*reuse root*/8; case PARTITION_META_PAGE_UPDATE_COUNTERS: - return 1 + /*cache ID*/4 + /*page ID*/8 + /*upd cntr*/8 + /*rmv id*/8 + /*part size*/4 + /*counters page id*/8 + /*state*/ 1 - + /*allocatedIdxCandidate*/ 4 + /*CRC*/4; + return commonFields + /*cache ID*/4 + /*page ID*/8 + /*upd cntr*/8 + /*rmv id*/8 + /*part size*/4 + /*counters page id*/8 + /*state*/ 1 + + /*allocatedIdxCandidate*/ 4; case MEMORY_RECOVERY: - return 1 + 8 + 4; + return commonFields + 8; case PARTITION_DESTROY: - return 1 + /*cacheId*/4 + /*partId*/4 + /*CRC*/4; + return commonFields + /*cacheId*/4 + /*partId*/4; case DATA_RECORD: DataRecord dataRec = (DataRecord)record; - return 5 + dataSize(dataRec) + 4; + return commonFields + 4 + dataSize(dataRec); case HEADER_RECORD: - return 13 + 4; + return commonFields + 12; case DATA_PAGE_INSERT_RECORD: DataPageInsertRecord diRec = (DataPageInsertRecord)record; - return 1 + 4 + 8 + 2 + - diRec.payload().length + 4; + return commonFields + 4 + 8 + 2 + diRec.payload().length; case DATA_PAGE_UPDATE_RECORD: DataPageUpdateRecord uRec = (DataPageUpdateRecord)record; - return 1 + 4 + 8 + 2 + 4 + - uRec.payload().length + 4; + return commonFields + 4 + 8 + 2 + 4 + + uRec.payload().length; case DATA_PAGE_INSERT_FRAGMENT_RECORD: final DataPageInsertFragmentRecord difRec = (DataPageInsertFragmentRecord)record; - return 1 + 4 + 8 + 8 + 4 + difRec.payloadSize() + 4; + return commonFields + 4 + 8 + 8 + 4 + difRec.payloadSize(); case DATA_PAGE_REMOVE_RECORD: - return 1 + 4 + 8 + 1 + 4; + return commonFields + 4 + 8 + 1; case DATA_PAGE_SET_FREE_LIST_PAGE: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case INIT_NEW_PAGE_RECORD: - return 1 + 4 + 8 + 2 + 2 + 8 + 4; + return commonFields + 4 + 8 + 2 + 2 + 8; case BTREE_META_PAGE_INIT_ROOT: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case BTREE_META_PAGE_INIT_ROOT2: - return 1 + 4 + 8 + 8 + 4 + 2; + return commonFields + 4 + 8 + 8 + 2; case BTREE_META_PAGE_ADD_ROOT: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case BTREE_META_PAGE_CUT_ROOT: - return 1 + 4 + 8 + 4; + return commonFields + 4 + 8; case BTREE_INIT_NEW_ROOT: NewRootInitRecord riRec = (NewRootInitRecord)record; - return 1 + 4 + 8 + 8 + 2 + 2 + 8 + 8 + riRec.io().getItemSize() + 4; + return commonFields + 4 + 8 + 8 + 2 + 2 + 8 + 8 + riRec.io().getItemSize(); case BTREE_PAGE_RECYCLE: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case BTREE_PAGE_INSERT: InsertRecord inRec = (InsertRecord)record; - return 1 + 4 + 8 + 2 + 2 + 2 + 8 + inRec.io().getItemSize() + 4; + return commonFields + 4 + 8 + 2 + 2 + 2 + 8 + inRec.io().getItemSize(); case BTREE_FIX_LEFTMOST_CHILD: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case BTREE_FIX_COUNT: - return 1 + 4 + 8 + 2 + 4; + return commonFields + 4 + 8 + 2; case BTREE_PAGE_REPLACE: ReplaceRecord rRec = (ReplaceRecord)record; - return 1 + 4 + 8 + 2 + 2 + 2 + rRec.io().getItemSize() + 4; + return commonFields + 4 + 8 + 2 + 2 + 2 + rRec.io().getItemSize(); case BTREE_PAGE_REMOVE: - return 1 + 4 + 8 + 2 + 2 + 4; + return commonFields + 4 + 8 + 2 + 2; case BTREE_PAGE_INNER_REPLACE: - return 1 + 4 + 8 + 2 + 8 + 2 + 8 + 4; + return commonFields + 4 + 8 + 2 + 8 + 2 + 8; case BTREE_FORWARD_PAGE_SPLIT: - return 1 + 4 + 8 + 8 + 2 + 2 + 8 + 2 + 2 + 4; + return commonFields + 4 + 8 + 8 + 2 + 2 + 8 + 2 + 2; case BTREE_EXISTING_PAGE_SPLIT: - return 1 + 4 + 8 + 2 + 8 + 4; + return commonFields + 4 + 8 + 2 + 8; case BTREE_PAGE_MERGE: - return 1 + 4 + 8 + 8 + 2 + 8 + 1 + 4; + return commonFields + 4 + 8 + 8 + 2 + 8 + 1; case BTREE_FIX_REMOVE_ID: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case PAGES_LIST_SET_NEXT: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case PAGES_LIST_SET_PREVIOUS: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case PAGES_LIST_INIT_NEW_PAGE: - return 1 + 4 + 8 + 4 + 4 + 8 + 8 + 8 + 4; + return commonFields + 4 + 8 + 4 + 4 + 8 + 8 + 8; case PAGES_LIST_ADD_PAGE: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case PAGES_LIST_REMOVE_PAGE: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case TRACKING_PAGE_DELTA: - return 1 + 4 + 8 + 8 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8 + 8 + 8; case META_PAGE_UPDATE_LAST_SUCCESSFUL_SNAPSHOT_ID: - return 1 + 4 + 8 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8 + 8; case META_PAGE_UPDATE_LAST_SUCCESSFUL_FULL_SNAPSHOT_ID: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case META_PAGE_UPDATE_NEXT_SNAPSHOT_ID: - return 1 + 4 + 8 + 8 + 4; + return commonFields + 4 + 8 + 8; case META_PAGE_UPDATE_LAST_ALLOCATED_INDEX: - return 1 + 4 + 8 + 4 + 4; + return commonFields + 4 + 8 + 4; case PART_META_UPDATE_STATE: - return /*Type*/ 1 + /*cacheId*/ 4 + /*partId*/ 4 + /*State*/1 + /*Update Counter*/ 8 + /*CRC*/4; + return commonFields + /*cacheId*/ 4 + /*partId*/ 4 + /*State*/1 + /*Update Counter*/ 8; case PAGE_LIST_META_RESET_COUNT_RECORD: - return /*Type*/ 1 + /*cacheId*/ 4 + /*pageId*/ 8 + /*CRC*/4; + return commonFields + /*cacheId*/ 4 + /*pageId*/ 8; case SWITCH_SEGMENT_RECORD: - return /*Type*/ 1 + /*CRC*/4; + return commonFields; default: throw new UnsupportedOperationException("Type: " + record.type()); } } + /** + * @param buf Byte buffer to serialize version to. + * @param ptr File WAL pointer to write. + */ + private void putPosition(ByteBuffer buf, FileWALPointer ptr) { + buf.putLong(ptr.index()); + buf.putInt(ptr.fileOffset()); + } + + /** + * @param in Data input to read pointer from. + * @return Read file WAL pointer. + * @throws IOException If failed to write. + */ + private FileWALPointer readPosition(DataInput in) throws IOException { + long idx = in.readLong(); + int fileOffset = in.readInt(); + + return new FileWALPointer(idx, fileOffset, 0); + } + /** * @param dataRec Data record to serialize. * @return Full data record size. @@ -1632,10 +1637,9 @@ private GridCacheVersion readVersion(ByteBufferBackedDataInput in, boolean allow /** * @param buf Buffer. * @param rowBytes Row bytes. - * @throws IgniteCheckedException If failed. */ @SuppressWarnings("unchecked") - private static void putRow(ByteBuffer buf, byte[] rowBytes) throws IgniteCheckedException { + private static void putRow(ByteBuffer buf, byte[] rowBytes) { assert rowBytes.length > 0; buf.put(rowBytes); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java index bdf333c5c46b0..225a9d2281834 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java @@ -464,7 +464,7 @@ private void checkWalRolloverMultithreaded(boolean logOnly) throws Exception { walSegmentSize = 2 * 1024 * 1024; - final long endTime = System.currentTimeMillis() + 3 * 60 * 1000; + final long endTime = System.currentTimeMillis() + 2 * 60 * 1000; try { IgniteEx ignite = startGrid(1); From b47db106d42afb5dcbee57b793b63efa43fc4ef2 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Mon, 5 Jun 2017 11:41:42 +0300 Subject: [PATCH 231/311] IGNITE-5323 - Moved record serializer version from file name to file header --- .../wal/FileWriteAheadLogManager.java | 105 ++++++++++++------ .../wal/serializer/RecordV1Serializer.java | 13 ++- 2 files changed, 79 insertions(+), 39 deletions(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java index 4b7930855d36f..8a113babb28b6 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -79,10 +79,10 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl private static final byte[] FILL_BUF = new byte[1024 * 1024]; /** */ - private static final Pattern WAL_NAME_PATTERN = Pattern.compile("\\d{16}\\.v\\d+\\.wal"); + private static final Pattern WAL_NAME_PATTERN = Pattern.compile("\\d{16}\\.wal"); /** */ - private static final Pattern WAL_TEMP_NAME_PATTERN = Pattern.compile("\\d{16}\\.v\\d+\\.wal\\.tmp"); + private static final Pattern WAL_TEMP_NAME_PATTERN = Pattern.compile("\\d{16}\\.wal\\.tmp"); /** */ private static final FileFilter WAL_SEGMENT_FILE_FILTER = new FileFilter() { @@ -322,6 +322,15 @@ protected String consistentId() { currentHnd = restoreWriteHandle(filePtr); + if (currentHnd.serializer.version() != serializer.version()) { + if (log.isInfoEnabled()) + log.info("Record serializer version change detected, will start logging with a new WAL record " + + "serializer to a new WAL segment [curFile=" + currentHnd + ", newVer=" + serializer.version() + + ", oldVer=" + currentHnd.serializer.version() + ']'); + + rollOver(currentHnd); + } + if (mode == Mode.BACKGROUND) { flusher = new QueueFlusher(cctx.igniteInstanceName()); @@ -443,7 +452,7 @@ protected String consistentId() { } private boolean hasIndex(long absIdx) { - String name = FileDescriptor.fileName(absIdx, serializer.version()); + String name = FileDescriptor.fileName(absIdx); boolean inArchive = new File(walArchiveDir, name).exists(); @@ -569,29 +578,35 @@ private FileWriteHandle rollOver(FileWriteHandle cur) throws StorageException, I private FileWriteHandle restoreWriteHandle(FileWALPointer lastReadPtr) throws IgniteCheckedException { long absIdx = lastReadPtr == null ? 0 : lastReadPtr.index(); - archiver.currentWalIndex(absIdx); - long segNo = absIdx % dbCfg.getWalSegments(); - File curFile = new File(walWorkDir, FileDescriptor.fileName(segNo, serializer.version())); + File curFile = new File(walWorkDir, FileDescriptor.fileName(segNo)); int offset = lastReadPtr == null ? 0 : lastReadPtr.fileOffset(); int len = lastReadPtr == null ? 0 : lastReadPtr.length(); - log.info("Resuming logging in WAL segment [file=" + curFile.getAbsolutePath() + - ", offset=" + offset + ']'); - try { RandomAccessFile file = new RandomAccessFile(curFile, "rw"); try { + // readSerializerVersion will change the channel position. + // This is fine because the FileWriteHandle consitructor will move it + // to offset + len anyways. + int serVer = readSerializerVersion(file, curFile, absIdx); + + RecordSerializer ser = forVersion(cctx, serVer); + + if (log.isInfoEnabled()) + log.info("Resuming logging to WAL segment [file=" + curFile.getAbsolutePath() + + ", offset=" + offset + ", ver=" + serVer + ']'); + FileWriteHandle hnd = new FileWriteHandle( file, absIdx, cctx.igniteInstanceName(), offset + len, maxWalSegmentSize, - serializer); + ser); if (lastReadPtr == null) { HeaderRecord header = new HeaderRecord(serializer.version()); @@ -601,6 +616,8 @@ private FileWriteHandle restoreWriteHandle(FileWALPointer lastReadPtr) throws Ig hnd.addRecord(header); } + archiver.currentWalIndex(absIdx); + return hnd; } catch (IgniteCheckedException | IOException e) { @@ -681,7 +698,7 @@ private void checkOrPrepareFiles() throws IgniteCheckedException { // Allocate the first segment synchronously. All other segments will be allocated by archiver in background. if (allFiles.length == 0) { - File first = new File(walWorkDir, FileDescriptor.fileName(0, serializer.version())); + File first = new File(walWorkDir, FileDescriptor.fileName(0)); createFile(first); } @@ -761,7 +778,7 @@ private File pollNextFile(long curIdx) throws IgniteCheckedException { long segmentIdx = absNextIdx % dbCfg.getWalSegments(); - return new File(walWorkDir, FileDescriptor.fileName(segmentIdx, serializer.version())); + return new File(walWorkDir, FileDescriptor.fileName(segmentIdx)); } /** @@ -1072,9 +1089,9 @@ private void releaseWorkSegment(long absIdx) { private File archiveSegment(long absIdx) throws IgniteCheckedException { long segIdx = absIdx % dbCfg.getWalSegments(); - File origFile = new File(walWorkDir, FileDescriptor.fileName(segIdx, serializer.version())); + File origFile = new File(walWorkDir, FileDescriptor.fileName(segIdx)); - String name = FileDescriptor.fileName(absIdx, serializer.version()); + String name = FileDescriptor.fileName(absIdx); File dstTmpFile = new File(walArchiveDir, name + ".tmp"); @@ -1163,7 +1180,7 @@ private void allocateRemainingFiles() throws IgniteCheckedException { */ private void checkFiles(int startWith, boolean create, IgnitePredicate p) throws IgniteCheckedException { for (int i = startWith; i < dbCfg.getWalSegments() && (p == null || (p != null && p.apply(i))); i++) { - File checkFile = new File(walWorkDir, FileDescriptor.fileName(i, serializer.version())); + File checkFile = new File(walWorkDir, FileDescriptor.fileName(i)); if (checkFile.exists()) { if (checkFile.isDirectory()) @@ -1178,6 +1195,35 @@ else if (create) } } + /** + * @param rf Random access file. + * @param file File object. + * @param idx File index to read. + * @return Serializer version stored in the file. + * @throws IOException If failed to read serializer version. + * @throws IgniteCheckedException If failed to read serializer version. + */ + private int readSerializerVersion(RandomAccessFile rf, File file, long idx) + throws IOException, IgniteCheckedException { + try { + ByteBuffer buf = ByteBuffer.allocate(RecordV1Serializer.HEADER_RECORD_SIZE); + buf.order(ByteOrder.nativeOrder()); + + FileInput in = new FileInput(rf.getChannel(), buf); + + // Header record must be agnostic to the serializer version. + WALRecord rec = serializer.readRecord(in, new FileWALPointer(idx, 0, 0)); + + if (rec.type() != WALRecord.RecordType.HEADER_RECORD) + throw new IOException("Missing file header record: " + file.getAbsoluteFile()); + + return ((HeaderRecord)rec).version(); + } + catch (SegmentEofException | EOFException ignore) { + return serializer.version(); + } + } + /** * WAL file descriptor. */ @@ -1188,9 +1234,6 @@ private static class FileDescriptor implements Comparable { /** Absolute WAL segment file index */ protected final long idx; - /** */ - protected final int ver; - /** * @param file File. */ @@ -1209,27 +1252,19 @@ private FileDescriptor(File file, Long idx) { assert fileName.endsWith(WAL_SEGMENT_FILE_EXT); - int v = fileName.lastIndexOf(".v"); - - assert v > 0; - - int begin = v + 2; int end = fileName.length() - WAL_SEGMENT_FILE_EXT.length(); if (idx == null) - this.idx = Long.parseLong(fileName.substring(0, v)); + this.idx = Long.parseLong(fileName.substring(0, end)); else this.idx = idx; - - ver = Integer.parseInt(fileName.substring(begin, end)); } /** * @param segment Segment index. - * @param ver Serializer version. * @return Segment file name. */ - private static String fileName(long segment, int ver) { + private static String fileName(long segment) { SB b = new SB(); String segmentStr = Long.toString(segment); @@ -1237,7 +1272,7 @@ private static String fileName(long segment, int ver) { for (int i = segmentStr.length(); i < 16; i++) b.a('0'); - b.a(segmentStr).a(".v").a(ver).a(WAL_SEGMENT_FILE_EXT); + b.a(segmentStr).a(WAL_SEGMENT_FILE_EXT); return b.toString(); } @@ -2232,13 +2267,13 @@ private void advanceSegment() throws IgniteCheckedException { if (readArchive) { fd = new FileDescriptor(new File(walArchiveDir, - FileDescriptor.fileName(curIdx, serializer.version()))); + FileDescriptor.fileName(curIdx))); } else { long workIdx = curIdx % dbCfg.getWalSegments(); fd = new FileDescriptor( - new File(walWorkDir, FileDescriptor.fileName(workIdx, serializer.version())), + new File(walWorkDir, FileDescriptor.fileName(workIdx)), curIdx); } @@ -2278,11 +2313,11 @@ private ReadFileHandle initReadHandle(FileDescriptor desc, FileWALPointer start) RandomAccessFile rf = new RandomAccessFile(desc.file, "r"); try { - RecordSerializer ser = forVersion(cctx, desc.ver); FileChannel channel = rf.getChannel(); FileInput in = new FileInput(channel, buf); - WALRecord rec = ser.readRecord(in, + // Header record must be agnostic to the serializer version. + WALRecord rec = serializer.readRecord(in, new FileWALPointer(desc.idx, (int)channel.position(), 0)); if (rec == null) @@ -2293,9 +2328,7 @@ private ReadFileHandle initReadHandle(FileDescriptor desc, FileWALPointer start) int ver = ((HeaderRecord)rec).version(); - if (ver != ser.version()) - throw new IOException("Unexpected file format version: " + ver + ", " + - desc.file.getAbsoluteFile()); + RecordSerializer ser = forVersion(cctx, ver); if (start != null && desc.idx == start.index()) in.seek(start.fileOffset()); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java index 1c56338687a9a..f39cdfdf84ec2 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java @@ -97,6 +97,7 @@ import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor; import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC; @@ -104,6 +105,9 @@ * Record V1 serializer. */ public class RecordV1Serializer implements RecordSerializer { + /** */ + public static final int HEADER_RECORD_SIZE = /*Type*/1 + /*Pointer */12 + /*Magic*/8 + /*Version*/4 + /*CRC*/4; + /** */ private GridCacheSharedContext cctx; @@ -779,8 +783,11 @@ private WALRecord readRecord(ByteBufferBackedDataInput in, WALPointer expPtr) th break; case HEADER_RECORD: - if (in.readLong() != HeaderRecord.MAGIC) - throw new EOFException("Magic is corrupted."); + long magic = in.readLong(); + + if (magic != HeaderRecord.MAGIC) + throw new EOFException("Magic is corrupted [exp=" + U.hexLong(HeaderRecord.MAGIC) + + ", actual=" + U.hexLong(magic) + ']'); int ver = in.readInt(); @@ -1246,7 +1253,7 @@ assert record instanceof PageSnapshot; return commonFields + 4 + dataSize(dataRec); case HEADER_RECORD: - return commonFields + 12; + return HEADER_RECORD_SIZE; case DATA_PAGE_INSERT_RECORD: DataPageInsertRecord diRec = (DataPageInsertRecord)record; From 0ce28c6462870f8b6ff798aa6e9236ade490f540 Mon Sep 17 00:00:00 2001 From: sboikov Date: Mon, 5 Jun 2017 12:33:47 +0300 Subject: [PATCH 232/311] DB managers initialization on client node. --- .../internal/processors/cache/GridCacheProcessor.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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 45e6a8bb766b4..577bfb946738b 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 @@ -2258,16 +2258,13 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, if (ctx.clientNode()) { U.warn(log, "Persistent Store is not supported on client nodes (Persistent Store's" + " configuration will be ignored)."); - - dbMgr = new IgniteCacheDatabaseSharedManager(); } - else { - dbMgr = IgniteComponentType.DATABASE_MANAGER.create(ctx, false); - pageStoreMgr = IgniteComponentType.PAGE_STORE_MANAGER.create(ctx, false); + dbMgr = IgniteComponentType.DATABASE_MANAGER.create(ctx, false); - walMgr = IgniteComponentType.WAL_MANAGER.create(ctx, false); - } + pageStoreMgr = IgniteComponentType.PAGE_STORE_MANAGER.create(ctx, false); + + walMgr = IgniteComponentType.WAL_MANAGER.create(ctx, false); } else dbMgr = new IgniteCacheDatabaseSharedManager(); From 874b1f472cdf866a516f858b2a069a32ce41156f Mon Sep 17 00:00:00 2001 From: sboikov Date: Mon, 5 Jun 2017 14:57:54 +0300 Subject: [PATCH 233/311] Fixed formatting. --- .../cache/CacheAffinitySharedManager.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 44bb04f4eb6d9..d8ca1771cd7ae 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 @@ -405,17 +405,18 @@ public boolean onCacheChangeRequest(final GridDhtPartitionsExchangeFuture fut, } } - Set gprs = new HashSet<>(); + Set gprs = new HashSet<>(); - for (ExchangeActions.ActionData action : exchActions.newAndClientCachesStartRequests()) { - Integer grpId = action.descriptor().groupId(); + for (ExchangeActions.ActionData action : exchActions.newAndClientCachesStartRequests()) { + Integer grpId = action.descriptor().groupId(); - if (gprs.add(grpId)) { - if (crd && lateAffAssign) - initStartedGroupOnCoordinator(fut, action.descriptor().groupDescriptor());else { - CacheGroupContext grp = cctx.cache().cacheGroup(grpId); + if (gprs.add(grpId)) { + if (crd && lateAffAssign) + initStartedGroupOnCoordinator(fut, action.descriptor().groupDescriptor()); + else { + CacheGroupContext grp = cctx.cache().cacheGroup(grpId); - if (grp != null && !grp.isLocal() && grp.localStartVersion().equals(fut.topologyVersion())) { + if (grp != null && !grp.isLocal() && grp.localStartVersion().equals(fut.topologyVersion())) { assert grp.affinity().lastVersion().equals(AffinityTopologyVersion.NONE) : grp.affinity().lastVersion(); initAffinity(registeredGrps.get(grp.groupId()), grp.affinity(), fut); From d7108af5925b38dbdacc1e685c65fccfa33236d4 Mon Sep 17 00:00:00 2001 From: sboikov Date: Tue, 6 Jun 2017 13:01:11 +0300 Subject: [PATCH 234/311] Merge remote-tracking branch 'remotes/origin/master' into ignite-5267 # Conflicts: # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandMessage.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java # modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java # modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheExchangeMessageDuplicatedStateTest.java # modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java # modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsSqlTest.java # modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java --- .../cache/CacheAffinitySharedManager.java | 6 +- .../processors/cache/GridCacheProcessor.java | 59 ------------------- .../dht/GridDhtLocalPartition.java | 14 ----- .../dht/GridDhtPartitionTopologyImpl.java | 12 +--- .../preloader/GridDhtPartitionDemander.java | 1 - .../GridDhtPartitionsExchangeFuture.java | 1 - .../GridDhtPartitionsFullMessage.java | 13 ++-- .../GridDhtPartitionsSingleMessage.java | 6 +- .../dht/preloader/GridDhtPreloader.java | 5 +- 9 files changed, 12 insertions(+), 105 deletions(-) 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 031033c6d5cf5..d8ca1771cd7ae 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 @@ -405,8 +405,7 @@ public boolean onCacheChangeRequest(final GridDhtPartitionsExchangeFuture fut, } } - Set< - Integer > gprs = new HashSet<>(); + Set gprs = new HashSet<>(); for (ExchangeActions.ActionData action : exchActions.newAndClientCachesStartRequests()) { Integer grpId = action.descriptor().groupId(); @@ -428,7 +427,8 @@ public boolean onCacheChangeRequest(final GridDhtPartitionsExchangeFuture fut, List closeReqs = exchActions.closeRequests(cctx.localNodeId()); - for (ExchangeActions.ActionData req : closeReqs) { cctx.cache().blockGateway(req.request()); + for (ExchangeActions.ActionData req : closeReqs) { + cctx.cache().blockGateway(req.request()); if (crd) { CacheGroupContext grp = cctx.cache().cacheGroup(req.descriptor().groupId()); 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 ec63c03dd32af..577bfb946738b 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 @@ -1315,15 +1315,6 @@ private void stopCache(GridCacheAdapter cache, boolean cancel, boolean des log.info("Stopped cache [cacheName=" + cache.name() + ']'); } - U.stopLifecycleAware(log, lifecycleAwares(ctx.group(), cache.configuration(), ctx.store().configuredStore())); - - if (log.isInfoEnabled()) { - if (ctx.group().sharedGroup()) - log.info("Stopped cache [cacheName=" + cache.name() + ", group=" + ctx.group().name() + ']'); - else - log.info("Stopped cache [cacheName=" + cache.name() + ']'); - } - cleanup(ctx); } @@ -2005,56 +1996,6 @@ private CacheGroupContext startCacheGroup( return grp; } - /** - * @param desc Group descriptor. - * @param cacheType Cache type. - * @param affNode Affinity node flag. - * @param cacheObjCtx Cache object context. - * @param exchTopVer Current topology version. - * @return Started cache group. - * @throws IgniteCheckedException If failed. - */ - private CacheGroupContext startCacheGroup( - CacheGroupDescriptor desc, - CacheType cacheType, - boolean affNode, - CacheObjectContext cacheObjCtx, - AffinityTopologyVersion exchTopVer) - throws IgniteCheckedException { - CacheConfiguration cfg = new CacheConfiguration(desc.config()); - - String memPlcName = cfg.getMemoryPolicyName(); - - MemoryPolicy memPlc = sharedCtx.database().memoryPolicy(memPlcName); - FreeList freeList = sharedCtx.database().freeList(memPlcName); - ReuseList reuseList = sharedCtx.database().reuseList(memPlcName); - - CacheGroupContext grp = new CacheGroupContext(sharedCtx, - desc.groupId(), - desc.receivedFrom(), - cacheType, - cfg, - affNode, - memPlc, - cacheObjCtx, - freeList, - reuseList, - exchTopVer); - - for (Object obj : grp.configuredUserObjects()) - prepare(cfg, obj, false); - - U.startLifecycleAware(grp.configuredUserObjects()); - - grp.start(); - - CacheGroupContext old = cacheGrps.put(desc.groupId(), grp); - - assert old == null : old.name(); - - return grp; - } - /** * @param req Stop request. */ 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 1e4b48dd67f1f..a53e8642bd1e6 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 @@ -422,20 +422,6 @@ private void removeVersionedEntry(int cacheId, KeyCacheObject key, GridCacheVers removeEntry(entry); } - /** - * @param cacheId Cache ID. - * @param key Key. - * @param ver Version. - */ - private void removeVersionedEntry(int cacheId, KeyCacheObject key, GridCacheVersion ver) { - CacheMapHolder hld = grp.sharedGroup() ? cacheMaps.get(cacheId) : singleCacheEntryMap; - - GridCacheMapEntry entry = hld != null ? hld.map.get(key) : null; - - if (entry != null && entry.markObsoleteVersion(ver)) - removeEntry(entry); - } - /** * */ 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 8baeffefdc6fa..19e48eb7cb69b 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 @@ -502,15 +502,6 @@ private boolean partitionLocalNode(int p, AffinityTopologyVersion topVer) { return grp.affinity().nodes(p, topVer).contains(ctx.localNode()); } - /** - * @param p Partition number. - * @param topVer Topology version. - * @return {@code True} if given partition belongs to local node. - */ - private boolean partitionLocalNode(int p, AffinityTopologyVersion topVer) { - return grp.affinity().nodes(p, topVer).contains(ctx.localNode()); - } - /** {@inheritDoc} */ @Override public boolean afterExchange(GridDhtPartitionsExchangeFuture exchFut) throws IgniteCheckedException { treatAllPartAsLoc = false; @@ -1204,9 +1195,8 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { changed = true; } - else { + else locPart.reload(true); - } } } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java index b19459debf433..cda24e5c5108f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java @@ -42,7 +42,6 @@ import org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection; import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheMetricsImpl; -import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; 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 3a9e2d86ba584..88dc863c3a4d1 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 @@ -59,7 +59,6 @@ import org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage; import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.CacheGroupContext; -import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheInvalidStateException; import org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask; import org.apache.ignite.internal.processors.cache.ClusterState; 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 e83c7fc245b77..0beb93503be7a 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 @@ -130,11 +130,6 @@ public GridDhtPartitionsFullMessage(@Nullable GridDhtPartitionExchangeId id, return 0; } - /** {@inheritDoc} */ - @Override public int handlerId() { - return 0; - } - /** * @param compress {@code True} if it is possible to use compression for message. */ @@ -434,13 +429,13 @@ public void topologyVersion(AffinityTopologyVersion topVer) { writer.incrementState(); - case 8: + case 9: if (!writer.writeByteArray("partsBytes", partsBytes)) return false; writer.incrementState(); - case 9: + case 10: if (!writer.writeByteArray("partsToReloadBytes", partsToReloadBytes)) return false; @@ -500,7 +495,7 @@ public void topologyVersion(AffinityTopologyVersion topVer) { reader.incrementState(); - case 8: + case 9: partsBytes = reader.readByteArray("partsBytes"); if (!reader.isLastRead()) @@ -508,7 +503,7 @@ public void topologyVersion(AffinityTopologyVersion topVer) { reader.incrementState(); - case 9: + case 10: partsToReloadBytes = reader.readByteArray("partsToReloadBytes"); if (!reader.isLastRead()) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java index 1b0ff7cc10c9d..1e5ea142d375d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java @@ -385,7 +385,7 @@ public Exception getException() { writer.incrementState(); - case 9: + case 10: if (!writer.writeByteArray("partsBytes", partsBytes)) return false; @@ -447,7 +447,7 @@ public Exception getException() { reader.incrementState(); - case 9: + case 10: partsBytes = reader.readByteArray("partsBytes"); if (!reader.isLastRead()) @@ -467,7 +467,7 @@ public Exception getException() { /** {@inheritDoc} */ @Override public byte fieldsCount() { - return 10; + return 11; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java index 93406782c134b..52dcc5c6eca11 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java @@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.internal.IgniteInternalFuture; @@ -57,10 +58,6 @@ import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST; import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_UNLOADED; -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.managers.communication.GridIoPolicy.AFFINITY_POOL; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.MOVING; import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.OWNING; From 70eea2aa641437a4c74f90f61dfd8fd1de56b08e Mon Sep 17 00:00:00 2001 From: sboikov Date: Tue, 6 Jun 2017 13:31:35 +0300 Subject: [PATCH 235/311] ignite-5267 --- .../cache/database/GridCacheDatabaseSharedManager.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index b5d52f09a3b94..f43a31ed52f81 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -1772,8 +1772,7 @@ private void finishDestroyPartitionsAsync(final Collection Date: Tue, 6 Jun 2017 13:33:32 +0300 Subject: [PATCH 236/311] IGNITE-5267 - Store sql created flag for cache --- .../org/apache/ignite/cache/QueryEntity.java | 28 +- .../org/apache/ignite/cache/QueryIndex.java | 28 +- .../pagemem/store/IgnitePageStoreManager.java | 16 +- .../cache/CacheJoinNodeDiscoveryData.java | 15 +- .../processors/cache/ClusterCachesInfo.java | 30 +- .../processors/cache/GridCacheProcessor.java | 24 +- .../processors/cache/StoredCacheData.java | 76 +++++ .../cluster/GridClusterStateProcessor.java | 18 +- .../processors/query/GridQueryProcessor.java | 62 ++-- .../GridCacheDatabaseSharedManager.java | 15 +- .../database/file/FilePageStoreManager.java | 53 ++-- .../IgnitePersistentStoreSchemaLoadTest.java | 297 ++++++++++++++++++ .../pagemem/NoOpPageStoreManager.java | 13 +- .../testsuites/IgnitePdsTestSuite2.java | 2 + 14 files changed, 568 insertions(+), 109 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java index 31d89a3af4853..955e7d2dcb036 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java @@ -25,9 +25,10 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; import java.util.Set; - import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.A; import org.apache.ignite.internal.util.typedef.internal.S; @@ -350,6 +351,31 @@ public QueryEntity addQueryField(String fullName, String type, String alias) { return this; } + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + QueryEntity entity = (QueryEntity)o; + + return F.eq(keyType, entity.keyType) && + F.eq(valType, entity.valType) && + F.eq(keyFieldName, entity.keyFieldName) && + F.eq(valueFieldName, entity.valueFieldName) && + F.eq(fields, entity.fields) && + F.eq(keyFields, entity.keyFields) && + F.eq(aliases, entity.aliases) && + F.eqNotOrdered(idxs, entity.idxs) && + F.eq(tableName, entity.tableName); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return Objects.hash(keyType, valType, keyFieldName, valueFieldName, fields, keyFields, aliases, idxs, tableName); + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(QueryEntity.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java index 555a006632529..6e73049ada3ff 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java @@ -16,13 +16,14 @@ */ package org.apache.ignite.cache; -import org.apache.ignite.internal.util.tostring.GridToStringInclude; -import org.apache.ignite.internal.util.typedef.internal.S; - import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashMap; +import java.util.Objects; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.S; /** * Contains list of fields to be indexed. It is possible to provide field name @@ -265,6 +266,27 @@ public void setInlineSize(int inlineSize) { this.inlineSize = inlineSize; } + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + QueryIndex index = (QueryIndex)o; + + return inlineSize == index.inlineSize && + F.eq(name, index.name) && + F.eq(fields, index.fields) && + type == index.type; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return Objects.hash(name, fields, type, inlineSize); + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(QueryIndex.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java index 11a3804fe558a..f3e3aa4b67c18 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java @@ -20,11 +20,11 @@ import java.nio.ByteBuffer; import java.util.Map; import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheSharedManager; +import org.apache.ignite.internal.processors.cache.StoredCacheData; import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport; /** @@ -45,10 +45,11 @@ public interface IgnitePageStoreManager extends GridCacheSharedManager, IgniteCh * Callback called when a cache is starting. * * @param grpDesc Cache group descriptor. - * @param ccfg Cache configuration of the cache being started. + * @param cacheData Cache data of the cache being started. * @throws IgniteCheckedException If failed to handle cache start callback. */ - public void initializeForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) throws IgniteCheckedException; + public void initializeForCache(CacheGroupDescriptor grpDesc, + StoredCacheData cacheData) throws IgniteCheckedException; /** * Callback called when a cache is stopping. After this callback is invoked, no data associated with @@ -178,7 +179,14 @@ public interface IgnitePageStoreManager extends GridCacheSharedManager, IgniteCh * @return Saved cache configurations. * @throws IgniteCheckedException If failed. */ - public Map readCacheConfigurations() throws IgniteCheckedException; + public Map readCacheConfigurations() throws IgniteCheckedException; + + /** + * @param grpDesc Cache group descriptor. + * @param cacheData Cache configuration. + * @throws IgniteCheckedException If failed. + */ + public void storeCacheData(CacheGroupDescriptor grpDesc, StoredCacheData cacheData) throws IgniteCheckedException; /** * @param grpId Cache group ID. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java index 58c9d823036fe..3f99134cea365 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java @@ -19,7 +19,6 @@ import java.io.Serializable; import java.util.Map; -import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.lang.IgniteUuid; @@ -100,7 +99,7 @@ static class CacheInfo implements Serializable { /** */ @GridToStringInclude - private final CacheConfiguration ccfg; + private final StoredCacheData cacheData; /** */ @GridToStringInclude @@ -114,23 +113,23 @@ static class CacheInfo implements Serializable { private final long flags; /** - * @param ccfg Cache configuration. + * @param cacheData Cache data. * @param cacheType Cache type. * @param sql SQL flag - {@code true} if cache was created with {@code CREATE TABLE}. * @param flags Flags (for future usage). */ - CacheInfo(CacheConfiguration ccfg, CacheType cacheType, boolean sql, long flags) { - this.ccfg = ccfg; + CacheInfo(StoredCacheData cacheData, CacheType cacheType, boolean sql, long flags) { + this.cacheData = cacheData; this.cacheType = cacheType; this.sql = sql; this.flags = flags; } /** - * @return Cache configuration. + * @return Cache data. */ - CacheConfiguration config() { - return ccfg; + StoredCacheData cacheData() { + return cacheData; } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index 0fcc74037cf80..e5847016c3a40 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -109,15 +109,15 @@ void onStart(CacheJoinNodeDiscoveryData joinDiscoData) throws IgniteCheckedExcep Map grpCfgs = new HashMap<>(); for (CacheJoinNodeDiscoveryData.CacheInfo info : joinDiscoData.caches().values()) { - if (info.config().getGroupName() == null) + if (info.cacheData().config().getGroupName() == null) continue; - CacheConfiguration ccfg = grpCfgs.get(info.config().getGroupName()); + CacheConfiguration ccfg = grpCfgs.get(info.cacheData().config().getGroupName()); if (ccfg == null) - grpCfgs.put(info.config().getGroupName(), info.config()); + grpCfgs.put(info.cacheData().config().getGroupName(), info.cacheData().config()); else - validateCacheGroupConfiguration(ccfg, info.config()); + validateCacheGroupConfiguration(ccfg, info.cacheData().config()); } String conflictErr = processJoiningNode(joinDiscoData, ctx.localNodeId(), true); @@ -147,7 +147,7 @@ void onKernalStart(boolean checkConsistency) throws IgniteCheckedException { if (checkConsistency && joinDiscoData != null && gridData != null) { for (CacheJoinNodeDiscoveryData.CacheInfo locCacheInfo : joinDiscoData.caches().values()) { - CacheConfiguration locCfg = locCacheInfo.config(); + CacheConfiguration locCfg = locCacheInfo.cacheData().config(); CacheData cacheData = gridData.gridData.caches().get(locCfg.getName()); @@ -173,7 +173,7 @@ void onKernalStart(boolean checkConsistency) throws IgniteCheckedException { private void checkCache(CacheJoinNodeDiscoveryData.CacheInfo locInfo, CacheData rmtData, UUID rmt) throws IgniteCheckedException { GridCacheAttributes rmtAttr = new GridCacheAttributes(rmtData.cacheConfiguration(), rmtData.sql()); - GridCacheAttributes locAttr = new GridCacheAttributes(locInfo.config(), locInfo.sql()); + GridCacheAttributes locAttr = new GridCacheAttributes(locInfo.cacheData().config(), locInfo.sql()); CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "cacheMode", "Cache mode", locAttr.cacheMode(), rmtAttr.cacheMode(), true); @@ -199,7 +199,7 @@ private void checkCache(CacheJoinNodeDiscoveryData.CacheInfo locInfo, CacheData ClusterNode rmtNode = ctx.discovery().node(rmt); - if (CU.affinityNode(ctx.discovery().localNode(), locInfo.config().getNodeFilter()) + if (CU.affinityNode(ctx.discovery().localNode(), locInfo.cacheData().config().getNodeFilter()) && rmtNode != null && CU.affinityNode(rmtNode, rmtData.cacheConfiguration().getNodeFilter())) { CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "storeFactory", "Store factory", locAttr.storeFactoryClassName(), rmtAttr.storeFactoryClassName(), true); @@ -860,7 +860,7 @@ void onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data) { if (joinDiscoData != null) { for (Map.Entry e : joinDiscoData.caches().entrySet()) { if (!registeredCaches.containsKey(e.getKey())) { - conflictErr = checkCacheConflict(e.getValue().config()); + conflictErr = checkCacheConflict(e.getValue().cacheData().config()); if (conflictErr != null) { conflictErr = "Failed to start configured cache due to conflict with started caches. " + @@ -900,10 +900,10 @@ private void initStartCachesForLocalJoin(boolean firstNode) { NearCacheConfiguration nearCfg = null; if (locCfg != null) { - nearCfg = locCfg.config().getNearConfiguration(); + nearCfg = locCfg.cacheData().config().getNearConfiguration(); DynamicCacheDescriptor desc0 = new DynamicCacheDescriptor(ctx, - locCfg.config(), + locCfg.cacheData().config(), desc.cacheType(), desc.groupDescriptor(), desc.template(), @@ -911,7 +911,7 @@ private void initStartCachesForLocalJoin(boolean firstNode) { desc.staticallyConfigured(), desc.sql(), desc.deploymentId(), - desc.schema()); + new QuerySchema(locCfg.cacheData().queryEntities())); desc0.startTopologyVersion(desc.startTopologyVersion()); desc0.receivedFromStartVersion(desc.receivedFromStartVersion()); @@ -1029,7 +1029,7 @@ private String checkCacheConflict(CacheConfiguration cfg) { */ private String processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID nodeId, boolean locJoin) { for (CacheJoinNodeDiscoveryData.CacheInfo cacheInfo : joinData.templates().values()) { - CacheConfiguration cfg = cacheInfo.config(); + CacheConfiguration cfg = cacheInfo.cacheData().config(); if (!registeredTemplates.containsKey(cfg.getName())) { DynamicCacheDescriptor desc = new DynamicCacheDescriptor(ctx, @@ -1041,7 +1041,7 @@ private String processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID node true, false, joinData.cacheDeploymentId(), - new QuerySchema(cfg.getQueryEntities())); + new QuerySchema(cacheInfo.cacheData().queryEntities())); DynamicCacheDescriptor old = registeredTemplates.put(cfg.getName(), desc); @@ -1050,7 +1050,7 @@ private String processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID node } for (CacheJoinNodeDiscoveryData.CacheInfo cacheInfo : joinData.caches().values()) { - CacheConfiguration cfg = cacheInfo.config(); + CacheConfiguration cfg = cacheInfo.cacheData().config(); if (!registeredCaches.containsKey(cfg.getName())) { String conflictErr = checkCacheConflict(cfg); @@ -1087,7 +1087,7 @@ private String processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID node true, cacheInfo.sql(), joinData.cacheDeploymentId(), - new QuerySchema(cfg.getQueryEntities())); + new QuerySchema(cacheInfo.cacheData().queryEntities())); DynamicCacheDescriptor old = registeredCaches.put(cfg.getName(), desc); 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 577bfb946738b..e9680749a4a42 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 @@ -689,15 +689,17 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near } /** - * @param cfg Cache configuration. + * @param cacheData Cache data. * @param sql SQL flag - {@code true} if cache was created with {@code CREATE TABLE}. * @param caches Caches map. * @param templates Templates map. * @throws IgniteCheckedException If failed. */ - private void addCacheOnJoin(CacheConfiguration cfg, boolean sql, + private void addCacheOnJoin(StoredCacheData cacheData, boolean sql, Map caches, Map templates) throws IgniteCheckedException { + CacheConfiguration cfg = cacheData.config(); + CU.validateCacheName(cfg.getName()); cloneCheckSerializable(cfg); @@ -732,10 +734,10 @@ else if (internalCaches.contains(cfg.getName())) else stopSeq.addFirst(cfg.getName()); - caches.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cfg, cacheType, sql, 0)); + caches.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cacheData, cacheType, sql, 0)); } else - templates.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cfg, CacheType.USER, false, 0)); + templates.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cacheData, CacheType.USER, false, 0)); } /** @@ -756,7 +758,7 @@ private void addCacheOnJoinFromConfig( cfgs[i] = cfg; // Replace original configuration value. - addCacheOnJoin(cfg, false, caches, templates); + addCacheOnJoin(new StoredCacheData(cfg), false, caches, templates); } } @@ -772,7 +774,7 @@ private void addCacheOnJoinFromPersistentStore( assert !ctx.config().isDaemon(); if (sharedCtx.pageStore() != null && sharedCtx.database().persistenceEnabled()) { - Map ccfgs = sharedCtx.pageStore().readCacheConfigurations(); + Map ccfgs = sharedCtx.pageStore().readCacheConfigurations(); for (String cache : caches.keySet()) ccfgs.remove(cache); @@ -785,7 +787,7 @@ private void addCacheOnJoinFromPersistentStore( log.info("Register persistent caches: " + ccfgs.keySet()); // TODO IGNITE-5306 - set correct SQL flag below. - for (CacheConfiguration ccfg : ccfgs.values()) + for (StoredCacheData ccfg : ccfgs.values()) addCacheOnJoin(ccfg, false, caches, templates); } } @@ -1888,7 +1890,7 @@ else if (CU.affinityNode(ctx.discovery().localNode(), grpDesc.config().getNodeFi } if (sharedCtx.pageStore() != null && affNode) - sharedCtx.pageStore().initializeForCache(grpDesc, startCfg); + sharedCtx.pageStore().initializeForCache(grpDesc, new StoredCacheData(startCfg)); String grpName = startCfg.getGroupName(); @@ -2747,10 +2749,10 @@ public Collection startAllCachesRequests() throws Ign if (!ctx.config().isDaemon() && sharedCtx.pageStore() != null && sharedCtx.database().persistenceEnabled()) { - Map savedCaches = sharedCtx.pageStore().readCacheConfigurations(); + Map savedCaches = sharedCtx.pageStore().readCacheConfigurations(); - for (CacheConfiguration cfg : savedCaches.values()) - reqs.add(createRequest(cfg, false)); + for (StoredCacheData cfg : savedCaches.values()) + reqs.add(createRequest(cfg.config(), false)); for (CacheConfiguration cfg : ctx.config().getCacheConfiguration()) { if (!savedCaches.containsKey(cfg.getName())) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java new file mode 100644 index 0000000000000..2b3dcdc6fef67 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java @@ -0,0 +1,76 @@ +/* + * 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 java.io.Serializable; +import java.util.Collection; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; +import org.apache.ignite.internal.util.typedef.internal.A; +import org.apache.ignite.marshaller.jdk.JdkMarshaller; + +/** + * Cache data to write to and read from {@link IgnitePageStoreManager}. In a nutshell, contains (most importantly) + * {@link CacheConfiguration} and additional information about cache which is not a part of configuration. + * This class is {@link Serializable} and is intended to be read-written with {@link JdkMarshaller} + * in order to be serialization wise agnostic to further additions or removals of fields. + */ +public class StoredCacheData implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** Cache configuration. */ + private final CacheConfiguration ccfg; + + /** Query entities. */ + private Collection qryEntities; + + /** + * Constructor. + * + * @param ccfg Cache configuration. + */ + public StoredCacheData(CacheConfiguration ccfg) { + A.notNull(ccfg, "ccfg"); + + this.ccfg = ccfg; + this.qryEntities = ccfg.getQueryEntities(); + } + + /** + * @return Cache configuration. + */ + public CacheConfiguration config() { + return ccfg; + } + + /** + * @return Query entities. + */ + public Collection queryEntities() { + return qryEntities; + } + + /** + * @param qryEntities Query entities. + */ + public void queryEntities(Collection qryEntities) { + this.qryEntities = qryEntities; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java index 730fab54d1f1c..3c500a469d125 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java @@ -33,7 +33,6 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.cluster.ClusterNode; -import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.events.Event; import org.apache.ignite.internal.GridKernalContext; @@ -53,6 +52,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheProcessor; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse; +import org.apache.ignite.internal.processors.cache.StoredCacheData; import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.tostring.GridToStringExclude; @@ -431,11 +431,11 @@ private Exception onActivate(ChangeGlobalStateContext cgsCtx) { log.info("Start activation process [nodeId=" + this.ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]"); - Collection cfgs = new ArrayList<>(); + Collection cfgs = new ArrayList<>(); for (DynamicCacheChangeRequest req : cgsCtx.batch.requests()) { if (req.startCacheConfiguration() != null) - cfgs.add(req.startCacheConfiguration()); + cfgs.add(new StoredCacheData(req.startCacheConfiguration())); } try { @@ -453,16 +453,16 @@ private Exception onActivate(ChangeGlobalStateContext cgsCtx) { sharedCtx.database().initDataBase(); // TODO IGNITE-5075 group descriptors. - for (CacheConfiguration cfg : cfgs) { - if (CU.isSystemCache(cfg.getName())) + for (StoredCacheData cacheData : cfgs) { + if (CU.isSystemCache(cacheData.config().getName())) if (pageStore != null) - pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cfg.getName()).groupDescriptor(), cfg); + pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(), cacheData); } - for (CacheConfiguration cfg : cfgs) { - if (!CU.isSystemCache(cfg.getName())) + for (StoredCacheData cacheData : cfgs) { + if (!CU.isSystemCache(cacheData.config().getName())) if (pageStore != null) - pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cfg.getName()).groupDescriptor(), cfg); + pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(), cacheData); } sharedCtx.database().onActivate(ctx); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 6197dd960c83a..e2238fa0ff5a2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -17,6 +17,25 @@ package org.apache.ignite.internal.processors.query; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.cache.Cache; +import javax.cache.CacheException; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteDataStreamer; import org.apache.ignite.IgniteException; @@ -34,16 +53,18 @@ import org.apache.ignite.events.CacheQueryExecutedEvent; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.managers.communication.GridMessageListener; import org.apache.ignite.internal.NodeStoppingException; +import org.apache.ignite.internal.managers.communication.GridMessageListener; import org.apache.ignite.internal.processors.GridProcessorAdapter; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.StoredCacheData; import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture; import org.apache.ignite.internal.processors.cache.query.CacheQueryType; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType; @@ -71,9 +92,9 @@ import org.apache.ignite.internal.util.lang.GridClosureException; import org.apache.ignite.internal.util.lang.IgniteOutClosureX; import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.T3; +import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.util.worker.GridWorker; import org.apache.ignite.internal.util.worker.GridWorkerFuture; @@ -87,26 +108,6 @@ import org.apache.ignite.thread.IgniteThread; import org.jetbrains.annotations.Nullable; -import javax.cache.Cache; -import javax.cache.CacheException; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.atomic.AtomicBoolean; - import static org.apache.ignite.events.EventType.EVT_CACHE_QUERY_EXECUTED; import static org.apache.ignite.internal.GridTopic.TOPIC_SCHEMA; import static org.apache.ignite.internal.IgniteComponentType.INDEXING; @@ -502,6 +503,23 @@ private void onSchemaFinishDiscovery(SchemaFinishDiscoveryMessage msg) { if (cacheDesc != null && F.eq(cacheDesc.deploymentId(), proposeMsg.deploymentId())) cacheDesc.schemaChangeFinish(msg); + + if (ctx.cache().context().pageStore() != null && + ctx.cache().context().database().persistenceEnabled()) { + + StoredCacheData cacheData = new StoredCacheData(cacheDesc.cacheConfiguration()); + + cacheData.queryEntities(cacheDesc.schema().entities()); + + CacheGroupDescriptor grpDesc = ctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(); + + try { + ctx.cache().context().pageStore().storeCacheData(grpDesc, cacheData); + } + catch (IgniteCheckedException e) { + throw new IllegalStateException("Failed to persist cache data: " + cacheData.config().getName(), e); + } + } } // Propose message will be used from exchange thread to diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index f43a31ed52f81..9f517506358cc 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -96,8 +96,10 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.ClusterState; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.StoredCacheData; import org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; @@ -413,7 +415,7 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { // TODO IGNITE-5075 group descriptors. for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) { if (CU.isSystemCache(ccfg.getName())) { - storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), ccfg); + storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), new StoredCacheData(ccfg)); cacheNames.add(ccfg.getName()); } @@ -421,14 +423,17 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) if (!CU.isSystemCache(ccfg.getName())) { - storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), ccfg); + DynamicCacheDescriptor cacheDesc = cctx.cache().cacheDescriptors().get(ccfg.getName()); + + if (cacheDesc != null) + storeMgr.initializeForCache(cacheDesc.groupDescriptor(), new StoredCacheData(ccfg)); cacheNames.add(ccfg.getName()); } - for (CacheConfiguration ccfg : cctx.pageStore().readCacheConfigurations().values()) { - if (!cacheNames.contains(ccfg.getName())) - storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), ccfg); + for (StoredCacheData cacheData : cctx.pageStore().readCacheConfigurations().values()) { + if (!cacheNames.contains(cacheData.config().getName())) + storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(), cacheData); } readCheckpointAndRestoreMemory(); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java index 1343589172bce..f91c47f0357ca 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java @@ -46,6 +46,7 @@ import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; +import org.apache.ignite.internal.processors.cache.StoredCacheData; import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.marshaller.Marshaller; @@ -75,7 +76,7 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen public static final String CACHE_GRP_DIR_PREFIX = "cacheGroup-"; /** */ - public static final String CACHE_CONF_FILENAME = "conf.dat"; + public static final String CACHE_DATA_FILENAME = "cache_data.dat"; /** Marshaller. */ private static final Marshaller marshaller = new JdkMarshaller(); @@ -192,48 +193,44 @@ public FilePageStoreManager(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void initializeForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) + @Override public void initializeForCache(CacheGroupDescriptor grpDesc, StoredCacheData cacheData) throws IgniteCheckedException { int grpId = grpDesc.groupId(); if (!idxCacheStores.containsKey(grpId)) { - CacheStoreHolder holder = initForCache(grpDesc, ccfg); + CacheStoreHolder holder = initForCache(grpDesc, cacheData.config()); CacheStoreHolder old = idxCacheStores.put(grpId, holder); - assert old == null : "Non-null old store holder for cache: " + ccfg.getName(); + assert old == null : "Non-null old store holder for cache: " + cacheData.config().getName(); } - storeCacheConfiguration(grpDesc, ccfg); + storeCacheData(grpDesc, cacheData); } - /** - * @param grpDesc Cache group descriptor. - * @param ccfg Cache configuration. - * @throws IgniteCheckedException If failed. - */ - private void storeCacheConfiguration(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) + /** {@inheritDoc} */ + @Override public void storeCacheData(CacheGroupDescriptor grpDesc, StoredCacheData cacheData) throws IgniteCheckedException { - File cacheWorkDir = cacheWorkDirectory(grpDesc, ccfg); + File cacheWorkDir = cacheWorkDirectory(grpDesc, cacheData.config()); File file; assert cacheWorkDir.exists() : "Work directory does not exist: " + cacheWorkDir; if (grpDesc.sharedGroup()) - file = new File(cacheWorkDir, ccfg.getName() + CACHE_CONF_FILENAME); + file = new File(cacheWorkDir, cacheData.config().getName() + CACHE_DATA_FILENAME); else - file = new File(cacheWorkDir, CACHE_CONF_FILENAME); + file = new File(cacheWorkDir, CACHE_DATA_FILENAME); if (!file.exists() || file.length() == 0) { try { file.createNewFile(); try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(file))) { - marshaller.marshal(ccfg, stream); + marshaller.marshal(cacheData, stream); } } catch (IOException ex) { - throw new IgniteCheckedException("Failed to persist cache configuration: " + ccfg.getName(), ex); + throw new IgniteCheckedException("Failed to persist cache configuration: " + cacheData.config().getName(), ex); } } } @@ -473,7 +470,7 @@ private CacheStoreHolder initForCache(CacheGroupDescriptor grpDesc, CacheConfigu } /** {@inheritDoc} */ - @Override public Map readCacheConfigurations() throws IgniteCheckedException { + @Override public Map readCacheConfigurations() throws IgniteCheckedException { if (cctx.kernalContext().clientNode()) return Collections.emptyMap(); @@ -482,17 +479,17 @@ private CacheStoreHolder initForCache(CacheGroupDescriptor grpDesc, CacheConfigu if (files == null) return Collections.emptyMap(); - Map ccfgs = new HashMap<>(); + Map ccfgs = new HashMap<>(); for (File file : files) { if (file.isDirectory()) { if (file.getName().startsWith(CACHE_DIR_PREFIX)) { - File conf = new File(file, CACHE_CONF_FILENAME); + File conf = new File(file, CACHE_DATA_FILENAME); if (conf.exists() && conf.length() > 0) { - CacheConfiguration ccfg = readCacheConfig(conf); + StoredCacheData cacheData = readCacheData(conf); - ccfgs.put(ccfg.getName(), ccfg); + ccfgs.put(cacheData.config().getName(), cacheData); } } else if (file.getName().startsWith(CACHE_GRP_DIR_PREFIX)) @@ -508,27 +505,27 @@ else if (file.getName().startsWith(CACHE_GRP_DIR_PREFIX)) * @param ccfgs Cache configurations. * @throws IgniteCheckedException If failed. */ - private void readCacheGroupCaches(File grpDir, Map ccfgs) throws IgniteCheckedException { + private void readCacheGroupCaches(File grpDir, Map ccfgs) throws IgniteCheckedException { File[] files = grpDir.listFiles(); if (files == null) return; for (File file : files) { - if (!file.isDirectory() && file.getName().endsWith(CACHE_CONF_FILENAME) && file.length() > 0) { - CacheConfiguration ccfg = readCacheConfig(file); + if (!file.isDirectory() && file.getName().endsWith(CACHE_DATA_FILENAME) && file.length() > 0) { + StoredCacheData cacheData = readCacheData(file); - ccfgs.put(ccfg.getName(), ccfg); + ccfgs.put(cacheData.config().getName(), cacheData); } } } /** - * @param conf File with stored configuration. - * @return Cache configuration. + * @param conf File with stored cache data. + * @return Cache data. * @throws IgniteCheckedException If failed. */ - private CacheConfiguration readCacheConfig(File conf) throws IgniteCheckedException { + private StoredCacheData readCacheData(File conf) throws IgniteCheckedException { try (InputStream stream = new BufferedInputStream(new FileInputStream(conf))) { return marshaller.unmarshal(stream, U.resolveClassLoader(igniteCfg)); } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java new file mode 100644 index 0000000000000..a93e8d5fc40d4 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java @@ -0,0 +1,297 @@ +/* + * 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.cache.database; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheRebalanceMode; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.QueryIndex; +import org.apache.ignite.cache.QueryIndexType; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.database.DbCheckpointListener; +import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing; +import org.apache.ignite.internal.util.lang.GridAbsPredicate; +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.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.IgniteSystemProperties.IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK; + +/** + * + */ +public class IgnitePersistentStoreSchemaLoadTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** Index name. */ + private static final String IDX_NAME = "my_idx"; + + /** Cache name. */ + private static final String TMPL_NAME = "test_cache*"; + + /** Table name. */ + private static final String TBL_NAME = Person.class.getSimpleName(); + + /** Schema name. */ + private static final String SCHEMA_NAME = TBL_NAME; + + /** Cache name. */ + private static final String CACHE_NAME = TBL_NAME; + + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); + + cfg.setCacheConfiguration(cacheCfg(TMPL_NAME)); + + PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); + + pCfg.setCheckpointingFrequency(1000); + + cfg.setPersistentStoreConfiguration(pCfg); + + return cfg; + } + + /** */ + private CacheConfiguration cacheCfg(String name) { + CacheConfiguration cfg = new CacheConfiguration<>(); + + cfg.setName(name); + + cfg.setRebalanceMode(CacheRebalanceMode.NONE); + + cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + + return cfg; + } + + /** */ + private QueryEntity getEntity() { + LinkedHashMap fields = new LinkedHashMap<>(); + + fields.put("id", Integer.class.getName()); + fields.put("name", String.class.getName()); + + QueryEntity entity = new QueryEntity(Integer.class.getName(), Person.class.getName()); + entity.setFields(fields); + entity.setTableName(TBL_NAME); + + return entity; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + System.setProperty(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK, "true"); + + stopAllGrids(); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + deleteWorkFiles(); + + System.clearProperty(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK); + } + + /** */ + public void testPersistIndex() throws Exception { + IgniteEx ig0 = startGrid(0); + startGrid(1); + + final AtomicInteger cnt = new AtomicInteger(); + + GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)ig0.context().cache().context().database(); + + db.addCheckpointListener(new DbCheckpointListener() { + @Override public void onCheckpointBegin(Context context) throws IgniteCheckedException { + cnt.incrementAndGet(); + } + }); + + QueryIndex idx = new QueryIndex("name"); + + idx.setName(IDX_NAME); + + ig0.context().query().dynamicTableCreate(SCHEMA_NAME, getEntity(), TMPL_NAME, true); + + assert indexCnt(ig0, CACHE_NAME) == 0; + + ig0.context().query().dynamicIndexCreate(CACHE_NAME, SCHEMA_NAME, TBL_NAME, idx, false).get(); + + assert indexCnt(ig0, CACHE_NAME) == 1; + + waitForCheckpoint(cnt); + + stopGrid(1); + + IgniteEx ig1 = startGrid(1); + + assert indexCnt(ig1, CACHE_NAME) == 1; + } + + /** */ + public void testPersistCompositeIndex() throws Exception { + IgniteEx ig0 = startGrid(0); + startGrid(1); + + final AtomicInteger cnt = new AtomicInteger(); + + GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)ig0.context().cache().context().database(); + + db.addCheckpointListener(new DbCheckpointListener() { + @Override public void onCheckpointBegin(Context context) throws IgniteCheckedException { + cnt.incrementAndGet(); + } + }); + + ig0.context().query().dynamicTableCreate(SCHEMA_NAME, getEntity(), TMPL_NAME, true); + + assert indexCnt(ig0, CACHE_NAME) == 0; + + QueryIndex idx = new QueryIndex(Arrays.asList("id", "name"), QueryIndexType.SORTED); + + idx.setName(IDX_NAME); + + ig0.context().query().dynamicIndexCreate(CACHE_NAME, SCHEMA_NAME, TBL_NAME, idx, false).get(); + + assert indexCnt(ig0, CACHE_NAME) == 1; + + waitForCheckpoint(cnt); + + stopGrid(1); + + IgniteEx ig1 = startGrid(1); + + assert indexCnt(ig1, CACHE_NAME) == 1; + } + + /** */ + private void waitForCheckpoint(final AtomicInteger cnt) throws IgniteInterruptedCheckedException { + final int i = cnt.get(); + + GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + return cnt.get() > i; + } + }, 2000); + } + + /** */ + private int indexCnt(IgniteEx node, String cacheName) { + + DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName); + + int cnt = 0; + + for (QueryEntity entity : desc.schema().entities()) { + cnt += entity.getIndexes().size(); + } + + return cnt; + } + + /** + * @return Indexing. + */ + private IgniteH2Indexing getIndexing(IgniteEx ignite) { + return U.field(ignite.context().query(), "idx"); + } + + /** + * + */ + private void deleteWorkFiles() throws IgniteCheckedException { + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * + */ + protected static class Person implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + @SuppressWarnings("unused") + private Person() { + // No-op. + } + + /** */ + public Person(int id) { + this.id = id; + } + + /** */ + @QuerySqlField + protected int id; + + /** */ + @QuerySqlField + protected String name; + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + IgnitePersistentStoreSchemaLoadTest.Person person = (IgnitePersistentStoreSchemaLoadTest.Person)o; + + if (id != person.id) + return false; + + return name != null ? name.equals(person.name) : person.name == null; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int result = id; + + result = 31 * result + (name != null ? name.hashCode() : 0); + + return result; + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java index 783faf8a33221..997eef55edf26 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java @@ -24,7 +24,6 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.pagemem.PageIdUtils; @@ -32,6 +31,7 @@ import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.StoredCacheData; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.lang.IgniteFuture; @@ -53,7 +53,8 @@ public class NoOpPageStoreManager implements IgnitePageStoreManager { } /** {@inheritDoc} */ - @Override public void initializeForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) throws IgniteCheckedException { + @Override public void initializeForCache(CacheGroupDescriptor grpDesc, + StoredCacheData cacheData) throws IgniteCheckedException { // No-op. } @@ -171,10 +172,16 @@ public class NoOpPageStoreManager implements IgnitePageStoreManager { } /** {@inheritDoc} */ - @Override public Map readCacheConfigurations() throws IgniteCheckedException { + @Override public Map readCacheConfigurations() throws IgniteCheckedException { return Collections.emptyMap(); } + /** {@inheritDoc} */ + @Override public void storeCacheData(CacheGroupDescriptor grpDesc, + StoredCacheData cacheData) throws IgniteCheckedException { + // No-op. + } + /** {@inheritDoc} */ @Override public boolean hasIndexStore(int grpId) { return false; diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java index 2db7ff7b4ec72..88d4d0d6a3cca 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java @@ -23,6 +23,7 @@ import org.apache.ignite.cache.database.IgnitePersistentStoreDataStructuresTest; import org.apache.ignite.cache.database.IgnitePersistentStorePageSizesTest; import org.apache.ignite.cache.database.IgnitePersistentStoreRecoveryAfterFileCorruptionTest; +import org.apache.ignite.cache.database.IgnitePersistentStoreSchemaLoadTest; import org.apache.ignite.cache.database.IgnitePersistentStoreTxCacheRebalancingTest; import org.apache.ignite.cache.database.db.DbPageEvictionDuringPartitionClearSelfTest; import org.apache.ignite.cache.database.db.IgniteDbWholeClusterRestartSelfTest; @@ -71,6 +72,7 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(IgnitePersistentStoreContinuousRestartSelfTest.class); + suite.addTestSuite(IgnitePersistentStoreSchemaLoadTest.class); suite.addTestSuite(IgnitePersistentStoreDataStructuresTest.class); return suite; From a2e173053fcd2c3f194ea1907341f18afc7f8adc Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Tue, 6 Jun 2017 14:13:56 +0300 Subject: [PATCH 237/311] IGNITE-5267 - Fixed compilation after merge --- .../cache/database/IgnitePersistentStoreSchemaLoadTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java index a93e8d5fc40d4..bdf64bbfcf526 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java @@ -151,7 +151,7 @@ public void testPersistIndex() throws Exception { idx.setName(IDX_NAME); - ig0.context().query().dynamicTableCreate(SCHEMA_NAME, getEntity(), TMPL_NAME, true); + ig0.context().query().dynamicTableCreate(SCHEMA_NAME, getEntity(), TMPL_NAME, null, 1, true); assert indexCnt(ig0, CACHE_NAME) == 0; @@ -183,7 +183,7 @@ public void testPersistCompositeIndex() throws Exception { } }); - ig0.context().query().dynamicTableCreate(SCHEMA_NAME, getEntity(), TMPL_NAME, true); + ig0.context().query().dynamicTableCreate(SCHEMA_NAME, getEntity(), TMPL_NAME, null, 1, true); assert indexCnt(ig0, CACHE_NAME) == 0; From fffad68f6c23c36cf28e61bd7465082d71569665 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Wed, 7 Jun 2017 12:28:29 +0300 Subject: [PATCH 238/311] IGNITE-5375 - Persistence metrics introduced --- .../main/java/org/apache/ignite/Ignite.java | 6 + .../java/org/apache/ignite/MemoryMetrics.java | 29 +- .../org/apache/ignite/PersistenceMetrics.java | 114 +++++++ .../PersistentStoreConfiguration.java | 95 +++++- .../apache/ignite/internal/IgniteKernal.java | 13 + .../wal/IgniteWriteAheadLogManager.java | 5 + .../IgniteCacheDatabaseSharedManager.java | 10 + .../cache/database/MemoryMetricsImpl.java | 203 +++++------- .../database/MemoryMetricsMXBeanImpl.java | 15 + .../cache/database/MemoryMetricsSnapshot.java | 27 ++ .../database/PersistenceMetricsSnapshot.java | 144 +++++++++ .../cache/database/tree/io/PageIO.java | 8 + .../ignite/mxbean/MemoryMetricsMXBean.java | 12 + .../mxbean/PersistenceMetricsMXBean.java | 121 +++++++ .../database/MemoryMetricsSelfTest.java | 10 +- .../processors/igfs/IgfsIgniteMock.java | 8 + .../testframework/junits/IgniteMock.java | 6 + .../junits/multijvm/IgniteProcessProxy.java | 6 + .../GridCacheDatabaseSharedManager.java | 189 ++++++++--- .../database/PersistenceMetricsImpl.java | 297 ++++++++++++++++++ .../pagemem/CheckpointMetricsTracker.java | 183 +++++++++++ .../cache/database/pagemem/PageMemoryEx.java | 3 +- .../database/pagemem/PageMemoryImpl.java | 38 ++- .../wal/FileWriteAheadLogManager.java | 138 ++++++-- .../IgnitePersistenceMetricsSelfTest.java | 236 ++++++++++++++ ...tStoreRecoveryAfterFileCorruptionTest.java | 2 +- ...PageStoreCheckpointSimulationSelfTest.java | 4 +- ...usTreeReuseListPageMemoryImplSelfTest.java | 6 +- ...lusTreeSelfTestPageMemoryImplSelfTest.java | 5 +- ...MetadataStoragePageMemoryImplSelfTest.java | 5 +- .../database/pagemem/NoOpWALManager.java | 5 + .../pagemem/PageMemoryImplNoLoadSelfTest.java | 5 +- .../database/pagemem/PageMemoryImplTest.java | 5 +- .../testsuites/IgnitePdsTestSuite2.java | 7 +- .../org/apache/ignite/IgniteSpringBean.java | 7 + 35 files changed, 1745 insertions(+), 222 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsSnapshot.java create mode 100644 modules/core/src/main/java/org/apache/ignite/mxbean/PersistenceMetricsMXBean.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsImpl.java create mode 100644 modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/CheckpointMetricsTracker.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistenceMetricsSelfTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java index 8d5e9679a9325..f32782aadcb41 100644 --- a/modules/core/src/main/java/org/apache/ignite/Ignite.java +++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java @@ -638,4 +638,10 @@ public IgniteQueue queue(String name, int cap, @Nullable CollectionConfig * @return {@link MemoryMetrics} snapshot or {@code null} if no memory region is configured under specified name. */ @Nullable public MemoryMetrics memoryMetrics(String memPlcName); + + /** + * + * @return {@link PersistenceMetrics} snapshot. + */ + public PersistenceMetrics persistentStoreMetrics(); } diff --git a/modules/core/src/main/java/org/apache/ignite/MemoryMetrics.java b/modules/core/src/main/java/org/apache/ignite/MemoryMetrics.java index 81f8309e86269..c709777b9193c 100644 --- a/modules/core/src/main/java/org/apache/ignite/MemoryMetrics.java +++ b/modules/core/src/main/java/org/apache/ignite/MemoryMetrics.java @@ -55,7 +55,9 @@ public interface MemoryMetrics { public String getName(); /** - * Gets a total number of allocated pages in a memory region. + * Gets a total number of allocated pages related to the memory policy. When persistence is disabled, this + * metric shows the total number of pages in memory. When persistence is enabled, this metric shows the + * total number of pages in memory and on disk. * * @return Total number of allocated pages. */ @@ -89,4 +91,29 @@ public interface MemoryMetrics { * @return The percentage of space that is still free and can be filled in. */ public float getPagesFillFactor(); + + /** + * Gets the number of dirty pages (pages which contents is different from the current persistent storage state). + * This metric is enabled only for Ignite nodes with enabled persistence. + * + * @return Current number of dirty pages. + */ + public long getDirtyPages(); + + /** + * Gets rate (pages per second) at which pages get replaced with other pages from persistent storage. + * The rate effectively represents the rate at which pages get 'evicted' in favor of newly needed pages. + * This metric is enabled only for Ignite nodes with enabled persistence. + * + * @return Pages per second replace rate. + */ + public float getPagesReplaceRate(); + + /** + * Gets total number of pages currently loaded to the RAM. When persistence is disabled, this metric is equal + * to {@link #getTotalAllocatedPages()}. + * + * @return Total number of pages loaded to RAM. + */ + public long getPhysicalMemoryPages(); } diff --git a/modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java b/modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java new file mode 100644 index 0000000000000..3f00b019a3685 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java @@ -0,0 +1,114 @@ +/* + * 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; + +import org.apache.ignite.configuration.PersistentStoreConfiguration; + +/** + * + */ +public interface PersistenceMetrics { + /** + * Gets the average number of WAL records per second written during the last time interval. + *

+ * The length of time interval is configured via {@link PersistentStoreConfiguration#setRateTimeInterval(long)} + * configurartion property. + * The number of subintervals is configured via {@link PersistentStoreConfiguration#setSubIntervals(int)} + * configuration property. + */ + public float getWalLoggingRate(); + + /** + * Gets the average number of bytes per second written during the last time interval. + * The length of time interval is configured via {@link PersistentStoreConfiguration#setRateTimeInterval(long)} + * configurartion property. + * The number of subintervals is configured via {@link PersistentStoreConfiguration#setSubIntervals(int)} + * configuration property. + */ + public float getWalWritingRate(); + + /** + * Gets the current number of WAL segments in the WAL archive. + */ + public int getWalArchiveSegments(); + + /** + * Gets the average WAL fsync duration in microseconds over the last time interval. + *

+ * The length of time interval is configured via {@link PersistentStoreConfiguration#setRateTimeInterval(long)} + * configurartion property. + * The number of subintervals is configured via {@link PersistentStoreConfiguration#setSubIntervals(int)} + * configuration property. + */ + public float getWalFsyncTimeAverage(); + + /** + * Gets the duration of the last checkpoint in milliseconds. + * + * @return Total checkpoint duration in milliseconds. + */ + public long getLastCheckpointingDuration(); + + /** + * Gets the duration of last checkpoint lock wait in milliseconds. + * + * @return Checkpoint lock wait time in milliseconds. + */ + public long getLastCheckpointLockWaitDuration(); + + /** + * Gets the duration of last checkpoint mark phase in milliseconds. + * + * @return Checkpoint mark duration in milliseconds. + */ + public long getLastCheckpointMarkDuration(); + + /** + * Gets the duration of last checkpoint pages write phase in milliseconds. + * + * @return Checkpoint pages write phase in milliseconds. + */ + public long getLastCheckpointPagesWriteDuration(); + + /** + * Gets the duration of the sync phase of the last checkpoint in milliseconds. + * + * @return Checkpoint fsync time in milliseconds. + */ + public long getLastCheckpointFsyncDuration(); + + /** + * Gets the total number of pages written during the last checkpoint. + * + * @return Total number of pages written during the last checkpoint. + */ + public long getLastCheckpointTotalPagesNumber(); + + /** + * Gets the number of data pages written during the last checkpoint. + * + * @return Total number of data pages written during the last checkpoint. + */ + public long getLastCheckpointDataPagesNumber(); + + /** + * Gets the number of pages copied to a temporary checkpoint buffer during the last checkpoint. + * + * @return Total number of pages copied to a temporary checkpoint buffer during the last checkpoint. + */ + public long getLastCheckpointCopiedOnWritePagesNumber(); +} 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 14e3a7354d930..362dcdf72848a 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 @@ -31,6 +31,15 @@ public class PersistentStoreConfiguration implements Serializable { /** Lock default wait time, 10 sec. */ public static final int DFLT_LOCK_WAIT_TIME = 10 * 1000; + /** */ + public static final boolean DFLT_METRICS_ENABLED = false; + + /** Default amount of sub intervals to calculate rate-based metric. */ + public static final int DFLT_SUB_INTERVALS = 5; + + /** Default length of interval over which rate-based metric is calculated. */ + public static final int DFLT_RATE_TIME_INTERVAL_MILLIS = 60_000; + /** */ @SuppressWarnings("UnnecessaryBoxing") public static final Long DFLT_CHECKPOINTING_PAGE_BUFFER_SIZE = new Long(256L * 1024 * 1024); @@ -48,7 +57,7 @@ public class PersistentStoreConfiguration implements Serializable { private static final int DFLT_WAL_SEGMENT_SIZE = 64 * 1024 * 1024; /** */ - private String persistenteStorePath; + private String persistenceStorePath; /** Checkpointing frequency. */ private long checkpointingFreq = DFLT_CHECKPOINTING_FREQ; @@ -77,11 +86,27 @@ public class PersistentStoreConfiguration implements Serializable { /** WAL archive path. */ private String walArchivePath; + /** Metrics enabled flag. */ + private boolean metricsEnabled = DFLT_METRICS_ENABLED; + + /** + * Number of sub-intervals the whole {@link #setRateTimeInterval(long)} will be split into to calculate + * rate-based metrics. + *

+ * Setting it to a bigger value will result in more precise calculation and smaller drops of + * rate-based metrics when next sub-interval has to be recycled but introduces bigger + * calculation overhead. + */ + private int subIntervals = DFLT_SUB_INTERVALS; + + /** Time interval (in milliseconds) for rate-based metrics. */ + private long rateTimeInterval = DFLT_RATE_TIME_INTERVAL_MILLIS; + /** * Returns a path the root directory where the Persistent Store will persist data and indexes. */ public String getPersistentStorePath() { - return persistenteStorePath; + return persistenceStorePath; } /** @@ -91,7 +116,7 @@ public String getPersistentStorePath() { * @param persistenceStorePath Persistence store path. */ public PersistentStoreConfiguration setPersistentStorePath(String persistenceStorePath) { - this.persistenteStorePath = persistenceStorePath; + this.persistenceStorePath = persistenceStorePath; return this; } @@ -291,4 +316,68 @@ public PersistentStoreConfiguration setWalArchivePath(String walArchivePath) { return this; } + + /** + * Gets flag indicating whether persistence metrics collection is enabled. + * Default value is {@link #DFLT_METRICS_ENABLED}. + * + * @return Metrics enabled flag. + */ + public boolean isMetricsEnabled() { + return metricsEnabled; + } + + /** + * Sets flag indicating whether persistence metrics collection is enabled. + * + * @param metricsEnabled Metrics enabled flag. + */ + public PersistentStoreConfiguration setMetricsEnabled(boolean metricsEnabled) { + this.metricsEnabled = metricsEnabled; + + return this; + } + + /** + * Gets the length of the time interval for rate-based metrics. This interval defines a window over which + * hits will be tracked. Default value is {@link #DFLT_RATE_TIME_INTERVAL_MILLIS}. + * + * @return Time interval in milliseconds. + */ + public long getRateTimeInterval() { + return rateTimeInterval; + } + + /** + * Sets the length of the time interval for rate-based metrics. This interval defines a window over which + * hits will be tracked. + * + * @param rateTimeInterval Time interval in milliseconds. + */ + public PersistentStoreConfiguration setRateTimeInterval(long rateTimeInterval) { + this.rateTimeInterval = rateTimeInterval; + + return this; + } + + /** + * Gets the number of sub-intervals to split the {@link #getRateTimeInterval()} into to track the update history. + * Default value is {@link #DFLT_SUB_INTERVALS}. + * + * @return The number of sub-intervals for history tracking. + */ + public int getSubIntervals() { + return subIntervals; + } + + /** + * Sets the number of sub-intervals to split the {@link #getRateTimeInterval()} into to track the update history. + * + * @param subIntervals The number of sub-intervals for history tracking. + */ + public PersistentStoreConfiguration setSubIntervals(int subIntervals) { + this.subIntervals = subIntervals; + + return this; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index b04a9699321b4..bce303238768a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -75,6 +75,7 @@ import org.apache.ignite.IgniteTransactions; import org.apache.ignite.Ignition; import org.apache.ignite.MemoryMetrics; +import org.apache.ignite.PersistenceMetrics; import org.apache.ignite.cache.affinity.Affinity; import org.apache.ignite.cluster.ClusterGroup; import org.apache.ignite.cluster.ClusterMetrics; @@ -3440,6 +3441,18 @@ public IgniteInternalFuture getOrCreateCacheAsync(String cacheName, boolean c } } + /** {@inheritDoc} */ + @Override public PersistenceMetrics persistentStoreMetrics() { + guard(); + + try { + return ctx.cache().context().database().persistentStoreMetrics(); + } + finally { + unguard(); + } + } + /** {@inheritDoc} */ @Nullable @Override public IgniteAtomicSequence atomicSequence(String name, long initVal, boolean create) { guard(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/IgniteWriteAheadLogManager.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/IgniteWriteAheadLogManager.java index ac785b6b024f8..187df8d196a42 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/IgniteWriteAheadLogManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/IgniteWriteAheadLogManager.java @@ -101,6 +101,11 @@ public interface IgniteWriteAheadLogManager extends GridCacheSharedManager, Igni */ public int truncate(WALPointer ptr); + /** + * @return Total number of segments in the WAL archive. + */ + public int walArchiveSegments(); + /** * @param ptr Pointer. * @return True if given pointer is located in reserved segment. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 19c25aa11d08d..f13532d8cc989 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -28,6 +28,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.MemoryMetrics; +import org.apache.ignite.PersistenceMetrics; import org.apache.ignite.configuration.DataPageEvictionMode; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; @@ -582,6 +583,13 @@ public Collection memoryMetrics() { return Collections.emptyList(); } + /** + * @return PersistenceMetrics if persistence is enabled or {@code null} otherwise. + */ + public PersistenceMetrics persistentStoreMetrics() { + return null; + } + /** * @param memPlcName Name of {@link MemoryPolicy} to obtain {@link MemoryMetrics} for. * @return {@link MemoryMetrics} snapshot for specified {@link MemoryPolicy} or {@code null} if @@ -904,6 +912,8 @@ protected PageMemory createPageMemory( MemoryPolicyConfiguration memPlcCfg, MemoryMetricsImpl memMetrics ) { + memMetrics.persistenceEnabled(false); + return new PageMemoryNoStoreImpl( log, memProvider, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java index 2bd96e75b5d38..2e5a78cb5222e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java @@ -16,12 +16,11 @@ */ package org.apache.ignite.internal.processors.cache.database; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; import org.apache.ignite.MemoryMetrics; import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl; -import org.apache.ignite.internal.util.IgniteUtils; +import org.apache.ignite.internal.processors.cache.ratemetrics.HitRateMetrics; import org.apache.ignite.internal.util.typedef.internal.U; import org.jsr166.LongAdder8; @@ -40,24 +39,30 @@ public class MemoryMetricsImpl implements MemoryMetrics { */ private final LongAdder8 largeEntriesPages = new LongAdder8(); + /** Counter for number of dirty pages. */ + private LongAdder8 dirtyPages = new LongAdder8(); + /** */ private volatile boolean metricsEnabled; /** */ - private volatile int subInts; + private boolean persistenceEnabled; /** */ - private volatile LongAdder8[] allocRateCounters; + private volatile int subInts; - /** */ - private final AtomicInteger counterIdx = new AtomicInteger(0); + /** Allocation rate calculator. */ + private volatile HitRateMetrics allocRate = new HitRateMetrics(60_000, 5); /** */ - private final AtomicLong lastUpdTime = new AtomicLong(0); + private volatile HitRateMetrics pageReplaceRate = new HitRateMetrics(60_000, 5); /** */ private final MemoryPolicyConfiguration memPlcCfg; + /** */ + private PageMemory pageMem; + /** Time interval (in milliseconds) when allocations/evictions are counted to calculate rate. */ private volatile long rateTimeInterval; @@ -72,11 +77,6 @@ public MemoryMetricsImpl(MemoryPolicyConfiguration memPlcCfg) { rateTimeInterval = memPlcCfg.getRateTimeInterval(); subInts = memPlcCfg.getSubIntervals(); - - allocRateCounters = new LongAdder8[subInts]; - - for (int i = 0; i < subInts; i++) - allocRateCounters[i] = new LongAdder8(); } /** {@inheritDoc} */ @@ -94,12 +94,7 @@ public MemoryMetricsImpl(MemoryPolicyConfiguration memPlcCfg) { if (!metricsEnabled) return 0; - float res = 0; - - for (int i = 0; i < subInts; i++) - res += allocRateCounters[i].floatValue(); - - return res * 1000 / rateTimeInterval; + return ((float) allocRate.getRate()) / rateTimeInterval; } /** {@inheritDoc} */ @@ -125,125 +120,87 @@ public MemoryMetricsImpl(MemoryPolicyConfiguration memPlcCfg) { return freeList.fillFactor(); } - /** - * Increments totalAllocatedPages counter. - */ - public void incrementTotalAllocatedPages() { - if (metricsEnabled) { - totalAllocatedPages.increment(); + /** {@inheritDoc} */ + @Override public long getDirtyPages() { + if (!metricsEnabled || !persistenceEnabled) + return 0; - try { - updateAllocationRateMetrics(); - } - catch (ArrayIndexOutOfBoundsException | NullPointerException ignored) { - // No-op. - } - } + return dirtyPages.longValue(); } - /** - * - */ - private void updateAllocationRateMetrics() { - long lastUpdT = lastUpdTime.get(); - long currT = IgniteUtils.currentTimeMillis(); - - int currIdx = counterIdx.get(); - - long deltaT = currT - lastUpdT; - - int subInts = this.subInts; - - LongAdder8[] rateCntrs = allocRateCounters; - - if (subInts != rateCntrs.length) - return; - - int cntrIdx = counterIdx.get(); - - for (int i = 1; i <= subInts; i++) { - if (deltaT < subInt(i)) { - if (i > 1) { - if (!lastUpdTime.compareAndSet(lastUpdT, currT)) { - rateCntrs[cntrIdx].increment(); - - break; - } - } - - if (rotateIndex(currIdx, i - 1)) { - currIdx = counterIdx.get(); - - resetCounters(currIdx, i - 1); - - rateCntrs[currIdx].increment(); + /** {@inheritDoc} */ + @Override public float getPagesReplaceRate() { + if (!metricsEnabled || !persistenceEnabled) + return 0; - break; - } - else { - rateCntrs[cntrIdx].increment(); + return ((float) pageReplaceRate.getRate()) / rateTimeInterval; + } - break; - } - } - else if (i == subInts && lastUpdTime.compareAndSet(lastUpdT, currT)) - resetAll(); + /** {@inheritDoc} */ + @Override public long getPhysicalMemoryPages() { + if (!metricsEnabled || !persistenceEnabled) + return 0; - if (currIdx != cntrIdx) { - rateCntrs[cntrIdx].increment(); + assert pageMem != null; - break; - } - } + return pageMem.loadedPages(); } /** - * @param intervalNum Interval number. + * Updates pageReplaceRate metric. */ - private long subInt(int intervalNum) { - return (rateTimeInterval * intervalNum) / subInts; + public void updatePageReplaceRate() { + if (metricsEnabled) + pageReplaceRate.onHit(); } /** - * @param idx Index. - * @param rotateStep Rotate step. + * Increments dirtyPages counter. */ - private boolean rotateIndex(int idx, int rotateStep) { - if (rotateStep == 0) - return true; + public void incrementDirtyPages() { + if (metricsEnabled) + dirtyPages.increment(); + } - int subInts = this.subInts; + /** + * Decrements dirtyPages counter. + */ + public void decrementDirtyPages() { + if (metricsEnabled) + dirtyPages.decrement(); + } - assert rotateStep < subInts; + /** + * Resets dirtyPages counter to zero. + */ + public void resetDirtyPages() { + if (metricsEnabled) + dirtyPages.reset(); + } - int nextIdx = (idx + rotateStep) % subInts; + /** + * Increments totalAllocatedPages counter. + */ + public void incrementTotalAllocatedPages() { + if (metricsEnabled) { + totalAllocatedPages.increment(); - return counterIdx.compareAndSet(idx, nextIdx); + updateAllocationRateMetrics(); + } } /** * */ - private void resetAll() { - LongAdder8[] cntrs = allocRateCounters; - - for (LongAdder8 cntr : cntrs) - cntr.reset(); + private void updateAllocationRateMetrics() { + allocRate.onHit(); } /** - * @param currIdx Current index. - * @param resettingCntrs Resetting allocRateCounters. + * @param intervalNum Interval number. */ - private void resetCounters(int currIdx, int resettingCntrs) { - if (resettingCntrs == 0) - return; - - for (int j = 0; j < resettingCntrs; j++) { - int cleanIdx = currIdx - j >= 0 ? currIdx - j : currIdx - j + subInts; - - allocRateCounters[cleanIdx].reset(); - } + private long subInt(int intervalNum) { + return (rateTimeInterval * intervalNum) / subInts; } /** @@ -276,11 +233,28 @@ public void disableMetrics() { metricsEnabled = false; } + /** + * @param persistenceEnabled Persistence enabled. + */ + public void persistenceEnabled(boolean persistenceEnabled) { + this.persistenceEnabled = persistenceEnabled; + } + + /** + * @param pageMem Page mem. + */ + public void pageMemory(PageMemory pageMem) { + this.pageMem = pageMem; + } + /** * @param rateTimeInterval Time interval (in milliseconds) used to calculate allocation/eviction rate. */ public void rateTimeInterval(long rateTimeInterval) { this.rateTimeInterval = rateTimeInterval; + + allocRate = new HitRateMetrics((int) rateTimeInterval, subInts); + pageReplaceRate = new HitRateMetrics((int) rateTimeInterval, subInts); } /** @@ -297,13 +271,8 @@ public void subIntervals(int subInts) { if (rateTimeInterval / subInts < 10) subInts = (int) rateTimeInterval / 10; - LongAdder8[] newCounters = new LongAdder8[subInts]; - - for (int i = 0; i < subInts; i++) - newCounters[i] = new LongAdder8(); - - this.subInts = subInts; - allocRateCounters = newCounters; + allocRate = new HitRateMetrics((int) rateTimeInterval, subInts); + pageReplaceRate = new HitRateMetrics((int) rateTimeInterval, subInts); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java index d3ae37841e042..b53db4b9b133b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java @@ -66,6 +66,21 @@ class MemoryMetricsMXBeanImpl implements MemoryMetricsMXBean { return memMetrics.getTotalAllocatedPages(); } + /** {@inheritDoc} */ + @Override public long getDirtyPages() { + return memMetrics.getDirtyPages(); + } + + /** {@inheritDoc} */ + @Override public float getPagesReplaceRate() { + return memMetrics.getPagesReplaceRate(); + } + + /** {@inheritDoc} */ + @Override public long getPhysicalMemoryPages() { + return memMetrics.getPhysicalMemoryPages(); + } + /** {@inheritDoc} */ @Override public void rateTimeInterval(long rateTimeInterval) { if (rateTimeInterval < 1000) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsSnapshot.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsSnapshot.java index 5f337bd58c86c..f4874ebfc2000 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsSnapshot.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsSnapshot.java @@ -41,6 +41,15 @@ public class MemoryMetricsSnapshot implements MemoryMetrics { /** */ private float pagesFillFactor; + /** */ + private long dirtyPages; + + /** */ + private float pageReplaceRate; + + /** */ + private long physicalMemoryPages; + /** * @param metrics Metrics instance to take a copy. */ @@ -51,6 +60,9 @@ public MemoryMetricsSnapshot(MemoryMetrics metrics) { evictionRate = metrics.getEvictionRate(); largeEntriesPagesPercentage = metrics.getLargeEntriesPagesPercentage(); pagesFillFactor = metrics.getPagesFillFactor(); + dirtyPages = metrics.getDirtyPages(); + pageReplaceRate = metrics.getPagesReplaceRate(); + physicalMemoryPages = metrics.getPhysicalMemoryPages(); } /** {@inheritDoc} */ @@ -82,4 +94,19 @@ public MemoryMetricsSnapshot(MemoryMetrics metrics) { @Override public float getPagesFillFactor() { return pagesFillFactor; } + + /** {@inheritDoc} */ + @Override public long getDirtyPages() { + return dirtyPages; + } + + /** {@inheritDoc} */ + @Override public float getPagesReplaceRate() { + return pageReplaceRate; + } + + /** {@inheritDoc} */ + @Override public long getPhysicalMemoryPages() { + return physicalMemoryPages; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsSnapshot.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsSnapshot.java new file mode 100644 index 0000000000000..c939710db6a32 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsSnapshot.java @@ -0,0 +1,144 @@ +/* + * 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.database; + +import org.apache.ignite.PersistenceMetrics; +import org.apache.ignite.internal.util.typedef.internal.S; + +/** + * + */ +public class PersistenceMetricsSnapshot implements PersistenceMetrics { + /** */ + private float walLoggingRate; + + /** */ + private float walWritingRate; + + /** */ + private int walArchiveSegments; + + /** */ + private float walFsyncTimeAvg; + + /** */ + private long lastCpDuration; + + /** */ + private long lastCpLockWaitDuration; + + /** */ + private long lastCpMmarkDuration; + + /** */ + private long lastCpPagesWriteDuration; + + /** */ + private long lastCpFsyncDuration; + + /** */ + private long lastCpTotalPages; + + /** */ + private long lastCpDataPages; + + /** */ + private long lastCpCowPages; + + /** + * @param metrics Metrics. + */ + public PersistenceMetricsSnapshot(PersistenceMetrics metrics) { + walLoggingRate = metrics.getWalLoggingRate(); + walWritingRate = metrics.getWalWritingRate(); + walArchiveSegments = metrics.getWalArchiveSegments(); + walFsyncTimeAvg = metrics.getWalFsyncTimeAverage(); + lastCpDuration = metrics.getLastCheckpointingDuration(); + lastCpLockWaitDuration = metrics.getLastCheckpointLockWaitDuration(); + lastCpMmarkDuration = metrics.getLastCheckpointMarkDuration(); + lastCpPagesWriteDuration = metrics.getLastCheckpointPagesWriteDuration(); + lastCpFsyncDuration = metrics.getLastCheckpointFsyncDuration(); + lastCpTotalPages = metrics.getLastCheckpointTotalPagesNumber(); + lastCpDataPages = metrics.getLastCheckpointDataPagesNumber(); + lastCpCowPages = metrics.getLastCheckpointCopiedOnWritePagesNumber(); + } + + /** {@inheritDoc} */ + @Override public float getWalLoggingRate() { + return walLoggingRate; + } + + /** {@inheritDoc} */ + @Override public float getWalWritingRate() { + return walWritingRate; + } + + /** {@inheritDoc} */ + @Override public int getWalArchiveSegments() { + return walArchiveSegments; + } + + /** {@inheritDoc} */ + @Override public float getWalFsyncTimeAverage() { + return walFsyncTimeAvg; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointingDuration() { + return lastCpDuration; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointLockWaitDuration() { + return lastCpLockWaitDuration; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointMarkDuration() { + return lastCpMmarkDuration; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointPagesWriteDuration() { + return lastCpPagesWriteDuration; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointFsyncDuration() { + return lastCpFsyncDuration; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointTotalPagesNumber() { + return lastCpTotalPages; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointDataPagesNumber() { + return lastCpDataPages; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointCopiedOnWritePagesNumber() { + return lastCpCowPages; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(PersistenceMetricsSnapshot.class, this); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java index e40ed11168f20..dd6a503a1766e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java @@ -537,4 +537,12 @@ public static > Q getBPlusIO(int type, int ver) throws Igni throw new IgniteCheckedException("Unknown page IO type: " + type); } + + /** + * @param type Type to test. + * @return {@code True} if data page. + */ + public static boolean isDataPageType(int type) { + return type == T_DATA; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java b/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java index d0900f6b8a73c..4d6c96a2353c5 100644 --- a/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java +++ b/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java @@ -73,6 +73,18 @@ public interface MemoryMetricsMXBean extends MemoryMetrics { @MXBeanDescription("Percentage of space that is still free and can be filled in.") @Override public float getPagesFillFactor(); + /** {@inheritDoc} */ + @MXBeanDescription("Number of pages in memory not yet synchronized with persistent storage.") + @Override public long getDirtyPages(); + + /** {@inheritDoc} */ + @MXBeanDescription("Rate at which pages in memory are replaced with pages from persistent storage (pages per second).") + @Override public float getPagesReplaceRate(); + + /** {@inheritDoc} */ + @MXBeanDescription("Number of pages residing in physical RAM.") + @Override public long getPhysicalMemoryPages(); + /** * Enables memory metrics collection on an Apache Ignite node. */ diff --git a/modules/core/src/main/java/org/apache/ignite/mxbean/PersistenceMetricsMXBean.java b/modules/core/src/main/java/org/apache/ignite/mxbean/PersistenceMetricsMXBean.java new file mode 100644 index 0000000000000..30ccab465c494 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/mxbean/PersistenceMetricsMXBean.java @@ -0,0 +1,121 @@ +/* + * 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.mxbean; + +import org.apache.ignite.PersistenceMetrics; +import org.apache.ignite.configuration.PersistentStoreConfiguration; + +/** + * + */ +public interface PersistenceMetricsMXBean extends PersistenceMetrics { + /** {@inheritDoc} */ + @MXBeanDescription("Average number of WAL records per second written during the last time interval.") + @Override float getWalLoggingRate(); + + /** {@inheritDoc} */ + @MXBeanDescription("Average number of bytes per second written during the last time interval.") + @Override float getWalWritingRate(); + + /** {@inheritDoc} */ + @MXBeanDescription("Current number of WAL segments in the WAL archive.") + @Override int getWalArchiveSegments(); + + /** {@inheritDoc} */ + @MXBeanDescription("Average WAL fsync duration in microseconds over the last time interval.") + @Override float getWalFsyncTimeAverage(); + + /** {@inheritDoc} */ + @MXBeanDescription("Duration of the last checkpoint in milliseconds.") + @Override long getLastCheckpointingDuration(); + + /** {@inheritDoc} */ + @MXBeanDescription("Duration of the checkpoint lock wait in milliseconds.") + @Override long getLastCheckpointLockWaitDuration(); + + /** {@inheritDoc} */ + @MXBeanDescription("Duration of the checkpoint mark in milliseconds.") + @Override long getLastCheckpointMarkDuration(); + + /** {@inheritDoc} */ + @MXBeanDescription("Duration of the checkpoint pages write in milliseconds.") + @Override long getLastCheckpointPagesWriteDuration(); + + /** {@inheritDoc} */ + @MXBeanDescription("Duration of the sync phase of the last checkpoint in milliseconds.") + @Override long getLastCheckpointFsyncDuration(); + + /** {@inheritDoc} */ + @MXBeanDescription("Total number of pages written during the last checkpoint.") + @Override long getLastCheckpointTotalPagesNumber(); + + /** {@inheritDoc} */ + @MXBeanDescription("Total number of data pages written during the last checkpoint.") + @Override long getLastCheckpointDataPagesNumber(); + + /** {@inheritDoc} */ + @MXBeanDescription("Number of pages copied to a temporary checkpoint buffer during the last checkpoint.") + @Override long getLastCheckpointCopiedOnWritePagesNumber(); + + /** + * Enables persistence metrics collection on an Apache Ignite node. + */ + @MXBeanDescription("Enables persistence metrics collection on an Apache Ignite node.") + public void enableMetrics(); + + /** + * Disables persistence metrics collection on an Apache Ignite node. + */ + @MXBeanDescription("Disables persistence metrics collection on an Apache Ignite node.") + public void disableMetrics(); + + /** + * Sets time interval for rate-based metrics. Identical to setting + * {@link PersistentStoreConfiguration#setRateTimeInterval(long)} configuration property. + * + * @param rateTimeInterval Time interval (in milliseconds) used for allocation and eviction rates calculations. + */ + @MXBeanDescription( + "Sets time interval for pages allocation and eviction monitoring purposes." + ) + @MXBeanParametersNames( + "rateTimeInterval" + ) + @MXBeanParametersDescriptions( + "Time interval (in milliseconds) to set." + ) + public void rateTimeInterval(long rateTimeInterval); + + /** + * Sets a number of sub-intervals the whole {@link #rateTimeInterval(long)} will be split into to calculate + * rate-based metrics. Identical to setting {@link PersistentStoreConfiguration#setSubIntervals(int)} configuration + * property. + * + * @param subInts A number of sub-intervals. + */ + @MXBeanDescription( + "Sets a number of sub-intervals to calculate allocation and eviction rates metrics." + ) + @MXBeanParametersNames( + "subInts" + ) + @MXBeanParametersDescriptions( + "Number of subintervals to set." + ) + public void subIntervals(int subInts); +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MemoryMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MemoryMetricsSelfTest.java index 706e7174936ca..3a99cb24c12b3 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MemoryMetricsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MemoryMetricsSelfTest.java @@ -66,7 +66,9 @@ public void testAllocationRateSingleThreaded() throws Exception { joinAllThreads(); - assertEquals(4, watcher.rateDropsCntr); + assertTrue(watcher.rateDropsCntr > 3); + + assertTrue(watcher.rateDropsCntr < 6); } /** @@ -87,7 +89,9 @@ public void testAllocationRateMultiThreaded() throws Exception { joinAllocationThreads(); - assertEquals(4, watcher.rateDropsCntr); + assertTrue(watcher.rateDropsCntr > 3); + + assertTrue(watcher.rateDropsCntr < 6); sleep(3); @@ -150,7 +154,7 @@ public void testAllocationRateSubintervalsConcurrentChange() throws Exception { for (int i = 0; i < 10; i++) { Thread.sleep(25); - memMetrics.subIntervals((2 + i * 5) % 3 + 1); + memMetrics.subIntervals((2 + i * 5) % 3 + 2); } joinAllThreads(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsIgniteMock.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsIgniteMock.java index b4fcc705a2b8a..2f3a878211bac 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsIgniteMock.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsIgniteMock.java @@ -39,6 +39,7 @@ import org.apache.ignite.IgniteSet; import org.apache.ignite.IgniteTransactions; import org.apache.ignite.MemoryMetrics; +import org.apache.ignite.PersistenceMetrics; import org.apache.ignite.cache.affinity.Affinity; import org.apache.ignite.cluster.ClusterGroup; import org.apache.ignite.cluster.ClusterNode; @@ -553,6 +554,13 @@ public IgfsIgniteMock(@Nullable String name, IgniteFileSystem igfs) { return null; } + /** {@inheritDoc} */ + @Override public PersistenceMetrics persistentStoreMetrics() { + throwUnsupported(); + + return null; + } + /** * Throw {@link UnsupportedOperationException}. */ diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java index 97157a88357d5..709639e0879dd 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java @@ -46,6 +46,7 @@ import org.apache.ignite.IgniteSet; import org.apache.ignite.IgniteTransactions; import org.apache.ignite.MemoryMetrics; +import org.apache.ignite.PersistenceMetrics; import org.apache.ignite.binary.BinaryObjectBuilder; import org.apache.ignite.binary.BinaryObjectException; import org.apache.ignite.cache.affinity.Affinity; @@ -452,6 +453,11 @@ public IgniteMock( return null; } + /** {@inheritDoc} */ + @Override public PersistenceMetrics persistentStoreMetrics() { + return null; + } + /** * @param staticCfg Configuration. */ diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java index f4dc49136d200..4fea480455530 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java @@ -50,6 +50,7 @@ import org.apache.ignite.IgniteSet; import org.apache.ignite.IgniteTransactions; import org.apache.ignite.MemoryMetrics; +import org.apache.ignite.PersistenceMetrics; import org.apache.ignite.cache.affinity.Affinity; import org.apache.ignite.cluster.ClusterGroup; import org.apache.ignite.cluster.ClusterNode; @@ -669,6 +670,11 @@ public void kill() throws Exception { throw new UnsupportedOperationException("Operation isn't supported yet."); } + /** {@inheritDoc} */ + @Override public PersistenceMetrics persistentStoreMetrics() { + throw new UnsupportedOperationException("Operation isn't supported yet."); + } + /** {@inheritDoc} */ @Override public void close() throws IgniteException { if (locJvmGrid != null) { diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 9f517506358cc..ff5dfa9bf50dd 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -57,10 +57,15 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.management.InstanceNotFoundException; +import javax.management.JMException; +import javax.management.MBeanRegistrationException; +import javax.management.ObjectName; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.PersistenceMetrics; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.DataPageEvictionMode; import org.apache.ignite.configuration.IgniteConfiguration; @@ -101,6 +106,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.StoredCacheData; import org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager; +import org.apache.ignite.internal.processors.cache.database.pagemem.CheckpointMetricsTracker; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; @@ -127,6 +133,7 @@ import org.apache.ignite.internal.util.worker.GridWorker; import org.apache.ignite.lang.IgniteBiTuple; import org.apache.ignite.lang.IgniteInClosure; +import org.apache.ignite.mxbean.PersistenceMetricsMXBean; import org.apache.ignite.thread.IgniteThread; import org.jetbrains.annotations.Nullable; @@ -235,7 +242,7 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan private volatile boolean printCheckpointStats = true; /** Database configuration. */ - private final PersistentStoreConfiguration dbCfg; + private final PersistentStoreConfiguration persistenceCfg; /** */ private final Collection lsnrs = new CopyOnWriteArrayList<>(); @@ -270,19 +277,25 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan /** Snapshot manager. */ private IgniteCacheSnapshotManager snapshotMgr; + /** */ + private PersistenceMetricsImpl persStoreMetrics; + + /** */ + private ObjectName persistenceMetricsMbeanName; + /** * @param ctx Kernal context. */ public GridCacheDatabaseSharedManager(GridKernalContext ctx) { IgniteConfiguration cfg = ctx.config(); - dbCfg = cfg.getPersistentStoreConfiguration(); + persistenceCfg = cfg.getPersistentStoreConfiguration(); - assert dbCfg != null : "PageStore should not be created if persistence is disabled."; + assert persistenceCfg != null : "PageStore should not be created if persistence is disabled."; - checkpointFreq = dbCfg.getCheckpointingFrequency(); + checkpointFreq = persistenceCfg.getCheckpointingFrequency(); - lockWaitTime = dbCfg.getLockWaitTime(); + lockWaitTime = persistenceCfg.getLockWaitTime(); final int pageSize = cfg.getMemoryConfiguration().getPageSize(); @@ -296,6 +309,12 @@ public GridCacheDatabaseSharedManager(GridKernalContext ctx) { return tmpWriteBuf; } }; + + persStoreMetrics = new PersistenceMetricsImpl( + persistenceCfg.isMetricsEnabled(), + persistenceCfg.getRateTimeInterval(), + persistenceCfg.getSubIntervals() + ); } /** @@ -339,6 +358,21 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { throw new IgniteCheckedException("Could not create directory for checkpoint metadata: " + cpDir); fileLockHolder = new FileLockHolder(storeMgr.workDir().getPath(), cctx.kernalContext(), log); + + persStoreMetrics.wal(cctx.wal()); + + try { + persistenceMetricsMbeanName = U.registerMBean( + cctx.kernalContext().config().getMBeanServer(), + cctx.kernalContext().igniteInstanceName(), + "Persistent Store", + "PersistenceMetrics", + persStoreMetrics, + PersistenceMetricsMXBean.class); + } + catch (JMException e) { + throw new IgniteCheckedException("Failed to register persistence metrics MBean", e); + } } } @@ -346,19 +380,19 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { * */ @Override public void initDataBase() throws IgniteCheckedException { - Long cpBufSize = dbCfg.getCheckpointingPageBufferSize(); + Long cpBufSize = persistenceCfg.getCheckpointingPageBufferSize(); - if (dbCfg.getCheckpointingThreads() > 1) + if (persistenceCfg.getCheckpointingThreads() > 1) asyncRunner = new ThreadPoolExecutor( - dbCfg.getCheckpointingThreads(), - dbCfg.getCheckpointingThreads(), + persistenceCfg.getCheckpointingThreads(), + persistenceCfg.getCheckpointingThreads(), 30L, TimeUnit.SECONDS, new LinkedBlockingQueue() ); // Intentionally use identity comparison to check if configuration default has changed. - // Noinspection NumberEquality. + //noinspection NumberEquality if (cpBufSize == PersistentStoreConfiguration.DFLT_CHECKPOINTING_PAGE_BUFFER_SIZE) { MemoryConfiguration memCfg = cctx.kernalContext().config().getMemoryConfiguration(); @@ -544,6 +578,18 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { fileLockHolder.close(); } + + if (persistenceMetricsMbeanName != null) { + try { + cctx.kernalContext().config().getMBeanServer().unregisterMBean(persistenceMetricsMbeanName); + } + catch (InstanceNotFoundException ignore) { + // No-op, nothing to unregister. + } + catch (MBeanRegistrationException e) { + U.error(log, "Failed to unregister persistence metrics MBean (will continue stop routine)", e); + } + } } /** {@inheritDoc} */ @@ -580,7 +626,9 @@ private long[] calculateFragmentSizes(int concLvl, long cacheSize) { MemoryPolicyConfiguration plcCfg, MemoryMetricsImpl memMetrics ) { - return new PageMemoryImpl( + memMetrics.persistenceEnabled(true); + + PageMemoryImpl pageMem = new PageMemoryImpl( memProvider, calculateFragmentSizes( memCfg.getConcurrencyLevel(), @@ -599,17 +647,22 @@ private long[] calculateFragmentSizes(int concLvl, long cacheSize) { snapshotMgr.flushDirtyPageHandler(fullId, pageBuf, tag); } }, - new GridInClosure3X() { + new GridInClosure3X() { @Override public void applyx( Long page, FullPageId fullId, PageMemoryEx pageMem ) throws IgniteCheckedException { - snapshotMgr.onChangeTrackerPage(page, fullId, pageMem); + snapshotMgr.onChangeTrackerPage(page, fullId, pageMem); } }, - this + this, + memMetrics ); + + memMetrics.pageMemory(pageMem); + + return pageMem; } /** {@inheritDoc} */ @@ -1074,8 +1127,6 @@ void cancelOrWaitPartitionDestroy(int grpId, int partId) cp.cancelOrWaitPartitionDestroy(grpId, partId); } - - /** * Tries to search for a WAL pointer for the given partition counter start. * @@ -1656,7 +1707,7 @@ private void finalizeCheckpointOnRecovery(long cpTs, UUID cpId, WALPointer walPt for (FullPageId fullId : cpPages) { tmpWriteBuf.rewind(); - Integer tag = pageMem.getForCheckpoint(fullId, tmpWriteBuf); + Integer tag = pageMem.getForCheckpoint(fullId, tmpWriteBuf, null); if (tag != null) { tmpWriteBuf.rewind(); @@ -1969,14 +2020,12 @@ private void cancelOrWaitPartitionDestroy(int grpId, int partId) */ private void doCheckpoint() { try { - long start = U.currentTimeMillis(); + CheckpointMetricsTracker tracker = new CheckpointMetricsTracker(); - Checkpoint chp = markCheckpointBegin(); + Checkpoint chp = markCheckpointBegin(tracker); snapshotMgr.onCheckPointBegin(); - long written, fsync, marked = U.currentTimeMillis(); - int pages = chp.cpPages.size(); boolean interrupted = true; @@ -1988,9 +2037,12 @@ private void doCheckpoint() { CountDownFuture doneWriteFut = new CountDownFuture( asyncRunner == null ? 1 : chp.cpPages.collectionsSize()); + tracker.onPagesWriteStart(); + if (asyncRunner != null) { for (int i = 0; i < chp.cpPages.collectionsSize(); i++) { Runnable write = new WriteCheckpointPages( + tracker, chp.cpPages.innerCollection(i), updStores, doneWriteFut @@ -2007,7 +2059,7 @@ private void doCheckpoint() { } else { // Single-threaded checkpoint. - Runnable write = new WriteCheckpointPages(chp.cpPages, updStores, doneWriteFut); + Runnable write = new WriteCheckpointPages(tracker, chp.cpPages, updStores, doneWriteFut); write.run(); } @@ -2022,7 +2074,7 @@ private void doCheckpoint() { snapshotMgr.afterCheckpointPageWritten(); - written = U.currentTimeMillis(); + tracker.onFsyncStart(); if (!skipSync) { for (PageStore updStore : updStores) { @@ -2033,8 +2085,6 @@ private void doCheckpoint() { } } - fsync = U.currentTimeMillis(); - // Must mark successful checkpoint only if there are no exceptions or interrupts. interrupted = false; } @@ -2043,7 +2093,7 @@ private void doCheckpoint() { markCheckpointEnd(chp); } - long fsyncEnd = U.currentTimeMillis(); + tracker.onEnd(); // We finished this checkpoint, now it's time to clean up partitions. PartitionDestroyQueue destroyQueue = chp.progress.destroyQueue; @@ -2073,19 +2123,30 @@ private void doCheckpoint() { finishDestroyPartitionsAsync(reqs); } - if (printCheckpointStats) - log.info(String.format("Checkpoint finished [cpId=%s, pages=%d, markPos=%s, " + - "walSegmentsCleared=%d, markBegin=%dms, pagesWrite=%dms, fsync=%dms, markEnd=%dms, " + - "total=%dms]", - chp.cpEntry.checkpointId(), - pages, - chp.cpEntry.checkpointMark(), - chp.walFilesDeleted, - marked - start, - written - marked, - fsync - written, - fsyncEnd - fsync, - fsyncEnd - start)); + if (printCheckpointStats) { + if (log.isInfoEnabled()) + log.info(String.format("Checkpoint finished [cpId=%s, pages=%d, markPos=%s, " + + "walSegmentsCleared=%d, markDuration=%dms, pagesWrite=%dms, fsync=%dms, " + + "total=%dms]", + chp.cpEntry.checkpointId(), + pages, + chp.cpEntry.checkpointMark(), + chp.walFilesDeleted, + tracker.markDuration(), + tracker.pagesWriteDuration(), + tracker.fsyncDuration(), + tracker.totalDuration())); + } + + persStoreMetrics.onCheckpoint( + tracker.lockWaitDuration(), + tracker.markDuration(), + tracker.pagesWriteDuration(), + tracker.fsyncDuration(), + tracker.totalDuration(), + pages, + tracker.dataPagesWritten(), + tracker.cowPagesWritten()); } catch (IgniteCheckedException e) { // TODO-ignite-db how to handle exception? @@ -2127,21 +2188,21 @@ private void waitCheckpointEvent() { * */ @SuppressWarnings("TooBroadScope") - private Checkpoint markCheckpointBegin() throws IgniteCheckedException { + private Checkpoint markCheckpointBegin(CheckpointMetricsTracker tracker) throws IgniteCheckedException { CheckpointRecord cpRec = new CheckpointRecord(null, false); WALPointer cpPtr; GridMultiCollectionWrapper cpPages; - long lockAcquired, lockReleased, lockStart = U.currentTimeMillis(); - final CheckpointProgress curr; + tracker.onLockWaitStart(); + checkpointLock.writeLock().lock(); try { - lockAcquired = U.currentTimeMillis(); + tracker.onMarkStart(); synchronized (this) { curr = scheduledCp; @@ -2210,7 +2271,7 @@ private Checkpoint markCheckpointBegin() throws IgniteCheckedException { finally { checkpointLock.writeLock().unlock(); - lockReleased = U.currentTimeMillis(); + tracker.onLockRelease(); } curr.cpBeginFut.onDone(); @@ -2236,8 +2297,8 @@ private Checkpoint markCheckpointBegin() throws IgniteCheckedException { "checkpointLockHoldTime=%dms, pages=%d, reason='%s']", cpRec.checkpointId(), cpPtr, - lockAcquired - lockStart, - lockReleased - lockAcquired, + tracker.lockWaitDuration(), + tracker.lockHoldDuration(), cpPages.size(), curr.reason) ); @@ -2314,6 +2375,9 @@ public void shutdownNow() { * */ private class WriteCheckpointPages implements Runnable { + /** */ + private CheckpointMetricsTracker tracker; + /** */ private Collection writePageIds; @@ -2327,10 +2391,12 @@ private class WriteCheckpointPages implements Runnable { * @param writePageIds Write page IDs. */ private WriteCheckpointPages( + CheckpointMetricsTracker tracker, Collection writePageIds, GridConcurrentHashSet updStores, CountDownFuture doneFut ) { + this.tracker = tracker; this.writePageIds = writePageIds; this.updStores = updStores; this.doneFut = doneFut; @@ -2362,11 +2428,18 @@ private WriteCheckpointPages( PageMemoryEx pageMem = (PageMemoryEx)grp.memoryPolicy().pageMemory(); - Integer tag = pageMem.getForCheckpoint(fullId, tmpWriteBuf); + Integer tag = pageMem.getForCheckpoint(fullId, tmpWriteBuf, persStoreMetrics.metricsEnabled() ? tracker : null); if (tag != null) { tmpWriteBuf.rewind(); + if (persStoreMetrics.metricsEnabled()) { + int pageType = PageIO.getType(tmpWriteBuf); + + if (PageIO.isDataPageType(pageType)) + tracker.onDataPageWritten(); + } + if (!skipCrc) { PageIO.setCrc(writeAddr, PureJavaCrc32.calcCrc32(tmpWriteBuf, pageSize())); @@ -2488,7 +2561,7 @@ public boolean needRestoreMemory() { /** * */ - public static class CheckpointProgress { + private static class CheckpointProgress { /** */ private volatile long nextCpTs; @@ -2499,13 +2572,13 @@ public static class CheckpointProgress { private GridFutureAdapter cpFinishFut = new GridFutureAdapter<>(); /** */ - public volatile boolean nextSnapshot; + private volatile boolean nextSnapshot; /** */ private volatile boolean started; /** */ - public volatile SnapshotOperation snapshotOperation; + private volatile SnapshotOperation snapshotOperation; /** Wakeup reason. */ private String reason; @@ -2629,7 +2702,7 @@ private void addCheckpointEntry(CheckpointEntry entry) { private int onCheckpointFinished() { int deleted = 0; - while (histMap.size() > dbCfg.getWalHistorySize()) { + while (histMap.size() > persistenceCfg.getWalHistorySize()) { Map.Entry entry = histMap.firstEntry(); CheckpointEntry cpEntry = entry.getValue(); @@ -2649,7 +2722,7 @@ private int onCheckpointFinished() { U.warn(log, "Failed to remove stale checkpoint files [startFile=" + startFile.getAbsolutePath() + ", endFile=" + endFile.getAbsolutePath() + ']'); - if (histMap.size() > 2 * dbCfg.getWalHistorySize()) { + if (histMap.size() > 2 * persistenceCfg.getWalHistorySize()) { U.error(log, "Too many stale checkpoint entries in the map, will truncate WAL archive anyway."); fail = false; @@ -3178,4 +3251,16 @@ private String lockPath() { return file.getAbsolutePath(); } } + + /** {@inheritDoc} */ + @Override public PersistenceMetrics persistentStoreMetrics() { + return new PersistenceMetricsSnapshot(persStoreMetrics); + } + + /** + * + */ + public PersistenceMetricsImpl persistentStoreMetricsImpl() { + return persStoreMetrics; + } } \ No newline at end of file diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsImpl.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsImpl.java new file mode 100644 index 0000000000000..25d95ae84d401 --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsImpl.java @@ -0,0 +1,297 @@ +/* + * 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.database; + +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.processors.cache.ratemetrics.HitRateMetrics; +import org.apache.ignite.mxbean.PersistenceMetricsMXBean; + +/** + * + */ +public class PersistenceMetricsImpl implements PersistenceMetricsMXBean { + /** */ + private volatile HitRateMetrics walLoggingRate; + + /** */ + private volatile HitRateMetrics walWritingRate; + + /** */ + private volatile HitRateMetrics walFsyncTimeDuration; + + /** */ + private volatile HitRateMetrics walFsyncTimeNumber; + + /** */ + private volatile long lastCpLockWaitDuration; + + /** */ + private volatile long lastCpMarkDuration; + + /** */ + private volatile long lastCpPagesWriteDuration; + + /** */ + private volatile long lastCpDuration; + + /** */ + private volatile long lastCpFsyncDuration; + + /** */ + private volatile long lastCpTotalPages; + + /** */ + private volatile long lastCpDataPages; + + /** */ + private volatile long lastCpCowPages; + + /** */ + private volatile long rateTimeInterval; + + /** */ + private volatile int subInts; + + /** */ + private volatile boolean metricsEnabled; + + /** */ + private IgniteWriteAheadLogManager wal; + + /** + * @param metricsEnabled Metrics enabled flag. + * @param rateTimeInterval Rate time interval. + * @param subInts Number of sub-intervals. + */ + public PersistenceMetricsImpl( + boolean metricsEnabled, + long rateTimeInterval, + int subInts + ) { + this.metricsEnabled = metricsEnabled; + this.rateTimeInterval = rateTimeInterval; + this.subInts = subInts; + + resetRates(); + } + + /** {@inheritDoc} */ + @Override public float getWalLoggingRate() { + if (!metricsEnabled) + return 0; + + return ((float)walLoggingRate.getRate()) / rateTimeInterval; + } + + /** {@inheritDoc} */ + @Override public float getWalWritingRate() { + if (!metricsEnabled) + return 0; + + return ((float)walWritingRate.getRate()) / rateTimeInterval; + } + + /** {@inheritDoc} */ + @Override public int getWalArchiveSegments() { + if (!metricsEnabled) + return 0; + + return wal.walArchiveSegments(); + } + + /** {@inheritDoc} */ + @Override public float getWalFsyncTimeAverage() { + if (!metricsEnabled) + return 0; + + long numRate = walFsyncTimeNumber.getRate(); + + if (numRate == 0) + return 0; + + return (float)walFsyncTimeDuration.getRate() / numRate; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointingDuration() { + if (!metricsEnabled) + return 0; + + return lastCpDuration; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointLockWaitDuration() { + if (!metricsEnabled) + return 0; + + return lastCpLockWaitDuration; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointMarkDuration() { + if (!metricsEnabled) + return 0; + + return lastCpMarkDuration; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointPagesWriteDuration() { + if (!metricsEnabled) + return 0; + + return lastCpPagesWriteDuration; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointFsyncDuration() { + if (!metricsEnabled) + return 0; + + return lastCpFsyncDuration; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointTotalPagesNumber() { + if (!metricsEnabled) + return 0; + + return lastCpTotalPages; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointDataPagesNumber() { + if (!metricsEnabled) + return 0; + + return lastCpDataPages; + } + + /** {@inheritDoc} */ + @Override public long getLastCheckpointCopiedOnWritePagesNumber() { + if (!metricsEnabled) + return 0; + + return lastCpCowPages; + } + + /** {@inheritDoc} */ + @Override public void enableMetrics() { + metricsEnabled = true; + } + + /** {@inheritDoc} */ + @Override public void disableMetrics() { + metricsEnabled = false; + } + + /** {@inheritDoc} */ + @Override public void rateTimeInterval(long rateTimeInterval) { + this.rateTimeInterval = rateTimeInterval; + + resetRates(); + } + + /** {@inheritDoc} */ + @Override public void subIntervals(int subInts) { + this.subInts = subInts; + + resetRates(); + } + + /** + * @param wal Write-ahead log manager. + */ + public void wal(IgniteWriteAheadLogManager wal) { + this.wal = wal; + } + + /** + * @return Metrics enabled flag. + */ + public boolean metricsEnabled() { + return metricsEnabled; + } + + /** + * @param lockWaitDuration Lock wait duration. + * @param markDuration Mark duration. + * @param pagesWriteDuration Pages write duration. + * @param fsyncDuration Total checkpoint fsync duration. + * @param duration Total checkpoint duration. + * @param totalPages Total number of all pages in checkpoint. + * @param dataPages Total number of data pages in checkpoint. + * @param cowPages Total number of COW-ed pages in checkpoint. + */ + public void onCheckpoint( + long lockWaitDuration, + long markDuration, + long pagesWriteDuration, + long fsyncDuration, + long duration, + long totalPages, + long dataPages, + long cowPages + ) { + if (metricsEnabled) { + lastCpLockWaitDuration = lockWaitDuration; + lastCpMarkDuration = markDuration; + lastCpPagesWriteDuration = pagesWriteDuration; + lastCpFsyncDuration = fsyncDuration; + lastCpDuration = duration; + lastCpTotalPages = totalPages; + lastCpDataPages = dataPages; + lastCpCowPages = cowPages; + } + } + + /** + * + */ + public void onWalRecordLogged() { + walLoggingRate.onHit(); + } + + /** + * @param size Size written. + */ + public void onWalBytesWritten(int size) { + walWritingRate.onHits(size); + } + + /** + * @param nanoTime Fsync nano time. + */ + public void onFsync(long nanoTime) { + long microseconds = nanoTime / 1_000; + + walFsyncTimeDuration.onHits(microseconds); + walFsyncTimeNumber.onHit(); + } + + /** + * + */ + private void resetRates() { + walLoggingRate = new HitRateMetrics((int)rateTimeInterval, subInts); + walWritingRate = new HitRateMetrics((int)rateTimeInterval, subInts); + + walFsyncTimeDuration = new HitRateMetrics((int)rateTimeInterval, subInts); + walFsyncTimeNumber = new HitRateMetrics((int)rateTimeInterval, subInts); + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/CheckpointMetricsTracker.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/CheckpointMetricsTracker.java new file mode 100644 index 0000000000000..e6b88d34f83fe --- /dev/null +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/CheckpointMetricsTracker.java @@ -0,0 +1,183 @@ +/* + * 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.database.pagemem; + +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; + +/** + * Tracks various checkpoint phases and stats. + * + * Assumed sequence of events: + *

    + *
  1. Checkpoint start
  2. + *
  3. CP Lock wait start
  4. + *
  5. CP mark start
  6. + *
  7. CP Lock release
  8. + *
  9. Pages write start
  10. + *
  11. fsync start
  12. + *
  13. Checkpoint end
  14. + *
+ */ +public class CheckpointMetricsTracker { + /** */ + private static final AtomicIntegerFieldUpdater DATA_PAGES_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(CheckpointMetricsTracker.class, "dataPages"); + + /** */ + private static final AtomicIntegerFieldUpdater COW_PAGES_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(CheckpointMetricsTracker.class, "cowPages"); + + /** */ + private volatile int dataPages; + + /** */ + private volatile int cowPages; + + /** */ + private long cpStart = System.currentTimeMillis(); + + /** */ + private long cpLockWaitStart; + + /** */ + private long cpMarkStart; + + /** */ + private long cpLockRelease; + + /** */ + private long cpPagesWriteStart; + + /** */ + private long cpFsyncStart; + + /** */ + private long cpEnd; + + /** + * + */ + public void onCowPageWritten() { + COW_PAGES_UPDATER.incrementAndGet(this); + } + + /** + * + */ + public void onDataPageWritten() { + DATA_PAGES_UPDATER.incrementAndGet(this); + } + + /** + * @return COW pages. + */ + public int cowPagesWritten() { + return cowPages; + } + + /** + * @return Data pages written. + */ + public int dataPagesWritten() { + return dataPages; + } + + /** + * + */ + public void onLockWaitStart() { + cpLockWaitStart = System.currentTimeMillis(); + } + + /** + * + */ + public void onMarkStart() { + cpMarkStart = System.currentTimeMillis(); + } + + /** + * + */ + public void onLockRelease() { + cpLockRelease = System.currentTimeMillis(); + } + + /** + * + */ + public void onPagesWriteStart() { + cpPagesWriteStart = System.currentTimeMillis(); + } + + /** + * + */ + public void onFsyncStart() { + cpFsyncStart = System.currentTimeMillis(); + } + + /** + * + */ + public void onEnd() { + cpEnd = System.currentTimeMillis(); + } + + /** + * @return Total checkpoint duration. + */ + public long totalDuration() { + return cpEnd - cpStart; + } + + /** + * @return Checkpoint lock wait duration. + */ + public long lockWaitDuration() { + return cpMarkStart - cpLockWaitStart; + } + + /** + * @return Checkpoint mark duration. + */ + public long markDuration() { + return cpPagesWriteStart - cpMarkStart; + } + + /** + * @return Checkpoint lock hold duration. + */ + public long lockHoldDuration() { + return cpLockRelease - cpMarkStart; + } + + /** + * @return Pages write duration. + */ + public long pagesWriteDuration() { + return cpFsyncStart - cpPagesWriteStart; + } + + /** + * @return Checkpoint fsync duration. + */ + public long fsyncDuration() { + return cpEnd - cpFsyncStart; + } +} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java index ef84d83a685bf..56d1be93eb638 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java @@ -116,10 +116,11 @@ void writeUnlock(int cacheId, long pageId, long page, Boolean walPlc, * @param pageId Page ID to get byte buffer for. The page ID must be present in the collection returned by * the {@link #beginCheckpoint()} method call. * @param tmpBuf Temporary buffer to write changes into. + * @param tracker Checkpoint metrics tracker. * @return {@code True} if data were read, {@code false} otherwise (data already saved to storage). * @throws IgniteException If failed to obtain page data. */ - @Nullable public Integer getForCheckpoint(FullPageId pageId, ByteBuffer tmpBuf); + @Nullable public Integer getForCheckpoint(FullPageId pageId, ByteBuffer tmpBuf, CheckpointMetricsTracker tracker); /** * Marks partition as invalid / outdated. diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java index f807229c91253..93ee4119a7194 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java @@ -55,6 +55,7 @@ import org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; import org.apache.ignite.internal.processors.cache.database.wal.crc.IgniteDataIntegrityViolationException; @@ -221,6 +222,9 @@ public class PageMemoryImpl implements PageMemoryEx { /** */ private long[] sizes; + /** */ + private MemoryMetricsImpl memMetrics; + /** * @param directMemoryProvider Memory allocator to use. * @param sharedCtx Cache shared context. @@ -235,7 +239,8 @@ public PageMemoryImpl( int pageSize, GridInClosure3X flushDirtyPage, GridInClosure3X changeTracker, - CheckpointLockStateChecker stateChecker + CheckpointLockStateChecker stateChecker, + MemoryMetricsImpl memMetrics ) { assert sharedCtx != null; @@ -257,6 +262,8 @@ public PageMemoryImpl( sysPageSize = pageSize + PAGE_OVERHEAD; rwLock = new OffheapReadWriteLock(128); + + this.memMetrics = memMetrics; } /** {@inheritDoc} */ @@ -555,6 +562,8 @@ public PageMemoryImpl( try { ByteBuffer buf = wrapPointer(pageAddr, pageSize()); + memMetrics.updatePageReplaceRate(); + storeMgr.read(cacheId, pageId, buf); } catch (IgniteDataIntegrityViolationException ignore) { @@ -769,6 +778,8 @@ private void tryToRestorePage(FullPageId fullId, long absPtr) throws IgniteCheck seg.dirtyPages = new GridConcurrentHashSet<>(); } + memMetrics.resetDirtyPages(); + return new GridMultiCollectionWrapper<>(collections); } @@ -780,7 +791,7 @@ private void tryToRestorePage(FullPageId fullId, long absPtr) throws IgniteCheck } /** {@inheritDoc} */ - @Override public Integer getForCheckpoint(FullPageId fullId, ByteBuffer tmpBuf) { + @Override public Integer getForCheckpoint(FullPageId fullId, ByteBuffer tmpBuf, CheckpointMetricsTracker tracker) { assert tmpBuf.remaining() == pageSize(); Segment seg = segment(fullId.cacheId(), fullId.pageId()); @@ -858,7 +869,7 @@ private void tryToRestorePage(FullPageId fullId, long absPtr) throws IgniteCheck } else { - copyPageForCheckpoint(absPtr, fullId, tmpBuf); + copyPageForCheckpoint(absPtr, fullId, tmpBuf, tracker); return tag; } @@ -869,7 +880,7 @@ private void tryToRestorePage(FullPageId fullId, long absPtr) throws IgniteCheck * @param fullId Full id. * @param tmpBuf Tmp buffer. */ - private void copyPageForCheckpoint(long absPtr, FullPageId fullId, ByteBuffer tmpBuf) { + private void copyPageForCheckpoint(long absPtr, FullPageId fullId, ByteBuffer tmpBuf, CheckpointMetricsTracker tracker) { assert absPtr != 0; long tmpRelPtr; @@ -907,6 +918,9 @@ private void copyPageForCheckpoint(long absPtr, FullPageId fullId, ByteBuffer tm PageHeader.dirty(tmpAbsPtr, false); + if (tracker != null) + tracker.onCowPageWritten(); + checkpointPool.releaseFreePage(tmpRelPtr); // We pinned the page when allocated the temp buffer, release it now. @@ -1264,11 +1278,19 @@ void setDirty(FullPageId pageId, long absPtr, boolean dirty, boolean forceAdd) { boolean wasDirty = PageHeader.dirty(absPtr, dirty); if (dirty) { - if (!wasDirty || forceAdd) - segment(pageId.cacheId(), pageId.pageId()).dirtyPages.add(pageId); + if (!wasDirty || forceAdd) { + boolean added = segment(pageId.cacheId(), pageId.pageId()).dirtyPages.add(pageId); + + if (added) + memMetrics.incrementDirtyPages(); + } + } + else { + boolean rmv = segment(pageId.cacheId(), pageId.pageId()).dirtyPages.remove(pageId); + + if (rmv) + memMetrics.decrementDirtyPages(); } - else - segment(pageId.cacheId(), pageId.pageId()).dirtyPages.remove(pageId); } /** diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java index 8a113babb28b6..3113c3ea77221 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -55,6 +55,8 @@ import org.apache.ignite.internal.pagemem.wal.record.WALRecord; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; +import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.PersistenceMetricsImpl; import org.apache.ignite.internal.processors.cache.database.wal.record.HeaderRecord; import org.apache.ignite.internal.processors.cache.database.wal.serializer.RecordV1Serializer; import org.apache.ignite.internal.util.GridCloseableIteratorAdapter; @@ -138,6 +140,9 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl /** */ private IgniteConfiguration igCfg; + /** Persistence metrics tracker. */ + private PersistenceMetricsImpl metrics; + /** */ private File walWorkDir; @@ -147,6 +152,9 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl /** Current log segment handle */ private volatile FileWriteHandle currentHnd; + /** */ + private volatile long oldestArchiveSegmentIdx; + /** Updater for {@link #currentHnd}, used for verify there are no concurrent update for current log segment handle */ private static final AtomicReferenceFieldUpdater currentHndUpd = AtomicReferenceFieldUpdater.newUpdater(FileWriteAheadLogManager.class, FileWriteHandle.class, "currentHnd"); @@ -215,9 +223,17 @@ public FileWriteAheadLogManager(GridKernalContext ctx) { serializer = new RecordV1Serializer(cctx); + GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)cctx.database(); + + metrics = dbMgr.persistentStoreMetricsImpl(); + checkOrPrepareFiles(); - archiver = new FileArchiver(); + IgniteBiTuple tup = scanMinMaxArchiveIndices(); + + oldestArchiveSegmentIdx = tup == null ? 0 : tup.get1(); + + archiver = new FileArchiver(tup == null ? -1 : tup.get2()); if (mode != Mode.DEFAULT) { if (log.isInfoEnabled()) @@ -279,13 +295,13 @@ protected String consistentId() { /** {@inheritDoc} */ @Override public void onActivate(GridKernalContext kctx) throws IgniteCheckedException { if (log.isDebugEnabled()) - log.debug("Activate file write ahead log [nodeId=" + cctx.localNodeId() + + log.debug("Activated file write ahead log manager [nodeId=" + cctx.localNodeId() + " topVer=" + cctx.discovery().topologyVersionEx() + " ]"); start0(); if (!cctx.kernalContext().clientNode()) { - archiver = new FileArchiver(); + assert archiver != null; archiver.start(); } @@ -361,6 +377,8 @@ protected String consistentId() { WALPointer ptr = current.addRecord(record); if (ptr != null) { + metrics.onWalRecordLogged(); + lastWALPtr.set(ptr); return ptr; @@ -451,6 +469,10 @@ protected String consistentId() { archiver0.release(((FileWALPointer)start).index()); } + /** + * @param absIdx Absolulte index to check. + * @return {@code true} if has this index. + */ private boolean hasIndex(long absIdx) { String name = FileDescriptor.fileName(absIdx); @@ -459,7 +481,7 @@ private boolean hasIndex(long absIdx) { if (inArchive) return true; - if (absIdx <= archiver.lastArchivedIndex()) + if (absIdx <= lastArchivedIndex()) return false; FileWriteHandle cur = currentHnd; @@ -494,12 +516,30 @@ private boolean hasIndex(long absIdx) { desc.file.getAbsolutePath()); else deleted++; + + // Bump up the oldest archive segment index. + if (oldestArchiveSegmentIdx < desc.idx) + oldestArchiveSegmentIdx = desc.idx; } } return deleted; } + /** {@inheritDoc} */ + @Override public int walArchiveSegments() { + long oldest = oldestArchiveSegmentIdx; + + long lastArchived = archiver.lastArchivedAbsoluteIndex(); + + if (lastArchived == -1) + return 0; + + int res = (int)(lastArchived - oldest); + + return res >= 0 ? res : 0; + } + /** {@inheritDoc} */ @Override public boolean reserved(WALPointer ptr) { FileWALPointer fPtr = (FileWALPointer)ptr; @@ -509,6 +549,52 @@ private boolean hasIndex(long absIdx) { return archiver0 != null && archiver0.reserved(fPtr.index()); } + /** + * Lists files in archive directory and returns the index of last archived file. + * + * @return The absolute index of last archived file. + */ + private long lastArchivedIndex() { + long lastIdx = -1; + + for (File file : walArchiveDir.listFiles(WAL_SEGMENT_FILE_FILTER)) { + try { + long idx = Long.parseLong(file.getName().substring(0, 16)); + + lastIdx = Math.max(lastIdx, idx); + } + catch (NumberFormatException | IndexOutOfBoundsException ignore) { + + } + } + + return lastIdx; + } + + /** + * Lists files in archive directory and returns the index of last archived file. + * + * @return The absolute index of last archived file. + */ + private IgniteBiTuple scanMinMaxArchiveIndices() { + long minIdx = Integer.MAX_VALUE; + long maxIdx = -1; + + for (File file : walArchiveDir.listFiles(WAL_SEGMENT_FILE_FILTER)) { + try { + long idx = Long.parseLong(file.getName().substring(0, 16)); + + minIdx = Math.min(minIdx, idx); + maxIdx = Math.max(maxIdx, idx); + } + catch (NumberFormatException | IndexOutOfBoundsException ignore) { + + } + } + + return maxIdx == -1 ? null : F.t(minIdx, maxIdx); + } + /** * Creates a directory specified by the given arguments. * @@ -863,10 +949,17 @@ private class FileArchiver extends Thread { /** * */ - private FileArchiver() { + private FileArchiver(long lastAbsArchivedIdx) { super("wal-file-archiver%" + cctx.igniteInstanceName()); - lastAbsArchivedIdx = lastArchivedIndex(); + this.lastAbsArchivedIdx = lastAbsArchivedIdx; + } + + /** + * @return Last archived segment absolute index. + */ + private synchronized long lastArchivedAbsoluteIndex() { + return lastAbsArchivedIdx; } /** @@ -1127,28 +1220,6 @@ private File archiveSegment(long absIdx) throws IgniteCheckedException { return origFile; } - /** - * Lists files in archive directory and returns the index of last archived file. - * - * @return The absolute index of last archived file. - */ - private int lastArchivedIndex() { - int lastIdx = -1; - - for (File file : walArchiveDir.listFiles(WAL_SEGMENT_FILE_FILTER)) { - try { - int idx = Integer.parseInt(file.getName().substring(0, 16)); - - lastIdx = Math.max(lastIdx, idx); - } - catch (NumberFormatException | IndexOutOfBoundsException ignore) { - - } - } - - return lastIdx; - } - /** * */ @@ -1751,6 +1822,10 @@ private void fsync(FileWALPointer ptr) throws StorageException, IgniteCheckedExc if (lastFsyncPos != written) { assert lastFsyncPos < written; // Fsync position must be behind. + boolean metricsEnabled = metrics.metricsEnabled(); + + long start = metricsEnabled ? System.nanoTime() : 0; + try { ch.force(false); } @@ -1762,6 +1837,11 @@ private void fsync(FileWALPointer ptr) throws StorageException, IgniteCheckedExc if (fsyncDelayNanos > 0) fsync.signalAll(); + + long end = metricsEnabled ? System.nanoTime() : 0; + + if (metricsEnabled) + metrics.onFsync(end - start); } } finally { @@ -1908,6 +1988,8 @@ private void writeBuffer(long pos, ByteBuffer buf) throws StorageException, Igni written += size; + metrics.onWalBytesWritten(size); + assert written == ch.position(); } catch (IOException e) { diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistenceMetricsSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistenceMetricsSelfTest.java new file mode 100644 index 0000000000000..fc25509290f62 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistenceMetricsSelfTest.java @@ -0,0 +1,236 @@ +/* + * 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.cache.database; + +import java.io.Serializable; +import java.util.Objects; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.MemoryMetrics; +import org.apache.ignite.PersistenceMetrics; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.MemoryConfiguration; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.PAX; +import org.apache.ignite.internal.util.typedef.internal.S; +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.CacheMode.PARTITIONED; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; + +/** + * + */ +public class IgnitePersistenceMetricsSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final String GROUP1 = "grp1"; + + /** */ + private boolean activeOnStart = true; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); + + GridTestUtils.deleteDbFiles(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + GridTestUtils.deleteDbFiles(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setConsistentId(gridName); + + cfg.setActiveOnStart(activeOnStart); + + MemoryConfiguration memCfg = new MemoryConfiguration(); + memCfg.setPageSize(1024); + + memCfg.setDefaultMemoryPolicyName("dflt-plc"); + + MemoryPolicyConfiguration memPlc = new MemoryPolicyConfiguration(); + memPlc.setName("dflt-plc"); + memPlc.setMaxSize(10 * 1024 * 1024); + memPlc.setMetricsEnabled(true); + + memCfg.setMemoryPolicies(memPlc); + + cfg.setMemoryConfiguration(memCfg); + + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration().setMetricsEnabled(true)); + + cfg.setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(false)); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER); + + cfg.setCacheConfiguration(cacheConfiguration(GROUP1, "cache", PARTITIONED, ATOMIC, 1)); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + GridTestUtils.deleteDbFiles(); + + super.afterTest(); + } + + /** + * @param grpName Cache group name. + * @param name Cache name. + * @param cacheMode Cache mode. + * @param atomicityMode Atomicity mode. + * @param backups Backups number. + * @return Cache configuration. + */ + private CacheConfiguration cacheConfiguration( + String grpName, + String name, + CacheMode cacheMode, + CacheAtomicityMode atomicityMode, + int backups + ) { + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setName(name); + ccfg.setGroupName(grpName); + ccfg.setAtomicityMode(atomicityMode); + ccfg.setBackups(backups); + ccfg.setCacheMode(cacheMode); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + + return ccfg; + } + + /** + * @throws Exception if failed. + */ + public void testPersistenceMetrics() throws Exception { + final IgniteEx ig = startGrid(0); + + try { + IgniteCache cache = ig.cache("cache"); + + for (int i = 0; i < 10; i++) + cache.put(i, new Person("first-" + i, "last-" + i)); + + { + MemoryMetrics memMetrics = ig.memoryMetrics("dflt-plc"); + + assertNotNull(memMetrics); + assertTrue(memMetrics.getDirtyPages() > 0); + } + + ig.context().cache().context().database().waitForCheckpoint("test"); + + GridTestUtils.waitForCondition(new PAX() { + @Override public boolean applyx() { + PersistenceMetrics pMetrics = ig.persistentStoreMetrics(); + + assertNotNull(pMetrics); + + return pMetrics.getLastCheckpointTotalPagesNumber() != 0 && + pMetrics.getLastCheckpointDataPagesNumber() != 0; + } + }, 5_000); + } + finally { + stopAllGrids(); + } + } + + /** + * + */ + static class Person implements Serializable { + /** */ + @GridToStringInclude + @QuerySqlField(index = true, groups = "full_name") + private String fName; + + /** */ + @GridToStringInclude + @QuerySqlField(index = true, groups = "full_name") + private String lName; + + /** + * @param fName First name. + * @param lName Last name. + */ + public Person(String fName, String lName) { + this.fName = fName; + this.lName = lName; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(Person.class, this); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + Person person = (Person)o; + + return Objects.equals(fName, person.fName) && + Objects.equals(lName, person.lName); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return Objects.hash(fName, lName); + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java index fd73204c87be6..e10acab0363d2 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java @@ -294,7 +294,7 @@ private void generateWal( if (pageIds.contains(fullId)) { long cpStart = System.nanoTime(); - Integer tag = mem.getForCheckpoint(fullId, tmpBuf); + Integer tag = mem.getForCheckpoint(fullId, tmpBuf, null); if (tag == null) continue; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java index f4445053f01a0..0addcb3e8ff25 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java @@ -602,7 +602,7 @@ public void testDirtyFlag() throws Exception { buf.rewind(); - mem.getForCheckpoint(fullId, buf); + mem.getForCheckpoint(fullId, buf, null); buf.position(PageIO.COMMON_HEADER_END); @@ -887,7 +887,7 @@ private IgniteBiTuple, WALPointer> runCheckpointing( for (FullPageId fullId : pageIds) { long cpStart = System.nanoTime(); - Integer tag = mem.getForCheckpoint(fullId, tmpBuf); + Integer tag = mem.getForCheckpoint(fullId, tmpBuf, null); if (tag == null) continue; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java index 4cfc14f4fdd23..b533ed1367ba0 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.cache.database.pagemem; import java.nio.ByteBuffer; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.mem.DirectMemoryProvider; import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; import org.apache.ignite.internal.pagemem.FullPageId; @@ -25,6 +26,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; @@ -96,7 +98,9 @@ public class BPlusTreeReuseListPageMemoryImplSelfTest extends BPlusTreeReuseSelf @Override public boolean checkpointLockIsHeldByThread() { return true; } - }); + }, + new MemoryMetricsImpl(new MemoryPolicyConfiguration()) + ); mem.start(); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java index 82b2de4b89f91..1eab1f884c5b7 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.cache.database.pagemem; import java.nio.ByteBuffer; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.mem.DirectMemoryProvider; import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; import org.apache.ignite.internal.pagemem.FullPageId; @@ -25,6 +26,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; @@ -96,7 +98,8 @@ public class BPlusTreeSelfTestPageMemoryImplSelfTest extends BPlusTreeSelfTest { @Override public boolean checkpointLockIsHeldByThread() { return true; } - }); + }, + new MemoryMetricsImpl(new MemoryPolicyConfiguration())); mem.start(); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java index 11e03868c2383..c9c6c18039e35 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java @@ -19,6 +19,7 @@ import java.io.File; import java.nio.ByteBuffer; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.mem.DirectMemoryProvider; import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider; import org.apache.ignite.internal.pagemem.FullPageId; @@ -26,6 +27,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; import org.apache.ignite.internal.processors.database.MetadataStorageSelfTest; @@ -96,6 +98,7 @@ public class MetadataStoragePageMemoryImplSelfTest extends MetadataStorageSelfTe @Override public boolean checkpointLockIsHeldByThread() { return true; } - }); + }, + new MemoryMetricsImpl(new MemoryPolicyConfiguration())); } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java index fec5b081e2b5e..f3e1cd39b43dd 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java @@ -120,4 +120,9 @@ public class NoOpWALManager implements IgniteWriteAheadLogManager { @Override public void onDeActivate(GridKernalContext kctx) throws IgniteCheckedException { } + + /** {@inheritDoc} */ + @Override public int walArchiveSegments() { + return 0; + } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java index 141ce82f1ef1c..8ff5345e03164 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java @@ -19,6 +19,7 @@ import java.io.File; import java.nio.ByteBuffer; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.mem.DirectMemoryProvider; import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider; import org.apache.ignite.internal.pagemem.FullPageId; @@ -26,6 +27,7 @@ import org.apache.ignite.internal.pagemem.impl.PageMemoryNoLoadSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; import org.apache.ignite.internal.util.lang.GridInClosure3X; @@ -87,7 +89,8 @@ public class PageMemoryImplNoLoadSelfTest extends PageMemoryNoLoadSelfTest { @Override public boolean checkpointLockIsHeldByThread() { return true; } - }); + }, + new MemoryMetricsImpl(new MemoryPolicyConfiguration())); } /** {@inheritDoc} */ diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java index bbcd383c32854..b5e4549a6acb5 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.cache.database.pagemem; import java.nio.ByteBuffer; +import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.mem.DirectMemoryProvider; import org.apache.ignite.internal.mem.IgniteOutOfMemoryException; import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; @@ -26,6 +27,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; import org.apache.ignite.internal.util.lang.GridInClosure3X; @@ -109,7 +111,8 @@ private PageMemoryImpl createPageMemory() throws Exception { @Override public boolean checkpointLockIsHeldByThread() { return true; } - }); + }, + new MemoryMetricsImpl(new MemoryPolicyConfiguration())); mem.start(); diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java index 88d4d0d6a3cca..1f45c25dc2560 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java @@ -18,6 +18,7 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; +import org.apache.ignite.cache.database.IgnitePersistenceMetricsSelfTest; import org.apache.ignite.cache.database.IgnitePersistentStoreAtomicCacheRebalancingTest; import org.apache.ignite.cache.database.IgnitePersistentStoreContinuousRestartSelfTest; import org.apache.ignite.cache.database.IgnitePersistentStoreDataStructuresTest; @@ -34,6 +35,7 @@ import org.apache.ignite.cache.database.db.file.IgniteWalRecoverySelfTest; import org.apache.ignite.cache.database.db.file.WalRecoveryTxLogicalRecordsTest; import org.apache.ignite.cache.database.db.wal.crc.IgniteDataIntegrityTests; +import org.apache.ignite.internal.pagemem.impl.PageMemoryNoLoadSelfTest; /** * @@ -46,11 +48,14 @@ public class IgnitePdsTestSuite2 extends TestSuite { public static TestSuite suite() throws Exception { TestSuite suite = new TestSuite("Ignite persistent Store Test Suite"); - // Integrity test + // Integrity test. suite.addTestSuite(IgniteDataIntegrityTests.class); suite.addTestSuite(IgnitePersistentStoreRecoveryAfterFileCorruptionTest.class); suite.addTestSuite(IgnitePersistentStorePageSizesTest.class); + // Metrics test. + suite.addTestSuite(IgnitePersistenceMetricsSelfTest.class); + // WAL recovery test. suite.addTestSuite(WalRecoveryTxLogicalRecordsTest.class); suite.addTestSuite(IgniteWalRecoverySelfTest.class); diff --git a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java index 094c2dcdda53b..ba4811ca2d3d3 100644 --- a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java +++ b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java @@ -285,6 +285,13 @@ public ApplicationContext getApplicationContext() throws BeansException { return g.memoryMetrics(memPlcName); } + /** {@inheritDoc} */ + @Override public PersistenceMetrics persistentStoreMetrics() { + checkIgnite(); + + return g.persistentStoreMetrics(); + } + /** {@inheritDoc} */ @Override public IgniteCache cache(@Nullable String name) { checkIgnite(); From 518238473c0a12380cb9ed96c67597d1fe42652c Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Wed, 7 Jun 2017 21:08:36 +0300 Subject: [PATCH 239/311] Merged 4.ea2 into 5267 --- assembly/release-fabric-base.xml | 1 + examples/pom-standalone-lgpl.xml | 19 - examples/pom-standalone.xml | 19 - examples/pom.xml | 30 - .../apache/ignite/IgniteSystemProperties.java | 6 + .../RendezvousAffinityFunction.java | 1 - .../org/apache/ignite/internal/GridTopic.java | 6 +- .../internal/IgniteDiagnosticAware.java | 28 + .../internal/IgniteDiagnosticMessage.java | 490 ++++++++++++++ .../apache/ignite/internal/IgniteKernal.java | 46 +- .../managers/communication/GridIoManager.java | 2 +- .../communication/GridIoMessageFactory.java | 6 + .../pagemem/snapshot/SnapshotOperation.java | 4 +- .../snapshot/SnapshotOperationType.java | 2 + ...tSnapshotOperationAckDiscoveryMessage.java | 8 + .../pagemem/wal/record/CacheState.java | 133 ++-- .../wal/record/delta/MetaPageInitRecord.java | 6 +- .../cache/DynamicCacheChangeBatch.java | 37 ++ .../cache/DynamicCacheChangeRequest.java | 11 +- .../processors/cache/GridCacheGateway.java | 5 +- .../processors/cache/GridCacheIoManager.java | 41 ++ .../GridCachePartitionExchangeManager.java | 49 +- .../processors/cache/GridCacheProcessor.java | 27 +- .../IgniteCacheDatabaseSharedManager.java | 7 + .../cache/database/freelist/PagesList.java | 57 +- .../cache/database/tree/BPlusTree.java | 11 +- .../cache/database/tree/io/PageMetaIO.java | 7 +- .../database/tree/io/PagePartitionMetaIO.java | 28 +- .../dht/GridClientPartitionTopology.java | 14 +- .../distributed/dht/GridDhtCacheEntry.java | 6 +- .../dht/GridDhtLocalPartition.java | 2 +- .../dht/GridDhtPartitionTopology.java | 6 + .../dht/GridDhtPartitionTopologyImpl.java | 501 ++++++++------ .../dht/GridDhtTxPrepareFuture.java | 30 +- .../dht/GridPartitionedSingleGetFuture.java | 24 +- .../colocated/GridDhtColocatedLockFuture.java | 49 +- .../dht/preloader/GridDhtPartitionMap.java | 23 +- .../GridDhtPartitionsExchangeFuture.java | 214 +++--- .../dht/preloader/GridDhtPreloader.java | 27 +- .../processors/cluster/ClusterProcessor.java | 354 ++++++++++ .../DataStructuresProcessor.java | 22 +- .../internal/util/GridPartitionStateMap.java | 174 +++++ .../ignite/internal/util/IgniteUtils.java | 12 + .../internal/util/OffheapReadWriteLock.java | 4 + .../internal/util/nio/GridNioServer.java | 246 +++++-- .../tcp/TcpCommunicationSpi.java | 152 +++-- .../resources/META-INF/classnames.properties | 29 + ...nosticMessagesMultipleConnectionsTest.java | 35 + .../IgniteDiagnosticMessagesTest.java | 152 +++++ .../CacheClientsConcurrentStartTest.java | 250 +++++++ ...CacheNearOnlyMultiNodeFullApiSelfTest.java | 4 +- .../junits/GridAbstractTest.java | 7 + .../testsuites/IgniteCacheTestSuite.java | 4 + .../query/h2/database/H2TreeIndex.java | 10 +- .../GridCacheDatabaseSharedManager.java | 610 ++++++------------ .../database/GridCacheOffheapManager.java | 30 +- .../database/pagemem/PageMemoryImpl.java | 14 +- .../cache/database/wal/FileWALPointer.java | 22 + .../wal/FileWriteAheadLogManager.java | 21 +- .../wal/serializer/RecordV1Serializer.java | 14 +- .../IgniteWalHistoryReservationsSelfTest.java | 1 - .../yardstick/IgniteBenchmarkArguments.java | 33 + 62 files changed, 3122 insertions(+), 1061 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticAware.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticMessage.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/util/GridPartitionStateMap.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/managers/IgniteDiagnosticMessagesMultipleConnectionsTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/managers/IgniteDiagnosticMessagesTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheClientsConcurrentStartTest.java diff --git a/assembly/release-fabric-base.xml b/assembly/release-fabric-base.xml index 5007785bb2a58..7484dfa9505c2 100644 --- a/assembly/release-fabric-base.xml +++ b/assembly/release-fabric-base.xml @@ -239,6 +239,7 @@ **/package.html src/test/** + src/main/ml/** diff --git a/examples/pom-standalone-lgpl.xml b/examples/pom-standalone-lgpl.xml index 4798d0335a728..e7eca1ecf960c 100644 --- a/examples/pom-standalone-lgpl.xml +++ b/examples/pom-standalone-lgpl.xml @@ -33,7 +33,6 @@ src/main/java src/main/java src/main/java - src/main/java 1.7 @@ -105,23 +104,6 @@ - - ml - - - src/main/ml - 1.8 - - - - - org.apache.ignite - ignite-ml - to_be_replaced_by_ignite_version - - - - scala @@ -248,7 +230,6 @@ ${lgpl.folder} ${java8.folder} ${spark.folder} - ${ml.folder} diff --git a/examples/pom-standalone.xml b/examples/pom-standalone.xml index e74082c2f4a5c..65b5402491b0e 100644 --- a/examples/pom-standalone.xml +++ b/examples/pom-standalone.xml @@ -33,7 +33,6 @@ src/main/java src/main/java src/main/java - src/main/java 1.7 @@ -105,23 +104,6 @@ - - ml - - - src/main/ml - 1.8 - - - - - org.apache.ignite - ignite-ml - to_be_replaced_by_ignite_version - - - - scala @@ -249,7 +231,6 @@ ${lgpl.folder} ${java8.folder} ${spark.folder} - ${ml.folder} diff --git a/examples/pom.xml b/examples/pom.xml index 47682700ab0b2..f749d7cb7a170 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -107,7 +107,6 @@ src/main/java src/main/java src/main/java - src/main/java src/test/java src/test/java src/test/java @@ -241,34 +240,6 @@ - - ml - - - src/main/ml - - - - - - maven-compiler-plugin - - 1.8 - 1.8 - - - - - - - - org.apache.ignite - ignite-ml - ${project.version} - - - - lgpl @@ -328,7 +299,6 @@ ${lgpl.folder} ${java8.folder} ${spark.folder} - ${ml.folder} 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 860617543bbba..3eec36185d857 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -448,6 +448,12 @@ public final class IgniteSystemProperties { /** If this property is set to {@code true} then Ignite will log thread dump in case of partition exchange timeout. */ public static final String IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT = "IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT"; + /** */ + public static final String IGNITE_IO_DUMP_ON_TIMEOUT = "IGNITE_IO_DUMP_ON_TIMEOUT"; + + /** */ + public static final String IGNITE_DIAGNOSTIC_ENABLED = "IGNITE_DIAGNOSTIC_ENABLED"; + /** Cache operations that take more time than value of this property will be output to log. Set to {@code 0} to disable. */ public static final String IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT = "IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT"; diff --git a/modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/RendezvousAffinityFunction.java b/modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/RendezvousAffinityFunction.java index f673e9c628db3..1bd0587c3b8a2 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/RendezvousAffinityFunction.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/RendezvousAffinityFunction.java @@ -163,7 +163,6 @@ public RendezvousAffinityFunction(int parts, @Nullable IgniteBiPredicate backupFilter) { A.ensure(parts > 0, "parts > 0"); - A.ensure(parts <= CacheConfiguration.MAX_PARTITIONS_COUNT, "parts <=" + CacheConfiguration.MAX_PARTITIONS_COUNT); this.exclNeighbors = exclNeighbors; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java b/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java index c38299923d2fe..abdbf956017f4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java @@ -96,6 +96,7 @@ public enum GridTopic { /** */ TOPIC_TX, + /** */ TOPIC_SNAPSHOT, /** */ @@ -111,7 +112,10 @@ public enum GridTopic { TOPIC_METADATA_REQ, /** */ - TOPIC_SCHEMA; + TOPIC_SCHEMA, + + /** */ + TOPIC_INTERNAL_DIAGNOSTIC; /** Enum values. */ private static final GridTopic[] VALS = values(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticAware.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticAware.java new file mode 100644 index 0000000000000..f41c178e184dc --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticAware.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * + */ +public interface IgniteDiagnosticAware { + /** + * + */ + public void dumpDiagnosticInfo(); +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticMessage.java new file mode 100644 index 0000000000000..4b2880612ab42 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticMessage.java @@ -0,0 +1,490 @@ +/* + * 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; + +import java.nio.ByteBuffer; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.UUID; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; +import org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; +import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.util.future.GridFinishedFuture; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteClosure; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageWriter; +import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; + +/** + * + */ +public class IgniteDiagnosticMessage implements Message { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private static final ThreadLocal dateFormat = new ThreadLocal() { + @Override protected DateFormat initialValue() { + return new SimpleDateFormat("HH:mm:ss.SSS"); + } + }; + + /** */ + private long futId; + + /** */ + private String msg; + + /** */ + private byte[] cBytes; + + /** + * Required by {@link GridIoMessageFactory}. + */ + public IgniteDiagnosticMessage() { + // No-op. + } + + /** + * @param ctx Context. + * @param c Closure to run. + * @param futId Future ID. + * @return Request message. + * @throws IgniteCheckedException If failed. + */ + public static IgniteDiagnosticMessage createRequest(GridKernalContext ctx, + IgniteClosure c, + long futId) + throws IgniteCheckedException + { + byte[] cBytes = U.marshal(ctx.config().getMarshaller(), c); + + IgniteDiagnosticMessage msg = new IgniteDiagnosticMessage(); + + msg.futId = futId; + msg.cBytes = cBytes; + + return msg; + } + + /** + * @param msg0 Message. + * @param futId Future ID. + * @return Response message. + */ + public static IgniteDiagnosticMessage createResponse(String msg0, long futId) { + IgniteDiagnosticMessage msg = new IgniteDiagnosticMessage(); + + msg.futId = futId; + msg.msg = msg0; + + return msg; + } + + /** + * @param ctx Context. + * @return Unmarshalled closure. + * @throws IgniteCheckedException If failed. + */ + public IgniteClosure unmarshalClosure(GridKernalContext ctx) + throws IgniteCheckedException { + assert cBytes != null; + + return U.unmarshal(ctx, cBytes, null); + } + + /** + * @return Future ID. + */ + public long futureId() { + return futId; + } + + /** + * @return {@code True} if this is request message. + */ + public boolean request() { + return cBytes != null; + } + + /** + * @return Message string. + */ + public String message() { + return msg; + } + + /** {@inheritDoc} */ + @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) { + writer.setBuffer(buf); + + if (!writer.isHeaderWritten()) { + if (!writer.writeHeader(directType(), fieldsCount())) + return false; + + writer.onHeaderWritten(); + } + + switch (writer.state()) { + case 0: + if (!writer.writeByteArray("cBytes", cBytes)) + return false; + + writer.incrementState(); + + case 1: + if (!writer.writeLong("futId", futId)) + return false; + + writer.incrementState(); + + case 2: + if (!writer.writeString("msg", msg)) + return false; + + writer.incrementState(); + + } + + return true; + } + + /** {@inheritDoc} */ + @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) { + reader.setBuffer(buf); + + if (!reader.beforeMessageRead()) + return false; + + switch (reader.state()) { + case 0: + cBytes = reader.readByteArray("cBytes"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 1: + futId = reader.readLong("futId"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 2: + msg = reader.readString("msg"); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + } + + return reader.afterMessageRead(IgniteDiagnosticMessage.class); + } + + /** {@inheritDoc} */ + @Override public short directType() { + return -61; + } + + /** {@inheritDoc} */ + @Override public byte fieldsCount() { + return 3; + } + + /** {@inheritDoc} */ + @Override public void onAckReceived() { + // No-op. + } + + /** + * + */ + public static class BaseClosure implements IgniteClosure { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + protected final UUID nodeId; + + /** + * @param ctx Local node context. + */ + public BaseClosure(GridKernalContext ctx) { + this.nodeId = ctx.localNodeId(); + } + + /** {@inheritDoc} */ + @Override public final String apply(GridKernalContext ctx) { + try { + StringBuilder sb = new StringBuilder(); + + IgniteInternalFuture commInfo = dumpCommunicationInfo(ctx, nodeId); + + sb.append(dumpNodeBasicInfo(ctx)); + + sb.append(U.nl()).append(dumpExchangeInfo(ctx)); + + String moreInfo = dumpInfo(ctx); + + sb.append(U.nl()).append(commInfo.get()); + + if (moreInfo != null) + sb.append(U.nl()).append(moreInfo); + + return sb.toString(); + } + catch (Exception e) { + ctx.cluster().diagnosticLog().error("Failed to execute diagnostic message closure: " + e, e); + + return "Failed to execute diagnostic message closure: " + e; + } + } + + /** + * @param ctx Context. + * @return Message. + */ + protected String dumpInfo(GridKernalContext ctx) { + return null; + } + } + + /** + * + */ + public static class TxEntriesInfoClosure extends BaseClosure { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final int cacheId; + + /** */ + private final Collection keys; + + /** + * @param ctx Context. + * @param cacheId Cache ID. + * @param keys Keys. + */ + public TxEntriesInfoClosure(GridKernalContext ctx, int cacheId, Collection keys) { + super(ctx); + + this.cacheId = cacheId; + this.keys = keys; + } + + /** {@inheritDoc} */ + @Override protected String dumpInfo(GridKernalContext ctx) { + GridCacheContext cctx = ctx.cache().context().cacheContext(cacheId); + + if (cctx == null) + return "Failed to find cache with id: " + cacheId; + + try { + for (KeyCacheObject key : keys) + key.finishUnmarshal(cctx.cacheObjectContext(), null); + } + catch (IgniteCheckedException e) { + ctx.cluster().diagnosticLog().error("Failed to unmarshal key: " + e, e); + + return "Failed to unmarshal key: " + e; + } + + StringBuilder sb = new StringBuilder("Cache entries [cacheId=" + cacheId + ", cacheName=" + cctx.name() + "]: "); + + for (KeyCacheObject key : keys) { + sb.append(U.nl()); + + GridCacheMapEntry e = (GridCacheMapEntry)cctx.cache().peekEx(key); + + sb.append("Key [key=").append(key).append(", entry=").append(e).append("]"); + } + + return sb.toString(); + } + } + + /** + * + */ + public static class ExchangeInfoClosure extends BaseClosure { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final AffinityTopologyVersion topVer; + + /** + * @param ctx Context. + * @param topVer Exchange version. + */ + public ExchangeInfoClosure(GridKernalContext ctx, AffinityTopologyVersion topVer) { + super(ctx); + + this.topVer = topVer; + } + + /** {@inheritDoc} */ + @Override protected String dumpInfo(GridKernalContext ctx) { + List futs = ctx.cache().context().exchange().exchangeFutures(); + + for (GridDhtPartitionsExchangeFuture fut : futs) { + if (topVer.equals(fut.topologyVersion())) + return "Exchange future: " + fut; + } + + return "Failed to find exchange future: " + topVer; + } + } + + /** + * + */ + public static class TxInfoClosure extends BaseClosure { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final GridCacheVersion dhtVer; + + /** */ + private final GridCacheVersion nearVer; + + /** + * @param ctx Context. + * @param dhtVer Tx dht version. + * @param nearVer Tx near version. + */ + public TxInfoClosure(GridKernalContext ctx, + GridCacheVersion dhtVer, + GridCacheVersion nearVer) { + super(ctx); + + this.dhtVer = dhtVer; + this.nearVer = nearVer; + } + + /** {@inheritDoc} */ + @Override protected String dumpInfo(GridKernalContext ctx) { + StringBuilder b = new StringBuilder(); + + b.append("Related transactions [dhtVer=").append(dhtVer). + append(", nearVer=").append(nearVer).append("]: "); + + boolean found = false; + + for (IgniteInternalTx tx : ctx.cache().context().tm().activeTransactions()) { + if (dhtVer.equals(tx.xidVersion()) || nearVer.equals(tx.nearXidVersion())) { + found = true; + + b.append(U.nl()); + b.append("Found related ttx [ver=").append(tx.xidVersion()). + append(", nearVer=").append(tx.nearXidVersion()). + append(", topVer=").append(tx.topologyVersion()). + append(", state=").append(tx.state()). + append(", fullTx=").append(tx). + append("]"); + } + } + + if (!found) { + b.append(U.nl()); + b.append("Failed to find related transactions."); + } + + return b.toString(); + } + } + + /** + * @param ctx Context. + * @return Node information string. + */ + static String dumpNodeBasicInfo(GridKernalContext ctx) { + StringBuilder sb = new StringBuilder("General node info [id=").append(ctx.localNodeId()); + + sb.append(", client=").append(ctx.clientNode()); + sb.append(", discoTopVer=").append(ctx.discovery().topologyVersionEx()); + sb.append(", time=").append(formatTime(U.currentTimeMillis())); + + sb.append(']'); + + return sb.toString(); + } + + /** + * @param ctx Context. + * @return Exchange information string. + */ + static String dumpExchangeInfo(GridKernalContext ctx) { + GridCachePartitionExchangeManager exchMgr = ctx.cache().context().exchange(); + + StringBuilder sb = new StringBuilder("Partitions exchange info [readyVer=").append(exchMgr.readyAffinityVersion()); + sb.append("]"); + + GridDhtTopologyFuture fut = exchMgr.lastTopologyFuture(); + + sb.append(U.nl()).append("Last initialized exchange future: ").append(fut); + + return sb.toString(); + } + + /** + * @param ctx Context. + * @param nodeId Target node ID. + * @return Communication information future. + */ + public static IgniteInternalFuture dumpCommunicationInfo(GridKernalContext ctx, UUID nodeId) { + if (ctx.config().getCommunicationSpi() instanceof TcpCommunicationSpi) + return ((TcpCommunicationSpi) ctx.config().getCommunicationSpi()).dumpNodeStatistics(nodeId); + else + return new GridFinishedFuture<>("Unexpected communication SPI: " + ctx.config().getCommunicationSpi()); + } + /** + * @param time Time. + * @return Time string. + */ + private static String formatTime(long time) { + return dateFormat.get().format(new Date(time)); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteDiagnosticMessage.class, this); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index bce303238768a..f092e2bb00a23 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -921,26 +921,27 @@ public void start( // Start processors before discovery manager, so they will // be able to start receiving messages once discovery completes. - try {startProcessor(createComponent(DiscoveryNodeValidationProcessor.class, ctx)); - startProcessor(new GridAffinityProcessor(ctx)); - startProcessor(createComponent(GridSegmentationProcessor.class, ctx)); - startProcessor(createComponent(IgniteCacheObjectProcessor.class, ctx)); - startProcessor(new GridCacheProcessor(ctx));startProcessor(new GridClusterStateProcessor(ctx)); - startProcessor(new GridQueryProcessor(ctx)); - startProcessor(new SqlListenerProcessor(ctx)); - startProcessor(new GridServiceProcessor(ctx)); - startProcessor(new GridTaskSessionProcessor(ctx)); - startProcessor(new GridJobProcessor(ctx)); - startProcessor(new GridTaskProcessor(ctx)); - startProcessor((GridProcessor)SCHEDULE.createOptional(ctx)); - startProcessor(new GridRestProcessor(ctx)); - startProcessor(new DataStreamProcessor(ctx)); - startProcessor((GridProcessor)IGFS.create(ctx, F.isEmpty(cfg.getFileSystemConfiguration()))); - startProcessor(new GridContinuousProcessor(ctx)); - startProcessor(createHadoopComponent()); - startProcessor(new DataStructuresProcessor(ctx)); - startProcessor(createComponent(PlatformProcessor.class, ctx)); - startProcessor(new GridMarshallerMappingProcessor(ctx)); + try { + startProcessor(createComponent(DiscoveryNodeValidationProcessor.class, ctx)); + startProcessor(new GridAffinityProcessor(ctx)); + startProcessor(createComponent(GridSegmentationProcessor.class, ctx)); + startProcessor(createComponent(IgniteCacheObjectProcessor.class, ctx)); + startProcessor(new GridCacheProcessor(ctx));startProcessor(new GridClusterStateProcessor(ctx)); + startProcessor(new GridQueryProcessor(ctx)); + startProcessor(new SqlListenerProcessor(ctx)); + startProcessor(new GridServiceProcessor(ctx)); + startProcessor(new GridTaskSessionProcessor(ctx)); + startProcessor(new GridJobProcessor(ctx)); + startProcessor(new GridTaskProcessor(ctx)); + startProcessor((GridProcessor)SCHEDULE.createOptional(ctx)); + startProcessor(new GridRestProcessor(ctx)); + startProcessor(new DataStreamProcessor(ctx)); + startProcessor((GridProcessor)IGFS.create(ctx, F.isEmpty(cfg.getFileSystemConfiguration()))); + startProcessor(new GridContinuousProcessor(ctx)); + startProcessor(createHadoopComponent()); + startProcessor(new DataStructuresProcessor(ctx)); + startProcessor(createComponent(PlatformProcessor.class, ctx)); + startProcessor(new GridMarshallerMappingProcessor(ctx)); // Start plugins. for (PluginProvider provider : ctx.plugins().allProviders()) { @@ -949,9 +950,12 @@ public void start( provider.start(ctx.plugins().pluginContextForProvider(provider)); } + ctx.cluster().initListeners(); + // Start platform plugins. if (ctx.config().getPlatformConfiguration() != null) - startProcessor(new PlatformPluginProcessor(ctx));fillNodeAttributes(clusterProc.updateNotifierEnabled());} + startProcessor(new PlatformPluginProcessor(ctx));fillNodeAttributes(clusterProc.updateNotifierEnabled()); + } catch (Throwable e) { U.error( log, "Exception during start processors, node will be stopped and close connections", e); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java index ea49dbe46fd28..3769a9c6ead9f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java @@ -2296,7 +2296,7 @@ public void dumpStats() { CommunicationSpi spi = getSpi(); if (spi instanceof TcpCommunicationSpi) - ((TcpCommunicationSpi)spi).dumpStats(); + ((TcpCommunicationSpi)spi).dumpDiagnosticInfo(); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java index 4bb9c9f220268..8f1c66e1126e0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java @@ -26,6 +26,7 @@ import org.apache.ignite.internal.GridJobSiblingsResponse; import org.apache.ignite.internal.GridTaskCancelRequest; import org.apache.ignite.internal.GridTaskSessionRequest; +import org.apache.ignite.internal.IgniteDiagnosticMessage; import org.apache.ignite.internal.binary.BinaryEnumObjectImpl; import org.apache.ignite.internal.binary.BinaryObjectImpl; import org.apache.ignite.internal.managers.checkpoint.GridCheckpointRequest; @@ -177,6 +178,11 @@ public GridIoMessageFactory(MessageFactory[] ext) { switch (type) { // -54 is reserved for SQL. + // -46 ... -51 - snapshot messages. + case -61: + msg = new IgniteDiagnosticMessage(); + + break; case -53: msg = new SchemaOperationStatusMessage(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index bdcc05a3e4726..eb07b0d1abf81 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -124,7 +124,9 @@ public Object extraParameter() { * @param op Op. */ public static Collection getOptionalPathsParameter(SnapshotOperation op) { - assert (op.type() == SnapshotOperationType.CHECK || op.type() == SnapshotOperationType.RESTORE) + assert (op.type() == SnapshotOperationType.CHECK || + op.type() == SnapshotOperationType.RESTORE || + op.type() == SnapshotOperationType.RESTORE_2_PHASE) && (op.extraParameter() == null || op.extraParameter() instanceof Collection); return (Collection)op.extraParameter(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java index 3fa6d2a0e32a1..c3b3a2ff738c2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java @@ -23,6 +23,8 @@ public enum SnapshotOperationType { CREATE, /** Restore. */ RESTORE, + /** Restore 2. */ + RESTORE_2_PHASE, /** Move. */ MOVE, /** Delete. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationAckDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationAckDiscoveryMessage.java index 72defd4b392a9..af7648d2edc7e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationAckDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationAckDiscoveryMessage.java @@ -78,6 +78,14 @@ public StartSnapshotOperationAckDiscoveryMessage( return id; } + /** + * + */ + public boolean needExchange() { + /* exchange for trigger saving cluster state*/ + return err == null && snapshotOperation.type() == SnapshotOperationType.CREATE; + } + /** * */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CacheState.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CacheState.java index 638acfa454b24..1c8b04a595e37 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CacheState.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CacheState.java @@ -17,19 +17,28 @@ package org.apache.ignite.internal.pagemem.wal.record; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import org.apache.ignite.internal.util.tostring.GridToStringInclude; -import org.apache.ignite.internal.util.typedef.internal.S; +import java.util.Arrays; /** * */ public class CacheState { /** */ - @GridToStringInclude - private Map parts; + private short[] parts; + + /** */ + private long[] vals; + + /** */ + private int idx; + + /** + * @param partsCnt Partitions count. + */ + public CacheState(int partsCnt) { + parts = new short[partsCnt]; + vals = new long[partsCnt * 2]; + } /** * @param partId Partition ID to add. @@ -37,60 +46,88 @@ public class CacheState { * @param cntr Partition counter. */ public void addPartitionState(int partId, long size, long cntr) { - if (parts == null) - parts = new HashMap<>(); + if (idx == parts.length) + throw new IllegalStateException("Failed to add new partition to the partitions state " + + "(no enough space reserved) [partId=" + partId + ", reserved=" + parts.length + ']'); + + if (idx > 0) { + if (parts[idx - 1] >= partId) + throw new IllegalStateException("Adding partition in a wrong order [prev=" + parts[idx - 1] + + ", cur=" + partId + ']'); + } + + parts[idx] = (short)partId; + vals[2 * idx] = size; + vals[2 * idx + 1] = cntr; - parts.put(partId, new PartitionState(size, cntr)); + idx++; } /** - * @return Partitions map. + * Gets partition size by partition ID. + * + * @param partId Partition ID. + * @return Partition size (will return {@code -1} if partition is not present in the record). */ - public Map partitions() { - return parts == null ? Collections.emptyMap() : parts; - } + public long sizeByPartition(int partId) { + int idx = indexByPartition(partId); - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(CacheState.class, this); + return idx >= 0 ? vals[2 * idx] : -1; } /** + * Gets partition counter by partition ID. * + * @param partId Partition ID. + * @return Partition update counter (will return {@code -1} if partition is not present in the record). */ - public static class PartitionState { - /** */ - private final long size; - - /** */ - private final long partCnt; - - /** - * @param size Partition size. - * @param partCnt Partition counter. - */ - public PartitionState(long size, long partCnt) { - this.size = size; - this.partCnt = partCnt; - } + public long counterByPartition(int partId) { + int idx = indexByPartition(partId); - /** - * @return Partition size. - */ - public long size() { - return size; - } + return idx >= 0 ? vals[2 * idx + 1] : 0; + } - /** - * @return Partition counter. - */ - public long partitionCounter() { - return partCnt; - } + /** + * @param idx Index to get. + * @return Partition ID. + */ + public int partitionByIndex(int idx) { + return parts[idx] & 0xFFFF; + } - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(PartitionState.class, this); - } + /** + * @param idx Index to get. + * @return Partition size by index. + */ + public long partitionSizeByIndex(int idx) { + return vals[idx * 2]; + } + + /** + * @param idx Index to get. + * @return Partition size by index. + */ + public long partitionCounterByIndex(int idx) { + return vals[idx * 2 + 1]; + } + + /** + * @return State size. + */ + public int size() { + return idx; + } + + /** + * @param partId Partition ID to search. + * @return Non-negative index of partition if found or negative value if not found. + */ + private int indexByPartition(int partId) { + return Arrays.binarySearch(parts, 0, idx, (short)partId); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "CacheState [cap=" + parts.length + ", size=" + idx + ']'; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java index 5c99d54f9baf8..1daf5a1226795 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java @@ -66,10 +66,8 @@ public long reuseListRoot() { return reuseListRoot; } - /** - * @return IO type. - */ - public int ioType() { + /** {@inheritDoc} */ + @Override public int ioType() { return ioType; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeBatch.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeBatch.java index 3c65326fae40c..d5c820f981e39 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeBatch.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeBatch.java @@ -18,6 +18,7 @@ package org.apache.ignite.internal.processors.cache; import java.util.Collection; +import java.util.Set; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.F; @@ -42,6 +43,12 @@ public class DynamicCacheChangeBatch implements DiscoveryCustomMessage { /** Cache updates to be executed on exchange. */ private transient ExchangeActions exchangeActions; + /** */ + private boolean startCaches; + + /** Restarting caches. */ + private Set restartingCaches; + /** * @param reqs Requests. */ @@ -96,6 +103,36 @@ void exchangeActions(ExchangeActions exchangeActions) { this.exchangeActions = exchangeActions; } + /** + * @return {@code True} if required to start all caches on client node. + */ + public boolean startCaches() { + return startCaches; + } + + /** + * @param restartingCaches Restarting caches. + */ + public DynamicCacheChangeBatch restartingCaches(Set restartingCaches) { + this.restartingCaches = restartingCaches; + + return this; + } + + /** + * @return Set of restarting caches. + */ + public Set restartingCaches() { + return restartingCaches; + } + + /** + * @param startCaches {@code True} if required to start all caches on client node. + */ + public void startCaches(boolean startCaches) { + this.startCaches = startCaches; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(DynamicCacheChangeBatch.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java index ecd12ba39f4bc..7c0c55c0ea7bc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java @@ -22,7 +22,6 @@ import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.processors.query.QuerySchema; import org.apache.ignite.internal.util.tostring.GridToStringExclude; -import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; @@ -47,6 +46,7 @@ public class DynamicCacheChangeRequest implements Serializable { private String cacheName; /** Cache start configuration. */ + @GridToStringExclude private CacheConfiguration startCfg; /** Cache type. */ @@ -56,6 +56,7 @@ public class DynamicCacheChangeRequest implements Serializable { private UUID initiatingNodeId; /** Near cache configuration. */ + @GridToStringExclude private NearCacheConfiguration nearCacheCfg; /** Start only client cache, do not start data nodes. */ @@ -446,6 +447,12 @@ public void schema(QuerySchema schema) { /** {@inheritDoc} */ @Override public String toString() { - return S.toString(DynamicCacheChangeRequest.class, this, "cacheName", cacheName()); + return "DynamicCacheChangeRequest [cacheName=" + cacheName() + + ", hasCfg=" + (startCfg != null) + + ", nodeId=" + initiatingNodeId + + ", clientStartOnly=" + clientStartOnly + + ", close=" + close + + ", stop=" + stop + + ']'; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java index b9a4b257b529f..81c7b6bf7a1e1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java @@ -304,8 +304,11 @@ public void onStopped() { try { if (rwLock.writeLock().tryLock(200, TimeUnit.MILLISECONDS)) break; - else + else { U.sleep(200); + + ctx.affinity().cancelFutures(); + } } catch (IgniteInterruptedCheckedException | InterruptedException ignore) { interrupted = true; 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 a2510470a8337..ebb6bf27ed65e 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 @@ -17,12 +17,15 @@ package org.apache.ignite.internal.processors.cache; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; @@ -126,6 +129,26 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter { /** Deployment enabled. */ private boolean depEnabled; + /** */ + private final List pendingMsgs = new ArrayList<>(); + + /** + * + */ + public void dumpPendingMessages() { + synchronized (pendingMsgs) { + if (pendingMsgs.isEmpty()) + return; + + log.info("Pending cache messages waiting for exchange [" + + "readyVer=" + cctx.exchange().readyAffinityVersion() + + ", discoVer=" + cctx.discovery().topologyVersion() + ']'); + + for (GridCacheMessage msg : pendingMsgs) + log.info("Message [waitVer=" + msg.topologyVersion() + ", msg=" + msg + ']'); + } + } + /** Message listener. */ private GridMessageListener lsnr = new GridMessageListener() { @Override public void onMessage(final UUID nodeId, final Object msg) { @@ -218,10 +241,19 @@ else if (desc.receivedFromStartVersion() != null) final int stripe = curThread instanceof IgniteThread ? ((IgniteThread)curThread).stripe() : -1; + synchronized (pendingMsgs) { + if (pendingMsgs.size() < 100) + pendingMsgs.add(cacheMsg); + } + fut.listen(new CI1>() { @Override public void apply(IgniteInternalFuture t) { Runnable c = new Runnable() { @Override public void run() { + synchronized (pendingMsgs) { + pendingMsgs.remove(cacheMsg); + } + IgniteLogger log = cacheMsg.messageLogger(cctx); if (log.isDebugEnabled()) { @@ -309,6 +341,15 @@ private void handleMessage(UUID nodeId, GridCacheMessage cacheMsg, MessageHandle else U.error(log, msg0.toString()); + try { + cacheMsg.onClassError(new IgniteCheckedException("Failed to find message handler for message: " + cacheMsg)); + + processFailedMessage(nodeId, cacheMsg, c); + } + catch (Exception e) { + U.error(log, "Failed to process failed message: " + e, e); + } + return; } 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 ae4c1647b330b..2053c727956f0 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 @@ -49,6 +49,7 @@ import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException; +import org.apache.ignite.internal.IgniteDiagnosticAware; import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteInterruptedCheckedException; @@ -119,7 +120,8 @@ */ public class GridCachePartitionExchangeManager extends GridCacheSharedManagerAdapter { /** Exchange history size. */ - private static final int EXCHANGE_HISTORY_SIZE = 1000; + private static final int EXCHANGE_HISTORY_SIZE = + IgniteSystemProperties.getInteger("IGNITE_EXCHANGE_HISTORY_SIZE", 1000); /** Atomic reference for pending timeout object. */ private AtomicReference pendingResend = new AtomicReference<>(); @@ -254,13 +256,12 @@ else if (customMsg instanceof CacheAffinityChangeMessage) { exchFut = exchangeFuture(exchId, evt, cache, null, msg); } } - else { + else exchangeFuture(msg.exchangeId(), null, null, null, null) .onAffinityChangeMessage(evt.eventNode(), msg); - } } else if (customMsg instanceof StartSnapshotOperationAckDiscoveryMessage - && !((StartSnapshotOperationAckDiscoveryMessage)customMsg).hasError()) { + && ((StartSnapshotOperationAckDiscoveryMessage)customMsg).needExchange()) { exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt.type()); exchFut = exchangeFuture(exchId, evt, null, null, null); @@ -1404,7 +1405,7 @@ public void dumpDebugInfo(@Nullable AffinityTopologyVersion exchTopVer) throws E int cnt = 0; for (GridDhtPartitionsExchangeFuture fut : exchFuts.values()) { - U.warn(log, ">>> " + fut); + U.warn(log, ">>> " + fut.shortInfo()); if (++cnt == 10) break; @@ -1418,8 +1419,11 @@ public void dumpDebugInfo(@Nullable AffinityTopologyVersion exchTopVer) throws E cctx.affinity().dumpDebugInfo(); + cctx.io().dumpPendingMessages(); + // Dump IO manager statistics. - cctx.gridIO().dumpStats(); + if (IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_IO_DUMP_ON_TIMEOUT, false)) + cctx.gridIO().dumpStats(); } /** @@ -1464,6 +1468,9 @@ public void dumpLongRunningOperations(long timeout) { if (longRunningOpsDumpCnt < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) { U.warn(log, "Found long running cache future [startTime=" + formatTime(fut.startTime()) + ", curTime=" + formatTime(curTime) + ", fut=" + fut + ']'); + + if (fut instanceof IgniteDiagnosticAware) + ((IgniteDiagnosticAware)fut).dumpDiagnosticInfo(); } else break; @@ -1477,6 +1484,9 @@ public void dumpLongRunningOperations(long timeout) { if (longRunningOpsDumpCnt < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) { U.warn(log, "Found long running cache future [startTime=" + formatTime(fut.startTime()) + ", curTime=" + formatTime(curTime) + ", fut=" + fut + ']'); + + if (fut instanceof IgniteDiagnosticAware) + ((IgniteDiagnosticAware)fut).dumpDiagnosticInfo(); } else break; @@ -1484,6 +1494,8 @@ public void dumpLongRunningOperations(long timeout) { } } + cctx.io().dumpPendingMessages(); + if (found) { if (longRunningOpsDumpCnt < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) { longRunningOpsDumpCnt++; @@ -1497,7 +1509,8 @@ public void dumpLongRunningOperations(long timeout) { U.warn(log, "Found long running cache operations, dump IO statistics."); // Dump IO manager statistics. - cctx.gridIO().dumpStats(); + if (IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_IO_DUMP_ON_TIMEOUT, false)) + cctx.gridIO().dumpStats(); } } else @@ -1556,14 +1569,22 @@ private void dumpPendingObjects(@Nullable AffinityTopologyVersion exchTopVer) { U.warn(log, "Pending cache futures:"); - for (GridCacheFuture fut : mvcc.activeFutures()) + for (GridCacheFuture fut : mvcc.activeFutures()) { U.warn(log, ">>> " + fut); + if (fut instanceof IgniteDiagnosticAware) + ((IgniteDiagnosticAware)fut).dumpDiagnosticInfo(); + } + U.warn(log, "Pending atomic cache futures:"); - for (GridCacheFuture fut : mvcc.atomicFutures()) + for (GridCacheFuture fut : mvcc.atomicFutures()) { U.warn(log, ">>> " + fut); + if (fut instanceof IgniteDiagnosticAware) + ((IgniteDiagnosticAware)fut).dumpDiagnosticInfo(); + } + U.warn(log, "Pending data streamer futures:"); for (IgniteInternalFuture fut : mvcc.dataStreamerFutures()) @@ -1819,6 +1840,8 @@ void dumpExchangeDebugInfo() { U.dumpThreads(log); dumpedObjects++; + + exchFut.dumpDiagnosticInfo(); } } catch (Exception e) { @@ -2075,8 +2098,14 @@ private ExchangeFutureSet() { GridDhtPartitionsExchangeFuture fut) { GridDhtPartitionsExchangeFuture cur = super.addx(fut); - while (size() > EXCHANGE_HISTORY_SIZE) + while (size() > EXCHANGE_HISTORY_SIZE) { + GridDhtPartitionsExchangeFuture last = last(); + + if (last != null && !last.isDone()) + break; + removeLast(); + } // Return the value in the set. return cur == null ? fut : cur; 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 e9680749a4a42..99daafcf88324 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 @@ -113,6 +113,7 @@ import org.apache.ignite.internal.processors.timeout.GridTimeoutObject; import org.apache.ignite.internal.suggestions.GridPerformanceSuggestions; import org.apache.ignite.internal.util.F0; +import org.apache.ignite.internal.util.GridConcurrentHashSet; import org.apache.ignite.internal.util.future.GridCompoundFuture; import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.internal.util.future.GridFutureAdapter; @@ -203,6 +204,9 @@ public class GridCacheProcessor extends GridProcessorAdapter { /** */ private ClusterCachesInfo cachesInfo; + /** Restarting caches */ + private final Set restartingCaches = new GridConcurrentHashSet<>(); + /** */ private IdentityHashMap sesHolders = new IdentityHashMap<>(); @@ -2113,6 +2117,9 @@ public void onExchangeDone( } } + if (exchActions != null && exchActions.systemCacheStarting()) + ctx.dataStructures().restoreStructuresState(ctx); + if (exchActions != null && (err == null || forceClose)) { Collection> stoppedGrps = null; @@ -2658,6 +2665,16 @@ public IgniteInternalFuture dynamicDestroyCache(String cacheName, boole */ public IgniteInternalFuture dynamicDestroyCaches(Collection cacheNames, boolean checkThreadTx, boolean restart) { + return dynamicDestroyCaches(cacheNames, checkThreadTx, restart, true); + } + + /** + * @param cacheNames Collection of cache names to destroy. + * @param checkThreadTx If {@code true} checks that current thread does not have active transactions. + * @return Future that will be completed when cache is destroyed. + */ + public IgniteInternalFuture dynamicDestroyCaches(Collection cacheNames, boolean checkThreadTx, + boolean restart, boolean destroy) { if (checkThreadTx) checkEmptyTransactions(); @@ -2667,7 +2684,7 @@ public IgniteInternalFuture dynamicDestroyCaches(Collection cacheName DynamicCacheChangeRequest req = DynamicCacheChangeRequest.stopRequest(ctx, cacheName, false, true); req.stop(true); - req.destroy(true); + req.destroy(destroy); req.restart(restart); reqs.add(req); @@ -2943,7 +2960,7 @@ public boolean onCustomEvent(DiscoveryCustomMessage msg, AffinityTopologyVersion return sharedCtx.affinity().onCustomEvent(((CacheAffinityChangeMessage)msg)); if (msg instanceof StartSnapshotOperationAckDiscoveryMessage && - ((StartSnapshotOperationAckDiscoveryMessage)msg).error() == null) + ((StartSnapshotOperationAckDiscoveryMessage)msg).needExchange()) return true; if (msg instanceof DynamicCacheChangeBatch) @@ -2996,6 +3013,12 @@ else if (rebalanceOrder < 0) */ @Nullable private IgniteNodeValidationResult validateHashIdResolvers(ClusterNode node) { if (!node.isClient()) { + if (restartingCaches.size() > 0) { + String msg = "Joining server node during cache restarting is not allowed"; + + return new IgniteNodeValidationResult(node.id(), msg, msg); + } + for (DynamicCacheDescriptor desc : cacheDescriptors().values()) { CacheConfiguration cfg = desc.cacheConfiguration(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index f13532d8cc989..27650a2168c05 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -738,6 +738,13 @@ public void beforeExchange(GridDhtPartitionsExchangeFuture discoEvt) throws Igni // No-op. } + /** + * Needed action before any cache will stop + */ + public void prepareCachesStop() { + // No-op. + } + /** * @param stoppedGrps A collection of tuples (cache group, destroy flag). */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java index d5d4c7cb66df7..a8f3037427daf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java @@ -73,6 +73,9 @@ public abstract class PagesList extends DataStructure { /** */ protected final AtomicLong[] bucketsSize; + /** */ + protected volatile boolean changed; + /** Page ID to store list metadata. */ private final long metaPageId; @@ -124,16 +127,15 @@ private final class CutTail extends PageHandler { * @param buckets Number of buckets. * @param wal Write ahead log manager. * @param metaPageId Metadata page ID. - * @throws IgniteCheckedException If failed. */ - public PagesList( + protected PagesList( int cacheId, String name, PageMemory pageMem, int buckets, IgniteWriteAheadLogManager wal, long metaPageId - ) throws IgniteCheckedException { + ) { super(cacheId, pageMem, wal); this.name = name; @@ -244,6 +246,8 @@ protected final void init(long metaPageId, boolean initNew) throws IgniteChecked assert ok; bucketsSize[bucket].set(bucketSize); + + changed = true; } } } @@ -263,6 +267,9 @@ public void saveMetadata() throws IgniteCheckedException { long nextPageId = metaPageId; + if (!changed) + return; + try { for (int bucket = 0; bucket < buckets; bucket++) { Stripe[] tails = getBucket(bucket); @@ -340,6 +347,8 @@ public void saveMetadata() throws IgniteCheckedException { releasePage(pageId, page); } } + + changed = false; } /** @@ -672,7 +681,7 @@ private boolean putDataPage( if (idx == -1) handlePageFull(pageId, page, pageAddr, io, dataId, dataPage, dataAddr, bucket); else { - bucketsSize[bucket].incrementAndGet(); + incrementBucketSize(bucket); if (needWalDeltaRecord(pageId, page, null)) wal.log(new PagesListAddPageRecord(cacheId, pageId, dataId)); @@ -733,7 +742,7 @@ private void handlePageFull( pageId, 0L)); // In reuse bucket the page itself can be used as a free page. - bucketsSize[bucket].incrementAndGet(); + incrementBucketSize(bucket); updateTail(bucket, pageId, newDataId); } @@ -776,7 +785,7 @@ private void handlePageFull( if (needWalDeltaRecord(dataId, data, null)) wal.log(new DataPageSetFreeListPageRecord(cacheId, dataId, nextId)); - bucketsSize[bucket].incrementAndGet(); + incrementBucketSize(bucket); updateTail(bucket, pageId, nextId); } @@ -862,7 +871,7 @@ private boolean putReuseBag( // In reuse bucket the page itself can be used as a free page. if (isReuseBucket(bucket)) - bucketsSize[bucket].incrementAndGet(); + incrementBucketSize(bucket); // Switch to this new page, which is now a part of our list // to add the rest of the bag to the new page. @@ -882,7 +891,7 @@ private boolean putReuseBag( if (needWalDeltaRecord(prevId, prevPage, walPlc)) wal.log(new PagesListAddPageRecord(cacheId, prevId, nextId)); - bucketsSize[bucket].incrementAndGet(); + incrementBucketSize(bucket); } } } @@ -1025,7 +1034,7 @@ protected final long takeEmptyPage(int bucket, @Nullable IOVersions initIoVers) long pageId = io.takeAnyPage(tailAddr); if (pageId != 0L) { - bucketsSize[bucket].decrementAndGet(); + decrementBucketSize(bucket); if (needWalDeltaRecord(tailId, tailPage, null)) wal.log(new PagesListRemovePageRecord(cacheId, tailId, pageId)); @@ -1068,7 +1077,7 @@ protected final long takeEmptyPage(int bucket, @Nullable IOVersions initIoVers) assert ok == TRUE : ok; - bucketsSize[bucket].decrementAndGet(); + decrementBucketSize(bucket); if (initIoVers != null) { dataPageId = PageIdUtils.changeType(tailId, FLAG_DATA); @@ -1153,7 +1162,7 @@ protected final boolean removeDataPage( if (!rmvd) return false; - bucketsSize[bucket].decrementAndGet(); + decrementBucketSize(bucket); if (needWalDeltaRecord(pageId, page, null)) wal.log(new PagesListRemovePageRecord(cacheId, pageId, dataId)); @@ -1393,6 +1402,32 @@ private void fairMerge( } } + /** + * Increments bucket size and updates changed flag. + * + * @param bucket Bucket number. + */ + private void incrementBucketSize(int bucket) { + bucketsSize[bucket].incrementAndGet(); + + // Ok to have a race here, see the field javadoc. + if (!changed) + changed = true; + } + + /** + * Increments bucket size and updates changed flag. + * + * @param bucket Bucket number. + */ + private void decrementBucketSize(int bucket) { + bucketsSize[bucket].decrementAndGet(); + + // Ok to have a race here, see the field javadoc. + if (!changed) + changed = true; + } + /** * Singleton reuse bag. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java index d92f8119b2bff..98204eb24e49f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java @@ -2091,9 +2091,12 @@ public final long destroy(IgniteInClosure c) throws IgniteCheckedException { assert pageId != 0; do { - long page = acquirePage(pageId); + final long pId = pageId; + + long page = acquirePage(pId); + try { - long pageAddr = writeLock(pageId, page); // No checks, we must be out of use. + long pageAddr = writeLock(pId, page); // No checks, we must be out of use. try { BPlusIO io = io(pageAddr); @@ -2109,11 +2112,11 @@ public final long destroy(IgniteInClosure c) throws IgniteCheckedException { pageId = fwdPageId; } finally { - writeUnlock(pageId, page, pageAddr, true); + writeUnlock(pId, page, pageAddr, true); } } finally { - releasePage(pageId, page); + releasePage(pId, page); } if (bag.size() == 128) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java index 7a5535c27022f..b04baf3ae3d3e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java @@ -204,8 +204,13 @@ public int getLastPageCount(long pageAddr) { * @param pageAddr Page address. * @param pageCnt Last page count. */ - public void setCandidatePageCount(long pageAddr, int pageCnt) { + public boolean setCandidatePageCount(long pageAddr, int pageCnt) { + if (getCandidatePageCount(pageAddr) == pageCnt) + return false; + PageUtils.putInt(pageAddr, CANDIDATE_PAGE_COUNT_OFF, pageCnt); + + return true; } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java index 67cc5a394516d..ddacf6972e46d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java @@ -74,8 +74,13 @@ public long getSize(long pageAddr) { * @param pageAddr Page address. * @param size Partition size. */ - public void setSize(long pageAddr, long size) { + public boolean setSize(long pageAddr, long size) { + if (getSize(pageAddr) == size) + return false; + PageUtils.putLong(pageAddr, SIZE_OFF, size); + + return true; } /** @@ -90,8 +95,13 @@ public long getUpdateCounter(long pageAddr) { * @param pageAddr Page address. * @param cntr Partition update counter. */ - public void setUpdateCounter(long pageAddr, long cntr) { + public boolean setUpdateCounter(long pageAddr, long cntr) { + if (getUpdateCounter(pageAddr) == cntr) + return false; + PageUtils.putLong(pageAddr, UPDATE_CNTR_OFF, cntr); + + return true; } /** @@ -106,8 +116,13 @@ public long getGlobalRemoveId(long pageAddr) { * @param pageAddr Page address. * @param rmvId Global remove ID. */ - public void setGlobalRemoveId(long pageAddr, long rmvId) { + public boolean setGlobalRemoveId(long pageAddr, long rmvId) { + if (getGlobalRemoveId(pageAddr) == rmvId) + return false; + PageUtils.putLong(pageAddr, GLOBAL_RMV_ID_OFF, rmvId); + + return true; } /** @@ -121,8 +136,13 @@ public byte getPartitionState(long pageAddr) { * @param pageAddr Page address * @param state State. */ - public void setPartitionState(long pageAddr, byte state) { + public boolean setPartitionState(long pageAddr, byte state) { + if (getPartitionState(pageAddr) == state) + return false; + PageUtils.putByte(pageAddr, PARTITION_STATE_OFF, state); + + return true; } /** 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 cace4e81cec85..c00ebca4dbc62 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 @@ -60,6 +60,9 @@ */ @GridToStringExclude public class GridClientPartitionTopology implements GridDhtPartitionTopology { + /** */ + private static final GridDhtPartitionState[] MOVING_STATES = new GridDhtPartitionState[] {MOVING}; + /** If true, then check consistency. */ private static final boolean CONSISTENCY_CHECK = false; @@ -504,7 +507,7 @@ private List nodes(int p, AffinityTopologyVersion topVer, GridDhtPa /** {@inheritDoc} */ @Override public List owners(int p, AffinityTopologyVersion topVer) { - return nodes(p, topVer, OWNING); + return nodes(p, topVer, OWNING, null); } /** {@inheritDoc} */ @@ -514,7 +517,7 @@ private List nodes(int p, AffinityTopologyVersion topVer, GridDhtPa /** {@inheritDoc} */ @Override public List moving(int p) { - return nodes(p, AffinityTopologyVersion.NONE, MOVING); + return nodes(p, AffinityTopologyVersion.NONE, MOVING, null); } /** @@ -523,7 +526,7 @@ private List nodes(int p, AffinityTopologyVersion topVer, GridDhtPa * @return List of nodes in state OWNING or MOVING. */ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) { - return nodes(p, topVer, OWNING, MOVING); + return nodes(p, topVer, OWNING, MOVING_STATES); } /** {@inheritDoc} */ @@ -786,6 +789,11 @@ public long lastUpdateSequence() { } } + /** {@inheritDoc} */ + @Override public void onExchangeDone(AffinityAssignment assignment) { + // no-op + } + /** {@inheritDoc} */ @Override public boolean detectLostPartitions(DiscoveryEvent discoEvt) { assert false : "detectLostPartitions should never be called on client topology"; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java index ebb2cfcfd2b92..7d2906423e996 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java @@ -41,6 +41,7 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.lang.GridPlainRunnable; +import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.C1; import org.apache.ignite.internal.util.typedef.CI1; @@ -70,6 +71,7 @@ public class GridDhtCacheEntry extends GridDistributedCacheEntry { private volatile ReaderId[] rdrs = ReaderId.EMPTY_ARRAY; /** Local partition. */ + @GridToStringExclude private final GridDhtLocalPartition locPart; /** @@ -723,7 +725,9 @@ protected final String cacheName() { /** {@inheritDoc} */ @Override public synchronized String toString() { - return S.toString(GridDhtCacheEntry.class, this, "super", super.toString()); + return S.toString(GridDhtCacheEntry.class, this, + "part", locPart.id(), + "super", super.toString()); } /** {@inheritDoc} */ 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 a53e8642bd1e6..4480efed5f7ee 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 @@ -737,7 +737,7 @@ public IgniteInternalFuture rent(boolean updateSeq) { /** * @param updateSeq Update sequence. */ - void tryEvictAsync(boolean updateSeq) { + public void tryEvictAsync(boolean updateSeq) { long state = this.state.get(); GridDhtPartitionState partState = getPartState(state); 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 4e0608dce2683..2236293dd92a1 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 @@ -328,4 +328,10 @@ public GridDhtPartitionMap update(@Nullable GridDhtPartitionsExchangeFuture exch * @return Set of node IDs that should reload partitions. */ public Set setOwners(int p, Set owners, boolean haveHistory, boolean updateSeq); + + /** + * Callback on exchange done. + * @param assignment New affinity assignment. + */ + public void onExchangeDone(AffinityAssignment assignment); } 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 19e48eb7cb69b..d8c40188ee146 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 @@ -70,12 +70,18 @@ */ @GridToStringExclude public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology { + /** */ + private static final GridDhtPartitionState[] MOVING_STATES = new GridDhtPartitionState[] {MOVING}; + /** If true, then check consistency. */ private static final boolean CONSISTENCY_CHECK = false; /** Flag to control amount of output for full map. */ private static final boolean FULL_MAP_DEBUG = false; + /** */ + private static final boolean FAST_DIFF_REBUILD = true; + /** */ private static final Long ZERO = 0L; @@ -88,14 +94,20 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology { /** Logger. */ private final IgniteLogger log; + /** Time logger. */ + private final IgniteLogger timeLog; + /** */ private final AtomicReferenceArray locParts; /** Node to partition map. */ private GridDhtPartitionFullMap node2part; - /** Partition to node map. */ - private final Map> part2node; + /** */ + private final Map> diffFromAffinity = new HashMap<>(); + + /** */ + private volatile AffinityTopologyVersion diffFromAffinityVer = AffinityTopologyVersion.NONE; /** */ private GridDhtPartitionExchangeId lastExchangeId; @@ -141,6 +153,8 @@ public GridDhtPartitionTopologyImpl(GridCacheSharedContext ctx, log = ctx.logger(getClass()); + timeLog = ctx.logger(GridDhtPartitionsExchangeFuture.EXCHANGE_LOG); + locParts = new AtomicReferenceArray<>(grp.affinityFunction().partitions()); part2node = new HashMap<>(grp.affinityFunction().partitions(), 1.0f); @@ -160,7 +174,7 @@ public void onReconnected() { try { node2part = null; - part2node.clear(); + diffFromAffinity.clear(); lastExchangeId = null; @@ -168,6 +182,8 @@ public void onReconnected() { topReadyFut = null; + diffFromAffinityVer = AffinityTopologyVersion.NONE; + rebalancedTopVer = AffinityTopologyVersion.NONE; topVer = AffinityTopologyVersion.NONE; @@ -873,18 +889,42 @@ else if (loc != null && state == RENTING && !showRenting) List nodes = null; - Collection nodeIds = part2node.get(p); + if (!topVer.equals(diffFromAffinityVer)) { + log.error("??? node2part [topVer=" + topVer + ", diffVer=" + diffFromAffinityVer + "]"); + + nodes = new ArrayList<>(); + + nodes.addAll(affNodes); + + for (Map.Entry entry : node2part.entrySet()) { + GridDhtPartitionState state = entry.getValue().get(p); + + ClusterNode n = ctx.discovery().node(entry.getKey()); + + if (n != null && state != null && (state == MOVING || state == OWNING) && !nodes.contains(n) + && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) { + nodes.add(n); + } + + } + + return nodes; + } + + Collection diffIds = diffFromAffinity.get(p); + + if (!F.isEmpty(diffIds)) { + HashSet affIds = affAssignment.getIds(p); - if (!F.isEmpty(nodeIds)) { - for (UUID nodeId : nodeIds) { - HashSet affIds = affAssignment.getIds(p); + for (UUID nodeId : diffIds) { + assert !affIds.contains(nodeId); - if (!affIds.contains(nodeId) && hasState(p, nodeId, OWNING, MOVING)) { + if (hasState(p, nodeId, OWNING, MOVING)) { ClusterNode n = ctx.discovery().node(nodeId); if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) { if (nodes == null) { - nodes = new ArrayList<>(affNodes.size() + 2); + nodes = new ArrayList<>(affNodes.size() + diffIds.size()); nodes.addAll(affNodes); } @@ -913,9 +953,7 @@ private List nodes(int p, AffinityTopologyVersion topVer, GridDhtPartitionState state, GridDhtPartitionState... states) { - Collection allIds = topVer.topologyVersion() > 0 ? - F.nodeIds(discoCache.cacheGroupAffinityNodes(grp.groupId())) : - null; + Collection allIds = F.nodeIds(discoCache.cacheGroupAffinityNodes(grp.groupId())); lock.readLock().lock(); @@ -925,20 +963,10 @@ private List nodes(int p, ", node2part=" + node2part + ", grp=" + grp.cacheOrGroupName() + ']'; - Collection nodeIds = part2node.get(p); - // Node IDs can be null if both, primary and backup, nodes disappear. - int size = nodeIds == null ? 0 : nodeIds.size(); - - if (size == 0) - return Collections.emptyList(); - - List nodes = new ArrayList<>(size); - - for (UUID id : nodeIds) { - if (topVer.topologyVersion() > 0 && !F.contains(allIds, id)) - continue; + List nodes = new ArrayList<>(); + for (UUID id : allIds) { if (hasState(p, id, state, states)) { ClusterNode n = ctx.discovery().node(id); @@ -959,7 +987,7 @@ private List nodes(int p, if (!grp.rebalanceEnabled()) return ownersAndMoving(p, topVer); - return nodes(p, topVer, OWNING); + return nodes(p, topVer, OWNING, null); } /** {@inheritDoc} */ @@ -972,7 +1000,7 @@ private List nodes(int p, if (!grp.rebalanceEnabled()) return ownersAndMoving(p, AffinityTopologyVersion.NONE); - return nodes(p, AffinityTopologyVersion.NONE, MOVING); + return nodes(p, AffinityTopologyVersion.NONE, MOVING, null); } /** @@ -981,7 +1009,7 @@ private List nodes(int p, * @return List of nodes in state OWNING or MOVING. */ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) { - return nodes(p, topVer, OWNING, MOVING); + return nodes(p, topVer, OWNING, MOVING_STATES); } /** {@inheritDoc} */ @@ -1110,30 +1138,39 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) node2part = partMap; - part2node.clear(); + AffinityTopologyVersion affVer = ctx.affinity().affinityTopologyVersion(); - for (Map.Entry e : partMap.entrySet()) { - for (Map.Entry e0 : e.getValue().entrySet()) { - if (e0.getValue() != MOVING && e0.getValue() != OWNING) - continue; + if (diffFromAffinityVer.compareTo(affVer) <= 0) { + AffinityAssignment affAssignment = ctx.affinity().assignment(affVer); - int p = e0.getKey(); + for (Map.Entry e : partMap.entrySet()) { + for (Map.Entry e0 : e.getValue().entrySet()) { + int p = e0.getKey(); - Set ids = part2node.get(p); + Set diffIds = diffFromAffinity.get(p); - if (ids == null) - // Initialize HashSet to size 3 in anticipation that there won't be - // more than 3 nodes per partitions. - part2node.put(p, ids = U.newHashSet(3)); + if ((e0.getValue() == MOVING || e0.getValue() == OWNING || e0.getValue() == RENTING) && + !affAssignment.getIds(p).contains(e.getKey())) { - ids.add(e.getKey()); + if (diffIds == null) + diffFromAffinity.put(p, diffIds = U.newHashSet(3)); + + diffIds.add(e.getKey()); + } + else { + if (diffIds != null && diffIds.remove(e.getKey())) { + if (diffIds.isEmpty()) + diffFromAffinity.remove(p); + } + } + } } + + diffFromAffinityVer = affVer; } boolean changed = false; - AffinityTopologyVersion affVer = grp.affinity().lastVersion(); - GridDhtPartitionMap nodeMap = partMap.get(ctx.localNodeId()); if (nodeMap != null && ctx.database().persistenceEnabled()) { @@ -1230,9 +1267,19 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { @Override public void applyUpdateCounters(Map> cntrMap) { assert cntrMap != null; + long now = U.currentTimeMillis(); + lock.writeLock().lock(); try { + long acquired = U.currentTimeMillis(); + + if (acquired - now >= 100) { + if (timeLog.isInfoEnabled()) + timeLog.info("Waited too long to acquire topology write lock " + + "[cache=" + grp.groupId() + ", waitTime=" + (acquired - now) + ']'); + } + if (stopping) return; @@ -1311,7 +1358,7 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { long updateSeq = this.updateSeq.incrementAndGet(); - node2part = new GridDhtPartitionFullMap(node2part, updateSeq); + node2part.updateSequence(updateSeq); boolean changed = false; @@ -1320,37 +1367,52 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { node2part.put(parts.nodeId(), parts); - // Add new mappings. - for (Map.Entry e : parts.entrySet()) { - int p = e.getKey(); + AffinityTopologyVersion affVer = grp.affinity().lastVersion(); + + if (affVer.compareTo(diffFromAffinityVer) >= 0) { + AffinityAssignment affAssignment = grp.affinity().assignment(affVer); - Set ids = part2node.get(p); + // Add new mappings. + for (Map.Entry e : parts.entrySet()) { + int p = e.getKey(); - if (e.getValue() == MOVING || e.getValue() == OWNING) { - if (ids == null) - // Initialize HashSet to size 3 in anticipation that there won't be - // more than 3 nodes per partition. - part2node.put(p, ids = U.newHashSet(3)); + Set diffIds = diffFromAffinity.get(p); - changed |= ids.add(parts.nodeId()); - } - else { - if (ids != null) - changed |= ids.remove(parts.nodeId()); + if ((e.getValue() == MOVING || e.getValue() == OWNING || e.getValue() == RENTING) + && !affAssignment.getIds(p).contains(parts.nodeId())) { + if (diffIds == null) + diffFromAffinity.put(p, diffIds = U.newHashSet(3)); + + if (diffIds.add(parts.nodeId())) + changed = true; + } + else { + if (diffIds != null && diffIds.remove(parts.nodeId())) { + changed = true; + + if (diffIds.isEmpty()) + diffFromAffinity.remove(p); + } + + } } - } - // Remove obsolete mappings. - if (cur != null) { - for (Integer p : F.view(cur.keySet(), F0.notIn(parts.keySet()))) { - Set ids = part2node.get(p); + // Remove obsolete mappings. + if (cur != null) { + for (Integer p : F.view(cur.keySet(), F0.notIn(parts.keySet()))) { + Set ids = diffFromAffinity.get(p); - if (ids != null) - changed |= ids.remove(parts.nodeId()); + if (ids != null && ids.remove(parts.nodeId())) { + changed = true; + + if (ids.isEmpty()) + diffFromAffinity.remove(p); + } + } } - } - AffinityTopologyVersion affVer = grp.affinity().lastVersion(); + diffFromAffinityVer = affVer; + } if (!affVer.equals(AffinityTopologyVersion.NONE) && affVer.compareTo(topVer) >= 0) { List> aff = grp.affinity().assignments(topVer); @@ -1376,44 +1438,96 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { } /** {@inheritDoc} */ - @Override public boolean detectLostPartitions(DiscoveryEvent discoEvt) { + @Override public void onExchangeDone(AffinityAssignment assignment) { lock.writeLock().lock(); try { - int parts = grp.affinity().partitions(); + if (assignment.topologyVersion().compareTo(diffFromAffinityVer) >= 0) + rebuildDiff(assignment); + } + finally { + lock.writeLock().unlock(); + } + } - Collection lost = null; + /** + * @param affAssignment New affinity assignment. + */ + private void rebuildDiff(AffinityAssignment affAssignment) { + assert lock.isWriteLockedByCurrentThread(); - for (int p = 0; p < parts; p++) { - boolean foundOwner = false; + if (node2part == null) + return; - Set nodeIds = part2node.get(p); + if (FAST_DIFF_REBUILD) { + Collection affNodes = F.nodeIds(ctx.discovery().cacheAffinityNodes(cctx.name(), affAssignment.topologyVersion())); - if (nodeIds != null) { - for (UUID nodeId : nodeIds) { - GridDhtPartitionMap partMap = node2part.get(nodeId); + for (Map.Entry> e : diffFromAffinity.entrySet()) { + int p = e.getKey(); - GridDhtPartitionState state = partMap.get(p); + Iterator iter = e.getValue().iterator(); - if (state == OWNING) { - foundOwner = true; + while (iter.hasNext()) { + UUID nodeId = iter.next(); - break; - } + if (!affNodes.contains(nodeId) || affAssignment.getIds(p).contains(nodeId)) + iter.remove(); + } + } + } + else { + for (Map.Entry e : node2part.entrySet()) { + UUID nodeId = e.getKey(); + + for (Map.Entry e0 : e.getValue().entrySet()) { + int p0 = e0.getKey(); + + GridDhtPartitionState state = e0.getValue(); + + Set ids = diffFromAffinity.get(p0); + + if ((state == MOVING || state == OWNING) && !affAssignment.getIds(p0).contains(nodeId)) { + if (ids == null) + diffFromAffinity.put(p0, ids = U.newHashSet(3)); + + ids.add(nodeId); + } + else { + if (ids != null) + ids.remove(nodeId); } } + } + } + + diffFromAffinityVer = affAssignment.topologyVersion(); + } + + /** {@inheritDoc} */ + @Override public boolean detectLostPartitions(DiscoveryEvent discoEvt) { + lock.writeLock().lock(); + + try { + if (node2part == null) + return false; + + int parts = grp.affinity().partitions(); - if (!foundOwner) { - if (lost == null) - lost = new HashSet<>(parts - p, 1.0f); + Set lost = new HashSet<>(parts); - lost.add(p); + for (int p = 0; p < parts; p++) + lost.add(p); + + for (GridDhtPartitionMap partMap : node2part.values()) { + for (Map.Entry e : partMap.entrySet()) { + if (e.getValue() == OWNING) + lost.remove(e.getKey()); } } boolean changed = false; - if (lost != null) { + if (!F.isEmpty(lost)) { PartitionLossPolicy plc = grp.config().getPartitionLossPolicy(); assert plc != null; @@ -1434,16 +1548,17 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { } // Update map for remote node. else if (plc != PartitionLossPolicy.IGNORE) { - Set nodeIds = part2node.get(part); - - if (nodeIds != null) { - for (UUID nodeId : nodeIds) { - GridDhtPartitionMap nodeMap = node2part.get(nodeId); - - if (nodeMap.get(part) != EVICTED) - nodeMap.put(part, LOST); - } - } + // TODO +// Set nodeIds = part2node.get(part); +// +// if (nodeIds != null) { +// for (UUID nodeId : nodeIds) { +// GridDhtPartitionMap nodeMap = node2part.get(nodeId); +// +// if (nodeMap.get(part) != EVICTED) +// nodeMap.put(part, LOST); +// } +// } } if (grp.eventRecordable(EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST)) { @@ -1468,86 +1583,83 @@ else if (plc != PartitionLossPolicy.IGNORE) { /** {@inheritDoc} */ @Override public void resetLostPartitions() { - lock.writeLock().lock(); - - try { - int parts = grp.affinity().partitions(); - long updSeq = updateSeq.incrementAndGet(); - - for (int part = 0; part < parts; part++) { - Set nodeIds = part2node.get(part); - - if (nodeIds != null) { - boolean lost = false; - - for (UUID node : nodeIds) { - GridDhtPartitionMap map = node2part.get(node); - - if (map.get(part) == LOST) { - lost = true; - - break; - } - } - - if (lost) { - GridDhtLocalPartition locPart = localPartition(part, topVer, false); - - if (locPart != null) { - boolean marked = locPart.own(); - - if (marked) - updateLocal(locPart.id(), locPart.state(), updSeq); - } - - for (UUID nodeId : nodeIds) { - GridDhtPartitionMap nodeMap = node2part.get(nodeId); - - if (nodeMap.get(part) == LOST) - nodeMap.put(part, OWNING); - } - } - } - } - - checkEvictions(updSeq, grp.affinity().assignments(topVer)); - - grp.needsRecovery(false); - } - finally { - lock.writeLock().unlock(); - } + // TODO + +// lock.writeLock().lock(); +// +// try { +// int parts = cctx.affinity().partitions(); +// long updSeq = updateSeq.incrementAndGet(); +// +// for (int part = 0; part < parts; part++) { +// Set nodeIds = part2node.get(part); +// +// if (nodeIds != null) { +// boolean lost = false; +// +// for (UUID node : nodeIds) { +// GridDhtPartitionMap2 map = node2part.get(node); +// +// if (map.get(part) == LOST) { +// lost = true; +// +// break; +// } +// } +// +// if (lost) { +// GridDhtLocalPartition locPart = localPartition(part, topVer, false); +// +// if (locPart != null) { +// boolean marked = locPart.own(); +// +// if (marked) +// updateLocal(locPart.id(), locPart.state(), updSeq); +// } +// +// for (UUID nodeId : nodeIds) { +// GridDhtPartitionMap2 nodeMap = node2part.get(nodeId); +// +// if (nodeMap.get(part) == LOST) +// nodeMap.put(part, OWNING); +// } +// } +// } +// } +// +// checkEvictions(updSeq, cctx.affinity().assignments(topVer)); +// +// cctx.needsRecovery(false); +// } +// finally { +// lock.writeLock().unlock(); +// } } /** {@inheritDoc} */ @Override public Collection lostPartitions() { + if (grp.config().getPartitionLossPolicy() == PartitionLossPolicy.IGNORE) + return Collections.emptySet(); + lock.readLock().lock(); try { - Collection res = null; + Set res = null; int parts = grp.affinity().partitions(); - for (int part = 0; part < parts; part++) { - Set nodeIds = part2node.get(part); - - if (nodeIds != null) { - for (UUID node : nodeIds) { - GridDhtPartitionMap map = node2part.get(node); - - if (map.get(part) == LOST) { - if (res == null) - res = new ArrayList<>(parts - part); + for (GridDhtPartitionMap partMap : node2part.values()) { + for (Map.Entry e : partMap.entrySet()) { + if (e.getValue() == LOST) { + if (res == null) + res = new HashSet<>(parts); - res.add(part); - - break; - } + res.add(e.getKey()); } } } - return res == null ? Collections.emptyList() : res; + return res == null ? Collections.emptySet() : res; } finally { lock.readLock().unlock(); @@ -1664,7 +1776,7 @@ private boolean checkEvictions(long updateSeq, List> aff) { List affNodes = aff.get(p); if (!affNodes.contains(ctx.localNode())) { - List nodes = nodes(p, topVer, OWNING); + List nodes = nodes(p, topVer, OWNING, null); Collection nodeIds = F.nodeIds(nodes); // If all affinity nodes are owners, then evict partition from local node. @@ -1778,12 +1890,18 @@ private long updateLocal(int p, GridDhtPartitionState state, long updateSeq) { map.put(p, state); - Set ids = part2node.get(p); + if (state == MOVING || state == OWNING) { + AffinityAssignment assignment = grp.affinity().assignment(diffFromAffinityVer); - if (ids == null) - part2node.put(p, ids = U.newHashSet(3)); + if (!assignment.getIds(p).contains(ctx.localNodeId())) { + Set diffIds = diffFromAffinity.get(p); - ids.add(locNodeId); + if (diffIds == null) + diffFromAffinity.put(p, diffIds = U.newHashSet(3)); + + diffIds.add(ctx.localNodeId()); + } + } } return updateSeq; @@ -1815,14 +1933,10 @@ private void removeNode(UUID nodeId) { if (parts != null) { for (Integer p : parts.keySet()) { - Set nodeIds = part2node.get(p); + Set diffIds = diffFromAffinity.get(p); - if (nodeIds != null) { - nodeIds.remove(nodeId); - - if (nodeIds.isEmpty()) - part2node.remove(p); - } + if (diffIds != null) + diffIds.remove(nodeId); } } @@ -2028,7 +2142,25 @@ private void updateRebalanceVersion(List> aff) { if (affNodes.isEmpty()) continue; - List owners = owners(i); + Set owners = U.newHashSet(affNodes.size()); + + for (ClusterNode node : affNodes) { + if (hasState(i, node.id(), OWNING)) + owners.add(node); + } + + Set diff = diffFromAffinity.get(i); + + if (diff != null) { + for (UUID nodeId : diff) { + if (hasState(i, nodeId, OWNING)) { + ClusterNode node = ctx.discovery().node(nodeId); + + if (node != null) + owners.add(node); + } + } + } if (affNodes.size() != owners.size() || !owners.containsAll(affNodes)) return; @@ -2077,30 +2209,7 @@ private boolean hasState(final int p, @Nullable UUID nodeId, final GridDhtPartit * Checks consistency after all operations. */ private void consistencyCheck() { - if (CONSISTENCY_CHECK) { - if (node2part == null) - return; - - for (Map.Entry e : node2part.entrySet()) { - for (Integer p : e.getValue().keySet()) { - Set nodeIds = part2node.get(p); - - assert nodeIds != null : "Failed consistency check [part=" + p + ", nodeId=" + e.getKey() + ']'; - assert nodeIds.contains(e.getKey()) : "Failed consistency check [part=" + p + ", nodeId=" + - e.getKey() + ", nodeIds=" + nodeIds + ']'; - } - } - - for (Map.Entry> e : part2node.entrySet()) { - for (UUID nodeId : e.getValue()) { - GridDhtPartitionMap map = node2part.get(nodeId); - - assert map != null : "Failed consistency check [part=" + e.getKey() + ", nodeId=" + nodeId + ']'; - assert map.containsKey(e.getKey()) : "Failed consistency check [part=" + e.getKey() + - ", nodeId=" + nodeId + ']'; - } - } - } + // no-op } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java index 75f836623549f..8bb6111b63e0e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java @@ -36,6 +36,7 @@ import org.apache.ignite.IgniteInterruptedException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.IgniteDiagnosticAware; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; @@ -100,7 +101,7 @@ */ @SuppressWarnings("unchecked") public final class GridDhtTxPrepareFuture extends GridCacheCompoundFuture - implements GridCacheMvccFuture { + implements GridCacheMvccFuture, IgniteDiagnosticAware { /** */ private static final long serialVersionUID = 0L; @@ -1566,6 +1567,33 @@ private Collection localDhtPendingVersions(Iterable { /** */ private boolean rcvRes; + /** Remap topology version for debug purpose. */ + private AffinityTopologyVersion remapTopVer; + /** * @param node Node. * @param keys Keys. @@ -1480,6 +1523,8 @@ void onResult(GridNearLockResponse res) { return; rcvRes = true; + + remapTopVer = res.clientRemapVersion(); } if (res.error() != null) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java index 0cead44656e19..589f603351286 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java @@ -28,6 +28,7 @@ import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; +import org.apache.ignite.internal.util.GridPartitionStateMap; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; @@ -50,7 +51,7 @@ public class GridDhtPartitionMap implements Comparable, Ext protected AffinityTopologyVersion top; /** */ - protected Map map; + protected GridPartitionStateMap map; /** */ private volatile int moving; @@ -81,7 +82,7 @@ public GridDhtPartitionMap(UUID nodeId, this.updateSeq = updateSeq; this.top = top; - map = U.newHashMap(m.size()); + map = new GridPartitionStateMap(m.size()); for (Map.Entry e : m.entrySet()) { GridDhtPartitionState state = e.getValue(); @@ -101,7 +102,7 @@ public GridDhtPartitionMap(UUID nodeId, private GridDhtPartitionMap(UUID nodeId, long updateSeq, AffinityTopologyVersion top, - Map map, + GridPartitionStateMap map, int moving) { this.nodeId = nodeId; this.updateSeq = updateSeq; @@ -117,7 +118,7 @@ public GridDhtPartitionMap emptyCopy() { return new GridDhtPartitionMap(nodeId, updateSeq, top, - U.newHashMap(0), + new GridPartitionStateMap(0), 0); } @@ -248,11 +249,11 @@ public AffinityTopologyVersion topologyVersion() { for (Map.Entry entry : map.entrySet()) { int ordinal = entry.getValue().ordinal(); - assert ordinal == (ordinal & 0x7); + assert ordinal == (ordinal & 0x3); assert entry.getKey() < CacheConfiguration.MAX_PARTITIONS_COUNT : entry.getKey(); - out.writeByte(ordinal); - out.writeShort(entry.getKey()); + int coded = (ordinal << 14) | entry.getKey(); + out.writeShort((short)coded); i++; } @@ -277,11 +278,13 @@ public AffinityTopologyVersion topologyVersion() { int size = in.readInt(); - map = U.newHashMap(size); + map = new GridPartitionStateMap(); for (int i = 0; i < size; i++) { - int ordinal = in.readByte(); - int part = in.readShort(); + int entry = in.readShort() & 0xFFFF; + + int part = entry & 0x3FFF; + int ordinal = entry >> 14; put(part, GridDhtPartitionState.fromOrdinal(ordinal)); } 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 88dc863c3a4d1..90eec85aa4e10 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 @@ -43,6 +43,7 @@ import org.apache.ignite.events.Event; import org.apache.ignite.events.EventType; import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException; +import org.apache.ignite.internal.IgniteDiagnosticAware; import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteInterruptedCheckedException; @@ -51,8 +52,9 @@ import org.apache.ignite.internal.events.DiscoveryCustomEvent; import org.apache.ignite.internal.managers.discovery.DiscoCache; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; +import org.apache.ignite.internal.managers.discovery.DiscoCache; +import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperation; -import org.apache.ignite.internal.pagemem.snapshot.SnapshotOperationType; import org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMessage; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; @@ -68,7 +70,6 @@ import org.apache.ignite.internal.processors.cache.ExchangeActions; 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.distributed.dht.GridClientPartitionTopology; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; @@ -79,6 +80,7 @@ import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor; import org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter; +import org.apache.ignite.internal.util.GridAtomicLong; import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -112,11 +114,14 @@ */ @SuppressWarnings({"TypeMayBeWeakened", "unchecked"}) public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter - implements Comparable, GridDhtTopologyFuture, CachePartitionExchangeWorkerTask { + implements Comparable, GridDhtTopologyFuture, CachePartitionExchangeWorkerTask, IgniteDiagnosticAware { /** */ public static final int DUMP_PENDING_OBJECTS_THRESHOLD = IgniteSystemProperties.getInteger(IgniteSystemProperties.IGNITE_DUMP_PENDING_OBJECTS_THRESHOLD, 10); + /** */ + public static final String EXCHANGE_LOG = "org.apache.ignite.internal.exchange.time"; + /** Dummy flag. */ private final boolean dummy; @@ -196,6 +201,8 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter msgs = new ConcurrentHashMap8<>(); /** */ + @GridToStringExclude private volatile IgniteDhtPartitionHistorySuppliersMap partHistSuppliers = new IgniteDhtPartitionHistorySuppliersMap(); /** Forced Rebalance future. */ @@ -237,6 +245,7 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter> partHistReserved; /** */ + @GridToStringExclude private volatile IgniteDhtPartitionsToReloadMap partsToReload = new IgniteDhtPartitionsToReloadMap(); /** */ @@ -266,6 +275,7 @@ public GridDhtPartitionsExchangeFuture( this.cctx = cctx; log = cctx.logger(getClass()); + exchLog = cctx.logger(EXCHANGE_LOG); onDone(exchId.topologyVersion()); } @@ -290,6 +300,7 @@ public GridDhtPartitionsExchangeFuture(GridCacheSharedContext cctx, DiscoveryEve this.forcedRebFut = forcedRebFut; log = cctx.logger(getClass()); + exchLog = cctx.logger(EXCHANGE_LOG); reassign = true; @@ -326,6 +337,7 @@ public GridDhtPartitionsExchangeFuture( this.affChangeMsg = affChangeMsg; log = cctx.logger(getClass()); + exchLog = cctx.logger(EXCHANGE_LOG); initFut = new GridFutureAdapter<>(); @@ -546,6 +558,14 @@ public void init() throws IgniteInterruptedCheckedException { skipPreload = cctx.kernalContext().clientNode(); + exchLog.info("Started exchange init [topVer=" + topVer + + ", crd=" + crdNode + + ", evt=" + discoEvt.type() + + ", node=" + discoEvt.node() + + ", evtNode=" + discoEvt.node() + + ", customEvt=" + (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT ? ((DiscoveryCustomEvent)discoEvt).customMessage() : null) + + ']'); + ExchangeType exchange; if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) { @@ -560,52 +580,6 @@ else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) { exchange = CU.clientNode(discoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode); - - StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg = (StartSnapshotOperationAckDiscoveryMessage)msg; - - if (!cctx.localNode().isDaemon()) { - SnapshotOperation op = snapshotOperationMsg.snapshotOperation(); - - if (op.type() == SnapshotOperationType.RESTORE) { - assert exchActions == null; - - exchActions = new ExchangeActions(); - - Set cacheNames = new HashSet<>(); - - Collection grpDescs = new ArrayList<>(); - - for (Integer grpId : op.cacheGroupIds()) { - CacheGroupContext cacheGrp = cctx.cache().cacheGroup(grpId); - - if (cacheGrp == null) - continue; - - grpDescs.add(cctx.cache().cacheGroupDescriptors().get(grpId)); - - for (Integer cacheId : cacheGrp.cacheIds()) - cacheNames.add(cctx.cacheContext(cacheId).name()); - } - - List destroyRequests = getStopCacheRequests( - cctx.cache(), cacheNames, cctx.localNodeId()); - - if (!F.isEmpty(destroyRequests)) { //Emulate destroy cache request - for (DynamicCacheChangeRequest req : destroyRequests) { - exchActions.addCacheToStop(req, cctx.cache() - .cacheDescriptor(CU.cacheId(req.cacheName()))); - } - - for (CacheGroupDescriptor grpDesc : grpDescs) - exchActions.addCacheGroupToStop(grpDesc); - - if (op.type() == SnapshotOperationType.RESTORE) - cctx.cache().onCustomEvent(new DynamicCacheChangeBatch(destroyRequests), topVer); - - onCacheChangeRequest(crdNode); - } - } - } } else { assert affChangeMsg != null : this; @@ -660,13 +634,10 @@ else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) { assert false; } - if (cctx.localNode().isClient()) { - StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg = getSnapshotOperationMessage(); + if (cctx.localNode().isClient()) + startLocalSnasphotOperation(); - // If it's a snapshot operation request, synchronously wait for backup start. - if (snapshotOperationMsg != null) - startLocalSnasphotOperation(snapshotOperationMsg); - } + exchLog.info("Finished exchange init [topVer=" + topVer + ", crd=" + crdNode + ']'); } catch (IgniteInterruptedCheckedException e) { onDone(e); @@ -690,36 +661,6 @@ else if (msg instanceof StartSnapshotOperationAckDiscoveryMessage) { } } - /** - * @param cache Cache. - * @param cacheNames Cache names. - * @param locNodeId Local node id. - */ - @NotNull public static List getStopCacheRequests(GridCacheProcessor cache, - Set cacheNames, UUID locNodeId) { - List destroyRequests = new ArrayList<>(); - - for (String cacheName : cacheNames) { - DynamicCacheDescriptor desc = cache.cacheDescriptor(CU.cacheId(cacheName)); - - if (desc == null) - continue; - - DynamicCacheChangeRequest t = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, locNodeId); - - t.stop(true); - t.destroy(false); - - t.deploymentId(desc.deploymentId()); - - t.restart(true); - - destroyRequests.add(t); - } - - return destroyRequests; - } - /** * @throws IgniteCheckedException If failed. */ @@ -948,16 +889,6 @@ private void distributedExchange() throws IgniteCheckedException { cctx.database().beforeExchange(this); - StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg = getSnapshotOperationMessage(); - - // If it's a snapshot operation request, synchronously wait for backup start. - if (snapshotOperationMsg != null) { - SnapshotOperation op = snapshotOperationMsg.snapshotOperation(); - - if (op.type() != SnapshotOperationType.RESTORE) - startLocalSnasphotOperation(snapshotOperationMsg); - } - if (crd.isLocal()) { if (remaining.isEmpty()) onAllReceived(); @@ -969,18 +900,23 @@ private void distributedExchange() throws IgniteCheckedException { } /** - * @param snapOpMsg Snapshot operation message. + */ - private void startLocalSnasphotOperation( - StartSnapshotOperationAckDiscoveryMessage snapOpMsg - ) throws IgniteCheckedException { - IgniteInternalFuture fut = cctx.snapshot().startLocalSnapshotOperation( - snapOpMsg.initiatorNodeId(), - snapOpMsg.snapshotOperation() - ); + private void startLocalSnasphotOperation() {StartSnapshotOperationAckDiscoveryMessage snapOpMsg= getSnapshotOperationMessage(); + if (snapOpMsg != null) { + SnapshotOperation op = snapOpMsg.snapshotOperation(); + + try { + IgniteInternalFuture fut = cctx.snapshot() + .startLocalSnapshotOperation(snapOpMsg.initiatorNodeId(), snapOpMsg.snapshotOperation()); - if (fut != null) - fut.get(); + if (fut != null) + fut.get(); + } + catch (IgniteCheckedException e) { + U.error(log, "Error while starting snapshot operation", e); + } + } } /** @@ -1340,6 +1276,8 @@ private boolean serverNodeDiscoveryEvent() { grpValidRes = m; } + startLocalSnasphotOperation(); + cctx.cache().onExchangeDone(exchId.topologyVersion(), exchActions, err, false); cctx.exchange().onExchangeDone(this, err); @@ -1347,20 +1285,6 @@ private boolean serverNodeDiscoveryEvent() { if (exchActions != null && err == null) exchActions.completeRequestFutures(cctx); - StartSnapshotOperationAckDiscoveryMessage snapshotOperationMsg = getSnapshotOperationMessage(); - - if (snapshotOperationMsg != null) { - SnapshotOperation op = snapshotOperationMsg.snapshotOperation(); - - if (op.type() == SnapshotOperationType.RESTORE) - try { - startLocalSnasphotOperation(snapshotOperationMsg); - } - catch (IgniteCheckedException e) { - log.error("Error while starting snapshot operation", e); - } - } - if (exchangeOnChangeGlobalState && err == null) cctx.kernalContext().state().onExchangeDone(); @@ -1380,6 +1304,15 @@ private boolean serverNodeDiscoveryEvent() { cctx.database().releaseHistoryForExchange(); + if (err == null && realExchange) { + for (GridCacheContext cacheCtx : cctx.cacheContexts()) { + if (cacheCtx.isLocal()) + continue; + + cacheCtx.topology().onExchangeDone(cacheCtx.affinity().assignment(topologyVersion())); + } + } + if (super.onDone(res, err) && realExchange) { if (log.isDebugEnabled()) log.debug("Completed partition exchange [localNode=" + cctx.localNodeId() + ", exchange= " + this + @@ -2121,7 +2054,8 @@ private void updatePartitionFullMap(GridDhtPartitionsFullMessage msg) { * @param msg Partitions single message. */ private void updatePartitionSingleMap(ClusterNode node, GridDhtPartitionsSingleMessage msg) { - msgs.put(node.id(), msg); + if (cctx.database().persistenceEnabled()) + msgs.put(node.id(), msg); for (Map.Entry entry : msg.partitions().entrySet()) { Integer grpId = entry.getKey(); @@ -2415,14 +2349,50 @@ private CacheValidation(boolean valid, Collection lostParts) { } } + /** {@inheritDoc} */ + @Override public void dumpDiagnosticInfo() { + if (!isDone()) { + ClusterNode crd; + Set remaining; + + synchronized (this) { + crd = this.crd; + remaining = new HashSet<>(this.remaining); + } + + if (crd != null) { + if (!crd.isLocal()) { + cctx.kernalContext().cluster().dumpExchangeInfo(crd.id(), topologyVersion(), "Exchange future waiting for coordinator " + + "response [crd=" + crd.id() + ", topVer=" + topologyVersion() + ']'); + } + else if (!remaining.isEmpty()){ + UUID nodeId = remaining.iterator().next(); + + cctx.kernalContext().cluster().dumpExchangeInfo(crd.id(), topologyVersion(), "Exchange future waiting for server " + + "response [node=" + nodeId + ", topVer=" + topologyVersion() + ']'); + } + } + } + } + + /** + * @return Short information string. + */ + public String shortInfo() { + return "GridDhtPartitionsExchangeFuture [topVer=" + topologyVersion() + + ", evt=" + (discoEvt != null ? discoEvt.type() : -1) + + ", evtNode=" + (discoEvt != null ? discoEvt.eventNode() : null) + + ", done=" + isDone() + ']'; + } + /** {@inheritDoc} */ @Override public String toString() { Set remaining; - List srvNodes; + int srvNodes; synchronized (this) { remaining = new HashSet<>(this.remaining); - srvNodes = this.srvNodes != null ? new ArrayList<>(this.srvNodes) : null; + srvNodes = this.srvNodes != null ? this.srvNodes.size() : 0; } return S.toString(GridDhtPartitionsExchangeFuture.class, this, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java index 52dcc5c6eca11..684ce13a4e7d8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java @@ -23,12 +23,15 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.events.DiscoveryEvent; +import org.apache.ignite.events.Event; +import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.NodeStoppingException; import org.apache.ignite.internal.processors.affinity.AffinityAssignment; @@ -250,11 +253,25 @@ private IgniteCheckedException stopError() { else { if (ctx.database().persistenceEnabled()) { if (part.state() == RENTING || part.state() == EVICTED) { - try { - part.rent(false).get(); - } - catch (IgniteCheckedException e) { - U.error(log, "Error while clearing outdated local partition", e); + IgniteInternalFuture rentFut = part.rent(false); + + while (true) { + try { + rentFut.get(20, TimeUnit.SECONDS); + + break; + } + catch (IgniteFutureTimeoutCheckedException ignore) { + // Continue. + U.warn(log, "Still waiting for partition eviction: " + part); + + part.tryEvictAsync(false); + } + catch (IgniteCheckedException e) { + U.error(log, "Error while clearing outdated local partition", e); + + break; + } } part = top.localPartition(p, topVer, true); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java index 075fb06596c4b..2396b109cae91 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java @@ -24,24 +24,49 @@ import java.util.Map; import java.util.Timer; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.events.DiscoveryEvent; +import org.apache.ignite.events.Event; import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.GridTopic; +import org.apache.ignite.internal.IgniteDiagnosticMessage; +import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.IgniteProperties; +import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.cluster.IgniteClusterImpl; +import org.apache.ignite.internal.managers.communication.GridIoPolicy; +import org.apache.ignite.internal.managers.communication.GridMessageListener; +import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener; import org.apache.ignite.internal.processors.GridProcessorAdapter; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.GridTimerTask; +import org.apache.ignite.internal.util.future.GridFinishedFuture; +import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl; import org.apache.ignite.internal.util.tostring.GridToStringExclude; +import org.apache.ignite.internal.util.typedef.CI1; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteClosure; import org.apache.ignite.lang.IgniteFuture; +import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.spi.discovery.DiscoveryDataBag; import org.apache.ignite.spi.discovery.DiscoveryDataBag.GridDiscoveryData; import org.jetbrains.annotations.Nullable; import static org.apache.ignite.IgniteSystemProperties.IGNITE_UPDATE_NOTIFIER; +import static org.apache.ignite.events.EventType.EVT_NODE_FAILED; +import static org.apache.ignite.events.EventType.EVT_NODE_LEFT; import static org.apache.ignite.internal.GridComponent.DiscoveryDataExchangeType.CLUSTER_PROC; import static org.apache.ignite.internal.IgniteVersionUtils.VER_STR; @@ -49,6 +74,13 @@ * */ public class ClusterProcessor extends GridProcessorAdapter { + /** */ + private final boolean DIAGNOSTIC_ENABLED = + IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_DIAGNOSTIC_ENABLED, false); + + /** */ + private static final String DIAGNOSTIC_LOG_CATEGORY = "org.apache.ignite.internal.diagnostic"; + /** */ private static final String ATTR_UPDATE_NOTIFIER_STATUS = "UPDATE_NOTIFIER_STATUS"; @@ -72,6 +104,16 @@ public class ClusterProcessor extends GridProcessorAdapter { @GridToStringExclude private GridUpdateNotifier verChecker; + /** */ + private final IgniteLogger diagnosticLog; + + /** */ + private final AtomicReference> diagnosticFutMap = + new AtomicReference<>(); + + /** */ + private final AtomicLong diagFutId = new AtomicLong(); + /** * @param ctx Kernal context. */ @@ -82,6 +124,102 @@ public ClusterProcessor(GridKernalContext ctx) { Boolean.parseBoolean(IgniteProperties.get("ignite.update.notifier.enabled.by.default")))); cluster = new IgniteClusterImpl(ctx); + + diagnosticLog = ctx.log(DIAGNOSTIC_LOG_CATEGORY); + } + + /** + * @throws IgniteCheckedException If failed. + */ + public void initListeners() throws IgniteCheckedException { + ctx.event().addLocalEventListener(new GridLocalEventListener() { + @Override public void onEvent(Event evt) { + assert evt instanceof DiscoveryEvent; + assert evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT; + + DiscoveryEvent discoEvt = (DiscoveryEvent)evt; + + UUID nodeId = discoEvt.eventNode().id(); + + ConcurrentHashMap futs = diagnosticFutMap.get(); + + if (futs != null) { + for (InternalDiagnosticFuture fut : futs.values()) { + if (fut.nodeId.equals(nodeId)) + fut.onDone("Target node failed: " + nodeId); + } + } + } + }, + EVT_NODE_FAILED, EVT_NODE_LEFT); + + ctx.io().addMessageListener(GridTopic.TOPIC_INTERNAL_DIAGNOSTIC, new GridMessageListener() { + @Override public void onMessage(UUID nodeId, Object msg) { + if (msg instanceof IgniteDiagnosticMessage) { + IgniteDiagnosticMessage msg0 = (IgniteDiagnosticMessage)msg; + + if (msg0.request()) { + ClusterNode node = ctx.discovery().node(nodeId); + + if (node == null) { + if (diagnosticLog.isDebugEnabled()) { + diagnosticLog.debug("Skip diagnostic request, sender node left " + + "[node=" + nodeId + ", msg=" + msg + ']'); + } + + return; + } + + String resMsg; + + IgniteClosure c; + + try { + c = msg0.unmarshalClosure(ctx); + + resMsg = c.apply(ctx); + } + catch (Exception e) { + U.error(diagnosticLog, "Failed to run diagnostic closure: " + e, e); + + resMsg = "Failed to run diagnostic closure: " + e; + } + + IgniteDiagnosticMessage res = IgniteDiagnosticMessage.createResponse(resMsg, msg0.futureId()); + + try { + ctx.io().sendToGridTopic(node, GridTopic.TOPIC_INTERNAL_DIAGNOSTIC, res, GridIoPolicy.SYSTEM_POOL); + } + catch (ClusterTopologyCheckedException ignore) { + if (diagnosticLog.isDebugEnabled()) { + diagnosticLog.debug("Failed to send diagnostic response, node left " + + "[node=" + nodeId + ", msg=" + msg + ']'); + } + } + catch (IgniteCheckedException e) { + U.error(diagnosticLog, "Failed to send diagnostic response [msg=" + msg0 + "]", e); + } + } + else { + InternalDiagnosticFuture fut = diagnosticFuturesMap().get(msg0.futureId()); + + if (fut != null) + fut.onResponse(msg0); + else + U.warn(diagnosticLog, "Failed to find diagnostic message future [msg=" + msg0 + ']'); + } + } + else + U.warn(diagnosticLog, "Received unexpected message: " + msg); + } + }); + } + + /** + * @return Logger for diagnostic category. + */ + public IgniteLogger diagnosticLog() { + return diagnosticLog; } /** @@ -214,6 +352,180 @@ public String latestVersion() { return verChecker != null ? verChecker.latestVersion() : null; } + /** + * @param nodeId Target node ID. + * @param dhtVer Tx dht version. + * @param nearVer Tx near version. + * @param msg Local message to log. + */ + public void dumpRemoteTxInfo(UUID nodeId, GridCacheVersion dhtVer, GridCacheVersion nearVer, final String msg) { + if (!DIAGNOSTIC_ENABLED) + return; + + IgniteInternalFuture fut = diagnosticInfo(nodeId, + new IgniteDiagnosticMessage.TxInfoClosure(ctx, dhtVer, nearVer), + msg); + + listenAndLog(fut); + } + + /** + * @param nodeId Target node ID. + * @param cacheId Cache ID. + * @param keys Keys. + * @param msg Local message to log. + */ + public void dumpTxKeyInfo(UUID nodeId, int cacheId, Collection keys, final String msg) { + if (!DIAGNOSTIC_ENABLED) + return; + + IgniteInternalFuture fut = diagnosticInfo(nodeId, new IgniteDiagnosticMessage.TxEntriesInfoClosure(ctx, cacheId, keys), msg); + + listenAndLog(fut); + } + + /** + * @param nodeId Target node ID. + * @param msg Local message to log. + */ + public void dumpBasicInfo(final UUID nodeId, final String msg, + @Nullable IgniteInClosure> lsnr) { + if (!DIAGNOSTIC_ENABLED) + return; + + IgniteInternalFuture fut = diagnosticInfo(nodeId, new IgniteDiagnosticMessage.BaseClosure(ctx), msg); + + if (lsnr != null) + fut.listen(lsnr); + + listenAndLog(fut); + } + + /** + * @param nodeId Target node ID. + * @param topVer Exchange topology version. + * @param msg Local message to log. + */ + public void dumpExchangeInfo(final UUID nodeId, AffinityTopologyVersion topVer, final String msg) { + if (!DIAGNOSTIC_ENABLED) + return; + + IgniteInternalFuture fut = diagnosticInfo(nodeId, new IgniteDiagnosticMessage.ExchangeInfoClosure(ctx, topVer), msg); + + listenAndLog(fut); + } + + /** + * @param fut Future. + */ + private void listenAndLog(IgniteInternalFuture fut) { + fut.listen(new CI1>() { + @Override public void apply(IgniteInternalFuture msgFut) { + try { + String msg = msgFut.get(); + + diagnosticLog.info(msg); + } + catch (Exception e) { + U.error(diagnosticLog, "Failed to dump diagnostic info: " + e, e); + } + } + }); + } + + /** + * @param nodeId Target node ID. + * @param c Closure. + * @param baseMsg Local message to log. + * @return Message future. + */ + private IgniteInternalFuture diagnosticInfo(final UUID nodeId, + IgniteClosure c, + final String baseMsg) { + final GridFutureAdapter infoFut = new GridFutureAdapter<>(); + + final IgniteInternalFuture rmtFut = sendDiagnosticMessage(nodeId, c); + + rmtFut.listen(new CI1>() { + @Override public void apply(IgniteInternalFuture fut) { + String rmtMsg; + + try { + rmtMsg = fut.get(); + } + catch (Exception e) { + rmtMsg = "Diagnostic processing error: " + e; + } + + final String rmtMsg0 = rmtMsg; + + IgniteInternalFuture locFut = IgniteDiagnosticMessage.dumpCommunicationInfo(ctx, nodeId); + + locFut.listen(new CI1>() { + @Override public void apply(IgniteInternalFuture locFut) { + String locMsg; + + try { + locMsg = locFut.get(); + } + catch (Exception e) { + locMsg = "Failed to get info for local node: " + e; + } + + String sb = baseMsg + U.nl() + + "Remote node information:" + U.nl() + rmtMsg0 + + U.nl() + "Local communication statistics:" + U.nl() + + locMsg; + + infoFut.onDone(sb); + } + }); + } + }); + + return infoFut; + } + + /** + * @param nodeId Target node ID. + * @param c Message closure. + * @return Message future. + */ + private IgniteInternalFuture sendDiagnosticMessage(UUID nodeId, IgniteClosure c) { + try { + IgniteDiagnosticMessage msg = IgniteDiagnosticMessage.createRequest(ctx, + c, + diagFutId.getAndIncrement()); + + InternalDiagnosticFuture fut = new InternalDiagnosticFuture(nodeId, msg.futureId()); + + diagnosticFuturesMap().put(msg.futureId(), fut); + + ctx.io().sendToGridTopic(nodeId, GridTopic.TOPIC_INTERNAL_DIAGNOSTIC, msg, GridIoPolicy.SYSTEM_POOL); + + return fut; + } + catch (Exception e) { + U.error(log, "Failed to send diagnostic message: " + e); + + return new GridFinishedFuture<>("Failed to send diagnostic message: " + e); + } + } + + /** + * @return Diagnostic messages futures map. + */ + private ConcurrentHashMap diagnosticFuturesMap() { + ConcurrentHashMap map = diagnosticFutMap.get(); + + if (map == null) { + if (!diagnosticFutMap.compareAndSet(null, map = new ConcurrentHashMap<>())) + map = diagnosticFutMap.get(); + } + + return map; + } + /** * Update notifier timer task. */ @@ -282,4 +594,46 @@ private UpdateNotifierTimerTask(IgniteKernal kernal, GridUpdateNotifier verCheck } } } + + /** + * + */ + class InternalDiagnosticFuture extends GridFutureAdapter { + /** */ + private final long id; + + /** */ + private final UUID nodeId; + + /** + * @param id Future ID. + */ + InternalDiagnosticFuture(UUID nodeId, long id) { + this.nodeId = nodeId; + this.id = id; + } + + /** + * @param msg Response message. + */ + public void onResponse(IgniteDiagnosticMessage msg) { + onDone(msg.message()); + } + + /** {@inheritDoc} */ + @Override public boolean onDone(@Nullable String res, @Nullable Throwable err) { + if (super.onDone(res, err)) { + diagnosticFuturesMap().remove(id); + + return true; + } + + return false; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(InternalDiagnosticFuture.class, this); + } + } } \ No newline at end of file diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java index df9d2699d9902..961fe46f06bca 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java @@ -317,11 +317,25 @@ private void startQuery() throws IgniteCheckedException { onKernalStart0(true); - for (Map.Entry e : dsMap.entrySet()) { - GridCacheRemovable v = e.getValue(); + restoreStructuresState(ctx); + } - if (v instanceof IgniteChangeGlobalStateSupport) - ((IgniteChangeGlobalStateSupport)v).onActivate(ctx); + /** + * @param ctx Context. + */ + public void restoreStructuresState(GridKernalContext ctx) { + onKernalStart0(true); + + try { + for (Map.Entry e : dsMap.entrySet()) { + GridCacheRemovable v = e.getValue(); + + if (v instanceof IgniteChangeGlobalStateSupport) + ((IgniteChangeGlobalStateSupport)v).onActivate(ctx); + } + } + catch (IgniteCheckedException e) { + U.error(log, "Failed restore data structures state", e); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridPartitionStateMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridPartitionStateMap.java new file mode 100644 index 0000000000000..72f8469216d30 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridPartitionStateMap.java @@ -0,0 +1,174 @@ +/* + * 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.util; + +import java.io.Externalizable; +import java.io.Serializable; +import java.util.AbstractMap; +import java.util.AbstractSet; +import java.util.BitSet; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; + +/** + * Grid partition state map. States are encoded using bits. + *

+ * Null values are prohibited. + */ +public class GridPartitionStateMap extends AbstractMap implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** Required bits to hold all state. Additional zero state is required as well. */ + private static final int BITS = Integer.SIZE - + Integer.numberOfLeadingZeros(GridDhtPartitionState.values().length + 1); + + /** */ + private final BitSet states; + + /** */ + private int size; + + /** {@inheritDoc} */ + @Override public Set> entrySet() { + return new AbstractSet>() { + @Override public Iterator> iterator() { + final int size = states.length() == 0 ? 0 : (states.length() - 1)/ BITS + 1; + + return new Iterator>() { + private int next; + private int cur; + + @Override public boolean hasNext() { + while(state(next) == null && next < size) + next++; + + return next < size; + } + + @Override public Entry next() { + cur = next; + next++; + + return new Entry() { + int p = cur; + + @Override public Integer getKey() { + return p; + } + + @Override public GridDhtPartitionState getValue() { + return state(p); + } + + @Override public GridDhtPartitionState setValue(GridDhtPartitionState val) { + return setState(p, val); + } + }; + } + + @Override public void remove() { + setState(cur, null); + } + }; + } + + @Override public int size() { + return GridPartitionStateMap.this.size(); + } + }; + } + + /** + * Default constructor. + */ + public GridPartitionStateMap() { + states = new BitSet(); + } + + /** + * @param parts Partitions to hold. + */ + public GridPartitionStateMap(int parts) { + states = new BitSet(parts); + } + + /** {@inheritDoc} */ + @Override public GridDhtPartitionState put(Integer key, GridDhtPartitionState val) { + assert val != null; + + return setState(key, val); + } + + /** {@inheritDoc} */ + @Override public GridDhtPartitionState get(Object key) { + return state((Integer)key); + } + + /** {@inheritDoc} */ + @Override public GridDhtPartitionState remove(Object key) { + return setState((Integer)key, null); + } + + /** {@inheritDoc} */ + @Override public boolean containsKey(Object key) { + return state((Integer)key) != null; + } + + /** {@inheritDoc} */ + @Override public int size() { + return size; + } + + /** */ + private GridDhtPartitionState setState(int part, GridDhtPartitionState st) { + GridDhtPartitionState old = state(part); + + if (old == st) + return old; + + int off = part * BITS; + + int ist = st == null ? 0 : st.ordinal() + 1; // Reserve all zero bits for empty value + + for (int i = 0; i < BITS; i++) { + states.set(off + i, (ist & 1) == 1); + + ist >>>= 1; + } + + size += (st == null ? -1 : old == null ? 1 : 0); + + return old; + } + + /** */ + private GridDhtPartitionState state(int part) { + int off = part * BITS; + + int st = 0; + + for (int i = 0; i < BITS; i++) + st |= ((states.get(off + i) ? 1 : 0) << i); + + return st == 0 ? null : GridDhtPartitionState.values()[st - 1]; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index ba4717abc74e4..e30333b1a70af 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -8567,6 +8567,18 @@ public static int hash(Object key) { return hash(key.hashCode()); } + /** + * A primitive override of {@link #hash(Object)} to avoid unnecessary boxing. + * + * @param key Value to hash. + * @return Hash value. + */ + public static int hash(long key) { + int val = (int)(key ^ (key >>> 32)); + + return hash(val); + } + /** * @return PID of the current JVM or {@code -1} if it can't be determined. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/OffheapReadWriteLock.java b/modules/core/src/main/java/org/apache/ignite/internal/util/OffheapReadWriteLock.java index 83765ce5eebb8..ee6a04d531481 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/OffheapReadWriteLock.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/OffheapReadWriteLock.java @@ -197,6 +197,8 @@ public boolean tryWriteLock(long lock, int tag) { * @param lock Lock address. */ public boolean writeLock(long lock, int tag) { + assert tag != 0; + for (int i = 0; i < SPIN_CNT; i++) { long state = GridUnsafe.getLongVolatile(null, lock); @@ -252,6 +254,8 @@ public boolean isReadLocked(long lock) { public void writeUnlock(long lock, int tag) { long updated; + assert tag != 0; + while (true) { long state = GridUnsafe.getLongVolatile(null, lock); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java index 66993ea3a4f01..d1e251f1f1cc3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java @@ -54,7 +54,9 @@ import org.apache.ignite.configuration.ConnectorConfiguration; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.managers.communication.GridIoMessage; import org.apache.ignite.internal.util.GridConcurrentHashSet; +import org.apache.ignite.internal.util.future.GridCompoundFuture; import org.apache.ignite.internal.util.nio.ssl.GridNioSslFilter; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.F; @@ -66,6 +68,7 @@ import org.apache.ignite.lang.IgniteBiInClosure; import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.lang.IgniteReducer; import org.apache.ignite.lang.IgniteRunnable; import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.plugin.extensions.communication.MessageReader; @@ -706,6 +709,7 @@ private GridNioFuture pauseResumeReads(GridNioSession ses, NioOperation op) { /** * */ + @SuppressWarnings("ForLoopReplaceableByForEach") public void dumpStats() { U.warn(log, "NIO server statistics [readerSesBalanceCnt=" + readerMoveCnt.get() + ", writerSesBalanceCnt=" + writerMoveCnt.get() + ']'); @@ -714,6 +718,51 @@ public void dumpStats() { clientWorkers.get(i).offer(new NioOperationFuture(null, NioOperation.DUMP_STATS)); } + /** + * @param msg Message to add. + * @param p Session predicate. + * @return Future. + */ + @SuppressWarnings("ForLoopReplaceableByForEach") + public IgniteInternalFuture dumpNodeStats(final String msg, IgnitePredicate p) { + GridCompoundFuture fut = new GridCompoundFuture<>(new IgniteReducer() { + private final StringBuilder sb = new StringBuilder(msg); + + @Override public boolean collect(@Nullable String msg) { + if (!F.isEmpty(msg)) { + synchronized (sb) { + if (sb.length() > 0) + sb.append(U.nl()); + + sb.append(msg); + } + } + + return true; + } + + @Override public String reduce() { + synchronized (sb) { + return sb.toString(); + } + } + }); + + for (int i = 0; i < clientWorkers.size(); i++) { + NioOperationFuture opFut = new NioOperationFuture<>(null, NioOperation.DUMP_STATS); + + opFut.msg = p; + + clientWorkers.get(i).offer(opFut); + + fut.add(opFut); + } + + fut.markInitialized(); + + return fut; + } + /** * Establishes a session. * @@ -1514,12 +1563,15 @@ private void processWrite0(SelectionKey key) throws IOException { */ private abstract class AbstractNioClientWorker extends GridWorker implements GridNioWorker { /** Queue of change requests on this selector. */ + @GridToStringExclude private final ConcurrentLinkedQueue changeReqs = new ConcurrentLinkedQueue<>(); /** Selector to select read events. */ + @GridToStringExclude private Selector selector; /** Selected keys. */ + @GridToStringExclude private SelectedSelectionKeySet selectedKeys; /** Worker index. */ @@ -1538,6 +1590,7 @@ private abstract class AbstractNioClientWorker extends GridWorker implements Gri private volatile long bytesSent0; /** Sessions assigned to this worker. */ + @GridToStringExclude private final GridConcurrentHashSet workerSessions = new GridConcurrentHashSet<>(); @@ -1812,12 +1865,28 @@ private void bodyInternal() throws IgniteCheckedException, InterruptedException case DUMP_STATS: { NioOperationFuture req = (NioOperationFuture)req0; - try { - dumpStats(); + if (req.msg instanceof IgnitePredicate) { + StringBuilder sb = new StringBuilder(); + + try { + dumpStats(sb, (IgnitePredicate)req.msg, true); + } + finally { + req.onDone(sb.toString()); + } } - finally { - // Complete the request just in case (none should wait on this future). - req.onDone(true); + else { + try { + StringBuilder sb = new StringBuilder(); + + dumpStats(sb, null, false); + + U.warn(log, sb.toString()); + } + finally { + // Complete the request just in case (none should wait on this future). + req.onDone(true); + } } } } @@ -1925,80 +1994,131 @@ public final void registerWrite(GridSelectorNioSessionImpl ses) { } /** - * + * @param sb Message builder. + * @param keys Keys. */ - private void dumpStats() { - StringBuilder sb = new StringBuilder(); - - Set keys = selector.keys(); - - sb.append(U.nl()) - .append(">> Selector info [idx=").append(idx) + private void dumpSelectorInfo(StringBuilder sb, Set keys) { + sb.append(">> Selector info [idx=").append(idx) .append(", keysCnt=").append(keys.size()) .append(", bytesRcvd=").append(bytesRcvd) .append(", bytesRcvd0=").append(bytesRcvd0) .append(", bytesSent=").append(bytesSent) .append(", bytesSent0=").append(bytesSent0) .append("]").append(U.nl()); + } + + /** + * @param sb Message builder. + * @param p Optional session predicate. + * @param shortInfo Short info flag. + */ + private void dumpStats(StringBuilder sb, + @Nullable IgnitePredicate p, + boolean shortInfo) { + Set keys = selector.keys(); + + boolean selInfo = p == null; + + if (selInfo) + dumpSelectorInfo(sb, keys); for (SelectionKey key : keys) { GridSelectorNioSessionImpl ses = (GridSelectorNioSessionImpl)key.attachment(); - MessageWriter writer = ses.meta(MSG_WRITER.ordinal()); - MessageReader reader = ses.meta(GridDirectParser.READER_META_KEY); + boolean sesInfo = p == null || p.apply(ses); - sb.append(" Connection info [") - .append("in=").append(ses.accepted()) - .append(", rmtAddr=").append(ses.remoteAddress()) - .append(", locAddr=").append(ses.localAddress()); + if (sesInfo) { + if (!selInfo) { + dumpSelectorInfo(sb, keys); - GridNioRecoveryDescriptor outDesc = ses.outRecoveryDescriptor(); + selInfo = true; + } - if (outDesc != null) { - sb.append(", msgsSent=").append(outDesc.sent()) - .append(", msgsAckedByRmt=").append(outDesc.acked()) - .append(", descIdHash=").append(System.identityHashCode(outDesc)); - } - else - sb.append(", outRecoveryDesc=null"); + sb.append(" Connection info [") + .append("in=").append(ses.accepted()) + .append(", rmtAddr=").append(ses.remoteAddress()) + .append(", locAddr=").append(ses.localAddress()); - GridNioRecoveryDescriptor inDesc = ses.inRecoveryDescriptor(); + GridNioRecoveryDescriptor outDesc = ses.outRecoveryDescriptor(); - if (inDesc != null) { - sb.append(", msgsRcvd=").append(inDesc.received()) - .append(", lastAcked=").append(inDesc.lastAcknowledged()) - .append(", descIdHash=").append(System.identityHashCode(inDesc)); - } - else - sb.append(", inRecoveryDesc=null"); + if (outDesc != null) { + sb.append(", msgsSent=").append(outDesc.sent()) + .append(", msgsAckedByRmt=").append(outDesc.acked()) + .append(", descIdHash=").append(System.identityHashCode(outDesc)); - sb.append(", bytesRcvd=").append(ses.bytesReceived()) - .append(", bytesRcvd0=").append(ses.bytesReceived0()) - .append(", bytesSent=").append(ses.bytesSent()) - .append(", bytesSent0=").append(ses.bytesSent0()) - .append(", opQueueSize=").append(ses.writeQueueSize()) - .append(", msgWriter=").append(writer != null ? writer.toString() : "null") - .append(", msgReader=").append(reader != null ? reader.toString() : "null"); + if (!outDesc.messagesRequests().isEmpty()) { + int cnt = 0; - int cnt = 0; + sb.append(", unackedMsgs=["); - for (SessionWriteRequest req : ses.writeQueue()) { - if (cnt == 0) - sb.append(",\n opQueue=[").append(req); + for (SessionWriteRequest req : outDesc.messagesRequests()) { + if (cnt != 0) + sb.append(", "); + + Object msg = req.message(); + + if (shortInfo && msg instanceof GridIoMessage) + msg = ((GridIoMessage)msg).message().getClass().getSimpleName(); + + sb.append(msg); + + if (++cnt == 5) + break; + } + + sb.append(']'); + } + } else - sb.append(',').append(req); + sb.append(", outRecoveryDesc=null"); - if (++cnt == 5) { - sb.append(']'); + GridNioRecoveryDescriptor inDesc = ses.inRecoveryDescriptor(); - break; + if (inDesc != null) { + sb.append(", msgsRcvd=").append(inDesc.received()) + .append(", lastAcked=").append(inDesc.lastAcknowledged()) + .append(", descIdHash=").append(System.identityHashCode(inDesc)); } - } + else + sb.append(", inRecoveryDesc=null"); - sb.append("]").append(U.nl()); - } + sb.append(", bytesRcvd=").append(ses.bytesReceived()) + .append(", bytesRcvd0=").append(ses.bytesReceived0()) + .append(", bytesSent=").append(ses.bytesSent()) + .append(", bytesSent0=").append(ses.bytesSent0()) + .append(", opQueueSize=").append(ses.writeQueueSize()); + + if (!shortInfo) { + MessageWriter writer = ses.meta(MSG_WRITER.ordinal()); + MessageReader reader = ses.meta(GridDirectParser.READER_META_KEY); + + sb.append(", msgWriter=").append(writer != null ? writer.toString() : "null") + .append(", msgReader=").append(reader != null ? reader.toString() : "null"); + } - U.warn(log, sb.toString()); + int cnt = 0; + + for (SessionWriteRequest req : ses.writeQueue()) { + Object msg = req.message(); + + if (shortInfo && msg instanceof GridIoMessage) + msg = ((GridIoMessage)msg).message().getClass().getSimpleName(); + + if (cnt == 0) + sb.append(",\n opQueue=[").append(msg); + else + sb.append(',').append(msg); + + if (++cnt == 5) { + sb.append(']'); + + break; + } + } + + sb.append("]"); + } + } } /** @@ -2037,7 +2157,14 @@ private void processSelectedKeysOptimized(SelectionKey[] keys) throws ClosedByIn // This exception will be handled in bodyInternal() method. throw e; } - catch (Exception e) { + catch (Exception | Error e) { // TODO IGNITE-2659. + try { + U.sleep(1000); + } + catch (IgniteInterruptedCheckedException ignore) { + // No-op. + } + U.warn(log, "Failed to process selector key (will close): " + ses, e); close(ses, new GridNioException(e)); @@ -2082,7 +2209,14 @@ private void processSelectedKeys(Set keys) throws ClosedByInterrup // This exception will be handled in bodyInternal() method. throw e; } - catch (Exception e) { + catch (Exception | Error e) { // TODO IGNITE-2659. + try { + U.sleep(1000); + } + catch (IgniteInterruptedCheckedException ignore) { + // No-op. + } + if (!closed) U.warn(log, "Failed to process selector key (will close): " + ses, e); diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java index 2e35c6ed719cb..b569aa2e8b3e3 100755 --- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java @@ -46,7 +46,6 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLException; import org.apache.ignite.Ignite; @@ -61,12 +60,14 @@ import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.events.Event; import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException; +import org.apache.ignite.internal.IgniteDiagnosticAware; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener; import org.apache.ignite.internal.util.GridConcurrentFactory; import org.apache.ignite.internal.util.GridSpinReadWriteLock; +import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.ipc.IpcEndpoint; import org.apache.ignite.internal.util.ipc.IpcToNioAdapter; @@ -238,7 +239,7 @@ */ @IgniteSpiMultipleInstancesSupport(true) @IgniteSpiConsistencyChecked(optional = false) -public class TcpCommunicationSpi extends IgniteSpiAdapter implements CommunicationSpi { +public class TcpCommunicationSpi extends IgniteSpiAdapter implements CommunicationSpi, IgniteDiagnosticAware { /** IPC error message. */ public static final String OUT_OF_RESOURCES_TCP_MSG = "Failed to allocate shared memory segment " + "(switching to TCP, may be slower)."; @@ -1763,19 +1764,71 @@ public CommunicationListener getListener() { rcvdBytesCnt.add(-rcvdBytesCnt.sum()); } + /** + * @param nodeId Target node ID. + * @return Future. + */ + public IgniteInternalFuture dumpNodeStatistics(final UUID nodeId) { + StringBuilder sb = new StringBuilder("Communication SPI statistics [rmtNode=").append(nodeId).append(']').append(U.nl()); + + dumpInfo(sb, nodeId); + + GridNioServer nioSrvr = this.nioSrvr; + + if (nioSrvr != null) { + sb.append("NIO sessions statistics:"); + + IgnitePredicate p = new IgnitePredicate() { + @Override public boolean apply(GridNioSession ses) { + ConnectionKey connId = ses.meta(CONN_IDX_META); + + return connId != null && nodeId.equals(connId.nodeId()); + } + }; + + return nioSrvr.dumpNodeStats(sb.toString(), p); + } + else { + sb.append(U.nl()).append("GridNioServer is null."); + + return new GridFinishedFuture<>(sb.toString()); + } + } + /** * Dumps SPI per-connection stats to logs. */ - public void dumpStats() { + @Override public void dumpDiagnosticInfo() { IgniteLogger log = this.log; if (log != null) { - StringBuilder sb = new StringBuilder("Communication SPI recovery descriptors: ").append(U.nl()); + StringBuilder sb = new StringBuilder(); - for (Map.Entry entry : recoveryDescs.entrySet()) { - GridNioRecoveryDescriptor desc = entry.getValue(); + dumpInfo(sb, null); - sb.append(" [key=").append(entry.getKey()) + U.warn(log, sb.toString()); + } + + GridNioServer nioSrvr = this.nioSrvr; + + if (nioSrvr != null) + nioSrvr.dumpStats(); + } + + /** + * @param sb Message builder. + * @param dstNodeId Target node ID. + */ + private void dumpInfo(StringBuilder sb, UUID dstNodeId) { + sb.append("Communication SPI recovery descriptors: ").append(U.nl()); + + for (Map.Entry entry : recoveryDescs.entrySet()) { + GridNioRecoveryDescriptor desc = entry.getValue(); + + if (dstNodeId != null && !dstNodeId.equals(entry.getKey().nodeId())) + continue; + + sb.append(" [key=").append(entry.getKey()) .append(", msgsSent=").append(desc.sent()) .append(", msgsAckedByRmt=").append(desc.acked()) .append(", msgsRcvd=").append(desc.received()) @@ -1783,12 +1836,15 @@ public void dumpStats() { .append(", reserveCnt=").append(desc.reserveCount()) .append(", descIdHash=").append(System.identityHashCode(desc)) .append(']').append(U.nl()); - } + } + + for (Map.Entry entry : outRecDescs.entrySet()) { + GridNioRecoveryDescriptor desc = entry.getValue(); - for (Map.Entry entry : outRecDescs.entrySet()) { - GridNioRecoveryDescriptor desc = entry.getValue(); + if (dstNodeId != null && !dstNodeId.equals(entry.getKey().nodeId())) + continue; - sb.append(" [key=").append(entry.getKey()) + sb.append(" [key=").append(entry.getKey()) .append(", msgsSent=").append(desc.sent()) .append(", msgsAckedByRmt=").append(desc.acked()) .append(", reserveCnt=").append(desc.reserveCount()) @@ -1796,12 +1852,15 @@ public void dumpStats() { .append(", reserved=").append(desc.reserved()) .append(", descIdHash=").append(System.identityHashCode(desc)) .append(']').append(U.nl()); - } + } + + for (Map.Entry entry : inRecDescs.entrySet()) { + GridNioRecoveryDescriptor desc = entry.getValue(); - for (Map.Entry entry : inRecDescs.entrySet()) { - GridNioRecoveryDescriptor desc = entry.getValue(); + if (dstNodeId != null && !dstNodeId.equals(entry.getKey().nodeId())) + continue; - sb.append(" [key=").append(entry.getKey()) + sb.append(" [key=").append(entry.getKey()) .append(", msgsRcvd=").append(desc.received()) .append(", lastAcked=").append(desc.lastAcknowledged()) .append(", reserveCnt=").append(desc.reserveCount()) @@ -1810,38 +1869,28 @@ public void dumpStats() { .append(", handshakeIdx=").append(desc.handshakeIndex()) .append(", descIdHash=").append(System.identityHashCode(desc)) .append(']').append(U.nl()); - } + } - sb.append("Communication SPI clients: ").append(U.nl()); + sb.append("Communication SPI clients: ").append(U.nl()); - for (Map.Entry entry : clients.entrySet()) { - UUID nodeId = entry.getKey(); - GridCommunicationClient[] clients0 = entry.getValue(); + for (Map.Entry entry : clients.entrySet()) { + UUID clientNodeId = entry.getKey(); - for (GridCommunicationClient client : clients0) { - if (client != null) { - sb.append(" [node=").append(nodeId) + if (dstNodeId != null && !dstNodeId.equals(clientNodeId)) + continue; + + GridCommunicationClient[] clients0 = entry.getValue(); + + for (GridCommunicationClient client : clients0) { + if (client != null) { + sb.append(" [node=").append(clientNodeId) .append(", client=").append(client) .append(']').append(U.nl()); - } } } - - U.warn(log, sb.toString()); } - - GridNioServer nioSrvr = this.nioSrvr; - - if (nioSrvr != null) - nioSrvr.dumpStats(); } - /** */ - private final ThreadLocal threadConnIdx = new ThreadLocal<>(); - - /** */ - private final AtomicInteger connIdx = new AtomicInteger(); - /** {@inheritDoc} */ @Override public Map getNodeAttributes() throws IgniteSpiException { initFailureDetectionTimeout(); @@ -2868,10 +2917,23 @@ protected GridCommunicationClient createTcpClient(ClusterNode node, int connIdx) // Try to connect first on bound addresses. if (isRmtAddrsExist) { - List addrs0 = new ArrayList<>(U.toSocketAddresses(rmtAddrs0, rmtHostNames0, boundPort)); - boolean sameHost = U.sameMacs(getSpiContext().localNode(), node); + List addrs0; + + Collection socketAddrs = U.toSocketAddresses(rmtAddrs0, rmtHostNames0, boundPort); + + if (sameHost) + addrs0 = new ArrayList<>(socketAddrs); + else { + addrs0 = new ArrayList<>(socketAddrs.size()); + + for (InetSocketAddress addr0 : socketAddrs) { + if (!addr0.getAddress().isLoopbackAddress()) + addrs0.add(addr0); + } + } + Collections.sort(addrs0, U.inetAddressesComparator(sameHost)); addrs = new LinkedHashSet<>(addrs0); @@ -3109,7 +3171,8 @@ else if (X.hasCause(e, SocketTimeoutException.class)) "in order to prevent parties from waiting forever in case of network issues " + "[nodeId=" + node.id() + ", addrs=" + addrs + ']'); - errs.addSuppressed(new IgniteCheckedException("Failed to connect to address: " + addr, e)); + errs.addSuppressed(new IgniteCheckedException("Failed to connect to address " + + "[addr=" + addr + ", err=" + e.getMessage() + ']', e)); // Reconnect for the second time, if connection is not established. if (!failureDetThrReached && connectAttempts < 2 && @@ -3139,11 +3202,10 @@ else if (X.hasCause(e, SocketTimeoutException.class)) if (getSpiContext().node(node.id()) != null && (CU.clientNode(node) || !CU.clientNode(getLocalNode())) && X.hasCause(errs, ConnectException.class, SocketTimeoutException.class, HandshakeTimeoutException.class, IgniteSpiOperationTimeoutException.class)) { - LT.warn(log, "TcpCommunicationSpi failed to establish connection to node, node will be dropped from " + + + U.error(log, "TcpCommunicationSpi failed to establish connection to node, node will be dropped from " + "cluster [" + - "rmtNode=" + node + - ", err=" + errs + - ", connectErrs=" + Arrays.toString(errs.getSuppressed()) + ']'); + "rmtNode=" + node + "]", errs); getSpiContext().failNode(node.id(), "TcpCommunicationSpi failed to establish connection to node [" + "rmtNode=" + node + @@ -4848,7 +4910,7 @@ private class TcpCommunicationSpiMBeanImpl extends IgniteSpiMBeanAdapter impleme /** {@inheritDoc} */ @Override public void dumpStats() { - TcpCommunicationSpi.this.dumpStats(); + TcpCommunicationSpi.this.dumpDiagnosticInfo(); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index 61ae27afdf5a3..fdc3d3454e660 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -2044,3 +2044,32 @@ org.apache.ignite.transactions.TransactionRollbackException org.apache.ignite.transactions.TransactionState org.apache.ignite.transactions.TransactionTimeoutException org.apache.ignite.util.AttributeNodeFilter +org.apache.ignite.internal.util.GridPartitionStateMap +org.gridgain.grid.cache.db.GridCacheOffheapManager$RebalanceIteratorAdapter +org.gridgain.grid.cache.db.wal.FileWriteAheadLogManager$FileArchiver$1 +org.gridgain.grid.cache.db.wal.FileWriteAheadLogManager$Mode +org.gridgain.grid.cache.db.wal.FileWriteAheadLogManager$RecordsIterator +org.gridgain.grid.internal.processors.cache.database.CollectDependantSnapshotSetTask +org.gridgain.grid.internal.processors.cache.database.CollectDependantSnapshotSetTask$CollectDependantSnapshotSetJob +org.gridgain.grid.internal.processors.cache.database.CollectSnapshotInfoTask +org.gridgain.grid.internal.processors.cache.database.CollectSnapshotInfoTask$CollectSnapshotInfoJob +org.gridgain.grid.internal.processors.cache.database.CollectSnapshotInfoTaskResult +org.gridgain.grid.internal.processors.cache.database.FullPageIdIterableComparator +org.gridgain.grid.internal.processors.cache.database.GetOngoingOperationTask +org.gridgain.grid.internal.processors.cache.database.GetOngoingOperationTask$GetOngoingOperationJob +org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$13 +org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$15 +org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$18 +org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$CheckpointEntryType +org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$Checkpointer$2 +org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$FullPageIdComparator +org.gridgain.grid.internal.processors.cache.database.SnapshotOperationFuture$1 +org.gridgain.grid.internal.processors.cache.database.SnapshotTaskBase +org.gridgain.grid.internal.processors.cache.database.messages.CheckSnapshotFinishedMessage +org.gridgain.grid.internal.processors.cache.database.messages.CheckSnapshotMetadataMessage +org.gridgain.grid.internal.processors.cache.database.messages.ClusterWideSnapshotOperationFinishedMessage +org.gridgain.grid.internal.processors.cache.database.messages.SnapshotIssueMessage +org.gridgain.grid.internal.processors.cache.database.messages.SnapshotOperationFinishedMessage +org.gridgain.grid.internal.processors.cache.database.messages.SnapshotProgressMessage +org.gridgain.grid.internal.visor.database.VisorCheckpointMetrics +org.gridgain.grid.internal.visor.database.VisorMemoryPoolMetrics diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/IgniteDiagnosticMessagesMultipleConnectionsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/IgniteDiagnosticMessagesMultipleConnectionsTest.java new file mode 100644 index 0000000000000..6b77704d7efdf --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/IgniteDiagnosticMessagesMultipleConnectionsTest.java @@ -0,0 +1,35 @@ +/* + * 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.managers; + +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; + +/** + * + */ +public class IgniteDiagnosticMessagesMultipleConnectionsTest extends IgniteDiagnosticMessagesTest { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + ((TcpCommunicationSpi)cfg.getCommunicationSpi()).setConnectionsPerNode(5); + + return cfg; + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/IgniteDiagnosticMessagesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/IgniteDiagnosticMessagesTest.java new file mode 100644 index 0000000000000..698cc1f478e91 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/IgniteDiagnosticMessagesTest.java @@ -0,0 +1,152 @@ +/* + * 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.managers; + +import java.util.concurrent.ThreadLocalRandom; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.util.future.GridFutureAdapter; +import org.apache.ignite.lang.IgniteInClosure; +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.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; + +/** + * + */ +public class IgniteDiagnosticMessagesTest extends GridCommonAbstractTest { + /** */ + private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + private boolean client; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); + + cfg.setClientMode(client); + + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setCacheMode(CacheMode.REPLICATED); + ccfg.setAtomicityMode(TRANSACTIONAL); + ccfg.setName("c1"); + + cfg.setCacheConfiguration(ccfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + System.setProperty(IgniteSystemProperties.IGNITE_DIAGNOSTIC_ENABLED, "true"); + + startGrids(3); + + client = true; + + startGrid(3); + + startGrid(4); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + System.setProperty(IgniteSystemProperties.IGNITE_DIAGNOSTIC_ENABLED, "false"); + + stopAllGrids(); + + super.afterTestsStopped(); + } + + /** + * @throws Exception If failed. + */ + public void testDiagnosticMessages() throws Exception { + awaitPartitionMapExchange(); + + sendDiagnostic(); + + for (int i = 0; i < 5; i++) { + final IgniteCache cache = ignite(i).cache("c1"); + + GridTestUtils.runMultiThreaded(new Runnable() { + @Override public void run() { + for (int j = 0; j < 10; j++) + cache.put(ThreadLocalRandom.current().nextInt(), j); + } + }, 10, "cache-thread"); + } + + sendDiagnostic(); + } + + /** + * @throws Exception If failed. + */ + private void sendDiagnostic() throws Exception { + for (int i = 0; i < 5; i++) { + IgniteKernal node = (IgniteKernal)ignite(i); + + for (int j = 0; j < 5; j++) { + if (i != j) { + ClusterNode dstNode = ignite(j).cluster().localNode(); + + final GridFutureAdapter fut = new GridFutureAdapter<>(); + + node.context().cluster().dumpBasicInfo(dstNode.id(), "Test diagnostic", + new IgniteInClosure>() { + @Override public void apply(IgniteInternalFuture diagFut) { + try { + fut.onDone(diagFut.get()); + } + catch (Exception e) { + fut.onDone(e); + } + } + } + ); + + String msg = fut.get(); + + assertTrue("Unexpected message: " + msg, + msg.contains("Test diagnostic") && + msg.contains("General node info [id=" + dstNode.id() + ", client=" + dstNode.isClient() + ", discoTopVer=AffinityTopologyVersion [topVer=5, minorTopVer=0]") && + msg.contains("Partitions exchange info [readyVer=AffinityTopologyVersion [topVer=5, minorTopVer=")); + } + } + } + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheClientsConcurrentStartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheClientsConcurrentStartTest.java new file mode 100644 index 0000000000000..58d4ea2c2af58 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheClientsConcurrentStartTest.java @@ -0,0 +1,250 @@ +/* + * 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 org.apache.ignite.Ignite; +import org.apache.ignite.IgniteAtomicSequence; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.TestRecordingCommunicationSpi; +import org.apache.ignite.internal.managers.communication.GridIoMessage; +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.IgniteBiPredicate; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.plugin.extensions.communication.Message; +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.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage; +import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.Socket; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; + +/** + * + */ +public class CacheClientsConcurrentStartTest extends GridCommonAbstractTest { + /** */ + private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final int SRV_CNT = 4; + + /** */ + private static final int CLIENTS_CNT = 16; + + /** */ + private static final int CACHES = 30; + + /** Stopped. */ + private volatile boolean stopped; + + /** Iteration. */ + private static final int ITERATIONS = 2; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + TcpDiscoverySpi testSpi = new TcpDiscoverySpi() { + @Override protected void writeToSocket(Socket sock, OutputStream out, TcpDiscoveryAbstractMessage msg, long timeout) throws IOException, IgniteCheckedException { + if (msg instanceof TcpDiscoveryCustomEventMessage && msg.verified()) { + try { + System.out.println(Thread.currentThread().getName() + " delay custom message"); + + U.sleep(ThreadLocalRandom.current().nextLong(500) + 100); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + super.writeToSocket(sock, out, msg, timeout); + } + }; + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); + + cfg.setMarshaller(null); + + cfg.setCommunicationSpi(new TestRecordingCommunicationSpi()); + + if (getTestIgniteInstanceIndex(gridName) >= SRV_CNT) + cfg.setClientMode(true); + else { + CacheConfiguration ccfgs[] = new CacheConfiguration[CACHES / 2]; + + for (int i = 0; i < ccfgs.length; i++) + ccfgs[i] = cacheConfiguration("cache-" + i); + + cfg.setCacheConfiguration(ccfgs); + } + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return 10 * 60 * 1000L; + } + + /** + * @throws Exception If failed. + */ + public void testStartNodes() throws Exception { + for (int i = 0; i < ITERATIONS; i++) { + try { + log.info("Iteration: " + (i + 1) + '/' + ITERATIONS); + + doTest(); + } + finally { + stopAllGrids(true); + } + } + } + + /** + * @throws Exception If failed. + */ + private void doTest() throws Exception { + final AtomicBoolean failed = new AtomicBoolean(); + + startGrids(SRV_CNT); + + for (int i = 0; i < SRV_CNT; i++) { + ((TestRecordingCommunicationSpi)ignite(i).configuration().getCommunicationSpi()).blockMessages(new IgniteBiPredicate() { + @Override public boolean apply(ClusterNode node, Message msg) { + if (msg instanceof GridDhtPartitionsFullMessage) { + try { + U.sleep(ThreadLocalRandom.current().nextLong(500) + 100); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + return false; + } + }); + } + + List> futs = new ArrayList<>(); + + for (int i = 0; i < CLIENTS_CNT; i++) { + final int idx = i; + + IgniteInternalFuture fut = multithreadedAsync(new Runnable() { + @Override public void run() { + Random rnd = new Random(); + + try { + Ignite ignite = startGrid(SRV_CNT + idx); + + assertTrue(ignite.configuration().isClientMode()); + + for (int i = 0; i < CACHES / 2; i++) { + String cacheName = "cache-" + rnd.nextInt(CACHES); + + IgniteCache cache = getCache(ignite, cacheName); + + cache.put(ignite.cluster().localNode().id(), UUID.randomUUID()); + + IgniteAtomicSequence seq = ignite.atomicSequence("seq-" + rnd.nextInt(20), 0, true); + + seq.getAndIncrement(); + } + + while (!stopped) { + IgniteCache cache = getCache(ignite, "cache-" + rnd.nextInt(CACHES)); + + int val = Math.abs(rnd.nextInt(100)); + + if (val >= 0 && val < 40) + cache.containsKey(ignite.cluster().localNode().id()); + else if (val >= 40 && val < 80) + cache.get(ignite.cluster().localNode().id()); + else + cache.put(ignite.cluster().localNode().id(), UUID.randomUUID()); + + Thread.sleep(10); + } + } + catch (Exception e) { + log.error("Unexpected error: " + e, e); + + failed.set(true); + } + } + }, 1, "client-thread"); + + futs.add(fut); + } + + Thread.sleep(10_000); + + stopped = true; + + for (IgniteInternalFuture fut : futs) + fut.get(); + + assertFalse(failed.get()); + } + + /** + * @param grid Grid. + * @return Cache. + */ + private IgniteCache getCache(Ignite grid, String cacheName) { + return grid.getOrCreateCache(cacheConfiguration(cacheName)); + } + + private CacheConfiguration cacheConfiguration(String cacheName) { + CacheConfiguration ccfg = defaultCacheConfiguration(); + + ccfg.setName(cacheName); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setBackups(2); + ccfg.setNearConfiguration(null); + ccfg.setAtomicityMode(TRANSACTIONAL); + + return ccfg; + } +} \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java index 1c8bede6b013a..c21d7068e2bee 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java @@ -73,9 +73,9 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio for (int i = 0; i < gridCount(); i++) { if (ignite(i).configuration().isClientMode()) { if (clientHasNearCache()) - ignite(i).createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>()); + ignite(i).getOrCreateCache(defaultCacheConfiguration(), new NearCacheConfiguration<>()); else - ignite(i).cache(DEFAULT_CACHE_NAME); + ignite(i).getOrCreateCache(DEFAULT_CACHE_NAME); break; } diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java index e938498a7d37f..0e31a45e7b3fd 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java @@ -1212,6 +1212,13 @@ protected Ignite startGrid(String igniteInstanceName, IgniteConfiguration cfg) t return startRemoteGrid(igniteInstanceName, cfg, null); } + /** + * @param cfg Config. + */ + protected Ignite startGrid(IgniteConfiguration cfg) throws Exception { + return startGrid(cfg.getIgniteInstanceName(), cfg); + } + /** * Loads configuration from the given Spring XML file. * 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 2ae92976acc9c..42d953419866f 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 @@ -32,6 +32,8 @@ import org.apache.ignite.cache.store.jdbc.GridCacheJdbcBlobStoreMultithreadedSelfTest; import org.apache.ignite.cache.store.jdbc.GridCacheJdbcBlobStoreSelfTest; import org.apache.ignite.cache.store.jdbc.JdbcTypesDefaultTransformerTest; +import org.apache.ignite.internal.managers.IgniteDiagnosticMessagesMultipleConnectionsTest; +import org.apache.ignite.internal.managers.IgniteDiagnosticMessagesTest; import org.apache.ignite.internal.managers.communication.IgniteCommunicationBalanceMultipleConnectionsTest; import org.apache.ignite.internal.managers.communication.IgniteCommunicationBalancePairedConnectionsTest; import org.apache.ignite.internal.managers.communication.IgniteCommunicationBalanceTest; @@ -305,6 +307,8 @@ public static TestSuite suite(Set ignoredTests) throws Exception { suite.addTestSuite(IgniteCommunicationBalancePairedConnectionsTest.class); suite.addTestSuite(IgniteCommunicationBalanceMultipleConnectionsTest.class); suite.addTestSuite(IgniteIoTestMessagesTest.class); + suite.addTestSuite(IgniteDiagnosticMessagesTest.class); + suite.addTestSuite(IgniteDiagnosticMessagesMultipleConnectionsTest.class); suite.addTestSuite(IgniteIncompleteCacheObjectSelfTest.class); diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java index b84daf11462c2..e7ce50ecb8e64 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java @@ -324,12 +324,14 @@ private List getAvailableInlineColumns(IndexColumn[] cols) { @Override public void destroy() { try { if (cctx.affinityNode()) { - for (int i = 0; i < segments.length; i++) { - H2Tree tree = segments[i]; + if (!cctx.kernalContext().cache().context().database().persistenceEnabled()) { + for (int i = 0; i < segments.length; i++) { + H2Tree tree = segments[i]; - tree.destroy(); + tree.destroy(); - dropMetaPage(tree.getName(), i); + dropMetaPage(tree.getName(), i); + } } } } diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index ff5dfa9bf50dd..1faffde9cee45 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -40,7 +40,6 @@ import java.util.List; import java.util.Map; import java.util.NavigableMap; -import java.util.Set; import java.util.TreeMap; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -77,6 +76,7 @@ import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.NodeStoppingException; import org.apache.ignite.internal.mem.DirectMemoryProvider; import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.pagemem.PageIdUtils; @@ -123,21 +123,22 @@ import org.apache.ignite.internal.util.future.CountDownFuture; import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.lang.GridInClosure3X; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.CI1; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.P3; import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.LT; +import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.SB; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.util.worker.GridWorker; import org.apache.ignite.lang.IgniteBiTuple; -import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.mxbean.PersistenceMetricsMXBean; import org.apache.ignite.thread.IgniteThread; import org.jetbrains.annotations.Nullable; -import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY; import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC; import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD; @@ -155,10 +156,6 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan /** */ private boolean skipCrc = IgniteSystemProperties.getBoolean(IGNITE_PDS_SKIP_CRC, false); - /** Checkpoint initiation delay after a partition has been scheduled for destroy. */ - private volatile long partDestroyCheckpointDelay = - IgniteSystemProperties.getLong(IGNITE_PDS_PARTITION_DESTROY_CHECKPOINT_DELAY, 30_000); - /** */ private final int walRebalanceThreshold = IgniteSystemProperties.getInteger( IGNITE_PDS_WAL_REBALANCE_THRESHOLD, 500_000); @@ -183,6 +180,13 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan } }; + /** */ + private static final Comparator ASC_PART_COMPARATOR = new Comparator() { + @Override public int compare(GridDhtLocalPartition a, GridDhtLocalPartition b) { + return Integer.compare(a.id(), b.id()); + } + }; + /** */ private static final Comparator CP_TS_COMPARATOR = new Comparator() { /** {@inheritDoc} */ @@ -702,6 +706,9 @@ private void shutdownCheckpointer(boolean cancel) { checkpointer = null; + cp.scheduledCp.cpFinishFut.onDone( + new NodeStoppingException("Checkpointer is stopped during node stop.")); + break; } catch (IgniteInterruptedCheckedException ignored) { @@ -1113,20 +1120,6 @@ public Map, T2> reservedForPreloading() { fut2.get(); } - /** - * Cancels partition destroy if it has not begun yet. Otherwise, will wait for cleanup to finish. - * - * @param grpId Cache group ID. - * @param partId Partition ID. - */ - void cancelOrWaitPartitionDestroy(int grpId, int partId) - throws IgniteCheckedException { - Checkpointer cp = checkpointer; - - if (cp != null) - cp.cancelOrWaitPartitionDestroy(grpId, partId); - } - /** * Tries to search for a WAL pointer for the given partition counter start. * @@ -1447,8 +1440,10 @@ else if (!F.eq(cpRec.checkpointId(), status.cpEndId)) } if (status.needRestoreMemory()) { - assert !apply : "Restoring memory state failed, checkpoint marker [cpId=" + status.cpStartId + - "] was not found in WAL"; + if (apply) + throw new IgniteCheckedException("Failed to restore memory state (checkpoint marker is present " + + "on disk, but checkpoint record is missed in WAL) " + + "[cpStatus=" + status + ", lastRead=" + lastRead + "]"); log.info("Finished applying memory changes [changesApplied=" + applied + ", time=" + (U.currentTimeMillis() - start) + "ms]"); @@ -1808,64 +1803,6 @@ private static String checkpointFileName(long cpTs, UUID cpId, CheckpointEntryTy return cpTs + "-" + cpId + "-" + type + ".bin"; } - /** - * @param reqs Destroy requests. - */ - @SuppressWarnings("TypeMayBeWeakened") - private void finishDestroyPartitionsAsync(final Collection reqs) { - final Map> filterMap = new HashMap<>(); - - final Set pageMemSet = new HashSet<>(); - - for (PartitionDestroyRequest req : reqs) { - Collection partIds = filterMap.get(req.grpId); - - if (partIds == null) { - partIds = new HashSet<>(); - - filterMap.put(req.grpId, partIds); - } - - partIds.add(req.partId); - - pageMemSet.add((PageMemoryEx)req.memPlc.pageMemory()); - } - - for (PageMemoryEx pageMem : pageMemSet) { - IgniteInternalFuture clearFut = pageMem.clearAsync(new P3() { - @Override public boolean apply(Integer grpId, Long pageId, Integer tag) { - assert grpId != null; - assert pageId != null; - - int partId = PageIdUtils.partId(pageId); - - Collection parts = filterMap.get(grpId); - - return parts != null && parts.contains(partId); - } - }, true); - - clearFut.listen(new IgniteInClosure>() { - @Override public void apply(IgniteInternalFuture clearFut) { - for (PartitionDestroyRequest req : reqs) { - try { - assert !req.allowFastEviction; - - // Tag should never grow in this case. - cctx.pageStore().onPartitionDestroyed(req.grpId, req.partId, 1); - } - catch (IgniteCheckedException e) { - req.onDone(e); - } - finally { - req.onDone(clearFut.error()); - } - } - } - }); - } - } - /** * */ @@ -1923,6 +1860,8 @@ protected Checkpointer(@Nullable String gridName, String name, IgniteLogger log) // Final run after the cancellation. if (checkpointsEnabled && !shutdownNow) doCheckpoint(); + + scheduledCp.cpFinishFut.onDone(new NodeStoppingException("Node is stopping.")); } /** @@ -1978,43 +1917,6 @@ public IgniteInternalFuture wakeupForSnapshotCreation(SnapshotOperation snapshot return ret; } - /** - * @param grp Cache group. - * @param partId Partition ID. - */ - private void schedulePartitionDestroy(CacheGroupContext grp, int partId) { - synchronized (this) { - scheduledCp.destroyQueue.addDestroyRequest(grp, partId); - } - - wakeupForCheckpoint(partDestroyCheckpointDelay, "partition destroy"); - } - - /** - * @param grpId Cache group ID. - * @param partId Partition ID. - */ - private void cancelOrWaitPartitionDestroy(int grpId, int partId) - throws IgniteCheckedException { - CheckpointProgress cur = curCpProgress; - - PartitionDestroyRequest req; - - if (cur != null) { - req = cur.destroyQueue.cancelDestroy(grpId, partId); - - if (req != null) - req.waitCompleted(); - } - - synchronized (this) { - req = scheduledCp.destroyQueue.cancelDestroy(grpId, partId); - } - - if (req != null) - req.waitCompleted(); - } - /** * */ @@ -2031,59 +1933,71 @@ private void doCheckpoint() { boolean interrupted = true; try { - // Identity stores set. - GridConcurrentHashSet updStores = new GridConcurrentHashSet<>(); + if (chp.hasDelta()) { + // Identity stores set. + GridConcurrentHashSet updStores = new GridConcurrentHashSet<>(); - CountDownFuture doneWriteFut = new CountDownFuture( - asyncRunner == null ? 1 : chp.cpPages.collectionsSize()); + CountDownFuture doneWriteFut = new CountDownFuture( + asyncRunner == null ? 1 : chp.cpPages.collectionsSize()); - tracker.onPagesWriteStart(); + tracker.onPagesWriteStart(); - if (asyncRunner != null) { - for (int i = 0; i < chp.cpPages.collectionsSize(); i++) { - Runnable write = new WriteCheckpointPages( - tracker, - chp.cpPages.innerCollection(i), - updStores, - doneWriteFut - ); + if (asyncRunner != null) { + for (int i = 0; i < chp.cpPages.collectionsSize(); i++) { + Runnable write = new WriteCheckpointPages( + tracker, + chp.cpPages.innerCollection(i), + updStores, + doneWriteFut + ); - try { - asyncRunner.execute(write); - } - catch (RejectedExecutionException ignore) { - // Run the task synchronously. - write.run(); + try { + asyncRunner.execute(write); + } + catch (RejectedExecutionException ignore) { + // Run the task synchronously. + write.run(); + } } } - } - else { - // Single-threaded checkpoint. - Runnable write = new WriteCheckpointPages(tracker, chp.cpPages, updStores, doneWriteFut); + else { + // Single-threaded checkpoint. + Runnable write = new WriteCheckpointPages(tracker, chp.cpPages, updStores, doneWriteFut); - write.run(); - } + write.run(); + } + + // Wait and check for errors. + doneWriteFut.get(); - // Wait and check for errors. - doneWriteFut.get(); + // Must re-check shutdown flag here because threads may have skipped some pages. + // If so, we should not put finish checkpoint mark. + if (shutdownNow) { + chp.progress.cpFinishFut.onDone(new NodeStoppingException("Node is stopping.")); - // Must re-check shutdown flag here because threads may have skipped some pages. - // If so, we should not put finish checkpoint mark. - if (shutdownNow) - return; + return; + } - snapshotMgr.afterCheckpointPageWritten(); + snapshotMgr.afterCheckpointPageWritten(); - tracker.onFsyncStart(); + tracker.onFsyncStart(); - if (!skipSync) { - for (PageStore updStore : updStores) { - if (shutdownNow) - return; + if (!skipSync) { + for (PageStore updStore : updStores) { + if (shutdownNow) { + chp.progress.cpFinishFut.onDone(new NodeStoppingException("Node is stopping.")); + + return; + } - updStore.sync(); + updStore.sync(); + } } } + else { + tracker.onPagesWriteStart(); + tracker.onFsyncStart(); + } // Must mark successful checkpoint only if there are no exceptions or interrupts. interrupted = false; @@ -2095,58 +2009,43 @@ private void doCheckpoint() { tracker.onEnd(); - // We finished this checkpoint, now it's time to clean up partitions. - PartitionDestroyQueue destroyQueue = chp.progress.destroyQueue; - - Collection reqs = null; - WALPointer lastPtr = null; - - for (T2 destroyId : destroyQueue.pendingReqs.keySet()) { - PartitionDestroyRequest req = destroyQueue.beginDestroy(destroyId); - - if (req != null) { - // Log destroy record before actual partition clear. - lastPtr = cctx.wal().log(new PartitionDestroyRecord(req.grpId, req.partId)); - - if (reqs == null) - reqs = new ArrayList<>(); - - reqs.add(req); + if (chp.hasDelta()) { + if (printCheckpointStats) { + if (log.isInfoEnabled()) + log.info(String.format("Checkpoint finished [cpId=%s, pages=%d, markPos=%s, " + + "walSegmentsCleared=%d, markDuration=%dms, pagesWrite=%dms, fsync=%dms, " + + "total=%dms]", + chp.cpEntry.checkpointId(), + pages, + chp.cpEntry.checkpointMark(), + chp.walFilesDeleted, + tracker.markDuration(), + tracker.pagesWriteDuration(), + tracker.fsyncDuration(), + tracker.totalDuration())); } - } - - if (reqs != null) { - assert lastPtr != null; - cctx.wal().fsync(lastPtr); - - finishDestroyPartitionsAsync(reqs); + persStoreMetrics.onCheckpoint( + tracker.lockWaitDuration(), + tracker.markDuration(), + tracker.pagesWriteDuration(), + tracker.fsyncDuration(), + tracker.totalDuration(), + pages, + tracker.dataPagesWritten(), + tracker.cowPagesWritten()); } - - if (printCheckpointStats) { - if (log.isInfoEnabled()) - log.info(String.format("Checkpoint finished [cpId=%s, pages=%d, markPos=%s, " + - "walSegmentsCleared=%d, markDuration=%dms, pagesWrite=%dms, fsync=%dms, " + - "total=%dms]", - chp.cpEntry.checkpointId(), - pages, - chp.cpEntry.checkpointMark(), - chp.walFilesDeleted, - tracker.markDuration(), - tracker.pagesWriteDuration(), - tracker.fsyncDuration(), - tracker.totalDuration())); + else { + persStoreMetrics.onCheckpoint( + tracker.lockWaitDuration(), + tracker.markDuration(), + tracker.pagesWriteDuration(), + tracker.fsyncDuration(), + tracker.totalDuration(), + pages, + tracker.dataPagesWritten(), + tracker.cowPagesWritten()); } - - persStoreMetrics.onCheckpoint( - tracker.lockWaitDuration(), - tracker.markDuration(), - tracker.pagesWriteDuration(), - tracker.fsyncDuration(), - tracker.totalDuration(), - pages, - tracker.dataPagesWritten(), - tracker.cowPagesWritten()); } catch (IgniteCheckedException e) { // TODO-ignite-db how to handle exception? @@ -2191,7 +2090,7 @@ private void waitCheckpointEvent() { private Checkpoint markCheckpointBegin(CheckpointMetricsTracker tracker) throws IgniteCheckedException { CheckpointRecord cpRec = new CheckpointRecord(null, false); - WALPointer cpPtr; + WALPointer cpPtr = null; GridMultiCollectionWrapper cpPages; @@ -2239,7 +2138,14 @@ private Checkpoint markCheckpointBegin(CheckpointMetricsTracker tracker) throws if (grp.isLocal()) continue; - CacheState state = new CacheState(); + List locParts = new ArrayList<>(); + + for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) + locParts.add(part); + + Collections.sort(locParts, ASC_PART_COMPARATOR); + + CacheState state = new CacheState(locParts.size()); for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) state.addPartitionState(part.id(), part.dataStore().fullSize(), part.lastAppliedUpdate()); @@ -2250,12 +2156,6 @@ private Checkpoint markCheckpointBegin(CheckpointMetricsTracker tracker) throws if (curr.nextSnapshot) snapshotMgr.onMarkCheckPointBegin(curr.snapshotOperation, map); - // No page updates for this checkpoint are allowed from now on. - cpPtr = cctx.wal().log(cpRec); - - if (cpPtr == null) - cpPtr = CheckpointStatus.NULL_PTR; - IgniteBiTuple>, Integer> tup = beginAllCheckpoints(); // Todo it maybe more optimally @@ -2267,6 +2167,14 @@ private Checkpoint markCheckpointBegin(CheckpointMetricsTracker tracker) throws } cpPages = new GridMultiCollectionWrapper<>(cpPagesList); + + if (!F.isEmpty(cpPages)) { + // No page updates for this checkpoint are allowed from now on. + cpPtr = cctx.wal().log(cpRec); + + if (cpPtr == null) + cpPtr = CheckpointStatus.NULL_PTR; + } } finally { checkpointLock.writeLock().unlock(); @@ -2276,34 +2184,50 @@ private Checkpoint markCheckpointBegin(CheckpointMetricsTracker tracker) throws curr.cpBeginFut.onDone(); - // Sync log outside the checkpoint write lock. - cctx.wal().fsync(cpPtr); + if (!F.isEmpty(cpPages)) { + assert cpPtr != null; - long cpTs = System.currentTimeMillis(); + // Sync log outside the checkpoint write lock. + cctx.wal().fsync(cpPtr); - CheckpointEntry cpEntry = writeCheckpointEntry( - tmpWriteBuf, - cpTs, - cpRec.checkpointId(), - cpPtr, - cpRec, - CheckpointEntryType.START); + long cpTs = System.currentTimeMillis(); - checkpointHist.addCheckpointEntry(cpEntry); + CheckpointEntry cpEntry = writeCheckpointEntry( + tmpWriteBuf, + cpTs, + cpRec.checkpointId(), + cpPtr, + cpRec, + CheckpointEntryType.START); - if (printCheckpointStats) - if (log.isInfoEnabled()) - log.info(String.format("Checkpoint started [checkpointId=%s, startPtr=%s, checkpointLockWait=%dms, " + - "checkpointLockHoldTime=%dms, pages=%d, reason='%s']", - cpRec.checkpointId(), - cpPtr, - tracker.lockWaitDuration(), - tracker.lockHoldDuration(), - cpPages.size(), - curr.reason) - ); + checkpointHist.addCheckpointEntry(cpEntry); + + if (printCheckpointStats) + if (log.isInfoEnabled()) + log.info(String.format("Checkpoint started [checkpointId=%s, startPtr=%s, checkpointLockWait=%dms, " + + "checkpointLockHoldTime=%dms, pages=%d, reason='%s']", + cpRec.checkpointId(), + cpPtr, + tracker.lockWaitDuration(), + tracker.lockHoldDuration(), + cpPages.size(), + curr.reason) + ); + + return new Checkpoint(cpEntry, cpPages, curr); + } + else { + if (printCheckpointStats) { + if (log.isInfoEnabled()) + LT.info(log, String.format("Skipping checkpoint (no pages were modified) [" + + "checkpointLockWait=%dms, checkpointLockHoldTime=%dms, reason='%s']", + tracker.lockWaitDuration(), + tracker.lockHoldDuration(), + curr.reason)); + } - return new Checkpoint(cpEntry, cpPages, curr); + return new Checkpoint(null, null, curr); + } } /** @@ -2333,16 +2257,17 @@ private void markCheckpointEnd(Checkpoint chp) throws IgniteCheckedException { for (MemoryPolicy memPlc : memoryPolicies()) ((PageMemoryEx)memPlc.pageMemory()).finishCheckpoint(); - writeCheckpointEntry( - tmpWriteBuf, - chp.cpEntry.checkpointTimestamp(), - chp.cpEntry.checkpointId(), - chp.cpEntry.checkpointMark(), - null, - CheckpointEntryType.END); + if (chp.hasDelta()) + writeCheckpointEntry( + tmpWriteBuf, + chp.cpEntry.checkpointTimestamp(), + chp.cpEntry.checkpointId(), + chp.cpEntry.checkpointMark(), + null, + CheckpointEntryType.END); } - chp.walFilesDeleted = checkpointHist.onCheckpointFinished(); + checkpointHist.onCheckpointFinished(chp); chp.progress.cpFinishFut.onDone(); } @@ -2493,6 +2418,12 @@ private static class Checkpoint { /** Number of deleted WAL files. */ private int walFilesDeleted; + /** Number of deleted WAL files. */ + private int walHistorySize; + + /** */ + private final int pagesSize; + /** * @param cpEntry Checkpoint entry. * @param cpPages Pages to write to the page store. @@ -2503,11 +2434,20 @@ private Checkpoint( GridMultiCollectionWrapper cpPages, CheckpointProgress progress ) { - assert cpEntry.initGuard != 0; + assert cpEntry == null || cpEntry.initGuard != 0; this.cpEntry = cpEntry; this.cpPages = cpPages; this.progress = progress; + + pagesSize = cpPages == null ? 0 : cpPages.size(); + } + + /** + * @return {@code true} if this checkpoint contains at least one dirty page. + */ + private boolean hasDelta() { + return pagesSize != 0; } } @@ -2528,12 +2468,14 @@ private static class CheckpointStatus { private UUID cpStartId; /** */ + @GridToStringInclude private WALPointer startPtr; /** */ private UUID cpEndId; /** */ + @GridToStringInclude private WALPointer endPtr; /** @@ -2556,6 +2498,11 @@ private CheckpointStatus(long cpStartTs, UUID cpStartId, WALPointer startPtr, UU public boolean needRestoreMemory() { return !F.eq(cpStartId, cpEndId) && !F.eq(NULL_UUID, cpStartId); } + + /** {@inheritDoc} */ + public String toString() { + return S.toString(CheckpointStatus.class, this); + } } /** @@ -2583,9 +2530,6 @@ private static class CheckpointProgress { /** Wakeup reason. */ private String reason; - /** */ - private final PartitionDestroyQueue destroyQueue = new PartitionDestroyQueue(); - /** * @param nextCpTs Next checkpoint timestamp. */ @@ -2699,7 +2643,7 @@ private void addCheckpointEntry(CheckpointEntry entry) { /** * Clears checkpoint history. */ - private int onCheckpointFinished() { + private void onCheckpointFinished(Checkpoint chp) { int deleted = 0; while (histMap.size() > persistenceCfg.getWalHistorySize()) { @@ -2707,8 +2651,12 @@ private int onCheckpointFinished() { CheckpointEntry cpEntry = entry.getValue(); - if (cctx.wal().reserved(cpEntry.checkpointMark())) + if (cctx.wal().reserved(cpEntry.checkpointMark())) { + U.warn(log, "Could not clear historyMap due to WAL reservation on cpEntry " + cpEntry.cpId + + ", history map size is " + histMap.size()); + break; + } File startFile = new File(cpDir.getAbsolutePath(), cpEntry.startFile()); File endFile = new File(cpDir.getAbsolutePath(), cpEntry.endFile()); @@ -2738,7 +2686,8 @@ private int onCheckpointFinished() { break; } - return deleted; + chp.walFilesDeleted = deleted; + chp.walHistorySize = histMap.size(); } /** @@ -2760,11 +2709,11 @@ private int onCheckpointFinished() { if (grpState == null) continue; - CacheState.PartitionState partState = grpState.partitions().get(partId); + long partCntr = grpState.counterByPartition(partId); - if (partState != null) { + if (partCntr >= 0) { if (cctx.wal().reserve(entry.checkpointMark())) - return partState.partitionCounter(); + return partCntr; } } catch (Exception e) { @@ -2888,9 +2837,9 @@ private Long partitionCounter(int grpId, int part) { CacheState state = cacheGrpStates.get(grpId); if (state != null) { - CacheState.PartitionState partState = state.partitions().get(part); + long cntr = state.counterByPartition(part); - return partState == null ? null : partState.partitionCounter(); + return cntr < 0 ? null : cntr; } return null; @@ -2930,157 +2879,6 @@ private void initIfNeeded(GridCacheSharedContext cctx) throws IgniteCheckedExcep } } - - - /** - * Partition destroy queue. - */ - private static class PartitionDestroyQueue { - /** */ - private final ConcurrentMap, PartitionDestroyRequest> pendingReqs = - new ConcurrentHashMap<>(); - - /** - * @param grp Cache group. - * @param partId Partition ID to destroy. - */ - private void addDestroyRequest(CacheGroupContext grp, int partId) { - PartitionDestroyRequest req = new PartitionDestroyRequest(grp, partId); - - PartitionDestroyRequest old = pendingReqs.putIfAbsent(new T2<>(grp.groupId(), partId), req); - - assert old == null : "Must wait for old destroy request to finish before adding a new one " + - "[grpId=" + grp.groupId() + ", name=" + grp.cacheOrGroupName() + ", partId=" + partId + ']'; - } - - /** - * @param destroyId Destroy ID. - * @return Destroy request to complete if was not concurrently cancelled. - */ - private PartitionDestroyRequest beginDestroy(T2 destroyId) { - PartitionDestroyRequest rmvd = pendingReqs.remove(destroyId); - - return rmvd == null ? null : rmvd.beginDestroy() ? rmvd : null; - } - - /** - * @param cacheId Cache ID. - * @param partId Partition ID. - * @return Destroy request to wait for if destroy has begun. - */ - private PartitionDestroyRequest cancelDestroy(int cacheId, int partId) { - PartitionDestroyRequest rmvd = pendingReqs.remove(new T2<>(cacheId, partId)); - - return rmvd == null ? null : !rmvd.cancel() ? rmvd : null; - } - } - - /** - * Partition destroy request. - */ - private static class PartitionDestroyRequest { - /** */ - private int grpId; - - /** */ - private final MemoryPolicy memPlc; - - /** */ - private String name; - - /** */ - private int partId; - - /** */ - private boolean allowFastEviction; - - /** Destroy cancelled flag. */ - private boolean cancelled; - - /** Destroy future. Not null if partition destroy has begun. */ - private GridFutureAdapter destroyFut; - - /** - * @param grp Cache group. - * @param partId Partition ID. - */ - private PartitionDestroyRequest(CacheGroupContext grp, int partId) { - grpId = grp.groupId(); - memPlc = grp.memoryPolicy(); - name = grp.cacheOrGroupName(); - allowFastEviction = grp.allowFastEviction(); - - this.partId = partId; - } - - /** - * Cancels partition destroy request. - * - * @return {@code False} if this request needs to be waited for. - */ - private synchronized boolean cancel() { - if (destroyFut != null) { - assert !cancelled; - - return false; - } - - cancelled = true; - - return true; - } - - /** - * Initiates partition destroy. - * - * @return {@code True} if destroy request should be executed, {@code false} otherwise. - */ - private synchronized boolean beginDestroy() { - if (cancelled) { - assert destroyFut == null; - - return false; - } - - if (destroyFut != null) - return false; - - destroyFut = new GridFutureAdapter<>(); - - return true; - } - - /** - * - */ - private synchronized void onDone(Throwable err) { - assert destroyFut != null; - - destroyFut.onDone(err); - } - - /** - * - */ - private void waitCompleted() throws IgniteCheckedException { - GridFutureAdapter fut; - - synchronized (this) { - assert destroyFut != null; - - fut = destroyFut; - } - - fut.get(); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return "PartitionDestroyRequest [grpId=" + grpId + ", name=" + name + - ", partId=" + partId + ']'; - } - } - /** * */ diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java index 3904205be9e17..c0176f658ea8b 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java @@ -137,9 +137,6 @@ public class GridCacheOffheapManager extends IgniteCacheOffheapManagerImpl imple throws IgniteCheckedException { GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)ctx.database(); - if (!grp.allowFastEviction()) - dbMgr.cancelOrWaitPartitionDestroy(grp.groupId(), p); - boolean exists = ctx.pageStore() != null && ctx.pageStore().exists(grp.groupId(), p); @@ -213,14 +210,24 @@ private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean sav try { long pageAddr = pageMem.writeLock(grpId, partMetaId, partMetaPage); + if (pageAddr == 0L) { + U.warn(log, "Failed to acquire write lock for meta page [metaPage=" + partMetaPage + + ", saveMeta=" + saveMeta + ", beforeDestroy=" + beforeDestroy + ", size=" + size + + ", updCntr=" + updCntr + ", state=" + state + ']'); + + return false; + } + + boolean changed = false; + try { PagePartitionMetaIO io = PageIO.getPageIO(pageAddr); - io.setUpdateCounter(pageAddr, updCntr); - io.setGlobalRemoveId(pageAddr, rmvId); - io.setSize(pageAddr, size); + changed |= io.setUpdateCounter(pageAddr, updCntr); + changed |= io.setGlobalRemoveId(pageAddr, rmvId); + changed |= io.setSize(pageAddr, size); - io.setPartitionState(pageAddr, (byte)state); + changed |= io.setPartitionState(pageAddr, (byte)state); long cntrsPageId; @@ -237,7 +244,10 @@ private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean sav if (init) { cntrsPageId = pageMem.allocatePage(grpId, store.partId(), PageIdAllocator.FLAG_DATA); + io.setCountersPageId(pageAddr, cntrsPageId); + + changed = true; } long nextId = cntrsPageId; @@ -256,6 +266,7 @@ private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean sav if (init) { partMetaIo = PagePartitionCountersIO.VERSIONS.latest(); + partMetaIo.initNewPage(curAddr, curId, pageSize); } else @@ -299,6 +310,7 @@ private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean sav try { long nextSnapshotTag = io.getNextSnapshotTag(metaPageAddr); + io.setNextSnapshotTag(metaPageAddr, nextSnapshotTag + 1); if (PageHandler.isWalDeltaRecordNeeded(pageMem, grpId, metaPageId, @@ -326,6 +338,8 @@ private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean sav partMap.get(store.partId()) == GridDhtPartitionState.OWNING) addPartition(ctx.partitionStatMap(), pageAddr, io, grpId, store.partId(), this.ctx.pageStore().pages(grpId, store.partId())); + + changed = true; } else pageCnt = io.getCandidatePageCount(pageAddr); @@ -343,7 +357,7 @@ private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean sav )); } finally { - pageMem.writeUnlock(grpId, partMetaId, partMetaPage, null, true); + pageMem.writeUnlock(grpId, partMetaId, partMetaPage, null, changed); } } finally { diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java index 93ee4119a7194..958e0ea30252c 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java @@ -1187,7 +1187,19 @@ private void writeUnlockPage( long pageId = PageIO.getPageId(page + PAGE_OVERHEAD); - rwLock.writeUnlock(page + PAGE_LOCK_OFFSET, PageIdUtils.tag(pageId)); + try { + rwLock.writeUnlock(page + PAGE_LOCK_OFFSET, PageIdUtils.tag(pageId)); + } + catch (AssertionError ex) { + StringBuilder sb = new StringBuilder(sysPageSize * 2); + + for (int i = 0; i < systemPageSize(); i += 8) + sb.append(U.hexLong(GridUnsafe.getLong(page + i))); + + U.error(log, "Failed to unlock page [fullPageId=" + fullId + ", binPage=" + sb + ']'); + + throw ex; + } } /** diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java index 36df2e7223d5a..8884fb3393c25 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java @@ -33,14 +33,29 @@ public class FileWALPointer implements WALPointer, Comparable { /** Written record length */ private int len; + /** Force flush flag. Used in BACKGROUND WAL mode. */ + private boolean forceFlush; + /** * @param idx File timestamp index. * @param fileOffset Offset in file, from the beginning. + * @param len Record length. */ public FileWALPointer(long idx, int fileOffset, int len) { + this(idx, fileOffset, len, false); + } + + /** + * @param idx File timestamp index. + * @param fileOffset Offset in file, from the beginning. + * @param len Record length. + * @param forceFlush Force flush flag. + */ + public FileWALPointer(long idx, int fileOffset, int len, boolean forceFlush) { this.idx = idx; this.fileOffset = fileOffset; this.len = len; + this.forceFlush = forceFlush; } /** @@ -81,6 +96,13 @@ public void length(int len) { return new FileWALPointer(idx, fileOffset + len, 0); } + /** + * @return Force flush flag. + */ + public boolean forceFlush() { + return forceFlush; + } + /** {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java index 3113c3ea77221..292118cb8ec01 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -52,6 +52,7 @@ import org.apache.ignite.internal.pagemem.wal.StorageException; import org.apache.ignite.internal.pagemem.wal.WALIterator; import org.apache.ignite.internal.pagemem.wal.WALPointer; +import org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord; import org.apache.ignite.internal.pagemem.wal.record.WALRecord; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; @@ -209,9 +210,9 @@ public FileWriteAheadLogManager(GridKernalContext ctx) { /** {@inheritDoc} */ @Override public void start0() throws IgniteCheckedException { - String consId = consistentId(); - if (!cctx.kernalContext().clientNode()) { + String consId = consistentId(); + A.notNullOrEmpty(consId, "consistentId"); consId = U.maskForFileName(consId); @@ -391,7 +392,7 @@ protected String consistentId() { /** {@inheritDoc} */ @Override public void fsync(WALPointer ptr) throws IgniteCheckedException, StorageException { - if (serializer == null || mode == Mode.NONE || mode == Mode.BACKGROUND) + if (serializer == null || mode == Mode.NONE) return; FileWriteHandle cur = currentHandle(); @@ -402,7 +403,12 @@ protected String consistentId() { FileWALPointer filePtr = (FileWALPointer)(ptr == null ? lastWALPtr.get() : ptr); - if (mode == Mode.LOG_ONLY) { + boolean forceFlush = filePtr != null && filePtr.forceFlush(); + + if (mode == Mode.BACKGROUND && !forceFlush) + return; + + if (mode == Mode.LOG_ONLY || forceFlush) { cur.flushOrWait(filePtr); return; @@ -1575,7 +1581,12 @@ private FileWriteHandle( rec.chainSize(newChainSize); rec.previous(h); - FileWALPointer ptr = new FileWALPointer(idx, (int)nextPos, rec.size()); + FileWALPointer ptr = new FileWALPointer( + idx, + (int)nextPos, + rec.size(), + // We need to force checkpoint records into file in BACKGROUND mode. + mode == Mode.BACKGROUND && rec instanceof CheckpointRecord); rec.position(ptr); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java index f39cdfdf84ec2..ce66b976ab1d7 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java @@ -1452,7 +1452,7 @@ private int cacheStatesSize(Map states) { CacheState state = entry.getValue(); // 2 bytes partition ID, size and counter per partition. - size += 18 * state.partitions().size(); + size += 18 * state.size(); } return size; @@ -1495,13 +1495,13 @@ private void putCacheStates(ByteBuffer buf, Map states) { CacheState state = entry.getValue(); // Need 2 bytes for the number of partitions. - buf.putShort((short)state.partitions().size()); + buf.putShort((short)state.size()); - for (Map.Entry partEntry : state.partitions().entrySet()) { - buf.putShort((short)(int)partEntry.getKey()); + for (int i = 0; i < state.size(); i++) { + buf.putShort((short)state.partitionByIndex(i)); - buf.putLong(partEntry.getValue().size()); - buf.putLong(partEntry.getValue().partitionCounter()); + buf.putLong(state.partitionSizeByIndex(i)); + buf.putLong(state.partitionCounterByIndex(i)); } } } @@ -1593,7 +1593,7 @@ private Map readPartitionStates(DataInput buf) throws IOExc int parts = buf.readShort() & 0xFFFF; - CacheState state = new CacheState(); + CacheState state = new CacheState(parts); for (int p = 0; p < parts; p++) { int partId = buf.readShort() & 0xFFFF; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java index 77715c33770d9..aec38746b2ac5 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java @@ -124,7 +124,6 @@ public void testReservedOnExchange() throws Exception { forceCheckpoint(); - Lock lock = cache.lock(0); lock.lock(); diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java index 602b2278497c5..d3b860c11907f 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java @@ -178,6 +178,14 @@ public class IgniteBenchmarkArguments { @Parameter(names = {"-kpt", "--keysPerThread"}, description = "Use not intersecting keys in putAll benchmark") private boolean keysPerThread; + /** */ + @Parameter(names = {"-pc", "--partitionedCachesNumber"}, description = "Number of partitioned caches") + private int partitionedCachesNumber = 1; + + /** */ + @Parameter(names = {"-rc", "--replicatedCachesNumber"}, description = "Number of replicated caches") + private int replicatedCachesNumber = 1; + /** */ @Parameter(names = {"-ac", "--additionalCachesNumber"}, description = "Number of additional caches") private int additionalCachesNum; @@ -198,6 +206,10 @@ public class IgniteBenchmarkArguments { @Parameter(names = {"-ps", "--pageSize"}, description = "Page size") private int pageSize = MemoryConfiguration.DFLT_PAGE_SIZE; + /** */ + @Parameter(names = {"-prt", "--partitions"}, description = "Number of cache partitions") + private int partitions = 10; + /** */ @Parameter(names = {"-cg", "--cacheGrp"}, description = "Cache group for caches") private String cacheGrp; @@ -476,6 +488,27 @@ public int getPageSize() { return pageSize; } + /** + * @return Number of partitioned caches. + */ + public int partitionedCachesNumber() { + return partitionedCachesNumber; + } + + /** + * @return Number of replicated caches. + */ + public int replicatedCachesNumber() { + return replicatedCachesNumber; + } + + /** + * @return Number of cache partitions. + */ + public int partitions() { + return partitions; + } + /** * @return Number of additional caches. */ From d52223aaa212f42fdccbba5262d3925715bd445d Mon Sep 17 00:00:00 2001 From: devozerov Date: Thu, 8 Jun 2017 14:51:40 +0300 Subject: [PATCH 240/311] WIP. --- .../ignite/internal/binary/BinaryContext.java | 42 +++---------------- .../CacheObjectBinaryProcessorImpl.java | 18 +++++++- 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java index be02ba1152e78..8f7720d9e43f5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java @@ -225,9 +225,6 @@ public class BinaryContext { /** Maps typeId to mappers. */ private final ConcurrentMap typeId2Mapper = new ConcurrentHashMap8<>(0); - /** Affinity key field names. */ - private final ConcurrentMap affKeyFieldNames = new ConcurrentHashMap8<>(0); - /** Maps className to mapper */ private final ConcurrentMap cls2Mappers = new ConcurrentHashMap8<>(0); @@ -325,6 +322,8 @@ public BinaryContext(BinaryMetadataHandler metaHnd, IgniteConfiguration igniteCf // Classes with overriden default serialization flag. registerPredefinedType(AffinityKey.class, 0, affinityFieldName(AffinityKey.class), false); + registerPredefinedType(CollocatedSetItemKey.class, 0, affinityFieldName(CollocatedSetItemKey.class), false); + registerPredefinedType(CollocatedQueueItemKey.class, 0, affinityFieldName(CollocatedQueueItemKey.class), false); registerPredefinedType(GridMapEntry.class, 60); registerPredefinedType(IgniteBiTuple.class, 61); @@ -472,19 +471,7 @@ private void configure( registerUserType(desc.clsName, desc.mapper, desc.serializer, desc.identity, desc.affKeyFieldName, desc.isEnum, desc.enumMap); - BinaryInternalMapper globalMapper = resolveMapper(globalNameMapper, globalIdMapper); - - // Put affinity field names for unconfigured types. - for (Map.Entry entry : affFields.entrySet()) { - String typeName = entry.getKey(); - - int typeId = globalMapper.typeId(typeName); - - affKeyFieldNames.putIfAbsent(typeId, entry.getValue()); - } - - addSystemClassAffinityKey(CollocatedSetItemKey.class); - addSystemClassAffinityKey(CollocatedQueueItemKey.class); + // TODO: Register rest classes from "affFields". } /** @@ -533,17 +520,6 @@ public static BinaryNameMapper defaultNameMapper() { return DFLT_MAPPER.nameMapper(); } - /** - * @param cls Class. - */ - private void addSystemClassAffinityKey(Class cls) { - String fieldName = affinityFieldName(cls); - - assert fieldName != null : cls; - - affKeyFieldNames.putIfAbsent(cls.getName().hashCode(), affinityFieldName(cls)); - } - /** * @param pkgName Package name. * @return Class names. @@ -1082,9 +1058,6 @@ public BinaryClassDescriptor registerPredefinedType(Class cls, int id, String descByCls.put(cls, desc); - if (affFieldName != null) - affKeyFieldNames.putIfAbsent(id, affFieldName); - return desc; } @@ -1133,11 +1106,6 @@ public void registerUserType(String clsName, throw duplicateTypeIdException(clsName, id); } - if (affKeyFieldName != null) { - if (affKeyFieldNames.put(id, affKeyFieldName) != null) - throw duplicateTypeIdException(clsName, id); - } - cls2Mappers.put(clsName, mapper); Map fieldsMeta = null; @@ -1248,7 +1216,9 @@ public BinaryType metadata(int typeId, int schemaId) throws BinaryObjectExceptio * @return Affinity key field name. */ public String affinityKeyFieldName(int typeId) { - return affKeyFieldNames.get(typeId); + BinaryMetadata meta = metaHnd.metadata0(typeId); + + return meta != null ? meta.affinityKeyFieldName() : null; } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java index a2d319f32573f..9dd3c6a33fa34 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java @@ -393,7 +393,21 @@ public GridBinaryMarshaller marshaller() { if (binaryCtx == null) return null; - return binaryCtx.affinityKeyFieldName(typeId(keyType)); + int typeId = typeId(keyType); + + return affinityField(typeId); + } + + /** + * Get affinity field. + * + * @param typeId Type ID. + * @return Affinity field. + */ + @Nullable private String affinityField(int typeId) { + BinaryMetadata meta = metadata0(typeId); + + return meta != null ? meta.affinityKeyFieldName() : null; } /** {@inheritDoc} */ @@ -673,7 +687,7 @@ public Object affinityKey(BinaryObject po) { else if (po instanceof BinaryObjectEx) { int typeId = ((BinaryObjectEx)po).typeId(); - String name = binaryCtx.affinityKeyFieldName(typeId); + String name = affinityField(typeId); if (name != null) return po.field(name); From 1a19b9004ab5317e8c620c55d5faa2f1a18db577 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Thu, 8 Jun 2017 15:46:34 +0300 Subject: [PATCH 241/311] IGNITE-5267 - Fixed compilation after merge. --- .../apache/ignite/IgniteSystemProperties.java | 3 ++ .../cache/CacheNodeCommonDiscoveryData.java | 16 ++++++- .../processors/cache/ClusterCachesInfo.java | 32 ++++++++++++- .../processors/cache/ExchangeActions.java | 15 +++++++ .../processors/cache/GridCacheGateway.java | 5 +-- .../GridCachePartitionExchangeManager.java | 2 +- .../processors/cache/GridCacheProcessor.java | 45 +++++++++++-------- .../dht/GridDhtPartitionTopologyImpl.java | 25 +++++------ .../dht/preloader/GridDhtPreloader.java | 1 - .../GridCacheAbstractFullApiSelfTest.java | 2 +- 10 files changed, 105 insertions(+), 41 deletions(-) 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 3eec36185d857..b77c98e1a9356 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -610,6 +610,9 @@ public final class IgniteSystemProperties { */ public static final String IGNITE_PDS_SKIP_CRC = "IGNITE_PDS_SKIP_CRC"; + /** */ + public static final String IGNITE_EXCHANGE_HISTORY_SIZE = "IGNITE_EXCHANGE_HISTORY_SIZE"; + /** * WAL rebalance threshold. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java index 4c70cb90d5d76..796ed9de4f22d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java @@ -18,6 +18,7 @@ package org.apache.ignite.internal.processors.cache; import java.io.Serializable; +import java.util.Collection; import java.util.Map; import java.util.UUID; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -45,6 +46,9 @@ class CacheNodeCommonDiscoveryData implements Serializable { /** */ private final Map> clientNodesMap; + /** */ + private Collection restartingCaches; + /** * @param caches Started caches. * @param templates Configured templates. @@ -54,7 +58,9 @@ class CacheNodeCommonDiscoveryData implements Serializable { CacheNodeCommonDiscoveryData(Map caches, Map templates, Map cacheGrps, - Map> clientNodesMap) { + Map> clientNodesMap, + Collection restartingCaches + ) { assert caches != null; assert templates != null; assert cacheGrps != null; @@ -64,6 +70,7 @@ class CacheNodeCommonDiscoveryData implements Serializable { this.templates = templates; this.cacheGrps = cacheGrps; this.clientNodesMap = clientNodesMap; + this.restartingCaches = restartingCaches; } /** @@ -94,6 +101,13 @@ Map> clientNodesMap() { return clientNodesMap; } + /** + * @return A collection of restarting cache names. + */ + Collection restartingCaches() { + return restartingCaches; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(CacheNodeCommonDiscoveryData.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index e5847016c3a40..b8cf6e13a9389 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -19,6 +19,7 @@ import java.io.Serializable; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -72,6 +73,9 @@ class ClusterCachesInfo { /** Cache templates. */ private final ConcurrentMap registeredTemplates = new ConcurrentHashMap<>(); + /** Caches currently being restarted. */ + private final Collection restartingCaches = new HashSet<>(); + /** */ private final IgniteLogger log; @@ -161,6 +165,7 @@ void onKernalStart(boolean checkConsistency) throws IgniteCheckedException { joinDiscoData = null; gridData = null; } + /** * Checks that remote caches has configuration compatible with the local. * @@ -324,6 +329,7 @@ boolean onCacheChangeRequested(DynamicCacheChangeBatch batch, AffinityTopologyVe AffinityTopologyVersion waitTopVer = null; if (req.start()) { + // Starting a new cache. if (desc == null) { String conflictErr = checkCacheConflict(req.startCacheConfiguration()); @@ -377,6 +383,8 @@ boolean onCacheChangeRequested(DynamicCacheChangeBatch batch, AffinityTopologyVe DynamicCacheDescriptor old = registeredCaches.put(ccfg.getName(), startDesc); + restartingCaches.remove(ccfg.getName()); + assert old == null; ctx.discovery().setCacheFilter( @@ -477,6 +485,9 @@ else if (req.stop()) { DynamicCacheDescriptor old = registeredCaches.remove(req.cacheName()); + if (req.restart()) + restartingCaches.add(req.cacheName()); + assert old != null && old == desc : "Dynamic cache map was concurrently modified [req=" + req + ']'; ctx.discovery().removeCacheFilter(req.cacheName()); @@ -572,6 +583,20 @@ void collectJoiningNodeData(DiscoveryDataBag dataBag) { dataBag.addJoiningNodeData(CACHE_PROC.ordinal(), joinDiscoveryData()); } + /** + * @return {@code True} if there are currently restarting caches. + */ + boolean hasRestartingCaches() { + return !F.isEmpty(restartingCaches); + } + + /** + * @return Collection of currently restarting caches. + */ + Collection restartingCaches() { + return restartingCaches; + } + /** * @return Discovery date sent on local node join. */ @@ -759,10 +784,13 @@ private CacheNodeCommonDiscoveryData collectCommonDiscoveryData() { templates.put(desc.cacheName(), cacheData); } + Collection restarting = new HashSet<>(restartingCaches); + return new CacheNodeCommonDiscoveryData(caches, templates, cacheGrps, - ctx.discovery().clientNodesMap()); + ctx.discovery().clientNodesMap(), + restarting); } /** @@ -1380,7 +1408,7 @@ void clearCaches() { /** * */ - static class GridData { + private static class GridData { /** */ private final CacheNodeCommonDiscoveryData gridData; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java index 8282b0c661bc4..3c2e47bb553c0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeActions.java @@ -27,6 +27,7 @@ import java.util.Set; import java.util.UUID; import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.CU; import org.jetbrains.annotations.Nullable; /** @@ -133,6 +134,20 @@ public void completeRequestFutures(GridCacheSharedContext ctx) { completeRequestFutures(cachesToResetLostParts, ctx); } + /** + * @return {@code True} if starting system caches. + */ + public boolean systemCachesStarting() { + if (cachesToStart != null) { + for (ActionData data : cachesToStart.values()) { + if (CU.isSystemCache(data.request().cacheName())) + return true; + } + } + + return false; + } + /** * @param map Actions map. * @param ctx Context. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java index 81c7b6bf7a1e1..b9a4b257b529f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java @@ -304,11 +304,8 @@ public void onStopped() { try { if (rwLock.writeLock().tryLock(200, TimeUnit.MILLISECONDS)) break; - else { + else U.sleep(200); - - ctx.affinity().cancelFutures(); - } } catch (IgniteInterruptedCheckedException | InterruptedException ignore) { interrupted = true; 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 2053c727956f0..e3b0ebf534763 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 @@ -121,7 +121,7 @@ public class GridCachePartitionExchangeManager extends GridCacheSharedManagerAdapter { /** Exchange history size. */ private static final int EXCHANGE_HISTORY_SIZE = - IgniteSystemProperties.getInteger("IGNITE_EXCHANGE_HISTORY_SIZE", 1000); + IgniteSystemProperties.getInteger(IgniteSystemProperties.IGNITE_EXCHANGE_HISTORY_SIZE, 1000); /** Atomic reference for pending timeout object. */ private AtomicReference pendingResend = new AtomicReference<>(); 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 99daafcf88324..958d9f345b4be 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 @@ -113,7 +113,6 @@ import org.apache.ignite.internal.processors.timeout.GridTimeoutObject; import org.apache.ignite.internal.suggestions.GridPerformanceSuggestions; import org.apache.ignite.internal.util.F0; -import org.apache.ignite.internal.util.GridConcurrentHashSet; import org.apache.ignite.internal.util.future.GridCompoundFuture; import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.internal.util.future.GridFutureAdapter; @@ -171,7 +170,7 @@ @SuppressWarnings({"unchecked", "TypeMayBeWeakened", "deprecation"}) public class GridCacheProcessor extends GridProcessorAdapter { /** */ - private final boolean START_CLIENT_CACHES = + private final boolean startClientCaches = IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_START_CACHES_ON_JOIN, false); /** Shared cache context. */ @@ -204,9 +203,6 @@ public class GridCacheProcessor extends GridProcessorAdapter { /** */ private ClusterCachesInfo cachesInfo; - /** Restarting caches */ - private final Set restartingCaches = new GridConcurrentHashSet<>(); - /** */ private IdentityHashMap sesHolders = new IdentityHashMap<>(); @@ -927,6 +923,8 @@ public Collection cacheGroups() { } }); + // Avoid iterator creation. + //noinspection ForLoopReplaceableByForEach for (int i = 0, size = syncFuts.size(); i < size; i++) syncFuts.get(i).get(); @@ -2117,7 +2115,7 @@ public void onExchangeDone( } } - if (exchActions != null && exchActions.systemCacheStarting()) + if (exchActions != null && exchActions.systemCachesStarting()) ctx.dataStructures().restoreStructuresState(ctx); if (exchActions != null && (err == null || forceClose)) { @@ -2327,7 +2325,7 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, * @return {@code True} if need locally start all existing caches on client node start. */ private boolean startAllCachesOnClientStart() { - return START_CLIENT_CACHES && ctx.clientNode(); + return startClientCaches && ctx.clientNode(); } /** {@inheritDoc} */ @@ -2463,10 +2461,7 @@ else if (dfltCacheCfg == null) private CacheConfiguration getOrCreateConfigFromTemplate(String cacheName) throws IgniteCheckedException { CacheConfiguration cfg = getConfigFromTemplate(cacheName); - if (cfg != null) - return cfg; - else - return new CacheConfiguration(cacheName); + return cfg != null ? cfg : new CacheConfiguration(cacheName); } /** @@ -3004,7 +2999,27 @@ else if (rebalanceOrder < 0) /** {@inheritDoc} */ @Nullable @Override public IgniteNodeValidationResult validateNode(ClusterNode node) { - return validateHashIdResolvers(node); + IgniteNodeValidationResult res = validateHashIdResolvers(node); + + if (res == null) + res = validateRestartingCaches(node); + + return res; + } + + /** + * @param node Joining node to validate. + * @return Node validation result if there was an issue with the joining node, {@code null} otherwise. + */ + private IgniteNodeValidationResult validateRestartingCaches(ClusterNode node) { + if (cachesInfo.hasRestartingCaches()) { + String msg = "Joining node during caches restart is not allowed [joiningNodeId=" + node.id() + + ", restartingCaches=" + new HashSet(cachesInfo.restartingCaches()) + ']'; + + return new IgniteNodeValidationResult(node.id(), msg, msg); + } + + return null; } /** @@ -3013,12 +3028,6 @@ else if (rebalanceOrder < 0) */ @Nullable private IgniteNodeValidationResult validateHashIdResolvers(ClusterNode node) { if (!node.isClient()) { - if (restartingCaches.size() > 0) { - String msg = "Joining server node during cache restarting is not allowed"; - - return new IgniteNodeValidationResult(node.id(), msg, msg); - } - for (DynamicCacheDescriptor desc : cacheDescriptors().values()) { CacheConfiguration cfg = desc.cacheConfiguration(); 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 d8c40188ee146..fa5a092790d4c 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 @@ -156,8 +156,6 @@ public GridDhtPartitionTopologyImpl(GridCacheSharedContext ctx, timeLog = ctx.logger(GridDhtPartitionsExchangeFuture.EXCHANGE_LOG); locParts = new AtomicReferenceArray<>(grp.affinityFunction().partitions()); - - part2node = new HashMap<>(grp.affinityFunction().partitions(), 1.0f); } /** {@inheritDoc} */ @@ -1138,10 +1136,10 @@ private List ownersAndMoving(int p, AffinityTopologyVersion topVer) node2part = partMap; - AffinityTopologyVersion affVer = ctx.affinity().affinityTopologyVersion(); + AffinityTopologyVersion affVer = grp.affinity().lastVersion(); if (diffFromAffinityVer.compareTo(affVer) <= 0) { - AffinityAssignment affAssignment = ctx.affinity().assignment(affVer); + AffinityAssignment affAssignment = grp.affinity().cachedAffinity(affVer); for (Map.Entry e : partMap.entrySet()) { for (Map.Entry e0 : e.getValue().entrySet()) { @@ -1370,7 +1368,7 @@ else if (locPart.state() == OWNING || locPart.state() == MOVING) { AffinityTopologyVersion affVer = grp.affinity().lastVersion(); if (affVer.compareTo(diffFromAffinityVer) >= 0) { - AffinityAssignment affAssignment = grp.affinity().assignment(affVer); + AffinityAssignment affAssignment = grp.affinity().cachedAffinity(affVer); // Add new mappings. for (Map.Entry e : parts.entrySet()) { @@ -1460,7 +1458,8 @@ private void rebuildDiff(AffinityAssignment affAssignment) { return; if (FAST_DIFF_REBUILD) { - Collection affNodes = F.nodeIds(ctx.discovery().cacheAffinityNodes(cctx.name(), affAssignment.topologyVersion())); + Collection affNodes = F.nodeIds(ctx.discovery().cacheGroupAffinityNodes(grp.groupId(), + affAssignment.topologyVersion())); for (Map.Entry> e : diffFromAffinity.entrySet()) { int p = e.getKey(); @@ -1891,17 +1890,17 @@ private long updateLocal(int p, GridDhtPartitionState state, long updateSeq) { map.put(p, state); if (state == MOVING || state == OWNING) { - AffinityAssignment assignment = grp.affinity().assignment(diffFromAffinityVer); + AffinityAssignment assignment = grp.affinity().cachedAffinity(diffFromAffinityVer); - if (!assignment.getIds(p).contains(ctx.localNodeId())) { - Set diffIds = diffFromAffinity.get(p); + if (!assignment.getIds(p).contains(ctx.localNodeId())) { + Set diffIds = diffFromAffinity.get(p); - if (diffIds == null) - diffFromAffinity.put(p, diffIds = U.newHashSet(3)); + if (diffIds == null) + diffFromAffinity.put(p, diffIds = U.newHashSet(3)); - diffIds.add(ctx.localNodeId()); - } + diffIds.add(ctx.localNodeId()); } + } } return updateSeq; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java index 684ce13a4e7d8..c71c3cc57b2ac 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java @@ -30,7 +30,6 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.events.DiscoveryEvent; -import org.apache.ignite.events.Event; import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.NodeStoppingException; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java index bf27e26b91e16..551d56555264f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java @@ -925,7 +925,7 @@ public void testGetAllWithNulls() throws Exception { final Set c = new HashSet<>(); c.add("key1"); - c.add(null); +// c.add(null); GridTestUtils.assertThrows(log, new Callable() { @Override public Void call() throws Exception { From 52640357b1c170b6917339dcb5933ec9fcc4e81a Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Thu, 8 Jun 2017 16:17:53 +0300 Subject: [PATCH 242/311] IGNITE-5068 - Fixed lost partitions handling --- .../distributed/dht/GridDhtPartitionTopologyImpl.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 626ae0a3b99c3..0e7803290e2a0 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 @@ -55,6 +55,7 @@ import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.X; import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.LT; import org.apache.ignite.internal.util.typedef.internal.U; import org.jetbrains.annotations.Nullable; @@ -71,9 +72,6 @@ @GridToStringExclude public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology { private static final GridDhtPartitionState[] MOVING_STATES = new GridDhtPartitionState[] {MOVING}; - /** If true, then check consistency. */ - private static final boolean CONSISTENCY_CHECK = false; - /** Flag to control amount of output for full map. */ private static final boolean FULL_MAP_DEBUG = false; @@ -886,7 +884,8 @@ else if (loc != null && state == RENTING && !showRenting) List nodes = null; if (!topVer.equals(diffFromAffinityVer)) { - log.error("??? node2part [topVer=" + topVer + ", diffVer=" + diffFromAffinityVer + "]"); + LT.warn(log, "Requested topology version does not match calculated diff, will require full iteration to" + + "calculate mapping [topVer=" + topVer + ", diffVer=" + diffFromAffinityVer + "]"); nodes = new ArrayList<>(); @@ -1599,9 +1598,9 @@ else if (plc != PartitionLossPolicy.IGNORE) { } } - checkEvictions(updSeq, cctx.affinity().assignments(topVer)); + checkEvictions(updSeq, grp.affinity().assignments(topVer)); - cctx.needsRecovery(false); + grp.needsRecovery(false); } finally { lock.writeLock().unlock(); From eff3e09cb66738e987f7993a7d68e2278c4afe95 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Thu, 8 Jun 2017 16:58:10 +0300 Subject: [PATCH 243/311] IGNITE-5267 - Fixed CacheState record --- .../ignite/internal/pagemem/wal/record/CacheState.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CacheState.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CacheState.java index 1c8b04a595e37..41d38d0c36e82 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CacheState.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/CacheState.java @@ -24,7 +24,7 @@ */ public class CacheState { /** */ - private short[] parts; + private int[] parts; /** */ private long[] vals; @@ -36,7 +36,7 @@ public class CacheState { * @param partsCnt Partitions count. */ public CacheState(int partsCnt) { - parts = new short[partsCnt]; + parts = new int[partsCnt]; vals = new long[partsCnt * 2]; } @@ -56,7 +56,7 @@ public void addPartitionState(int partId, long size, long cntr) { ", cur=" + partId + ']'); } - parts[idx] = (short)partId; + parts[idx] = partId; vals[2 * idx] = size; vals[2 * idx + 1] = cntr; @@ -92,7 +92,7 @@ public long counterByPartition(int partId) { * @return Partition ID. */ public int partitionByIndex(int idx) { - return parts[idx] & 0xFFFF; + return parts[idx]; } /** @@ -123,7 +123,7 @@ public int size() { * @return Non-negative index of partition if found or negative value if not found. */ private int indexByPartition(int partId) { - return Arrays.binarySearch(parts, 0, idx, (short)partId); + return Arrays.binarySearch(parts, 0, idx, partId); } /** {@inheritDoc} */ From cd4d04007ca7ad1bfbd7f358f9182f970d38ec3e Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Thu, 8 Jun 2017 19:10:54 +0300 Subject: [PATCH 244/311] IGNITE-5267 - Moved WAL system properties to WAL configuration --- .../PersistentStoreConfiguration.java | 158 ++++++++++- .../apache/ignite/configuration/WALMode.java | 43 +++ .../GridCacheDatabaseSharedManager.java | 2 +- .../wal/FileWriteAheadLogManager.java | 245 +++++++++--------- ... IgnitePdsAtomicCacheRebalancingTest.java} | 2 +- ...gnitePdsCacheRebalancingAbstractTest.java} | 39 +-- ...> IgnitePdsClientNearCachePutGetTest.java} | 13 +- ...va => IgnitePdsContinuousRestartTest.java} | 26 +- ...st.java => IgnitePdsDynamicCacheTest.java} | 60 ++--- ... IgnitePdsMultiNodePutGetRestartTest.java} | 4 +- ...sTest.java => IgnitePdsPageSizesTest.java} | 26 +- ...tePdsRecoveryAfterFileCorruptionTest.java} | 24 +- ...IgnitePdsRemoveDuringRebalancingTest.java} | 35 +-- ...tePdsSingleNodePutGetPersistenceTest.java} | 13 +- ...ingAndGroupPutGetPersistenceSelfTest.java} | 4 +- ...odeWithIndexingPutGetPersistenceTest.java} | 13 +- ...a => IgnitePdsTxCacheRebalancingTest.java} | 2 +- .../IgnitePersistenceMetricsSelfTest.java | 14 +- .../IgnitePersistentStoreCacheGroupsTest.java | 14 +- ...nitePersistentStoreDataStructuresTest.java | 13 +- ... IgnitePdsMultiNodePutGetRestartTest.java} | 14 +- ...PageEvictionDuringPartitionClearTest.java} | 15 +- ...st.java => IgnitePdsPageEvictionTest.java} | 18 +- ...dsRebalancingOnNotStableTopologyTest.java} | 15 +- ...ava => IgnitePdsTransactionsHangTest.java} | 19 +- ... => IgnitePdsWholeClusterRestartTest.java} | 18 +- ...ava => IgnitePdsCacheIntegrationTest.java} | 19 +- ...lfTest.java => IgnitePdsEvictionTest.java} | 2 +- ...a => IgnitePdsNoActualWalHistoryTest.java} | 22 +- ...=> ignitePdsCheckpointSimulationTest.java} | 44 ++-- .../wal/IgnitePdsWalTlbTest.java} | 16 +- ...IgniteWalDirectoriesConfigurationTest.java | 2 +- .../IgniteWalHistoryReservationsTest.java} | 4 +- .../IgniteWalRecoverySeveralRestartsTest.java | 15 +- .../IgniteWalRecoveryTest.java} | 34 +-- .../WalRecoveryTxLogicalRecordsTest.java | 4 +- ....java => BPlusTreePageMemoryImplTest.java} | 17 +- ...BPlusTreeReuseListPageMemoryImplTest.java} | 17 +- ...=> MetadataStoragePageMemoryImplTest.java} | 2 +- ...est.java => PageMemoryImplNoLoadTest.java} | 2 +- ... IgniteChangeGlobalStateAbstractTest.java} | 2 +- ... => IgniteChangeGlobalStateCacheTest.java} | 2 +- ...iteChangeGlobalStateDataStreamerTest.java} | 2 +- ...teChangeGlobalStateDataStructureTest.java} | 2 +- ... IgniteChangeGlobalStateFailOverTest.java} | 2 +- ...> IgniteChangeGlobalStateServiceTest.java} | 2 +- ....java => IgniteChangeGlobalStateTest.java} | 2 +- .../IgnitePdsOutOfMemoryTestSuite.java | 4 +- .../ignite/testsuites/IgnitePdsTestSuite.java | 58 ++--- .../testsuites/IgnitePdsTestSuite2.java | 53 ++-- .../testsuites/IgniteStandByClusterSuite.java | 22 +- 51 files changed, 639 insertions(+), 561 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/configuration/WALMode.java rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreAtomicCacheRebalancingTest.java => IgnitePdsAtomicCacheRebalancingTest.java} (92%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreCacheRebalancingAbstractTest.java => IgnitePdsCacheRebalancingAbstractTest.java} (94%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java => IgnitePdsClientNearCachePutGetTest.java} (79%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreContinuousRestartSelfTest.java => IgnitePdsContinuousRestartTest.java} (90%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreDynamicCacheTest.java => IgnitePdsDynamicCacheTest.java} (91%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java => IgnitePdsMultiNodePutGetRestartTest.java} (97%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStorePageSizesTest.java => IgnitePdsPageSizesTest.java} (86%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java => IgnitePdsRecoveryAfterFileCorruptionTest.java} (94%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java => IgnitePdsRemoveDuringRebalancingTest.java} (82%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java => IgnitePdsSingleNodePutGetPersistenceTest.java} (79%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java => IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java} (89%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java => IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.java} (79%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreTxCacheRebalancingTest.java => IgnitePdsTxCacheRebalancingTest.java} (94%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/{IgniteDbMultiNodePutGetRestartSelfTest.java => IgnitePdsMultiNodePutGetRestartTest.java} (95%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/{DbPageEvictionDuringPartitionClearSelfTest.java => IgnitePdsPageEvictionDuringPartitionClearTest.java} (92%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/{IgniteDbPageEvictionSelfTest.java => IgnitePdsPageEvictionTest.java} (93%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/{RebalancingOnNotStableTopologyTest.java => IgnitePdsRebalancingOnNotStableTopologyTest.java} (95%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/{TransactionsHangTest.java => IgnitePdsTransactionsHangTest.java} (96%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/{IgniteDbWholeClusterRestartSelfTest.java => IgnitePdsWholeClusterRestartTest.java} (90%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/{IgniteCachePageStoreIntegrationSelfTest.java => IgnitePdsCacheIntegrationTest.java} (94%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/{PageStoreEvictionSelfTest.java => IgnitePdsEvictionTest.java} (99%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/{IgniteNoActualWalHistorySelfTest.java => IgnitePdsNoActualWalHistoryTest.java} (91%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/{PageStoreCheckpointSimulationSelfTest.java => ignitePdsCheckpointSimulationTest.java} (96%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/{IgnitePersistentStoreWalTlbSelfTest.java => db/wal/IgnitePdsWalTlbTest.java} (88%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/{file => wal}/IgniteWalDirectoriesConfigurationTest.java (97%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/{file/IgniteWalHistoryReservationsSelfTest.java => wal/IgniteWalHistoryReservationsTest.java} (98%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/{file => wal}/IgniteWalRecoverySeveralRestartsTest.java (96%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/{file/IgniteWalRecoverySelfTest.java => wal/IgniteWalRecoveryTest.java} (98%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/db/{file => wal}/WalRecoveryTxLogicalRecordsTest.java (99%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/{BPlusTreeSelfTestPageMemoryImplSelfTest.java => BPlusTreePageMemoryImplTest.java} (86%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/{BPlusTreeReuseListPageMemoryImplSelfTest.java => BPlusTreeReuseListPageMemoryImplTest.java} (86%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/{MetadataStoragePageMemoryImplSelfTest.java => MetadataStoragePageMemoryImplTest.java} (98%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/{PageMemoryImplNoLoadSelfTest.java => PageMemoryImplNoLoadTest.java} (98%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/{GridChangeGlobalStateAbstractTest.java => IgniteChangeGlobalStateAbstractTest.java} (99%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/{GridChangeGlobalStateCacheTest.java => IgniteChangeGlobalStateCacheTest.java} (98%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/{GridChangeGlobalStateDataStreamerTest.java => IgniteChangeGlobalStateDataStreamerTest.java} (97%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/{GridChangeGlobalStateDataStructureTest.java => IgniteChangeGlobalStateDataStructureTest.java} (98%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/{GridChangeGlobalStateFailOverTest.java => IgniteChangeGlobalStateFailOverTest.java} (99%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/{GridChangeGlobalStateServiceTest.java => IgniteChangeGlobalStateServiceTest.java} (96%) rename modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/{GridChangeGlobalStateTest.java => IgniteChangeGlobalStateTest.java} (99%) 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 362dcdf72848a..d3cee9f91a678 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 @@ -48,13 +48,37 @@ public class PersistentStoreConfiguration implements Serializable { public static final int DFLT_CHECKPOINTING_THREADS = 1; /** */ - private static final int DFLT_WAL_HISTORY_SIZE = 20; + public static final int DFLT_WAL_HISTORY_SIZE = 20; /** */ public static final int DFLT_WAL_SEGMENTS = 10; /** */ - private static final int DFLT_WAL_SEGMENT_SIZE = 64 * 1024 * 1024; + public static final int DFLT_WAL_SEGMENT_SIZE = 64 * 1024 * 1024; + + /** Default wal mode. */ + public static final WALMode DFLT_WAL_MODE = WALMode.DEFAULT; + + /** Default thread local buffer size. */ + public static final int DFLT_TLB_SIZE = 128 * 1024; + + /** Default Wal flush frequency. */ + public static final int DFLT_WAL_FLUSH_FREQ = 2000; + + /** Default wal fsync delay. */ + public static final int DFLT_WAL_FSYNC_DELAY = 1; + + /** Default wal record iterator buffer size. */ + public static final int DFLT_WAL_RECORD_ITERATOR_BUFFER_SIZE = 64 * 1024 * 1024; + + /** Default wal always write full pages. */ + public static final boolean DFLT_WAL_ALWAYS_WRITE_FULL_PAGES = false; + + /** Default wal directory. */ + public static final String DFLT_WAL_STORE_PATH = "db/wal"; + + /** Default wal archive directory. */ + public static final String DFLT_WAL_ARCHIVE_PATH = "db/wal/archive"; /** */ private String persistenceStorePath; @@ -81,14 +105,32 @@ public class PersistentStoreConfiguration implements Serializable { private int walSegmentSize = DFLT_WAL_SEGMENT_SIZE; /** WAL persistence path. */ - private String walStorePath; + private String walStorePath = DFLT_WAL_STORE_PATH; /** WAL archive path. */ - private String walArchivePath; + private String walArchivePath = DFLT_WAL_ARCHIVE_PATH; /** Metrics enabled flag. */ private boolean metricsEnabled = DFLT_METRICS_ENABLED; + /** Wal mode. */ + private WALMode walMode = DFLT_WAL_MODE; + + /** WAl thread local buffer size. */ + private int tlbSize = DFLT_TLB_SIZE; + + /** Wal flush frequency. */ + private int walFlushFreq = DFLT_WAL_FLUSH_FREQ; + + /** Wal fsync delay. */ + private int walFsyncDelay = DFLT_WAL_FSYNC_DELAY; + + /** Wal record iterator buffer size. */ + private int walRecordIterBuffSize = DFLT_WAL_RECORD_ITERATOR_BUFFER_SIZE; + + /** Always write full pages. */ + private boolean alwaysWriteFullPages = DFLT_WAL_ALWAYS_WRITE_FULL_PAGES; + /** * Number of sub-intervals the whole {@link #setRateTimeInterval(long)} will be split into to calculate * rate-based metrics. @@ -380,4 +422,112 @@ public PersistentStoreConfiguration setSubIntervals(int subIntervals) { return this; } + + /** + * Type define behavior wal fsync. + * Different type provide different guarantees for consistency. + * + * @return WAL mode. + */ + public WALMode getWalMode() { + return walMode == null ? DFLT_WAL_MODE : walMode; + } + + /** + * @param walMode Wal mode. + */ + public PersistentStoreConfiguration setWalMode(WALMode walMode) { + this.walMode = walMode; + + return this; + } + + /** + * Property define size thread local buffer. + * Each thread which write to wal have thread local buffer for serialize recode before write in wal. + * + * @return Thread local buffer size. + */ + public int getTlbSize() { + return tlbSize <= 0 ? DFLT_TLB_SIZE : tlbSize; + } + + /** + * @param tlbSize Tlb size. + */ + public PersistentStoreConfiguration setTlbSize(int tlbSize) { + this.tlbSize = tlbSize; + + return this; + } + + /** + * Property define how often will be fsync. + * In background mode, exist thread which do fsync by timeout. + * + * @return Flush frequency. + */ + public int getWalFlushFrequency() { + return walFlushFreq; + } + + /** + * @param walFlushFreq Wal flush frequency. + */ + public PersistentStoreConfiguration setWalFlushFrequency(int walFlushFreq) { + this.walFlushFreq = walFlushFreq; + + return this; + } + + /** + * + */ + public int getWalFsyncDelay() { + return walFsyncDelay <= 0 ? DFLT_WAL_FSYNC_DELAY : walFsyncDelay; + } + + /** + * @param walFsyncDelay Wal fsync delay. + */ + public PersistentStoreConfiguration setWalFsyncDelay(int walFsyncDelay) { + this.walFsyncDelay = walFsyncDelay; + + return this; + } + + /** + * Property define how many bytes iterator read from + * disk (for one reading), during go ahead wal. + * + * @return Record iterator buffer size. + */ + public int getWalRecordIteratorBufferSize() { + return walRecordIterBuffSize <= 0 ? DFLT_WAL_RECORD_ITERATOR_BUFFER_SIZE : walRecordIterBuffSize; + } + + /** + * @param walRecordIterBuffSize Wal record iterator buffer size. + */ + public PersistentStoreConfiguration setWalRecordIteratorBufferSize(int walRecordIterBuffSize) { + this.walRecordIterBuffSize = walRecordIterBuffSize; + + return this; + } + + /** + * + */ + public boolean isAlwaysWriteFullPages() { + return alwaysWriteFullPages; + } + + /** + * @param alwaysWriteFullPages Always write full pages. + */ + public PersistentStoreConfiguration setAlwaysWriteFullPages(boolean alwaysWriteFullPages) { + this.alwaysWriteFullPages = alwaysWriteFullPages; + + return this; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/WALMode.java b/modules/core/src/main/java/org/apache/ignite/configuration/WALMode.java new file mode 100644 index 0000000000000..f30ab8d73595e --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/configuration/WALMode.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.configuration; + +/** + * WAL Mode. This enum defines crash recovery guarantees when Ignite persistence is enabled. + */ +public enum WALMode { + /** + * + */ + DEFAULT, + + /** + * + */ + LOG_ONLY, + + /** + * + */ + BACKGROUND, + + /** + * + */ + NONE +} \ No newline at end of file diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 1faffde9cee45..555fa6026ee20 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -603,7 +603,7 @@ private void readCheckpointAndRestoreMemory() throws IgniteCheckedException { snapshotMgr.stop(cancel); } - /** {@inheritDoc} */ + /** */ private long[] calculateFragmentSizes(int concLvl, long cacheSize) { if (concLvl < 2) concLvl = Runtime.getRuntime().availableProcessors(); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java index 292118cb8ec01..51a2437371996 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java @@ -43,9 +43,9 @@ import java.util.regex.Pattern; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; -import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; @@ -75,6 +75,9 @@ * File WAL manager. */ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter implements IgniteWriteAheadLogManager { + /** */ + public static final FileDescriptor[] EMPTY_DESCRIPTORS = new FileDescriptor[0]; + /** */ public static final String WAL_SEGMENT_FILE_EXT = ".wal"; @@ -101,42 +104,26 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl } }; - /** System property (env variable) for configuring DB WAL mode, see values in {@link Mode} */ - public static final String IGNITE_PDS_WAL_MODE = "IGNITE_PDS_WAL_MODE"; - - /** Thread local byte buffer size */ - public static final String IGNITE_PDS_WAL_TLB_SIZE = "IGNITE_PDS_WAL_TLB_SIZE"; - - /** WAL flush frequency for {@link Mode#BACKGROUND} log mode */ - public static final String IGNITE_PDS_WAL_FLUSH_FREQ = "IGNITE_PDS_WAL_FLUSH_FREQUENCY"; - /** */ - public static final String IGNITE_PDS_WAL_FSYNC_DELAY = "IGNITE_PDS_WAL_FSYNC_DELAY"; // TODO may be move to config - - /** Ignite pds wal record iterator buffer size. */ - public static final String IGNITE_PDS_WAL_RECORD_ITERATOR_BUFFER_SIZE = "IGNITE_PDS_WAL_RECORD_ITERATOR_BUFFER_SIZE"; + private final boolean alwaysWriteFullPages; - /** */ - public static final String IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES = "IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES"; + /** WAL segment size in bytes */ + private final long maxWalSegmentSize; /** */ - private static long fsyncDelayNanos = IgniteSystemProperties.getLong(IGNITE_PDS_WAL_FSYNC_DELAY, 1); + private final WALMode mode; /** Thread local byte buffer size, see {@link #tlb} */ - public final int tlbSize = IgniteSystemProperties.getInteger(IGNITE_PDS_WAL_TLB_SIZE, 128 * 1024); - - /** WAL flush frequency. Makes sense only for {@link Mode#BACKGROUND} log mode. */ - public static final int FLUSH_FREQ = IgniteSystemProperties.getInteger(IGNITE_PDS_WAL_FLUSH_FREQ, 2_000); + private final int tlbSize; - /** */ - private final boolean alwaysWriteFullPages = - IgniteSystemProperties.getBoolean(IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES, false); + /** WAL flush frequency. Makes sense only for {@link WALMode#BACKGROUND} log WALMode. */ + public final int flushFreq; - /** WAL segment size in bytes */ - private long maxWalSegmentSize; + /** Fsync delay. */ + private final long fsyncDelay; /** */ - private final PersistentStoreConfiguration dbCfg; + private final PersistentStoreConfiguration psCfg; /** */ private IgniteConfiguration igCfg; @@ -150,8 +137,8 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl /** */ private File walArchiveDir; - /** Current log segment handle */ - private volatile FileWriteHandle currentHnd; + /** */ + private RecordSerializer serializer; /** */ private volatile long oldestArchiveSegmentIdx; @@ -176,19 +163,16 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl }; /** */ - private RecordSerializer serializer; - - /** WAL file archiver thread, started on server nodes at cluster init */ private volatile FileArchiver archiver; - /** */ - private final Mode mode; - /** */ private QueueFlusher flusher; /** */ - private ThreadLocal lastWALPtr = new ThreadLocal<>(); + private final ThreadLocal lastWALPtr = new ThreadLocal<>(); + + /** Current log segment handle */ + private volatile FileWriteHandle currentHnd; /** * @param ctx Kernal context. @@ -196,16 +180,18 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl public FileWriteAheadLogManager(GridKernalContext ctx) { igCfg = ctx.config(); - PersistentStoreConfiguration dbCfg = igCfg.getPersistentStoreConfiguration(); - - assert dbCfg != null : "WAL should not be created if persistence is disabled."; + PersistentStoreConfiguration psCfg = igCfg.getPersistentStoreConfiguration(); - this.dbCfg = dbCfg; + assert psCfg != null : "WAL should not be created if persistence is disabled."; - maxWalSegmentSize = dbCfg.getWalSegmentSize(); + this.psCfg = psCfg; - String modeStr = IgniteSystemProperties.getString(IGNITE_PDS_WAL_MODE); - mode = modeStr == null ? Mode.DEFAULT : Mode.valueOf(modeStr.trim().toUpperCase()); + maxWalSegmentSize = psCfg.getWalSegmentSize(); + mode = psCfg.getWalMode(); + tlbSize = psCfg.getTlbSize(); + flushFreq = psCfg.getWalFlushFrequency(); + fsyncDelay = psCfg.getWalFsyncDelay(); + alwaysWriteFullPages = psCfg.isAlwaysWriteFullPages(); } /** {@inheritDoc} */ @@ -218,9 +204,20 @@ public FileWriteAheadLogManager(GridKernalContext ctx) { consId = U.maskForFileName(consId); checkWalConfiguration(); - walWorkDir = initDirectory(dbCfg.getWalStorePath(), "db/wal", consId, "write ahead log work directory"); - walArchiveDir = initDirectory(dbCfg.getWalArchivePath(), "db/wal/archive", consId, - "write ahead log archive directory"); + + walWorkDir = initDirectory( + psCfg.getWalStorePath(), + PersistentStoreConfiguration.DFLT_WAL_STORE_PATH, + consId, + "write ahead log work directory" + ); + + walArchiveDir = initDirectory( + psCfg.getWalArchivePath(), + PersistentStoreConfiguration.DFLT_WAL_ARCHIVE_PATH, + consId, + "write ahead log archive directory" + ); serializer = new RecordV1Serializer(cctx); @@ -236,7 +233,7 @@ public FileWriteAheadLogManager(GridKernalContext ctx) { archiver = new FileArchiver(tup == null ? -1 : tup.get2()); - if (mode != Mode.DEFAULT) { + if (mode != WALMode.DEFAULT) { if (log.isInfoEnabled()) log.info("Started write-ahead log manager [mode=" + mode + ']'); } @@ -247,9 +244,12 @@ public FileWriteAheadLogManager(GridKernalContext ctx) { * @throws IgniteCheckedException if WAL store path is configured and archive path isn't (or vice versa) */ private void checkWalConfiguration() throws IgniteCheckedException { - if (dbCfg.getWalStorePath() == null ^ dbCfg.getWalArchivePath() == null) { - throw new IgniteCheckedException("Properties should be either both specified or both null " + - "[walStorePath = " + dbCfg.getWalStorePath() + ", walArchivePath = " + dbCfg.getWalArchivePath() + "]"); + if (psCfg.getWalStorePath() == null ^ psCfg.getWalArchivePath() == null) { + throw new IgniteCheckedException( + "Properties should be either both specified or both null " + + "[walStorePath = " + psCfg.getWalStorePath() + + ", walArchivePath = " + psCfg.getWalArchivePath() + "]" + ); } } @@ -326,7 +326,7 @@ protected String consistentId() { /** {@inheritDoc} */ @Override public boolean isFullSync() { - return mode == Mode.DEFAULT; + return mode == WALMode.DEFAULT; } /** {@inheritDoc} */ @@ -348,7 +348,7 @@ protected String consistentId() { rollOver(currentHnd); } - if (mode == Mode.BACKGROUND) { + if (mode == WALMode.BACKGROUND) { flusher = new QueueFlusher(cctx.igniteInstanceName()); flusher.start(); @@ -362,7 +362,7 @@ protected String consistentId() { /** {@inheritDoc} */ @SuppressWarnings("TooBroadScope") @Override public WALPointer log(WALRecord record) throws IgniteCheckedException, StorageException { - if (serializer == null || mode == Mode.NONE) + if (serializer == null || mode == WALMode.NONE) return null; FileWriteHandle current = currentHandle(); @@ -392,7 +392,7 @@ protected String consistentId() { /** {@inheritDoc} */ @Override public void fsync(WALPointer ptr) throws IgniteCheckedException, StorageException { - if (serializer == null || mode == Mode.NONE) + if (serializer == null || mode == WALMode.NONE) return; FileWriteHandle cur = currentHandle(); @@ -405,10 +405,10 @@ protected String consistentId() { boolean forceFlush = filePtr != null && filePtr.forceFlush(); - if (mode == Mode.BACKGROUND && !forceFlush) + if (mode == WALMode.BACKGROUND && !forceFlush) return; - if (mode == Mode.LOG_ONLY || forceFlush) { + if (mode == WALMode.LOG_ONLY || forceFlush) { cur.flushOrWait(filePtr); return; @@ -433,15 +433,25 @@ protected String consistentId() { if (hnd != null) end = hnd.position(); - return new RecordsIterator(cctx, walWorkDir, walArchiveDir, (FileWALPointer)start, end, dbCfg, serializer, - archiver, log, tlbSize); + return new RecordsIterator( + cctx, + walWorkDir, + walArchiveDir, + (FileWALPointer)start, + end, + psCfg, + serializer, + archiver, + log, + tlbSize + ); } /** {@inheritDoc} */ @Override public boolean reserve(WALPointer start) throws IgniteCheckedException { assert start != null && start instanceof FileWALPointer : "Invalid start pointer: " + start; - if (mode == Mode.NONE) + if (mode == WALMode.NONE) return false; FileArchiver archiver0 = archiver; @@ -464,7 +474,7 @@ protected String consistentId() { @Override public void release(WALPointer start) throws IgniteCheckedException { assert start != null && start instanceof FileWALPointer : "Invalid start pointer: " + start; - if (mode == Mode.NONE) + if (mode == WALMode.NONE) return; FileArchiver archiver0 = archiver; @@ -617,7 +627,6 @@ private File initDirectory(String cfg, String defDir, String consId, String msg) if (cfg != null) { File workDir0 = new File(cfg); - //TODO check path dir = workDir0.isAbsolute() ? new File(workDir0, consId) : new File(U.resolveWorkDirectory(igCfg.getWorkDirectory(), cfg, false), consId); @@ -654,7 +663,8 @@ private FileWriteHandle rollOver(FileWriteHandle cur) throws StorageException, I assert swapped : "Concurrent updates on rollover are not allowed"; - hnd.signalNextAvailable(); // let other threads to proceed with new segment + // Let other threads to proceed with new segment. + hnd.signalNextAvailable(); } else hnd.awaitNext(); @@ -670,7 +680,7 @@ private FileWriteHandle rollOver(FileWriteHandle cur) throws StorageException, I private FileWriteHandle restoreWriteHandle(FileWALPointer lastReadPtr) throws IgniteCheckedException { long absIdx = lastReadPtr == null ? 0 : lastReadPtr.index(); - long segNo = absIdx % dbCfg.getWalSegments(); + long segNo = absIdx % psCfg.getWalSegments(); File curFile = new File(walWorkDir, FileDescriptor.fileName(segNo)); @@ -784,9 +794,9 @@ private void checkOrPrepareFiles() throws IgniteCheckedException { File[] allFiles = walWorkDir.listFiles(WAL_SEGMENT_FILE_FILTER); - if (allFiles.length != 0 && allFiles.length > dbCfg.getWalSegments()) + if (allFiles.length != 0 && allFiles.length > psCfg.getWalSegments()) throw new IgniteCheckedException("Failed to initialize wal (work directory contains " + - "incorrect number of segments) [cur=" + allFiles.length + ", expected=" + dbCfg.getWalSegments() + ']'); + "incorrect number of segments) [cur=" + allFiles.length + ", expected=" + psCfg.getWalSegments() + ']'); // Allocate the first segment synchronously. All other segments will be allocated by archiver in background. if (allFiles.length == 0) { @@ -808,9 +818,9 @@ private void formatFile(File file) throws IgniteCheckedException { log.debug("Formatting file [exists=" + file.exists() + ", file=" + file.getAbsolutePath() + ']'); try (RandomAccessFile rnd = new RandomAccessFile(file, "rw")) { - int left = dbCfg.getWalSegmentSize(); + int left = psCfg.getWalSegmentSize(); - if (mode == Mode.DEFAULT) { + if (mode == WALMode.DEFAULT) { while (left > 0) { int toWrite = Math.min(FILL_BUF.length, left); @@ -821,9 +831,8 @@ private void formatFile(File file) throws IgniteCheckedException { rnd.getChannel().force(false); } - else { + else rnd.setLength(0); - } } catch (IOException e) { throw new IgniteCheckedException("Failed to format WAL segment file: " + file.getAbsolutePath(), e); @@ -868,7 +877,7 @@ private File pollNextFile(long curIdx) throws IgniteCheckedException { // Signal to archiver that we are done with the segment and it can be archived. long absNextIdx = archiver.nextAbsoluteSegmentIndex(curIdx); - long segmentIdx = absNextIdx % dbCfg.getWalSegments(); + long segmentIdx = absNextIdx % psCfg.getWalSegments(); return new File(walWorkDir, FileDescriptor.fileName(segmentIdx)); } @@ -896,7 +905,7 @@ private static RecordSerializer forVersion(GridCacheSharedContext cctx, int ver) */ private static FileDescriptor[] scan(File[] allFiles) { if (allFiles == null) - return new FileDescriptor[0]; + return EMPTY_DESCRIPTORS; FileDescriptor[] descs = new FileDescriptor[allFiles.length]; @@ -913,7 +922,7 @@ private static FileDescriptor[] scan(File[] allFiles) { /** * File archiver operates on absolute segment indexes. For any given absolute segment index N we can calculate - * the work WAL segment: S(N) = N % dbCfg.walSegments. + * the work WAL segment: S(N) = N % psCfg.walSegments. * When a work segment is finished, it is given to the archiver. If the absolute index of last archived segment * is denoted by A and the absolute index of next segment we want to write is denoted by W, then we can allow * write to S(W) if W - A <= walSegments.
@@ -1119,7 +1128,7 @@ private long nextAbsoluteSegmentIndex(long curIdx) throws IgniteCheckedException // Notify archiver thread. notifyAll(); - while (curAbsWalIdx - lastAbsArchivedIdx > dbCfg.getWalSegments() && cleanException == null) + while (curAbsWalIdx - lastAbsArchivedIdx > psCfg.getWalSegments() && cleanException == null) wait(); return curAbsWalIdx; @@ -1186,7 +1195,7 @@ private void releaseWorkSegment(long absIdx) { * @param absIdx Absolute index to archive. */ private File archiveSegment(long absIdx) throws IgniteCheckedException { - long segIdx = absIdx % dbCfg.getWalSegments(); + long segIdx = absIdx % psCfg.getWalSegments(); File origFile = new File(walWorkDir, FileDescriptor.fileName(segIdx)); @@ -1207,7 +1216,7 @@ private File archiveSegment(long absIdx) throws IgniteCheckedException { Files.move(dstTmpFile.toPath(), dstFile.toPath()); - if (mode == Mode.DEFAULT) { + if (mode == WALMode.DEFAULT) { try (RandomAccessFile f0 = new RandomAccessFile(dstFile, "rw")) { f0.getChannel().force(false); } @@ -1256,14 +1265,14 @@ private void allocateRemainingFiles() throws IgniteCheckedException { * @throws IgniteCheckedException if validation or create file fail. */ private void checkFiles(int startWith, boolean create, IgnitePredicate p) throws IgniteCheckedException { - for (int i = startWith; i < dbCfg.getWalSegments() && (p == null || (p != null && p.apply(i))); i++) { + for (int i = startWith; i < psCfg.getWalSegments() && (p == null || (p != null && p.apply(i))); i++) { File checkFile = new File(walWorkDir, FileDescriptor.fileName(i)); if (checkFile.exists()) { if (checkFile.isDirectory()) throw new IgniteCheckedException("Failed to initialize WAL log segment (a directory with " + "the same name already exists): " + checkFile.getAbsolutePath()); - else if (checkFile.length() != dbCfg.getWalSegmentSize() && mode == Mode.DEFAULT) + else if (checkFile.length() != psCfg.getWalSegmentSize() && mode == WALMode.DEFAULT) throw new IgniteCheckedException("Failed to initialize WAL log segment " + "(WAL segment size change is not supported):" + checkFile.getAbsolutePath()); } @@ -1331,10 +1340,7 @@ private FileDescriptor(File file, Long idx) { int end = fileName.length() - WAL_SEGMENT_FILE_EXT.length(); - if (idx == null) - this.idx = Long.parseLong(fileName.substring(0, end)); - else - this.idx = idx; + this.idx = idx == null ? Long.parseLong(fileName.substring(0, end)) : idx; } /** @@ -1426,6 +1432,9 @@ private FileHandle(RandomAccessFile file, long idx, String gridName) { } } + /** + * + */ private static class ReadFileHandle extends FileHandle { /** Entry serializer. */ private RecordSerializer ser; @@ -1505,7 +1514,7 @@ private class FileWriteHandle extends FileHandle { /** Condition activated each time writeBuffer() completes. Used to wait previously flushed write to complete */ private final Condition writeComplete = lock.newCondition(); - /** Condition for timed wait of several threads, see {@link #fsyncDelayNanos} */ + /** Condition for timed wait of several threads, see {@link PersistentStoreConfiguration#getWalFsyncDelay()} */ private final Condition fsync = lock.newCondition(); /** @@ -1585,8 +1594,8 @@ private FileWriteHandle( idx, (int)nextPos, rec.size(), - // We need to force checkpoint records into file in BACKGROUND mode. - mode == Mode.BACKGROUND && rec instanceof CheckpointRecord); + // We need to force checkpoint records into file in BACKGROUND WALMode. + mode == WALMode.BACKGROUND && rec instanceof CheckpointRecord); rec.position(ptr); @@ -1819,9 +1828,9 @@ private void fsync(FileWALPointer ptr) throws StorageException, IgniteCheckedExc if (!needFsync(ptr)) return; - if (fsyncDelayNanos > 0 && !stop.get()) { + if (fsyncDelay > 0 && !stop.get()) { // Delay fsync to collect as many updates as possible: trade latency for throughput. - U.await(fsync, fsyncDelayNanos, TimeUnit.NANOSECONDS); + U.await(fsync, fsyncDelay, TimeUnit.NANOSECONDS); if (!needFsync(ptr)) return; @@ -1846,7 +1855,7 @@ private void fsync(FileWALPointer ptr) throws StorageException, IgniteCheckedExc lastFsyncPos = written; - if (fsyncDelayNanos > 0) + if (fsyncDelay > 0) fsync.signalAll(); long end = metricsEnabled ? System.nanoTime() : 0; @@ -1868,7 +1877,7 @@ private void fsync(FileWALPointer ptr) throws StorageException, IgniteCheckedExc private boolean close(boolean rollOver) throws IgniteCheckedException, StorageException { if (stop.compareAndSet(false, true)) { // Here we can be sure that no other records will be added and this fsync will be the last. - if (mode == Mode.DEFAULT) + if (mode == WALMode.DEFAULT) fsync(null); else flushOrWait(null); @@ -1880,7 +1889,7 @@ private boolean close(boolean rollOver) throws IgniteCheckedException, StorageEx ch.write(allocate, written); - if (mode == Mode.DEFAULT) + if (mode == WALMode.DEFAULT) ch.force(false); } @@ -1899,14 +1908,15 @@ private boolean close(boolean rollOver) throws IgniteCheckedException, StorageEx return false; } - - /** Signals next segment available to wake up other worker threads waiting for WAL to write */ + /** + * Signals next segment available to wake up other worker threads waiting for WAL to write + */ private void signalNextAvailable() { lock.lock(); try { assert head.get() instanceof FakeRecord: "head"; - assert written == lastFsyncPos || mode != Mode.DEFAULT : + assert written == lastFsyncPos || mode != WALMode.DEFAULT : "fsync [written=" + written + ", lastFsync=" + lastFsyncPos + ']'; ch = null; @@ -1959,8 +1969,8 @@ private void writeBuffer(long pos, ByteBuffer buf) throws StorageException, Igni while (written != pos) { assert written < pos : "written = " + written + ", pos = " + pos; // No one can write further than we are now. - // Permutation occurred between blocks write operations - // order of acquiring lock is not the same as order of write + // Permutation occurred between blocks write operations. + // Order of acquiring lock is not the same as order of write. long now = U.currentTimeMillis(); if (now - lastLogged >= logBackoff) { @@ -2116,15 +2126,10 @@ private static final class FakeRecord extends WALRecord { /** * Iterator over WAL-log. */ - public static class RecordsIterator extends GridCloseableIteratorAdapter> + private static class RecordsIterator extends GridCloseableIteratorAdapter> implements WALIterator { /** */ private static final long serialVersionUID = 0L; - - /** Buffer size. */ - private final int buffSize = IgniteSystemProperties.getInteger( - IGNITE_PDS_WAL_RECORD_ITERATOR_BUFFER_SIZE, 64 * 1024 * 1024); - /** */ private final File walWorkDir; @@ -2135,7 +2140,7 @@ public static class RecordsIterator extends GridCloseableIteratorAdapter() { + IgniteInternalFuture fut = runMultiThreadedAsync(new Callable() { @Override public Void call() throws Exception { while (true) { if (stop.get()) @@ -420,7 +420,7 @@ public void testTopologyChangesWithConstantLoad() throws Exception { try { ignite.cache(cacheName).put(k, new TestValue(v1, v2)); } - catch (Exception e) { + catch (Exception ignored) { success = false; } finally { @@ -428,7 +428,7 @@ public void testTopologyChangesWithConstantLoad() throws Exception { try { tx.commit(); } - catch (Exception e) { + catch (Exception ignored) { success = false; } } @@ -444,6 +444,7 @@ public void testTopologyChangesWithConstantLoad() throws Exception { U.sleep(3_000); boolean add; + if (nodesCnt.get() <= maxNodesCount / 2) add = true; else if (nodesCnt.get() > maxNodesCount) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsClientNearCachePutGetTest.java similarity index 79% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsClientNearCachePutGetTest.java index 0993bf32082c4..240171e6ccbeb 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsClientNearCachePutGetTest.java @@ -19,19 +19,22 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.processors.database.IgniteDbClientNearCachePutGetTest; import org.apache.ignite.internal.util.typedef.internal.U; /** * */ -public class IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest extends IgniteDbClientNearCachePutGetTest { +public class IgnitePdsClientNearCachePutGetTest extends IgniteDbClientNearCachePutGetTest { /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalMode(WALMode.LOG_ONLY) + ); return cfg; } @@ -40,8 +43,6 @@ public class IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest e @Override protected void beforeTest() throws Exception { deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - super.beforeTest(); } @@ -49,8 +50,6 @@ public class IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest e @Override protected void afterTest() throws Exception { super.afterTest(); - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsContinuousRestartTest.java similarity index 90% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsContinuousRestartTest.java index fa9879bc7d2f6..a149836480f76 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreContinuousRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsContinuousRestartTest.java @@ -35,8 +35,8 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; @@ -44,7 +44,7 @@ /** * */ -public class IgnitePersistentStoreContinuousRestartSelfTest extends GridCommonAbstractTest { +public class IgnitePdsContinuousRestartTest extends GridCommonAbstractTest { /** */ private static final int GRID_CNT = 4; @@ -58,7 +58,7 @@ public class IgnitePersistentStoreContinuousRestartSelfTest extends GridCommonAb @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - MemoryConfiguration dbCfg = new MemoryConfiguration(); + MemoryConfiguration memCfg = new MemoryConfiguration(); MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); @@ -66,10 +66,10 @@ public class IgnitePersistentStoreContinuousRestartSelfTest extends GridCommonAb memPlcCfg.setMaxSize(400 * 1024 * 1024); memPlcCfg.setInitialSize(400 * 1024 * 1024); - dbCfg.setMemoryPolicies(memPlcCfg); - dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); + memCfg.setMemoryPolicies(memPlcCfg); + memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); - cfg.setMemoryConfiguration(dbCfg); + cfg.setMemoryConfiguration(memCfg); CacheConfiguration ccfg1 = new CacheConfiguration(); @@ -81,15 +81,16 @@ public class IgnitePersistentStoreContinuousRestartSelfTest extends GridCommonAb cfg.setCacheConfiguration(ccfg1); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalMode(WALMode.LOG_ONLY) + ); return cfg; } /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - stopAllGrids(); deleteWorkFiles(); @@ -102,13 +103,6 @@ public class IgnitePersistentStoreContinuousRestartSelfTest extends GridCommonAb deleteWorkFiles(); } - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - super.afterTestsStopped(); - - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - } - /** * @throws IgniteCheckedException If failed. */ diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsDynamicCacheTest.java similarity index 91% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsDynamicCacheTest.java index 96957daf7e1ed..63bf557b7b5cd 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDynamicCacheTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsDynamicCacheTest.java @@ -28,42 +28,15 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.processors.database.IgniteDbDynamicCacheSelfTest; import org.apache.ignite.internal.util.typedef.internal.U; /** * */ -public class IgnitePersistentStoreDynamicCacheTest extends IgniteDbDynamicCacheSelfTest { - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - - System.setProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC, "true"); - - super.beforeTest(); - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - super.beforeTestsStarted(); - - deleteWorkFiles(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - super.afterTest(); - - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - - System.clearProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC); - - deleteWorkFiles(); - } - +public class IgnitePdsDynamicCacheTest extends IgniteDbDynamicCacheSelfTest { /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); @@ -81,7 +54,10 @@ public class IgnitePersistentStoreDynamicCacheTest extends IgniteDbDynamicCacheS cfg.setMemoryConfiguration(dbCfg); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalMode(WALMode.LOG_ONLY) + ); if ("client".equals(gridName)) cfg.setClientMode(true); @@ -89,6 +65,30 @@ public class IgnitePersistentStoreDynamicCacheTest extends IgniteDbDynamicCacheS return cfg; } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + System.setProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC, "true"); + + super.beforeTest(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + deleteWorkFiles(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + System.clearProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC); + + deleteWorkFiles(); + } + /** * @throws Exception If failed. */ diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsMultiNodePutGetRestartTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsMultiNodePutGetRestartTest.java index a2eb3d446c9a2..d4d9eb62fbcaf 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreMultiNodePutGetRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsMultiNodePutGetRestartTest.java @@ -45,7 +45,7 @@ /** * */ -public class IgnitePersistentStoreMultiNodePutGetRestartSelfTest extends GridCommonAbstractTest { +public class IgnitePdsMultiNodePutGetRestartTest extends GridCommonAbstractTest { /** */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); @@ -58,7 +58,7 @@ public class IgnitePersistentStoreMultiNodePutGetRestartSelfTest extends GridCom /** * Default constructor. */ - public IgnitePersistentStoreMultiNodePutGetRestartSelfTest() { + public IgnitePdsMultiNodePutGetRestartTest() { String home = U.getIgniteHome(); allocPath = new File(home, "work/db/" + UUID.randomUUID()); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsPageSizesTest.java similarity index 86% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsPageSizesTest.java index 9616d76608f92..a15b96c986a6a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStorePageSizesTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsPageSizesTest.java @@ -27,8 +27,8 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; @@ -36,7 +36,10 @@ /** * */ -public class IgnitePersistentStorePageSizesTest extends GridCommonAbstractTest { +public class IgnitePdsPageSizesTest extends GridCommonAbstractTest { + /** Cache name. */ + private final String cacheName = "cache"; + /** */ private int pageSize; @@ -59,26 +62,19 @@ public class IgnitePersistentStorePageSizesTest extends GridCommonAbstractTest { cfg.setMemoryConfiguration(memCfg); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalMode(WALMode.LOG_ONLY) + ); cfg.setCacheConfiguration( - new CacheConfiguration("partitioned") + new CacheConfiguration(cacheName) .setAffinity(new RendezvousAffinityFunction(false, 32)) ); return cfg; } - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - } - /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); @@ -133,7 +129,7 @@ private void checkPageSize(int pageSize) throws Exception { IgniteEx ignite = startGrid(0); try { - final IgniteCache cache = ignite.cache("partitioned"); + final IgniteCache cache = ignite.cache(cacheName); final long endTime = System.currentTimeMillis() + 60_000; GridTestUtils.runMultiThreaded(new Callable() { diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRecoveryAfterFileCorruptionTest.java similarity index 94% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRecoveryAfterFileCorruptionTest.java index e10acab0363d2..eb3662d80aadc 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRecoveryAfterFileCorruptionTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRecoveryAfterFileCorruptionTest.java @@ -48,19 +48,16 @@ import org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; 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.TcpDiscoveryIpFinder; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import static org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager.IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES; - /** * */ -public class IgnitePersistentStoreRecoveryAfterFileCorruptionTest extends GridCommonAbstractTest { +public class IgnitePdsRecoveryAfterFileCorruptionTest extends GridCommonAbstractTest { /** Ip finder. */ private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); @@ -97,21 +94,22 @@ public class IgnitePersistentStoreRecoveryAfterFileCorruptionTest extends GridCo cfg.setMemoryConfiguration(dbCfg); - PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); - - pCfg.setCheckpointingFrequency(500); - - cfg.setPersistentStoreConfiguration(pCfg); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setCheckpointingFrequency(500) + .setAlwaysWriteFullPages(true) + ); - cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder)); + cfg.setDiscoverySpi( + new TcpDiscoverySpi() + .setIpFinder(ipFinder) + ); return cfg; } /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - System.setProperty(IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES, "true"); - stopAllGrids(); deleteWorkFiles(); @@ -122,8 +120,6 @@ public class IgnitePersistentStoreRecoveryAfterFileCorruptionTest extends GridCo stopAllGrids(); deleteWorkFiles(); - - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES); } /** diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRemoveDuringRebalancingTest.java similarity index 82% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRemoveDuringRebalancingTest.java index 5544aaf39941a..79d8e40b391b3 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreRemoveDuringRebalancingSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRemoveDuringRebalancingTest.java @@ -29,9 +29,9 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.typedef.G; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; @@ -43,7 +43,7 @@ /** * */ -public class IgnitePersistentStoreRemoveDuringRebalancingSelfTest extends GridCommonAbstractTest { +public class IgnitePdsRemoveDuringRebalancingTest extends GridCommonAbstractTest { /** */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); @@ -51,9 +51,13 @@ public class IgnitePersistentStoreRemoveDuringRebalancingSelfTest extends GridCo @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - cfg.setCacheConfiguration(new CacheConfiguration().setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) - .setBackups(1).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC) - .setRebalanceMode(CacheRebalanceMode.SYNC)); + cfg.setCacheConfiguration( + new CacheConfiguration() + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) + .setBackups(1) + .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC) + .setRebalanceMode(CacheRebalanceMode.SYNC) + ); MemoryConfiguration dbCfg = new MemoryConfiguration(); @@ -72,20 +76,22 @@ public class IgnitePersistentStoreRemoveDuringRebalancingSelfTest extends GridCo cfg.setMemoryConfiguration(dbCfg); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalMode(WALMode.LOG_ONLY) + ); - TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); - - discoSpi.setIpFinder(IP_FINDER); + cfg.setDiscoverySpi( + new TcpDiscoverySpi() + .setIpFinder(IP_FINDER) + ); return cfg; } /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { - G.stopAll(true); - - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); + stopAllGrids(); deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); @@ -101,11 +107,6 @@ public class IgnitePersistentStoreRemoveDuringRebalancingSelfTest extends GridCo U.delete(new File(U.getIgniteHome(), "db")); } - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - } - /** * @throws Exception if failed. */ diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodePutGetPersistenceTest.java similarity index 79% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodePutGetPersistenceTest.java index e1edf8e9004ad..d92ac25601a6f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodePutGetPersistenceTest.java @@ -19,19 +19,22 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.processors.database.IgniteDbSingleNodePutGetTest; import org.apache.ignite.internal.util.typedef.internal.U; /** * */ -public class IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest extends IgniteDbSingleNodePutGetTest { +public class IgnitePdsSingleNodePutGetPersistenceTest extends IgniteDbSingleNodePutGetTest { /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalMode(WALMode.LOG_ONLY) + ); return cfg; } @@ -40,8 +43,6 @@ public class IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest extends Ig @Override protected void beforeTest() throws Exception { deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - super.beforeTest(); } @@ -49,8 +50,6 @@ public class IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest extends Ig @Override protected void afterTest() throws Exception { super.afterTest(); - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java similarity index 89% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java index 665b9afb7fd0f..257e0e840cfb1 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java @@ -25,8 +25,8 @@ /** * */ -public class IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest - extends IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest { +public class IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest + extends IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest { /** {@inheritDoc} */ @Override protected void configure(IgniteConfiguration cfg) { super.configure(cfg); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.java similarity index 79% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.java index 392315c0cc191..a18ba75caa747 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.java @@ -19,19 +19,22 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.processors.database.IgniteDbSingleNodeWithIndexingPutGetTest; import org.apache.ignite.internal.util.typedef.internal.U; /** * */ -public class IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest extends IgniteDbSingleNodeWithIndexingPutGetTest { +public class IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest extends IgniteDbSingleNodeWithIndexingPutGetTest { /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalMode(WALMode.LOG_ONLY) + ); return cfg; } @@ -40,8 +43,6 @@ public class IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTes @Override protected void beforeTestsStarted() throws Exception { deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - super.beforeTestsStarted(); } @@ -49,8 +50,6 @@ public class IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTes @Override protected void afterTestsStopped() throws Exception { super.afterTestsStopped(); - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsTxCacheRebalancingTest.java similarity index 94% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsTxCacheRebalancingTest.java index fb71b8a6fa33e..f29807e7cc2d2 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreTxCacheRebalancingTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsTxCacheRebalancingTest.java @@ -27,7 +27,7 @@ /** * */ -public class IgnitePersistentStoreTxCacheRebalancingTest extends IgnitePersistentStoreCacheRebalancingAbstractTest { +public class IgnitePdsTxCacheRebalancingTest extends IgnitePdsCacheRebalancingAbstractTest { /** {@inheritDoc} */ @Override protected CacheConfiguration cacheConfiguration(String cacheName) { CacheConfiguration ccfg = new CacheConfiguration(cacheName); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistenceMetricsSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistenceMetricsSelfTest.java index fc25509290f62..79d4a4def9d0d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistenceMetricsSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistenceMetricsSelfTest.java @@ -31,8 +31,8 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.PAX; import org.apache.ignite.internal.util.typedef.internal.S; @@ -59,17 +59,8 @@ public class IgnitePersistenceMetricsSelfTest extends GridCommonAbstractTest { /** */ private boolean activeOnStart = true; - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - super.beforeTestsStarted(); - - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - } - /** {@inheritDoc} */ @Override protected void afterTestsStopped() throws Exception { - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - GridTestUtils.deleteDbFiles(); } @@ -102,7 +93,8 @@ public class IgnitePersistenceMetricsSelfTest extends GridCommonAbstractTest { cfg.setMemoryConfiguration(memCfg); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration().setMetricsEnabled(true)); + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration() + .setMetricsEnabled(true).setWalMode(WALMode.LOG_ONLY)); cfg.setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(false)); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheGroupsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheGroupsTest.java index 7a6b34c179fc5..4a0ae15301c87 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheGroupsTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheGroupsTest.java @@ -16,6 +16,7 @@ */ package org.apache.ignite.cache.database; + import java.io.Serializable; import java.util.Arrays; import java.util.List; @@ -35,7 +36,7 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; @@ -69,17 +70,8 @@ public class IgnitePersistentStoreCacheGroupsTest extends GridCommonAbstractTest /** */ private boolean activeOnStart = true; - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - super.beforeTestsStarted(); - - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - } - /** {@inheritDoc} */ @Override protected void afterTestsStopped() throws Exception { - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - GridTestUtils.deleteDbFiles(); } @@ -104,7 +96,7 @@ public class IgnitePersistentStoreCacheGroupsTest extends GridCommonAbstractTest cfg.setMemoryConfiguration(memCfg); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration().setWalMode(WALMode.LOG_ONLY)); cfg.setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(false)); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDataStructuresTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDataStructuresTest.java index 0183779ef94b4..718cf5431d350 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDataStructuresTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDataStructuresTest.java @@ -27,7 +27,7 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.configuration.WALMode; 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; @@ -60,24 +60,15 @@ public class IgnitePersistentStoreDataStructuresTest extends GridCommonAbstractT cfg.setMemoryConfiguration(dbCfg); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration().setWalMode(WALMode.LOG_ONLY)); cfg.setActiveOnStart(false); return cfg; } - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - super.beforeTestsStarted(); - - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - } - /** {@inheritDoc} */ @Override protected void afterTestsStopped() throws Exception { - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - GridTestUtils.deleteDbFiles(); } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsMultiNodePutGetRestartTest.java similarity index 95% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsMultiNodePutGetRestartTest.java index 88bdf1e021023..41b1b297c505f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbMultiNodePutGetRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsMultiNodePutGetRestartTest.java @@ -45,13 +45,10 @@ /** * */ -public class IgniteDbMultiNodePutGetRestartSelfTest extends GridCommonAbstractTest { +public class IgnitePdsMultiNodePutGetRestartTest extends GridCommonAbstractTest { /** */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - /** */ - private File allocPath; - /** */ private static final int GRID_CNT = 3; @@ -88,12 +85,7 @@ public class IgniteDbMultiNodePutGetRestartSelfTest extends GridCommonAbstractTe cfg.setCacheConfiguration(ccfg); cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); - - TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); - - discoSpi.setIpFinder(IP_FINDER); - - cfg.setDiscoverySpi(discoSpi); + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER)); cfg.setMarshaller(null); @@ -126,7 +118,7 @@ public class IgniteDbMultiNodePutGetRestartSelfTest extends GridCommonAbstractTe public void testPutGetSimple() throws Exception { String home = U.getIgniteHome(); - allocPath = new File(home, "work/db/" + UUID.randomUUID()); + File allocPath = new File(home, "work/db/" + UUID.randomUUID()); allocPath.mkdirs(); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionDuringPartitionClearTest.java similarity index 92% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionDuringPartitionClearTest.java index 1d14c40bdb9b4..b4ffde8c2cdc7 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/DbPageEvictionDuringPartitionClearSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionDuringPartitionClearTest.java @@ -29,10 +29,10 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; @@ -40,7 +40,7 @@ /** * */ -public class DbPageEvictionDuringPartitionClearSelfTest extends GridCommonAbstractTest { +public class IgnitePdsPageEvictionDuringPartitionClearTest extends GridCommonAbstractTest { /** */ public static final String CACHE_NAME = "cache"; @@ -57,8 +57,6 @@ public class DbPageEvictionDuringPartitionClearSelfTest extends GridCommonAbstra cfg.setCacheConfiguration(ccfg); - MemoryConfiguration memCfg = new MemoryConfiguration(); - // Intentionally set small page cache size. MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); @@ -68,13 +66,18 @@ public class DbPageEvictionDuringPartitionClearSelfTest extends GridCommonAbstra memPlcCfg.setName("dfltMemPlc"); + MemoryConfiguration memCfg = new MemoryConfiguration(); + memCfg.setMemoryPolicies(memPlcCfg); memCfg.setDefaultMemoryPolicyName(memPlcCfg.getName()); cfg.setMemoryConfiguration(memCfg); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalMode(WALMode.LOG_ONLY) + ); return cfg; } @@ -86,13 +89,11 @@ public class DbPageEvictionDuringPartitionClearSelfTest extends GridCommonAbstra /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); System.setProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC, "true"); } /** {@inheritDoc} */ @Override protected void afterTestsStopped() throws Exception { - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); System.clearProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC); } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionTest.java similarity index 93% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionTest.java index f962f80809ca6..d48617d410b80 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbPageEvictionSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionTest.java @@ -32,7 +32,6 @@ import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; @@ -43,7 +42,7 @@ /** * */ -public class IgniteDbPageEvictionSelfTest extends GridCommonAbstractTest { +public class IgnitePdsPageEvictionTest extends GridCommonAbstractTest { /** IP finder. */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); @@ -85,11 +84,11 @@ public class IgniteDbPageEvictionSelfTest extends GridCommonAbstractTest { cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); - TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + cfg.setDiscoverySpi( + new TcpDiscoverySpi() + .setIpFinder(IP_FINDER) + ); - discoSpi.setIpFinder(IP_FINDER); - - cfg.setDiscoverySpi(discoSpi); cfg.setMarshaller(null); return cfg; @@ -99,8 +98,6 @@ public class IgniteDbPageEvictionSelfTest extends GridCommonAbstractTest { @Override protected void beforeTest() throws Exception { deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - assertNull(System.getProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE)); - stopAllGrids(); startGrids(1); @@ -138,8 +135,9 @@ public void testPageEvictionSql() throws Exception { } for (int i = 0; i < ENTRY_CNT; i++) { - List> rows = cache.query(new SqlFieldsQuery("select lVal from DbValue where iVal=?").setArgs(i)) - .getAll(); + List> rows = cache.query( + new SqlFieldsQuery("select lVal from DbValue where iVal=?").setArgs(i) + ).getAll(); assertEquals(1, rows.size()); assertEquals(Long.MAX_VALUE - i, rows.get(0).get(0)); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsRebalancingOnNotStableTopologyTest.java similarity index 95% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsRebalancingOnNotStableTopologyTest.java index e85c639faf444..dfe174accc251 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/RebalancingOnNotStableTopologyTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsRebalancingOnNotStableTopologyTest.java @@ -42,7 +42,7 @@ * There will be entries in WAL which belongs to evicted partitions. * We should ignore them (not throw exceptions). This point is tested. */ -public class RebalancingOnNotStableTopologyTest extends GridCommonAbstractTest { +public class IgnitePdsRebalancingOnNotStableTopologyTest extends GridCommonAbstractTest { /** Checkpoint frequency. */ private static final long CHECKPOINT_FREQUENCY = 2_000_000; @@ -56,8 +56,6 @@ public class RebalancingOnNotStableTopologyTest extends GridCommonAbstractTest { * @throws Exception When fails. */ public void test() throws Exception { - stopAllGrids(); - Ignite ex = startGrid(0); startGrid(1); @@ -165,11 +163,10 @@ public void test() throws Exception { cfg.setCacheConfiguration(ccfg); - PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); - - pCfg.setCheckpointingFrequency(CHECKPOINT_FREQUENCY); - - cfg.setPersistentStoreConfiguration(pCfg); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setCheckpointingFrequency(CHECKPOINT_FREQUENCY) + ); MemoryConfiguration memCfg = new MemoryConfiguration(); @@ -200,12 +197,14 @@ public void test() throws Exception { /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { stopAllGrids(); + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); } /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { stopAllGrids(); + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsTransactionsHangTest.java similarity index 96% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsTransactionsHangTest.java index 3d57ba4ed550e..0007a3b9a6381 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/TransactionsHangTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsTransactionsHangTest.java @@ -54,7 +54,7 @@ /** * Checks that transactions don't hang during checkpoint creation. */ -public class TransactionsHangTest extends GridCommonAbstractTest { +public class IgnitePdsTransactionsHangTest extends GridCommonAbstractTest { /** IP finder. */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); @@ -65,7 +65,7 @@ public class TransactionsHangTest extends GridCommonAbstractTest { private static final Integer PAGE_SIZE = 16; /** Cache name. */ - private static final String CACHE_NAME = "TransactionsHangTest"; + private static final String CACHE_NAME = "IgnitePdsTransactionsHangTest"; /** Number of insert threads. */ public static final int THREADS_CNT = 32; @@ -122,14 +122,11 @@ public class TransactionsHangTest extends GridCommonAbstractTest { cfg.setTransactionConfiguration(txCfg); - PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); - - pCfg.setWalHistorySize(1); - pCfg.setCheckpointingFrequency(CHECKPOINT_FREQUENCY); - - cfg.setPersistentStoreConfiguration(pCfg); - - MemoryConfiguration memCfg = new MemoryConfiguration(); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalHistorySize(1) + .setCheckpointingFrequency(CHECKPOINT_FREQUENCY) + ); MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); @@ -137,6 +134,8 @@ public class TransactionsHangTest extends GridCommonAbstractTest { memPlcCfg.setInitialSize(PAGE_CACHE_SIZE * 1024 * 1024); memPlcCfg.setMaxSize(PAGE_CACHE_SIZE * 1024 * 1024); + MemoryConfiguration memCfg = new MemoryConfiguration(); + memCfg.setMemoryPolicies(memPlcCfg); memCfg.setDefaultMemoryPolicyName("dfltMemPlc"); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsWholeClusterRestartTest.java similarity index 90% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsWholeClusterRestartTest.java index 6032cce628ba8..576b40e96c8a4 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgniteDbWholeClusterRestartSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsWholeClusterRestartTest.java @@ -32,7 +32,7 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.checkpoint.noop.NoopCheckpointSpi; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; @@ -40,7 +40,7 @@ /** * */ -public class IgniteDbWholeClusterRestartSelfTest extends GridCommonAbstractTest { +public class IgnitePdsWholeClusterRestartTest extends GridCommonAbstractTest { /** */ private static final int GRID_CNT = 5; @@ -84,7 +84,10 @@ public class IgniteDbWholeClusterRestartSelfTest extends GridCommonAbstractTest cfg.setCacheConfiguration(ccfg1); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalMode(WALMode.LOG_ONLY) + ); cfg.setConsistentId(gridName); @@ -93,8 +96,6 @@ public class IgniteDbWholeClusterRestartSelfTest extends GridCommonAbstractTest /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - stopAllGrids(); deleteWorkFiles(); @@ -107,13 +108,6 @@ public class IgniteDbWholeClusterRestartSelfTest extends GridCommonAbstractTest deleteWorkFiles(); } - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - super.afterTestsStopped(); - - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - } - /** * @throws IgniteCheckedException If failed. */ diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsCacheIntegrationTest.java similarity index 94% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsCacheIntegrationTest.java index 229c226c0efd2..97bb05ef204f2 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteCachePageStoreIntegrationSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsCacheIntegrationTest.java @@ -35,9 +35,9 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; @@ -49,7 +49,7 @@ /** * */ -public class IgniteCachePageStoreIntegrationSelfTest extends GridCommonAbstractTest { +public class IgnitePdsCacheIntegrationTest extends GridCommonAbstractTest { /** */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); @@ -76,7 +76,10 @@ public class IgniteCachePageStoreIntegrationSelfTest extends GridCommonAbstractT dbCfg.setMemoryPolicies(memPlcCfg); dbCfg.setDefaultMemoryPolicyName("dfltMemPlc"); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalMode(WALMode.LOG_ONLY) + ); cfg.setMemoryConfiguration(dbCfg); @@ -94,11 +97,7 @@ public class IgniteCachePageStoreIntegrationSelfTest extends GridCommonAbstractT cfg.setCacheConfiguration(ccfg); - TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); - - discoSpi.setIpFinder(IP_FINDER); - - cfg.setDiscoverySpi(discoSpi); + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER)); cfg.setMarshaller(null); @@ -114,16 +113,12 @@ public class IgniteCachePageStoreIntegrationSelfTest extends GridCommonAbstractT /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); } /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { super.afterTest(); - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsEvictionTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsEvictionTest.java index 2ef4524a66b30..45bcef651bbe8 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreEvictionSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsEvictionTest.java @@ -43,7 +43,7 @@ /** * Test for page evictions. */ -public class PageStoreEvictionSelfTest extends GridCommonAbstractTest { +public class IgnitePdsEvictionTest extends GridCommonAbstractTest { /** */ private static final int NUMBER_OF_SEGMENTS = 64; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsNoActualWalHistoryTest.java similarity index 91% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsNoActualWalHistoryTest.java index 1c5024a0cd9ca..5a9da83ac2604 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteNoActualWalHistorySelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsNoActualWalHistoryTest.java @@ -30,9 +30,9 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.typedef.X; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; @@ -41,7 +41,7 @@ /** * */ -public class IgniteNoActualWalHistorySelfTest extends GridCommonAbstractTest { +public class IgnitePdsNoActualWalHistoryTest extends GridCommonAbstractTest { /** Cache name. */ private static final String CACHE_NAME = "cache"; @@ -63,13 +63,13 @@ public class IgniteNoActualWalHistorySelfTest extends GridCommonAbstractTest { cfg.setMemoryConfiguration(dbCfg); - PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); - - pCfg.setWalSegmentSize(4 * 1024 * 1024); - pCfg.setWalHistorySize(2); - pCfg.setWalSegments(10); - - cfg.setPersistentStoreConfiguration(pCfg); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalSegmentSize(4 * 1024 * 1024) + .setWalHistorySize(2) + .setWalSegments(10) + .setWalMode(WALMode.LOG_ONLY) + ); cfg.setMarshaller(null); @@ -87,8 +87,6 @@ public class IgniteNoActualWalHistorySelfTest extends GridCommonAbstractTest { stopAllGrids(); deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); } /** {@inheritDoc} */ @@ -96,8 +94,6 @@ public class IgniteNoActualWalHistorySelfTest extends GridCommonAbstractTest { stopAllGrids(); deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); } /** diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/ignitePdsCheckpointSimulationTest.java similarity index 96% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/ignitePdsCheckpointSimulationTest.java index 0addcb3e8ff25..b30162d3531a0 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/PageStoreCheckpointSimulationSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/ignitePdsCheckpointSimulationTest.java @@ -40,6 +40,7 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.pagemem.FullPageId; @@ -52,7 +53,6 @@ import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; 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; @@ -80,7 +80,7 @@ /** * */ -public class PageStoreCheckpointSimulationSelfTest extends GridCommonAbstractTest { +public class ignitePdsCheckpointSimulationTest extends GridCommonAbstractTest { /** */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); @@ -90,11 +90,14 @@ public class PageStoreCheckpointSimulationSelfTest extends GridCommonAbstractTes /** */ private static final boolean VERBOSE = false; + /** Cache name. */ + private final String cacheName = "cache"; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - CacheConfiguration ccfg = new CacheConfiguration("partitioned"); + CacheConfiguration ccfg = new CacheConfiguration(cacheName); ccfg.setRebalanceMode(CacheRebalanceMode.NONE); @@ -104,11 +107,12 @@ public class PageStoreCheckpointSimulationSelfTest extends GridCommonAbstractTes cfg.setMemoryConfiguration(dbCfg); - PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); - - pCfg.setCheckpointingFrequency(500); - - cfg.setPersistentStoreConfiguration(pCfg); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setCheckpointingFrequency(500) + .setWalMode(WALMode.LOG_ONLY) + .setAlwaysWriteFullPages(true) + ); TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); @@ -124,18 +128,10 @@ public class PageStoreCheckpointSimulationSelfTest extends GridCommonAbstractTes stopAllGrids(); deleteWorkFiles(); - - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES, "true"); } /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_ALWAYS_WRITE_FULL_PAGES); - stopAllGrids(); deleteWorkFiles(); @@ -160,7 +156,7 @@ public void testCheckpointSimulationMultiThreaded() throws Exception { // Must put something in partition 0 in order to initialize meta page. // Otherwise we will violate page store integrity rules. - ig.cache("partitioned").put(0, 0); + ig.cache(cacheName).put(0, 0); PageMemory mem = shared.database().memoryPolicy(null).pageMemory(); @@ -168,7 +164,7 @@ public void testCheckpointSimulationMultiThreaded() throws Exception { try { res = runCheckpointing(ig, (PageMemoryImpl)mem, pageStore, shared.wal(), - shared.cache().cache("partitioned").context().cacheId()); + shared.cache().cache(cacheName).context().cacheId()); } catch (Throwable th) { log().error("Error while running checkpointing", th); @@ -202,7 +198,7 @@ public void testGetForInitialWrite() throws Exception { GridCacheSharedContext shared = ig.context().cache().context(); - int cacheId = shared.cache().cache("partitioned").context().cacheId(); + int cacheId = shared.cache().cache(cacheName).context().cacheId(); GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)shared.database(); @@ -294,7 +290,7 @@ public void testDataWalEntries() throws Exception { IgniteEx ig = startGrid(0); GridCacheSharedContext sharedCtx = ig.context().cache().context(); - GridCacheContext cctx = sharedCtx.cache().cache("partitioned").context(); + GridCacheContext cctx = sharedCtx.cache().cache(cacheName).context(); GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)sharedCtx.database(); IgniteWriteAheadLogManager wal = sharedCtx.wal(); @@ -340,7 +336,7 @@ public void testDataWalEntries() throws Exception { ig = startGrid(0); sharedCtx = ig.context().cache().context(); - cctx = sharedCtx.cache().cache("partitioned").context(); + cctx = sharedCtx.cache().cache(cacheName).context(); db = (GridCacheDatabaseSharedManager)sharedCtx.database(); wal = sharedCtx.wal(); @@ -413,7 +409,7 @@ public void testPageWalEntries() throws Exception { IgniteEx ig = startGrid(0); GridCacheSharedContext sharedCtx = ig.context().cache().context(); - int cacheId = sharedCtx.cache().cache("partitioned").context().cacheId(); + int cacheId = sharedCtx.cache().cache(cacheName).context().cacheId(); GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)sharedCtx.database(); PageMemory pageMem = sharedCtx.database().memoryPolicy(null).pageMemory(); @@ -526,7 +522,7 @@ public void testDirtyFlag() throws Exception { GridCacheSharedContext shared = ig.context().cache().context(); - int cacheId = shared.cache().cache("partitioned").context().cacheId(); + int cacheId = shared.cache().cache(cacheName).context().cacheId(); GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)shared.database(); @@ -750,6 +746,7 @@ private IgniteBiTuple, WALPointer> runCheckpointing( final ConcurrentMap resMap = new ConcurrentHashMap<>(); final FullPageId pages[] = new FullPageId[TOTAL_PAGES]; + Set allocated = new HashSet<>(); for (int i = 0; i < TOTAL_PAGES; i++) { @@ -758,6 +755,7 @@ private IgniteBiTuple, WALPointer> runCheckpointing( resMap.put(fullId, -1); pages[i] = fullId; + allocated.add(fullId); } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgnitePdsWalTlbTest.java similarity index 88% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgnitePdsWalTlbTest.java index 26e2aa6d433ed..03b1384d3faab 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreWalTlbSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgnitePdsWalTlbTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.cache.database.db.wal; import javax.cache.CacheException; import org.apache.ignite.IgniteDataStreamer; @@ -25,7 +25,6 @@ import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; 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.TcpDiscoveryIpFinder; @@ -37,7 +36,7 @@ /** * */ -public class IgnitePersistentStoreWalTlbSelfTest extends GridCommonAbstractTest { +public class IgnitePdsWalTlbTest extends GridCommonAbstractTest { /** Ip finder. */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); @@ -68,6 +67,7 @@ public class IgnitePersistentStoreWalTlbSelfTest extends GridCommonAbstractTest cfg.setPersistentStoreConfiguration( new PersistentStoreConfiguration() .setCheckpointingPageBufferSize(DFLT_CHECKPOINTING_PAGE_BUFFER_SIZE + 1) + .setTlbSize(640000000) ); TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); @@ -82,16 +82,6 @@ public class IgnitePersistentStoreWalTlbSelfTest extends GridCommonAbstractTest return cfg; } - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_TLB_SIZE, "640000000"); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_TLB_SIZE); - } - /** {@inheritDoc} */ @Override protected long getTestTimeout() { return 30_000; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalDirectoriesConfigurationTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalDirectoriesConfigurationTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalDirectoriesConfigurationTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalDirectoriesConfigurationTest.java index 2e31686eb2419..4cca40145bb73 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalDirectoriesConfigurationTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalDirectoriesConfigurationTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.file; +package org.apache.ignite.cache.database.db.wal; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalHistoryReservationsTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalHistoryReservationsTest.java index aec38746b2ac5..fc46c2ec5e8e5 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalHistoryReservationsSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalHistoryReservationsTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.file; +package org.apache.ignite.cache.database.db.wal; import java.util.Map; import java.util.concurrent.locks.Lock; @@ -44,7 +44,7 @@ /** * */ -public class IgniteWalHistoryReservationsSelfTest extends GridCommonAbstractTest { +public class IgniteWalHistoryReservationsTest extends GridCommonAbstractTest { /** */ private volatile boolean client; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoverySeveralRestartsTest.java similarity index 96% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoverySeveralRestartsTest.java index 9b0231d329cf9..d70bea2c9554e 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySeveralRestartsTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoverySeveralRestartsTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.file; +package org.apache.ignite.cache.database.db.wal; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; @@ -32,8 +32,8 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.GridTestUtils; @@ -93,9 +93,10 @@ public class IgniteWalRecoverySeveralRestartsTest extends GridCommonAbstractTest cfg.setMemoryConfiguration(dbCfg); - PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); - - cfg.setPersistentStoreConfiguration(pCfg); + cfg.setPersistentStoreConfiguration( + new PersistentStoreConfiguration() + .setWalMode(WALMode.LOG_ONLY) + ); cfg.setMarshaller(null); @@ -112,8 +113,6 @@ public class IgniteWalRecoverySeveralRestartsTest extends GridCommonAbstractTest @Override protected void beforeTest() throws Exception { deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - super.beforeTest(); } @@ -121,8 +120,6 @@ public class IgniteWalRecoverySeveralRestartsTest extends GridCommonAbstractTest @Override protected void afterTest() throws Exception { super.afterTest(); - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoveryTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoveryTest.java index 225a9d2281834..4eb3d34bf44ea 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgniteWalRecoverySelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoveryTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.file; +package org.apache.ignite.cache.database.db.wal; import java.io.File; import java.nio.ByteBuffer; @@ -45,6 +45,7 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteInterruptedCheckedException; @@ -77,12 +78,10 @@ import org.junit.Assert; import sun.nio.ch.DirectBuffer; -import static org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE; - /** * */ -public class IgniteWalRecoverySelfTest extends GridCommonAbstractTest { +public class IgniteWalRecoveryTest extends GridCommonAbstractTest { /** */ private static final String HAS_CACHE = "HAS_CACHE"; @@ -98,6 +97,9 @@ public class IgniteWalRecoverySelfTest extends GridCommonAbstractTest { /** */ private int walSegmentSize; + /** Logger only. */ + private boolean logOnly; + /** {@inheritDoc} */ @Override protected boolean isMultiJvm() { return fork; @@ -134,6 +136,9 @@ public class IgniteWalRecoverySelfTest extends GridCommonAbstractTest { PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration(); + if (logOnly) + pCfg.setWalMode(WALMode.LOG_ONLY); + if (walSegmentSize != 0) pCfg.setWalSegmentSize(walSegmentSize); @@ -166,6 +171,8 @@ public class IgniteWalRecoverySelfTest extends GridCommonAbstractTest { @Override protected void afterTest() throws Exception { stopAllGrids(); + logOnly = false; + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); } @@ -394,14 +401,18 @@ public void testWalLargeValue() throws Exception { * @throws Exception if failed. */ public void testWalRolloverMultithreadedDefault() throws Exception { - checkWalRolloverMultithreaded(false); + logOnly = false; + + checkWalRolloverMultithreaded(); } /** * @throws Exception if failed. */ public void testWalRolloverMultithreadedLogOnly() throws Exception { - checkWalRolloverMultithreaded(true); + logOnly = true; + + checkWalRolloverMultithreaded(); } /** @@ -409,8 +420,6 @@ public void testWalRolloverMultithreadedLogOnly() throws Exception { */ public void testHugeCheckpointRecord() throws Exception { try { - System.setProperty(IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - final IgniteEx ignite = startGrid(1); for (int i = 0; i < 50; i++) { @@ -449,8 +458,6 @@ public void testHugeCheckpointRecord() throws Exception { fut.get(); } finally { - System.clearProperty(IGNITE_PDS_WAL_MODE); - stopAllGrids(); } } @@ -458,10 +465,7 @@ public void testHugeCheckpointRecord() throws Exception { /** * @throws Exception if failed. */ - private void checkWalRolloverMultithreaded(boolean logOnly) throws Exception { - if (logOnly) - System.setProperty(IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - + private void checkWalRolloverMultithreaded() throws Exception { walSegmentSize = 2 * 1024 * 1024; final long endTime = System.currentTimeMillis() + 2 * 60 * 1000; @@ -483,8 +487,6 @@ private void checkWalRolloverMultithreaded(boolean logOnly) throws Exception { }, 16, "put-thread"); } finally { - System.clearProperty(IGNITE_PDS_WAL_MODE); - stopAllGrids(); } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/WalRecoveryTxLogicalRecordsTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/WalRecoveryTxLogicalRecordsTest.java index fa537231eb586..30a7f9ea827eb 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/WalRecoveryTxLogicalRecordsTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/WalRecoveryTxLogicalRecordsTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.file; +package org.apache.ignite.cache.database.db.wal; import java.io.File; import java.util.ArrayList; @@ -84,7 +84,7 @@ public class WalRecoveryTxLogicalRecordsTest extends GridCommonAbstractTest { private int pageSize = 4 * 1024; /** */ - private CacheConfiguration extraCcfg; + private CacheConfiguration extraCcfg; /** */ private Long checkpointFreq; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreePageMemoryImplTest.java similarity index 86% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreePageMemoryImplTest.java index 1eab1f884c5b7..a35903c9e6023 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeSelfTestPageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreePageMemoryImplTest.java @@ -29,7 +29,6 @@ import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.processors.database.BPlusTreeSelfTest; import org.apache.ignite.internal.util.typedef.CIX3; import org.apache.ignite.testframework.junits.GridTestKernalContext; @@ -37,21 +36,7 @@ /** * */ -public class BPlusTreeSelfTestPageMemoryImplSelfTest extends BPlusTreeSelfTest { - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - - super.beforeTest(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - super.afterTest(); - - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - } - +public class BPlusTreePageMemoryImplTest extends BPlusTreeSelfTest { /** {@inheritDoc} */ @Override protected PageMemory createPageMemory() throws Exception { long[] sizes = new long[CPUS + 1]; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplTest.java similarity index 86% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplTest.java index b533ed1367ba0..5c4502c187e34 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplTest.java @@ -29,7 +29,6 @@ import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.processors.database.BPlusTreeReuseSelfTest; import org.apache.ignite.internal.util.lang.GridInClosure3X; import org.apache.ignite.internal.util.typedef.CIX3; @@ -38,21 +37,7 @@ /** * */ -public class BPlusTreeReuseListPageMemoryImplSelfTest extends BPlusTreeReuseSelfTest { - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - System.setProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE, "LOG_ONLY"); - - super.beforeTest(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - super.afterTest(); - - System.clearProperty(FileWriteAheadLogManager.IGNITE_PDS_WAL_MODE); - } - +public class BPlusTreeReuseListPageMemoryImplTest extends BPlusTreeReuseSelfTest { /** {@inheritDoc} */ @Override protected PageMemory createPageMemory() throws Exception { long[] sizes = new long[CPUS + 1]; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplTest.java index c9c6c18039e35..a6e241c21dbe4 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplTest.java @@ -39,7 +39,7 @@ /** * */ -public class MetadataStoragePageMemoryImplSelfTest extends MetadataStorageSelfTest{ +public class MetadataStoragePageMemoryImplTest extends MetadataStorageSelfTest{ /** Make sure page is small enough to trigger multiple pages in a linked list. */ public static final int PAGE_SIZE = 1024; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadTest.java index 8ff5345e03164..38baea8cf73b6 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadSelfTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadTest.java @@ -39,7 +39,7 @@ /** * */ -public class PageMemoryImplNoLoadSelfTest extends PageMemoryNoLoadSelfTest { +public class PageMemoryImplNoLoadTest extends PageMemoryNoLoadSelfTest { /** * @return Page memory implementation. */ diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java index 62239edf49181..f392e6bad7289 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java @@ -36,7 +36,7 @@ /** * */ -public abstract class GridChangeGlobalStateAbstractTest extends GridCommonAbstractTest { +public abstract class IgniteChangeGlobalStateAbstractTest extends GridCommonAbstractTest { /** Primary suffix. */ private static final String primarySuffix = "-primary"; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateCacheTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateCacheTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateCacheTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateCacheTest.java index 06ceeec0fa764..ebbab5885efc4 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateCacheTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateCacheTest.java @@ -28,7 +28,7 @@ /** * */ -public class GridChangeGlobalStateCacheTest extends GridChangeGlobalStateAbstractTest { +public class IgniteChangeGlobalStateCacheTest extends IgniteChangeGlobalStateAbstractTest { /** * */ diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java index 20ddd8202a624..bd655976a95d3 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java @@ -24,7 +24,7 @@ /** * */ -public class GridChangeGlobalStateDataStreamerTest extends GridChangeGlobalStateAbstractTest { +public class IgniteChangeGlobalStateDataStreamerTest extends IgniteChangeGlobalStateAbstractTest { /** {@inheritDoc} */ @Override protected int backUpNodes() { return 0; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStructureTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStructureTest.java index a33a02eefa880..d10521e0ea485 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStructureTest.java @@ -33,7 +33,7 @@ /** * */ -public class GridChangeGlobalStateDataStructureTest extends GridChangeGlobalStateAbstractTest { +public class IgniteChangeGlobalStateDataStructureTest extends IgniteChangeGlobalStateAbstractTest { /** * */ diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateFailOverTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateFailOverTest.java index 2fb5137cd3f1f..53a2eec30cf42 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateFailOverTest.java @@ -32,7 +32,7 @@ /** * */ -public class GridChangeGlobalStateFailOverTest extends GridChangeGlobalStateAbstractTest { +public class IgniteChangeGlobalStateFailOverTest extends IgniteChangeGlobalStateAbstractTest { /** {@inheritDoc} */ @Override protected int primaryNodes() { return 0; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateServiceTest.java similarity index 96% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateServiceTest.java index f6fbc2cb5e501..da4d20cc50620 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateServiceTest.java @@ -29,7 +29,7 @@ /** * */ -public class GridChangeGlobalStateServiceTest extends GridChangeGlobalStateAbstractTest { +public class IgniteChangeGlobalStateServiceTest extends IgniteChangeGlobalStateAbstractTest { /** {@inheritDoc} */ @Override protected int backUpClientNodes() { return 0; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java rename to modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateTest.java index b7dd082ae1dfd..d87ec5ef62339 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateTest.java @@ -39,7 +39,7 @@ /** * */ -public class GridChangeGlobalStateTest extends GridChangeGlobalStateAbstractTest { +public class IgniteChangeGlobalStateTest extends IgniteChangeGlobalStateAbstractTest { /** * @throws Exception if fail. */ diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java index dc733bf26e28d..59b7f393ae176 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java @@ -18,7 +18,7 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; -import org.apache.ignite.cache.database.IgnitePersistentStoreWalTlbSelfTest; +import org.apache.ignite.cache.database.db.wal.IgnitePdsWalTlbTest; /** * @@ -31,7 +31,7 @@ public class IgnitePdsOutOfMemoryTestSuite extends TestSuite { public static TestSuite suite() throws Exception { TestSuite suite = new TestSuite("Ignite Persistent Store OOM Test Suite"); - suite.addTestSuite(IgnitePersistentStoreWalTlbSelfTest.class); + suite.addTestSuite(IgnitePdsWalTlbTest.class); return suite; } diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java index d38d403c1b05c..d0c55c9fd8df0 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java @@ -19,21 +19,21 @@ import junit.framework.TestSuite; import org.apache.ignite.cache.database.IgnitePersistentStoreCacheGroupsTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreDynamicCacheTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest; -import org.apache.ignite.cache.database.db.IgniteDbMultiNodePutGetRestartSelfTest; -import org.apache.ignite.cache.database.db.IgniteDbPageEvictionSelfTest; -import org.apache.ignite.cache.database.db.file.IgniteCachePageStoreIntegrationSelfTest; -import org.apache.ignite.cache.database.db.file.IgniteWalDirectoriesConfigurationTest; -import org.apache.ignite.cache.database.db.file.PageStoreCheckpointSimulationSelfTest; -import org.apache.ignite.cache.database.db.file.PageStoreEvictionSelfTest; -import org.apache.ignite.cache.database.pagemem.BPlusTreeReuseListPageMemoryImplSelfTest; -import org.apache.ignite.cache.database.pagemem.BPlusTreeSelfTestPageMemoryImplSelfTest; -import org.apache.ignite.cache.database.pagemem.MetadataStoragePageMemoryImplSelfTest; -import org.apache.ignite.cache.database.pagemem.PageMemoryImplNoLoadSelfTest; +import org.apache.ignite.cache.database.IgnitePdsClientNearCachePutGetTest; +import org.apache.ignite.cache.database.IgnitePdsDynamicCacheTest; +import org.apache.ignite.cache.database.IgnitePdsSingleNodePutGetPersistenceTest; +import org.apache.ignite.cache.database.IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest; +import org.apache.ignite.cache.database.IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest; +import org.apache.ignite.cache.database.db.IgnitePdsMultiNodePutGetRestartTest; +import org.apache.ignite.cache.database.db.IgnitePdsPageEvictionTest; +import org.apache.ignite.cache.database.db.file.IgnitePdsCacheIntegrationTest; +import org.apache.ignite.cache.database.db.wal.IgniteWalDirectoriesConfigurationTest; +import org.apache.ignite.cache.database.db.file.ignitePdsCheckpointSimulationTest; +import org.apache.ignite.cache.database.db.file.IgnitePdsEvictionTest; +import org.apache.ignite.cache.database.pagemem.BPlusTreeReuseListPageMemoryImplTest; +import org.apache.ignite.cache.database.pagemem.BPlusTreePageMemoryImplTest; +import org.apache.ignite.cache.database.pagemem.MetadataStoragePageMemoryImplTest; +import org.apache.ignite.cache.database.pagemem.PageMemoryImplNoLoadTest; import org.apache.ignite.cache.database.pagemem.PageMemoryImplTest; import org.apache.ignite.internal.processors.database.IgniteDbClientNearCachePutGetTest; import org.apache.ignite.internal.processors.database.IgniteDbDynamicCacheSelfTest; @@ -56,18 +56,18 @@ public static TestSuite suite() throws Exception { TestSuite suite = new TestSuite("Ignite Persistent Store Test Suite"); // Basic PageMemory tests. - suite.addTestSuite(PageMemoryImplNoLoadSelfTest.class); - suite.addTestSuite(MetadataStoragePageMemoryImplSelfTest.class); - suite.addTestSuite(PageStoreEvictionSelfTest.class); + suite.addTestSuite(PageMemoryImplNoLoadTest.class); + suite.addTestSuite(MetadataStoragePageMemoryImplTest.class); + suite.addTestSuite(IgnitePdsEvictionTest.class); suite.addTestSuite(PageMemoryImplTest.class); // Checkpointing smoke-test. - suite.addTestSuite(IgniteCachePageStoreIntegrationSelfTest.class); - suite.addTestSuite(PageStoreCheckpointSimulationSelfTest.class); + suite.addTestSuite(IgnitePdsCacheIntegrationTest.class); + suite.addTestSuite(ignitePdsCheckpointSimulationTest.class); // BTree tests with store page memory. - suite.addTestSuite(BPlusTreeSelfTestPageMemoryImplSelfTest.class); - suite.addTestSuite(BPlusTreeReuseListPageMemoryImplSelfTest.class); + suite.addTestSuite(BPlusTreePageMemoryImplTest.class); + suite.addTestSuite(BPlusTreeReuseListPageMemoryImplTest.class); // Basic API tests. suite.addTestSuite(IgniteDbSingleNodePutGetTest.class); @@ -79,14 +79,14 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(IgniteDbClientNearCachePutGetTest.class); // Persistence-enabled. - suite.addTestSuite(IgniteDbMultiNodePutGetRestartSelfTest.class); - suite.addTestSuite(IgnitePersistentStoreSingleNodePutGetPersistenceSelfTest.class); - suite.addTestSuite(IgnitePersistentStoreSingleNodeWithIndexingPutGetPersistenceSelfTest.class); - suite.addTestSuite(IgnitePersistentStoreSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.class); - suite.addTestSuite(IgniteDbPageEvictionSelfTest.class); - suite.addTestSuite(IgnitePersistentStoreDynamicCacheTest.class); + suite.addTestSuite(IgnitePdsMultiNodePutGetRestartTest.class); + suite.addTestSuite(IgnitePdsSingleNodePutGetPersistenceTest.class); + suite.addTestSuite(IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.class); + suite.addTestSuite(IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.class); + suite.addTestSuite(IgnitePdsPageEvictionTest.class); + suite.addTestSuite(IgnitePdsDynamicCacheTest.class); suite.addTestSuite(IgniteWalDirectoriesConfigurationTest.class); - suite.addTestSuite(IgnitePersistentStoreClientNearCachePutGetWithPersistenceSelfTest.class); + suite.addTestSuite(IgnitePdsClientNearCachePutGetTest.class); suite.addTestSuite(IgnitePersistentStoreCacheGroupsTest.class); diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java index 1f45c25dc2560..acfac6386d60c 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java @@ -18,24 +18,23 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; +import org.apache.ignite.cache.database.IgnitePdsAtomicCacheRebalancingTest; +import org.apache.ignite.cache.database.IgnitePdsTxCacheRebalancingTest; +import org.apache.ignite.cache.database.IgnitePdsContinuousRestartTest; +import org.apache.ignite.cache.database.IgnitePdsPageSizesTest; +import org.apache.ignite.cache.database.IgnitePdsRecoveryAfterFileCorruptionTest; import org.apache.ignite.cache.database.IgnitePersistenceMetricsSelfTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreAtomicCacheRebalancingTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreContinuousRestartSelfTest; import org.apache.ignite.cache.database.IgnitePersistentStoreDataStructuresTest; -import org.apache.ignite.cache.database.IgnitePersistentStorePageSizesTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreRecoveryAfterFileCorruptionTest; import org.apache.ignite.cache.database.IgnitePersistentStoreSchemaLoadTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreTxCacheRebalancingTest; -import org.apache.ignite.cache.database.db.DbPageEvictionDuringPartitionClearSelfTest; -import org.apache.ignite.cache.database.db.IgniteDbWholeClusterRestartSelfTest; -import org.apache.ignite.cache.database.db.RebalancingOnNotStableTopologyTest; -import org.apache.ignite.cache.database.db.TransactionsHangTest; -import org.apache.ignite.cache.database.db.file.IgniteNoActualWalHistorySelfTest; -import org.apache.ignite.cache.database.db.file.IgniteWalHistoryReservationsSelfTest; -import org.apache.ignite.cache.database.db.file.IgniteWalRecoverySelfTest; -import org.apache.ignite.cache.database.db.file.WalRecoveryTxLogicalRecordsTest; +import org.apache.ignite.cache.database.db.IgnitePdsPageEvictionDuringPartitionClearTest; +import org.apache.ignite.cache.database.db.IgnitePdsTransactionsHangTest; +import org.apache.ignite.cache.database.db.IgnitePdsWholeClusterRestartTest; +import org.apache.ignite.cache.database.db.IgnitePdsRebalancingOnNotStableTopologyTest; +import org.apache.ignite.cache.database.db.file.IgnitePdsNoActualWalHistoryTest; +import org.apache.ignite.cache.database.db.wal.IgniteWalHistoryReservationsTest; +import org.apache.ignite.cache.database.db.wal.IgniteWalRecoveryTest; +import org.apache.ignite.cache.database.db.wal.WalRecoveryTxLogicalRecordsTest; import org.apache.ignite.cache.database.db.wal.crc.IgniteDataIntegrityTests; -import org.apache.ignite.internal.pagemem.impl.PageMemoryNoLoadSelfTest; /** * @@ -46,36 +45,36 @@ public class IgnitePdsTestSuite2 extends TestSuite { * @throws Exception If failed. */ public static TestSuite suite() throws Exception { - TestSuite suite = new TestSuite("Ignite persistent Store Test Suite"); + TestSuite suite = new TestSuite("Ignite persistent Store Test Suite 2"); // Integrity test. suite.addTestSuite(IgniteDataIntegrityTests.class); - suite.addTestSuite(IgnitePersistentStoreRecoveryAfterFileCorruptionTest.class); - suite.addTestSuite(IgnitePersistentStorePageSizesTest.class); + suite.addTestSuite(IgnitePdsRecoveryAfterFileCorruptionTest.class); + suite.addTestSuite(IgnitePdsPageSizesTest.class); // Metrics test. suite.addTestSuite(IgnitePersistenceMetricsSelfTest.class); // WAL recovery test. suite.addTestSuite(WalRecoveryTxLogicalRecordsTest.class); - suite.addTestSuite(IgniteWalRecoverySelfTest.class); + suite.addTestSuite(IgniteWalRecoveryTest.class); - suite.addTestSuite(TransactionsHangTest.class); + suite.addTestSuite(IgnitePdsTransactionsHangTest.class); - suite.addTestSuite(IgniteNoActualWalHistorySelfTest.class); + suite.addTestSuite(IgnitePdsNoActualWalHistoryTest.class); - suite.addTestSuite(RebalancingOnNotStableTopologyTest.class); + suite.addTestSuite(IgnitePdsRebalancingOnNotStableTopologyTest.class); - suite.addTestSuite(IgniteDbWholeClusterRestartSelfTest.class); + suite.addTestSuite(IgnitePdsWholeClusterRestartTest.class); - suite.addTestSuite(DbPageEvictionDuringPartitionClearSelfTest.class); + suite.addTestSuite(IgnitePdsPageEvictionDuringPartitionClearTest.class); // Rebalancing test - suite.addTestSuite(IgnitePersistentStoreAtomicCacheRebalancingTest.class); - suite.addTestSuite(IgnitePersistentStoreTxCacheRebalancingTest.class); - suite.addTestSuite(IgniteWalHistoryReservationsSelfTest.class); + suite.addTestSuite(IgnitePdsAtomicCacheRebalancingTest.class); + suite.addTestSuite(IgnitePdsTxCacheRebalancingTest.class); + suite.addTestSuite(IgniteWalHistoryReservationsTest.class); - suite.addTestSuite(IgnitePersistentStoreContinuousRestartSelfTest.class); + suite.addTestSuite(IgnitePdsContinuousRestartTest.class); suite.addTestSuite(IgnitePersistentStoreSchemaLoadTest.class); suite.addTestSuite(IgnitePersistentStoreDataStructuresTest.class); diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java index 2d0006158621b..1d0754be870e9 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java +++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java @@ -18,11 +18,11 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; -import org.apache.ignite.cache.database.standbycluster.GridChangeGlobalStateCacheTest; -import org.apache.ignite.cache.database.standbycluster.GridChangeGlobalStateDataStreamerTest; -import org.apache.ignite.cache.database.standbycluster.GridChangeGlobalStateDataStructureTest; -import org.apache.ignite.cache.database.standbycluster.GridChangeGlobalStateFailOverTest; -import org.apache.ignite.cache.database.standbycluster.GridChangeGlobalStateTest; +import org.apache.ignite.cache.database.standbycluster.IgniteChangeGlobalStateCacheTest; +import org.apache.ignite.cache.database.standbycluster.IgniteChangeGlobalStateDataStreamerTest; +import org.apache.ignite.cache.database.standbycluster.IgniteChangeGlobalStateDataStructureTest; +import org.apache.ignite.cache.database.standbycluster.IgniteChangeGlobalStateFailOverTest; +import org.apache.ignite.cache.database.standbycluster.IgniteChangeGlobalStateTest; /** * @@ -34,12 +34,12 @@ public class IgniteStandByClusterSuite extends TestSuite { public static TestSuite suite() { TestSuite suite = new TestSuite("Ignite Activate/DeActivate Cluster Test Suit"); - suite.addTestSuite(GridChangeGlobalStateTest.class); - suite.addTestSuite(GridChangeGlobalStateCacheTest.class); - suite.addTestSuite(GridChangeGlobalStateDataStructureTest.class); - suite.addTestSuite(GridChangeGlobalStateDataStreamerTest.class); - suite.addTestSuite(GridChangeGlobalStateFailOverTest.class); -// suite.addTestSuite(GridChangeGlobalStateServiceTest.class); + suite.addTestSuite(IgniteChangeGlobalStateTest.class); + suite.addTestSuite(IgniteChangeGlobalStateCacheTest.class); + suite.addTestSuite(IgniteChangeGlobalStateDataStructureTest.class); + suite.addTestSuite(IgniteChangeGlobalStateDataStreamerTest.class); + suite.addTestSuite(IgniteChangeGlobalStateFailOverTest.class); +// suite.addTestSuite(IgniteChangeGlobalStateServiceTest.class); return suite; } From 4269eee2a43674b4a24b81ee3b09210b9c0eb202 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 10:28:34 +0300 Subject: [PATCH 245/311] WIP. --- .../org/apache/ignite/internal/binary/BinaryContext.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java index 8f7720d9e43f5..72a387163c88e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java @@ -321,9 +321,9 @@ public BinaryContext(BinaryMetadataHandler metaHnd, IgniteConfiguration igniteCf registerPredefinedType(LinkedHashMap.class, 0); // Classes with overriden default serialization flag. - registerPredefinedType(AffinityKey.class, 0, affinityFieldName(AffinityKey.class), false); - registerPredefinedType(CollocatedSetItemKey.class, 0, affinityFieldName(CollocatedSetItemKey.class), false); - registerPredefinedType(CollocatedQueueItemKey.class, 0, affinityFieldName(CollocatedQueueItemKey.class), false); + registerPredefinedType(AffinityKey.class, 0, affinityFieldName(AffinityKey.class), true); + registerPredefinedType(CollocatedSetItemKey.class, 0, affinityFieldName(CollocatedSetItemKey.class), true); + registerPredefinedType(CollocatedQueueItemKey.class, 0, affinityFieldName(CollocatedQueueItemKey.class), true); registerPredefinedType(GridMapEntry.class, 60); registerPredefinedType(IgniteBiTuple.class, 61); From 54afab2b9b934e9dae96c5eb095ab4a344633b34 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 10:35:48 +0300 Subject: [PATCH 246/311] Returning old mappings. --- .../ignite/internal/binary/BinaryContext.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java index 72a387163c88e..4659f22c2c407 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java @@ -225,6 +225,9 @@ public class BinaryContext { /** Maps typeId to mappers. */ private final ConcurrentMap typeId2Mapper = new ConcurrentHashMap8<>(0); + /** Affinity key field names. */ + private final ConcurrentMap affKeyFieldNames = new ConcurrentHashMap8<>(0); + /** Maps className to mapper */ private final ConcurrentMap cls2Mappers = new ConcurrentHashMap8<>(0); @@ -457,13 +460,19 @@ private void configure( if (clsName.endsWith(".*")) { String pkgName = clsName.substring(0, clsName.length() - 2); - for (String clsName0 : classesInPackage(pkgName)) - descs.add(clsName0, mapper, serializer, identity, affFields.get(clsName0), + for (String clsName0 : classesInPackage(pkgName)) { + String affField = affFields.remove(clsName0); + + descs.add(clsName0, mapper, serializer, identity, affField, typeCfg.isEnum(), typeCfg.getEnumValues(), true); + } } - else + else { + String affField = affFields.remove(clsName); + descs.add(clsName, mapper, serializer, identity, affFields.get(clsName), typeCfg.isEnum(), typeCfg.getEnumValues(), false); + } } } @@ -471,7 +480,16 @@ private void configure( registerUserType(desc.clsName, desc.mapper, desc.serializer, desc.identity, desc.affKeyFieldName, desc.isEnum, desc.enumMap); - // TODO: Register rest classes from "affFields". + BinaryInternalMapper globalMapper = resolveMapper(globalNameMapper, globalIdMapper); + + // Put affinity field names for unconfigured types. + for (Map.Entry entry : affFields.entrySet()) { + String typeName = entry.getKey(); + + int typeId = globalMapper.typeId(typeName); + + affKeyFieldNames.putIfAbsent(typeId, entry.getValue()); + } } /** From 78276a21878559e14b8cf9d0407cda62aebf1bb0 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 10:38:54 +0300 Subject: [PATCH 247/311] WIP. --- .../apache/ignite/internal/binary/BinaryContext.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java index 4659f22c2c407..ec769a063158a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java @@ -470,7 +470,7 @@ private void configure( else { String affField = affFields.remove(clsName); - descs.add(clsName, mapper, serializer, identity, affFields.get(clsName), + descs.add(clsName, mapper, serializer, identity, affField, typeCfg.isEnum(), typeCfg.getEnumValues(), false); } } @@ -1076,6 +1076,9 @@ public BinaryClassDescriptor registerPredefinedType(Class cls, int id, String descByCls.put(cls, desc); + if (affFieldName != null) + affKeyFieldNames.putIfAbsent(id, affFieldName); + return desc; } @@ -1124,6 +1127,11 @@ public void registerUserType(String clsName, throw duplicateTypeIdException(clsName, id); } + if (affKeyFieldName != null) { + if (affKeyFieldNames.put(id, affKeyFieldName) != null) + throw duplicateTypeIdException(clsName, id); + } + cls2Mappers.put(clsName, mapper); Map fieldsMeta = null; From bc4a4c7774a1d1be2a2437fcfb241b5d6c966cd9 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 10:40:39 +0300 Subject: [PATCH 248/311] WIP. --- .../ignite/internal/binary/BinaryContext.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java index ec769a063158a..76c5a5059cd5a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java @@ -1238,13 +1238,22 @@ public BinaryType metadata(int typeId, int schemaId) throws BinaryObjectExceptio } /** + * Get affinity key field name for type. First consult to predefined configuration, then delegate to metadata. + * * @param typeId Type ID. * @return Affinity key field name. */ public String affinityKeyFieldName(int typeId) { - BinaryMetadata meta = metaHnd.metadata0(typeId); + String res = affKeyFieldNames.get(typeId); + + if (res == null) { + BinaryMetadata meta = metaHnd.metadata0(typeId); + + if (meta != null) + res = meta.affinityKeyFieldName(); + } - return meta != null ? meta.affinityKeyFieldName() : null; + return res; } /** From 53011359a1ccc85825ff09fbb28be2e57e6c78d6 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 10:42:04 +0300 Subject: [PATCH 249/311] WIP. --- .../cache/binary/CacheObjectBinaryProcessorImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java index 9dd3c6a33fa34..ed3ece5d6707a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java @@ -405,9 +405,7 @@ public GridBinaryMarshaller marshaller() { * @return Affinity field. */ @Nullable private String affinityField(int typeId) { - BinaryMetadata meta = metadata0(typeId); - - return meta != null ? meta.affinityKeyFieldName() : null; + return binaryCtx.affinityKeyFieldName(typeId); } /** {@inheritDoc} */ From 4c7e3653eb3d7abef843b2f9bab1da9519660d72 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 10:59:42 +0300 Subject: [PATCH 250/311] WIP. --- .../internal/processors/cache/GridCacheContext.java | 11 +++++++++++ .../ignite/internal/processors/query/QueryUtils.java | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java index 839ddbd9cdc52..d2cb4158ad013 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java @@ -2063,6 +2063,17 @@ else if (type == EVT_CACHE_REBALANCE_STOPPED) { return true; } + /** + * Get affinity field name for type. + * + * @param typeName Type name. + * @return Affinity field name. + */ + @Nullable public String affinityField(String typeName) { + // TODO: Consult to config first. + return ctx.cacheObjects().affinityField(typeName); + } + /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { U.writeString(out, igniteInstanceName()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java index e0815fd0b54bb..01e06a35b2e84 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java @@ -431,7 +431,7 @@ public static QueryTypeCandidate typeForQueryEntity(String cacheName, GridCacheC // Need to setup affinity key for distributed joins. if (!cctx.customAffinityMapper() && qryEntity.findKeyType() != null) - affField = ctx.cacheObjects().affinityField(qryEntity.findKeyType()); + affField = cctx.affinityField(qryEntity.findKeyType()); else if (cctx.config().getAffinityMapper() instanceof DynamicTableAffinityKeyMapper) affField = ((DynamicTableAffinityKeyMapper)cctx.config().getAffinityMapper()).fieldName(); From bc952483e626c6599faad41f2b3bb30162f407bb Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 12:30:40 +0300 Subject: [PATCH 251/311] WIP. --- .../CacheDefaultBinaryAffinityKeyMapper.java | 77 ++++++++++++++++++- .../processors/cache/GridCacheContext.java | 11 --- .../CacheDefaultBinaryAffinityKeyMapper.java | 51 ------------ .../binary/CacheObjectBinaryContext.java | 10 ++- .../CacheObjectBinaryProcessorImpl.java | 77 ++++++------------- .../IgniteCacheObjectProcessor.java | 6 -- .../internal/processors/query/QueryUtils.java | 6 +- .../resources/META-INF/classnames.properties | 1 - 8 files changed, 110 insertions(+), 129 deletions(-) delete mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultBinaryAffinityKeyMapper.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java index 9b3dd159d2494..ae43386a491da 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java @@ -19,10 +19,18 @@ import org.apache.ignite.Ignite; import org.apache.ignite.IgniteException; +import org.apache.ignite.binary.BinaryField; import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.cache.CacheKeyConfiguration; import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.binary.BinaryObjectEx; import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.U; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; /** * @@ -34,6 +42,24 @@ public class CacheDefaultBinaryAffinityKeyMapper extends GridCacheDefaultAffinit /** */ private CacheObjectBinaryProcessorImpl proc; + /** Mapping from type name to affinity field name. */ + private Map typeNameAffFields = new HashMap<>(); + + /** Mapping from type ID to affinity field name. */ + private volatile transient Map typeIdAffFields; + + /** + * Constructor. + * + * @param cacheKeyCfgs Cache key configurations. + */ + public CacheDefaultBinaryAffinityKeyMapper(@Nullable CacheKeyConfiguration[] cacheKeyCfgs) { + if (!F.isEmpty(cacheKeyCfgs)) { + for (CacheKeyConfiguration cacheKeyCfg : cacheKeyCfgs) + typeNameAffFields.put(cacheKeyCfg.getTypeName(), cacheKeyCfg.getAffinityKeyFieldName()); + } + } + /** {@inheritDoc} */ @Override public Object affinityKey(Object key) { try { @@ -43,12 +69,59 @@ public class CacheDefaultBinaryAffinityKeyMapper extends GridCacheDefaultAffinit U.error(log, "Failed to marshal key to binary: " + key, e); } - if (key instanceof BinaryObject) - return proc.affinityKey((BinaryObject)key); + if (key instanceof BinaryObject) { + assert key instanceof BinaryObjectEx : "All BinaryObject implementations must implement " + + BinaryObjectEx.class.getName() + ": " + key.getClass().getName(); + + BinaryObjectEx key0 = (BinaryObjectEx)key; + + BinaryField affField = affinityKeyField(key0.typeId()); + + if (affField == null) + affField = proc.affinityKeyField(key0); + + if (affField != null) { + Object res = affField.value(key0); + + if (res != null) + return res; + } + + return key; + } else return super.affinityKey(key); } + /** + * Get affinity field override for type. + * + * @param typeId Type ID. + * @return Affinity field override if any. + */ + @Nullable private BinaryField affinityKeyField(int typeId) { + Map typeIdAffFields0 = typeIdAffFields; + + if (typeIdAffFields0 == null) { + typeIdAffFields0 = new HashMap<>(); + + for (Map.Entry entry : typeNameAffFields.entrySet()) { + String typeName = entry.getKey(); + String affFieldName = entry.getValue(); + + int curTypeId = proc.typeId(typeName); + + BinaryField field = proc.binaryContext().createField(curTypeId, affFieldName); + + typeIdAffFields0.put(curTypeId, field); + } + + typeIdAffFields = typeIdAffFields0; + } + + return typeIdAffFields0.get(typeId); + } + /** {@inheritDoc} */ @Override public void ignite(Ignite ignite) { super.ignite(ignite); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java index d2cb4158ad013..839ddbd9cdc52 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java @@ -2063,17 +2063,6 @@ else if (type == EVT_CACHE_REBALANCE_STOPPED) { return true; } - /** - * Get affinity field name for type. - * - * @param typeName Type name. - * @return Affinity field name. - */ - @Nullable public String affinityField(String typeName) { - // TODO: Consult to config first. - return ctx.cacheObjects().affinityField(typeName); - } - /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { U.writeString(out, igniteInstanceName()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultBinaryAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultBinaryAffinityKeyMapper.java deleted file mode 100644 index 0ca06e3b2bc84..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultBinaryAffinityKeyMapper.java +++ /dev/null @@ -1,51 +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.binary; - -import org.apache.ignite.IgniteException; -import org.apache.ignite.internal.IgniteKernal; -import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.binary.BinaryObject; - -/** - * - */ -public class CacheDefaultBinaryAffinityKeyMapper extends GridCacheDefaultAffinityKeyMapper { - /** */ - private static final long serialVersionUID = 0L; - - /** {@inheritDoc} */ - @Override public Object affinityKey(Object key) { - IgniteKernal kernal = (IgniteKernal)ignite; - - CacheObjectBinaryProcessorImpl proc = (CacheObjectBinaryProcessorImpl)kernal.context().cacheObjects(); - - try { - key = proc.toBinary(key); - } - catch (IgniteException e) { - U.error(log, "Failed to marshal key to binary: " + key, e); - } - - if (key instanceof BinaryObject) - return proc.affinityKey((BinaryObject)key); - else - return super.affinityKey(key); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java index 3b3cf678d65d6..72f610e28fa3b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.processors.cache.binary; +import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.processors.cache.CacheDefaultBinaryAffinityKeyMapper; import org.apache.ignite.internal.processors.cache.CacheObjectContext; @@ -31,21 +32,22 @@ public class CacheObjectBinaryContext extends CacheObjectContext { /** * @param kernalCtx Kernal context. - * @param cacheName Cache name. + * @param ccfg Cache configuration. * @param binaryEnabled Binary enabled flag. * @param cpyOnGet Copy on get flag. * @param storeVal {@code True} if should store unmarshalled value in cache. * @param depEnabled {@code true} if deployment is enabled for the given cache. */ public CacheObjectBinaryContext(GridKernalContext kernalCtx, - String cacheName, + CacheConfiguration ccfg, boolean cpyOnGet, boolean storeVal, boolean binaryEnabled, boolean depEnabled) { super(kernalCtx, - cacheName, - binaryEnabled ? new CacheDefaultBinaryAffinityKeyMapper() : new GridCacheDefaultAffinityKeyMapper(), + ccfg.getName(), + binaryEnabled ? new CacheDefaultBinaryAffinityKeyMapper(ccfg.getCacheKeyConfiguration()) : + new GridCacheDefaultAffinityKeyMapper(), cpyOnGet, storeVal, depEnabled); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java index ed3ece5d6707a..6751c665727e2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java @@ -388,26 +388,6 @@ public GridBinaryMarshaller marshaller() { return binaryMarsh; } - /** {@inheritDoc} */ - @Override public String affinityField(String keyType) { - if (binaryCtx == null) - return null; - - int typeId = typeId(keyType); - - return affinityField(typeId); - } - - /** - * Get affinity field. - * - * @param typeId Type ID. - * @return Affinity field. - */ - @Nullable private String affinityField(int typeId) { - return binaryCtx.affinityKeyFieldName(typeId); - } - /** {@inheritDoc} */ @Override public BinaryObjectBuilder builder(String clsName) { return new BinaryObjectBuilderImpl(binaryCtx, clsName); @@ -648,54 +628,47 @@ public GridBinaryMarshaller marshaller() { } /** + * Get affinity key field. + * * @param po Binary object. * @return Affinity key. */ - public Object affinityKey(BinaryObject po) { + // TODO: Take in count aff key fields. + public BinaryField affinityKeyField(BinaryObjectEx po) { // Fast path for already cached field. - if (po instanceof BinaryObjectEx) { - int typeId = ((BinaryObjectEx)po).typeId(); - - T1 fieldHolder = affKeyFields.get(typeId); + int typeId = po.typeId(); - if (fieldHolder != null) { - BinaryField field = fieldHolder.get(); + T1 fieldHolder = affKeyFields.get(typeId); - return field != null ? field.value(po) : po; - } - } + if (fieldHolder != null) + return fieldHolder.get(); // Slow path if affinity field is not cached yet. - try { - BinaryType meta = po instanceof BinaryObjectEx ? ((BinaryObjectEx)po).rawType() : po.type(); + BinaryType meta = po.rawType(); - if (meta != null) { - String name = meta.affinityKeyFieldName(); + if (meta != null) { + String name = meta.affinityKeyFieldName(); - if (name != null) { - BinaryField field = meta.field(name); + if (name != null) { + BinaryField field = meta.field(name); - affKeyFields.putIfAbsent(meta.typeId(), new T1<>(field)); + affKeyFields.putIfAbsent(meta.typeId(), new T1<>(field)); - return field.value(po); - } - else - affKeyFields.putIfAbsent(meta.typeId(), new T1(null)); + return field; } - else if (po instanceof BinaryObjectEx) { - int typeId = ((BinaryObjectEx)po).typeId(); - - String name = affinityField(typeId); + else { + affKeyFields.putIfAbsent(meta.typeId(), new T1(null)); - if (name != null) - return po.field(name); + return null; } } - catch (BinaryObjectException e) { - U.error(log, "Failed to get affinity field from binary object: " + po, e); - } - return po; + String name = binaryCtx.affinityKeyFieldName(typeId); + + if (name != null) + return po.field(name); + + return null; } /** {@inheritDoc} */ @@ -736,7 +709,7 @@ public BinaryContext binaryContext() { CacheObjectContext ctx0 = super.contextForCache(cfg); CacheObjectContext res = new CacheObjectBinaryContext(ctx, - cfg.getName(), + cfg, ctx0.copyOnGet(), ctx0.storeValue(), binaryEnabled, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java index ee2d1f29e060f..ae6428ea5a97f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java @@ -211,10 +211,4 @@ public IncompleteCacheObject toKeyCacheObject(CacheObjectContext ctx, ByteBuffer * @return Ignite binary interface. */ public IgniteBinary binary(); - - /** - * @param keyType Key type name. - * @return Affinity filed name or {@code null}. - */ - public String affinityField(String keyType); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java index 01e06a35b2e84..84ada4b48842d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java @@ -430,8 +430,10 @@ public static QueryTypeCandidate typeForQueryEntity(String cacheName, GridCacheC String affField = null; // Need to setup affinity key for distributed joins. - if (!cctx.customAffinityMapper() && qryEntity.findKeyType() != null) - affField = cctx.affinityField(qryEntity.findKeyType()); + if (!cctx.customAffinityMapper() && qryEntity.findKeyType() != null) { + // TODO: How to get affinity field here? + affField = null; + } else if (cctx.config().getAffinityMapper() instanceof DynamicTableAffinityKeyMapper) affField = ((DynamicTableAffinityKeyMapper)cctx.config().getAffinityMapper()).fieldName(); diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index 2218aade1dc37..55ed30a43274f 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -557,7 +557,6 @@ org.apache.ignite.internal.processors.cache.QueryCursorImpl$State org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityProxy org.apache.ignite.internal.processors.cache.binary.BinaryMetadataHolder org.apache.ignite.internal.processors.cache.binary.BinaryMetadataKey -org.apache.ignite.internal.processors.cache.binary.CacheDefaultBinaryAffinityKeyMapper org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$3 org.apache.ignite.internal.processors.cache.binary.MetadataRequestMessage org.apache.ignite.internal.processors.cache.binary.MetadataResponseMessage From ae7bd7c1767fbd7018cd193a235aea8cabb8ee11 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 12:44:14 +0300 Subject: [PATCH 252/311] WIP. --- .../CacheDefaultBinaryAffinityKeyMapper.java | 12 ++++++++++++ .../internal/processors/query/QueryUtils.java | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java index ae43386a491da..9078e49c6ef24 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java @@ -93,6 +93,18 @@ public CacheDefaultBinaryAffinityKeyMapper(@Nullable CacheKeyConfiguration[] cac return super.affinityKey(key); } + /** + * Get affinity field override for type. + * + * @param typeName Type name. + * @return Affinity field override if any. + */ + @Nullable public BinaryField affinityKeyField(String typeName) { + int typeId = proc.typeId(typeName); + + return affinityKeyField(typeId); + } + /** * Get affinity field override for type. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java index 84ada4b48842d..ec8ebb1019640 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java @@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; +import org.apache.ignite.binary.BinaryField; import org.apache.ignite.cache.QueryEntity; import org.apache.ignite.cache.QueryIndex; import org.apache.ignite.cache.QueryIndexType; @@ -39,6 +40,7 @@ import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.binary.BinaryMarshaller; +import org.apache.ignite.internal.processors.cache.CacheDefaultBinaryAffinityKeyMapper; import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheContext; @@ -430,9 +432,18 @@ public static QueryTypeCandidate typeForQueryEntity(String cacheName, GridCacheC String affField = null; // Need to setup affinity key for distributed joins. - if (!cctx.customAffinityMapper() && qryEntity.findKeyType() != null) { - // TODO: How to get affinity field here? - affField = null; + String keyType = qryEntity.getKeyType(); + + if (!cctx.customAffinityMapper() && keyType != null) { + if (coCtx != null) { + CacheDefaultBinaryAffinityKeyMapper mapper = + (CacheDefaultBinaryAffinityKeyMapper)coCtx.defaultAffMapper(); + + BinaryField field = mapper.affinityKeyField(keyType); + + if (field != null) + affField = field.name(); + } } else if (cctx.config().getAffinityMapper() instanceof DynamicTableAffinityKeyMapper) affField = ((DynamicTableAffinityKeyMapper)cctx.config().getAffinityMapper()).fieldName(); From 36265d1dbf91b4a795b324626aa5ce94add6b7c7 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 12:45:49 +0300 Subject: [PATCH 253/311] Property. --- .../configuration/CacheConfiguration.java | 25 +++++++++++++++++++ .../binary/CacheObjectBinaryContext.java | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java index 6e0836e82f281..9b3d48d618d84 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java @@ -47,6 +47,7 @@ import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheEntryProcessor; import org.apache.ignite.cache.CacheInterceptor; +import org.apache.ignite.cache.CacheKeyConfiguration; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.cache.CacheRebalanceMode; import org.apache.ignite.cache.CacheWriteSynchronizationMode; @@ -369,6 +370,9 @@ public class CacheConfiguration extends MutableConfiguration { /** */ private int qryParallelism = DFLT_QUERY_PARALLELISM; + /** Cache key configuration. */ + private CacheKeyConfiguration[] cacheKeyCfg; + /** Empty constructor (all values are initialized to their defaults). */ public CacheConfiguration() { /* No-op. */ @@ -402,6 +406,7 @@ public CacheConfiguration(CompleteConfiguration cfg) { affMapper = cc.getAffinityMapper(); atomicityMode = cc.getAtomicityMode(); backups = cc.getBackups(); + cacheKeyCfg = cc.getKeyConfiguration(); cacheLoaderFactory = cc.getCacheLoaderFactory(); cacheMode = cc.getCacheMode(); cacheWriterFactory = cc.getCacheWriterFactory(); @@ -2289,6 +2294,26 @@ private static void processAnnotation(boolean key, QuerySqlField sqlAnn, QueryTe return this; } + /** + * Gets cache key configuration. + * + * @return Cache key configuration. + */ + public CacheKeyConfiguration[] getKeyConfiguration() { + return cacheKeyCfg; + } + + /** + * Sets cache key configuration. + * + * @param cacheKeyCfg Cache key configuration. + */ + public CacheConfiguration setKeyConfiguration(CacheKeyConfiguration... cacheKeyCfg) { + this.cacheKeyCfg = cacheKeyCfg; + + return this; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(CacheConfiguration.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java index 72f610e28fa3b..7f7e26e6b09f5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java @@ -46,7 +46,7 @@ public CacheObjectBinaryContext(GridKernalContext kernalCtx, boolean depEnabled) { super(kernalCtx, ccfg.getName(), - binaryEnabled ? new CacheDefaultBinaryAffinityKeyMapper(ccfg.getCacheKeyConfiguration()) : + binaryEnabled ? new CacheDefaultBinaryAffinityKeyMapper(ccfg.getKeyConfiguration()) : new GridCacheDefaultAffinityKeyMapper(), cpyOnGet, storeVal, From 5bb8fb008e7365d2b3b489bb5e047a1dc9be9038 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 12:48:54 +0300 Subject: [PATCH 254/311] Removed affinitydynamic table affinity mapper. --- .../query/DynamicTableAffinityKeyMapper.java | 92 ------------------- .../processors/query/GridQueryProcessor.java | 8 +- .../internal/processors/query/QueryUtils.java | 2 - .../processors/query/h2/opt/GridH2Table.java | 5 +- 4 files changed, 4 insertions(+), 103 deletions(-) delete mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/query/DynamicTableAffinityKeyMapper.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/DynamicTableAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/DynamicTableAffinityKeyMapper.java deleted file mode 100644 index e49341ab87f16..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/DynamicTableAffinityKeyMapper.java +++ /dev/null @@ -1,92 +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.query; - -import org.apache.ignite.binary.BinaryObject; -import org.apache.ignite.binary.BinaryType; -import org.apache.ignite.cache.affinity.AffinityKeyMapper; -import org.apache.ignite.internal.binary.BinaryFieldEx; -import org.apache.ignite.internal.binary.BinaryObjectEx; -import org.apache.ignite.internal.util.typedef.F; - -/** - * Trivial mapper to take extract field value from binary object of specific type as affinity key. - */ -@SuppressWarnings("deprecation") -public class DynamicTableAffinityKeyMapper implements AffinityKeyMapper { - /** */ - private static final long serialVersionUID = 0L; - - /** Type name. */ - private final String typeName; - - /** Field name. */ - private final String fieldName; - - /** Type id for faster type checks. */ - private transient volatile BinaryFieldEx field; - - /** - * Constructor. - * - * @param typeName Type name. - * @param fieldName Field name. - */ - DynamicTableAffinityKeyMapper(String typeName, String fieldName) { - this.typeName = typeName; - this.fieldName = fieldName; - } - - /** - * @return Field name. - */ - public String fieldName() { - return fieldName; - } - - /** {@inheritDoc} */ - @Override public Object affinityKey(Object key) { - if (!(key instanceof BinaryObject)) - return key; - - assert key instanceof BinaryObjectEx; - - BinaryObjectEx key0 = (BinaryObjectEx)key; - - if (field == null) { - BinaryType type = key0.type(); - - if (!F.eq(type.typeName(), typeName)) - return key; - - field = (BinaryFieldEx)type.field(fieldName); - } - - if (!F.eq(key0.typeId(), field.typeId())) - return key; - - Object affKey = field.value(key0); - - return affKey != null ? affKey : key; - } - - /** {@inheritDoc} */ - @Override public void reset() { - // No-op. - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index dd07584d1ffb7..d88f062d43254 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -41,6 +41,7 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.binary.Binarylizable; import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheKeyConfiguration; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.cache.QueryEntity; import org.apache.ignite.cache.QueryIndex; @@ -1321,11 +1322,8 @@ else if (QueryUtils.TEMPLATE_REPLICÄTED.equalsIgnoreCase(templateName)) ccfg.setSqlEscapeAll(true); ccfg.setQueryEntities(Collections.singleton(entity)); - if (affinityKey != null) { - assert entity.getFields().containsKey(affinityKey) && entity.getKeyFields().contains(affinityKey); - - ccfg.setAffinityMapper(new DynamicTableAffinityKeyMapper(entity.getKeyType(), affinityKey)); - } + if (affinityKey != null) + ccfg.setKeyConfiguration(new CacheKeyConfiguration(entity.getValueType(), affinityKey)); boolean res; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java index ec8ebb1019640..cb9a1e1e9f6dc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java @@ -445,8 +445,6 @@ public static QueryTypeCandidate typeForQueryEntity(String cacheName, GridCacheC affField = field.name(); } } - else if (cctx.config().getAffinityMapper() instanceof DynamicTableAffinityKeyMapper) - affField = ((DynamicTableAffinityKeyMapper)cctx.config().getAffinityMapper()).fieldName(); if (affField != null) { if (!escape) diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java index 4f3ef01c44ac3..d656cc3194ee4 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java @@ -34,7 +34,6 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.query.QueryTable; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; -import org.apache.ignite.internal.processors.query.DynamicTableAffinityKeyMapper; import org.apache.ignite.internal.processors.query.h2.database.H2RowFactory; import org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex; import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory; @@ -131,9 +130,7 @@ public GridH2Table(CreateTableData createTblData, @Nullable GridH2RowDescriptor this.desc = desc; this.cctx = cctx; - if (desc != null && desc.context() != null && - (!desc.context().customAffinityMapper() || - desc.context().config().getAffinityMapper() instanceof DynamicTableAffinityKeyMapper)) { + if (desc != null && desc.context() != null && !desc.context().customAffinityMapper()) { boolean affinityColExists = true; String affKey = desc.type().affinityKey(); From 38597d1910a2ddaaf65c81e71d7e86609e20a8b2 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 12:50:40 +0300 Subject: [PATCH 255/311] MInors. --- .../ignite/configuration/CacheConfiguration.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java index 9b3d48d618d84..9c9361fd29ca4 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java @@ -371,7 +371,7 @@ public class CacheConfiguration extends MutableConfiguration { private int qryParallelism = DFLT_QUERY_PARALLELISM; /** Cache key configuration. */ - private CacheKeyConfiguration[] cacheKeyCfg; + private CacheKeyConfiguration[] keyCfg; /** Empty constructor (all values are initialized to their defaults). */ public CacheConfiguration() { @@ -406,7 +406,6 @@ public CacheConfiguration(CompleteConfiguration cfg) { affMapper = cc.getAffinityMapper(); atomicityMode = cc.getAtomicityMode(); backups = cc.getBackups(); - cacheKeyCfg = cc.getKeyConfiguration(); cacheLoaderFactory = cc.getCacheLoaderFactory(); cacheMode = cc.getCacheMode(); cacheWriterFactory = cc.getCacheWriterFactory(); @@ -421,23 +420,22 @@ public CacheConfiguration(CompleteConfiguration cfg) { interceptor = cc.getInterceptor(); invalidate = cc.isInvalidate(); isReadThrough = cc.isReadThrough(); - qryParallelism = cc.getQueryParallelism(); isWriteThrough = cc.isWriteThrough(); - storeKeepBinary = cc.isStoreKeepBinary() != null ? cc.isStoreKeepBinary() : DFLT_STORE_KEEP_BINARY; + keyCfg = cc.getKeyConfiguration(); listenerConfigurations = cc.listenerConfigurations; loadPrevVal = cc.isLoadPreviousValue(); longQryWarnTimeout = cc.getLongQueryWarningTimeout(); maxConcurrentAsyncOps = cc.getMaxConcurrentAsyncOperations(); memPlcName = cc.getMemoryPolicyName(); - sqlIdxMaxInlineSize = cc.getSqlIndexMaxInlineSize(); name = cc.getName(); nearCfg = cc.getNearConfiguration(); nodeFilter = cc.getNodeFilter(); onheapCache = cc.isOnheapCacheEnabled(); partLossPlc = cc.getPartitionLossPolicy(); pluginCfgs = cc.getPluginConfigurations(); - qryEntities = cc.getQueryEntities() == Collections.emptyList() ? null : cc.getQueryEntities(); qryDetailMetricsSz = cc.getQueryDetailMetricsSize(); + qryEntities = cc.getQueryEntities() == Collections.emptyList() ? null : cc.getQueryEntities(); + qryParallelism = cc.getQueryParallelism(); readFromBackup = cc.isReadFromBackup(); rebalanceBatchSize = cc.getRebalanceBatchSize(); rebalanceBatchesPrefetchCnt = cc.getRebalanceBatchesPrefetchCount(); @@ -450,7 +448,9 @@ public CacheConfiguration(CompleteConfiguration cfg) { sqlSchema = cc.getSqlSchema(); sqlEscapeAll = cc.isSqlEscapeAll(); sqlFuncCls = cc.getSqlFunctionClasses(); + sqlIdxMaxInlineSize = cc.getSqlIndexMaxInlineSize(); storeFactory = cc.getCacheStoreFactory(); + storeKeepBinary = cc.isStoreKeepBinary() != null ? cc.isStoreKeepBinary() : DFLT_STORE_KEEP_BINARY; storeSesLsnrs = cc.getCacheStoreSessionListenerFactories(); tmLookupClsName = cc.getTransactionManagerLookupClassName(); topValidator = cc.getTopologyValidator(); @@ -2300,7 +2300,7 @@ private static void processAnnotation(boolean key, QuerySqlField sqlAnn, QueryTe * @return Cache key configuration. */ public CacheKeyConfiguration[] getKeyConfiguration() { - return cacheKeyCfg; + return keyCfg; } /** @@ -2309,7 +2309,7 @@ public CacheKeyConfiguration[] getKeyConfiguration() { * @param cacheKeyCfg Cache key configuration. */ public CacheConfiguration setKeyConfiguration(CacheKeyConfiguration... cacheKeyCfg) { - this.cacheKeyCfg = cacheKeyCfg; + this.keyCfg = cacheKeyCfg; return this; } From 6cb550053e95d3529771bb16ccf648f3c0066720 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 12:53:24 +0300 Subject: [PATCH 256/311] WIP. --- .../CacheObjectBinaryProcessorImpl.java | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java index 6751c665727e2..bf456c7a8d536 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java @@ -633,7 +633,6 @@ public GridBinaryMarshaller marshaller() { * @param po Binary object. * @return Affinity key. */ - // TODO: Take in count aff key fields. public BinaryField affinityKeyField(BinaryObjectEx po) { // Fast path for already cached field. int typeId = po.typeId(); @@ -644,31 +643,20 @@ public BinaryField affinityKeyField(BinaryObjectEx po) { return fieldHolder.get(); // Slow path if affinity field is not cached yet. - BinaryType meta = po.rawType(); - - if (meta != null) { - String name = meta.affinityKeyFieldName(); - - if (name != null) { - BinaryField field = meta.field(name); + String name = binaryCtx.affinityKeyFieldName(typeId); - affKeyFields.putIfAbsent(meta.typeId(), new T1<>(field)); + if (name != null) { + BinaryField field = binaryCtx.createField(typeId, name); - return field; - } - else { - affKeyFields.putIfAbsent(meta.typeId(), new T1(null)); + affKeyFields.putIfAbsent(typeId, new T1<>(field)); - return null; - } + return field; } + else { + affKeyFields.putIfAbsent(typeId, new T1(null)); - String name = binaryCtx.affinityKeyFieldName(typeId); - - if (name != null) - return po.field(name); - - return null; + return null; + } } /** {@inheritDoc} */ From 72dfc1d86bdef2e7e620967f1f025198fff16143 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 13:22:43 +0300 Subject: [PATCH 257/311] WIP. --- .../ignite/internal/binary/builder/BinaryObjectBuilderImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java index d6cd5ca4de2af..60bd3190318c4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java @@ -349,6 +349,7 @@ else if (readCache == null) { BinarySchema curSchema = writer.currentSchema(); + // TODO: Put correct affinity key field name here. ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fieldsMeta, ctx.affinityKeyFieldName(typeId), Collections.singleton(curSchema), false, null)); From 386f614170e42bf8089536d6f944098caae9eb68 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 13:33:54 +0300 Subject: [PATCH 258/311] Fixed affinity key field name resolution for DML. --- .../builder/BinaryObjectBuilderImpl.java | 22 +++++++++++++-- .../CacheDefaultBinaryAffinityKeyMapper.java | 2 +- .../processors/cache/GridCacheContext.java | 28 +++++++++++++++++++ .../query/h2/DmlStatementsProcessor.java | 6 ++-- .../query/h2/dml/UpdatePlanBuilder.java | 11 +++++++- 5 files changed, 61 insertions(+), 8 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java index 60bd3190318c4..26684dc44324b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java @@ -86,6 +86,9 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder { /** Context of BinaryObject reading process. Or {@code null} if object is not created from BinaryObject. */ private final BinaryBuilderReader reader; + /** Affinity key field name. */ + private String affFieldName; + /** * @param clsName Class name. * @param ctx Binary context. @@ -349,9 +352,13 @@ else if (readCache == null) { BinarySchema curSchema = writer.currentSchema(); - // TODO: Put correct affinity key field name here. - ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fieldsMeta, - ctx.affinityKeyFieldName(typeId), Collections.singleton(curSchema), false, null)); + String affFieldName0 = affFieldName; + + if (affFieldName0 == null) + ctx.affinityKeyFieldName(typeId); + + ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fieldsMeta, affFieldName0, + Collections.singleton(curSchema), false, null)); schemaReg.addSchema(curSchema.schemaId(), curSchema); } @@ -619,4 +626,13 @@ int start() { public int typeId() { return typeId; } + + /** + * Set known affinity key field name. + * + * @param affFieldName Affinity key field name. + */ + public void affinityFieldName(String affFieldName) { + this.affFieldName = affFieldName; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java index 9078e49c6ef24..b7264332a4925 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java @@ -111,7 +111,7 @@ public CacheDefaultBinaryAffinityKeyMapper(@Nullable CacheKeyConfiguration[] cac * @param typeId Type ID. * @return Affinity field override if any. */ - @Nullable private BinaryField affinityKeyField(int typeId) { + @Nullable public BinaryField affinityKeyField(int typeId) { Map typeIdAffFields0 = typeIdAffFields; if (typeIdAffFields0 == null) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java index 839ddbd9cdc52..b007574db1fbc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java @@ -39,6 +39,8 @@ import javax.cache.processor.EntryProcessorResult; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.binary.BinaryField; +import org.apache.ignite.binary.BinaryObjectBuilder; import org.apache.ignite.cache.CacheInterceptor; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.cache.affinity.AffinityKeyMapper; @@ -51,6 +53,7 @@ import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.IgnitionEx; import org.apache.ignite.internal.binary.BinaryMarshaller; +import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl; import org.apache.ignite.internal.managers.communication.GridIoManager; import org.apache.ignite.internal.managers.deployment.GridDeploymentManager; import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager; @@ -2063,6 +2066,31 @@ else if (type == EVT_CACHE_REBALANCE_STOPPED) { return true; } + /** + * Prepare affinity field for builder (if possible). + * + * @param buider Builder. + */ + public void prepareAffinityField(BinaryObjectBuilder buider) { + assert binaryMarshaller(); + assert buider instanceof BinaryObjectBuilderImpl; + + BinaryObjectBuilderImpl builder0 = (BinaryObjectBuilderImpl)buider; + + if (!customAffinityMapper()) { + CacheDefaultBinaryAffinityKeyMapper mapper = + (CacheDefaultBinaryAffinityKeyMapper)cacheObjCtx.defaultAffMapper(); + + BinaryField field = mapper.affinityKeyField(builder0.typeId()); + + if (field != null) { + String fieldName = field.name(); + + builder0.affinityFieldName(fieldName); + } + } + } + /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { U.writeString(out, igniteInstanceName()); diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java index 98d123f4f9dec..40ff38b8c671a 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java @@ -633,7 +633,7 @@ private UpdateResult doUpdate(UpdatePlan plan, Iterable> cursor, int pag if (bin && hasProps) { assert newVal instanceof BinaryObjectBuilder; - newVal = ((BinaryObjectBuilder) newVal).build(); + newVal = ((BinaryObjectBuilder)newVal).build(); } Object srcVal = e.get(1); @@ -1005,10 +1005,10 @@ private static PageProcessingResult processPage(GridCacheContext cctx, if (cctx.binaryMarshaller()) { if (key instanceof BinaryObjectBuilder) - key = ((BinaryObjectBuilder) key).build(); + key = ((BinaryObjectBuilder)key).build(); if (val instanceof BinaryObjectBuilder) - val = ((BinaryObjectBuilder) val).build(); + val = ((BinaryObjectBuilder)val).build(); } return new IgniteBiTuple<>(key, val); diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java index 22c3e3357cd8d..44a38647002d6 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java @@ -24,6 +24,7 @@ import javax.cache.CacheException; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.binary.BinaryObjectBuilder; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode; import org.apache.ignite.internal.processors.query.GridQueryProperty; @@ -343,7 +344,11 @@ else if (isSqlType) BinaryObject bin = cctx.grid().binary().toBinary(obj); - return cctx.grid().binary().builder(bin); + BinaryObjectBuilder builder = cctx.grid().binary().builder(bin); + + cctx.prepareAffinityField(builder); + + return builder; } }; } @@ -352,6 +357,10 @@ else if (isSqlType) return new KeyValueSupplier() { /** {@inheritDoc} */ @Override public Object apply(List arg) throws IgniteCheckedException { + BinaryObjectBuilder builder = cctx.grid().binary().builder(typeName); + + cctx.prepareAffinityField(builder); + return cctx.grid().binary().builder(typeName); } }; From a491d1d607560ffa25f4e4021ba731adbccc482a Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 14:06:05 +0300 Subject: [PATCH 259/311] WIP. --- .../internal/binary/builder/BinaryObjectBuilderImpl.java | 2 +- .../cacheobject/IgniteCacheObjectProcessorImpl.java | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java index 26684dc44324b..fa9f1c3e54dea 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java @@ -355,7 +355,7 @@ else if (readCache == null) { String affFieldName0 = affFieldName; if (affFieldName0 == null) - ctx.affinityKeyFieldName(typeId); + affFieldName0 = ctx.affinityKeyFieldName(typeId); ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fieldsMeta, affFieldName0, Collections.singleton(curSchema), false, null)); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java index de9256c9b1419..67e14dc084d81 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java @@ -81,11 +81,6 @@ public IgniteCacheObjectProcessorImpl(GridKernalContext ctx) { super(ctx); } - /** {@inheritDoc} */ - @Override public String affinityField(String keyType) { - return null; - } - /** {@inheritDoc} */ @Override public IgniteBinary binary() { return noOpBinary; From 5665fe2c0e7583f0cc80f3d1a63af7d9011f5e27 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 14:10:12 +0300 Subject: [PATCH 260/311] Appears to work somehow. --- .../internal/processors/query/h2/dml/UpdatePlanBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java index 44a38647002d6..b304109993ca9 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java @@ -361,7 +361,7 @@ else if (isSqlType) cctx.prepareAffinityField(builder); - return cctx.grid().binary().builder(typeName); + return builder; } }; } From ec175880c753f8f70fb66e7c9428c6bcad364ad6 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 14:16:29 +0300 Subject: [PATCH 261/311] Fixes. --- .../ignite/internal/processors/query/GridQueryProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index d88f062d43254..01f745d9de4d6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -1323,7 +1323,7 @@ else if (QueryUtils.TEMPLATE_REPLICÄTED.equalsIgnoreCase(templateName)) ccfg.setQueryEntities(Collections.singleton(entity)); if (affinityKey != null) - ccfg.setKeyConfiguration(new CacheKeyConfiguration(entity.getValueType(), affinityKey)); + ccfg.setKeyConfiguration(new CacheKeyConfiguration(entity.getKeyType(), affinityKey)); boolean res; From 4b89ae0197ca4acc4d1ee730d296d0e1693674f7 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 9 Jun 2017 14:23:48 +0300 Subject: [PATCH 262/311] IGNITE-5267 - Cleaning public API --- .../ignite/internal/pagemem/snapshot/SnapshotOperation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index eb07b0d1abf81..2ec4db094a017 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -54,7 +54,7 @@ public class SnapshotOperation implements Serializable { * @param snapshotId Snapshot id. * @param cacheGrpIds Cache group ids. * @param cacheNames Cache names. - * @param msg + * @param msg Extra user message. * @param extraParam Additional parameter. */ public SnapshotOperation( @@ -85,7 +85,7 @@ public SnapshotOperationType type() { * * @return Snapshot ID. */ - public long id() { + public long snapshotId() { return snapshotId; } From 4d50bc5d9020135e06a7c9d3b9dde6337eec4b9c Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 14:26:57 +0300 Subject: [PATCH 263/311] Fixing tests. --- .../internal/processors/query/IgniteSqlRoutingTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlRoutingTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlRoutingTest.java index fddd3f4b78c21..ffd6318612b13 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlRoutingTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlRoutingTest.java @@ -69,6 +69,7 @@ public class IgniteSqlRoutingTest extends GridCommonAbstractTest { private static String FINAL_QRY_PARAM = "Abracadabra"; /** {@inheritDoc} */ + @SuppressWarnings("ConstantConditions") @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration c = super.getConfiguration(gridName); @@ -88,15 +89,13 @@ public class IgniteSqlRoutingTest extends GridCommonAbstractTest { ccfgs.add(ccfg); ccfgs.add(buildCacheConfiguration(CACHE_PERSON)); - ccfgs.add(buildCacheConfiguration(CACHE_CALL)); + ccfgs.add(buildCacheConfiguration(CACHE_CALL).setKeyConfiguration(new CacheKeyConfiguration(CallKey.class))); c.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()])); if (gridName.equals(NODE_CLIENT)) c.setClientMode(true); - c.setCacheKeyConfiguration(new CacheKeyConfiguration(CallKey.class)); - return c; } From 9686fbaf4f082bac0a49d54fde86f2a1137e26a0 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 14:37:07 +0300 Subject: [PATCH 264/311] Fixing tests. --- .../cache/CacheDefaultBinaryAffinityKeyMapper.java | 10 ++++++---- .../cache/binary/CacheObjectBinaryProcessorImpl.java | 6 ++---- .../processors/query/IgniteSqlRoutingTest.java | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java index b7264332a4925..43506873fb427 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java @@ -77,9 +77,6 @@ public CacheDefaultBinaryAffinityKeyMapper(@Nullable CacheKeyConfiguration[] cac BinaryField affField = affinityKeyField(key0.typeId()); - if (affField == null) - affField = proc.affinityKeyField(key0); - if (affField != null) { Object res = affField.value(key0); @@ -131,7 +128,12 @@ public CacheDefaultBinaryAffinityKeyMapper(@Nullable CacheKeyConfiguration[] cac typeIdAffFields = typeIdAffFields0; } - return typeIdAffFields0.get(typeId); + BinaryField res = typeIdAffFields0.get(typeId); + + if (res == null) + res = proc.affinityKeyField(typeId); + + return res; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java index bf456c7a8d536..5b35a66175f61 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java @@ -630,13 +630,11 @@ public GridBinaryMarshaller marshaller() { /** * Get affinity key field. * - * @param po Binary object. + * @param typeId Binary object type ID. * @return Affinity key. */ - public BinaryField affinityKeyField(BinaryObjectEx po) { + public BinaryField affinityKeyField(int typeId) { // Fast path for already cached field. - int typeId = po.typeId(); - T1 fieldHolder = affKeyFields.get(typeId); if (fieldHolder != null) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlRoutingTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlRoutingTest.java index ffd6318612b13..fddd3f4b78c21 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlRoutingTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlRoutingTest.java @@ -69,7 +69,6 @@ public class IgniteSqlRoutingTest extends GridCommonAbstractTest { private static String FINAL_QRY_PARAM = "Abracadabra"; /** {@inheritDoc} */ - @SuppressWarnings("ConstantConditions") @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration c = super.getConfiguration(gridName); @@ -89,13 +88,15 @@ public class IgniteSqlRoutingTest extends GridCommonAbstractTest { ccfgs.add(ccfg); ccfgs.add(buildCacheConfiguration(CACHE_PERSON)); - ccfgs.add(buildCacheConfiguration(CACHE_CALL).setKeyConfiguration(new CacheKeyConfiguration(CallKey.class))); + ccfgs.add(buildCacheConfiguration(CACHE_CALL)); c.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()])); if (gridName.equals(NODE_CLIENT)) c.setClientMode(true); + c.setCacheKeyConfiguration(new CacheKeyConfiguration(CallKey.class)); + return c; } From 87551427c5796a5d48f60a412a770b810269b797 Mon Sep 17 00:00:00 2001 From: Konstantin Dudkov Date: Fri, 9 Jun 2017 16:21:31 +0300 Subject: [PATCH 265/311] IGNITE-5306 - Persist SQL context along with cache configuration --- .../processors/cache/GridCacheProcessor.java | 138 ++++++++---------- .../processors/cache/StoredCacheData.java | 17 +++ .../IgnitePersistentStoreSchemaLoadTest.java | 2 +- 3 files changed, 82 insertions(+), 75 deletions(-) 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 e9680749a4a42..8dc6026e02ca1 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 @@ -270,7 +270,7 @@ else if (cfg.getCacheMode() == REPLICATED) { if (cfg.getCacheMode() == REPLICATED) cfg.setBackups(Integer.MAX_VALUE); - if( cfg.getQueryParallelism() > 1 && cfg.getCacheMode() != PARTITIONED) + if (cfg.getQueryParallelism() > 1 && cfg.getCacheMode() != PARTITIONED) throw new IgniteCheckedException("Segmented indices are supported for PARTITIONED mode only."); if (cfg.getAffinityMapper() == null) @@ -502,12 +502,12 @@ private void validate(IgniteConfiguration c, else if (cc.getRebalanceMode() == SYNC) { if (delay < 0) { U.warn(log, "Ignoring SYNC rebalance mode with manual rebalance start (node will not wait for " + - "rebalancing to be finished): " + U.maskName(cc.getName()), + "rebalancing to be finished): " + U.maskName(cc.getName()), "Node will not wait for rebalance in SYNC mode: " + U.maskName(cc.getName())); } else { U.warn(log, "Using SYNC rebalance mode with rebalance delay (node will wait until rebalancing is " + - "initiated for " + delay + "ms) for cache: " + U.maskName(cc.getName()), + "initiated for " + delay + "ms) for cache: " + U.maskName(cc.getName()), "Node will wait until rebalancing is initiated for " + delay + "ms for cache: " + U.maskName(cc.getName())); } } @@ -646,7 +646,7 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near if (!F.isEmpty(ctx.config().getCacheConfiguration())) { if (depMode != CONTINUOUS && depMode != SHARED) U.warn(log, "Deployment mode for cache is not CONTINUOUS or SHARED " + - "(it is recommended that you change deployment mode and restart): " + depMode, + "(it is recommended that you change deployment mode and restart): " + depMode, "Deployment mode for cache is not CONTINUOUS or SHARED."); } @@ -690,12 +690,11 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near /** * @param cacheData Cache data. - * @param sql SQL flag - {@code true} if cache was created with {@code CREATE TABLE}. * @param caches Caches map. * @param templates Templates map. * @throws IgniteCheckedException If failed. */ - private void addCacheOnJoin(StoredCacheData cacheData, boolean sql, + private void addCacheOnJoin(StoredCacheData cacheData, Map caches, Map templates) throws IgniteCheckedException { CacheConfiguration cfg = cacheData.config(); @@ -734,7 +733,7 @@ else if (internalCaches.contains(cfg.getName())) else stopSeq.addFirst(cfg.getName()); - caches.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cacheData, cacheType, sql, 0)); + caches.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cacheData, cacheType, cacheData.sql(), 0)); } else templates.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cacheData, CacheType.USER, false, 0)); @@ -757,8 +756,10 @@ private void addCacheOnJoinFromConfig( CacheConfiguration cfg = new CacheConfiguration(cfgs[i]); cfgs[i] = cfg; // Replace original configuration value. + StoredCacheData cacheData = new StoredCacheData(cfg); + cacheData.sql(false); - addCacheOnJoin(new StoredCacheData(cfg), false, caches, templates); + addCacheOnJoin(cacheData, caches, templates); } } @@ -774,21 +775,20 @@ private void addCacheOnJoinFromPersistentStore( assert !ctx.config().isDaemon(); if (sharedCtx.pageStore() != null && sharedCtx.database().persistenceEnabled()) { - Map ccfgs = sharedCtx.pageStore().readCacheConfigurations(); + Map cacheDataMap = sharedCtx.pageStore().readCacheConfigurations(); for (String cache : caches.keySet()) - ccfgs.remove(cache); + cacheDataMap.remove(cache); for (String cache : internalCaches) - ccfgs.remove(cache); + cacheDataMap.remove(cache); - if (!F.isEmpty(ccfgs)) { + if (!F.isEmpty(cacheDataMap)) { if (log.isInfoEnabled()) - log.info("Register persistent caches: " + ccfgs.keySet()); + log.info("Register persistent caches: " + cacheDataMap.keySet()); - // TODO IGNITE-5306 - set correct SQL flag below. - for (StoredCacheData ccfg : ccfgs.values()) - addCacheOnJoin(ccfg, false, caches, templates); + for (StoredCacheData cacheData : cacheDataMap.values()) + addCacheOnJoin(cacheData, caches, templates); } } } @@ -981,7 +981,7 @@ private void checkConsistency() throws IgniteCheckedException { /** * @param cancel Cancel. */ - public void stopCaches(boolean cancel){ + public void stopCaches(boolean cancel) { for (String cacheName : stopSeq) { GridCacheAdapter cache = stoppedCaches.remove(cacheName); @@ -1040,7 +1040,7 @@ public void blockGateways() { /** * @param cancel Cancel. */ - public void onKernalStopCaches(boolean cancel){ + public void onKernalStopCaches(boolean cancel) { IgniteCheckedException affErr = new IgniteCheckedException("Failed to wait for topology update, node is stopping."); @@ -1235,14 +1235,13 @@ private void startCache(GridCacheAdapter cache, QuerySchema schema) throws cacheCtx.onStarted(); - if (log.isInfoEnabled()) { log.info("Started cache [name=" + cfg.getName() + (cfg.getGroupName() != null ? ", group=" + cfg.getGroupName() : "") + ", memoryPolicyName=" + cfg.getMemoryPolicyName() + ", mode=" + cfg.getCacheMode() + ", atomicity=" + cfg.getAtomicityMode() + ']'); -} + } } /** @@ -1772,26 +1771,6 @@ public CacheMode cacheMode(String cacheName) { return desc != null ? desc.cacheConfiguration().getCacheMode() : null; } - /** - * @param cacheDesc Cache start request. - * @param nearCfg Near cache configuration. - * @param exchTopVer Current exchange version. - * @throws IgniteCheckedException If failed. - */ - void prepareCacheStart(DynamicCacheDescriptor cacheDesc, - @Nullable NearCacheConfiguration nearCfg, - AffinityTopologyVersion exchTopVer) - throws IgniteCheckedException { - prepareCacheStart( - cacheDesc.groupDescriptor(), - cacheDesc.cacheConfiguration(), - nearCfg, - cacheDesc, - exchTopVer, - cacheDesc.schema() - ); - } - /** * @param exchTopVer Current exchange version. * @throws IgniteCheckedException If failed. @@ -1804,12 +1783,9 @@ public void startCachesOnLocalJoin(AffinityTopologyVersion exchTopVer) throws Ig DynamicCacheDescriptor desc = t.get1(); prepareCacheStart( - desc.groupDescriptor(), - desc.cacheConfiguration(), - t.get2(), desc, - exchTopVer, - desc.schema() + t.get2(), + exchTopVer ); } } @@ -1833,12 +1809,9 @@ public Collection startReceivedCaches(UUID nodeId, Affin if (CU.affinityNode(ctx.discovery().localNode(), filter)) { prepareCacheStart( - desc.groupDescriptor(), - desc.cacheConfiguration(), - null, desc, - exchTopVer, - desc.schema() + null, + exchTopVer ); } } @@ -1848,22 +1821,17 @@ public Collection startReceivedCaches(UUID nodeId, Affin } /** - * @param grpDesc Cache group descriptor. - * @param startCfg Start configuration. - * @param reqNearCfg Near configuration if specified for client cache start request. * @param desc Cache descriptor. + * @param reqNearCfg Near configuration if specified for client cache start request. * @param exchTopVer Current exchange version. - * @param schema Query schema. * @throws IgniteCheckedException If failed. */ - private void prepareCacheStart( - CacheGroupDescriptor grpDesc, - CacheConfiguration startCfg, - @Nullable NearCacheConfiguration reqNearCfg, + public void prepareCacheStart( DynamicCacheDescriptor desc, - AffinityTopologyVersion exchTopVer, - @Nullable QuerySchema schema + @Nullable NearCacheConfiguration reqNearCfg, + AffinityTopologyVersion exchTopVer ) throws IgniteCheckedException { + CacheConfiguration startCfg = desc.cacheConfiguration(); assert !caches.containsKey(startCfg.getName()) : startCfg.getName(); CacheConfiguration ccfg = new CacheConfiguration(startCfg); @@ -1881,7 +1849,7 @@ private void prepareCacheStart( ccfg.setNearConfiguration(null); } - else if (CU.affinityNode(ctx.discovery().localNode(), grpDesc.config().getNodeFilter())) + else if (CU.affinityNode(ctx.discovery().localNode(), desc.groupDescriptor().config().getNodeFilter())) affNode = true; else { affNode = false; @@ -1889,8 +1857,10 @@ else if (CU.affinityNode(ctx.discovery().localNode(), grpDesc.config().getNodeFi ccfg.setNearConfiguration(reqNearCfg); } - if (sharedCtx.pageStore() != null && affNode) - sharedCtx.pageStore().initializeForCache(grpDesc, new StoredCacheData(startCfg)); + StoredCacheData cacheData = toStoredData(desc); + + if (sharedCtx.pageStore() != null && affNode) + sharedCtx.pageStore().initializeForCache(desc.groupDescriptor(), cacheData); String grpName = startCfg.getGroupName(); @@ -1906,7 +1876,7 @@ else if (CU.affinityNode(ctx.discovery().localNode(), grpDesc.config().getNodeFi } if (grp == null) { - grp = startCacheGroup(grpDesc, + grp = startCacheGroup(desc.groupDescriptor(), desc.cacheType(), affNode, cacheObjCtx, @@ -1914,7 +1884,7 @@ else if (CU.affinityNode(ctx.discovery().localNode(), grpDesc.config().getNodeFi } } else { - grp = startCacheGroup(grpDesc, + grp = startCacheGroup(desc.groupDescriptor(), desc.cacheType(), affNode, cacheObjCtx, @@ -1938,7 +1908,7 @@ else if (CU.affinityNode(ctx.discovery().localNode(), grpDesc.config().getNodeFi caches.put(cacheCtx.name(), cache); - startCache(cache, schema != null ? schema : new QuerySchema()); + startCache(cache, desc.schema() != null ? desc.schema() : new QuerySchema()); grp.onCacheStarted(cacheCtx); @@ -2079,7 +2049,7 @@ void forceCloseCache( final ExchangeActions.ActionData act, Throwable err ) { - ExchangeActions actions = new ExchangeActions(){ + ExchangeActions actions = new ExchangeActions() { @Override List closeRequests(UUID nodeId) { return Collections.singletonList(act); } @@ -2168,7 +2138,7 @@ public void onExchangeDone( GridCacheContext stopCtx = prepareCacheStop(req.request(), forceClose); if (stopCtx != null && !stopCtx.group().hasCaches()) { - assert !stopCtx.group().affinityNode() : stopCtx.name(); + assert !stopCtx.group().affinityNode() : stopCtx.name(); stopCacheGroup(stopCtx.groupId()); } @@ -2631,12 +2601,13 @@ private IgniteInternalFuture dynamicStartCaches( /** * @param cacheName Cache name to destroy. - * @param sql If the cache needs to be destroyed only if it was created as the result - * of SQL {@code CREATE TABLE} command. + * @param sql If the cache needs to be destroyed only if it was created as the result of SQL {@code CREATE TABLE} + * command. * @param checkThreadTx If {@code true} checks that current thread does not have active transactions. * @return Future that will be completed when cache is destroyed. */ - public IgniteInternalFuture dynamicDestroyCache(String cacheName, boolean sql, boolean checkThreadTx, boolean restart) { + public IgniteInternalFuture dynamicDestroyCache(String cacheName, boolean sql, boolean checkThreadTx, + boolean restart) { assert cacheName != null; if (checkThreadTx) @@ -2770,7 +2741,7 @@ public Collection startAllCachesRequests() throws Ign /** * */ - public Collection stopAllCachesRequests(){ + public Collection stopAllCachesRequests() { List reqs = new ArrayList<>(); for (String cacheName : cacheNames()) { @@ -2794,7 +2765,7 @@ private DynamicCacheChangeRequest createRequest( cloneCheckSerializable(cfg); - if (needInit){ + if (needInit) { CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(cfg); initialize(cfg, cacheObjCtx); @@ -2820,6 +2791,25 @@ else if (internalCaches.contains(cacheName)) return req; } + /** + * Form a {@link StoredCacheData} with all data to correctly restore cache params when its configuration + * is read from page store. Essentially, this method takes from {@link DynamicCacheDescriptor} all that's + * needed to start cache correctly, leaving out everything else. + * + * @param desc Cache descriptor to process. + * @return {@link StoredCacheData} based on {@code desc}. + */ + private static StoredCacheData toStoredData(DynamicCacheDescriptor desc) { + A.notNull(desc, "desc"); + + StoredCacheData res = new StoredCacheData(desc.cacheConfiguration()); + + res.queryEntities(desc.schema() == null ? Collections.emptyList() : desc.schema().entities()); + res.sql(desc.sql()); + + return res; + } + /** * @param reqs Requests. * @param failIfExists Fail if exists flag. @@ -3213,7 +3203,7 @@ public IgniteCacheProxy publicJCache(String cacheName) throws Ignit /** * @param cacheName Cache name. * @param failIfNotStarted If {@code true} throws {@link IllegalArgumentException} if cache is not started, - * otherwise returns {@code null} in this case. + * otherwise returns {@code null} in this case. * @param checkThreadTx If {@code true} checks that current thread does not have active transactions. * @return Cache instance for given name. * @throws IgniteCheckedException If failed. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java index 2b3dcdc6fef67..39c3cd156fc41 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java @@ -41,6 +41,9 @@ public class StoredCacheData implements Serializable { /** Query entities. */ private Collection qryEntities; + /** SQL flag - {@code true} if cache was created with {@code CREATE TABLE}. */ + private boolean sql; + /** * Constructor. * @@ -73,4 +76,18 @@ public Collection queryEntities() { public void queryEntities(Collection qryEntities) { this.qryEntities = qryEntities; } + + /** + * @return SQL flag - {@code true} if cache was created with {@code CREATE TABLE}. + */ + public boolean sql() { + return sql; + } + + /** + * @param sql SQL flag - {@code true} if cache was created with {@code CREATE TABLE}. + */ + public void sql(boolean sql) { + this.sql = sql; + } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java index bdf64bbfcf526..7719f1a1b2dce 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java @@ -64,7 +64,7 @@ public class IgnitePersistentStoreSchemaLoadTest extends GridCommonAbstractTest private static final String TBL_NAME = Person.class.getSimpleName(); /** Schema name. */ - private static final String SCHEMA_NAME = TBL_NAME; + private static final String SCHEMA_NAME = "PUBLIC"; /** Cache name. */ private static final String CACHE_NAME = TBL_NAME; From ffe1a010c9452954aabd091b25e3dc47128acdcd Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 9 Jun 2017 17:20:07 +0300 Subject: [PATCH 266/311] Merge from ignite-5267 --- .../processors/cache/GridCacheAbstractFullApiSelfTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java index 551d56555264f..bf27e26b91e16 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java @@ -925,7 +925,7 @@ public void testGetAllWithNulls() throws Exception { final Set c = new HashSet<>(); c.add("key1"); -// c.add(null); + c.add(null); GridTestUtils.assertThrows(log, new Callable() { @Override public Void call() throws Exception { From f9ed6120baa6d0db826f1e58f4fd7b791711734a Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Fri, 9 Jun 2017 18:15:28 +0300 Subject: [PATCH 267/311] IGNITE-5267 - Fixed NPE in checkpointer --- .../cache/database/GridCacheDatabaseSharedManager.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 555fa6026ee20..10b664d10b9ea 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -1928,8 +1928,6 @@ private void doCheckpoint() { snapshotMgr.onCheckPointBegin(); - int pages = chp.cpPages.size(); - boolean interrupted = true; try { @@ -2016,7 +2014,7 @@ private void doCheckpoint() { "walSegmentsCleared=%d, markDuration=%dms, pagesWrite=%dms, fsync=%dms, " + "total=%dms]", chp.cpEntry.checkpointId(), - pages, + chp.pagesSize, chp.cpEntry.checkpointMark(), chp.walFilesDeleted, tracker.markDuration(), @@ -2031,7 +2029,7 @@ private void doCheckpoint() { tracker.pagesWriteDuration(), tracker.fsyncDuration(), tracker.totalDuration(), - pages, + chp.pagesSize, tracker.dataPagesWritten(), tracker.cowPagesWritten()); } @@ -2042,7 +2040,7 @@ private void doCheckpoint() { tracker.pagesWriteDuration(), tracker.fsyncDuration(), tracker.totalDuration(), - pages, + chp.pagesSize, tracker.dataPagesWritten(), tracker.cowPagesWritten()); } From da1e917858a117383d0974fca0e16292497c3c45 Mon Sep 17 00:00:00 2001 From: devozerov Date: Fri, 9 Jun 2017 20:14:21 +0300 Subject: [PATCH 268/311] Fixed NPE in BinaryContext. --- .../java/org/apache/ignite/internal/binary/BinaryContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java index 76c5a5059cd5a..26cf2ab086693 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java @@ -1247,7 +1247,7 @@ public String affinityKeyFieldName(int typeId) { String res = affKeyFieldNames.get(typeId); if (res == null) { - BinaryMetadata meta = metaHnd.metadata0(typeId); + BinaryType meta = metaHnd.metadata(typeId); if (meta != null) res = meta.affinityKeyFieldName(); From bdbba0ee9a5437a3f66d05c8175bfcb2f309b3bd Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Sun, 11 Jun 2017 21:53:56 +0300 Subject: [PATCH 269/311] IGNITE-5392 - Joining node must accept cluster active status --- .../apache/ignite/internal/GridComponent.java | 4 +- .../ignite/internal/GridPluginComponent.java | 4 +- .../apache/ignite/internal/IgniteKernal.java | 13 +- .../internal/managers/GridManagerAdapter.java | 2 +- .../checkpoint/GridCheckpointManager.java | 2 +- .../collision/GridCollisionManager.java | 2 +- .../managers/communication/GridIoManager.java | 2 +- .../deployment/GridDeploymentManager.java | 2 +- .../discovery/GridDiscoveryManager.java | 43 +- .../eventstorage/GridEventStorageManager.java | 2 +- .../failover/GridFailoverManager.java | 2 +- .../indexing/GridIndexingManager.java | 2 +- .../loadbalancer/GridLoadBalancerManager.java | 2 +- .../pagemem/store/IgnitePageStoreManager.java | 2 +- .../processors/GridProcessorAdapter.java | 4 +- .../affinity/GridAffinityProcessor.java | 2 +- .../cache/CacheAffinitySharedManager.java | 38 +- .../CacheClientReconnectDiscoveryData.java | 2 +- .../internal/processors/cache/CacheData.java | 7 + .../cache/CacheJoinNodeDiscoveryData.java | 20 +- .../cache/CacheNodeCommonDiscoveryData.java | 10 +- .../processors/cache/ClusterCachesInfo.java | 56 +- .../cache/DynamicCacheChangeRequest.java | 7 +- .../processors/cache/GridCacheProcessor.java | 259 ++---- .../CacheObjectBinaryProcessorImpl.java | 6 +- .../IgniteCacheDatabaseSharedManager.java | 16 +- .../closure/GridClosureProcessor.java | 2 +- .../processors/cluster/ClusterProcessor.java | 2 +- .../cluster/GridClusterStateProcessor.java | 362 +++++++-- .../continuous/GridContinuousProcessor.java | 2 +- .../datastreamer/DataStreamProcessor.java | 2 +- .../DataStructuresProcessor.java | 20 +- .../processors/igfs/IgfsProcessor.java | 4 +- .../processors/job/GridJobProcessor.java | 2 +- .../jobmetrics/GridJobMetricsProcessor.java | 2 +- .../GridMarshallerMappingProcessor.java | 2 +- .../processors/odbc/SqlListenerProcessor.java | 2 +- .../platform/PlatformProcessorImpl.java | 2 +- .../plugin/IgnitePluginProcessor.java | 2 +- .../processors/port/GridPortProcessor.java | 2 +- .../processors/query/GridQueryProcessor.java | 4 +- .../resource/GridResourceProcessor.java | 2 +- .../processors/rest/GridRestProcessor.java | 4 +- .../service/GridServiceProcessor.java | 12 +- .../session/GridTaskSessionProcessor.java | 2 +- .../processors/task/GridTaskProcessor.java | 4 +- .../timeout/GridTimeoutProcessor.java | 2 +- .../ignite/spi/discovery/tcp/ServerImpl.java | 26 - ...idManagerLocalMessageListenerSelfTest.java | 8 +- .../managers/GridNoopManagerSelfTest.java | 2 +- ...CommunicationSpiMultithreadedSelfTest.java | 4 +- .../discovery/tcp/TestReconnectProcessor.java | 2 +- .../junits/GridAbstractTest.java | 18 +- .../junits/GridTestKernalContext.java | 2 +- .../processors/hadoop/HadoopProcessor.java | 6 +- .../GridCacheDatabaseSharedManager.java | 109 ++- .../database/file/FilePageStoreManager.java | 66 +- .../pagemem/NoOpPageStoreManager.java | 1 + .../AbstractNodeJoinTemplate.java | 743 ++++++++++++++++++ .../IgniteChangeGlobalStateAbstractTest.java | 4 +- .../IgniteStandByClusterTest.java | 213 +++++ .../join/JoinActiveNodeToActiveCluster.java | 431 ++++++++++ .../join/JoinActiveNodeToInActiveCluster.java | 227 ++++++ .../join/JoinInActiveNodeToActiveCluster.java | 356 +++++++++ .../JoinInActiveNodeToInActiveCluster.java | 226 ++++++ ...iveNodeToActiveClusterWithPersistence.java | 97 +++ ...eNodeToInActiveClusterWithPersistence.java | 31 + ...iveNodeToActiveClusterWithPersistence.java | 85 ++ ...eNodeToInActiveClusterWithPersistence.java | 31 + ...iteAbstractStandByClientReconnectTest.java | 336 ++++++++ .../IgniteStandByClientReconnectTest.java | 283 +++++++ ...tandByClientReconnectToNewClusterTest.java | 289 +++++++ .../schedule/IgniteScheduleProcessor.java | 2 +- 73 files changed, 4031 insertions(+), 516 deletions(-) create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/AbstractNodeJoinTemplate.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteStandByClusterTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToActiveCluster.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToInActiveCluster.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToActiveCluster.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToInActiveCluster.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectTest.java create mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridComponent.java b/modules/core/src/main/java/org/apache/ignite/internal/GridComponent.java index 98edf0fb269fa..0505929ac8f76 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridComponent.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridComponent.java @@ -69,7 +69,7 @@ enum DiscoveryDataExchangeType { * * @throws IgniteCheckedException Throws in case of any errors. */ - public void start(boolean activeOnStart) throws IgniteCheckedException; + public void start() throws IgniteCheckedException; /** * Stops grid component. @@ -86,7 +86,7 @@ enum DiscoveryDataExchangeType { * * @throws IgniteCheckedException Thrown in case of any errors. */ - public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException; + public void onKernalStart() throws IgniteCheckedException; /** * Callback to notify that kernal is about to stop. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridPluginComponent.java b/modules/core/src/main/java/org/apache/ignite/internal/GridPluginComponent.java index 1e613b7fded36..cc1ae714d8cf2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridPluginComponent.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridPluginComponent.java @@ -51,7 +51,7 @@ public PluginProvider plugin() { /** {@inheritDoc} */ @SuppressWarnings("unchecked") - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { throw new UnsupportedOperationException(); } @@ -61,7 +61,7 @@ public PluginProvider plugin() { } /** {@inheritDoc} */ - @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { + @Override public void onKernalStart() throws IgniteCheckedException { plugin.onIgniteStart(); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index f092e2bb00a23..fa605d6f74acd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -926,7 +926,8 @@ public void start( startProcessor(new GridAffinityProcessor(ctx)); startProcessor(createComponent(GridSegmentationProcessor.class, ctx)); startProcessor(createComponent(IgniteCacheObjectProcessor.class, ctx)); - startProcessor(new GridCacheProcessor(ctx));startProcessor(new GridClusterStateProcessor(ctx)); + startProcessor(new GridClusterStateProcessor(ctx)); + startProcessor(new GridCacheProcessor(ctx)); startProcessor(new GridQueryProcessor(ctx)); startProcessor(new SqlListenerProcessor(ctx)); startProcessor(new GridServiceProcessor(ctx)); @@ -991,10 +992,10 @@ public void start( ctx.performance().addAll(OsConfigurationSuggestions.getSuggestions()); // Notify discovery manager the first to make sure that topology is discovered. - ctx.discovery().onKernalStart(activeOnStart); + ctx.discovery().onKernalStart(); // Notify IO manager the second so further components can send and receive messages. - ctx.io().onKernalStart(activeOnStart); + ctx.io().onKernalStart(); // Start plugins. for (PluginProvider provider : ctx.plugins().allProviders()) @@ -1017,7 +1018,7 @@ public void start( if (!skipDaemon(comp)) { try { - comp.onKernalStart(activeOnStart); + comp.onKernalStart(); } catch (IgniteNeedReconnectException e) { assert ctx.discovery().reconnectSupported(); @@ -1749,7 +1750,7 @@ private void startManager(GridManager mgr) throws IgniteCheckedException { try { if (!skipDaemon(mgr)) - mgr.start(cfg.isActiveOnStart()); + mgr.start(); } catch (IgniteCheckedException e) { U.error(log, "Failed to start manager: " + mgr, e); @@ -1767,7 +1768,7 @@ private void startProcessor(GridProcessor proc) throws IgniteCheckedException { try { if (!skipDaemon(proc)) - proc.start(cfg.isActiveOnStart()); + proc.start(); } catch (IgniteCheckedException e) { throw new IgniteCheckedException("Failed to start processor: " + proc, e); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java index 7d9ee7417076e..7dfeffbcf76cf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java @@ -362,7 +362,7 @@ protected final String stopInfo() { } /** {@inheritDoc} */ - @Override public final void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { + @Override public final void onKernalStart() throws IgniteCheckedException { for (final IgniteSpi spi : spis) { try { spi.onContextInitialized(new IgniteSpiContext() { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointManager.java index 782ee5e5014ee..3c08e9e6e052f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointManager.java @@ -102,7 +102,7 @@ public GridCheckpointManager(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { for (CheckpointSpi spi : getSpis()) { spi.setCheckpointListener(new CheckpointListener() { @Override public void onCheckpointRemoved(String key) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/collision/GridCollisionManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/collision/GridCollisionManager.java index 14f69def2cffe..40901b6794631 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/collision/GridCollisionManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/collision/GridCollisionManager.java @@ -47,7 +47,7 @@ public GridCollisionManager(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { startSpi(); if (enabled()) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java index 3769a9c6ead9f..85ae024bfd5c8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java @@ -261,7 +261,7 @@ public void resetMetrics() { /** {@inheritDoc} */ @SuppressWarnings("deprecation") - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { assertParameter(discoDelay > 0, "discoveryStartupDelay > 0"); startSpi(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentManager.java index 17d30eb74438e..cea178604be50 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentManager.java @@ -91,7 +91,7 @@ public GridDeploymentManager(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { GridProtocolHandler.registerDeploymentManager(this); assertParameter(ctx.config().getDeploymentMode() != null, "ctx.config().getDeploymentMode() != null"); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java index a442d04c0157e..5bb02653df109 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java @@ -73,6 +73,7 @@ import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; +import org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor; import org.apache.ignite.internal.processors.jobmetrics.GridJobMetrics; import org.apache.ignite.internal.processors.security.SecurityContext; import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor; @@ -463,7 +464,7 @@ private void updateClientNodes(UUID leftNodeId) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { long totSysMemory = -1; try { @@ -741,19 +742,36 @@ else if (type == EVT_CLIENT_NODE_RECONNECTED) { } @Override public void onExchange(DiscoveryDataBag dataBag) { + assert dataBag != null; + assert dataBag.joiningNodeId() != null; + if (ctx.localNodeId().equals(dataBag.joiningNodeId())) { - //NodeAdded msg reached joining node after round-trip over the ring + // NodeAdded msg reached joining node after round-trip over the ring. + GridClusterStateProcessor stateProc = ctx.state(); + + stateProc.onGridDataReceived(dataBag.gridDiscoveryData( + stateProc.discoveryDataType().ordinal())); + for (GridComponent c : ctx.components()) { - if (c.discoveryDataType() != null) + if (c.discoveryDataType() != null && c != stateProc) c.onGridDataReceived(dataBag.gridDiscoveryData(c.discoveryDataType().ordinal())); } } else { - //discovery data from newly joined node has to be applied to the current old node + // Discovery data from newly joined node has to be applied to the current old node. + GridClusterStateProcessor stateProc = ctx.state(); + + JoiningNodeDiscoveryData data0 = dataBag.newJoinerDiscoveryData( + stateProc.discoveryDataType().ordinal()); + + assert data0 != null; + + stateProc.onJoiningNodeDataReceived(data0); + for (GridComponent c : ctx.components()) { - if (c.discoveryDataType() != null) { - JoiningNodeDiscoveryData data = - dataBag.newJoinerDiscoveryData(c.discoveryDataType().ordinal()); + if (c.discoveryDataType() != null && c != stateProc) { + JoiningNodeDiscoveryData data = dataBag.newJoinerDiscoveryData( + c.discoveryDataType().ordinal()); if (data != null) c.onJoiningNodeDataReceived(data); @@ -1222,17 +1240,6 @@ private void checkAttributes(Iterable nodes) throws IgniteCheckedEx ", rmtAddrs=" + U.addressesAsString(n) + ']'); } - boolean rmtActiveOnStart = n.attribute(ATTR_ACTIVE_ON_START); - - if (locActiveOnStart != rmtActiveOnStart) { - throw new IgniteCheckedException("Remote node has active on start flag different from local " + - "[locId8=" + U.id8(locNode.id()) + - ", locActiveOnStart=" + locActiveOnStart + - ", rmtId8=" + U.id8(n.id()) + - ", rmtActiveOnStart=" + rmtActiveOnStart + - ", rmtAddrs=" + U.addressesAsString(n) + ']'); - } - Boolean rmtSrvcCompatibilityEnabled = n.attribute(ATTR_SERVICES_COMPATIBILITY_MODE); if (!F.eq(locSrvcCompatibilityEnabled, rmtSrvcCompatibilityEnabled)) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java index 04fb5b9a9a6bf..53b258a216298 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java @@ -273,7 +273,7 @@ private void leaveBusy() { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { Map, int[]> evtLsnrs = ctx.config().getLocalEventListeners(); if (evtLsnrs != null) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/failover/GridFailoverManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/failover/GridFailoverManager.java index 5393d9cc76350..d287e63f63e9e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/failover/GridFailoverManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/failover/GridFailoverManager.java @@ -40,7 +40,7 @@ public GridFailoverManager(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { startSpi(); if (log.isDebugEnabled()) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java index 6d2960437f60d..f1f8f873ff238 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java @@ -48,7 +48,7 @@ public GridIndexingManager(GridKernalContext ctx) { /** * @throws IgniteCheckedException Thrown in case of any errors. */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { startSpi(); if (log.isDebugEnabled()) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/loadbalancer/GridLoadBalancerManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/loadbalancer/GridLoadBalancerManager.java index 2c218f09331c8..15a4d2cd9510b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/loadbalancer/GridLoadBalancerManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/loadbalancer/GridLoadBalancerManager.java @@ -45,7 +45,7 @@ public GridLoadBalancerManager(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { startSpi(); if (log.isDebugEnabled()) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java index f3e3aa4b67c18..468d35dfc93ff 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java @@ -20,6 +20,7 @@ import java.nio.ByteBuffer; import java.util.Map; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; @@ -187,7 +188,6 @@ public void initializeForCache(CacheGroupDescriptor grpDesc, * @throws IgniteCheckedException If failed. */ public void storeCacheData(CacheGroupDescriptor grpDesc, StoredCacheData cacheData) throws IgniteCheckedException; - /** * @param grpId Cache group ID. * @return {@code True} if index store for given cache group existed before node started. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/GridProcessorAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/GridProcessorAdapter.java index cd97aea646ab7..4b4aec5b9c554 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/GridProcessorAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/GridProcessorAdapter.java @@ -55,7 +55,7 @@ protected GridProcessorAdapter(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { + @Override public void onKernalStart() throws IgniteCheckedException { // No-op. } @@ -100,7 +100,7 @@ protected GridProcessorAdapter(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { // No-op. } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java index 87c424a9ba4e1..71a6e72253959 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java @@ -133,7 +133,7 @@ public GridAffinityProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { ctx.event().addLocalEventListener(lsnr, EVT_NODE_FAILED, EVT_NODE_LEFT, EVT_NODE_JOINED); } 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 d8ca1771cd7ae..70bf117c91eb4 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 @@ -349,11 +349,11 @@ private void updateCachesInfo(ExchangeActions exchActions) { * @throws IgniteCheckedException If failed. * @return {@code True} if client-only exchange is needed. */ - public boolean onCacheChangeRequest(final GridDhtPartitionsExchangeFuture fut, + public boolean onCacheChangeRequest( + final GridDhtPartitionsExchangeFuture fut, boolean crd, - final ExchangeActions exchActions) - throws IgniteCheckedException - { + final ExchangeActions exchActions + ) throws IgniteCheckedException { assert exchActions != null && !exchActions.empty() : exchActions; updateCachesInfo(exchActions); @@ -377,7 +377,19 @@ public boolean onCacheChangeRequest(final GridDhtPartitionsExchangeFuture fut, NearCacheConfiguration nearCfg = null; - if (cctx.localNodeId().equals(req.initiatingNodeId())) { + if (exchActions.newClusterState() == ClusterState.ACTIVE) { + if (CU.isSystemCache(req.cacheName())) + startCache = true; + else if (!cctx.localNode().isClient()) { + startCache = cctx.cacheContext(action.descriptor().cacheId()) == null && + CU.affinityNode(cctx.localNode(), req.startCacheConfiguration().getNodeFilter()); + + nearCfg = req.nearCacheConfiguration(); + } + else // Only static cache configured on client must be started. + startCache = cctx.kernalContext().state().isLocalConfigure(req.cacheName()); + } + else if (cctx.localNodeId().equals(req.initiatingNodeId())) { startCache = true; nearCfg = req.nearCacheConfiguration(); @@ -388,9 +400,19 @@ public boolean onCacheChangeRequest(final GridDhtPartitionsExchangeFuture fut, } try { + // Save configuration before cache started. + if (cctx.pageStore() != null && !cctx.localNode().isClient()) + cctx.pageStore().storeCacheData( + cacheDesc.groupDescriptor(), + new StoredCacheData(req.startCacheConfiguration()) + ); + if (startCache) { cctx.cache().prepareCacheStart(cacheDesc, nearCfg, fut.topologyVersion()); + if (exchActions.newClusterState() == null) + cctx.kernalContext().state().onCacheStart(req); + if (fut.cacheAddedOnExchange(cacheDesc.cacheId(), cacheDesc.receivedFrom())) { if (fut.discoCache().cacheGroupAffinityNodes(cacheDesc.groupId()).isEmpty()) U.quietAndWarn(log, "No server nodes found for cache client: " + req.cacheName()); @@ -845,9 +867,11 @@ else if (grpHolder.client() && grp != null) { * @param descs Cache descriptors. * @throws IgniteCheckedException If failed. */ - public void initStartedCaches(boolean crd, + public void initStartedCaches( + boolean crd, final GridDhtPartitionsExchangeFuture fut, - Collection descs) throws IgniteCheckedException { + Collection descs + ) throws IgniteCheckedException { for (DynamicCacheDescriptor desc : descs) { CacheGroupDescriptor grpDesc = desc.groupDescriptor(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClientReconnectDiscoveryData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClientReconnectDiscoveryData.java index 6a6f40d90f998..c264263f1592c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClientReconnectDiscoveryData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheClientReconnectDiscoveryData.java @@ -56,7 +56,7 @@ Map clientCacheGroups() { /** * @return Information about caches started on re-joining client node. */ - Map clientCaches() { + public Map clientCaches() { return clientCaches; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheData.java index b728d9611ccb3..dee32fa157c60 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheData.java @@ -177,6 +177,13 @@ public UUID receivedFrom() { return rcvdFrom; } + /** + * @return Flags. + */ + public long flags() { + return flags; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(CacheData.class, this, "cacheName", cacheCfg.getName()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java index 3f99134cea365..ecfa8bc6afecc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java @@ -26,7 +26,7 @@ /** * Information about configured caches sent from joining node. */ -class CacheJoinNodeDiscoveryData implements Serializable { +public class CacheJoinNodeDiscoveryData implements Serializable { /** */ private static final long serialVersionUID = 0L; @@ -51,7 +51,7 @@ class CacheJoinNodeDiscoveryData implements Serializable { * @param templates Templates. * @param startCaches {@code True} if required to start all caches on joining node. */ - CacheJoinNodeDiscoveryData( + public CacheJoinNodeDiscoveryData( IgniteUuid cacheDeploymentId, Map caches, Map templates, @@ -72,28 +72,28 @@ boolean startCaches() { /** * @return Deployment ID assigned on joining node. */ - IgniteUuid cacheDeploymentId() { + public IgniteUuid cacheDeploymentId() { return cacheDeploymentId; } /** * @return Templates configured on joining node. */ - Map templates() { + public Map templates() { return templates; } /** * @return Caches configured on joining node. */ - Map caches() { + public Map caches() { return caches; } /** * */ - static class CacheInfo implements Serializable { + public static class CacheInfo implements Serializable { /** */ private static final long serialVersionUID = 0L; @@ -118,7 +118,7 @@ static class CacheInfo implements Serializable { * @param sql SQL flag - {@code true} if cache was created with {@code CREATE TABLE}. * @param flags Flags (for future usage). */ - CacheInfo(StoredCacheData cacheData, CacheType cacheType, boolean sql, long flags) { + public CacheInfo(StoredCacheData cacheData, CacheType cacheType, boolean sql, long flags) { this.cacheData = cacheData; this.cacheType = cacheType; this.sql = sql; @@ -128,21 +128,21 @@ static class CacheInfo implements Serializable { /** * @return Cache data. */ - StoredCacheData cacheData() { + public StoredCacheData cacheData() { return cacheData; } /** * @return Cache type. */ - CacheType cacheType() { + public CacheType cacheType() { return cacheType; } /** * @return SQL flag - {@code true} if cache was created with {@code CREATE TABLE}. */ - boolean sql() { + public boolean sql() { return sql; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java index 796ed9de4f22d..abcc1927d927f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheNodeCommonDiscoveryData.java @@ -27,7 +27,7 @@ /** * Cache information sent in discovery data to joining node. */ -class CacheNodeCommonDiscoveryData implements Serializable { +public class CacheNodeCommonDiscoveryData implements Serializable { /** */ private static final long serialVersionUID = 0L; @@ -55,7 +55,7 @@ class CacheNodeCommonDiscoveryData implements Serializable { * @param cacheGrps Started cache groups. * @param clientNodesMap Information about cache client nodes. */ - CacheNodeCommonDiscoveryData(Map caches, + public CacheNodeCommonDiscoveryData(Map caches, Map templates, Map cacheGrps, Map> clientNodesMap, @@ -83,21 +83,21 @@ Map cacheGroups() { /** * @return Started caches. */ - Map caches() { + public Map caches() { return caches; } /** * @return Configured templates. */ - Map templates() { + public Map templates() { return templates; } /** * @return Information about cache client nodes. */ - Map> clientNodesMap() { + public Map> clientNodesMap() { return clientNodesMap; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index 4838a82141a09..ef5dd51a8de11 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -82,10 +82,10 @@ class ClusterCachesInfo { /** */ private CachesOnDisconnect cachesOnDisconnect; - /** */ + /** Local cache info */ private CacheJoinNodeDiscoveryData joinDiscoData; - /** */ + /** Cluster cache info */ private GridData gridData; /** */ @@ -109,25 +109,6 @@ class ClusterCachesInfo { */ void onStart(CacheJoinNodeDiscoveryData joinDiscoData) throws IgniteCheckedException { this.joinDiscoData = joinDiscoData; - - Map grpCfgs = new HashMap<>(); - - for (CacheJoinNodeDiscoveryData.CacheInfo info : joinDiscoData.caches().values()) { - if (info.cacheData().config().getGroupName() == null) - continue; - - CacheConfiguration ccfg = grpCfgs.get(info.cacheData().config().getGroupName()); - - if (ccfg == null) - grpCfgs.put(info.cacheData().config().getGroupName(), info.cacheData().config()); - else - validateCacheGroupConfiguration(ccfg, info.cacheData().config()); - } - - String conflictErr = processJoiningNode(joinDiscoData, ctx.localNodeId(), true); - - if (conflictErr != null) - throw new IgniteCheckedException("Failed to start configured cache. " + conflictErr); } /** @@ -175,7 +156,6 @@ void onKernalStart(boolean checkConsistency) throws IgniteCheckedException { joinDiscoData = null; gridData = null; } - /** * Checks that remote caches has configuration compatible with the local. * @@ -218,7 +198,7 @@ private void checkCache(CacheJoinNodeDiscoveryData.CacheInfo locInfo, CacheData } CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "cacheAffinity", "Cache affinity", - locAttr.cacheAffinityClassName(), rmtAttr.cacheAffinityClassName(), true); + locAttr.cacheAffinityClassName(), rmtAttr.cacheAffinityClassName(), true); CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "cacheAffinityMapper", "Cache affinity mapper", locAttr.cacheAffinityMapperClassName(), @@ -691,6 +671,27 @@ List cachesReceivedFromJoin(UUID joinedNodeId) { return started != null ? started : Collections.emptyList(); } + public void addJoinInfo() { + Map grpCfgs = new HashMap<>(); + + for (CacheJoinNodeDiscoveryData.CacheInfo info : joinDiscoData.caches().values()) { + if (info.cacheData().config().getGroupName() == null) + continue; + + CacheConfiguration ccfg = grpCfgs.get(info.cacheData().config().getGroupName()); + + if (ccfg == null) + grpCfgs.put(info.cacheData().config().getGroupName(), info.cacheData().config()); + /*else + validateCacheGroupConfiguration(ccfg, info.cacheData().config());*/ + } + + String conflictErr = processJoiningNode(joinDiscoData, ctx.localNodeId(), true); + + /* if (conflictErr != null) + throw new IgniteCheckedException("Failed to start configured cache. " + conflictErr);*/ + } + /** * Discovery event callback, executed from discovery thread. * @@ -719,6 +720,9 @@ void onDiscoveryEvent(int type, ClusterNode node, AffinityTopologyVersion topVer if (gridData == null) { // First node starts. assert joinDiscoData != null || !ctx.state().active(); + if (ctx.state().active()) + addJoinInfo(); + initStartCachesForLocalJoin(true); } } @@ -983,7 +987,7 @@ void onJoiningNodeDataReceived(DiscoveryDataBag.JoiningNodeDiscoveryData data) { clientReconnectReqs.put(data.joiningNodeId(), (CacheClientReconnectDiscoveryData)joiningNodeData); } else - processClientReconnectData((CacheClientReconnectDiscoveryData) joiningNodeData, data.joiningNodeId()); + processClientReconnectData((CacheClientReconnectDiscoveryData)joiningNodeData, data.joiningNodeId()); } else if (joiningNodeData instanceof CacheJoinNodeDiscoveryData) processJoiningNode((CacheJoinNodeDiscoveryData)joiningNodeData, data.joiningNodeId(), false); @@ -1364,7 +1368,7 @@ ClusterCachesReconnectResult onReconnected() { boolean stopped; - if (!surviveReconnect(cacheName)) { + if (!surviveReconnect(cacheName) || !ctx.state().active()) { DynamicCacheDescriptor newDesc = registeredCaches.get(cacheName); stopped = newDesc == null || !desc.deploymentId().equals(newDesc.deploymentId()); @@ -1391,7 +1395,7 @@ ClusterCachesReconnectResult onReconnected() { /** * @return {@code True} if client node is currently in disconnected state. */ - private boolean disconnectedState() { + public boolean disconnectedState() { return cachesOnDisconnect != null; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java index 7c0c55c0ea7bc..ae6f9e0e762e8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java @@ -176,7 +176,12 @@ static DynamicCacheChangeRequest closeRequest(GridKernalContext ctx, String cach * @param destroy Destroy flag. * @return Cache stop request. */ - static DynamicCacheChangeRequest stopRequest(GridKernalContext ctx, String cacheName, boolean sql, boolean destroy) { + public static DynamicCacheChangeRequest stopRequest( + GridKernalContext ctx, + String cacheName, + boolean sql, + boolean destroy + ) { DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, ctx.localNodeId()); req.sql(sql); 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 fefaf07fc4deb..5ee80ef6ab8b7 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 @@ -74,6 +74,7 @@ import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; import org.apache.ignite.internal.processors.GridProcessorAdapter; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.CacheJoinNodeDiscoveryData.CacheInfo; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; @@ -638,7 +639,7 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near /** {@inheritDoc} */ @SuppressWarnings({"unchecked"}) - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { cachesInfo = new ClusterCachesInfo(ctx); DeploymentMode depMode = ctx.config().getDeploymentMode(); @@ -652,8 +653,10 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near initializeInternalCacheNames(); - sharedCtx = createSharedContext( - ctx, CU.startStoreSessionListeners(ctx, ctx.config().getCacheStoreSessionListenerFactories())); + Collection sessionListeners = + CU.startStoreSessionListeners(ctx, ctx.config().getCacheStoreSessionListenerFactories()); + + sharedCtx = createSharedContext(ctx, sessionListeners); transactions = new IgniteTransactionsImpl(sharedCtx); @@ -661,31 +664,28 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near for (GridCacheSharedManager mgr : sharedCtx.managers()) mgr.start(sharedCtx); - if (activeOnStart && !ctx.config().isDaemon()) { - Map caches = new HashMap<>(); + if (ctx.config().isDaemon()) + return; - Map templates = new HashMap<>(); + Map caches = new HashMap<>(); - addCacheOnJoinFromConfig(caches, templates); + Map templates = new HashMap<>(); - addCacheOnJoinFromPersistentStore(caches, templates); + addCacheOnJoinFromConfig(caches, templates); - CacheJoinNodeDiscoveryData discoData = new CacheJoinNodeDiscoveryData(IgniteUuid.randomUuid(), - caches, - templates, - startAllCachesOnClientStart()); + CacheJoinNodeDiscoveryData discoData = new CacheJoinNodeDiscoveryData( + IgniteUuid.randomUuid(), + caches, + templates, + startAllCachesOnClientStart() + ); - cachesInfo.onStart(discoData); - } - else { - cachesInfo.onStart(new CacheJoinNodeDiscoveryData(IgniteUuid.randomUuid(), - Collections.emptyMap(), - Collections.emptyMap(), - false)); - } + cachesInfo.onStart(discoData); if (log.isDebugEnabled()) log.debug("Started cache processor."); + + ctx.state().cacheProcessorStarted(discoData); } /** @@ -695,8 +695,8 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near * @throws IgniteCheckedException If failed. */ private void addCacheOnJoin(StoredCacheData cacheData, - Map caches, - Map templates) throws IgniteCheckedException { + Map caches, + Map templates) throws IgniteCheckedException { CacheConfiguration cfg = cacheData.config(); CU.validateCacheName(cfg.getName()); @@ -716,14 +716,7 @@ private void addCacheOnJoin(StoredCacheData cacheData, "assign unique name to each cache): " + cfg.getName()); } - CacheType cacheType; - - if (CU.isUtilityCache(cfg.getName())) - cacheType = CacheType.UTILITY; - else if (internalCaches.contains(cfg.getName())) - cacheType = CacheType.INTERNAL; - else - cacheType = CacheType.USER; + CacheType cacheType = cacheType(cfg.getName()); if (cacheType != CacheType.USER && cfg.getMemoryPolicyName() == null) cfg.setMemoryPolicyName(sharedCtx.database().systemMemoryPolicyName()); @@ -745,8 +738,8 @@ else if (internalCaches.contains(cfg.getName())) * @throws IgniteCheckedException If failed. */ private void addCacheOnJoinFromConfig( - Map caches, - Map templates + Map caches, + Map templates ) throws IgniteCheckedException { assert !ctx.config().isDaemon(); @@ -755,7 +748,8 @@ private void addCacheOnJoinFromConfig( for (int i = 0; i < cfgs.length; i++) { CacheConfiguration cfg = new CacheConfiguration(cfgs[i]); - cfgs[i] = cfg; // Replace original configuration value. + // Replace original configuration value. + cfgs[i] = cfg; StoredCacheData cacheData = new StoredCacheData(cfg); cacheData.sql(false); @@ -763,36 +757,6 @@ private void addCacheOnJoinFromConfig( } } - /** - * @param caches Caches map. - * @param templates Templates map. - * @throws IgniteCheckedException If failed. - */ - private void addCacheOnJoinFromPersistentStore( - Map caches, - Map templates - ) throws IgniteCheckedException { - assert !ctx.config().isDaemon(); - - if (sharedCtx.pageStore() != null && sharedCtx.database().persistenceEnabled()) { - Map cacheDataMap = sharedCtx.pageStore().readCacheConfigurations(); - - for (String cache : caches.keySet()) - cacheDataMap.remove(cache); - - for (String cache : internalCaches) - cacheDataMap.remove(cache); - - if (!F.isEmpty(cacheDataMap)) { - if (log.isInfoEnabled()) - log.info("Register persistent caches: " + cacheDataMap.keySet()); - - for (StoredCacheData cacheData : cacheDataMap.values()) - addCacheOnJoin(cacheData, caches, templates); - } - } - } - /** * Initialize internal cache names */ @@ -829,9 +793,11 @@ public Collection cacheGroups() { /** {@inheritDoc} */ @SuppressWarnings("unchecked") - @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { + @Override public void onKernalStart() throws IgniteCheckedException { ClusterNode locNode = ctx.discovery().localNode(); + boolean active = ctx.state().active(); + try { boolean checkConsistency = !ctx.config().isDaemon() && !getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK); @@ -841,42 +807,7 @@ public Collection cacheGroups() { cachesInfo.onKernalStart(checkConsistency); - boolean currStatus = ctx.state().active(); - - // If we start as inactive node, and join to active cluster, we must register all caches - // which were received on join. - if (!ctx.isDaemon() && currStatus && !activeOnStart) { - List tmpCacheCfg = new ArrayList<>(); - - for (CacheConfiguration conf : ctx.config().getCacheConfiguration()) { - assert conf.getName() != null; - - for (DynamicCacheDescriptor desc : cacheDescriptors().values()) { - CacheConfiguration c = desc.cacheConfiguration(); - IgnitePredicate filter = desc.groupDescriptor().config().getNodeFilter(); - - if (c.getName().equals(conf.getName()) && - ((desc.receivedOnDiscovery() && CU.affinityNode(locNode, filter)) || - CU.isSystemCache(c.getName()))) { - tmpCacheCfg.add(c); - - break; - } - } - } - - if (!tmpCacheCfg.isEmpty()) { - CacheConfiguration[] newCacheCfg = new CacheConfiguration[tmpCacheCfg.size()]; - - tmpCacheCfg.toArray(newCacheCfg); - - ctx.config().setCacheConfiguration(newCacheCfg); - } - - activeOnStart = currStatus; - } - - if (activeOnStart && !ctx.clientNode() && !ctx.isDaemon()) + if (active && !ctx.clientNode() && !ctx.isDaemon()) sharedCtx.database().lock(); // Must start database before start first cache. @@ -884,6 +815,8 @@ public Collection cacheGroups() { ctx.query().onCacheKernalStart(); + // In shared context, we start exchange manager and wait until processed local join + // event, all caches which we get on join will be start. for (GridCacheSharedManager mgr : sharedCtx.managers()) { if (sharedCtx.database() != mgr) mgr.onKernalStart(false); @@ -893,8 +826,8 @@ public Collection cacheGroups() { cacheStartedLatch.countDown(); } - // Escape if start active on start false - if (!activeOnStart) + // Escape if cluster inactive. + if (!active) return; if (!ctx.config().isDaemon()) @@ -1809,7 +1742,8 @@ public Collection startReceivedCaches(UUID nodeId, Affin for (DynamicCacheDescriptor desc : started) { IgnitePredicate filter = desc.groupDescriptor().config().getNodeFilter(); - if (CU.affinityNode(ctx.discovery().localNode(), filter)) { + //Todo check second condition. + if (CU.affinityNode(ctx.discovery().localNode(), filter) || CU.isSystemCache(desc.cacheName())) { prepareCacheStart( desc, null, @@ -2029,7 +1963,8 @@ private void stopGateway(DynamicCacheChangeRequest req) { sharedCtx.removeCacheContext(ctx); - onKernalStop(cache, req.destroy()); + // Todo cancel = true? + onKernalStop(cache, true); stopCache(cache, true, req.destroy()); @@ -2102,6 +2037,9 @@ public void onExchangeDone( try { stopCtx = prepareCacheStop(action.request(), forceClose); destroy = action.request().destroy(); + + if (exchActions.newClusterState() == null) + ctx.state().onCacheStop(action.request()); } finally { sharedCtx.database().checkpointReadUnlock(); @@ -2231,7 +2169,7 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, IgnitePageStoreManager pageStoreMgr = null; IgniteWriteAheadLogManager walMgr = null; - if (ctx.config().isPersistentStoreEnabled()) { + if (ctx.config().isPersistentStoreEnabled() && !ctx.clientNode()) { if (ctx.clientNode()) { U.warn(log, "Persistent Store is not supported on client nodes (Persistent Store's" + " configuration will be ignored)."); @@ -2288,24 +2226,37 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, /** {@inheritDoc} */ @Override public void collectGridNodeData(DiscoveryDataBag dataBag) { - cachesInfo.collectGridNodeData(dataBag); - } - - /** - * @return {@code True} if need locally start all existing caches on client node start. - */ - private boolean startAllCachesOnClientStart() { - return startClientCaches && ctx.clientNode(); + if (ctx.state().active()) + cachesInfo.collectGridNodeData(dataBag); + else + ctx.state().collectGridNodeData0(dataBag); } /** {@inheritDoc} */ @Override public void onJoiningNodeDataReceived(JoiningNodeDiscoveryData data) { - cachesInfo.onJoiningNodeDataReceived(data); + if (ctx.state().active()) + cachesInfo.onJoiningNodeDataReceived(data); + + ctx.state().onJoiningNodeDataReceived0(data); } /** {@inheritDoc} */ @Override public void onGridDataReceived(GridDiscoveryData data) { - cachesInfo.onGridDataReceived(data); + if (ctx.state().active()) { + if (!cachesInfo.disconnectedState()) + cachesInfo.addJoinInfo(); + + cachesInfo.onGridDataReceived(data); + } + + ctx.state().onGridDataReceived0(data); + } + + /** + * @return {@code True} if need locally start all existing caches on client node start. + */ + private boolean startAllCachesOnClientStart() { + return startClientCaches && ctx.clientNode(); } /** @@ -2723,84 +2674,14 @@ public IgniteInternalFuture resetCacheState(Collection cacheNames) { return fut; } - /** - * - */ - public Collection startAllCachesRequests() throws IgniteCheckedException { - List reqs = new ArrayList<>(); - - if (!ctx.config().isDaemon() && - sharedCtx.pageStore() != null && - sharedCtx.database().persistenceEnabled()) { - Map savedCaches = sharedCtx.pageStore().readCacheConfigurations(); - - for (StoredCacheData cfg : savedCaches.values()) - reqs.add(createRequest(cfg.config(), false)); - - for (CacheConfiguration cfg : ctx.config().getCacheConfiguration()) { - if (!savedCaches.containsKey(cfg.getName())) - reqs.add(createRequest(cfg, true)); - } - } - else { - for (CacheConfiguration cfg : ctx.config().getCacheConfiguration()) - reqs.add(createRequest(cfg, true)); - } - - return reqs; - } - - /** - * - */ - public Collection stopAllCachesRequests() { - List reqs = new ArrayList<>(); - - for (String cacheName : cacheNames()) { - DynamicCacheChangeRequest req = DynamicCacheChangeRequest.stopRequest(ctx, cacheName, false, false); - - reqs.add(req); - } - - return reqs; - } - - /** - * @param cfg Cache configuration. - */ - private DynamicCacheChangeRequest createRequest( - CacheConfiguration cfg, - boolean needInit - ) throws IgniteCheckedException { - assert cfg != null; - assert cfg.getName() != null; - - cloneCheckSerializable(cfg); - - if (needInit) { - CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(cfg); - - initialize(cfg, cacheObjCtx); - } - - String cacheName = cfg.getName(); - - DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, ctx.localNodeId()); - - req.startCacheConfiguration(cfg); - req.template(cfg.getName().endsWith("*")); - req.nearCacheConfiguration(cfg.getNearConfiguration()); - req.deploymentId(IgniteUuid.randomUuid()); - req.schema(new QuerySchema(cfg.getQueryEntities())); + public CacheType cacheType (String cacheName ) { if (CU.isUtilityCache(cacheName)) - req.cacheType(CacheType.UTILITY); + return CacheType.UTILITY; else if (internalCaches.contains(cacheName)) - req.cacheType(CacheType.INTERNAL); + return CacheType.INTERNAL; else - req.cacheType(CacheType.USER); - - return req; + return CacheType.USER; } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java index a2d319f32573f..f46b4bcc14368 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java @@ -138,7 +138,7 @@ public CacheObjectBinaryProcessorImpl(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { if (marsh instanceof BinaryMarshaller) { if (ctx.clientNode()) ctx.event().addLocalEventListener(clientDisconLsnr, EVT_CLIENT_NODE_DISCONNECTED); @@ -251,8 +251,8 @@ public void addBinaryMetadataUpdateListener(BinaryMetadataUpdatedListener lsnr) } /** {@inheritDoc} */ - @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { - super.onKernalStart(activeOnStart); + @Override public void onKernalStart() throws IgniteCheckedException { + super.onKernalStart(); discoveryStarted = true; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java index 27650a2168c05..a4ca5d2338095 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java @@ -118,7 +118,7 @@ public void init() throws IgniteCheckedException { initPageMemoryPolicies(memCfg); - registerMetricsMBeans(); + //registerMetricsMBeans(); startMemoryPolicies(); @@ -143,9 +143,11 @@ private void registerMetricsMBeans() { * @param memPlcCfg Memory policy configuration. * @param cfg Ignite configuration. */ - private void registerMetricsMBean(MemoryMetricsImpl memMetrics, + private void registerMetricsMBean( + MemoryMetricsImpl memMetrics, MemoryPolicyConfiguration memPlcCfg, - IgniteConfiguration cfg) { + IgniteConfiguration cfg + ) { try { U.registerMBean( cfg.getMBeanServer(), @@ -660,7 +662,7 @@ public ReuseList reuseList(String memPlcName) { IgniteConfiguration cfg = cctx.gridConfig(); - try { + /* try { cfg.getMBeanServer().unregisterMBean( U.makeMBeanName( cfg.getIgniteInstanceName(), @@ -670,7 +672,7 @@ public ReuseList reuseList(String memPlcName) { catch (JMException e) { U.error(log, "Failed to unregister MBean for memory metrics: " + memPlc.memoryMetrics().getName(), e); - } + }*/ } } } @@ -949,12 +951,12 @@ protected File buildPath(String path, String consId) { /** {@inheritDoc} */ @Override public void onActivate(GridKernalContext kctx) throws IgniteCheckedException { - // No-op. + start0(); } /** {@inheritDoc} */ @Override public void onDeActivate(GridKernalContext kctx) throws IgniteCheckedException { - // No-op. + stop0(true); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java index 40e21a07b9a6f..01207e382607d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java @@ -104,7 +104,7 @@ public GridClosureProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { if (log.isDebugEnabled()) log.debug("Started closure processor."); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java index 26b1a2e496735..7cb8577074945 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java @@ -294,7 +294,7 @@ private Boolean findLastFlag(Collection vals) { } /** {@inheritDoc} */ - @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { + @Override public void onKernalStart() throws IgniteCheckedException { if (notifyEnabled.get()) { try { verChecker = new GridUpdateNotifier(ctx.igniteInstanceName(), diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java index 3c500a469d125..643480dec6ae9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicReference; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCheckedException; @@ -33,6 +34,7 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.events.Event; import org.apache.ignite.internal.GridKernalContext; @@ -44,6 +46,11 @@ import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; import org.apache.ignite.internal.processors.GridProcessorAdapter; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.CacheClientReconnectDiscoveryData; +import org.apache.ignite.internal.processors.cache.CacheData; +import org.apache.ignite.internal.processors.cache.CacheJoinNodeDiscoveryData; +import org.apache.ignite.internal.processors.cache.CacheJoinNodeDiscoveryData.CacheInfo; +import org.apache.ignite.internal.processors.cache.CacheNodeCommonDiscoveryData; import org.apache.ignite.internal.processors.cache.ChangeGlobalStateMessage; import org.apache.ignite.internal.processors.cache.ClusterState; import org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch; @@ -53,6 +60,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse; import org.apache.ignite.internal.processors.cache.StoredCacheData; +import org.apache.ignite.internal.processors.query.QuerySchema; import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.tostring.GridToStringExclude; @@ -60,21 +68,25 @@ import org.apache.ignite.internal.util.typedef.CI1; import org.apache.ignite.internal.util.typedef.CI2; 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.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteFuture; import org.apache.ignite.lang.IgniteRunnable; +import org.apache.ignite.lang.IgniteUuid; import org.apache.ignite.resources.IgniteInstanceResource; import org.apache.ignite.spi.discovery.DiscoveryDataBag; +import org.apache.ignite.spi.discovery.DiscoveryDataBag.JoiningNodeDiscoveryData; import org.jetbrains.annotations.Nullable; import static org.apache.ignite.events.EventType.EVT_NODE_FAILED; import static org.apache.ignite.events.EventType.EVT_NODE_LEFT; +import static org.apache.ignite.internal.GridComponent.DiscoveryDataExchangeType.CACHE_PROC; +import static org.apache.ignite.internal.GridComponent.DiscoveryDataExchangeType.STATE_PROC; import static org.apache.ignite.internal.managers.communication.GridIoPolicy.SYSTEM_POOL; import static org.apache.ignite.internal.processors.cache.ClusterState.ACTIVE; import static org.apache.ignite.internal.processors.cache.ClusterState.INACTIVE; import static org.apache.ignite.internal.processors.cache.ClusterState.TRANSITION; +import static org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest.stopRequest; /** * @@ -127,20 +139,10 @@ public GridClusterStateProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { - super.start(activeOnStart); - - globalState = activeOnStart ? ACTIVE : INACTIVE; - cacheProc = ctx.cache(); - sharedCtx = cacheProc.context(); - - sharedCtx.io().addCacheHandler(0, - GridChangeGlobalStateMessageResponse.class, - new CI2() { - @Override public void apply(UUID nodeId, GridChangeGlobalStateMessageResponse msg) { - processChangeGlobalStateResponse(nodeId, msg); - } - }); + @Override public void start() throws IgniteCheckedException { + // Start first node as inactive if persistent enable. + globalState = ctx.config().isPersistentStoreEnabled() ? INACTIVE : + ctx.config().isActiveOnStart() ? ACTIVE : INACTIVE; ctx.discovery().setCustomEventListener( ChangeGlobalStateMessage.class, new CustomEventListener() { @@ -190,6 +192,23 @@ public GridClusterStateProcessor(GridKernalContext ctx) { ctx.event().addLocalEventListener(lsr, EVT_NODE_LEFT, EVT_NODE_FAILED); } + public void cacheProcessorStarted(CacheJoinNodeDiscoveryData data) { + assert data != null; + + localCacheData = data; + + cacheProc = ctx.cache(); + sharedCtx = cacheProc.context(); + + sharedCtx.io().addCacheHandler( + 0, GridChangeGlobalStateMessageResponse.class, + new CI2() { + @Override public void apply(UUID nodeId, GridChangeGlobalStateMessageResponse msg) { + processChangeGlobalStateResponse(nodeId, msg); + } + }); + } + /** {@inheritDoc} */ @Override public void stop(boolean cancel) throws IgniteCheckedException { super.stop(cancel); @@ -215,7 +234,8 @@ public GridClusterStateProcessor(GridKernalContext ctx) { /** {@inheritDoc} */ @Override public void collectGridNodeData(DiscoveryDataBag dataBag) { - dataBag.addGridCommonData(DiscoveryDataExchangeType.STATE_PROC.ordinal(), globalState); + if (!dataBag.commonDataCollectedFor(STATE_PROC.ordinal())) + dataBag.addGridCommonData(STATE_PROC.ordinal(), globalState); } /** {@inheritDoc} */ @@ -224,6 +244,25 @@ public GridClusterStateProcessor(GridKernalContext ctx) { if (state != null) globalState = state; + + // TODO warning, processing in discovery thread!!! + if (globalState == INACTIVE) { + // Clean up. + try { + if (sharedCtx.pageStore() != null) + sharedCtx.pageStore().onDeActivate(ctx); + + if (sharedCtx.wal() != null) + sharedCtx.wal().onDeActivate(ctx); + + // Todo check after join + sharedCtx.database().onDeActivate(ctx); + } + catch (IgniteCheckedException e) { + // Todo Need handler correct . + e.printStackTrace(); + } + } } /** @@ -250,33 +289,32 @@ public IgniteInternalFuture changeGlobalState(final boolean activate) { "fail " + prettyStr(activate) + ", because now in progress" + prettyStr(locF.activate))); } - try { - if (ctx.clientNode()) { - AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx(); + if (ctx.clientNode()) { + AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx(); - IgniteCompute comp = ((ClusterGroupAdapter)ctx.cluster().get().forServers()) - .compute().withAsync(); + IgniteCompute comp = ((ClusterGroupAdapter)ctx.cluster().get().forServers()).compute(); - if (log.isInfoEnabled()) - log.info("Send " + prettyStr(activate) + " request from client node [id=" + - ctx.localNodeId() + " topVer=" + topVer + " ]"); + if (log.isInfoEnabled()) + log.info("Send " + prettyStr(activate) + " request from client node [id=" + + ctx.localNodeId() + " topVer=" + topVer + " ]"); - comp.run(new ClientChangeGlobalStateComputeRequest(activate)); + IgniteFuture fut = comp.runAsync(new ClientChangeGlobalStateComputeRequest(activate)); - comp.future().listen(new CI1() { - @Override public void apply(IgniteFuture fut) { - try { - fut.get(); + fut.listen(new CI1() { + @Override public void apply(IgniteFuture fut) { + try { + fut.get(); - cgsFut.onDone(); - } - catch (Exception e) { - cgsFut.onDone(e); - } + cgsFut.onDone(); } - }); - } - else { + catch (Exception e) { + cgsFut.onDone(e); + } + } + }); + } + else { + try { List reqs = new ArrayList<>(); DynamicCacheChangeRequest changeGlobalStateReq = new DynamicCacheChangeRequest( @@ -284,7 +322,11 @@ public IgniteInternalFuture changeGlobalState(final boolean activate) { reqs.add(changeGlobalStateReq); - reqs.addAll(activate ? cacheProc.startAllCachesRequests() : cacheProc.stopAllCachesRequests()); + List cacheReqs = activate ? startAllCachesRequests() : stopAllCachesRequests(); + + reqs.addAll(cacheReqs); + + printCacheInfo(cacheReqs, activate); ChangeGlobalStateMessage changeGlobalStateMsg = new ChangeGlobalStateMessage( requestId, ctx.localNodeId(), activate, new DynamicCacheChangeBatch(reqs)); @@ -302,14 +344,123 @@ public IgniteInternalFuture changeGlobalState(final boolean activate) { cgsFut.onDone(e); } } + catch (IgniteCheckedException e) { + cgsFut.onDone(e); + } } - catch (IgniteCheckedException e) { - log.error("Fail create or send change global state request." + cgsFut, e); - cgsFut.onDone(e); + return cgsFut; + } + + private void printCacheInfo(List reqs, boolean active) { + assert reqs != null; + + StringBuilder sb = new StringBuilder(); + + sb.append("["); + + for (int i = 0; i < reqs.size() - 1; i++) + sb.append(reqs.get(i).cacheName()).append(", "); + + sb.append(reqs.get(reqs.size() - 1).cacheName()); + + sb.append("]"); + + sb.append(" ").append(reqs.size()) + .append(" caches will be ") + .append(active ? "started" : "stopped"); + + if (log.isInfoEnabled()) + log.info(sb.toString()); + } + + public void onCacheStart(DynamicCacheChangeRequest req) { + CacheInfo cacheInfo = cacheData.get(req.cacheName()); + + if (cacheInfo == null) + cacheData.put(req.cacheName(), + new CacheInfo( + new StoredCacheData(req.startCacheConfiguration()), + req.cacheType(), req.sql(), + 0L) + ); + } + + public void onCacheStop(DynamicCacheChangeRequest req) { + CacheInfo cacheInfo = cacheData.get(req.cacheName()); + + if (cacheInfo != null) + cacheData.remove(req.cacheName()); + } + + private Map allCaches() { + Map cfgs = new HashMap<>(); + + for (Map.Entry entry : cacheData.entrySet()) + if (cfgs.get(entry.getKey()) == null) + cfgs.put(entry.getKey(), entry.getValue().cacheData().config()); + + return cfgs; + } + + private List startAllCachesRequests() throws IgniteCheckedException { + assert !ctx.config().isDaemon(); + + Collection cacheCfgs = allCaches().values(); + + final List reqs = new ArrayList<>(); + + if (sharedCtx.pageStore() != null && sharedCtx.database().persistenceEnabled()) { + Map ccfgs = sharedCtx.pageStore().readCacheConfigurations(); + + for (Map.Entry entry : ccfgs.entrySet()) + reqs.add(createRequest(entry.getValue().config())); + + for (CacheConfiguration cfg : cacheCfgs) + if (!ccfgs.keySet().contains(cfg.getName())) + reqs.add(createRequest(cfg)); + + return reqs; } + else { + for (CacheConfiguration cfg : cacheCfgs) + reqs.add(createRequest(cfg)); - return cgsFut; + return reqs; + } + } + + private DynamicCacheChangeRequest createRequest(CacheConfiguration cfg) { + assert cfg != null; + assert cfg.getName() != null; + + String cacheName = cfg.getName(); + + DynamicCacheChangeRequest req = new DynamicCacheChangeRequest( + UUID.randomUUID(), cacheName, ctx.localNodeId()); + + req.startCacheConfiguration(cfg); + req.template(cfg.getName().endsWith("*")); + req.nearCacheConfiguration(cfg.getNearConfiguration()); + req.deploymentId(IgniteUuid.randomUuid()); + req.schema(new QuerySchema(cfg.getQueryEntities())); + req.cacheType(cacheProc.cacheType(cacheName)); + + return req; + } + + private List stopAllCachesRequests() { + Collection cacheCfgs = allCaches().values(); + + List reqs = new ArrayList<>(cacheCfgs.size()); + + for (CacheConfiguration cfg : cacheCfgs) { + DynamicCacheChangeRequest req = stopRequest(ctx, cfg.getName(), false, false); + + reqs.add(req); + } + + return reqs; } /** @@ -327,6 +478,79 @@ public boolean active() { return globalState == ACTIVE; } + @Override public void onKernalStart() throws IgniteCheckedException { + super.onKernalStart(); + + // First node started (coordinator). + if (ctx.discovery().serverNodes(AffinityTopologyVersion.NONE).get(0).isLocal()) + cacheData.putAll(localCacheData.caches()); + } + + private final ConcurrentHashMap cacheData = new ConcurrentHashMap<>(); + + private volatile CacheJoinNodeDiscoveryData localCacheData; + + public boolean isLocalConfigure(String cacheName){ + assert localCacheData != null; + + return localCacheData.caches().containsKey(cacheName) || localCacheData.templates().containsKey(cacheName); + } + + // Invoke if cluster inactive. + public void collectGridNodeData0(DiscoveryDataBag dataBag) { + if (!dataBag.commonDataCollectedFor(CACHE_PROC.ordinal())) + dataBag.addGridCommonData(CACHE_PROC.ordinal(), cacheData); + } + + public void onJoiningNodeDataReceived0(JoiningNodeDiscoveryData data) { + if (data.hasJoiningNodeData()) { + if (data.joiningNodeData() instanceof CacheJoinNodeDiscoveryData) { + CacheJoinNodeDiscoveryData data0 = (CacheJoinNodeDiscoveryData)data.joiningNodeData(); + + cacheData.putAll(data0.caches()); + } + else if (data.joiningNodeData() instanceof CacheClientReconnectDiscoveryData) { + CacheClientReconnectDiscoveryData data0 = (CacheClientReconnectDiscoveryData)data.joiningNodeData(); + + //Todo think how handler? + } + } + } + + public void onGridDataReceived0(DiscoveryDataBag.GridDiscoveryData data) { + // Receive data from active cluster. + if (data.commonData() instanceof CacheNodeCommonDiscoveryData) { + CacheNodeCommonDiscoveryData data0 = (CacheNodeCommonDiscoveryData)data.commonData(); + + Map caches = data0.caches(); + + Map cacheInfos = new HashMap<>(); + + for (Map.Entry entry : caches.entrySet()) { + CacheData val = entry.getValue(); + + CacheInfo info = new CacheInfo( + new StoredCacheData(val.cacheConfiguration()), + val.cacheType(), + val.sql(), + val.flags() + ); + + cacheInfos.put(entry.getKey(), info); + } + + cacheData.putAll(cacheInfos); + + } // Receive data from inactive cluster. + else if (data.commonData() instanceof Map) { + Map data0 = (Map)data.commonData(); + + cacheData.putAll(data0); + } + + cacheData.putAll(localCacheData.caches()); + } + /** * @param exchActions Requests. * @param topVer Exchange topology version. @@ -341,7 +565,7 @@ public boolean changeGlobalState( if (exchActions.newClusterState() != null) { ChangeGlobalStateContext cgsCtx = lastCgsCtx; - assert cgsCtx != null : exchActions; + assert cgsCtx != null : topVer; cgsCtx.topologyVersion(topVer); @@ -412,7 +636,7 @@ public void onFullResponseMessage(Map exs) { GridChangeGlobalStateFuture af = cgsLocFut.get(); if (af != null && af.requestId.equals(actx.requestId)) { - IgniteCheckedException e = new IgniteCheckedException("see suppressed"); + IgniteCheckedException e = new IgniteCheckedException("Fail " + prettyStr(actx.activate), null, false); for (Map.Entry entry : exs.entrySet()) e.addSuppressed(entry.getValue()); @@ -439,34 +663,18 @@ private Exception onActivate(ChangeGlobalStateContext cgsCtx) { } try { - if (!client) { + if (!client) sharedCtx.database().lock(); - IgnitePageStoreManager pageStore = sharedCtx.pageStore(); + IgnitePageStoreManager pageStore = sharedCtx.pageStore(); - if (pageStore != null) - pageStore.onActivate(ctx); + if (pageStore != null) + pageStore.onActivate(ctx); - if (sharedCtx.wal() != null) - sharedCtx.wal().onActivate(ctx); + if (sharedCtx.wal() != null) + sharedCtx.wal().onActivate(ctx); - sharedCtx.database().initDataBase(); - - // TODO IGNITE-5075 group descriptors. - for (StoredCacheData cacheData : cfgs) { - if (CU.isSystemCache(cacheData.config().getName())) - if (pageStore != null) - pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(), cacheData); - } - - for (StoredCacheData cacheData : cfgs) { - if (!CU.isSystemCache(cacheData.config().getName())) - if (pageStore != null) - pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(), cacheData); - } - - sharedCtx.database().onActivate(ctx); - } + sharedCtx.database().onActivate(ctx); if (log.isInfoEnabled()) log.info("Success activate wal, dataBase, pageStore [nodeId=" @@ -478,7 +686,7 @@ private Exception onActivate(ChangeGlobalStateContext cgsCtx) { log.error("Fail activate wal, dataBase, pageStore [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]", e); - if (!ctx.clientNode()) + if (!client) sharedCtx.database().unLock(); return e; @@ -512,10 +720,6 @@ public Exception onDeActivate(ChangeGlobalStateContext cgsCtx) { return e; } - finally { - if (!client) - sharedCtx.database().unLock(); - } } /** @@ -574,17 +778,15 @@ public void onFinalDeActivate(ChangeGlobalStateContext cgsCtx) { Exception ex = null; try { - if (!client) { - sharedCtx.database().onDeActivate(ctx); + sharedCtx.database().onDeActivate(ctx); - if (sharedCtx.pageStore() != null) - sharedCtx.pageStore().onDeActivate(ctx); + if (sharedCtx.pageStore() != null) + sharedCtx.pageStore().onDeActivate(ctx); - if (sharedCtx.wal() != null) - sharedCtx.wal().onDeActivate(ctx); + if (sharedCtx.wal() != null) + sharedCtx.wal().onDeActivate(ctx); - sharedCtx.affinity().removeAllCacheInfo(); - } + sharedCtx.affinity().removeAllCacheInfo(); } catch (Exception e) { ex = e; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java index a72dcd6b56c7b..9b04af98e23c3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java @@ -152,7 +152,7 @@ public GridContinuousProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { if (ctx.config().isDaemon()) return; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessor.java index c52f7aca926d8..70b3103995604 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessor.java @@ -94,7 +94,7 @@ public DataStreamProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { if (ctx.config().isDaemon()) return; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java index 961fe46f06bca..369a90970d7fa 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java @@ -202,31 +202,23 @@ public DataStructuresProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { - super.start(activeOnStart); - - if (!activeOnStart) - return; - + @Override public void start() throws IgniteCheckedException { ctx.event().addLocalEventListener(lsnr, EVT_NODE_LEFT, EVT_NODE_FAILED); } /** {@inheritDoc} */ @SuppressWarnings("unchecked") - @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { + @Override public void onKernalStart() throws IgniteCheckedException { if (ctx.config().isDaemon() || !ctx.state().active()) return; - onKernalStart0(activeOnStart); + onKernalStart0(); } /** * */ - private void onKernalStart0(boolean activeOnStart){ - if (!activeOnStart && ctx.state().active()) - ctx.event().addLocalEventListener(lsnr, EVT_NODE_LEFT, EVT_NODE_FAILED); - + private void onKernalStart0(){ utilityCache = (IgniteInternalCache)ctx.cache().utilityCache(); utilityDataCache = (IgniteInternalCache)ctx.cache().utilityCache(); @@ -315,7 +307,7 @@ private void startQuery() throws IgniteCheckedException { ctx.event().addLocalEventListener(lsnr, EVT_NODE_LEFT, EVT_NODE_FAILED); - onKernalStart0(true); + onKernalStart0(); restoreStructuresState(ctx); } @@ -324,7 +316,7 @@ private void startQuery() throws IgniteCheckedException { * @param ctx Context. */ public void restoreStructuresState(GridKernalContext ctx) { - onKernalStart0(true); + onKernalStart0(); try { for (Map.Entry e : dsMap.entrySet()) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java index d848d2fb4fd40..3c2f64d70aa3b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java @@ -75,7 +75,7 @@ public IgfsProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { IgniteConfiguration igniteCfg = ctx.config(); if (igniteCfg.isDaemon()) @@ -177,7 +177,7 @@ public IgfsProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { + @Override public void onKernalStart() throws IgniteCheckedException { if (ctx.config().isDaemon()) return; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobProcessor.java index e0bc4d2d493ad..9108967acf905 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobProcessor.java @@ -235,7 +235,7 @@ public GridJobProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { if (metricsUpdateFreq < -1) throw new IgniteCheckedException("Invalid value for 'metricsUpdateFrequency' configuration property " + "(should be greater than or equals to -1): " + metricsUpdateFreq); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/jobmetrics/GridJobMetricsProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/jobmetrics/GridJobMetricsProcessor.java index e7fe8aee9e1fd..c40cfdab0263a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/jobmetrics/GridJobMetricsProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/jobmetrics/GridJobMetricsProcessor.java @@ -127,7 +127,7 @@ int getHistorySize() { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { assertParameter(histSize > 0, "metricsHistorySize > 0"); assertParameter(expireTime > 0, "metricsExpireTime > 0"); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/marshaller/GridMarshallerMappingProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/marshaller/GridMarshallerMappingProcessor.java index 9b65aa50f984f..266c6f0957e01 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/marshaller/GridMarshallerMappingProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/marshaller/GridMarshallerMappingProcessor.java @@ -100,7 +100,7 @@ public GridMarshallerMappingProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { GridDiscoveryManager discoMgr = ctx.discovery(); GridIoManager ioMgr = ctx.io(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlListenerProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlListenerProcessor.java index 9a30d546a0cc3..a7061ffdb389b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlListenerProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlListenerProcessor.java @@ -67,7 +67,7 @@ public SqlListenerProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { IgniteConfiguration cfg = ctx.config(); SqlConnectorConfiguration sqlCfg = prepareConfiguration(cfg); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java index 792df86110ec9..1da3112b3ae10 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java @@ -147,7 +147,7 @@ public PlatformProcessorImpl(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { try (PlatformMemory mem = platformCtx.memory().allocate()) { PlatformOutputStream out = mem.output(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java index 687700cfe948d..c1e542d2be27e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java @@ -148,7 +148,7 @@ public T createComponent(Class cls) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { ackPluginsInfo(); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/port/GridPortProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/port/GridPortProcessor.java index 3d06a2af3087c..5d75a4a070ed5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/port/GridPortProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/port/GridPortProcessor.java @@ -57,7 +57,7 @@ public GridPortProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { if (log.isDebugEnabled()) log.debug("Started port processor."); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 2a715956a2613..6079ae82b93d5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -223,8 +223,8 @@ public GridQueryProcessor(GridKernalContext ctx) throws IgniteCheckedException { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { - super.start(activeOnStart); + @Override public void start() throws IgniteCheckedException { + super.start(); if (idx != null) { ctx.resource().injectGeneric(idx); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java index 345bf34b4ef35..6d508fe7830de 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java @@ -77,7 +77,7 @@ public GridResourceProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { if (log.isDebugEnabled()) log.debug("Started resource processor."); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java index f2f2b348bd23d..716adf74bd05a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java @@ -451,7 +451,7 @@ public GridRestProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { if (isRestEnabled()) { if (notStartOnClient()) { U.quietAndInfo(log, "REST protocols do not start on client node. " + @@ -503,7 +503,7 @@ private boolean notStartOnClient() { } /** {@inheritDoc} */ - @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { + @Override public void onKernalStart() throws IgniteCheckedException { if (isRestEnabled()) { for (GridRestProtocol proto : protos) proto.onKernalStart(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java index e3d365fef1886..5c1872ca46228 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java @@ -194,10 +194,10 @@ CU.UTILITY_CACHE_NAME, new ServiceEntriesListener(), null, null } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { ctx.addNodeAttribute(ATTR_SERVICES_COMPATIBILITY_MODE, srvcCompatibilitySysProp); - if (ctx.isDaemon() || !activeOnStart) + if (ctx.isDaemon()) return; IgniteConfiguration cfg = ctx.config(); @@ -211,7 +211,7 @@ CU.UTILITY_CACHE_NAME, new ServiceEntriesListener(), null, null /** {@inheritDoc} */ @SuppressWarnings("unchecked") - @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { + @Override public void onKernalStart() throws IgniteCheckedException { if (ctx.isDaemon() || !ctx.state().active()) return; @@ -348,9 +348,9 @@ CU.UTILITY_CACHE_NAME, new ServiceEntriesListener(), null, null depExe = Executors.newSingleThreadExecutor(new IgniteThreadFactory(ctx.igniteInstanceName(), "srvc-deploy")); - start(true); + start(); - onKernalStart(true); + onKernalStart(); } /** {@inheritDoc} */ @@ -364,6 +364,8 @@ CU.UTILITY_CACHE_NAME, new ServiceEntriesListener(), null, null cancelFutures(undepFuts, new IgniteCheckedException("Failed to undeploy service, cluster in active.")); onKernalStop(true); + + busyLock.unblock(); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/session/GridTaskSessionProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/session/GridTaskSessionProcessor.java index f9937a6bb6843..91ccf4a3a800c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/session/GridTaskSessionProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/session/GridTaskSessionProcessor.java @@ -49,7 +49,7 @@ public GridTaskSessionProcessor(GridKernalContext ctx) { /** * Starts session processor. */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { if (log.isDebugEnabled()) log.debug("Session processor started."); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java index e73d292044995..683d3c6d3336f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java @@ -140,7 +140,7 @@ public GridTaskProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) { + @Override public void start() { ctx.event().addLocalEventListener(discoLsnr, EVT_NODE_FAILED, EVT_NODE_LEFT); ctx.io().addMessageListener(TOPIC_JOB_SIBLINGS, new JobSiblingsMessageListener()); @@ -152,7 +152,7 @@ public GridTaskProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { + @Override public void onKernalStart() throws IgniteCheckedException { tasksMetaCache = ctx.security().enabled() && !ctx.isDaemon() ? ctx.cache().utilityCache() : null; 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 1651d17f6238e..9deca9a229d5b 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 @@ -67,7 +67,7 @@ public GridTimeoutProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) { + @Override public void start() { timeoutWorker.start(); if (log.isDebugEnabled()) diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java index c253a6d9763b9..184b6cd447681 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java @@ -3729,32 +3729,6 @@ else if (log.isDebugEnabled()) return; } - boolean locActiveOnStart = booleanAttribute(locNode, ATTR_ACTIVE_ON_START, true); - boolean rmtActiveOnStart = booleanAttribute(node, ATTR_ACTIVE_ON_START, true); - - if (locActiveOnStart != rmtActiveOnStart) { - String errMsg = "Local node's active on start flag differs from " + - "the same property on remote node (make sure all nodes in topology have the same " + - "active on start flag) [locActiveOnStart=" + locActiveOnStart + - ", rmtActiveOnStart=" + rmtActiveOnStart + - ", locNodeAddrs=" + U.addressesAsString(locNode) + - ", rmtNodeAddrs=" + U.addressesAsString(node) + - ", locNodeId=" + locNode.id() + ", rmtNodeId=" + msg.creatorNodeId() + ']'; - - String sndMsg = "Local node's active on start flag differs from " + - "the same property on remote node (make sure all nodes in topology have the same " + - "active on start flag) [locActiveOnStart=" + rmtActiveOnStart + - ", rmtActiveOnStart=" + locActiveOnStart + - ", locNodeAddrs=" + U.addressesAsString(node) + ", locPort=" + node.discoveryPort() + - ", rmtNodeAddr=" + U.addressesAsString(locNode) + ", locNodeId=" + node.id() + - ", rmtNodeId=" + locNode.id() + ']'; - - nodeCheckError(node, errMsg, sndMsg); - - // Ignore join request. - return; - } - final Boolean locSrvcCompatibilityEnabled = locNode.attribute(ATTR_SERVICES_COMPATIBILITY_MODE); final Boolean rmtSrvcCompatibilityEnabled = node.attribute(ATTR_SERVICES_COMPATIBILITY_MODE); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/GridManagerLocalMessageListenerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/GridManagerLocalMessageListenerSelfTest.java index 48e617f3cfe6c..5e85b62b26b75 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/GridManagerLocalMessageListenerSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/GridManagerLocalMessageListenerSelfTest.java @@ -126,9 +126,9 @@ public void testAddLocalMessageListener() throws Exception { Manager mgr = new Manager(grid().context(), new Spi()); - mgr.start(true); + mgr.start(); - mgr.onKernalStart(true); + mgr.onKernalStart(); assertTrue(mgr.enabled()); } @@ -143,7 +143,7 @@ public void testRemoveLocalMessageListener() throws Exception { assertTrue(mgr.enabled()); - mgr.onKernalStart(true); + mgr.onKernalStart(); mgr.onKernalStop(false); @@ -163,7 +163,7 @@ protected Manager(GridKernalContext ctx, IgniteSpi... spis) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { // No-op. } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/GridNoopManagerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/GridNoopManagerSelfTest.java index cb7efc8de9fc8..795bda41fe069 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/GridNoopManagerSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/GridNoopManagerSelfTest.java @@ -57,7 +57,7 @@ protected Manager(GridKernalContext ctx, IgniteSpi... spis) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { // No-op. } diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiMultithreadedSelfTest.java index 1df86f17dc703..90af25e481f26 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiMultithreadedSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiMultithreadedSelfTest.java @@ -477,9 +477,9 @@ private int getSpiCount() { timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log)); - timeoutProcessor.start(true); + timeoutProcessor.start(); - timeoutProcessor.onKernalStart(true); + timeoutProcessor.onKernalStart(); for (int i = 0; i < getSpiCount(); i++) { CommunicationSpi spi = newCommunicationSpi(); diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TestReconnectProcessor.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TestReconnectProcessor.java index d15ddf9811fd2..2476bd3d787bf 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TestReconnectProcessor.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TestReconnectProcessor.java @@ -50,7 +50,7 @@ protected TestReconnectProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS, new SecurityCredentials()); } diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java index 5b7e4b27df2fb..93f691e0c202a 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java @@ -778,6 +778,17 @@ protected IgniteEx startGrid(int idx) throws Exception { return (IgniteEx)startGrid(getTestIgniteInstanceName(idx)); } + /** + * Starts new grid with given configuration. + * + * @param cfg Ignite configuration. + * @return Started grid. + * @throws Exception If anything failed. + */ + protected IgniteEx startGrid(IgniteConfiguration cfg) throws Exception { + return (IgniteEx)startGrid(cfg.getIgniteInstanceName(), cfg, null); + } + /** * Starts new grid with given index and Spring application context. * @@ -1212,13 +1223,6 @@ protected Ignite startGrid(String igniteInstanceName, IgniteConfiguration cfg) t return startRemoteGrid(igniteInstanceName, cfg, null); } - /** - * @param cfg Config. - */ - protected Ignite startGrid(IgniteConfiguration cfg) throws Exception { - return startGrid(cfg.getIgniteInstanceName(), cfg); - } - /** * Loads configuration from the given Spring XML file. * diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java index b8d1ce97f4ff9..bb92e255e0944 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java @@ -83,7 +83,7 @@ public GridTestKernalContext(IgniteLogger log, IgniteConfiguration cfg) { */ public void start() throws IgniteCheckedException { for (GridComponent comp : this) - comp.start(config().isActiveOnStart()); + comp.start(); } /** diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopProcessor.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopProcessor.java index c7db48ff6449b..329d67fed653f 100644 --- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopProcessor.java +++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopProcessor.java @@ -64,7 +64,7 @@ public HadoopProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { if (ctx.isDaemon()) return; @@ -95,8 +95,8 @@ public HadoopProcessor(GridKernalContext ctx) { } /** {@inheritDoc} */ - @Override public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException { - super.onKernalStart(activeOnStart); + @Override public void onKernalStart() throws IgniteCheckedException { + super.onKernalStart(); if (hctx == null) return; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java index 10b664d10b9ea..cae59a4045279 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java @@ -103,6 +103,7 @@ import org.apache.ignite.internal.processors.cache.ClusterState; import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheProcessor; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.StoredCacheData; import org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager; @@ -347,7 +348,7 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { @Override protected void start0() throws IgniteCheckedException { snapshotMgr = cctx.snapshot(); - initDataBase(); + assert !cctx.kernalContext().state().active() : "Cluster with persistent must starting as inactive."; if (!cctx.kernalContext().clientNode()) { IgnitePageStoreManager store = cctx.pageStore(); @@ -447,56 +448,102 @@ public IgniteInternalFuture enableCheckpoints(boolean enable) { /** {@inheritDoc} */ @Override protected void onKernalStart0(boolean reconnect) throws IgniteCheckedException { - if (!reconnect && !cctx.kernalContext().clientNode() && cctx.kernalContext().state().active()) { - Collection cacheNames = new HashSet<>(); + if (reconnect || cctx.kernalContext().clientNode() || !cctx.kernalContext().state().active()) + return; - // TODO IGNITE-5075 group descriptors. - for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) { - if (CU.isSystemCache(ccfg.getName())) { - storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), new StoredCacheData(ccfg)); + if (persistenceEnabled() && cctx.kernalContext().state().active()) + initDataBase(); - cacheNames.add(ccfg.getName()); - } - } + GridCacheProcessor cachePrc = cctx.kernalContext().cache(); - for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) - if (!CU.isSystemCache(ccfg.getName())) { - DynamicCacheDescriptor cacheDesc = cctx.cache().cacheDescriptors().get(ccfg.getName()); + // Todo before join local node. - if (cacheDesc != null) - storeMgr.initializeForCache(cacheDesc.groupDescriptor(), new StoredCacheData(ccfg)); + Collection cacheNames = new HashSet<>(); - cacheNames.add(ccfg.getName()); - } + // TODO IGNITE-5075 group descriptors. + for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) { + if (CU.isSystemCache(ccfg.getName())) { + storeMgr.initializeForCache( + cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), new StoredCacheData(ccfg)); - for (StoredCacheData cacheData : cctx.pageStore().readCacheConfigurations().values()) { - if (!cacheNames.contains(cacheData.config().getName())) - storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(), cacheData); + cacheNames.add(ccfg.getName()); } + } + + for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) + if (!CU.isSystemCache(ccfg.getName())) { + DynamicCacheDescriptor cacheDesc = cctx.cache().cacheDescriptors().get(ccfg.getName()); - readCheckpointAndRestoreMemory(); + if (cacheDesc != null) + storeMgr.initializeForCache(cacheDesc.groupDescriptor(), new StoredCacheData(ccfg)); + + cacheNames.add(ccfg.getName()); + } + + for (StoredCacheData cacheData : cctx.pageStore().readCacheConfigurations().values()) { + if (!cacheNames.contains(cacheData.config().getName())) + storeMgr.initializeForCache( + cctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(), cacheData); } + + readCheckpointAndRestoreMemory(); } + /** {@inheritDoc} */ @Override public void onActivate(GridKernalContext kctx) throws IgniteCheckedException { - super.onActivate(kctx); + snapshotMgr = cctx.snapshot(); + + if (cctx.localNode().isClient()) + return; + + initDataBase(); if (log.isDebugEnabled()) log.debug("Activate database manager [id=" + cctx.localNodeId() + " topVer=" + cctx.discovery().topologyVersionEx() + " ]"); - if (!cctx.kernalContext().clientNode()) { - readCheckpointAndRestoreMemory(); + GridCacheProcessor cachePrc = cctx.kernalContext().cache(); - if (log.isDebugEnabled()) - log.debug("Restore state after activation [nodeId=" + cctx.localNodeId() + " ]"); + // Todo join local info. + + Collection cacheNames = new HashSet<>(); + + // TODO IGNITE-5075 group descriptors. + for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) { + if (CU.isSystemCache(ccfg.getName())) { + storeMgr.initializeForCache( + cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), new StoredCacheData(ccfg)); + + cacheNames.add(ccfg.getName()); + } + } + + for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) + if (!CU.isSystemCache(ccfg.getName())) { + DynamicCacheDescriptor cacheDesc = cctx.cache().cacheDescriptors().get(ccfg.getName()); + + if (cacheDesc != null) + storeMgr.initializeForCache(cacheDesc.groupDescriptor(), new StoredCacheData(ccfg)); + + cacheNames.add(ccfg.getName()); + } + + for (StoredCacheData cacheData : cctx.pageStore().readCacheConfigurations().values()) { + if (!cacheNames.contains(cacheData.config().getName())) + storeMgr.initializeForCache( + cctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(), cacheData); } + + readCheckpointAndRestoreMemory(); + + if (log.isDebugEnabled()) + log.debug("Restore state after activation [nodeId=" + cctx.localNodeId() + " ]"); } /** {@inheritDoc} */ @Override public void onDeActivate(GridKernalContext kctx) throws IgniteCheckedException { - super.onDeActivate(kctx); + stop0(true); if (log.isDebugEnabled()) log.debug("DeActivate database manager [id=" + cctx.localNodeId() + @@ -1926,6 +1973,9 @@ private void doCheckpoint() { Checkpoint chp = markCheckpointBegin(tracker); + if (chp.cpPages == null) + return; + snapshotMgr.onCheckPointBegin(); boolean interrupted = true; @@ -2967,8 +3017,9 @@ public void tryLock(int lockWaitTime) throws IgniteCheckedException { if (content == null) content = readContent(); - log.warning("Failed to acquire file lock (already locked by " + content - + "), will try again in 1s: " + file.getAbsolutePath()); + log.warning("Failed to acquire file lock (local nodeId:" + ctx.localNodeId() + + ", already locked by " + content + "), will try again in 1s: " + + file.getAbsolutePath()); } U.sleep(1000); diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java index f91c47f0357ca..8c096f1e7e6cc 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java +++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java @@ -204,16 +204,19 @@ public FilePageStoreManager(GridKernalContext ctx) { assert old == null : "Non-null old store holder for cache: " + cacheData.config().getName(); } - - storeCacheData(grpDesc, cacheData); } /** {@inheritDoc} */ - @Override public void storeCacheData(CacheGroupDescriptor grpDesc, StoredCacheData cacheData) - throws IgniteCheckedException { + @Override public void storeCacheData( + CacheGroupDescriptor grpDesc, + StoredCacheData cacheData + ) throws IgniteCheckedException { + File cacheWorkDir = cacheWorkDirectory(grpDesc, cacheData.config()); File file; + checkAndInitCacheWorkDir(cacheWorkDir); + assert cacheWorkDir.exists() : "Work directory does not exist: " + cacheWorkDir; if (grpDesc.sharedGroup()) @@ -356,6 +359,34 @@ private CacheStoreHolder initForCache(CacheGroupDescriptor grpDesc, CacheConfigu File cacheWorkDir = cacheWorkDirectory(grpDesc, ccfg); + boolean dirExisted = checkAndInitCacheWorkDir(cacheWorkDir); + + File idxFile = new File(cacheWorkDir, INDEX_FILE_NAME); + + if (dirExisted && !idxFile.exists()) + grpsWithoutIdx.add(grpDesc.groupId()); + + FilePageStore idxStore = new FilePageStore( + PageMemory.FLAG_IDX, + idxFile, + cctx.kernalContext().config().getMemoryConfiguration()); + + FilePageStore[] partStores = new FilePageStore[grpDesc.config().getAffinity().partitions()]; + + for (int partId = 0; partId < partStores.length; partId++) { + FilePageStore partStore = new FilePageStore( + PageMemory.FLAG_DATA, + new File(cacheWorkDir, String.format(PART_FILE_TEMPLATE, partId)), + cctx.kernalContext().config().getMemoryConfiguration() + ); + + partStores[partId] = partStore; + } + + return new CacheStoreHolder(idxStore, partStores); + } + + private boolean checkAndInitCacheWorkDir(File cacheWorkDir) throws IgniteCheckedException { boolean dirExisted = false; if (!cacheWorkDir.exists()) { @@ -389,7 +420,8 @@ private CacheStoreHolder initForCache(CacheGroupDescriptor grpDesc, CacheConfigu catch (IOException e) { throw new IgniteCheckedException(e); } - } else { + } + else { U.warn(log, "Ignite node crashed during the snapshot restore process " + "(there is a snapshot restore lock file left for cache). Will remove both the lock file and " + "incomplete cache directory [cacheDir=" + cacheWorkDir.getAbsolutePath() + ']'); @@ -411,29 +443,7 @@ private CacheStoreHolder initForCache(CacheGroupDescriptor grpDesc, CacheConfigu dirExisted = true; } - File idxFile = new File(cacheWorkDir, INDEX_FILE_NAME); - - if (dirExisted && !idxFile.exists()) - grpsWithoutIdx.add(grpDesc.groupId()); - - FilePageStore idxStore = new FilePageStore( - PageMemory.FLAG_IDX, - idxFile, - cctx.kernalContext().config().getMemoryConfiguration()); - - FilePageStore[] partStores = new FilePageStore[grpDesc.config().getAffinity().partitions()]; - - for (int partId = 0; partId < partStores.length; partId++) { - FilePageStore partStore = new FilePageStore( - PageMemory.FLAG_DATA, - new File(cacheWorkDir, String.format(PART_FILE_TEMPLATE, partId)), - cctx.kernalContext().config().getMemoryConfiguration() - ); - - partStores[partId] = partStore; - } - - return new CacheStoreHolder(idxStore, partStores); + return dirExisted; } /** {@inheritDoc} */ diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java index 997eef55edf26..144bbefca57ee 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java @@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.pagemem.PageIdUtils; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/AbstractNodeJoinTemplate.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/AbstractNodeJoinTemplate.java new file mode 100644 index 0000000000000..112ea03b23e72 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/AbstractNodeJoinTemplate.java @@ -0,0 +1,743 @@ +/* + * 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.cache.database.standbycluster; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; +import org.apache.ignite.internal.util.typedef.CI1; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteCallable; +import org.apache.ignite.lang.IgniteClosure; +import org.apache.ignite.lang.IgniteInClosure; +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.junits.common.GridCommonAbstractTest; +import org.junit.Assert; + +import static org.apache.ignite.internal.util.IgniteUtils.field; + +/** + * + */ +public abstract class AbstractNodeJoinTemplate extends GridCommonAbstractTest { + /** Cache 1. */ + protected static final String cache1 = "cache1"; + + /** Cache 2. */ + protected static final String cache2 = "cache2"; + + //Todo Cache with node filter. + protected static final String cache3 = "cache3"; + + protected static final String cache4 = "cache4"; + + protected static final String cache5 = "cache5"; + + /** Caches info. */ + public static final String CACHES_INFO = "cachesInfo"; + + /** Registered caches. */ + public static final String REGISTERED_CACHES = "registeredCaches"; + + /** Caches. */ + public static final String CACHES = "caches"; + + /** + * @param ig Ig. + */ + protected static Map cacheDescriptors(IgniteEx ig) { + return field(field(ig.context().cache(), CACHES_INFO), REGISTERED_CACHES); + } + + /** + * @param ig Ig. + */ + protected static Map caches(IgniteEx ig){ + return field(ig.context().cache(), CACHES); + } + + /** + * + */ + public abstract JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception; + + /** + * + */ + public abstract JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception; + + /** + * + */ + public abstract JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception; + + /** + * + */ + public abstract JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception; + + /** + * + */ + public abstract JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception; + + // Client node join. + + public abstract JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception; + + public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception; + + public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception; + + public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception; + + public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception; + + /** + * + */ + public abstract void testJoinWithOutConfiguration() throws Exception; + + /** + * + */ + public abstract void testStaticCacheConfigurationOnJoin() throws Exception; + + /** + * + */ + public abstract void testStaticCacheConfigurationInCluster() throws Exception; + + /** + * + */ + public abstract void testStaticCacheConfigurationSameOnBoth() throws Exception; + + /** + * + */ + public abstract void testStaticCacheConfigurationDifferentOnBoth() throws Exception; + + /** + * + */ + public abstract void testJoinClientWithOutConfiguration() throws Exception; + + /** + * + */ + public abstract void testJoinClientStaticCacheConfigurationOnJoin() throws Exception; + + /** + * + */ + public abstract void testJoinClientStaticCacheConfigurationInCluster() throws Exception; + + /** + * + */ + public abstract void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception; + + /** + * + */ + public abstract void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception; + + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @param idx Index. + */ + protected String name(int idx) { + return getTestIgniteInstanceName(idx); + } + + /** + * @param name Name. + */ + protected IgniteConfiguration cfg(String name) throws Exception { + try { + return getConfiguration(name); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * + */ + protected JoinNodeTestPlanBuilder builder() { + return JoinNodeTestPlanBuilder.builder(); + } + + /** + * @param cfgs Cfgs. + */ + protected static T[] buildConfiguration(T... cfgs) { + return cfgs; + } + + /** + * + */ + protected CacheConfiguration atomicCfg() { + return new CacheConfiguration(cache1) + .setAtomicityMode(CacheAtomicityMode.ATOMIC); + } + + /** + * + */ + protected CacheConfiguration transactionCfg() { + return new CacheConfiguration(cache2) + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + } + + /** + * + */ + protected CacheConfiguration[] allCacheConfigurations() { + return buildConfiguration(atomicCfg(), transactionCfg()); + } + + /** Set client. */ + protected final IgniteClosure setClient = + new IgniteClosure() { + @Override public IgniteConfiguration apply(IgniteConfiguration cfg) { + return cfg.setClientMode(true); + } + }; + + /** Ip finder. */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String name) throws Exception { + return super.getConfiguration(name) + .setDiscoverySpi( + new TcpDiscoverySpi() + .setIpFinder(ipFinder) + ); + } + + /** {@inheritDoc} */ + protected IgniteConfiguration persistentCfg(IgniteConfiguration cfg) throws Exception { + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + + return cfg; + } + + /** + * + */ + public static class JoinNodeTestPlanBuilder extends GridCommonAbstractTest { + /** String plan builder. */ + private final StringBuilder strPlanBuilder = new StringBuilder().append("**** Execution plan ****\n"); + + /** Nodes. */ + protected List nodes = new ArrayList<>(4); + + /** Cluster config. */ + private IgniteConfiguration[] clusterCfg; + + /** Node config. */ + private IgniteConfiguration nodeCfg; + + /** State default. */ + private static final Boolean stateDefault = new Boolean(true); + + /** State. */ + private Boolean state = stateDefault; + + /** Noop. */ + private static final Runnable Noop = new Runnable() { + @Override public void run() { + } + }; + + /** After cluster started. */ + private Runnable afterClusterStarted = Noop; + + /** After node join. */ + private Runnable afterNodeJoin = Noop; + + /** After activate. */ + private Runnable afterActivate = Noop; + + /** After de activate. */ + private Runnable afterDeActivate = Noop; + + private IgniteCallable> dynamicCacheStart = + new IgniteCallable>() { + @Override public List call() throws Exception { + return Arrays.asList(new CacheConfiguration(cache4), new CacheConfiguration(cache5)); + } + }; + + private IgniteCallable> dynamicCacheStop = + new IgniteCallable>() { + @Override public List call() throws Exception { + return Arrays.asList(cache4, cache5); + } + }; + + private Runnable afterDynamicCacheStarted = Noop; + + private Runnable afterDynamicCacheStopped = Noop; + + /** End. */ + private Runnable end = Noop; + + /** + * + */ + public JoinNodeTestPlanBuilder clusterConfiguration(IgniteConfiguration... cfgs) throws Exception { + clusterCfg = cfgs; + + strPlanBuilder.append("Start cluster:\n"); + + for (IgniteConfiguration cfg : cfgs) { + strPlanBuilder.append("node: ") + .append(cfg.getIgniteInstanceName()) + .append(" activeOnStart - ") + .append(cfg.isActiveOnStart()) + .append("\n"); + + CacheConfiguration[] ccfgs = cfg.getCacheConfiguration(); + + if (ccfgs != null) { + for (CacheConfiguration ccfg : ccfgs) + strPlanBuilder.append(" cache - ") + .append(ccfg.getName()) + .append("\n"); + } + } + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder nodeConfiguration(IgniteConfiguration cfg) { + nodeCfg = cfg; + + strPlanBuilder.append("Join node:\n") + .append(cfg.getIgniteInstanceName()) + .append(cfg.isClientMode() != null && cfg.isClientMode() ? " (client)" : "") + .append(" activeOnStart - ") + .append(cfg.isActiveOnStart()) + .append("\n"); + + CacheConfiguration[] ccfgs = cfg.getCacheConfiguration(); + + if (ccfgs != null) + for (CacheConfiguration ccfg : ccfgs) + strPlanBuilder.append(" cache - ").append(ccfg.getName()).append("\n"); + + return this; + } + + /** + * @param func Func. + */ + public JoinNodeTestPlanBuilder nodeConfiguration( + IgniteClosure func + ) { + + nodeCfg = func.apply(nodeCfg); + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder afterClusterStarted(Runnable r) { + strPlanBuilder.append("Check after cluster start\n"); + + afterClusterStarted = r; + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder afterNodeJoin(Runnable r) { + strPlanBuilder.append("Check after node join") + .append("\n"); + + afterNodeJoin = r; + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder stateAfterJoin(boolean state) { + strPlanBuilder.append("Check state on all nodes after join, must be ") + .append(state ? "<>" : "<>") + .append(" \n"); + + this.state = state; + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder afterActivate(Runnable r) { + strPlanBuilder.append("Check after activate") + .append("\n"); + + afterActivate = r; + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder afterDeActivate(Runnable r) { + strPlanBuilder.append("Check after deActivate") + .append("\n"); + + afterDeActivate = r; + + return this; + } + + public JoinNodeTestPlanBuilder dynamicCacheStart(IgniteCallable> caches){ + strPlanBuilder.append("Dynamic caches start") + .append("\n"); + + dynamicCacheStart = caches; + + return this; + } + + public JoinNodeTestPlanBuilder afterDynamicCacheStarted(Runnable r){ + strPlanBuilder.append("Check after dynamic caches start") + .append("\n"); + + afterDynamicCacheStarted = r; + + return this; + } + + public JoinNodeTestPlanBuilder dynamicCacheStop(IgniteCallable> caches){ + strPlanBuilder.append("Dynamic caches stop") + .append("\n"); + + dynamicCacheStop = caches; + + return this; + } + + public JoinNodeTestPlanBuilder afterDynamicCacheStopped(Runnable r){ + strPlanBuilder.append("Check after dynamic caches stop") + .append("\n"); + + afterDynamicCacheStopped = r; + + return this; + } + + /** + * @param end End. + */ + public JoinNodeTestPlanBuilder setEnd(Runnable end) { + strPlanBuilder.append("Check before stop") + .append("\n"); + + this.end = end; + + return this; + } + + /** + * + */ + public void execute() throws Exception { + try { + if (state == stateDefault) + fail("State after join must be specific. See JoinNodeTestPlanBuilder.stateAfterJoin(boolean)."); + + System.out.println(strPlanBuilder.append("********************").toString()); + + IgniteConfiguration[] cfgs = clusterCfg; + + System.out.println(">>> Start cluster"); + + for (IgniteConfiguration cfg : cfgs) { + startGrid(cfg); + + nodes.add(cfg.getIgniteInstanceName()); + } + + System.out.println(">>> Check after cluster started"); + + afterClusterStarted.run(); + + System.out.println(">>> Start new node"); + + startGrid(nodeCfg); + + nodes.add(nodeCfg.getIgniteInstanceName()); + + System.out.println(">>> Check after new node join in cluster"); + + afterNodeJoin.run(); + + System.out.println(">>> Check cluster state on all nodes"); + + IgniteEx crd = grid(nodes.get(0)); + + for (IgniteEx ig : grids()) + assertEquals((boolean)state, ig.active()); + + if (!state) { + System.out.println(">>> Activate cluster"); + + crd.active(true); + + System.out.println(">>> Check after cluster activated"); + + afterActivate.run(); + } + else { + System.out.println(">>> DeActivate cluster"); + + crd.active(false); + + System.out.println(">>> Check after cluster deActivated"); + + afterDeActivate.run(); + + System.out.println(">>> Activate cluster"); + + crd.active(true); + } + + AffinityTopologyVersion next0Ver = nextMinorVersion(crd); + + crd.createCaches(dynamicCacheStart.call()); + + awaitTopologyVersion(next0Ver); + + afterDynamicCacheStarted.run(); + + onAllNode(new CI1() { + @Override public void apply(IgniteEx ig) { + if (ig.context().discovery().localNode().isClient()) + return; + + Assert.assertNotNull(ig.context().cache().cache(cache4)); + Assert.assertNotNull(ig.context().cache().cache(cache5)); + + } + }); + + AffinityTopologyVersion next1Ver = nextMinorVersion(crd); + + crd.destroyCaches(dynamicCacheStop.call()); + + afterDynamicCacheStopped.run(); + + awaitTopologyVersion(next1Ver); + + onAllNode(new CI1() { + @Override public void apply(IgniteEx ig) { + if (ig.context().discovery().localNode().isClient()) + return; + + Assert.assertNull(ig.context().cache().cache(cache4)); + Assert.assertNull(ig.context().cache().cache(cache5)); + + } + }); + + System.out.println(">>> Finish check"); + + end.run(); + } + finally { + stopAllGrids(); + } + } + + private AffinityTopologyVersion nextMinorVersion(IgniteEx ig){ + AffinityTopologyVersion cur = ig.context().discovery().topologyVersionEx(); + + return new AffinityTopologyVersion(cur.topologyVersion(), cur.minorTopologyVersion() + 1); + } + + private void awaitTopologyVersion(final AffinityTopologyVersion ver){ + onAllNode(new CI1() { + @Override public void apply(IgniteEx ig) { + while (true) { + AffinityTopologyVersion locTopVer = ig.context().cache().context() + .exchange().readyAffinityVersion(); + + if (locTopVer.compareTo(ver) < 0){ + System.out.println("Top ready " + locTopVer + " on " + ig.localNode().id()); + + try { + Thread.sleep(100); + } + catch (InterruptedException e) { + break; + } + } + else + break; + } + } + }).run(); + + } + + /** + * + */ + protected List grids() { + List res = new ArrayList<>(); + + for (String name : nodes) + res.add(grid(name)); + + return res; + } + + /** + * + */ + public static JoinNodeTestPlanBuilder builder() { + return new JoinNodeTestPlanBuilder(); + } + + /** + * + */ + public Runnable checkCacheOnlySystem() { + return onAllNode(new IgniteInClosure() { + @Override public void apply(IgniteEx ig) { + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(2, desc.size()); + + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + Assert.assertEquals(2, caches.size()); + } + }); + } + + /** + * + */ + public Runnable checkCacheEmpty() { + return onAllNode(new IgniteInClosure() { + @Override public void apply(IgniteEx ig) { + Map desc = cacheDescriptors(ig); + + Assert.assertTrue(desc.isEmpty()); + + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + Assert.assertEquals(0, caches.size()); + } + }); + } + + /** + * + */ + public Runnable checkCacheNotEmpty() { + return onAllNode(new IgniteInClosure() { + @Override public void apply(IgniteEx ig) { + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + }); + } + + /** + * @param cls Closure. + */ + private Runnable onAllNode(final IgniteInClosure cls) { + return new Runnable() { + @Override public void run() { + for (IgniteEx ig : grids()) { + try { + cls.apply(ig); + } + catch (AssertionError e) { + System.out.println("Assertion on " + ig.name()); + + throw e; + } + } + } + }; + } + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java index f392e6bad7289..5bc5c3ae25f13 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java @@ -344,8 +344,8 @@ private void stopAll(String suffix) { memCfg.setConcurrencyLevel(64); MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration(); - memPlcCfg.setInitialSize(5 * 1024 * 1024); - memPlcCfg.setMaxSize(5 * 1024 * 1024); + memPlcCfg.setInitialSize(20 * 1024 * 1024); + memPlcCfg.setMaxSize(20 * 1024 * 1024); memPlcCfg.setName("dfltMemPlc"); memCfg.setMemoryPolicies(memPlcCfg); diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteStandByClusterTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteStandByClusterTest.java new file mode 100644 index 0000000000000..b248208b08319 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteStandByClusterTest.java @@ -0,0 +1,213 @@ +/* + * 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.cache.database.standbycluster; + +import java.util.Arrays; +import java.util.Map; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; +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; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Assert; + +/** + * + */ +public class IgniteStandByClusterTest extends GridCommonAbstractTest { + private static final TcpDiscoveryIpFinder vmIpFinder = new TcpDiscoveryVmIpFinder(true); + + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(vmIpFinder)); + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setConsistentId(igniteInstanceName); + + return cfg; + } + + public void testNotStartDynamicCachesOnClientAfterActivation() throws Exception { + final String cacheName0 = "cache0"; + final String cacheName = "cache"; + + IgniteConfiguration cfg1 = getConfiguration("serv1"); + IgniteConfiguration cfg2 = getConfiguration("serv2"); + + IgniteConfiguration cfg3 = getConfiguration("client"); + cfg3.setCacheConfiguration(new CacheConfiguration(cacheName0)); + + cfg3.setClientMode(true); + + IgniteEx ig1 = startGrid(cfg1); + IgniteEx ig2 = startGrid(cfg2); + IgniteEx ig3 = startGrid(cfg3); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + ig3.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + ig3.createCache(new CacheConfiguration<>(cacheName)); + + assertNotNull(ig3.cache(cacheName)); + assertNotNull(ig1.cache(cacheName)); + assertNotNull(ig2.cache(cacheName)); + + assertNotNull(ig1.cache(cacheName0)); + assertNotNull(ig3.cache(cacheName0)); + assertNotNull(ig2.cache(cacheName0)); + + ig3.active(false); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + ig3.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + assertNotNull(ig1.cache(cacheName)); + assertNotNull(ig2.cache(cacheName)); + + Map> caches = U.field(ig3.context().cache(), "caches"); + + // Only system caches and cache0 + assertTrue(caches.size() == 3); + + assertNull(caches.get(cacheName)); + + assertNotNull(caches.get(cacheName0)); + + assertNotNull(ig3.cache(cacheName)); + } + + public void testStaticCacheStartAfterActivationWithCacheFilter() throws Exception { + String cache1 = "cache1"; + String cache2 = "cache2"; + String cache3 = "cache3"; + + IgniteConfiguration cfg1 = getConfiguration("node1"); + + cfg1.setCacheConfiguration( + new CacheConfiguration(cache1).setNodeFilter(new NodeFilterIgnoreByName("node2"))); + + IgniteConfiguration cfg2 = getConfiguration("node2"); + + cfg2.setCacheConfiguration( + new CacheConfiguration(cache2).setNodeFilter(new NodeFilterIgnoreByName("node3"))); + + IgniteConfiguration cfg3 = getConfiguration("node3"); + + cfg3.setCacheConfiguration( + new CacheConfiguration(cache3).setNodeFilter(new NodeFilterIgnoreByName("node1"))); + + IgniteEx ig1 = startGrid(cfg1); + IgniteEx ig2 = startGrid(cfg2); + IgniteEx ig3 = startGrid(cfg3); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + for (IgniteEx ig: Arrays.asList(ig1,ig2,ig3)){ + Map desc = U.field(U.field(ig.context().cache(), "cachesInfo"), "registeredCaches"); + + assertEquals(0, desc.size()); + } + + ig3.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + for (IgniteEx ig: Arrays.asList(ig1,ig2,ig3)){ + Map desc = U.field( + U.field(ig.context().cache(), "cachesInfo"), "registeredCaches"); + + assertEquals(5, desc.size()); + + Map> caches = U.field(ig.context().cache(), "caches"); + + assertEquals(4, caches.keySet().size()); + } + + Map> caches1 = U.field(ig1.context().cache(), "caches"); + + Assert.assertNotNull(caches1.get(cache1)); + Assert.assertNotNull(caches1.get(cache2)); + Assert.assertNull(caches1.get(cache3)); + + Map> caches2 = U.field(ig2.context().cache(), "caches"); + + Assert.assertNull(caches2.get(cache1)); + Assert.assertNotNull(caches2.get(cache2)); + Assert.assertNotNull(caches2.get(cache3)); + + Map> caches3 = U.field(ig3.context().cache(), "caches"); + + Assert.assertNotNull(caches3.get(cache1)); + Assert.assertNull(caches3.get(cache2)); + Assert.assertNotNull(caches3.get(cache3)); + } + + private static class NodeFilterIgnoreByName implements IgnitePredicate{ + private final String name; + + private NodeFilterIgnoreByName(String name) { + this.name = name; + } + + @Override public boolean apply(ClusterNode node) { + return !name.equals(node.consistentId()); + } + } + + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); + } + + @Override protected void afterTest() throws Exception { + super.beforeTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToActiveCluster.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToActiveCluster.java new file mode 100644 index 0000000000000..6042267aa4080 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToActiveCluster.java @@ -0,0 +1,431 @@ +/* + * 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.cache.database.standbycluster.join; + +import java.util.Map; +import org.apache.ignite.cache.database.standbycluster.AbstractNodeJoinTemplate; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; +import org.junit.Assert; + +/** + * + */ +public class JoinActiveNodeToActiveCluster extends AbstractNodeJoinTemplate { + /** + * + */ + @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(true), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheOnlySystem() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(true) + ).afterNodeJoin( + b.checkCacheOnlySystem() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheOnlySystem() + ); + + return b; + } + + /** + * + */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(true), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheOnlySystem() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** + * + */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheNotEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** + * + */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheNotEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** + * + */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(atomicCfg()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(3, desc.size()); + + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + Assert.assertEquals(3, caches.size()); + } + } + } + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(transactionCfg()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + // Server node join. + + /** {@inheritDoc} */ + @Override public void testJoinWithOutConfiguration() throws Exception { + withOutConfigurationTemplate().execute(); + } + + /** + * + */ + @Override public void testStaticCacheConfigurationOnJoin() throws Exception { + staticCacheConfigurationOnJoinTemplate().execute(); + } + + /** + * + */ + @Override public void testStaticCacheConfigurationInCluster() throws Exception { + staticCacheConfigurationInClusterTemplate().execute(); + } + + /** + * + */ + @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { + staticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** + * + */ + @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { + staticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + // Client node join. + + /** + * + */ + @Override public void testJoinClientWithOutConfiguration() throws Exception { + joinClientWithOutConfigurationTemplate().execute(); + } + + /** + * + */ + @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { + joinClientStaticCacheConfigurationOnJoinTemplate().execute(); + } + + /** + * + */ + @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { + joinClientStaticCacheConfigurationInClusterTemplate().execute(); + } + + /** + * + */ + @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { + joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** + * + */ + @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { + joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + return withOutConfigurationTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { + return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { + return staticCacheConfigurationInClusterTemplate() + .nodeConfiguration(setClient) + .afterActivate(new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }).afterNodeJoin( + new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }).setEnd(new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }); + } + + @Override + public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return staticCacheConfigurationDifferentOnBothTemplate() + .nodeConfiguration(setClient) + .afterActivate(new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }) + .afterNodeJoin(new Runnable() { + @Override public void run() { + for (int i = 0; i < 4; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertNotNull(ig.context().cache().cache(cache1)); + + Assert.assertNotNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertEquals(4, caches.size()); + else + Assert.assertEquals(3, caches.size()); + } + } + }) + .setEnd(new Runnable() { + @Override public void run() { + for (int i = 0; i < 4; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertNotNull(ig.context().cache().cache(cache1)); + + Assert.assertNotNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertEquals(4, caches.size()); + else + Assert.assertEquals(3, caches.size()); + } + } + }); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { + return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToInActiveCluster.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToInActiveCluster.java new file mode 100644 index 0000000000000..62ab114f1046f --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToInActiveCluster.java @@ -0,0 +1,227 @@ +/* + * 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.cache.database.standbycluster.join; + +import org.apache.ignite.cache.database.standbycluster.AbstractNodeJoinTemplate; + +/** + * + */ +public class JoinActiveNodeToInActiveCluster extends AbstractNodeJoinTemplate { + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(false), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheOnlySystem() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(false), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(true) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(atomicCfg()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(transactionCfg()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + // Server node join. + + /** {@inheritDoc} */ + @Override public void testJoinWithOutConfiguration() throws Exception { + withOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationOnJoin() throws Exception { + staticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationInCluster() throws Exception { + staticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { + staticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { + staticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + // Client node join. + + /** {@inheritDoc} */ + @Override public void testJoinClientWithOutConfiguration() throws Exception { + joinClientWithOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { + joinClientStaticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { + joinClientStaticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { + joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { + joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + return withOutConfigurationTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { + return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { + return staticCacheConfigurationInClusterTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return staticCacheConfigurationDifferentOnBothTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { + return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); + } + +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToActiveCluster.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToActiveCluster.java new file mode 100644 index 0000000000000..d0cc7b39cbeba --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToActiveCluster.java @@ -0,0 +1,356 @@ +/* + * 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.cache.database.standbycluster.join; + +import java.util.Map; +import org.apache.ignite.cache.database.standbycluster.AbstractNodeJoinTemplate; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; +import org.junit.Assert; + +/** + * + */ +public class JoinInActiveNodeToActiveCluster extends AbstractNodeJoinTemplate { + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(true), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheOnlySystem() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(false) + ).afterNodeJoin( + b.checkCacheOnlySystem() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheOnlySystem() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(true), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheOnlySystem() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheNotEmpty() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(false) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheNotEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(atomicCfg()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(3, desc.size()); + + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + Assert.assertEquals(3, caches.size()); + } + } + } + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(transactionCfg()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + // Server node join. + + /** {@inheritDoc} */ + @Override public void testJoinWithOutConfiguration() throws Exception { + withOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationOnJoin() throws Exception { + staticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationInCluster() throws Exception { + staticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { + staticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { + staticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + // Client node join. + + /** {@inheritDoc} */ + @Override public void testJoinClientWithOutConfiguration() throws Exception { + joinClientWithOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { + joinClientStaticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { + joinClientStaticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { + joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { + joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + return withOutConfigurationTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { + return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { + return staticCacheConfigurationInClusterTemplate() + .nodeConfiguration(setClient) + .afterNodeJoin(new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }).setEnd(new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { + return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return staticCacheConfigurationDifferentOnBothTemplate() + .nodeConfiguration(setClient) + .afterNodeJoin( + new Runnable() { + @Override public void run() { + for (int i = 0; i < 4; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertNotNull(ig.context().cache().cache(cache1)); + + Assert.assertNotNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertEquals(4, caches.size()); + else + Assert.assertEquals(3, caches.size()); + } + } + } + ).setEnd( + new Runnable() { + @Override public void run() { + for (int i = 0; i < 4; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertNotNull(ig.context().cache().cache(cache1)); + + Assert.assertNotNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertEquals(4, caches.size()); + else + Assert.assertEquals(3, caches.size()); + } + } + } + ); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToInActiveCluster.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToInActiveCluster.java new file mode 100644 index 0000000000000..7333c2e860a7b --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToInActiveCluster.java @@ -0,0 +1,226 @@ +/* + * 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.cache.database.standbycluster.join; + +import org.apache.ignite.cache.database.standbycluster.AbstractNodeJoinTemplate; + +/** + * + */ +public class JoinInActiveNodeToInActiveCluster extends AbstractNodeJoinTemplate { + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(false), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(false) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheOnlySystem() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(false), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(false) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(transactionCfg()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(atomicCfg()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + // Server node join. + + /** {@inheritDoc} */ + @Override public void testJoinWithOutConfiguration() throws Exception { + withOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationOnJoin() throws Exception { + staticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationInCluster() throws Exception { + staticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { + staticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { + staticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + // Client node join. + + /** {@inheritDoc} */ + @Override public void testJoinClientWithOutConfiguration() throws Exception { + joinClientWithOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { + joinClientStaticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { + joinClientStaticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { + joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { + joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + return withOutConfigurationTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { + return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { + return staticCacheConfigurationInClusterTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { + return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return staticCacheConfigurationDifferentOnBothTemplate().nodeConfiguration(setClient); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java new file mode 100644 index 0000000000000..fc4b5ce2aaf78 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java @@ -0,0 +1,97 @@ +/* + * 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.cache.database.standbycluster.join.persistence; + +import org.apache.ignite.cache.database.standbycluster.join.JoinActiveNodeToActiveCluster; +import org.apache.ignite.configuration.IgniteConfiguration; + +/** + * + */ +public class JoinActiveNodeToActiveClusterWithPersistence extends JoinActiveNodeToActiveCluster { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration cfg(String name) throws Exception { + return persistentCfg(super.cfg(name)); + } + + private JoinNodeTestPlanBuilder persistent(JoinNodeTestPlanBuilder b) { + b.afterClusterStarted( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterNodeJoin( + b.checkCacheEmpty() + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = persistent(super.withOutConfigurationTemplate()); + + b.afterActivate(b.checkCacheOnlySystem()); + + return b; + } + + @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = persistent(super.joinClientWithOutConfigurationTemplate()); + + b.afterActivate(b.checkCacheOnlySystem()); + + return b; + } + + @Override public void testJoinWithOutConfiguration() throws Exception { + withOutConfigurationTemplate().execute(); + } + + @Override public void testJoinClientWithOutConfiguration() throws Exception { + joinClientWithOutConfigurationTemplate().execute(); + } + + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + return persistent(super.staticCacheConfigurationOnJoinTemplate()); + } + + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + return persistent(super.staticCacheConfigurationInClusterTemplate()); + } + + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + return persistent(super.staticCacheConfigurationSameOnBothTemplate()); + } + + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return persistent(super.staticCacheConfigurationDifferentOnBothTemplate()); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { + return persistent(super.joinClientStaticCacheConfigurationOnJoinTemplate()); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { + return persistent(super.joinClientStaticCacheConfigurationInClusterTemplate()); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return persistent(super.joinClientStaticCacheConfigurationDifferentOnBothTemplate()); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java new file mode 100644 index 0000000000000..9981322b61f2b --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java @@ -0,0 +1,31 @@ +/* + * 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.cache.database.standbycluster.join.persistence; + +import org.apache.ignite.cache.database.standbycluster.join.JoinActiveNodeToInActiveCluster; +import org.apache.ignite.configuration.IgniteConfiguration; + +/** + * + */ +public class JoinActiveNodeToInActiveClusterWithPersistence extends JoinActiveNodeToInActiveCluster { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration cfg(String name) throws Exception { + return persistentCfg(super.cfg(name)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java new file mode 100644 index 0000000000000..4731647bbef88 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java @@ -0,0 +1,85 @@ +/* + * 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.cache.database.standbycluster.join.persistence; + +import org.apache.ignite.cache.database.standbycluster.join.JoinInActiveNodeToActiveCluster; +import org.apache.ignite.configuration.IgniteConfiguration; + +/** + * + */ +public class JoinInActiveNodeToActiveClusterWithPersistence extends JoinInActiveNodeToActiveCluster { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration cfg(String name) throws Exception { + return persistentCfg(super.cfg(name)); + } + + private JoinNodeTestPlanBuilder persistent(JoinNodeTestPlanBuilder b) { + b.afterClusterStarted( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterNodeJoin( + b.checkCacheEmpty() + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = persistent(super.withOutConfigurationTemplate()); + + b.afterActivate(b.checkCacheOnlySystem()); + + return b; + } + + @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = persistent(super.joinClientWithOutConfigurationTemplate()); + + b.afterActivate(b.checkCacheOnlySystem()); + + return b; + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception{ + return persistent(super.joinClientStaticCacheConfigurationInClusterTemplate()); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return persistent(super.joinClientStaticCacheConfigurationDifferentOnBothTemplate()); + } + + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + return persistent(super.staticCacheConfigurationOnJoinTemplate()); + } + + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + return persistent(super.staticCacheConfigurationInClusterTemplate()); + } + + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + return persistent(super.staticCacheConfigurationSameOnBothTemplate()); + } + + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return persistent(super.staticCacheConfigurationDifferentOnBothTemplate()); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java new file mode 100644 index 0000000000000..01154b154e1d2 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java @@ -0,0 +1,31 @@ +/* + * 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.cache.database.standbycluster.join.persistence; + +import org.apache.ignite.cache.database.standbycluster.join.JoinInActiveNodeToInActiveCluster; +import org.apache.ignite.configuration.IgniteConfiguration; + +/** + * + */ +public class JoinInActiveNodeToInActiveClusterWithPersistence extends JoinInActiveNodeToInActiveCluster { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration cfg(String name) throws Exception { + return persistentCfg(super.cfg(name)); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java new file mode 100644 index 0000000000000..e5f34f84f1862 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java @@ -0,0 +1,336 @@ +/* + * 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.cache.database.standbycluster.reconnect; + +import com.google.common.collect.Sets; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.events.Event; +import org.apache.ignite.events.EventType; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage; +import org.apache.ignite.spi.discovery.DiscoverySpiListener; +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.jetbrains.annotations.Nullable; +import org.junit.Assert; + +import static org.apache.ignite.events.EventType.EVT_CLIENT_NODE_DISCONNECTED; + +/** + * + */ +public abstract class IgniteAbstractStandByClientReconnectTest extends GridCommonAbstractTest { + + private static final TcpDiscoveryVmIpFinder vmIpFinder = new TcpDiscoveryVmIpFinder(true); + + private static final TcpDiscoveryVmIpFinder clientIpFinder = new TcpDiscoveryVmIpFinder(true); + + protected final String node1 = "node1"; + protected final String node2 = "node2"; + protected final String nodeClient = "nodeClient"; + + protected final String ccfg1staticName = "cache1static"; + protected final String ccfg2staticName = "cache2static"; + protected final String ccfg3staticName = "cache3static"; + + protected final String ccfg1staticWithFilterName = "ccfg1staticWithFilter"; + protected final String ccfg2staticWithFilterName = "ccfg2staticWithFilter"; + protected final String ccfg3staticWithFilterName = "ccfg3staticWithFilter"; + + protected final String ccfgDynamicName = "ccfgDynamic"; + protected final String ccfgDynamicWithFilterName = "ccfgDynamicWithFilter"; + + protected final CacheConfiguration ccfg1static = new CacheConfiguration(ccfg1staticName); + protected final CacheConfiguration ccfg2static = new CacheConfiguration(ccfg2staticName); + protected final CacheConfiguration ccfg3static = new CacheConfiguration(ccfg3staticName); + + protected final CacheConfiguration ccfg1staticWithFilter = + new CacheConfiguration(ccfg1staticWithFilterName).setNodeFilter(new FilterNode(node2)); + + protected final CacheConfiguration ccfg2staticWithFilter = + new CacheConfiguration(ccfg2staticWithFilterName).setNodeFilter(new FilterNode(nodeClient)); + + protected final CacheConfiguration ccfg3staticWithFilter = + new CacheConfiguration(ccfg3staticWithFilterName).setNodeFilter(new FilterNode(node1)); + + protected final CacheConfiguration ccfgDynamic = new CacheConfiguration(ccfgDynamicName); + + protected final CacheConfiguration ccfgDynamicWithFilter = + new CacheConfiguration(ccfgDynamicWithFilterName).setNodeFilter(new FilterNode(node2)); + + protected final Set staticCacheNames = Sets.newHashSet( + ccfg1staticName, ccfg2staticName, ccfg3staticName, + ccfg1staticWithFilterName, ccfg2staticWithFilterName, ccfg3staticWithFilterName + ); + + protected final Set allCacheNames = Sets.newHashSet( + ccfg1staticName, ccfg2staticName, ccfg3staticName, + ccfg1staticWithFilterName, ccfg2staticWithFilterName, ccfg3staticWithFilterName, + ccfgDynamicName, ccfgDynamicWithFilterName + ); + + @Override protected IgniteConfiguration getConfiguration(String name) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(name); + + if (!nodeClient.equals(name)) + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(vmIpFinder)); + else { + clientIpFinder.setAddresses(Collections.singletonList("127.0.0.1:47501")); + + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(clientIpFinder)); + } + + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setConsistentId(name); + + return cfg; + } + + protected void addDisconnectListener( + final CountDownLatch disconnectedLatch, + final CountDownLatch reconnectedLatch + ) { + grid(nodeClient).events().localListen(new IgnitePredicate() { + @Override public boolean apply(Event event) { + switch (event.type()) { + case EventType.EVT_CLIENT_NODE_DISCONNECTED: + info("Client disconnected"); + + disconnectedLatch.countDown(); + + break; + case EventType.EVT_CLIENT_NODE_RECONNECTED: + info("Client reconnected"); + + reconnectedLatch.countDown(); + } + + return true; + } + }, EventType.EVT_CLIENT_NODE_DISCONNECTED, EventType.EVT_CLIENT_NODE_RECONNECTED); + } + + protected void checkDescriptors(IgniteEx ig, Set cacheNames) { + Collection descs = ig.context().cache().cacheDescriptors().values(); + + assertEquals("Node name: " + ig.name(), cacheNames.size() + 2, descs.size()); + + int systemCnt = 0; + + for (DynamicCacheDescriptor desc : descs) + if (!CU.isSystemCache(desc.cacheName())) + assertTrue(desc.cacheName(), cacheNames.contains(desc.cacheName())); + else + systemCnt++; + + assertEquals(2, systemCnt); + } + + protected void startNodes(CountDownLatch activateLatch) throws Exception { + IgniteConfiguration cfg1 = getConfiguration(node1) + .setCacheConfiguration(ccfg1static, ccfg1staticWithFilter); + + IgniteConfiguration cfg2 = getConfiguration(node2) + .setCacheConfiguration(ccfg2static, ccfg2staticWithFilter); + + IgniteConfiguration cfg3 = getConfiguration(nodeClient) + .setCacheConfiguration(ccfg3static, ccfg3staticWithFilter); + + if (activateLatch != null) + cfg3.setDiscoverySpi( + new AwaitTcpDiscoverySpi(activateLatch) + .setIpFinder(clientIpFinder) + ); + + cfg3.setClientMode(true); + + IgniteEx ig1 = startGrid(cfg1); + IgniteEx ig2 = startGrid(cfg2); + IgniteEx client = startGrid(cfg3); + } + + protected void checkStaticCaches() { + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + Assert.assertNotNull(ig1.cache(ccfg1staticName)); + Assert.assertNotNull(ig1.cache(ccfg2staticName)); + Assert.assertNotNull(ig1.cache(ccfg3staticName)); + + Assert.assertNotNull(ig1.cache(ccfg1staticWithFilterName)); + Assert.assertNotNull(ig1.cache(ccfg2staticWithFilterName)); + + Assert.assertNotNull(ig2.cache(ccfg1staticName)); + Assert.assertNotNull(ig2.cache(ccfg2staticName)); + Assert.assertNotNull(ig2.cache(ccfg3staticName)); + + Assert.assertNotNull(ig2.cache(ccfg3staticWithFilterName)); + Assert.assertNotNull(ig2.cache(ccfg2staticWithFilterName)); + + Assert.assertNotNull(client.cache(ccfg1staticName)); + Assert.assertNotNull(client.cache(ccfg2staticName)); + Assert.assertNotNull(client.cache(ccfg3staticName)); + + Assert.assertNotNull(client.cache(ccfg3staticWithFilterName)); + Assert.assertNotNull(client.cache(ccfg1staticWithFilterName)); + } + + protected void checkAllCaches() { + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + checkStaticCaches(); + + Assert.assertNotNull(ig1.cache(ccfgDynamicName)); + Assert.assertNotNull(ig1.cache(ccfgDynamicWithFilterName)); + + Assert.assertNotNull(ig2.cache(ccfgDynamicName)); + + Assert.assertNotNull(client.cache(ccfgDynamicName)); + Assert.assertNotNull(client.cache(ccfgDynamicWithFilterName)); + } + + protected void checkOnlySystemCaches() { + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + Assert.assertNull(ig1.cache(ccfg1staticName)); + Assert.assertNull(ig1.cache(ccfg2staticName)); + Assert.assertNull(ig1.cache(ccfg3staticName)); + + Assert.assertNull(ig1.cache(ccfg1staticWithFilterName)); + Assert.assertNull(ig1.cache(ccfg2staticWithFilterName)); + + Assert.assertNull(ig2.cache(ccfg1staticName)); + Assert.assertNull(ig2.cache(ccfg2staticName)); + Assert.assertNull(ig2.cache(ccfg3staticName)); + + Assert.assertNull(ig2.cache(ccfg3staticWithFilterName)); + Assert.assertNull(ig2.cache(ccfg2staticWithFilterName)); + + Assert.assertNull(client.cache(ccfg1staticName)); + Assert.assertNull(client.cache(ccfg2staticName)); + Assert.assertNull(client.cache(ccfg3staticName)); + + Assert.assertNull(client.cache(ccfg3staticWithFilterName)); + Assert.assertNull(client.cache(ccfg1staticWithFilterName)); + + checkDescriptors(ig1,Collections.emptySet()); + checkDescriptors(ig2,Collections.emptySet()); + checkDescriptors(client, Collections.emptySet()); + } + + private static class FilterNode implements IgnitePredicate { + + private final String consistentId; + + private FilterNode(String id) { + consistentId = id; + } + + @Override public boolean apply(ClusterNode node) { + return !consistentId.equals(node.consistentId()); + } + } + + private static class AwaitTcpDiscoverySpi extends TcpDiscoverySpi { + + private final CountDownLatch latch; + + private AwaitTcpDiscoverySpi(CountDownLatch latch) { + this.latch = latch; + } + + @Override public void setListener(@Nullable DiscoverySpiListener lsnr) { + super.setListener(new AwaitDiscoverySpiListener(latch, lsnr)); + } + } + + private static class AwaitDiscoverySpiListener implements DiscoverySpiListener { + + private final CountDownLatch latch; + + private final DiscoverySpiListener delegate; + + private AwaitDiscoverySpiListener( + CountDownLatch latch, + DiscoverySpiListener delegate + ) { + this.latch = latch; + this.delegate = delegate; + } + + @Override public void onLocalNodeInitialized(ClusterNode locNode) { + delegate.onLocalNodeInitialized(locNode); + } + + @Override public void onDiscovery( + int type, + long topVer, + ClusterNode node, + Collection topSnapshot, + @Nullable Map> topHist, + @Nullable DiscoverySpiCustomMessage data + ) { + delegate.onDiscovery(type, topVer, node, topSnapshot, topHist, data); + + if (type == EVT_CLIENT_NODE_DISCONNECTED) + try { + System.out.println("Await cluster change state"); + + latch.await(); + } + catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); + } + + @Override protected void afterTest() throws Exception { + super.beforeTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); + } + +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectTest.java new file mode 100644 index 0000000000000..1266f8940c114 --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectTest.java @@ -0,0 +1,283 @@ +/* + * 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.cache.database.standbycluster.reconnect; + +import java.util.concurrent.CountDownLatch; +import org.apache.ignite.internal.IgniteEx; + +/** + * + */ +public class IgniteStandByClientReconnectTest extends IgniteAbstractStandByClientReconnectTest { + + public void testActiveClientReconnectToActiveCluster() throws Exception { + CountDownLatch activateLatch = new CountDownLatch(1); + + startNodes(activateLatch); + + info(">>>> star grid"); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + client.active(true); + + info(">>>> activate grid"); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + checkDescriptors(client, staticCacheNames); + + checkStaticCaches(); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + info(">>>> stop servers"); + + stopGrid(node2); + + disconnectedLatch.await(); + + ig2 = startGrid(getConfiguration(node2)); + + info(">>>> activate new servers"); + + ig1.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + + activateLatch.countDown(); + + info(">>>> reconnect client"); + + reconnectedLatch.await(); + + info(">>>> client reconnected"); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + checkAllCaches(); + } + + public void testActiveClientReconnectToInActiveCluster() throws Exception { + CountDownLatch activateLatch = new CountDownLatch(1); + + startNodes(activateLatch); + + info(">>>> star grid"); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + info(">>>> activate grid"); + + client.active(true); + + checkStaticCaches(); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + checkDescriptors(client, staticCacheNames); + + info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + info(">>>> stop " + node2); + + stopGrid(node2); + + disconnectedLatch.await(); + + ig1.active(false); + + activateLatch.countDown(); + + info(">>>> restart " + node2); + + ig2 = startGrid(getConfiguration(node2)); + + reconnectedLatch.await(); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + client.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + checkAllCaches(); + } + + public void testInActiveClientReconnectToActiveCluster() throws Exception { + CountDownLatch activateLatch = new CountDownLatch(1); + + startNodes(activateLatch); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + stopGrid(node2); + + disconnectedLatch.await(); + + ig2 = startGrid(getConfiguration(node2)); + + ig1.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + + activateLatch.countDown(); + + reconnectedLatch.await(); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + checkAllCaches(); + } + + public void testInActiveClientReconnectToInActiveCluster() throws Exception { + startNodes(null); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + stopGrid(node2); + + disconnectedLatch.await(); + + ig2 = startGrid(getConfiguration(node2)); + + reconnectedLatch.await(); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + client.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkStaticCaches(); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + checkAllCaches(); + } +} diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java new file mode 100644 index 0000000000000..d0933feed81ff --- /dev/null +++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java @@ -0,0 +1,289 @@ +/* + * 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.cache.database.standbycluster.reconnect; + +import com.google.common.collect.Sets; +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import org.apache.ignite.internal.IgniteEx; + +/** + * + */ +public class IgniteStandByClientReconnectToNewClusterTest extends IgniteAbstractStandByClientReconnectTest { + + public void testActiveClientReconnectToActiveCluster() throws Exception { + CountDownLatch activateLatch = new CountDownLatch(1); + + startNodes(activateLatch); + + info(">>>> star grid"); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + info(">>>> activate grid"); + + client.active(true); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + checkDescriptors(client, staticCacheNames); + + checkStaticCaches(); + + info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + info(">>>> stop servers"); + + stopGrid(node1); + stopGrid(node2); + + disconnectedLatch.await(); + + ig1 = startGrid(getConfiguration(node1)); + ig2 = startGrid(getConfiguration(node2)); + + info(">>>> activate new servers"); + + ig1.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + + activateLatch.countDown(); + + info(">>>> reconnect client"); + + reconnectedLatch.await(); + + info(">>>> client reconnected"); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkAllCaches(); + } + + public void testActiveClientReconnectToInActiveCluster() throws Exception { + startNodes(null); + + info(">>>> star grid"); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + info(">>>> activate grid"); + + client.active(true); + + checkStaticCaches(); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + checkDescriptors(client, staticCacheNames); + + info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + info(">>>> stop servers"); + + stopGrid(node1); + stopGrid(node2); + + assertTrue(client.active()); + + System.out.println("Await disconnected"); + + disconnectedLatch.await(); + + ig1 = startGrid(getConfiguration("node1")); + ig2 = startGrid(getConfiguration("node2")); + + info(">>>> reconnect client"); + + reconnectedLatch.await(); + + info(">>>> client reconnected"); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + info(">>>> activate new servers"); + + client.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkAllCaches(); + } + + public void testInActiveClientReconnectToActiveCluster() throws Exception { + CountDownLatch activateLatch = new CountDownLatch(1); + + startNodes(activateLatch); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + stopGrid(node1); + stopGrid(node2); + + disconnectedLatch.await(); + + ig1 = startGrid(getConfiguration(node1)); + ig2 = startGrid(getConfiguration(node2)); + + ig1.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + + checkDescriptors(ig1, Collections.emptySet()); + checkDescriptors(ig2, Collections.emptySet()); + + activateLatch.countDown(); + + reconnectedLatch.await(); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkOnlySystemCaches(); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + Set exp2 = Sets.newHashSet(ccfgDynamicName, ccfgDynamicWithFilterName); + + checkDescriptors(ig1, exp2); + checkDescriptors(ig2, exp2); + checkDescriptors(client, exp2); + } + + public void testInActiveClientReconnectToInActiveCluster() throws Exception { + startNodes(null); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + stopGrid(node1); + stopGrid(node2); + + assertTrue(!client.active()); + + disconnectedLatch.await(); + + ig1 = startGrid(getConfiguration(node1)); + ig2 = startGrid(getConfiguration(node2)); + + reconnectedLatch.await(); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + client.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkOnlySystemCaches(); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + Set exp2 = Sets.newHashSet(ccfgDynamicName, ccfgDynamicWithFilterName); + + checkDescriptors(ig1, exp2); + checkDescriptors(ig2, exp2); + checkDescriptors(client, exp2); + } +} diff --git a/modules/schedule/src/main/java/org/apache/ignite/internal/processors/schedule/IgniteScheduleProcessor.java b/modules/schedule/src/main/java/org/apache/ignite/internal/processors/schedule/IgniteScheduleProcessor.java index e57d200ed19bf..2b16fbc58d8d8 100644 --- a/modules/schedule/src/main/java/org/apache/ignite/internal/processors/schedule/IgniteScheduleProcessor.java +++ b/modules/schedule/src/main/java/org/apache/ignite/internal/processors/schedule/IgniteScheduleProcessor.java @@ -109,7 +109,7 @@ void onScheduled(SchedulerFuture fut) { } /** {@inheritDoc} */ - @Override public void start(boolean activeOnStart) throws IgniteCheckedException { + @Override public void start() throws IgniteCheckedException { sched = new Scheduler(); sched.start(); From 6bf5ce46c1e6c4e3dcf042ac91a5b61a726c5821 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Sun, 11 Jun 2017 23:02:44 +0300 Subject: [PATCH 270/311] IGNITE-5267 - Moved ignite-ps module to ignite-core --- .../jmh/tree/BPlusTreeBenchmark.java | 18 +- modules/core/pom.xml | 14 ++ .../ignite/internal/IgniteComponentType.java | 17 +- .../apache/ignite/internal/IgniteKernal.java | 2 +- .../pagemem/impl/PageMemoryNoStoreImpl.java | 4 +- .../delta/DataPageInsertFragmentRecord.java | 2 +- .../record/delta/DataPageInsertRecord.java | 2 +- .../record/delta/DataPageRemoveRecord.java | 2 +- .../delta/DataPageSetFreeListPageRecord.java | 2 +- .../record/delta/DataPageUpdateRecord.java | 2 +- .../wal/record/delta/FixCountRecord.java | 4 +- .../record/delta/FixLeftmostChildRecord.java | 4 +- .../pagemem/wal/record/delta/FixRemoveId.java | 4 +- .../wal/record/delta/InitNewPageRecord.java | 2 +- .../wal/record/delta/InsertRecord.java | 2 +- .../record/delta/MetaPageAddRootRecord.java | 2 +- .../record/delta/MetaPageCutRootRecord.java | 3 +- .../wal/record/delta/MetaPageInitRecord.java | 4 +- .../delta/MetaPageInitRootInlineRecord.java | 2 +- .../record/delta/MetaPageInitRootRecord.java | 2 +- .../MetaPageUpdateLastAllocatedIndex.java | 4 +- ...ageUpdateLastSuccessfulFullSnapshotId.java | 2 +- ...etaPageUpdateLastSuccessfulSnapshotId.java | 2 +- .../delta/MetaPageUpdateNextSnapshotId.java | 2 +- .../MetaPageUpdatePartitionDataRecord.java | 2 +- .../wal/record/delta/NewRootInitRecord.java | 2 +- .../delta/PageListMetaResetCountRecord.java | 2 +- .../record/delta/PagesListAddPageRecord.java | 2 +- .../delta/PagesListInitNewPageRecord.java | 4 +- .../delta/PagesListRemovePageRecord.java | 2 +- .../record/delta/PagesListSetNextRecord.java | 2 +- .../delta/PagesListSetPreviousRecord.java | 2 +- .../wal/record/delta/RecycleRecord.java | 2 +- .../wal/record/delta/RemoveRecord.java | 4 +- .../wal/record/delta/ReplaceRecord.java | 2 +- .../record/delta/SplitExistingPageRecord.java | 4 +- .../record/delta/TrackingPageDeltaRecord.java | 2 +- .../cache/CacheAffinitySharedManager.java | 2 +- .../processors/cache/CacheGroupContext.java | 12 +- .../processors/cache/GridCacheAdapter.java | 2 +- .../processors/cache/GridCacheContext.java | 2 +- .../processors/cache/GridCacheMapEntry.java | 6 +- .../processors/cache/GridCacheProcessor.java | 19 +- .../cache/GridCacheSharedContext.java | 4 +- .../cache/IgniteCacheOffheapManager.java | 8 +- .../cache/IgniteCacheOffheapManagerImpl.java | 28 +-- .../cache/IgniteRebalanceIterator.java | 2 +- .../dht/GridDhtLocalPartition.java | 2 +- .../dht/GridPartitionedGetFuture.java | 2 +- .../dht/GridPartitionedSingleGetFuture.java | 2 +- .../dht/atomic/GridDhtAtomicCache.java | 3 +- .../dht/colocated/GridDhtColocatedCache.java | 3 +- .../colocated/GridDhtDetachedCacheEntry.java | 2 +- .../preloader/GridDhtPartitionSupplier.java | 2 +- .../distributed/near/GridNearCacheEntry.java | 2 +- .../local/atomic/GridLocalAtomicCache.java | 3 +- .../CacheDataRow.java | 2 +- .../CacheDataRowAdapter.java | 8 +- .../CacheSearchRow.java | 2 +- .../CheckpointLockStateChecker.java | 2 +- .../DataStructure.java | 12 +- .../persistence}/DbCheckpointListener.java | 2 +- .../FullPageIdIterableComparator.java | 2 +- .../GridCacheDatabaseSharedManager.java | 18 +- .../persistence}/GridCacheOffheapManager.java | 20 +- .../IgniteCacheDatabaseSharedManager.java | 18 +- .../IgniteCacheSnapshotManager.java | 2 +- .../MemoryMetricsImpl.java | 4 +- .../MemoryMetricsMXBeanImpl.java | 2 +- .../MemoryMetricsSnapshot.java | 2 +- .../MemoryPolicy.java | 4 +- .../{database => persistence}/MetaStore.java | 2 +- .../MetadataStorage.java | 16 +- .../persistence}/PersistenceMetricsImpl.java | 2 +- .../PersistenceMetricsSnapshot.java | 2 +- .../{database => persistence}/RootPage.java | 2 +- .../{database => persistence}/RowStore.java | 4 +- .../evict/FairFifoPageEvictionTracker.java | 2 +- .../evict/NoOpPageEvictionTracker.java | 2 +- .../evict/PageAbstractEvictionTracker.java | 8 +- .../evict/PageEvictionTracker.java | 2 +- .../evict/Random2LruPageEvictionTracker.java | 2 +- .../evict/RandomLruPageEvictionTracker.java | 2 +- .../persistence}/file/FilePageStore.java | 8 +- .../file/FilePageStoreManager.java | 4 +- .../freelist/FreeList.java | 4 +- .../freelist/FreeListImpl.java | 24 +-- .../freelist/PagesList.java | 22 +- .../freelist/io/PagesListMetaIO.java | 8 +- .../freelist/io/PagesListNodeIO.java | 8 +- .../pagemem/CheckpointMetricsTracker.java | 2 +- .../persistence}/pagemem/EvictCandidate.java | 2 +- .../persistence}/pagemem/FullPageIdTable.java | 2 +- .../persistence}/pagemem/PageMemoryEx.java | 2 +- .../persistence}/pagemem/PageMemoryImpl.java | 12 +- .../tree/BPlusTree.java | 42 ++-- .../tree/io/BPlusIO.java | 4 +- .../tree/io/BPlusInnerIO.java | 4 +- .../tree/io/BPlusLeafIO.java | 4 +- .../tree/io/BPlusMetaIO.java | 2 +- .../tree/io/CacheVersionIO.java | 2 +- .../tree/io/DataPageIO.java | 6 +- .../tree/io/DataPagePayload.java | 2 +- .../tree/io/IOVersions.java | 2 +- .../tree/io/PageIO.java | 12 +- .../tree/io/PageMetaIO.java | 2 +- .../tree/io/PagePartitionCountersIO.java | 2 +- .../tree/io/PagePartitionMetaIO.java | 2 +- .../tree/io/TrackingPageIO.java | 4 +- .../tree/reuse/ReuseBag.java | 2 +- .../tree/reuse/ReuseList.java | 2 +- .../tree/reuse/ReuseListImpl.java | 4 +- .../tree/util/PageHandler.java | 4 +- .../tree/util/PageLockListener.java | 2 +- .../wal/ByteBufferBackedDataInput.java | 2 +- .../wal/ByteBufferBackedDataInputImpl.java | 2 +- .../cache/persistence}/wal/FileInput.java | 6 +- .../persistence}/wal/FileWALPointer.java | 2 +- .../wal/FileWriteAheadLogManager.java | 10 +- .../persistence}/wal/RecordSerializer.java | 2 +- .../persistence}/wal/SegmentEofException.java | 2 +- ...IgniteDataIntegrityViolationException.java | 2 +- .../persistence}/wal/crc/PureJavaCrc32.java | 2 +- .../persistence}/wal/record/HeaderRecord.java | 2 +- .../wal/serializer/RecordV1Serializer.java | 22 +- .../cache/query/GridCacheQueryManager.java | 2 +- .../CacheContinuousQueryManager.java | 2 +- .../cluster/GridClusterStateProcessor.java | 154 +++++++++----- .../processors/igfs/IgfsDataManager.java | 2 +- .../schema/SchemaIndexCacheVisitorImpl.java | 2 +- .../internal/ClusterNodeMetricsSelfTest.java | 2 +- .../impl/PageMemoryNoLoadSelfTest.java | 4 +- .../cache/IgniteCacheGroupsTest.java | 2 +- .../IgnitePdsAtomicCacheRebalancingTest.java | 2 +- ...IgnitePdsCacheRebalancingAbstractTest.java | 2 +- .../IgnitePdsClientNearCachePutGetTest.java | 2 +- .../IgnitePdsContinuousRestartTest.java | 2 +- .../IgnitePdsDynamicCacheTest.java | 4 +- .../IgnitePdsMultiNodePutGetRestartTest.java | 2 +- .../persistence}/IgnitePdsPageSizesTest.java | 2 +- ...itePdsRecoveryAfterFileCorruptionTest.java | 12 +- .../IgnitePdsRemoveDuringRebalancingTest.java | 2 +- ...itePdsSingleNodePutGetPersistenceTest.java | 2 +- .../IgnitePdsTxCacheRebalancingTest.java | 2 +- .../IgnitePersistenceMetricsSelfTest.java | 2 +- .../IgnitePersistentStoreCacheGroupsTest.java | 2 +- ...nitePersistentStoreDataStructuresTest.java | 2 +- .../MemoryPolicyInitializationTest.java | 2 +- .../IgnitePdsMultiNodePutGetRestartTest.java | 2 +- ...sPageEvictionDuringPartitionClearTest.java | 4 +- .../db/IgnitePdsPageEvictionTest.java | 2 +- ...PdsRebalancingOnNotStableTopologyTest.java | 2 +- .../db/IgnitePdsTransactionsHangTest.java | 2 +- .../db/IgnitePdsWholeClusterRestartTest.java | 2 +- .../file/IgnitePdsCacheIntegrationTest.java | 2 +- .../db/file/IgnitePdsEvictionTest.java | 6 +- .../file/IgnitePdsNoActualWalHistoryTest.java | 4 +- .../ignitePdsCheckpointSimulationTest.java | 14 +- .../db/wal/IgnitePdsWalTlbTest.java | 2 +- ...IgniteWalDirectoriesConfigurationTest.java | 2 +- .../wal/IgniteWalHistoryReservationsTest.java | 6 +- .../IgniteWalRecoverySeveralRestartsTest.java | 2 +- .../db/wal/IgniteWalRecoveryTest.java | 46 +++- .../wal/WalRecoveryTxLogicalRecordsTest.java | 14 +- .../db/wal/crc/IgniteDataIntegrityTests.java | 8 +- .../pagemem/BPlusTreePageMemoryImplTest.java | 10 +- .../BPlusTreeReuseListPageMemoryImplTest.java | 10 +- .../pagemem/FullPageIdTableTest.java | 4 +- .../MetadataStoragePageMemoryImplTest.java | 10 +- .../persistence}/pagemem/NoOpWALManager.java | 2 +- .../pagemem/PageIdDistributionTest.java | 6 +- .../pagemem/PageMemoryImplNoLoadTest.java | 10 +- .../pagemem/PageMemoryImplTest.java | 10 +- .../AbstractNodeJoinTemplate.java | 2 +- .../IgniteChangeGlobalStateAbstractTest.java | 2 +- .../IgniteChangeGlobalStateCacheTest.java | 2 +- ...niteChangeGlobalStateDataStreamerTest.java | 2 +- ...iteChangeGlobalStateDataStructureTest.java | 2 +- .../IgniteChangeGlobalStateFailOverTest.java | 2 +- .../IgniteChangeGlobalStateServiceTest.java | 2 +- .../IgniteChangeGlobalStateTest.java | 2 +- .../IgniteStandByClusterTest.java | 2 +- .../extended/GridActivateExtensionTest.java | 2 +- .../GridActivationAtomicCacheSuit.java | 2 +- .../GridActivationCacheAbstractTestSuit.java | 2 +- .../GridActivationLocalAndNearCacheSuit.java | 2 +- .../GridActivationPartitionedCacheSuit.java | 2 +- .../GridActivationReplicatedCacheSuit.java | 2 +- .../join/JoinActiveNodeToActiveCluster.java | 4 +- .../join/JoinActiveNodeToInActiveCluster.java | 4 +- .../join/JoinInActiveNodeToActiveCluster.java | 4 +- .../JoinInActiveNodeToInActiveCluster.java | 4 +- ...iveNodeToActiveClusterWithPersistence.java | 29 +-- ...eNodeToInActiveClusterWithPersistence.java | 4 +- ...iveNodeToActiveClusterWithPersistence.java | 27 +-- ...eNodeToInActiveClusterWithPersistence.java | 4 +- ...iteAbstractStandByClientReconnectTest.java | 2 +- .../IgniteStandByClientReconnectTest.java | 2 +- ...tandByClientReconnectToNewClusterTest.java | 2 +- .../tree/io/TrackingPageIOTest.java | 2 +- .../database/BPlusTreeFakeReuseSelfTest.java | 4 +- .../database/BPlusTreeReuseSelfTest.java | 6 +- .../database/BPlusTreeSelfTest.java | 20 +- .../database/FreeListImplSelfTest.java | 12 +- .../database/IgniteDbAbstractTest.java | 2 +- .../IgniteDbMemoryLeakAbstractTest.java | 2 +- .../database/MemoryMetricsSelfTest.java | 2 +- .../database/MetadataStorageSelfTest.java | 6 +- .../hashmap/GridCacheTestContext.java | 5 +- .../testsuites/IgniteCacheTestSuite2.java | 2 +- .../IgnitePdsOutOfMemoryTestSuite.java | 2 +- .../ignite/testsuites/IgnitePdsTestSuite.java | 38 ++-- .../testsuites/IgnitePdsTestSuite2.java | 34 ++- .../testsuites/IgniteStandByClusterSuite.java | 10 +- .../processors/query/h2/IgniteH2Indexing.java | 2 +- .../query/h2/database/H2PkHashIndex.java | 2 +- .../query/h2/database/H2RowFactory.java | 2 +- .../processors/query/h2/database/H2Tree.java | 8 +- .../query/h2/database/H2TreeIndex.java | 6 +- .../query/h2/database/io/H2ExtrasInnerIO.java | 10 +- .../query/h2/database/io/H2ExtrasLeafIO.java | 10 +- .../query/h2/database/io/H2InnerIO.java | 8 +- .../query/h2/database/io/H2LeafIO.java | 8 +- .../processors/query/h2/opt/GridH2Row.java | 2 +- ...teCacheLockPartitionOnAffinityRunTest.java | 2 +- ...xingAndGroupPutGetPersistenceSelfTest.java | 2 +- ...NodeWithIndexingPutGetPersistenceTest.java | 2 +- ...iteDbSingleNodeWithIndexingPutGetTest.java | 1 - .../IgnitePersistentStoreSchemaLoadTest.java | 6 +- .../h2/database/InlineIndexHelperTest.java | 2 +- .../IgnitePdsWithIndexingTestSuite.java | 46 ++++ modules/pds/pom.xml | 189 ----------------- .../resources/META-INF/classnames.properties | 28 --- .../pagemem/NoOpPageStoreManager.java | 200 ------------------ parent/pom.xml | 1 + pom.xml | 1 - 236 files changed, 761 insertions(+), 1078 deletions(-) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/CacheDataRow.java (96%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/CacheDataRowAdapter.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/CacheSearchRow.java (95%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/CheckpointLockStateChecker.java (94%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/DataStructure.java (96%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/DbCheckpointListener.java (95%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/FullPageIdIterableComparator.java (96%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/GridCacheDatabaseSharedManager.java (99%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/GridCacheOffheapManager.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/IgniteCacheDatabaseSharedManager.java (97%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/IgniteCacheSnapshotManager.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/MemoryMetricsImpl.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/MemoryMetricsMXBeanImpl.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/MemoryMetricsSnapshot.java (97%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/MemoryPolicy.java (93%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/MetaStore.java (96%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/MetadataStorage.java (95%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/PersistenceMetricsImpl.java (99%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/PersistenceMetricsSnapshot.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/RootPage.java (96%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/RowStore.java (95%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/evict/FairFifoPageEvictionTracker.java (97%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/evict/NoOpPageEvictionTracker.java (95%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/evict/PageAbstractEvictionTracker.java (94%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/evict/PageEvictionTracker.java (96%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/evict/Random2LruPageEvictionTracker.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/evict/RandomLruPageEvictionTracker.java (98%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/file/FilePageStore.java (97%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/file/FilePageStoreManager.java (99%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/freelist/FreeList.java (91%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/freelist/FreeListImpl.java (94%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/freelist/PagesList.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/freelist/io/PagesListMetaIO.java (93%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/freelist/io/PagesListNodeIO.java (94%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/CheckpointMetricsTracker.java (98%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/EvictCandidate.java (96%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/FullPageIdTable.java (99%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/PageMemoryEx.java (98%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/PageMemoryImpl.java (99%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/BPlusTree.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/BPlusIO.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/BPlusInnerIO.java (97%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/BPlusLeafIO.java (92%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/BPlusMetaIO.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/CacheVersionIO.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/DataPageIO.java (99%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/DataPagePayload.java (95%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/IOVersions.java (96%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/PageIO.java (96%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/PageMetaIO.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/PagePartitionCountersIO.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/PagePartitionMetaIO.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/TrackingPageIO.java (98%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/reuse/ReuseBag.java (93%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/reuse/ReuseList.java (95%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/reuse/ReuseListImpl.java (95%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/util/PageHandler.java (99%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/util/PageLockListener.java (96%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/wal/ByteBufferBackedDataInput.java (95%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/wal/ByteBufferBackedDataInputImpl.java (98%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/wal/FileInput.java (97%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/wal/FileWALPointer.java (98%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/wal/FileWriteAheadLogManager.java (99%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/wal/RecordSerializer.java (96%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/wal/SegmentEofException.java (95%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/wal/crc/IgniteDataIntegrityViolationException.java (94%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/wal/crc/PureJavaCrc32.java (99%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/wal/record/HeaderRecord.java (94%) rename modules/{pds/src/main/java/org/apache/ignite/internal/processors/cache/database => core/src/main/java/org/apache/ignite/internal/processors/cache/persistence}/wal/serializer/RecordV1Serializer.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePdsAtomicCacheRebalancingTest.java (95%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePdsCacheRebalancingAbstractTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePdsClientNearCachePutGetTest.java (96%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePdsContinuousRestartTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePdsDynamicCacheTest.java (96%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePdsMultiNodePutGetRestartTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePdsPageSizesTest.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePdsRecoveryAfterFileCorruptionTest.java (95%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePdsRemoveDuringRebalancingTest.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePdsSingleNodePutGetPersistenceTest.java (96%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePdsTxCacheRebalancingTest.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePersistenceMetricsSelfTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePersistentStoreCacheGroupsTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/IgnitePersistentStoreDataStructuresTest.java (98%) rename modules/core/src/test/java/org/apache/ignite/internal/processors/cache/{database => persistence}/MemoryPolicyInitializationTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/IgnitePdsMultiNodePutGetRestartTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/IgnitePdsPageEvictionDuringPartitionClearTest.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/IgnitePdsPageEvictionTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/IgnitePdsRebalancingOnNotStableTopologyTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/IgnitePdsTransactionsHangTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/IgnitePdsWholeClusterRestartTest.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/file/IgnitePdsCacheIntegrationTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/file/IgnitePdsEvictionTest.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/file/IgnitePdsNoActualWalHistoryTest.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/file/ignitePdsCheckpointSimulationTest.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/wal/IgnitePdsWalTlbTest.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/wal/IgniteWalDirectoriesConfigurationTest.java (96%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/wal/IgniteWalHistoryReservationsTest.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/wal/IgniteWalRecoverySeveralRestartsTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/wal/IgniteWalRecoveryTest.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/wal/WalRecoveryTxLogicalRecordsTest.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/db/wal/crc/IgniteDataIntegrityTests.java (91%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/BPlusTreePageMemoryImplTest.java (87%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/BPlusTreeReuseListPageMemoryImplTest.java (87%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/FullPageIdTableTest.java (95%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/MetadataStoragePageMemoryImplTest.java (88%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/NoOpWALManager.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/PageIdDistributionTest.java (96%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/PageMemoryImplNoLoadTest.java (88%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/pagemem/PageMemoryImplTest.java (89%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/AbstractNodeJoinTemplate.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/IgniteChangeGlobalStateAbstractTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/IgniteChangeGlobalStateCacheTest.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/IgniteChangeGlobalStateDataStructureTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/IgniteChangeGlobalStateFailOverTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/IgniteChangeGlobalStateServiceTest.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/IgniteChangeGlobalStateTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/IgniteStandByClusterTest.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/extended/GridActivateExtensionTest.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/extended/GridActivationAtomicCacheSuit.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/extended/GridActivationCacheAbstractTestSuit.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java (95%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/extended/GridActivationPartitionedCacheSuit.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/extended/GridActivationReplicatedCacheSuit.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/join/JoinActiveNodeToActiveCluster.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/join/JoinActiveNodeToInActiveCluster.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/join/JoinInActiveNodeToActiveCluster.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/join/JoinInActiveNodeToInActiveCluster.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java (56%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java (84%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java (54%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java (84%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java (99%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/reconnect/IgniteStandByClientReconnectTest.java (98%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => core/src/test/java/org/apache/ignite/internal/processors/cache/persistence}/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java (98%) rename modules/core/src/test/java/org/apache/ignite/internal/processors/cache/{database => persistence}/tree/io/TrackingPageIOTest.java (99%) rename modules/{pds => core}/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java (93%) rename modules/{pds => core}/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java (62%) rename modules/{pds => core}/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java (59%) rename modules/{pds => core}/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java (73%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => indexing/src/test/java/org/apache/ignite/internal/processors/cache}/IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java (96%) rename modules/{pds/src/test/java/org/apache/ignite/cache/database => indexing/src/test/java/org/apache/ignite/internal/processors/cache}/IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.java (97%) rename modules/{pds/src/test/java/org/apache/ignite/cache => indexing/src/test/java/org/apache/ignite/internal/processors}/database/IgnitePersistentStoreSchemaLoadTest.java (97%) create mode 100644 modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingTestSuite.java delete mode 100644 modules/pds/pom.xml delete mode 100644 modules/pds/src/main/resources/META-INF/classnames.properties delete mode 100644 modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java diff --git a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/tree/BPlusTreeBenchmark.java b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/tree/BPlusTreeBenchmark.java index c9ad0cfccb715..94abc86a64e61 100644 --- a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/tree/BPlusTreeBenchmark.java +++ b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/tree/BPlusTreeBenchmark.java @@ -30,15 +30,15 @@ import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseBag; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseBag; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; import org.apache.ignite.logger.java.JavaLogger; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Scope; diff --git a/modules/core/pom.xml b/modules/core/pom.xml index 6c714d0f3d22c..17e850d0a7fe8 100644 --- a/modules/core/pom.xml +++ b/modules/core/pom.xml @@ -211,6 +211,20 @@ 1.1 test + + + com.google.guava + guava + ${guava.version} + test + + + + org.javassist + javassist + ${javassist.version} + test + diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java index 1b70ab4c556dd..0cd2fc16d1e2a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java @@ -89,22 +89,7 @@ public enum IgniteComponentType { "org.apache.ignite.internal.processors.schedule.IgniteNoopScheduleProcessor", "org.apache.ignite.internal.processors.schedule.IgniteScheduleProcessor", "ignite-schedule" - ), - - /** Database manager used when persistence is enabled. */ - DATABASE_MANAGER(null, - "org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager", - "ignite-pds"), - - /** Page store manager used when persistence is enabled. */ - PAGE_STORE_MANAGER(null, - "org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager", - "ignite-pds"), - - /** Write-Ahead Log manager used when persistence is enabled. */ - WAL_MANAGER(null, - "org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager", - "ignite-pds"); + ); /** No-op class name. */ private final String noOpClsName; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index fa605d6f74acd..a6ad89e0c225d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -112,7 +112,7 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheProxy; import org.apache.ignite.internal.processors.cache.IgniteInternalCache; import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; -import org.apache.ignite.internal.processors.cache.database.MemoryPolicy; +import org.apache.ignite.internal.processors.cache.persistence.MemoryPolicy; import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor; import org.apache.ignite.internal.processors.closure.GridClosureProcessor; import org.apache.ignite.internal.processors.cluster.ClusterProcessor; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java index dc72482634802..8f146dc0bc1b5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java @@ -34,8 +34,8 @@ import org.apache.ignite.internal.pagemem.PageIdUtils; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.util.GridUnsafe; import org.apache.ignite.internal.util.IgniteUtils; import org.apache.ignite.internal.util.OffheapReadWriteLock; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageInsertFragmentRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageInsertFragmentRecord.java index eeaabd1d114f0..042fbe473d083 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageInsertFragmentRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageInsertFragmentRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO; /** * Insert fragment to data page record. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageInsertRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageInsertRecord.java index f23d57aa1562c..17425feb579a3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageInsertRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageInsertRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO; /** * Insert into data page. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageRemoveRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageRemoveRecord.java index 17c7fe8bc1d54..3aabe08a89a00 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageRemoveRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageRemoveRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO; import org.apache.ignite.internal.util.typedef.internal.S; /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageSetFreeListPageRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageSetFreeListPageRecord.java index c835052846351..82281de664e63 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageSetFreeListPageRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageSetFreeListPageRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO; import static org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.DATA_PAGE_SET_FREE_LIST_PAGE; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageUpdateRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageUpdateRecord.java index 65b7172010102..d4e2811ad13ae 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageUpdateRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/DataPageUpdateRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO; /** * Update existing record in data page. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixCountRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixCountRecord.java index c7277108ed67b..3ab1c4a04a234 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixCountRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixCountRecord.java @@ -19,8 +19,8 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; /** * Fix elements count record. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixLeftmostChildRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixLeftmostChildRecord.java index 94155c9bd3e69..15ee7dd8a0446 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixLeftmostChildRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixLeftmostChildRecord.java @@ -19,8 +19,8 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; /** * Fix leftmost child. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixRemoveId.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixRemoveId.java index b9900e1210890..b6ea410a75546 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixRemoveId.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/FixRemoveId.java @@ -19,8 +19,8 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; /** * Fix remove ID record. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/InitNewPageRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/InitNewPageRecord.java index f5607dde947cf..f883e068daea9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/InitNewPageRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/InitNewPageRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/InsertRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/InsertRecord.java index f6d8f8c22fe07..d0e66a3343f30 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/InsertRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/InsertRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageAddRootRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageAddRootRecord.java index 176df33e8cfd1..1f1e97697f3d4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageAddRootRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageAddRootRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO; /** * New root in meta page. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageCutRootRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageCutRootRecord.java index 50ccddc78638b..3fc42a15dfffd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageCutRootRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageCutRootRecord.java @@ -17,10 +17,9 @@ package org.apache.ignite.internal.pagemem.wal.record.delta; -import java.nio.ByteBuffer; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO; /** * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java index 1daf5a1226795..692b8f1782d2f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRecord.java @@ -19,8 +19,8 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO; /** * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootInlineRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootInlineRecord.java index 212f5b9d5dbeb..7eb8426dd38c2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootInlineRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootInlineRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO; /** * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootRecord.java index 280310f87f065..0eb61b577fdb5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO; /** * Initialize new meta page. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastAllocatedIndex.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastAllocatedIndex.java index d916be26e92b7..548735eceb226 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastAllocatedIndex.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastAllocatedIndex.java @@ -19,8 +19,8 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO; /** * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastSuccessfulFullSnapshotId.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastSuccessfulFullSnapshotId.java index e322b4f538cee..34be353f4a580 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastSuccessfulFullSnapshotId.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastSuccessfulFullSnapshotId.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO; /** * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastSuccessfulSnapshotId.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastSuccessfulSnapshotId.java index df9d778f963e4..7fca5dc9516e0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastSuccessfulSnapshotId.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateLastSuccessfulSnapshotId.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO; /** * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateNextSnapshotId.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateNextSnapshotId.java index 1403bd7c11376..0cd72ece5ca34 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateNextSnapshotId.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdateNextSnapshotId.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO; /** * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java index b28dd528350e1..15d1a0ce084bf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageUpdatePartitionDataRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO; import org.apache.ignite.internal.util.typedef.internal.S; /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/NewRootInitRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/NewRootInitRecord.java index 277d7739910b7..bdfdef5ea025b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/NewRootInitRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/NewRootInitRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO; /** * Initialize new root page. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PageListMetaResetCountRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PageListMetaResetCountRecord.java index 16587d3322daa..4756c9af60634 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PageListMetaResetCountRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PageListMetaResetCountRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO; /** * Delta record for page-list meta count reset diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListAddPageRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListAddPageRecord.java index a503b463a5b6c..2577ec33c5d09 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListAddPageRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListAddPageRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO; +import org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListInitNewPageRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListInitNewPageRecord.java index b03532326b439..673d33c0987a2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListInitNewPageRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListInitNewPageRecord.java @@ -19,8 +19,8 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListRemovePageRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListRemovePageRecord.java index 26f832ca32e52..23411295e28fd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListRemovePageRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListRemovePageRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO; +import org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListSetNextRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListSetNextRecord.java index c0bed60868c48..30600e17447c0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListSetNextRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListSetNextRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO; +import org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO; /** * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListSetPreviousRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListSetPreviousRecord.java index 21c3ef2c01417..590643e094145 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListSetPreviousRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/PagesListSetPreviousRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO; +import org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO; /** * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/RecycleRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/RecycleRecord.java index 1737e12cd8f63..92ea88e819983 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/RecycleRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/RecycleRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; /** * Recycle index page. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/RemoveRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/RemoveRecord.java index 6d278e9aa1d92..ac5d442aa30b0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/RemoveRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/RemoveRecord.java @@ -19,8 +19,8 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.util.typedef.internal.S; /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/ReplaceRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/ReplaceRecord.java index 4e85c430d7aaa..2f504adce9c42 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/ReplaceRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/ReplaceRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; /** * Replace. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/SplitExistingPageRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/SplitExistingPageRecord.java index 418d28bcf2e0a..5cb3023119296 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/SplitExistingPageRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/SplitExistingPageRecord.java @@ -19,8 +19,8 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/TrackingPageDeltaRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/TrackingPageDeltaRecord.java index 7cd094817a3b3..05e96ff99367d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/TrackingPageDeltaRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/TrackingPageDeltaRecord.java @@ -19,7 +19,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.TrackingPageIO; /** * Delta record for updates in tracking pages 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 70bf117c91eb4..6340360c4e670 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 @@ -387,7 +387,7 @@ else if (!cctx.localNode().isClient()) { nearCfg = req.nearCacheConfiguration(); } else // Only static cache configured on client must be started. - startCache = cctx.kernalContext().state().isLocalConfigure(req.cacheName()); + startCache = cctx.kernalContext().state().isLocallyConfigured(req.cacheName()); } else if (cctx.localNodeId().equals(req.initiatingNodeId())) { startCache = true; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java index b85c41deed186..7367374eff78b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java @@ -37,9 +37,10 @@ import org.apache.ignite.internal.processors.affinity.AffinityAssignment; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; -import org.apache.ignite.internal.processors.cache.database.MemoryPolicy; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeList; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager; +import org.apache.ignite.internal.processors.cache.persistence.MemoryPolicy; +import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentRequest; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentResponse; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; @@ -855,10 +856,7 @@ public void start() throws IgniteCheckedException { ClassLoader clsLdr = U.gridClassLoader(); try { - offheapMgr = (IgniteCacheOffheapManager) clsLdr - .loadClass("org.apache.ignite.internal.processors.cache.database.GridCacheOffheapManager") - .getConstructor() - .newInstance(); + offheapMgr = new GridCacheOffheapManager(); } catch (Exception e) { throw new IgniteCheckedException("Failed to initialize offheap manager", e); 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 535cfdd37dc3f..81cb1f2f39d60 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 @@ -83,7 +83,7 @@ import org.apache.ignite.internal.cluster.IgniteClusterEx; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityImpl; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java index 44cf4e056104e..83f7aa0509156 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java @@ -56,7 +56,7 @@ import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager; import org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.database.MemoryPolicy; +import org.apache.ignite.internal.processors.cache.persistence.MemoryPolicy; import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; 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 28656fb79903b..eea8935423763 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 @@ -38,9 +38,9 @@ import org.apache.ignite.internal.pagemem.wal.record.DataRecord; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheUpdateAtomicResult.UpdateOutcome; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; -import org.apache.ignite.internal.processors.cache.database.CacheDataRowAdapter; -import org.apache.ignite.internal.processors.cache.database.MemoryPolicy; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter; +import org.apache.ignite.internal.processors.cache.persistence.MemoryPolicy; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicAbstractUpdateFuture; 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 5ee80ef6ab8b7..55b49982d769d 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 @@ -77,11 +77,13 @@ import org.apache.ignite.internal.processors.cache.CacheJoinNodeDiscoveryData.CacheInfo; import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache; import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager; -import org.apache.ignite.internal.processors.cache.database.MemoryPolicy; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeList; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheSnapshotManager; +import org.apache.ignite.internal.processors.cache.persistence.MemoryPolicy; +import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager; +import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCache; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; @@ -95,6 +97,7 @@ import org.apache.ignite.internal.processors.cache.jta.CacheJtaManagerAdapter; import org.apache.ignite.internal.processors.cache.local.GridLocalCache; import org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache; +import org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager; import org.apache.ignite.internal.processors.cache.query.GridCacheLocalQueryManager; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager; @@ -2175,11 +2178,11 @@ private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, " configuration will be ignored)."); } - dbMgr = IgniteComponentType.DATABASE_MANAGER.create(ctx, false); + dbMgr = new GridCacheDatabaseSharedManager(ctx); - pageStoreMgr = IgniteComponentType.PAGE_STORE_MANAGER.create(ctx, false); + pageStoreMgr = new FilePageStoreManager(ctx); - walMgr = IgniteComponentType.WAL_MANAGER.create(ctx, false); + walMgr = new FileWriteAheadLogManager(ctx); } else dbMgr = new IgniteCacheDatabaseSharedManager(); 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 be1ab3d4c93e5..0ee00204cd7e7 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 @@ -40,8 +40,8 @@ import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheSnapshotManager; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java index 8951396f1133a..001848e60c244 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java @@ -21,10 +21,10 @@ import javax.cache.Cache; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; -import org.apache.ignite.internal.processors.cache.database.RootPage; -import org.apache.ignite.internal.processors.cache.database.RowStore; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.RootPage; +import org.apache.ignite.internal.processors.cache.persistence.RowStore; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.GridAtomicLong; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index ae47443a3b294..b9afad831dbc0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -36,20 +36,20 @@ import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; -import org.apache.ignite.internal.processors.cache.database.CacheDataRowAdapter; -import org.apache.ignite.internal.processors.cache.database.CacheSearchRow; -import org.apache.ignite.internal.processors.cache.database.RootPage; -import org.apache.ignite.internal.processors.cache.database.RowStore; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeList; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPagePayload; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter; +import org.apache.ignite.internal.processors.cache.persistence.CacheSearchRow; +import org.apache.ignite.internal.processors.cache.persistence.RootPage; +import org.apache.ignite.internal.processors.cache.persistence.RowStore; +import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteRebalanceIterator.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteRebalanceIterator.java index c191c72109623..4efe640b6901a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteRebalanceIterator.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteRebalanceIterator.java @@ -17,7 +17,7 @@ package org.apache.ignite.internal.processors.cache; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.util.lang.GridCloseableIterator; /** 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 4480efed5f7ee..f0d5bf181964a 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 @@ -47,7 +47,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader; import org.apache.ignite.internal.processors.cache.extras.GridCacheObsoleteEntryExtras; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java index f29c507ea34ca..78ff595e995f1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java @@ -41,7 +41,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheMessage; import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetResponse; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java index aabe025844969..cab90aec92ead 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java @@ -42,7 +42,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheMessage; import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.near.CacheVersionedValue; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetResponse; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index 2f99033807e5c..432e3f96f399a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -56,13 +56,12 @@ import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException; import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; -import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory; import org.apache.ignite.internal.processors.cache.GridCacheOperation; import org.apache.ignite.internal.processors.cache.GridCacheReturn; import org.apache.ignite.internal.processors.cache.GridCacheUpdateAtomicResult; import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtFuture; 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 708df49dc9a2b..c72f53ed6acd5 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 @@ -38,12 +38,11 @@ import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException; import org.apache.ignite.internal.processors.cache.GridCacheLockTimeoutException; -import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory; import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate; import org.apache.ignite.internal.processors.cache.GridCacheReturn; import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedLockCancelledException; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedUnlockRequest; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java index 404265dff6bd9..7da3d4f8b6623 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java @@ -22,7 +22,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheOperation; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.typedef.internal.S; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java index 467b9069352b3..1cc6c28cb8223 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java @@ -30,7 +30,7 @@ import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; import org.apache.ignite.internal.processors.cache.IgniteRebalanceIterator; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; import org.apache.ignite.internal.util.lang.GridCloseableIterator; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java index b17d0b527ec72..646281bcf41f2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java @@ -30,7 +30,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate; import org.apache.ignite.internal.processors.cache.GridCacheOperation; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java index 384cd41cbc487..730c71d1d63d3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -55,7 +54,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheReturn; import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.local.GridLocalCache; import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRow.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CacheDataRow.java similarity index 96% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRow.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CacheDataRow.java index cc26b21e358e3..57aeaef709280 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRow.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CacheDataRow.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.KeyCacheObject; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CacheDataRowAdapter.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CacheDataRowAdapter.java index a25d7942559b2..4d75475a8ed21 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CacheDataRowAdapter.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.nio.ByteBuffer; import org.apache.ignite.IgniteCheckedException; @@ -29,9 +29,9 @@ import org.apache.ignite.internal.processors.cache.IncompleteCacheObject; import org.apache.ignite.internal.processors.cache.IncompleteObject; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.tree.io.CacheVersionIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPagePayload; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.CacheVersionIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheSearchRow.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CacheSearchRow.java similarity index 95% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheSearchRow.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CacheSearchRow.java index 6e429c48fef12..1637eb05c4719 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheSearchRow.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CacheSearchRow.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.internal.processors.cache.KeyCacheObject; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CheckpointLockStateChecker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CheckpointLockStateChecker.java similarity index 94% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CheckpointLockStateChecker.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CheckpointLockStateChecker.java index df90f332c7060..ca6fb694c56fd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CheckpointLockStateChecker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/CheckpointLockStateChecker.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; /** * Interface for perform checking that checkpoint lock is held by current track diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DataStructure.java similarity index 96% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DataStructure.java index 0e35bf4dd0cc3..b2a8f3636bd16 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DataStructure.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; @@ -25,11 +25,11 @@ import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; import org.apache.ignite.internal.pagemem.wal.record.delta.RecycleRecord; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseBag; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageLockListener; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseBag; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener; import org.apache.ignite.internal.util.typedef.internal.U; import static org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_DATA; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/DbCheckpointListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DbCheckpointListener.java similarity index 95% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/DbCheckpointListener.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DbCheckpointListener.java index 7f66790d9f0fb..f4da637947031 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/DbCheckpointListener.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DbCheckpointListener.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.util.Map; import org.apache.ignite.IgniteCheckedException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterableComparator.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/FullPageIdIterableComparator.java similarity index 96% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterableComparator.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/FullPageIdIterableComparator.java index 8e2afde4f43f1..c056c52d00dc6 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/FullPageIdIterableComparator.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/FullPageIdIterableComparator.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.io.Serializable; import java.util.Comparator; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java similarity index 99% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java index cae59a4045279..2146f9850a1cd 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.io.File; import java.io.FileFilter; @@ -106,14 +106,14 @@ import org.apache.ignite.internal.processors.cache.GridCacheProcessor; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.StoredCacheData; -import org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager; -import org.apache.ignite.internal.processors.cache.database.pagemem.CheckpointMetricsTracker; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionMetaIO; -import org.apache.ignite.internal.processors.cache.database.wal.FileWALPointer; -import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; +import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.CheckpointMetricsTracker; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer; +import org.apache.ignite.internal.processors.cache.persistence.wal.crc.PureJavaCrc32; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java similarity index 98% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java index c0176f658ea8b..eb9f4dfeb1cb0 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheOffheapManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.util.HashMap; import java.util.Iterator; @@ -47,15 +47,15 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl; import org.apache.ignite.internal.processors.cache.IgniteRebalanceIterator; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageMetaIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionCountersIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PagePartitionMetaIO; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseListImpl; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeListImpl; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionCountersIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseListImpl; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java similarity index 97% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java index a4ca5d2338095..e45d3790829ee 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.io.File; import java.util.ArrayList; @@ -44,14 +44,14 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; -import org.apache.ignite.internal.processors.cache.database.evict.FairFifoPageEvictionTracker; -import org.apache.ignite.internal.processors.cache.database.evict.NoOpPageEvictionTracker; -import org.apache.ignite.internal.processors.cache.database.evict.PageEvictionTracker; -import org.apache.ignite.internal.processors.cache.database.evict.Random2LruPageEvictionTracker; -import org.apache.ignite.internal.processors.cache.database.evict.RandomLruPageEvictionTracker; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeList; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.evict.FairFifoPageEvictionTracker; +import org.apache.ignite.internal.processors.cache.persistence.evict.NoOpPageEvictionTracker; +import org.apache.ignite.internal.processors.cache.persistence.evict.PageEvictionTracker; +import org.apache.ignite.internal.processors.cache.persistence.evict.Random2LruPageEvictionTracker; +import org.apache.ignite.internal.processors.cache.persistence.evict.RandomLruPageEvictionTracker; +import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList; +import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeListImpl; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport; import org.apache.ignite.internal.util.typedef.F; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheSnapshotManager.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheSnapshotManager.java index 91957dbcc9a9e..e490e3521fe60 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheSnapshotManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheSnapshotManager.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.nio.ByteBuffer; import java.util.NavigableMap; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsImpl.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsImpl.java index 2e5a78cb5222e..271767c546681 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsImpl.java @@ -14,12 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.MemoryMetrics; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl; +import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeListImpl; import org.apache.ignite.internal.processors.cache.ratemetrics.HitRateMetrics; import org.apache.ignite.internal.util.typedef.internal.U; import org.jsr166.LongAdder8; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsMXBeanImpl.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsMXBeanImpl.java index b53db4b9b133b..392f83f4b5fb6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsMXBeanImpl.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.MemoryMetrics; import org.apache.ignite.configuration.MemoryPolicyConfiguration; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsSnapshot.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsSnapshot.java similarity index 97% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsSnapshot.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsSnapshot.java index f4874ebfc2000..4e7f90a1464a5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsSnapshot.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsSnapshot.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.MemoryMetrics; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicy.java similarity index 93% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicy.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicy.java index cb35d331d23de..7c7d7bc28e00f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicy.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.evict.PageEvictionTracker; +import org.apache.ignite.internal.processors.cache.persistence.evict.PageEvictionTracker; /** * Memory policy provides access to objects configured with {@link MemoryPolicyConfiguration} configuration. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetaStore.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MetaStore.java similarity index 96% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetaStore.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MetaStore.java index c21b8183400c5..c09ce4e523b5a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetaStore.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MetaStore.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.IgniteCheckedException; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MetadataStorage.java similarity index 95% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MetadataStorage.java index 139bf7333dddb..806afb8d136f8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MetadataStorage.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.nio.charset.StandardCharsets; import java.util.concurrent.atomic.AtomicLong; @@ -25,13 +25,13 @@ import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; import org.apache.ignite.internal.util.typedef.internal.U; /** diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/PersistenceMetricsImpl.java similarity index 99% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsImpl.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/PersistenceMetricsImpl.java index 25d95ae84d401..7952937ec9b68 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/PersistenceMetricsImpl.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; import org.apache.ignite.internal.processors.cache.ratemetrics.HitRateMetrics; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsSnapshot.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/PersistenceMetricsSnapshot.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsSnapshot.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/PersistenceMetricsSnapshot.java index c939710db6a32..0de995032d911 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/PersistenceMetricsSnapshot.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/PersistenceMetricsSnapshot.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.PersistenceMetrics; import org.apache.ignite.internal.util.typedef.internal.S; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RootPage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RootPage.java similarity index 96% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RootPage.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RootPage.java index 935046db3623c..da9efe5203ca4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RootPage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RootPage.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.util.tostring.GridToStringInclude; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RowStore.java similarity index 95% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RowStore.java index d707869001557..9cc5c626df139 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RowStore.java @@ -15,14 +15,14 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeList; +import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList; /** * Data store for H2 rows. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/FairFifoPageEvictionTracker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/FairFifoPageEvictionTracker.java similarity index 97% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/FairFifoPageEvictionTracker.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/FairFifoPageEvictionTracker.java index b7c6b57e67677..f5c7c8a9b5b82 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/FairFifoPageEvictionTracker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/FairFifoPageEvictionTracker.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.evict; +package org.apache.ignite.internal.processors.cache.persistence.evict; import java.util.LinkedList; import org.apache.ignite.IgniteCheckedException; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/NoOpPageEvictionTracker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/NoOpPageEvictionTracker.java similarity index 95% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/NoOpPageEvictionTracker.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/NoOpPageEvictionTracker.java index ba466bf6a7c6d..b420ecda8be8a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/NoOpPageEvictionTracker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/NoOpPageEvictionTracker.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.evict; +package org.apache.ignite.internal.processors.cache.persistence.evict; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/PageAbstractEvictionTracker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/PageAbstractEvictionTracker.java similarity index 94% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/PageAbstractEvictionTracker.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/PageAbstractEvictionTracker.java index c61acedd3903b..a524d5ef74c45 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/PageAbstractEvictionTracker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/PageAbstractEvictionTracker.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.evict; +package org.apache.ignite.internal.processors.cache.persistence.evict; import java.util.List; import org.apache.ignite.IgniteCheckedException; @@ -24,9 +24,9 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.CacheDataRowAdapter; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/PageEvictionTracker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/PageEvictionTracker.java similarity index 96% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/PageEvictionTracker.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/PageEvictionTracker.java index b13dcf88b3786..baa5462a4dcac 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/PageEvictionTracker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/PageEvictionTracker.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.evict; +package org.apache.ignite.internal.processors.cache.persistence.evict; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.lifecycle.LifecycleAware; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/Random2LruPageEvictionTracker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/Random2LruPageEvictionTracker.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/Random2LruPageEvictionTracker.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/Random2LruPageEvictionTracker.java index 21ebba1f78cf4..00f1b16d11db0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/Random2LruPageEvictionTracker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/Random2LruPageEvictionTracker.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.evict; +package org.apache.ignite.internal.processors.cache.persistence.evict; import java.util.concurrent.ThreadLocalRandom; import org.apache.ignite.IgniteCheckedException; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/RandomLruPageEvictionTracker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/RandomLruPageEvictionTracker.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/RandomLruPageEvictionTracker.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/RandomLruPageEvictionTracker.java index d241148e421ba..035a91a93be43 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/RandomLruPageEvictionTracker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/evict/RandomLruPageEvictionTracker.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.evict; +package org.apache.ignite.internal.processors.cache.persistence.evict; import java.util.concurrent.ThreadLocalRandom; import org.apache.ignite.IgniteCheckedException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStore.java similarity index 97% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStore.java index 2042358213d11..6ddc9fc1678ee 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStore.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStore.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.file; +package org.apache.ignite.internal.processors.cache.persistence.file; import java.io.File; import java.io.IOException; @@ -32,9 +32,9 @@ import org.apache.ignite.configuration.MemoryConfiguration; import org.apache.ignite.internal.pagemem.PageIdUtils; import org.apache.ignite.internal.pagemem.store.PageStore; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.wal.crc.IgniteDataIntegrityViolationException; -import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException; +import org.apache.ignite.internal.processors.cache.persistence.wal.crc.PureJavaCrc32; import org.apache.ignite.internal.util.typedef.internal.U; import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java similarity index 99% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java index 8c096f1e7e6cc..f908512488f1d 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.file; +package org.apache.ignite.internal.processors.cache.persistence.file; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -47,7 +47,7 @@ import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; import org.apache.ignite.internal.processors.cache.StoredCacheData; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheSnapshotManager; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.marshaller.Marshaller; import org.apache.ignite.marshaller.jdk.JdkMarshaller; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeList.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/FreeList.java similarity index 91% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeList.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/FreeList.java index 3266b957665c1..d2f009973f329 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeList.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/FreeList.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.freelist; +package org.apache.ignite.internal.processors.cache.persistence.freelist; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; /** */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeListImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/FreeListImpl.java similarity index 94% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeListImpl.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/FreeListImpl.java index fadd685c5dd31..4e8b8d8b77b0b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeListImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/FreeListImpl.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.freelist; +package org.apache.ignite.internal.processors.cache.persistence.freelist; import java.util.concurrent.atomic.AtomicReferenceArray; import org.apache.ignite.IgniteCheckedException; @@ -28,17 +28,17 @@ import org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.DataPageRemoveRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.DataPageUpdateRecord; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.MemoryPolicy; -import org.apache.ignite.internal.processors.cache.database.evict.PageEvictionTracker; -import org.apache.ignite.internal.processors.cache.database.tree.io.CacheVersionIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPagePayload; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseBag; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.MemoryPolicy; +import org.apache.ignite.internal.processors.cache.persistence.evict.PageEvictionTracker; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.CacheVersionIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseBag; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; import org.apache.ignite.internal.util.typedef.internal.U; /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java index a8f3037427daf..eb5df6bb0a34c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java @@ -15,12 +15,10 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.freelist; +package org.apache.ignite.internal.processors.cache.persistence.freelist; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import org.apache.ignite.IgniteCheckedException; @@ -36,14 +34,14 @@ import org.apache.ignite.internal.pagemem.wal.record.delta.PagesListRemovePageRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetPreviousRecord; -import org.apache.ignite.internal.processors.cache.database.DataStructure; -import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListMetaIO; -import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseBag; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.DataStructure; +import org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseBag; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; import org.apache.ignite.internal.util.GridArrays; import org.apache.ignite.internal.util.GridLongList; import org.apache.ignite.internal.util.typedef.F; @@ -55,7 +53,7 @@ import static java.lang.Boolean.TRUE; import static org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_DATA; import static org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX; -import static org.apache.ignite.internal.processors.cache.database.tree.io.PageIO.getPageId; +import static org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO.getPageId; /** * Striped doubly-linked list of page IDs optionally organized in buckets. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/io/PagesListMetaIO.java similarity index 93% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListMetaIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/io/PagesListMetaIO.java index 6bd50a3aa299b..41e1bb51badca 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListMetaIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/io/PagesListMetaIO.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.freelist.io; +package org.apache.ignite.internal.processors.cache.persistence.freelist.io; import java.util.Map; import org.apache.ignite.internal.pagemem.PageUtils; -import org.apache.ignite.internal.processors.cache.database.freelist.PagesList; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.freelist.PagesList; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.util.GridLongList; /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListNodeIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/io/PagesListNodeIO.java similarity index 94% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListNodeIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/io/PagesListNodeIO.java index 6bd0532ed5ad9..7db89eb9976e1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListNodeIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/io/PagesListNodeIO.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.freelist.io; +package org.apache.ignite.internal.processors.cache.persistence.freelist.io; import org.apache.ignite.internal.pagemem.PageUtils; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; -import static org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler.copyMemory; +import static org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler.copyMemory; /** * TODO optimize: now we have slow {@link #removePage(long, long)} diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/CheckpointMetricsTracker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/CheckpointMetricsTracker.java similarity index 98% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/CheckpointMetricsTracker.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/CheckpointMetricsTracker.java index e6b88d34f83fe..e533f41a50319 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/CheckpointMetricsTracker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/CheckpointMetricsTracker.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/EvictCandidate.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/EvictCandidate.java similarity index 96% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/EvictCandidate.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/EvictCandidate.java index 906871f57cab0..eb172c978f899 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/EvictCandidate.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/EvictCandidate.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.util.tostring.GridToStringExclude; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/FullPageIdTable.java similarity index 99% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/FullPageIdTable.java index 01d7bce56c9fc..78d83b3faac36 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/FullPageIdTable.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/FullPageIdTable.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import org.apache.ignite.internal.mem.IgniteOutOfMemoryException; import org.apache.ignite.internal.pagemem.FullPageId; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryEx.java similarity index 98% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryEx.java index 56d1be93eb638..3246f218ee3a0 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryEx.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import java.nio.ByteBuffer; import org.apache.ignite.IgniteCheckedException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryImpl.java similarity index 99% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryImpl.java index 958e0ea30252c..423d572192cb8 100755 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/pagemem/PageMemoryImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryImpl.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -54,11 +54,11 @@ import org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; -import org.apache.ignite.internal.processors.cache.database.wal.crc.IgniteDataIntegrityViolationException; +import org.apache.ignite.internal.processors.cache.persistence.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.TrackingPageIO; +import org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException; import org.apache.ignite.internal.util.GridConcurrentHashSet; import org.apache.ignite.internal.util.GridLongList; import org.apache.ignite.internal.util.GridMultiCollectionWrapper; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java index 98204eb24e49f..74d251a4c4761 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree; +package org.apache.ignite.internal.processors.cache.persistence.tree; import java.io.Externalizable; import java.util.ArrayList; @@ -42,16 +42,16 @@ import org.apache.ignite.internal.pagemem.wal.record.delta.RemoveRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.ReplaceRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.SplitExistingPageRecord; -import org.apache.ignite.internal.processors.cache.database.DataStructure; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusMetaIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseBag; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.DataStructure; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseBag; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; import org.apache.ignite.internal.util.GridArrays; import org.apache.ignite.internal.util.GridLongList; import org.apache.ignite.internal.util.IgniteTree; @@ -63,16 +63,16 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteInClosure; -import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.Bool.DONE; -import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.Bool.FALSE; -import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.Bool.READY; -import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.Bool.TRUE; -import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.Result.FOUND; -import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.Result.GO_DOWN; -import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.Result.GO_DOWN_X; -import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.Result.NOT_FOUND; -import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.Result.RETRY; -import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.Result.RETRY_ROOT; +import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.Bool.DONE; +import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.Bool.FALSE; +import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.Bool.READY; +import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.Bool.TRUE; +import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.Result.FOUND; +import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.Result.GO_DOWN; +import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.Result.GO_DOWN_X; +import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.Result.NOT_FOUND; +import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.Result.RETRY; +import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.Result.RETRY_ROOT; /** * Abstract B+Tree. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusIO.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusIO.java index fe1a0d08facb8..4c2b2e0945663 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusIO.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageUtils; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; import org.apache.ignite.lang.IgniteInClosure; /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusInnerIO.java similarity index 97% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusInnerIO.java index 60fd24c800c09..88fc8c826c5a7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusInnerIO.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageUtils; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; /** * Abstract IO routines for B+Tree inner pages. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusLeafIO.java similarity index 92% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusLeafIO.java index f6011b342585e..931bf10242d08 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusLeafIO.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; /** * Abstract IO routines for B+Tree leaf pages. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusMetaIO.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusMetaIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusMetaIO.java index 6755820e6ae3a..6f430c1d06ab4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusMetaIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusMetaIO.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import org.apache.ignite.IgniteException; import org.apache.ignite.internal.pagemem.PageUtils; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/CacheVersionIO.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/CacheVersionIO.java index 7c4537e566024..fef561202b2ef 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/CacheVersionIO.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import java.nio.ByteBuffer; import org.apache.ignite.IgniteCheckedException; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/DataPageIO.java similarity index 99% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/DataPageIO.java index 3ed69e1c8fc4d..d8ed1a6ee579b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/DataPageIO.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -28,8 +28,8 @@ import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.processors.cache.CacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.typedef.internal.SB; import org.jetbrains.annotations.Nullable; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPagePayload.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/DataPagePayload.java similarity index 95% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPagePayload.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/DataPagePayload.java index 277bdc7089612..49eed8889b4bb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPagePayload.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/DataPagePayload.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; /** * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/IOVersions.java similarity index 96% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/IOVersions.java index 3545b328333f5..48b0da161b0b9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/IOVersions.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; /** * Registry for IO versions. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PageIO.java similarity index 96% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PageIO.java index dd6a503a1766e..6fb5fd08a940b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PageIO.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -25,11 +25,11 @@ import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl; -import org.apache.ignite.internal.processors.cache.database.MetadataStorage; -import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListMetaIO; -import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageLockListener; +import org.apache.ignite.internal.processors.cache.persistence.MetadataStorage; +import org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener; /** * Base format for all the page types. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PageMetaIO.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PageMetaIO.java index b04baf3ae3d3e..ac482e88a8e99 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PageMetaIO.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import java.nio.ByteBuffer; import org.apache.ignite.internal.pagemem.PageUtils; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionCountersIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PagePartitionCountersIO.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionCountersIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PagePartitionCountersIO.java index 015b8ff9e57a3..9bd806fc7b3ca 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionCountersIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PagePartitionCountersIO.java @@ -16,7 +16,7 @@ * */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import java.util.Map; import org.apache.ignite.internal.pagemem.PageUtils; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PagePartitionMetaIO.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PagePartitionMetaIO.java index ddacf6972e46d..88dbf9cbff77a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/PagePartitionMetaIO.java @@ -16,7 +16,7 @@ * */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import org.apache.ignite.internal.pagemem.PageUtils; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/TrackingPageIO.java similarity index 98% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/TrackingPageIO.java index 136ebfff79a60..aa6ba9a5360bb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/TrackingPageIO.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import java.nio.ByteBuffer; import org.apache.ignite.internal.pagemem.PageIdUtils; -import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; /** * We use dedicated page for tracking pages updates. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseBag.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/reuse/ReuseBag.java similarity index 93% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseBag.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/reuse/ReuseBag.java index 903e93f42fbb2..843eccfbb4bfa 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseBag.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/reuse/ReuseBag.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.reuse; +package org.apache.ignite.internal.processors.cache.persistence.tree.reuse; /** * Reuse bag for free index pages. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseList.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/reuse/ReuseList.java similarity index 95% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseList.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/reuse/ReuseList.java index 801f89ae75f08..aaab186618bc2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseList.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/reuse/ReuseList.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.reuse; +package org.apache.ignite.internal.processors.cache.persistence.tree.reuse; import org.apache.ignite.IgniteCheckedException; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/reuse/ReuseListImpl.java similarity index 95% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/reuse/ReuseListImpl.java index 1c6c8d58b19f3..6291c1d0f3d4d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/reuse/ReuseListImpl.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.reuse; +package org.apache.ignite.internal.processors.cache.persistence.tree.reuse; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; -import org.apache.ignite.internal.processors.cache.database.freelist.PagesList; +import org.apache.ignite.internal.processors.cache.persistence.freelist.PagesList; /** * Reuse list. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/util/PageHandler.java similarity index 99% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/util/PageHandler.java index 0d331e7325dfc..648ddf78fa9bc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/util/PageHandler.java @@ -15,14 +15,14 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.util; +package org.apache.ignite.internal.processors.cache.persistence.tree.util; import java.nio.ByteBuffer; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; import org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.util.GridUnsafe; import static java.lang.Boolean.FALSE; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/util/PageLockListener.java similarity index 96% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/util/PageLockListener.java index 904d217720eb4..75cf8878da6da 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/util/PageLockListener.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.util; +package org.apache.ignite.internal.processors.cache.persistence.tree.util; /** * Page lock listener. diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInput.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferBackedDataInput.java similarity index 95% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInput.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferBackedDataInput.java index 220f27b494bd1..807a9685decb4 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInput.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferBackedDataInput.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.wal; +package org.apache.ignite.internal.processors.cache.persistence.wal; import java.io.DataInput; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInputImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferBackedDataInputImpl.java similarity index 98% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInputImpl.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferBackedDataInputImpl.java index d5fc9ed470df4..2351ea7f5f3ad 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/ByteBufferBackedDataInputImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferBackedDataInputImpl.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.wal; +package org.apache.ignite.internal.processors.cache.persistence.wal; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileInput.java similarity index 97% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileInput.java index 1ba002fd2cd35..be1e477f9599c 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileInput.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileInput.java @@ -15,14 +15,14 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.wal; +package org.apache.ignite.internal.processors.cache.persistence.wal; import java.io.EOFException; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; -import org.apache.ignite.internal.processors.cache.database.wal.crc.IgniteDataIntegrityViolationException; -import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; +import org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException; +import org.apache.ignite.internal.processors.cache.persistence.wal.crc.PureJavaCrc32; import org.jetbrains.annotations.NotNull; /** diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWALPointer.java similarity index 98% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWALPointer.java index 8884fb3393c25..033b1c4feb185 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWALPointer.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWALPointer.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.wal; +package org.apache.ignite.internal.processors.cache.persistence.wal; import org.apache.ignite.internal.pagemem.wal.WALPointer; import org.apache.ignite.internal.util.typedef.internal.S; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java similarity index 99% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java index 51a2437371996..4ec1efd285f0b 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/FileWriteAheadLogManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.wal; +package org.apache.ignite.internal.processors.cache.persistence.wal; import java.io.EOFException; import java.io.File; @@ -56,10 +56,10 @@ import org.apache.ignite.internal.pagemem.wal.record.WALRecord; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter; -import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.PersistenceMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.wal.record.HeaderRecord; -import org.apache.ignite.internal.processors.cache.database.wal.serializer.RecordV1Serializer; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.PersistenceMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord; +import org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer; import org.apache.ignite.internal.util.GridCloseableIteratorAdapter; import org.apache.ignite.internal.util.GridUnsafe; import org.apache.ignite.internal.util.typedef.F; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/RecordSerializer.java similarity index 96% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/RecordSerializer.java index c929789e7d657..75a62a95a4bbd 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/RecordSerializer.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/RecordSerializer.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.wal; +package org.apache.ignite.internal.processors.cache.persistence.wal; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/SegmentEofException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/SegmentEofException.java similarity index 95% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/SegmentEofException.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/SegmentEofException.java index fcb9fe3ff9f01..80c375e2ad205 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/SegmentEofException.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/SegmentEofException.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.wal; +package org.apache.ignite.internal.processors.cache.persistence.wal; import org.apache.ignite.IgniteCheckedException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/IgniteDataIntegrityViolationException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/crc/IgniteDataIntegrityViolationException.java similarity index 94% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/IgniteDataIntegrityViolationException.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/crc/IgniteDataIntegrityViolationException.java index 7c3eaa27fdac3..b4d0ae0ddf696 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/IgniteDataIntegrityViolationException.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/crc/IgniteDataIntegrityViolationException.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.wal.crc; +package org.apache.ignite.internal.processors.cache.persistence.wal.crc; import org.apache.ignite.IgniteException; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/PureJavaCrc32.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/crc/PureJavaCrc32.java similarity index 99% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/PureJavaCrc32.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/crc/PureJavaCrc32.java index a947b2883102c..6bd4a35b2fdf8 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/crc/PureJavaCrc32.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/crc/PureJavaCrc32.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.wal.crc; +package org.apache.ignite.internal.processors.cache.persistence.wal.crc; import java.nio.ByteBuffer; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/record/HeaderRecord.java similarity index 94% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/record/HeaderRecord.java index 35ce761927160..3fc56376bb56b 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/record/HeaderRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/record/HeaderRecord.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.wal.record; +package org.apache.ignite.internal.processors.cache.persistence.wal.record; import org.apache.ignite.internal.pagemem.wal.record.WALRecord; diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/serializer/RecordV1Serializer.java similarity index 98% rename from modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/serializer/RecordV1Serializer.java index ce66b976ab1d7..0ccd3a08218e5 100644 --- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/wal/serializer/RecordV1Serializer.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/serializer/RecordV1Serializer.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.wal.serializer; +package org.apache.ignite.internal.processors.cache.persistence.wal.serializer; import java.io.DataInput; import java.io.EOFException; @@ -83,16 +83,16 @@ import org.apache.ignite.internal.processors.cache.GridCacheOperation; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.CacheVersionIO; -import org.apache.ignite.internal.processors.cache.database.wal.ByteBufferBackedDataInput; -import org.apache.ignite.internal.processors.cache.database.wal.FileInput; -import org.apache.ignite.internal.processors.cache.database.wal.FileWALPointer; -import org.apache.ignite.internal.processors.cache.database.wal.RecordSerializer; -import org.apache.ignite.internal.processors.cache.database.wal.SegmentEofException; -import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; -import org.apache.ignite.internal.processors.cache.database.wal.record.HeaderRecord; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.CacheVersionIO; +import org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferBackedDataInput; +import org.apache.ignite.internal.processors.cache.persistence.wal.FileInput; +import org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer; +import org.apache.ignite.internal.processors.cache.persistence.wal.RecordSerializer; +import org.apache.ignite.internal.processors.cache.persistence.wal.SegmentEofException; +import org.apache.ignite.internal.processors.cache.persistence.wal.crc.PureJavaCrc32; +import org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java index 0c264dbd5ba59..352a46239fdef 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java @@ -71,7 +71,7 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy; import org.apache.ignite.internal.processors.cache.IgniteInternalCache; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtUnreservedPartitionException; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java index f264056934ce5..628111b47edc3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java @@ -57,7 +57,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter; import org.apache.ignite.internal.processors.cache.IgniteCacheProxy; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicAbstractUpdateFuture; import org.apache.ignite.internal.processors.continuous.GridContinuousHandler; import org.apache.ignite.internal.util.tostring.GridToStringInclude; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java index 643480dec6ae9..e0751f92b1f7f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java @@ -109,7 +109,11 @@ public class GridClusterStateProcessor extends GridProcessorAdapter { @GridToStringExclude private GridCacheSharedContext sharedCtx; - //todo may be add init latch + /** */ + private final ConcurrentHashMap cacheData = new ConcurrentHashMap<>(); + + /** */ + private volatile CacheJoinNodeDiscoveryData localCacheData; /** Listener. */ private final GridLocalEventListener lsr = new GridLocalEventListener() { @@ -123,8 +127,8 @@ public class GridClusterStateProcessor extends GridProcessorAdapter { final GridChangeGlobalStateFuture f = cgsLocFut.get(); if (f != null) - f.initFut.listen(new CI1() { - @Override public void apply(IgniteInternalFuture fut) { + f.initFut.listen(new CI1>() { + @Override public void apply(IgniteInternalFuture fut) { f.onDiscoveryEvent(e); } }); @@ -192,6 +196,9 @@ public GridClusterStateProcessor(GridKernalContext ctx) { ctx.event().addLocalEventListener(lsr, EVT_NODE_LEFT, EVT_NODE_FAILED); } + /** + * @param data Joining node discovery data. + */ public void cacheProcessorStarted(CacheJoinNodeDiscoveryData data) { assert data != null; @@ -227,6 +234,15 @@ public void cacheProcessorStarted(CacheJoinNodeDiscoveryData data) { cgsLocFut.set(null); } + /** {@inheritDoc} */ + @Override public void onKernalStart() throws IgniteCheckedException { + super.onKernalStart(); + + // First node started (coordinator). + if (ctx.discovery().serverNodes(AffinityTopologyVersion.NONE).get(0).isLocal()) + cacheData.putAll(localCacheData.caches()); + } + /** {@inheritDoc} */ @Nullable @Override public DiscoveryDataExchangeType discoveryDataType() { return DiscoveryDataExchangeType.STATE_PROC; @@ -270,9 +286,10 @@ public void cacheProcessorStarted(CacheJoinNodeDiscoveryData data) { */ public IgniteInternalFuture changeGlobalState(final boolean activate) { if (cacheProc.transactions().tx() != null || sharedCtx.lockedTopologyVersion(null) != null) - throw new IgniteException("Cannot " + prettyStr(activate) + " cluster, because cache locked on transaction."); + throw new IgniteException("Failed to " + prettyStr(activate) + " cluster (must invoke the " + + "method outside of an active transaction)."); - if ((globalState == ACTIVE && activate) || (this.globalState == INACTIVE && !activate)) + if ((globalState == ACTIVE && activate) || (globalState == INACTIVE && !activate)) return new GridFinishedFuture<>(); final UUID requestId = UUID.randomUUID(); @@ -284,9 +301,10 @@ public IgniteInternalFuture changeGlobalState(final boolean activate) { if (locF.activate == activate) return locF; - else - return new GridFinishedFuture<>(new IgniteException( - "fail " + prettyStr(activate) + ", because now in progress" + prettyStr(locF.activate))); + + return new GridFinishedFuture<>(new IgniteException( + "Failed to " + prettyStr(activate) + ", because another state change operation is currently " + + "in progress: " + prettyStr(locF.activate))); } if (ctx.clientNode()) { @@ -295,7 +313,7 @@ public IgniteInternalFuture changeGlobalState(final boolean activate) { IgniteCompute comp = ((ClusterGroupAdapter)ctx.cluster().get().forServers()).compute(); if (log.isInfoEnabled()) - log.info("Send " + prettyStr(activate) + " request from client node [id=" + + log.info("Sending " + prettyStr(activate) + " request from client node [id=" + ctx.localNodeId() + " topVer=" + topVer + " ]"); IgniteFuture fut = comp.runAsync(new ClientChangeGlobalStateComputeRequest(activate)); @@ -339,7 +357,7 @@ public IgniteInternalFuture changeGlobalState(final boolean activate) { "node is stopping.")); } catch (IgniteCheckedException e) { - log.error("Fail create or send change global state request." + cgsFut, e); + U.error(log, "Failed to create or send global state change request: " + cgsFut, e); cgsFut.onDone(e); } @@ -352,6 +370,10 @@ public IgniteInternalFuture changeGlobalState(final boolean activate) { return cgsFut; } + /** + * @param reqs Requests to print. + * @param active Active flag. + */ private void printCacheInfo(List reqs, boolean active) { assert reqs != null; @@ -374,6 +396,9 @@ private void printCacheInfo(List reqs, boolean active log.info(sb.toString()); } + /** + * @param req Cache being started. + */ public void onCacheStart(DynamicCacheChangeRequest req) { CacheInfo cacheInfo = cacheData.get(req.cacheName()); @@ -386,6 +411,9 @@ public void onCacheStart(DynamicCacheChangeRequest req) { ); } + /** + * @param req Cache being stopped. + */ public void onCacheStop(DynamicCacheChangeRequest req) { CacheInfo cacheInfo = cacheData.get(req.cacheName()); @@ -393,6 +421,9 @@ public void onCacheStop(DynamicCacheChangeRequest req) { cacheData.remove(req.cacheName()); } + /** + * @return All caches map. + */ private Map allCaches() { Map cfgs = new HashMap<>(); @@ -403,6 +434,10 @@ private Map allCaches() { return cfgs; } + /** + * @return Collection of all caches start requests. + * @throws IgniteCheckedException If failed to create requests. + */ private List startAllCachesRequests() throws IgniteCheckedException { assert !ctx.config().isDaemon(); @@ -430,6 +465,27 @@ private List startAllCachesRequests() throws IgniteCh } } + /** + * @return Collection of requests to stop caches. + */ + private List stopAllCachesRequests() { + Collection cacheCfgs = allCaches().values(); + + List reqs = new ArrayList<>(cacheCfgs.size()); + + for (CacheConfiguration cfg : cacheCfgs) { + DynamicCacheChangeRequest req = stopRequest(ctx, cfg.getName(), false, false); + + reqs.add(req); + } + + return reqs; + } + + /** + * @param cfg Configuration to create request for. + * @return Dynamic cache change request. + */ private DynamicCacheChangeRequest createRequest(CacheConfiguration cfg) { assert cfg != null; assert cfg.getName() != null; @@ -449,20 +505,6 @@ private DynamicCacheChangeRequest createRequest(CacheConfiguration cfg) { return req; } - private List stopAllCachesRequests() { - Collection cacheCfgs = allCaches().values(); - - List reqs = new ArrayList<>(cacheCfgs.size()); - - for (CacheConfiguration cfg : cacheCfgs) { - DynamicCacheChangeRequest req = stopRequest(ctx, cfg.getName(), false, false); - - reqs.add(req); - } - - return reqs; - } - /** * */ @@ -478,30 +520,29 @@ public boolean active() { return globalState == ACTIVE; } - @Override public void onKernalStart() throws IgniteCheckedException { - super.onKernalStart(); - - // First node started (coordinator). - if (ctx.discovery().serverNodes(AffinityTopologyVersion.NONE).get(0).isLocal()) - cacheData.putAll(localCacheData.caches()); - } - - private final ConcurrentHashMap cacheData = new ConcurrentHashMap<>(); - - private volatile CacheJoinNodeDiscoveryData localCacheData; - - public boolean isLocalConfigure(String cacheName){ + /** + * @param cacheName Cache name to check. + * @return Locally configured flag. + */ + public boolean isLocallyConfigured(String cacheName){ assert localCacheData != null; return localCacheData.caches().containsKey(cacheName) || localCacheData.templates().containsKey(cacheName); } - // Invoke if cluster inactive. + /** + * Invoked if cluster is inactive. + * + * @param dataBag Bag to collect data to. + */ public void collectGridNodeData0(DiscoveryDataBag dataBag) { if (!dataBag.commonDataCollectedFor(CACHE_PROC.ordinal())) dataBag.addGridCommonData(CACHE_PROC.ordinal(), cacheData); } + /** + * @param data Joining node discovery data. + */ public void onJoiningNodeDataReceived0(JoiningNodeDiscoveryData data) { if (data.hasJoiningNodeData()) { if (data.joiningNodeData() instanceof CacheJoinNodeDiscoveryData) { @@ -624,7 +665,7 @@ public void onFullResponseMessage(Map exs) { for (Map.Entry entry : exs.entrySet()) e.addSuppressed(entry.getValue()); - log.error("Fail while revert activation request changes", e); + U.error(log, "Failed to revert activation request changes", e); } } else { @@ -652,7 +693,7 @@ private Exception onActivate(ChangeGlobalStateContext cgsCtx) { final boolean client = ctx.clientNode(); if (log.isInfoEnabled()) - log.info("Start activation process [nodeId=" + this.ctx.localNodeId() + ", client=" + client + + log.info("Start activation process [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]"); Collection cfgs = new ArrayList<>(); @@ -677,13 +718,13 @@ private Exception onActivate(ChangeGlobalStateContext cgsCtx) { sharedCtx.database().onActivate(ctx); if (log.isInfoEnabled()) - log.info("Success activate wal, dataBase, pageStore [nodeId=" + log.info("Successfully activated persistence managers [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]"); return null; } catch (Exception e) { - log.error("Fail activate wal, dataBase, pageStore [nodeId=" + ctx.localNodeId() + ", client=" + client + + U.error(log, "Failed to activate persistence managers [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]", e); if (!client) @@ -700,7 +741,7 @@ public Exception onDeActivate(ChangeGlobalStateContext cgsCtx) { final boolean client = ctx.clientNode(); if (log.isInfoEnabled()) - log.info("Start deactivate process [id=" + ctx.localNodeId() + ", client=" + + log.info("Starting deactivation [id=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]"); try { @@ -709,13 +750,13 @@ public Exception onDeActivate(ChangeGlobalStateContext cgsCtx) { ctx.service().onDeActivate(ctx); if (log.isInfoEnabled()) - log.info("Success deactivate services, dataStructures, database, pageStore, wal [id=" + ctx.localNodeId() + ", client=" + + log.info("Successfully deactivated persistence processors [id=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]"); return null; } catch (Exception e) { - log.error("DeActivation fail [nodeId=" + ctx.localNodeId() + ", client=" + client + + U.error(log, "Failed to execute deactivation callback [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]", e); return e; @@ -743,21 +784,21 @@ private void onFinalActivate(final ChangeGlobalStateContext cgsCtx) { ctx.dataStructures().onActivate(ctx); if (log.isInfoEnabled()) - log.info("Success final activate [nodeId=" + log.info("Successfully performed final activation steps [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]"); } catch (Exception ex) { e = ex; - log.error("Fail activate finished [nodeId=" + ctx.localNodeId() + ", client=" + client + - ", topVer=" + GridClusterStateProcessor.this.lastCgsCtx.topVer + "]", ex); + U.error(log, "Failed to perform final activation steps [nodeId=" + ctx.localNodeId() + + ", client=" + client + ", topVer=" + lastCgsCtx.topVer + "]", ex); } finally { globalState = ACTIVE; sendChangeGlobalStateResponse(cgsCtx.requestId, cgsCtx.initiatingNodeId, e); - GridClusterStateProcessor.this.lastCgsCtx = null; + lastCgsCtx = null; } } }); @@ -772,7 +813,7 @@ public void onFinalDeActivate(ChangeGlobalStateContext cgsCtx) { final boolean client = ctx.clientNode(); if (log.isInfoEnabled()) - log.info("Success final deactivate [nodeId=" + log.info("Successfully performed final deactivation steps [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]"); Exception ex = null; @@ -797,7 +838,7 @@ public void onFinalDeActivate(ChangeGlobalStateContext cgsCtx) { sendChangeGlobalStateResponse(cgsCtx.requestId, cgsCtx.initiatingNodeId, ex); - this.lastCgsCtx = null; + lastCgsCtx = null; } /** @@ -830,7 +871,7 @@ private void sendChangeGlobalStateResponse(UUID requestId, UUID initNodeId, Exce GridChangeGlobalStateMessageResponse actResp = new GridChangeGlobalStateMessageResponse(requestId, ex); if (log.isDebugEnabled()) - log.debug("Send change global state response [nodeId=" + ctx.localNodeId() + + log.debug("Sending global state change response [nodeId=" + ctx.localNodeId() + ", topVer=" + ctx.discovery().topologyVersionEx() + ", response=" + actResp + "]"); if (ctx.localNodeId().equals(initNodeId)) @@ -893,7 +934,7 @@ private String prettyStr(boolean activate) { /** * */ - private static class GridChangeGlobalStateFuture extends GridFutureAdapter { + private static class GridChangeGlobalStateFuture extends GridFutureAdapter { /** Request id. */ @GridToStringInclude private final UUID requestId; @@ -919,7 +960,7 @@ private static class GridChangeGlobalStateFuture extends GridFutureAdapter { /** */ @GridToStringInclude - private final GridFutureAdapter initFut = new GridFutureAdapter(); + private final GridFutureAdapter initFut = new GridFutureAdapter<>(); /** Grid logger. */ @GridToStringExclude @@ -932,7 +973,8 @@ public GridChangeGlobalStateFuture(UUID requestId, boolean activate, GridKernalC this.requestId = requestId; this.activate = activate; this.ctx = ctx; - this.log = ctx.log(getClass()); + + log = ctx.log(getClass()); } /** @@ -1025,7 +1067,7 @@ private void onAllReceived() { } /** {@inheritDoc} */ - @Override public boolean onDone(@Nullable Object res, @Nullable Throwable err) { + @Override public boolean onDone(@Nullable Void res, @Nullable Throwable err) { ctx.state().cgsLocFut.set(null); return super.onDone(res, err); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java index 8ae6db839f943..6874bbe4e3811 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java @@ -65,7 +65,7 @@ import org.apache.ignite.internal.managers.communication.GridMessageListener; import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener; import org.apache.ignite.internal.processors.cache.IgniteInternalCache; -import org.apache.ignite.internal.processors.cache.database.MemoryPolicy; +import org.apache.ignite.internal.processors.cache.persistence.MemoryPolicy; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal; import org.apache.ignite.internal.processors.datastreamer.DataStreamerCacheUpdaters; import org.apache.ignite.internal.processors.igfs.data.IgfsDataPutProcessor; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorImpl.java index b3fa47c5e81b9..3a445bf79e72e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaIndexCacheVisitorImpl.java @@ -24,7 +24,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java index da2203de21931..f842440b68346 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java @@ -29,7 +29,7 @@ import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.events.Event; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; import org.apache.ignite.internal.processors.task.GridInternal; import org.apache.ignite.internal.util.lang.GridAbsPredicate; import org.apache.ignite.lang.IgnitePredicate; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java index 93b68f3ee3a54..02c521ee2606f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java @@ -32,8 +32,8 @@ import org.apache.ignite.internal.pagemem.PageIdUtils; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.PageUtils; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java index a8b0c8bf19ceb..7b420ccbe6d63 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java @@ -78,7 +78,7 @@ import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.binary.BinaryMarshaller; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicyFactory; import org.apache.ignite.internal.util.lang.GridAbsPredicate; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsAtomicCacheRebalancingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsAtomicCacheRebalancingTest.java similarity index 95% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsAtomicCacheRebalancingTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsAtomicCacheRebalancingTest.java index 0c4812d1cf7e7..21551b66c227d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsAtomicCacheRebalancingTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsAtomicCacheRebalancingTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsCacheRebalancingAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsCacheRebalancingAbstractTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java index 6c0ec194c7fea..a9428f8d0940d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsCacheRebalancingAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.io.Serializable; import java.util.Collections; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsClientNearCachePutGetTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsClientNearCachePutGetTest.java similarity index 96% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsClientNearCachePutGetTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsClientNearCachePutGetTest.java index 240171e6ccbeb..17dad10f8582a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsClientNearCachePutGetTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsClientNearCachePutGetTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsContinuousRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsContinuousRestartTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsContinuousRestartTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsContinuousRestartTest.java index a149836480f76..3721031962398 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsContinuousRestartTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsContinuousRestartTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.util.Map; import java.util.Random; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsDynamicCacheTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java similarity index 96% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsDynamicCacheTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java index 63bf557b7b5cd..ba55c09848b5d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsDynamicCacheTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCheckedException; @@ -29,7 +29,7 @@ import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; import org.apache.ignite.configuration.WALMode; -import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; import org.apache.ignite.internal.processors.database.IgniteDbDynamicCacheSelfTest; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsMultiNodePutGetRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMultiNodePutGetRestartTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsMultiNodePutGetRestartTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMultiNodePutGetRestartTest.java index d4d9eb62fbcaf..21ea626f5b8d6 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsMultiNodePutGetRestartTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMultiNodePutGetRestartTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.io.File; import java.io.Serializable; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsPageSizesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsPageSizesTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsPageSizesTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsPageSizesTest.java index a15b96c986a6a..5014399f8225c 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsPageSizesTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsPageSizesTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.util.Random; import java.util.concurrent.Callable; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRecoveryAfterFileCorruptionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRecoveryAfterFileCorruptionTest.java similarity index 95% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRecoveryAfterFileCorruptionTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRecoveryAfterFileCorruptionTest.java index eb3662d80aadc..4981095a2b21d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRecoveryAfterFileCorruptionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRecoveryAfterFileCorruptionTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.io.IOException; import java.nio.ByteBuffer; @@ -43,11 +43,11 @@ import org.apache.ignite.internal.pagemem.wal.WALPointer; import org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.file.FilePageStore; -import org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore; +import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; 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.TcpDiscoveryIpFinder; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRemoveDuringRebalancingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRemoveDuringRebalancingTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRemoveDuringRebalancingTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRemoveDuringRebalancingTest.java index 79d8e40b391b3..e8558597eb69c 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsRemoveDuringRebalancingTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRemoveDuringRebalancingTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.io.File; import java.util.concurrent.Callable; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodePutGetPersistenceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsSingleNodePutGetPersistenceTest.java similarity index 96% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodePutGetPersistenceTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsSingleNodePutGetPersistenceTest.java index d92ac25601a6f..1f861c76a494f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodePutGetPersistenceTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsSingleNodePutGetPersistenceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsTxCacheRebalancingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsTxCacheRebalancingTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsTxCacheRebalancingTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsTxCacheRebalancingTest.java index f29807e7cc2d2..c641ea4857dbc 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsTxCacheRebalancingTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsTxCacheRebalancingTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistenceMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistenceMetricsSelfTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistenceMetricsSelfTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistenceMetricsSelfTest.java index 79d4a4def9d0d..72e0b612a7235 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistenceMetricsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistenceMetricsSelfTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.io.Serializable; import java.util.Objects; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheGroupsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreCacheGroupsTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheGroupsTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreCacheGroupsTest.java index 4a0ae15301c87..57cc8d08026c7 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreCacheGroupsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreCacheGroupsTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.io.Serializable; import java.util.Arrays; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDataStructuresTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreDataStructuresTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDataStructuresTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreDataStructuresTest.java index 718cf5431d350..64949034bc7f4 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreDataStructuresTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreDataStructuresTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteAtomicLong; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicyInitializationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java similarity index 99% rename from modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicyInitializationTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java index ec798eed5cea7..9a49b6c6cd46f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicyInitializationTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database; +package org.apache.ignite.internal.processors.cache.persistence; import java.util.Collection; import org.apache.ignite.IgniteCache; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsMultiNodePutGetRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsMultiNodePutGetRestartTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsMultiNodePutGetRestartTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsMultiNodePutGetRestartTest.java index 41b1b297c505f..e24433343117e 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsMultiNodePutGetRestartTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsMultiNodePutGetRestartTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db; +package org.apache.ignite.internal.processors.cache.persistence.db; import java.io.File; import java.io.Serializable; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionDuringPartitionClearTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionDuringPartitionClearTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionDuringPartitionClearTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionDuringPartitionClearTest.java index b4ffde8c2cdc7..fb7113f45d4de 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionDuringPartitionClearTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionDuringPartitionClearTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db; +package org.apache.ignite.internal.processors.cache.persistence.db; import java.util.concurrent.Callable; import org.apache.ignite.Ignite; @@ -32,7 +32,7 @@ import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionTest.java index d48617d410b80..e8bc701caba88 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsPageEvictionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db; +package org.apache.ignite.internal.processors.cache.persistence.db; import java.io.Serializable; import java.util.List; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsRebalancingOnNotStableTopologyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsRebalancingOnNotStableTopologyTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsRebalancingOnNotStableTopologyTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsRebalancingOnNotStableTopologyTest.java index dfe174accc251..0724eb9e322e4 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsRebalancingOnNotStableTopologyTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsRebalancingOnNotStableTopologyTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db; +package org.apache.ignite.internal.processors.cache.persistence.db; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsTransactionsHangTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsTransactionsHangTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsTransactionsHangTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsTransactionsHangTest.java index 0007a3b9a6381..d4dfdec5c94c9 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsTransactionsHangTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsTransactionsHangTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db; +package org.apache.ignite.internal.processors.cache.persistence.db; import java.util.Random; import java.util.concurrent.CyclicBarrier; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsWholeClusterRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsWholeClusterRestartTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsWholeClusterRestartTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsWholeClusterRestartTest.java index 576b40e96c8a4..b512a64db399b 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/IgnitePdsWholeClusterRestartTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsWholeClusterRestartTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db; +package org.apache.ignite.internal.processors.cache.persistence.db; import java.util.ArrayList; import java.util.Collections; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsCacheIntegrationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsCacheIntegrationTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsCacheIntegrationTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsCacheIntegrationTest.java index 97bb05ef204f2..c68f7e79804b9 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsCacheIntegrationTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsCacheIntegrationTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.file; +package org.apache.ignite.internal.processors.cache.persistence.db.file; import java.io.Serializable; import java.util.List; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsEvictionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsEvictionTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsEvictionTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsEvictionTest.java index 45bcef651bbe8..1026d4e7df5b0 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsEvictionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsEvictionTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.file; +package org.apache.ignite.internal.processors.cache.persistence.db.file; import java.util.ArrayList; import java.util.Collection; @@ -33,8 +33,8 @@ import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.GridTestUtils; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsNoActualWalHistoryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsNoActualWalHistoryTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsNoActualWalHistoryTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsNoActualWalHistoryTest.java index 5a9da83ac2604..96316860bd94f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/IgnitePdsNoActualWalHistoryTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsNoActualWalHistoryTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.file; +package org.apache.ignite.internal.processors.cache.persistence.db.file; import java.util.HashMap; import java.util.Map; @@ -32,7 +32,7 @@ import org.apache.ignite.configuration.PersistentStoreConfiguration; import org.apache.ignite.configuration.WALMode; import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; import org.apache.ignite.internal.util.typedef.X; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/ignitePdsCheckpointSimulationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/ignitePdsCheckpointSimulationTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/ignitePdsCheckpointSimulationTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/ignitePdsCheckpointSimulationTest.java index b30162d3531a0..840042e16372b 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/file/ignitePdsCheckpointSimulationTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/ignitePdsCheckpointSimulationTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.file; +package org.apache.ignite.internal.processors.cache.persistence.db.file; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -47,12 +47,12 @@ import org.apache.ignite.internal.pagemem.PageIdAllocator; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.PageUtils; -import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; -import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.TrackingPageIO; 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; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgnitePdsWalTlbTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgnitePdsWalTlbTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgnitePdsWalTlbTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgnitePdsWalTlbTest.java index 03b1384d3faab..6ca0a1dca1228 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgnitePdsWalTlbTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgnitePdsWalTlbTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.wal; +package org.apache.ignite.internal.processors.cache.persistence.db.wal; import javax.cache.CacheException; import org.apache.ignite.IgniteDataStreamer; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalDirectoriesConfigurationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalDirectoriesConfigurationTest.java similarity index 96% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalDirectoriesConfigurationTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalDirectoriesConfigurationTest.java index 4cca40145bb73..97e70c2953fad 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalDirectoriesConfigurationTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalDirectoriesConfigurationTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.wal; +package org.apache.ignite.internal.processors.cache.persistence.db.wal; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalHistoryReservationsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalHistoryReservationsTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalHistoryReservationsTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalHistoryReservationsTest.java index fc46c2ec5e8e5..5f92100f39862 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalHistoryReservationsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalHistoryReservationsTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.wal; +package org.apache.ignite.internal.processors.cache.persistence.db.wal; import java.util.Map; import java.util.concurrent.locks.Lock; @@ -31,8 +31,8 @@ import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.util.lang.GridAbsPredicate; import org.apache.ignite.internal.util.typedef.G; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoverySeveralRestartsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalRecoverySeveralRestartsTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoverySeveralRestartsTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalRecoverySeveralRestartsTest.java index d70bea2c9554e..99b738339d309 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoverySeveralRestartsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalRecoverySeveralRestartsTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.wal; +package org.apache.ignite.internal.processors.cache.persistence.db.wal; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoveryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalRecoveryTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoveryTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalRecoveryTest.java index 4eb3d34bf44ea..f4c732bef4ba6 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/IgniteWalRecoveryTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalRecoveryTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.wal; +package org.apache.ignite.internal.processors.cache.persistence.db.wal; import java.io.File; import java.nio.ByteBuffer; @@ -58,9 +58,9 @@ import org.apache.ignite.internal.pagemem.wal.record.WALRecord; import org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; -import org.apache.ignite.internal.processors.cache.database.tree.io.TrackingPageIO; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.TrackingPageIO; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.PA; import org.apache.ignite.internal.util.typedef.PAX; @@ -183,6 +183,8 @@ public void testWalBig() throws Exception { try { IgniteEx ignite = startGrid(1); + ignite.active(true); + IgniteCache cache = ignite.cache("partitioned"); Random rnd = new Random(); @@ -208,6 +210,8 @@ public void testWalBig() throws Exception { ignite = startGrid(1); + ignite.active(true); + cache = ignite.cache("partitioned"); // Check. @@ -229,6 +233,8 @@ public void testSwitchClassLoader() throws Exception { // CustomDiscoveryMessage will trigger service tasks startGrid(2); + igniteEx.active(true); + IgniteCache cache = igniteEx.cache("partitioned"); // Creates LoadCacheJobV2 @@ -268,6 +274,8 @@ public void testWalSimple() throws Exception { try { IgniteEx ignite = startGrid(1); + ignite.active(true); + IgniteCache cache = ignite.cache("partitioned"); info(" --> step1"); @@ -310,6 +318,8 @@ else if (i % 2 == 0) ignite = startGrid(1); + ignite.active(true); + cache = ignite.cache("partitioned"); info(" --> check2"); @@ -344,6 +354,8 @@ public void testWalLargeValue() throws Exception { try { IgniteEx ignite = startGrid(1); + ignite.active(true); + IgniteCache cache = ignite.cache("partitioned"); for (int i = 0; i < 10_000; i++) { @@ -375,6 +387,8 @@ public void testWalLargeValue() throws Exception { ignite = startGrid(1); + ignite.active(true); + cache = ignite.cache("partitioned"); info(" --> check2"); @@ -422,6 +436,8 @@ public void testHugeCheckpointRecord() throws Exception { try { final IgniteEx ignite = startGrid(1); + ignite.active(true); + for (int i = 0; i < 50; i++) { CacheConfiguration ccfg = new CacheConfiguration<>("cache-" + i); @@ -473,6 +489,8 @@ private void checkWalRolloverMultithreaded() throws Exception { try { IgniteEx ignite = startGrid(1); + ignite.active(true); + final IgniteCache cache = ignite.cache("partitioned"); GridTestUtils.runMultiThreaded(new Callable() { @@ -498,6 +516,8 @@ public void testWalRenameDirSimple() throws Exception { try { IgniteEx ignite = startGrid(1); + ignite.active(true); + IgniteCache cache = ignite.cache("partitioned"); for (int i = 0; i < 100; i++) @@ -515,6 +535,8 @@ public void testWalRenameDirSimple() throws Exception { ignite = startGrid(1); + ignite.active(true); + cache = ignite.cache(cacheName); for (int i = 0; i < 100; i++) @@ -560,6 +582,8 @@ public void testRecoveryNoCheckpoint() throws Exception { IgniteEx cacheGrid = startGrid(1); + ctrlGrid.active(true); + ctrlGrid.compute(ctrlGrid.cluster().forRemotes()).run(new LoadRunnable(false)); info("Killing remote process..."); @@ -606,6 +630,8 @@ public void testRecoveryLargeNoCheckpoint() throws Exception { IgniteEx cacheGrid = startGrid(1); + ctrlGrid.active(true); + ctrlGrid.compute(ctrlGrid.cluster().forRemotes()).run(new LargeLoadRunnable(false)); info("Killing remote process..."); @@ -659,6 +685,8 @@ public void testRandomCrash() throws Exception { IgniteEx cacheGrid = startGrid(1); + ctrlGrid.active(true); + IgniteCompute rmt = ctrlGrid.compute(ctrlGrid.cluster().forRemotes()); rmt.run(new LoadRunnable(false)); @@ -695,6 +723,8 @@ public void testLargeRandomCrash() throws Exception { IgniteEx cacheGrid = startGrid(1); + ctrlGrid.active(true); + IgniteCompute rmt = ctrlGrid.compute(ctrlGrid.cluster().forRemotes()); rmt.run(new LargeLoadRunnable(false)); @@ -737,6 +767,8 @@ public void testDestroyCache() throws Exception { try { IgniteEx ignite = startGrid(1); + ignite.active(true); + IgniteCache cache = ignite.getOrCreateCache("test"); cache.put(1, new IndexedObject(1)); @@ -760,6 +792,8 @@ public void testEvictPartition() throws Exception { try { Ignite ignite1 = startGrid("node1"); + ignite1.active(true); + IgniteCache cache1 = ignite1.cache(cacheName); for (int i = 0; i < 100; i++) @@ -780,6 +814,8 @@ public void testEvictPartition() throws Exception { ignite1 = startGrid("node1"); ignite2 = startGrid("node2"); + ignite1.active(true); + cache1 = ignite1.cache(cacheName); cache2 = ignite2.cache(cacheName); @@ -800,6 +836,8 @@ public void testApplyDeltaRecords() throws Exception { try { IgniteEx ignite0 = (IgniteEx)startGrid("node0"); + ignite0.active(true); + IgniteCache cache0 = ignite0.cache(cacheName); for (int i = 0; i < 1000; i++) diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/WalRecoveryTxLogicalRecordsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalRecoveryTxLogicalRecordsTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/WalRecoveryTxLogicalRecordsTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalRecoveryTxLogicalRecordsTest.java index 30a7f9ea827eb..205e0fce95f99 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/WalRecoveryTxLogicalRecordsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalRecoveryTxLogicalRecordsTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.wal; +package org.apache.ignite.internal.processors.cache.persistence.db.wal; import java.io.File; import java.util.ArrayList; @@ -48,12 +48,12 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager; import org.apache.ignite.internal.processors.cache.IgniteRebalanceIterator; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; -import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl; -import org.apache.ignite.internal.processors.cache.database.freelist.PagesList; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseListImpl; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager; +import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeListImpl; +import org.apache.ignite.internal.processors.cache.persistence.freelist.PagesList; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseListImpl; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.T2; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/crc/IgniteDataIntegrityTests.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/crc/IgniteDataIntegrityTests.java similarity index 91% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/crc/IgniteDataIntegrityTests.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/crc/IgniteDataIntegrityTests.java index c40a4ed8b1f14..303f14e0992f6 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/db/wal/crc/IgniteDataIntegrityTests.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/crc/IgniteDataIntegrityTests.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.db.wal.crc; +package org.apache.ignite.internal.processors.cache.persistence.db.wal.crc; import junit.framework.TestCase; import java.io.EOFException; @@ -24,9 +24,9 @@ import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.util.concurrent.ThreadLocalRandom; -import org.apache.ignite.internal.processors.cache.database.wal.FileInput; -import org.apache.ignite.internal.processors.cache.database.wal.crc.IgniteDataIntegrityViolationException; -import org.apache.ignite.internal.processors.cache.database.wal.crc.PureJavaCrc32; +import org.apache.ignite.internal.processors.cache.persistence.wal.FileInput; +import org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException; +import org.apache.ignite.internal.processors.cache.persistence.wal.crc.PureJavaCrc32; /** * diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreePageMemoryImplTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/BPlusTreePageMemoryImplTest.java similarity index 87% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreePageMemoryImplTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/BPlusTreePageMemoryImplTest.java index a35903c9e6023..6f58782f5197a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreePageMemoryImplTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/BPlusTreePageMemoryImplTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import java.nio.ByteBuffer; import org.apache.ignite.configuration.MemoryPolicyConfiguration; @@ -24,11 +24,9 @@ import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.persistence.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; import org.apache.ignite.internal.processors.database.BPlusTreeSelfTest; import org.apache.ignite.internal.util.typedef.CIX3; import org.apache.ignite.testframework.junits.GridTestKernalContext; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/BPlusTreeReuseListPageMemoryImplTest.java similarity index 87% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/BPlusTreeReuseListPageMemoryImplTest.java index 5c4502c187e34..b263d4f81ff17 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/BPlusTreeReuseListPageMemoryImplTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/BPlusTreeReuseListPageMemoryImplTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import java.nio.ByteBuffer; import org.apache.ignite.configuration.MemoryPolicyConfiguration; @@ -24,11 +24,9 @@ import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.persistence.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; import org.apache.ignite.internal.processors.database.BPlusTreeReuseSelfTest; import org.apache.ignite.internal.util.lang.GridInClosure3X; import org.apache.ignite.internal.util.typedef.CIX3; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/FullPageIdTableTest.java similarity index 95% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/FullPageIdTableTest.java index df212be915a52..1f29549faf5a0 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/FullPageIdTableTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/FullPageIdTableTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import java.util.HashMap; import java.util.Map; @@ -23,7 +23,7 @@ import org.apache.ignite.internal.mem.DirectMemoryRegion; import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; import org.apache.ignite.internal.pagemem.FullPageId; -import org.apache.ignite.internal.processors.cache.database.pagemem.FullPageIdTable; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.FullPageIdTable; import org.apache.ignite.internal.util.typedef.CI2; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.logger.java.JavaLogger; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/MetadataStoragePageMemoryImplTest.java similarity index 88% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/MetadataStoragePageMemoryImplTest.java index a6e241c21dbe4..d9257bd3c444b 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/MetadataStoragePageMemoryImplTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/MetadataStoragePageMemoryImplTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import java.io.File; import java.nio.ByteBuffer; @@ -25,11 +25,9 @@ import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.persistence.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; import org.apache.ignite.internal.processors.database.MetadataStorageSelfTest; import org.apache.ignite.internal.util.lang.GridInClosure3X; import org.apache.ignite.internal.util.typedef.CIX3; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/NoOpWALManager.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/NoOpWALManager.java index f3e1cd39b43dd..0ef593f7d604b 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpWALManager.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/NoOpWALManager.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.GridKernalContext; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageIdDistributionTest.java similarity index 96% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageIdDistributionTest.java index a37f981ad1af8..1a8aaa455f44c 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageIdDistributionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageIdDistributionTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import java.io.FileOutputStream; import java.io.OutputStreamWriter; @@ -29,8 +29,8 @@ import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider; import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.pagemem.PageIdUtils; -import org.apache.ignite.internal.processors.cache.database.pagemem.FullPageIdTable; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.FullPageIdTable; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl; import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryImplNoLoadTest.java similarity index 88% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryImplNoLoadTest.java index 38baea8cf73b6..1fff1f023ee80 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplNoLoadTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryImplNoLoadTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import java.io.File; import java.nio.ByteBuffer; @@ -26,12 +26,10 @@ import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.impl.PageMemoryNoLoadSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.persistence.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; import org.apache.ignite.internal.util.lang.GridInClosure3X; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager; import org.apache.ignite.internal.util.typedef.CIX3; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.junits.GridTestKernalContext; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryImplTest.java similarity index 89% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryImplTest.java index b5e4549a6acb5..0366eca6a263a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/PageMemoryImplTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PageMemoryImplTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.pagemem; +package org.apache.ignite.internal.processors.cache.persistence.pagemem; import java.nio.ByteBuffer; import org.apache.ignite.configuration.MemoryPolicyConfiguration; @@ -25,11 +25,9 @@ import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.pagemem.PageIdAllocator; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.database.CheckpointLockStateChecker; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx; -import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl; +import org.apache.ignite.internal.processors.cache.persistence.CheckpointLockStateChecker; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; import org.apache.ignite.internal.util.lang.GridInClosure3X; import org.apache.ignite.internal.util.typedef.CIX3; import org.apache.ignite.testframework.junits.GridTestKernalContext; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/AbstractNodeJoinTemplate.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/AbstractNodeJoinTemplate.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java index 112ea03b23e72..76a5260a90a5a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/AbstractNodeJoinTemplate.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster; import java.util.ArrayList; import java.util.Arrays; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateAbstractTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateAbstractTest.java index 5bc5c3ae25f13..d16b845796c26 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateAbstractTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster; import java.util.ArrayList; import java.util.List; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateCacheTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateCacheTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateCacheTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateCacheTest.java index ebbab5885efc4..1dc99f90deb15 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateCacheTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateCacheTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster; import javax.cache.configuration.Configuration; import org.apache.ignite.Ignite; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java index bd655976a95d3..f13ef97257035 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStructureTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateDataStructureTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStructureTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateDataStructureTest.java index d10521e0ea485..901322664ade6 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStructureTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateDataStructureTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicInteger; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateFailOverTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateFailOverTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateFailOverTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateFailOverTest.java index 53a2eec30cf42..bb05048af537a 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateFailOverTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateFailOverTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateServiceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateServiceTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateServiceTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateServiceTest.java index da4d20cc50620..44e03573f949e 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateServiceTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateServiceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster; import java.util.Collection; import org.apache.ignite.Ignite; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateTest.java index d87ec5ef62339..4d5eba797fa83 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster; import java.util.Arrays; import java.util.List; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteStandByClusterTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteStandByClusterTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java index b248208b08319..2d704db44d137 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteStandByClusterTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster; import java.util.Arrays; import java.util.Map; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivateExtensionTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivateExtensionTest.java index 1baf4a5704e01..4f4d838aeaeda 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivateExtensionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivateExtensionTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.extended; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.extended; import java.lang.reflect.Method; import java.util.LinkedHashMap; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationAtomicCacheSuit.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationAtomicCacheSuit.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationAtomicCacheSuit.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationAtomicCacheSuit.java index 397d8d0085a01..99b1152ce84f9 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationAtomicCacheSuit.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationAtomicCacheSuit.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.extended; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.extended; import junit.framework.TestSuite; import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAtomicFullApiSelfTest; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationCacheAbstractTestSuit.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationCacheAbstractTestSuit.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationCacheAbstractTestSuit.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationCacheAbstractTestSuit.java index 553546a313fc2..9380745c26e8c 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationCacheAbstractTestSuit.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationCacheAbstractTestSuit.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.extended; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.extended; import java.io.IOException; import java.util.ArrayList; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java similarity index 95% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java index b6ef49ceace31..4eb8a38fb595d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationLocalAndNearCacheSuit.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.extended; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.extended; import junit.framework.TestSuite; import org.apache.ignite.internal.processors.cache.local.GridCacheLocalAtomicFullApiSelfTest; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationPartitionedCacheSuit.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationPartitionedCacheSuit.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationPartitionedCacheSuit.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationPartitionedCacheSuit.java index fc437ada6b58f..c74aadac30a7f 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationPartitionedCacheSuit.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationPartitionedCacheSuit.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.extended; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.extended; import junit.framework.TestSuite; import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedNearDisabledFullApiSelfTest; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationReplicatedCacheSuit.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationReplicatedCacheSuit.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationReplicatedCacheSuit.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationReplicatedCacheSuit.java index 6cdc87bd4c92a..127fe9a2120d1 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/extended/GridActivationReplicatedCacheSuit.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationReplicatedCacheSuit.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.extended; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.extended; import junit.framework.TestSuite; import org.apache.ignite.internal.processors.cache.distributed.replicated.CacheReplicatedRendezvousAffinityExcludeNeighborsMultiNodeFullApiSelfTest; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToActiveCluster.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToActiveCluster.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToActiveCluster.java index 6042267aa4080..fc9d307e3ba73 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToActiveCluster.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToActiveCluster.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.join; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.join; import java.util.Map; -import org.apache.ignite.cache.database.standbycluster.AbstractNodeJoinTemplate; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToInActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToInActiveCluster.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToInActiveCluster.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToInActiveCluster.java index 62ab114f1046f..b248b210804f3 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinActiveNodeToInActiveCluster.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToInActiveCluster.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.join; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.join; -import org.apache.ignite.cache.database.standbycluster.AbstractNodeJoinTemplate; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; /** * diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToActiveCluster.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToActiveCluster.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToActiveCluster.java index d0cc7b39cbeba..6ba3a2020d171 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToActiveCluster.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToActiveCluster.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.join; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.join; import java.util.Map; -import org.apache.ignite.cache.database.standbycluster.AbstractNodeJoinTemplate; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToInActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToInActiveCluster.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToInActiveCluster.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToInActiveCluster.java index 7333c2e860a7b..244001bf1c486 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/JoinInActiveNodeToInActiveCluster.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToInActiveCluster.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.join; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.join; -import org.apache.ignite.cache.database.standbycluster.AbstractNodeJoinTemplate; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; /** * diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java similarity index 56% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java index fc4b5ce2aaf78..54087ba883e1d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java @@ -15,10 +15,11 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.join.persistence; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.persistence; -import org.apache.ignite.cache.database.standbycluster.join.JoinActiveNodeToActiveCluster; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinActiveNodeToActiveCluster; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; /** * @@ -29,7 +30,7 @@ public class JoinActiveNodeToActiveClusterWithPersistence extends JoinActiveNode return persistentCfg(super.cfg(name)); } - private JoinNodeTestPlanBuilder persistent(JoinNodeTestPlanBuilder b) { + private AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder persistent(AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b) { b.afterClusterStarted( b.checkCacheEmpty() ).stateAfterJoin( @@ -43,16 +44,16 @@ private JoinNodeTestPlanBuilder persistent(JoinNodeTestPlanBuilder b) { return b; } - @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { - JoinNodeTestPlanBuilder b = persistent(super.withOutConfigurationTemplate()); + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.withOutConfigurationTemplate()); b.afterActivate(b.checkCacheOnlySystem()); return b; } - @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { - JoinNodeTestPlanBuilder b = persistent(super.joinClientWithOutConfigurationTemplate()); + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.joinClientWithOutConfigurationTemplate()); b.afterActivate(b.checkCacheOnlySystem()); @@ -67,31 +68,31 @@ private JoinNodeTestPlanBuilder persistent(JoinNodeTestPlanBuilder b) { joinClientWithOutConfigurationTemplate().execute(); } - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { return persistent(super.staticCacheConfigurationOnJoinTemplate()); } - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { return persistent(super.staticCacheConfigurationInClusterTemplate()); } - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { return persistent(super.staticCacheConfigurationSameOnBothTemplate()); } - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { return persistent(super.staticCacheConfigurationDifferentOnBothTemplate()); } - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { return persistent(super.joinClientStaticCacheConfigurationOnJoinTemplate()); } - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { return persistent(super.joinClientStaticCacheConfigurationInClusterTemplate()); } - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { return persistent(super.joinClientStaticCacheConfigurationDifferentOnBothTemplate()); } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java similarity index 84% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java index 9981322b61f2b..305255c95c214 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.join.persistence; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.persistence; -import org.apache.ignite.cache.database.standbycluster.join.JoinActiveNodeToInActiveCluster; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinActiveNodeToInActiveCluster; import org.apache.ignite.configuration.IgniteConfiguration; /** diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java similarity index 54% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java index 4731647bbef88..a138d8dcdb8cd 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java @@ -15,10 +15,11 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.join.persistence; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.persistence; -import org.apache.ignite.cache.database.standbycluster.join.JoinInActiveNodeToActiveCluster; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinInActiveNodeToActiveCluster; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; /** * @@ -29,7 +30,7 @@ public class JoinInActiveNodeToActiveClusterWithPersistence extends JoinInActive return persistentCfg(super.cfg(name)); } - private JoinNodeTestPlanBuilder persistent(JoinNodeTestPlanBuilder b) { + private AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder persistent(AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b) { b.afterClusterStarted( b.checkCacheEmpty() ).stateAfterJoin( @@ -43,43 +44,43 @@ private JoinNodeTestPlanBuilder persistent(JoinNodeTestPlanBuilder b) { return b; } - @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { - JoinNodeTestPlanBuilder b = persistent(super.withOutConfigurationTemplate()); + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.withOutConfigurationTemplate()); b.afterActivate(b.checkCacheOnlySystem()); return b; } - @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { - JoinNodeTestPlanBuilder b = persistent(super.joinClientWithOutConfigurationTemplate()); + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.joinClientWithOutConfigurationTemplate()); b.afterActivate(b.checkCacheOnlySystem()); return b; } - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception{ + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception{ return persistent(super.joinClientStaticCacheConfigurationInClusterTemplate()); } - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { return persistent(super.joinClientStaticCacheConfigurationDifferentOnBothTemplate()); } - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { return persistent(super.staticCacheConfigurationOnJoinTemplate()); } - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { return persistent(super.staticCacheConfigurationInClusterTemplate()); } - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { return persistent(super.staticCacheConfigurationSameOnBothTemplate()); } - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { return persistent(super.staticCacheConfigurationDifferentOnBothTemplate()); } } diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java similarity index 84% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java index 01154b154e1d2..b3db10d045e34 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.join.persistence; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.persistence; -import org.apache.ignite.cache.database.standbycluster.join.JoinInActiveNodeToInActiveCluster; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinInActiveNodeToInActiveCluster; import org.apache.ignite.configuration.IgniteConfiguration; /** diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java similarity index 99% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java index e5f34f84f1862..eec267b5ed208 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.reconnect; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.reconnect; import com.google.common.collect.Sets; import java.util.Collection; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectTest.java index 1266f8940c114..02f7d000e5853 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.reconnect; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.reconnect; import java.util.concurrent.CountDownLatch; import org.apache.ignite.internal.IgniteEx; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java similarity index 98% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java index d0933feed81ff..2bcc177796dd6 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database.standbycluster.reconnect; +package org.apache.ignite.internal.processors.cache.persistence.standbycluster.reconnect; import com.google.common.collect.Sets; import java.util.Collections; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIOTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/TrackingPageIOTest.java similarity index 99% rename from modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIOTest.java rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/TrackingPageIOTest.java index e2767bbbf8327..b50f0262fdab1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIOTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/tree/io/TrackingPageIOTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.cache.database.tree.io; +package org.apache.ignite.internal.processors.cache.persistence.tree.io; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeFakeReuseSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeFakeReuseSelfTest.java index 83a07ab255438..cab54a45319ba 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeFakeReuseSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeFakeReuseSelfTest.java @@ -20,8 +20,8 @@ import java.util.concurrent.ConcurrentLinkedDeque; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseBag; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseBag; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; /** * diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java index e5375f7547246..d12c92fd8102f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java @@ -22,9 +22,9 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseListImpl; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseListImpl; import static org.apache.ignite.internal.pagemem.PageIdUtils.effectivePageId; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java index a46242cc09042..fadfc23e3710d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java @@ -41,15 +41,15 @@ import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl; -import org.apache.ignite.internal.processors.cache.database.DataStructure; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.DataStructure; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; import org.apache.ignite.internal.util.GridConcurrentHashSet; import org.apache.ignite.internal.util.GridRandom; import org.apache.ignite.internal.util.GridStripedLock; @@ -65,7 +65,7 @@ import org.jsr166.ConcurrentLinkedHashMap; import static org.apache.ignite.internal.pagemem.PageIdUtils.effectivePageId; -import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.rnd; +import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.rnd; import static org.apache.ignite.internal.util.IgniteTree.OperationType.NOOP; import static org.apache.ignite.internal.util.IgniteTree.OperationType.PUT; import static org.apache.ignite.internal.util.IgniteTree.OperationType.REMOVE; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java index 7ccddb711635e..d650ac15a789a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java @@ -39,12 +39,12 @@ import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.MemoryPolicy; -import org.apache.ignite.internal.processors.cache.database.evict.NoOpPageEvictionTracker; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeList; -import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.MemoryPolicy; +import org.apache.ignite.internal.processors.cache.persistence.evict.NoOpPageEvictionTracker; +import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList; +import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeListImpl; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.plugin.extensions.communication.MessageReader; import org.apache.ignite.plugin.extensions.communication.MessageWriter; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java index 723c5965bc479..2245a4dc79d64 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java @@ -24,7 +24,7 @@ import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.MemoryConfiguration; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java index 0a6e9f8bc6e80..93e5181093032 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbMemoryLeakAbstractTest.java @@ -25,7 +25,7 @@ import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.IgniteCacheProxy; -import org.apache.ignite.internal.processors.cache.database.DataStructure; +import org.apache.ignite.internal.processors.cache.persistence.DataStructure; import static org.apache.ignite.IgniteSystemProperties.getInteger; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MemoryMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MemoryMetricsSelfTest.java index 3a99cb24c12b3..f9a9824bb7985 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MemoryMetricsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MemoryMetricsSelfTest.java @@ -19,7 +19,7 @@ import java.util.concurrent.CountDownLatch; import org.apache.ignite.MemoryMetrics; import org.apache.ignite.configuration.MemoryPolicyConfiguration; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import static java.lang.Thread.sleep; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MetadataStorageSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MetadataStorageSelfTest.java index 52064722c9400..dcd4ce196a2cf 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MetadataStorageSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/MetadataStorageSelfTest.java @@ -28,11 +28,11 @@ import org.apache.ignite.internal.pagemem.FullPageId; import org.apache.ignite.internal.pagemem.PageIdAllocator; import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; -import org.apache.ignite.internal.processors.cache.database.MetadataStorage; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.MetadataStorage; import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider; import org.apache.ignite.internal.pagemem.PageMemory; -import org.apache.ignite.internal.processors.cache.database.RootPage; +import org.apache.ignite.internal.processors.cache.persistence.RootPage; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java index 310082da5b40a..12200ae0a5c48 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java @@ -18,7 +18,6 @@ package org.apache.ignite.loadtests.hashmap; import java.util.IdentityHashMap; -import java.util.UUID; import org.apache.ignite.cache.store.CacheStore; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; @@ -35,9 +34,9 @@ import org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.GridCacheTtlManager; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager; import org.apache.ignite.internal.processors.cache.GridCacheSharedTtlCleanupManager; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheSnapshotManager; import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager; import org.apache.ignite.internal.processors.cache.dr.GridOsCacheDrManager; import org.apache.ignite.internal.processors.cache.jta.CacheNoopJtaManager; diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java index 943c5f5c63494..46d5498f34cea 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java @@ -45,7 +45,7 @@ import org.apache.ignite.internal.processors.cache.IgniteDynamicCacheAndNodeStop; import org.apache.ignite.internal.processors.cache.IgniteOnePhaseCommitInvokeTest; import org.apache.ignite.internal.processors.cache.MemoryPolicyConfigValidationTest; -import org.apache.ignite.internal.processors.cache.database.MemoryPolicyInitializationTest; +import org.apache.ignite.internal.processors.cache.persistence.MemoryPolicyInitializationTest; import org.apache.ignite.internal.processors.cache.distributed.CacheLoadingConcurrentGridStartSelfTest; import org.apache.ignite.internal.processors.cache.distributed.CacheLoadingConcurrentGridStartSelfTestAllowOverwrite; import org.apache.ignite.internal.processors.cache.distributed.CacheLockReleaseNodeLeaveTest; diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java similarity index 93% rename from modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java rename to modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java index 59b7f393ae176..3e040f4db7ce4 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsOutOfMemoryTestSuite.java @@ -18,7 +18,7 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; -import org.apache.ignite.cache.database.db.wal.IgnitePdsWalTlbTest; +import org.apache.ignite.internal.processors.cache.persistence.db.wal.IgnitePdsWalTlbTest; /** * diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java similarity index 62% rename from modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java rename to modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java index d0c55c9fd8df0..59e7ae9f3ed91 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java @@ -18,30 +18,26 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; -import org.apache.ignite.cache.database.IgnitePersistentStoreCacheGroupsTest; -import org.apache.ignite.cache.database.IgnitePdsClientNearCachePutGetTest; -import org.apache.ignite.cache.database.IgnitePdsDynamicCacheTest; -import org.apache.ignite.cache.database.IgnitePdsSingleNodePutGetPersistenceTest; -import org.apache.ignite.cache.database.IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest; -import org.apache.ignite.cache.database.IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest; -import org.apache.ignite.cache.database.db.IgnitePdsMultiNodePutGetRestartTest; -import org.apache.ignite.cache.database.db.IgnitePdsPageEvictionTest; -import org.apache.ignite.cache.database.db.file.IgnitePdsCacheIntegrationTest; -import org.apache.ignite.cache.database.db.wal.IgniteWalDirectoriesConfigurationTest; -import org.apache.ignite.cache.database.db.file.ignitePdsCheckpointSimulationTest; -import org.apache.ignite.cache.database.db.file.IgnitePdsEvictionTest; -import org.apache.ignite.cache.database.pagemem.BPlusTreeReuseListPageMemoryImplTest; -import org.apache.ignite.cache.database.pagemem.BPlusTreePageMemoryImplTest; -import org.apache.ignite.cache.database.pagemem.MetadataStoragePageMemoryImplTest; -import org.apache.ignite.cache.database.pagemem.PageMemoryImplNoLoadTest; -import org.apache.ignite.cache.database.pagemem.PageMemoryImplTest; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsClientNearCachePutGetTest; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDynamicCacheTest; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsSingleNodePutGetPersistenceTest; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePersistentStoreCacheGroupsTest; +import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsMultiNodePutGetRestartTest; +import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsPageEvictionTest; +import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsCacheIntegrationTest; +import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsEvictionTest; +import org.apache.ignite.internal.processors.cache.persistence.db.file.ignitePdsCheckpointSimulationTest; +import org.apache.ignite.internal.processors.cache.persistence.db.wal.IgniteWalDirectoriesConfigurationTest; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.BPlusTreePageMemoryImplTest; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.BPlusTreeReuseListPageMemoryImplTest; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.MetadataStoragePageMemoryImplTest; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImplNoLoadTest; +import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImplTest; import org.apache.ignite.internal.processors.database.IgniteDbClientNearCachePutGetTest; import org.apache.ignite.internal.processors.database.IgniteDbDynamicCacheSelfTest; import org.apache.ignite.internal.processors.database.IgniteDbMultiNodePutGetTest; -import org.apache.ignite.internal.processors.database.IgniteDbMultiNodeWithIndexingPutGetTest; import org.apache.ignite.internal.processors.database.IgniteDbSingleNodePutGetTest; import org.apache.ignite.internal.processors.database.IgniteDbSingleNodeTinyPutGetTest; -import org.apache.ignite.internal.processors.database.IgniteDbSingleNodeWithIndexingPutGetTest; /** @@ -71,9 +67,7 @@ public static TestSuite suite() throws Exception { // Basic API tests. suite.addTestSuite(IgniteDbSingleNodePutGetTest.class); - suite.addTestSuite(IgniteDbSingleNodeWithIndexingPutGetTest.class); suite.addTestSuite(IgniteDbMultiNodePutGetTest.class); - suite.addTestSuite(IgniteDbMultiNodeWithIndexingPutGetTest.class); suite.addTestSuite(IgniteDbSingleNodeTinyPutGetTest.class); suite.addTestSuite(IgniteDbDynamicCacheSelfTest.class); suite.addTestSuite(IgniteDbClientNearCachePutGetTest.class); @@ -81,8 +75,6 @@ public static TestSuite suite() throws Exception { // Persistence-enabled. suite.addTestSuite(IgnitePdsMultiNodePutGetRestartTest.class); suite.addTestSuite(IgnitePdsSingleNodePutGetPersistenceTest.class); - suite.addTestSuite(IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.class); - suite.addTestSuite(IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.class); suite.addTestSuite(IgnitePdsPageEvictionTest.class); suite.addTestSuite(IgnitePdsDynamicCacheTest.class); suite.addTestSuite(IgniteWalDirectoriesConfigurationTest.class); diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java similarity index 59% rename from modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java rename to modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java index acfac6386d60c..f645dba2b14b3 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java @@ -18,23 +18,22 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; -import org.apache.ignite.cache.database.IgnitePdsAtomicCacheRebalancingTest; -import org.apache.ignite.cache.database.IgnitePdsTxCacheRebalancingTest; -import org.apache.ignite.cache.database.IgnitePdsContinuousRestartTest; -import org.apache.ignite.cache.database.IgnitePdsPageSizesTest; -import org.apache.ignite.cache.database.IgnitePdsRecoveryAfterFileCorruptionTest; -import org.apache.ignite.cache.database.IgnitePersistenceMetricsSelfTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreDataStructuresTest; -import org.apache.ignite.cache.database.IgnitePersistentStoreSchemaLoadTest; -import org.apache.ignite.cache.database.db.IgnitePdsPageEvictionDuringPartitionClearTest; -import org.apache.ignite.cache.database.db.IgnitePdsTransactionsHangTest; -import org.apache.ignite.cache.database.db.IgnitePdsWholeClusterRestartTest; -import org.apache.ignite.cache.database.db.IgnitePdsRebalancingOnNotStableTopologyTest; -import org.apache.ignite.cache.database.db.file.IgnitePdsNoActualWalHistoryTest; -import org.apache.ignite.cache.database.db.wal.IgniteWalHistoryReservationsTest; -import org.apache.ignite.cache.database.db.wal.IgniteWalRecoveryTest; -import org.apache.ignite.cache.database.db.wal.WalRecoveryTxLogicalRecordsTest; -import org.apache.ignite.cache.database.db.wal.crc.IgniteDataIntegrityTests; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsAtomicCacheRebalancingTest; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsTxCacheRebalancingTest; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsContinuousRestartTest; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsPageSizesTest; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsRecoveryAfterFileCorruptionTest; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePersistenceMetricsSelfTest; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePersistentStoreDataStructuresTest; +import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsPageEvictionDuringPartitionClearTest; +import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsTransactionsHangTest; +import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsWholeClusterRestartTest; +import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsRebalancingOnNotStableTopologyTest; +import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsNoActualWalHistoryTest; +import org.apache.ignite.internal.processors.cache.persistence.db.wal.IgniteWalHistoryReservationsTest; +import org.apache.ignite.internal.processors.cache.persistence.db.wal.IgniteWalRecoveryTest; +import org.apache.ignite.internal.processors.cache.persistence.db.wal.WalRecoveryTxLogicalRecordsTest; +import org.apache.ignite.internal.processors.cache.persistence.db.wal.crc.IgniteDataIntegrityTests; /** * @@ -76,7 +75,6 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(IgnitePdsContinuousRestartTest.class); - suite.addTestSuite(IgnitePersistentStoreSchemaLoadTest.class); suite.addTestSuite(IgnitePersistentStoreDataStructuresTest.class); return suite; diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java similarity index 73% rename from modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java rename to modules/core/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java index 1d0754be870e9..b120c62b69039 100644 --- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java @@ -18,11 +18,11 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; -import org.apache.ignite.cache.database.standbycluster.IgniteChangeGlobalStateCacheTest; -import org.apache.ignite.cache.database.standbycluster.IgniteChangeGlobalStateDataStreamerTest; -import org.apache.ignite.cache.database.standbycluster.IgniteChangeGlobalStateDataStructureTest; -import org.apache.ignite.cache.database.standbycluster.IgniteChangeGlobalStateFailOverTest; -import org.apache.ignite.cache.database.standbycluster.IgniteChangeGlobalStateTest; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.IgniteChangeGlobalStateCacheTest; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.IgniteChangeGlobalStateDataStreamerTest; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.IgniteChangeGlobalStateDataStructureTest; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.IgniteChangeGlobalStateFailOverTest; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.IgniteChangeGlobalStateTest; /** * diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index ddd0c59e2742f..2a7e8885ce721 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -72,7 +72,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException; import org.apache.ignite.internal.processors.cache.QueryCursorImpl; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException; import org.apache.ignite.internal.processors.cache.query.CacheQueryPartitionInfo; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java index 0440615a9fe26..2ae5868a97afb 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java @@ -26,7 +26,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java index 86b27492af624..2e57ca34af6b1 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java @@ -21,7 +21,7 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.internal.pagemem.PageIdUtils; import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.database.CacheDataRowAdapter; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row; import org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java index f2b8badfef85e..b60328dc74370 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java @@ -23,10 +23,10 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusMetaIO; -import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; import org.apache.ignite.internal.processors.query.h2.database.io.H2ExtrasInnerIO; import org.apache.ignite.internal.processors.query.h2.database.io.H2ExtrasLeafIO; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java index e7ce50ecb8e64..70d8632a8b54a 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java @@ -24,9 +24,9 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.database.RootPage; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.RootPage; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.processors.query.h2.H2Cursor; import org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2ExtrasInnerIO.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2ExtrasInnerIO.java index 5e6a36fdbcc89..0e8407ca8ea66 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2ExtrasInnerIO.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2ExtrasInnerIO.java @@ -20,11 +20,11 @@ import java.util.List; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageUtils; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.processors.query.h2.database.H2Tree; import org.apache.ignite.internal.processors.query.h2.database.InlineIndexHelper; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2ExtrasLeafIO.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2ExtrasLeafIO.java index c4bb3872da92f..4a6873909358c 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2ExtrasLeafIO.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2ExtrasLeafIO.java @@ -20,11 +20,11 @@ import java.util.List; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageUtils; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; -import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; import org.apache.ignite.internal.processors.query.h2.database.H2Tree; import org.apache.ignite.internal.processors.query.h2.database.InlineIndexHelper; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2InnerIO.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2InnerIO.java index 8252a6914d529..4d7b3a2f03bdb 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2InnerIO.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2InnerIO.java @@ -19,10 +19,10 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageUtils; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; import org.apache.ignite.internal.processors.query.h2.database.H2Tree; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row; import org.h2.result.SearchRow; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2LeafIO.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2LeafIO.java index a24eb99e9926e..f292fc10b0ad9 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2LeafIO.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2LeafIO.java @@ -19,10 +19,10 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageUtils; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO; -import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; import org.apache.ignite.internal.processors.query.h2.database.H2Tree; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row; import org.h2.result.SearchRow; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Row.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Row.java index 7de6740f6f40f..bd64bce721ba7 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Row.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Row.java @@ -19,7 +19,7 @@ import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.h2.result.Row; import org.h2.result.SearchRow; diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheLockPartitionOnAffinityRunTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheLockPartitionOnAffinityRunTest.java index 48a61ccea80da..33a9b850846c1 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheLockPartitionOnAffinityRunTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheLockPartitionOnAffinityRunTest.java @@ -35,7 +35,7 @@ import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.database.CacheDataRow; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition; import org.apache.ignite.internal.util.lang.GridCursor; import org.apache.ignite.lang.IgniteBiPredicate; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java similarity index 96% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java rename to modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java index 257e0e840cfb1..2d566a0733d7d 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache; import org.apache.ignite.cache.affinity.AffinityFunction; import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.java rename to modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.java index a18ba75caa747..7e7b9e6fbc6f5 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.cache; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodeWithIndexingPutGetTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodeWithIndexingPutGetTest.java index 46a24a034e375..2971fff3e9767 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodeWithIndexingPutGetTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodeWithIndexingPutGetTest.java @@ -32,7 +32,6 @@ import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.S; diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgnitePersistentStoreSchemaLoadTest.java similarity index 97% rename from modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java rename to modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgnitePersistentStoreSchemaLoadTest.java index bed17ac7aa32c..927de07beef67 100644 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgnitePersistentStoreSchemaLoadTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ignite.cache.database; +package org.apache.ignite.internal.processors.database; import java.io.Serializable; import java.util.Arrays; @@ -34,8 +34,8 @@ import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; -import org.apache.ignite.internal.processors.cache.database.DbCheckpointListener; -import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.DbCheckpointListener; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing; import org.apache.ignite.internal.util.lang.GridAbsPredicate; import org.apache.ignite.internal.util.typedef.internal.U; diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java index c101d0423e385..25790234f0a65 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java @@ -29,7 +29,7 @@ import org.apache.ignite.internal.pagemem.PageIdAllocator; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl; -import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl; +import org.apache.ignite.internal.processors.cache.persistence.MemoryMetricsImpl; import org.apache.ignite.logger.java.JavaLogger; import org.h2.result.SortOrder; import org.h2.value.CompareMode; diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingTestSuite.java new file mode 100644 index 0000000000000..cb3cd1b3e5e24 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingTestSuite.java @@ -0,0 +1,46 @@ +/* + * 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.testsuites; + +import junit.framework.TestSuite; +import org.apache.ignite.internal.processors.cache.IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest; +import org.apache.ignite.internal.processors.cache.IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest; +import org.apache.ignite.internal.processors.database.IgniteDbMultiNodeWithIndexingPutGetTest; +import org.apache.ignite.internal.processors.database.IgniteDbSingleNodeWithIndexingPutGetTest; +import org.apache.ignite.internal.processors.database.IgnitePersistentStoreSchemaLoadTest; + +/** + * + */ +public class IgnitePdsWithIndexingTestSuite extends TestSuite { + /** + * @return Test suite. + * @throws Exception Thrown in case of the failure. + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("Ignite Db Memory Leaks With Indexing Test Suite"); + + suite.addTestSuite(IgniteDbSingleNodeWithIndexingPutGetTest.class); + suite.addTestSuite(IgniteDbMultiNodeWithIndexingPutGetTest.class); + suite.addTestSuite(IgnitePdsSingleNodeWithIndexingPutGetPersistenceTest.class); + suite.addTestSuite(IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.class); + suite.addTestSuite(IgnitePersistentStoreSchemaLoadTest.class); + + return suite; + } +} diff --git a/modules/pds/pom.xml b/modules/pds/pom.xml deleted file mode 100644 index 3bbccb9043d7d..0000000000000 --- a/modules/pds/pom.xml +++ /dev/null @@ -1,189 +0,0 @@ - - - - - - - 4.0.0 - - - org.apache.ignite - ignite-parent - 1 - ../../parent - - - ignite-pds - 2.1.0-SNAPSHOT - - - 2.4 - 1.4.8 - 14.0.1 - 3.20.0-GA - - - - - org.apache.ignite - ignite-core - ${project.version} - - - - commons-io - commons-io - ${common.io.version} - test - - - - org.apache.ignite - ignite-spring - ${project.version} - test - - - - log4j - log4j - test - - - - com.thoughtworks.xstream - xstream - ${xstream.version} - test - - - - org.apache.ignite - ignite-indexing - ${project.version} - test - - - - org.apache.ignite - ignite-indexing - ${project.version} - test-jar - test - - - - org.apache.ignite - ignite-core - ${project.version} - test-jar - test - - - - com.google.guava - guava - ${guava.version} - test - - - - org.javassist - javassist - ${javassist.version} - test - - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.3.2 - - - org.apache.ignite - ignite-tools - ${project.version} - - - - - process-classes - - java - - - true - org.apache.ignite.tools.classgen.ClassesGenerator - - ${project.basedir}/target/classes - - - - org.apache.ignite - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.2 - - - - test-jar - - - - - - - org.apache.maven.plugins - maven-deploy-plugin - 2.8.2 - - false - - - - - diff --git a/modules/pds/src/main/resources/META-INF/classnames.properties b/modules/pds/src/main/resources/META-INF/classnames.properties deleted file mode 100644 index 3003e5f2cbb25..0000000000000 --- a/modules/pds/src/main/resources/META-INF/classnames.properties +++ /dev/null @@ -1,28 +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. -# - -org.apache.ignite.internal.processors.cache.database.FullPageIdIterableComparator -org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager$11 -org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager$7 -org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager$CheckpointEntryType -org.apache.ignite.internal.processors.cache.database.GridCacheOffheapManager$RebalanceIteratorAdapter -org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl$Segment -org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager$FileArchiver$1 -org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager$Mode -org.apache.ignite.internal.processors.cache.database.wal.FileWriteAheadLogManager$RecordsIterator -org.apache.ignite.internal.processors.cache.database.wal.SegmentEofException -org.apache.ignite.internal.processors.cache.database.wal.crc.IgniteDataIntegrityViolationException diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java deleted file mode 100644 index 144bbefca57ee..0000000000000 --- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java +++ /dev/null @@ -1,200 +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.cache.database.pagemem; - -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.atomic.AtomicInteger; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.pagemem.FullPageId; -import org.apache.ignite.internal.pagemem.PageIdUtils; -import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; -import org.apache.ignite.internal.processors.cache.CacheGroupContext; -import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.StoredCacheData; -import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.lang.IgniteFuture; - -/** - * - */ -public class NoOpPageStoreManager implements IgnitePageStoreManager { - /** */ - private ConcurrentMap allocators = new ConcurrentHashMap<>(); - - /** {@inheritDoc} */ - @Override public void beginRecover() { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void finishRecover() { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void initializeForCache(CacheGroupDescriptor grpDesc, - StoredCacheData cacheData) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void shutdownForCacheGroup(CacheGroupContext grp, boolean destroy) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void onPartitionCreated(int grpId, int partId) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void onPartitionDestroyed(int cacheId, int partId, int tag) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void read(int cacheId, long pageId, ByteBuffer pageBuf) throws IgniteCheckedException { - - } - - /** {@inheritDoc} */ - @Override public boolean exists(int cacheId, int partId) throws IgniteCheckedException { - return false; - } - - /** {@inheritDoc} */ - @Override public void readHeader(int cacheId, int partId, ByteBuffer buf) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void write(int cacheId, long pageId, ByteBuffer pageBuf, int tag) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void sync(int cacheId, int partId) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void ensure(int cacheId, int partId) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public long pageOffset(int cacheId, long pageId) throws IgniteCheckedException { - return 0; - } - - /** {@inheritDoc} */ - @Override public long allocatePage(int cacheId, int partId, byte flags) throws IgniteCheckedException { - long root = PageIdUtils.pageId(partId, flags, 0); - - FullPageId fullId = new FullPageId(root, cacheId); - - AtomicInteger allocator = allocators.get(fullId); - - if (allocator == null) - allocator = F.addIfAbsent(allocators, fullId, new AtomicInteger(1)); - - return PageIdUtils.pageId(partId, flags, allocator.getAndIncrement()); - } - - /** {@inheritDoc} */ - @Override public int pages(int cacheId, int partId) throws IgniteCheckedException { - long root = PageIdUtils.pageId(partId, (byte)0, 0); - - FullPageId fullId = new FullPageId(root, cacheId); - - AtomicInteger allocator = allocators.get(fullId); - - if (allocator == null) - allocator = F.addIfAbsent(allocators, fullId, new AtomicInteger(2)); - - return allocator.get(); - } - - /** {@inheritDoc} */ - @Override public long metaPageId(int cacheId) { - return 1; - } - - /** {@inheritDoc} */ - @Override public void start(GridCacheSharedContext cctx) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void stop(boolean cancel) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void onKernalStart(boolean reconnect) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void onKernalStop(boolean cancel) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void onDisconnected(IgniteFuture reconnectFut) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void printMemoryStats() { - // No-op. - } - - /** {@inheritDoc} */ - @Override public Map readCacheConfigurations() throws IgniteCheckedException { - return Collections.emptyMap(); - } - - /** {@inheritDoc} */ - @Override public void storeCacheData(CacheGroupDescriptor grpDesc, - StoredCacheData cacheData) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public boolean hasIndexStore(int grpId) { - return false; - } - - /** {@inheritDoc} */ - @Override public void onActivate(GridKernalContext kctx) { - - } - - /** {@inheritDoc} */ - @Override public void onDeActivate(GridKernalContext kctx) { - - } -} diff --git a/parent/pom.xml b/parent/pom.xml index 270ece49e6f71..6ec74b053d293 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -107,6 +107,7 @@ 2.2.0 0.5 3.4.6 + 3.20.0-GA * diff --git a/pom.xml b/pom.xml index f18aedc3a5192..7fa3eef39820b 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,6 @@ modules/kubernetes modules/zeromq modules/rocketmq - modules/pds From 4dc81ca86347107848328d1e2e206b796976fb23 Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Mon, 12 Jun 2017 08:22:49 +0300 Subject: [PATCH 271/311] IGNITE-5267 - Added missing class --- .../pagemem/NoOpPageStoreManager.java | 199 ++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/NoOpPageStoreManager.java diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/NoOpPageStoreManager.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/NoOpPageStoreManager.java new file mode 100644 index 0000000000000..4dfe69b03c6cb --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/NoOpPageStoreManager.java @@ -0,0 +1,199 @@ +/* + * 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.pagemem; + +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; +import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.StoredCacheData; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.lang.IgniteFuture; + +/** + * + */ +public class NoOpPageStoreManager implements IgnitePageStoreManager { + /** */ + private ConcurrentMap allocators = new ConcurrentHashMap<>(); + + /** {@inheritDoc} */ + @Override public void beginRecover() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void finishRecover() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void initializeForCache(CacheGroupDescriptor grpDesc, + StoredCacheData cacheData) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void shutdownForCacheGroup(CacheGroupContext grp, boolean destroy) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onPartitionCreated(int grpId, int partId) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onPartitionDestroyed(int cacheId, int partId, int tag) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void read(int cacheId, long pageId, ByteBuffer pageBuf) throws IgniteCheckedException { + + } + + /** {@inheritDoc} */ + @Override public boolean exists(int cacheId, int partId) throws IgniteCheckedException { + return false; + } + + /** {@inheritDoc} */ + @Override public void readHeader(int cacheId, int partId, ByteBuffer buf) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void write(int cacheId, long pageId, ByteBuffer pageBuf, int tag) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void sync(int cacheId, int partId) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void ensure(int cacheId, int partId) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public long pageOffset(int cacheId, long pageId) throws IgniteCheckedException { + return 0; + } + + /** {@inheritDoc} */ + @Override public long allocatePage(int cacheId, int partId, byte flags) throws IgniteCheckedException { + long root = PageIdUtils.pageId(partId, flags, 0); + + FullPageId fullId = new FullPageId(root, cacheId); + + AtomicInteger allocator = allocators.get(fullId); + + if (allocator == null) + allocator = F.addIfAbsent(allocators, fullId, new AtomicInteger(1)); + + return PageIdUtils.pageId(partId, flags, allocator.getAndIncrement()); + } + + /** {@inheritDoc} */ + @Override public int pages(int cacheId, int partId) throws IgniteCheckedException { + long root = PageIdUtils.pageId(partId, (byte)0, 0); + + FullPageId fullId = new FullPageId(root, cacheId); + + AtomicInteger allocator = allocators.get(fullId); + + if (allocator == null) + allocator = F.addIfAbsent(allocators, fullId, new AtomicInteger(2)); + + return allocator.get(); + } + + /** {@inheritDoc} */ + @Override public long metaPageId(int cacheId) { + return 1; + } + + /** {@inheritDoc} */ + @Override public void start(GridCacheSharedContext cctx) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void stop(boolean cancel) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onKernalStart(boolean reconnect) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onKernalStop(boolean cancel) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void onDisconnected(IgniteFuture reconnectFut) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void printMemoryStats() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public Map readCacheConfigurations() throws IgniteCheckedException { + return Collections.emptyMap(); + } + + /** {@inheritDoc} */ + @Override public void storeCacheData(CacheGroupDescriptor grpDesc, + StoredCacheData cacheData) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public boolean hasIndexStore(int grpId) { + return false; + } + + /** {@inheritDoc} */ + @Override public void onActivate(GridKernalContext kctx) { + + } + + /** {@inheritDoc} */ + @Override public void onDeActivate(GridKernalContext kctx) { + + } +} From 195147d573d7cb3fc637f74937ee561b03a3c574 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 13 Jun 2017 08:23:38 +0300 Subject: [PATCH 272/311] IGNITE-5267 - Activate nodes after start --- .../apache/ignite/internal/IgniteKernal.java | 2 + .../service/GridServiceProcessor.java | 2 - ...IgnitePdsCacheRebalancingAbstractTest.java | 8 + .../IgnitePdsContinuousRestartTest.java | 2 + .../IgnitePdsDynamicCacheTest.java | 5 +- .../IgnitePdsMultiNodePutGetRestartTest.java | 2 + .../persistence/IgnitePdsPageSizesTest.java | 2 + ...itePdsRecoveryAfterFileCorruptionTest.java | 2 + .../IgnitePdsRemoveDuringRebalancingTest.java | 2 + .../IgnitePersistenceMetricsSelfTest.java | 7 +- .../IgnitePersistentStoreCacheGroupsTest.java | 20 +- ...nitePersistentStoreDataStructuresTest.java | 2 - .../IgnitePdsMultiNodePutGetRestartTest.java | 2 + ...sPageEvictionDuringPartitionClearTest.java | 2 + .../db/IgnitePdsPageEvictionTest.java | 2 + ...PdsRebalancingOnNotStableTopologyTest.java | 2 + .../db/IgnitePdsTransactionsHangTest.java | 2 + .../file/IgnitePdsCacheIntegrationTest.java | 4 + .../db/file/IgnitePdsEvictionTest.java | 2 + .../file/IgnitePdsNoActualWalHistoryTest.java | 2 + .../ignitePdsCheckpointSimulationTest.java | 10 + .../db/wal/IgnitePdsWalTlbTest.java | 2 + ...IgniteWalDirectoriesConfigurationTest.java | 2 + .../wal/IgniteWalHistoryReservationsTest.java | 8 + .../IgniteWalRecoverySeveralRestartsTest.java | 12 + .../wal/WalRecoveryTxLogicalRecordsTest.java | 2 + .../AbstractNodeJoinTemplate.java | 743 ------------------ .../IgniteChangeGlobalStateAbstractTest.java | 11 +- .../IgniteStandByClusterTest.java | 213 ----- .../join/JoinActiveNodeToActiveCluster.java | 431 ---------- .../join/JoinActiveNodeToInActiveCluster.java | 227 ------ .../join/JoinInActiveNodeToActiveCluster.java | 356 --------- .../JoinInActiveNodeToInActiveCluster.java | 226 ------ ...iveNodeToActiveClusterWithPersistence.java | 98 --- ...eNodeToInActiveClusterWithPersistence.java | 31 - ...iveNodeToActiveClusterWithPersistence.java | 86 -- ...eNodeToInActiveClusterWithPersistence.java | 31 - ...iteAbstractStandByClientReconnectTest.java | 336 -------- .../IgniteStandByClientReconnectTest.java | 283 ------- ...tandByClientReconnectToNewClusterTest.java | 289 ------- .../database/IgniteDbAbstractTest.java | 4 + .../IgniteDbDynamicCacheSelfTest.java | 4 + 42 files changed, 105 insertions(+), 3374 deletions(-) delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToActiveCluster.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToInActiveCluster.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToActiveCluster.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToInActiveCluster.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectTest.java delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index a6ad89e0c225d..ff2b7bd041115 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -2755,6 +2755,8 @@ public IgniteInternalCache getCache(String name) { guard(); try { + checkClusterState(); + ctx.cache().dynamicStartCaches(cacheCfgs, true, true).get(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java index 5c1872ca46228..e2cf53b249450 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java @@ -364,8 +364,6 @@ CU.UTILITY_CACHE_NAME, new ServiceEntriesListener(), null, null cancelFutures(undepFuts, new IgniteCheckedException("Failed to undeploy service, cluster in active.")); onKernalStop(true); - - busyLock.unblock(); } /** {@inheritDoc} */ 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 a9428f8d0940d..f085e4879ecb8 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 @@ -157,6 +157,8 @@ public abstract class IgnitePdsCacheRebalancingAbstractTest extends GridCommonAb public void testRebalancingOnRestart() throws Exception { Ignite ignite0 = startGrid(0); + ignite0.active(true); + startGrid(1); IgniteEx ignite2 = startGrid(2); @@ -211,6 +213,8 @@ public void testRebalancingOnRestartAfterCheckpoint() throws Exception { IgniteEx ignite2 = startGrid(2); IgniteEx ignite3 = startGrid(3); + ignite0.active(true); + ignite0.cache(cacheName).rebalance().get(); ignite1.cache(cacheName).rebalance().get(); ignite2.cache(cacheName).rebalance().get(); @@ -279,6 +283,8 @@ public void testDataCorrectnessAfterRestart() throws Exception { awaitPartitionMapExchange(); + ignite1.active(true); + IgniteCache cache1 = ignite1.cache(cacheName); for (int i = 0; i < 100; i++) @@ -375,6 +381,8 @@ public void testTopologyChangesWithConstantLoad() throws Exception { Ignite ignite = startGrid(0); + ignite.active(true); + IgniteCache cache = ignite.cache(cacheName); for (int i = 0; i < entriesCnt; i++) { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsContinuousRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsContinuousRestartTest.java index 3721031962398..238e1d17a857b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsContinuousRestartTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsContinuousRestartTest.java @@ -208,6 +208,8 @@ private void checkRebalancingDuringLoad( final Ignite load = ignite(0); + load.active(true); + try (IgniteDataStreamer s = load.dataStreamer(CACHE_NAME)) { s.allowOverwrite(true); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java index ba55c09848b5d..f30e78514395a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java @@ -29,7 +29,6 @@ import org.apache.ignite.configuration.MemoryPolicyConfiguration; import org.apache.ignite.configuration.PersistentStoreConfiguration; import org.apache.ignite.configuration.WALMode; -import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; import org.apache.ignite.internal.processors.database.IgniteDbDynamicCacheSelfTest; import org.apache.ignite.internal.util.typedef.internal.U; @@ -97,6 +96,8 @@ public void testRestartAndCreate() throws Exception { Ignite ignite = ignite(0); + ignite.active(true); + CacheConfiguration ccfg1 = new CacheConfiguration(); ccfg1.setName("cache1"); @@ -129,6 +130,8 @@ public void testRestartAndCreate() throws Exception { ignite = ignite(0); + ignite.active(true); + ignite.getOrCreateCache(ccfg1); ignite.getOrCreateCache(ccfg2); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMultiNodePutGetRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMultiNodePutGetRestartTest.java index 21ea626f5b8d6..849d9b2901b8b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMultiNodePutGetRestartTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMultiNodePutGetRestartTest.java @@ -139,6 +139,8 @@ public void testPutGetSimple() throws Exception { try { IgniteEx ig = grid(0); + ig.active(true); + checkPutGetSql(ig, true); } finally { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsPageSizesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsPageSizesTest.java index 5014399f8225c..aa480ed886ad3 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsPageSizesTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsPageSizesTest.java @@ -128,6 +128,8 @@ private void checkPageSize(int pageSize) throws Exception { IgniteEx ignite = startGrid(0); + ignite.active(true); + try { final IgniteCache cache = ignite.cache(cacheName); final long endTime = System.currentTimeMillis() + 60_000; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRecoveryAfterFileCorruptionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRecoveryAfterFileCorruptionTest.java index 4981095a2b21d..098ea317aea98 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRecoveryAfterFileCorruptionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRecoveryAfterFileCorruptionTest.java @@ -128,6 +128,8 @@ public class IgnitePdsRecoveryAfterFileCorruptionTest extends GridCommonAbstract public void testPageRecoveryAfterFileCorruption() throws Exception { IgniteEx ig = startGrid(0); + ig.active(true); + IgniteCache cache = ig.cache(cacheName); // Put for create data store and init meta page. diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRemoveDuringRebalancingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRemoveDuringRebalancingTest.java index e8558597eb69c..544ef82d8155f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRemoveDuringRebalancingTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRemoveDuringRebalancingTest.java @@ -113,6 +113,8 @@ public class IgnitePdsRemoveDuringRebalancingTest extends GridCommonAbstractTest public void testRemovesDuringRebalancing() throws Exception { IgniteEx ig = startGrid(0); + ig.active(true); + try (IgniteDataStreamer streamer = ig.dataStreamer(null)) { streamer.allowOverwrite(true); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistenceMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistenceMetricsSelfTest.java index 72e0b612a7235..cfa170627c34a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistenceMetricsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistenceMetricsSelfTest.java @@ -56,9 +56,6 @@ public class IgnitePersistenceMetricsSelfTest extends GridCommonAbstractTest { /** */ private static final String GROUP1 = "grp1"; - /** */ - private boolean activeOnStart = true; - /** {@inheritDoc} */ @Override protected void afterTestsStopped() throws Exception { GridTestUtils.deleteDbFiles(); @@ -77,8 +74,6 @@ public class IgnitePersistenceMetricsSelfTest extends GridCommonAbstractTest { cfg.setConsistentId(gridName); - cfg.setActiveOnStart(activeOnStart); - MemoryConfiguration memCfg = new MemoryConfiguration(); memCfg.setPageSize(1024); @@ -147,6 +142,8 @@ private CacheConfiguration cacheConfiguration( public void testPersistenceMetrics() throws Exception { final IgniteEx ig = startGrid(0); + ig.active(true); + try { IgniteCache cache = ig.cache("cache"); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreCacheGroupsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreCacheGroupsTest.java index 57cc8d08026c7..f85ddfd8d0469 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreCacheGroupsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreCacheGroupsTest.java @@ -67,9 +67,6 @@ public class IgnitePersistentStoreCacheGroupsTest extends GridCommonAbstractTest /** */ private CacheConfiguration[] ccfgs; - /** */ - private boolean activeOnStart = true; - /** {@inheritDoc} */ @Override protected void afterTestsStopped() throws Exception { GridTestUtils.deleteDbFiles(); @@ -88,8 +85,6 @@ public class IgnitePersistentStoreCacheGroupsTest extends GridCommonAbstractTest cfg.setConsistentId(gridName); - cfg.setActiveOnStart(activeOnStart); - MemoryConfiguration memCfg = new MemoryConfiguration(); memCfg.setPageSize(1024); memCfg.setDefaultMemoryPolicySize(10 * 1024 * 1024); @@ -173,6 +168,8 @@ public void testClusterRestartCachesWithH2Indexes() throws Exception { Ignite node = ignite(0); + node.active(true); + node.createCaches(Arrays.asList(ccfgs1)); putPersons(caches, node); @@ -214,8 +211,6 @@ public void testClusterRestartCachesWithH2Indexes() throws Exception { public void _testExpiryPolicy() throws Exception { long ttl = 10000; - activeOnStart = false; - CacheConfiguration[] ccfgs1 = new CacheConfiguration[5]; ccfgs1[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1); @@ -281,6 +276,8 @@ public void testCreateDropCache() throws Exception { Ignite ignite = startGrid(); + ignite.active(true); + ignite.cache("c1").destroy(); stopGrid(); @@ -296,8 +293,9 @@ public void testCreateDropCache1() throws Exception { Ignite ignite = startGrid(); - ignite.createCaches(Arrays.asList(ccfg1, ccfg2)); + ignite.active(true); + ignite.createCaches(Arrays.asList(ccfg1, ccfg2)); ignite.cache("c1").destroy(); @@ -321,6 +319,8 @@ public void testCreateDropCache2() throws Exception { Ignite ignite = startGrid(); + ignite.active(true); + ignite.createCaches(Arrays.asList(ccfg1, ccfg2)); ignite.cache("c1").destroy(); @@ -403,6 +403,8 @@ private void clusterRestart(int nodes, boolean staticCaches) throws Exception { Ignite node = ignite(0); + node.active(true); + if (!staticCaches) node.createCaches(Arrays.asList(ccfgs)); @@ -422,6 +424,8 @@ private void clusterRestart(int nodes, boolean staticCaches) throws Exception { node = startGrids(nodes); + node.active(true); + awaitPartitionMapExchange(); for (String cacheName : caches) { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreDataStructuresTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreDataStructuresTest.java index 64949034bc7f4..87e789de27cce 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreDataStructuresTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreDataStructuresTest.java @@ -62,8 +62,6 @@ public class IgnitePersistentStoreDataStructuresTest extends GridCommonAbstractT cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration().setWalMode(WALMode.LOG_ONLY)); - cfg.setActiveOnStart(false); - return cfg; } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsMultiNodePutGetRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsMultiNodePutGetRestartTest.java index e24433343117e..d4c51fc111d7e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsMultiNodePutGetRestartTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsMultiNodePutGetRestartTest.java @@ -129,6 +129,8 @@ public void testPutGetSimple() throws Exception { try { IgniteEx ig = grid(0); + ig.active(true); + checkPutGetSql(ig, true); } finally { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionDuringPartitionClearTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionDuringPartitionClearTest.java index fb7113f45d4de..38b1d55d63d38 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionDuringPartitionClearTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionDuringPartitionClearTest.java @@ -109,6 +109,8 @@ public void testPageEvictionOnNodeStart() throws Exception { try { Ignite ig = ignite(0); + ig.active(true); + IgniteDataStreamer streamer = ig.dataStreamer(CACHE_NAME); for (int i = 0; i < 300_000; i++) { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionTest.java index e8bc701caba88..d266125b28d33 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionTest.java @@ -116,6 +116,8 @@ public class IgnitePdsPageEvictionTest extends GridCommonAbstractTest { public void testPageEvictionSql() throws Exception { IgniteEx ig = grid(0); + ig.active(true); + try (IgniteDataStreamer streamer = ig.dataStreamer(CACHE_NAME)) { for (int i = 0; i < ENTRY_CNT; i++) { streamer.addData(new DbKey(i), new DbValue(i, "value-" + i, Long.MAX_VALUE - i)); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsRebalancingOnNotStableTopologyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsRebalancingOnNotStableTopologyTest.java index 0724eb9e322e4..967c8f08979c2 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsRebalancingOnNotStableTopologyTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsRebalancingOnNotStableTopologyTest.java @@ -58,6 +58,8 @@ public class IgnitePdsRebalancingOnNotStableTopologyTest extends GridCommonAbstr public void test() throws Exception { Ignite ex = startGrid(0); + ex.active(true); + startGrid(1); final CountDownLatch startLatch = new CountDownLatch(1); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsTransactionsHangTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsTransactionsHangTest.java index d4dfdec5c94c9..a927454d9beba 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsTransactionsHangTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsTransactionsHangTest.java @@ -174,6 +174,8 @@ public void testTransactionsDontHang() throws Exception { try { final Ignite g = startGrids(2); + g.active(true); + g.getOrCreateCache(getCacheConfiguration()); ExecutorService threadPool = Executors.newFixedThreadPool(THREADS_CNT); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsCacheIntegrationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsCacheIntegrationTest.java index c68f7e79804b9..6e89b46e1fbaf 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsCacheIntegrationTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsCacheIntegrationTest.java @@ -131,6 +131,8 @@ public void testPutGetSimple() throws Exception { try { IgniteEx ig = grid(0); + ig.active(true); + checkPutGetSql(ig, true); } finally { @@ -162,6 +164,8 @@ public void testPutMultithreaded() throws Exception { try { final IgniteEx grid = grid(0); + grid.active(true); + GridTestUtils.runMultiThreaded(new Callable() { @Override public Object call() throws Exception { for (int i = 0; i < 1000; i++) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsEvictionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsEvictionTest.java index 1026d4e7df5b0..ea4a0e9426b77 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsEvictionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsEvictionTest.java @@ -117,6 +117,8 @@ private MemoryConfiguration createDbConfig() { public void testPageEviction() throws Exception { final IgniteEx ig = startGrid(0); + ig.active(true); + final PageMemory memory = getMemory(ig); writeData(ig, memory, CU.cacheId(cacheName)); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsNoActualWalHistoryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsNoActualWalHistoryTest.java index 96316860bd94f..c948d58311e87 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsNoActualWalHistoryTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/IgnitePdsNoActualWalHistoryTest.java @@ -103,6 +103,8 @@ public void testWalBig() throws Exception { try { IgniteEx ignite = startGrid(1); + ignite.active(true); + IgniteCache cache = ignite.cache(CACHE_NAME); Random rnd = new Random(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/ignitePdsCheckpointSimulationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/ignitePdsCheckpointSimulationTest.java index 840042e16372b..b9daabaae0802 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/ignitePdsCheckpointSimulationTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/ignitePdsCheckpointSimulationTest.java @@ -143,6 +143,8 @@ public class ignitePdsCheckpointSimulationTest extends GridCommonAbstractTest { public void testCheckpointSimulationMultiThreaded() throws Exception { IgniteEx ig = startGrid(0); + ig.active(true); + GridCacheSharedContext shared = ig.context().cache().context(); GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)shared.database(); @@ -196,6 +198,8 @@ public void testCheckpointSimulationMultiThreaded() throws Exception { public void testGetForInitialWrite() throws Exception { IgniteEx ig = startGrid(0); + ig.active(true); + GridCacheSharedContext shared = ig.context().cache().context(); int cacheId = shared.cache().cache(cacheName).context().cacheId(); @@ -289,6 +293,8 @@ public void testGetForInitialWrite() throws Exception { public void testDataWalEntries() throws Exception { IgniteEx ig = startGrid(0); + ig.active(true); + GridCacheSharedContext sharedCtx = ig.context().cache().context(); GridCacheContext cctx = sharedCtx.cache().cache(cacheName).context(); @@ -408,6 +414,8 @@ public void testDataWalEntries() throws Exception { public void testPageWalEntries() throws Exception { IgniteEx ig = startGrid(0); + ig.active(true); + GridCacheSharedContext sharedCtx = ig.context().cache().context(); int cacheId = sharedCtx.cache().cache(cacheName).context().cacheId(); @@ -520,6 +528,8 @@ public void testPageWalEntries() throws Exception { public void testDirtyFlag() throws Exception { IgniteEx ig = startGrid(0); + ig.active(true); + GridCacheSharedContext shared = ig.context().cache().context(); int cacheId = shared.cache().cache(cacheName).context().cacheId(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgnitePdsWalTlbTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgnitePdsWalTlbTest.java index 6ca0a1dca1228..a1a7286ac0913 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgnitePdsWalTlbTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgnitePdsWalTlbTest.java @@ -109,6 +109,8 @@ public class IgnitePdsWalTlbTest extends GridCommonAbstractTest { public void testWalDirectOutOfMemory() throws Exception { IgniteEx ig = grid(1); + ig.active(true); + boolean locked = true; try { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalDirectoriesConfigurationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalDirectoriesConfigurationTest.java index 97e70c2953fad..e61d2fd8157cd 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalDirectoriesConfigurationTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalDirectoriesConfigurationTest.java @@ -44,6 +44,8 @@ public class IgniteWalDirectoriesConfigurationTest extends GridCommonAbstractTes public void testPartialWalConfigurationNotAllowed() { try { startGrid(); + + grid(0).active(true); } catch (Exception ignore) { return; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalHistoryReservationsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalHistoryReservationsTest.java index 5f92100f39862..793806e18b652 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalHistoryReservationsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalHistoryReservationsTest.java @@ -107,6 +107,8 @@ public void testReservedOnExchange() throws Exception { final IgniteEx ig0 = (IgniteEx)startGrids(initGridCnt); + ig0.active(true); + IgniteCache cache = ig0.cache("cache1"); for (int k = 0; k < entryCnt; k++) @@ -201,6 +203,8 @@ public void testRemovesArePreloadedIfHistoryIsAvailable() throws Exception { Ignite ig0 = startGrids(2); + ig0.active(true); + IgniteCache cache = ig0.cache("cache1"); for (int k = 0; k < entryCnt; k++) @@ -242,6 +246,8 @@ public void testNodeIsClearedIfHistoryIsUnavailable() throws Exception { Ignite ig0 = startGrids(2); + ig0.active(true); + IgniteCache cache = ig0.cache("cache1"); for (int k = 0; k < entryCnt; k++) @@ -293,6 +299,8 @@ public void testNodeLeftDuringExchange() throws Exception { final IgniteEx ig0 = (IgniteEx)startGrids(initGridCnt); + ig0.active(true); + IgniteCache cache = ig0.cache("cache1"); for (int k = 0; k < entryCnt; k++) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalRecoverySeveralRestartsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalRecoverySeveralRestartsTest.java index 99b738339d309..a6e65d603b0e8 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalRecoverySeveralRestartsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgniteWalRecoverySeveralRestartsTest.java @@ -130,6 +130,8 @@ public void testWalRecoverySeveralRestarts() throws Exception { try { IgniteEx ignite = startGrid(1); + ignite.active(true); + Random locRandom = ThreadLocalRandom.current(); try (IgniteDataStreamer dataLdr = ignite.dataStreamer(cacheName)) { @@ -151,6 +153,8 @@ public void testWalRecoverySeveralRestarts() throws Exception { ignite = startGrid(1); + ignite.active(true); + IgniteCache cache = ignite.cache(cacheName); assertEquals(size, cache.size()); @@ -181,6 +185,8 @@ public void testWalRecoveryWithDynamicCache() throws Exception { try { IgniteEx ignite = startGrid(1); + ignite.active(true); + CacheConfiguration dynCacheCfg = new CacheConfiguration<>(); dynCacheCfg.setName("dyncache"); @@ -210,6 +216,8 @@ public void testWalRecoveryWithDynamicCache() throws Exception { ignite = startGrid(1); + ignite.active(true); + ThreadLocalRandom locRandom = ThreadLocalRandom.current(); IgniteCache cache = ignite.getOrCreateCache(dynCacheCfg); @@ -230,6 +238,8 @@ public void testWalRecoveryWithDynamicCacheLargeObjects() throws Exception { try { IgniteEx ignite = startGrid(1); + ignite.active(true); + CacheConfiguration dynCacheCfg = new CacheConfiguration<>(); dynCacheCfg.setName("dyncache"); @@ -263,6 +273,8 @@ public void testWalRecoveryWithDynamicCacheLargeObjects() throws Exception { ignite = startGrid(1); + ignite.active(true); + ThreadLocalRandom locRandom = ThreadLocalRandom.current(); IgniteCache cache = ignite.getOrCreateCache(dynCacheCfg); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalRecoveryTxLogicalRecordsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalRecoveryTxLogicalRecordsTest.java index 205e0fce95f99..b21fc2a688c44 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalRecoveryTxLogicalRecordsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalRecoveryTxLogicalRecordsTest.java @@ -147,6 +147,8 @@ public class WalRecoveryTxLogicalRecordsTest extends GridCommonAbstractTest { public void testWalTxSimple() throws Exception { Ignite ignite = startGrid(); + ignite.active(true); + try { GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)((IgniteEx)ignite).context() .cache().context().database(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java deleted file mode 100644 index 76a5260a90a5a..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java +++ /dev/null @@ -1,743 +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.persistence.standbycluster; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import org.apache.ignite.cache.CacheAtomicityMode; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.configuration.PersistentStoreConfiguration; -import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; -import org.apache.ignite.internal.processors.cache.GridCacheAdapter; -import org.apache.ignite.internal.util.typedef.CI1; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.lang.IgniteCallable; -import org.apache.ignite.lang.IgniteClosure; -import org.apache.ignite.lang.IgniteInClosure; -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.junits.common.GridCommonAbstractTest; -import org.junit.Assert; - -import static org.apache.ignite.internal.util.IgniteUtils.field; - -/** - * - */ -public abstract class AbstractNodeJoinTemplate extends GridCommonAbstractTest { - /** Cache 1. */ - protected static final String cache1 = "cache1"; - - /** Cache 2. */ - protected static final String cache2 = "cache2"; - - //Todo Cache with node filter. - protected static final String cache3 = "cache3"; - - protected static final String cache4 = "cache4"; - - protected static final String cache5 = "cache5"; - - /** Caches info. */ - public static final String CACHES_INFO = "cachesInfo"; - - /** Registered caches. */ - public static final String REGISTERED_CACHES = "registeredCaches"; - - /** Caches. */ - public static final String CACHES = "caches"; - - /** - * @param ig Ig. - */ - protected static Map cacheDescriptors(IgniteEx ig) { - return field(field(ig.context().cache(), CACHES_INFO), REGISTERED_CACHES); - } - - /** - * @param ig Ig. - */ - protected static Map caches(IgniteEx ig){ - return field(ig.context().cache(), CACHES); - } - - /** - * - */ - public abstract JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception; - - /** - * - */ - public abstract JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception; - - /** - * - */ - public abstract JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception; - - /** - * - */ - public abstract JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception; - - /** - * - */ - public abstract JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception; - - // Client node join. - - public abstract JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception; - - public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception; - - public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception; - - public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception; - - public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception; - - /** - * - */ - public abstract void testJoinWithOutConfiguration() throws Exception; - - /** - * - */ - public abstract void testStaticCacheConfigurationOnJoin() throws Exception; - - /** - * - */ - public abstract void testStaticCacheConfigurationInCluster() throws Exception; - - /** - * - */ - public abstract void testStaticCacheConfigurationSameOnBoth() throws Exception; - - /** - * - */ - public abstract void testStaticCacheConfigurationDifferentOnBoth() throws Exception; - - /** - * - */ - public abstract void testJoinClientWithOutConfiguration() throws Exception; - - /** - * - */ - public abstract void testJoinClientStaticCacheConfigurationOnJoin() throws Exception; - - /** - * - */ - public abstract void testJoinClientStaticCacheConfigurationInCluster() throws Exception; - - /** - * - */ - public abstract void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception; - - /** - * - */ - public abstract void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception; - - @Override protected void beforeTest() throws Exception { - super.beforeTest(); - - stopAllGrids(); - - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - } - - @Override protected void afterTest() throws Exception { - super.afterTest(); - - stopAllGrids(); - - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); - } - - /** - * @param idx Index. - */ - protected String name(int idx) { - return getTestIgniteInstanceName(idx); - } - - /** - * @param name Name. - */ - protected IgniteConfiguration cfg(String name) throws Exception { - try { - return getConfiguration(name); - } - catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * - */ - protected JoinNodeTestPlanBuilder builder() { - return JoinNodeTestPlanBuilder.builder(); - } - - /** - * @param cfgs Cfgs. - */ - protected static T[] buildConfiguration(T... cfgs) { - return cfgs; - } - - /** - * - */ - protected CacheConfiguration atomicCfg() { - return new CacheConfiguration(cache1) - .setAtomicityMode(CacheAtomicityMode.ATOMIC); - } - - /** - * - */ - protected CacheConfiguration transactionCfg() { - return new CacheConfiguration(cache2) - .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); - } - - /** - * - */ - protected CacheConfiguration[] allCacheConfigurations() { - return buildConfiguration(atomicCfg(), transactionCfg()); - } - - /** Set client. */ - protected final IgniteClosure setClient = - new IgniteClosure() { - @Override public IgniteConfiguration apply(IgniteConfiguration cfg) { - return cfg.setClientMode(true); - } - }; - - /** Ip finder. */ - private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String name) throws Exception { - return super.getConfiguration(name) - .setDiscoverySpi( - new TcpDiscoverySpi() - .setIpFinder(ipFinder) - ); - } - - /** {@inheritDoc} */ - protected IgniteConfiguration persistentCfg(IgniteConfiguration cfg) throws Exception { - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); - - return cfg; - } - - /** - * - */ - public static class JoinNodeTestPlanBuilder extends GridCommonAbstractTest { - /** String plan builder. */ - private final StringBuilder strPlanBuilder = new StringBuilder().append("**** Execution plan ****\n"); - - /** Nodes. */ - protected List nodes = new ArrayList<>(4); - - /** Cluster config. */ - private IgniteConfiguration[] clusterCfg; - - /** Node config. */ - private IgniteConfiguration nodeCfg; - - /** State default. */ - private static final Boolean stateDefault = new Boolean(true); - - /** State. */ - private Boolean state = stateDefault; - - /** Noop. */ - private static final Runnable Noop = new Runnable() { - @Override public void run() { - } - }; - - /** After cluster started. */ - private Runnable afterClusterStarted = Noop; - - /** After node join. */ - private Runnable afterNodeJoin = Noop; - - /** After activate. */ - private Runnable afterActivate = Noop; - - /** After de activate. */ - private Runnable afterDeActivate = Noop; - - private IgniteCallable> dynamicCacheStart = - new IgniteCallable>() { - @Override public List call() throws Exception { - return Arrays.asList(new CacheConfiguration(cache4), new CacheConfiguration(cache5)); - } - }; - - private IgniteCallable> dynamicCacheStop = - new IgniteCallable>() { - @Override public List call() throws Exception { - return Arrays.asList(cache4, cache5); - } - }; - - private Runnable afterDynamicCacheStarted = Noop; - - private Runnable afterDynamicCacheStopped = Noop; - - /** End. */ - private Runnable end = Noop; - - /** - * - */ - public JoinNodeTestPlanBuilder clusterConfiguration(IgniteConfiguration... cfgs) throws Exception { - clusterCfg = cfgs; - - strPlanBuilder.append("Start cluster:\n"); - - for (IgniteConfiguration cfg : cfgs) { - strPlanBuilder.append("node: ") - .append(cfg.getIgniteInstanceName()) - .append(" activeOnStart - ") - .append(cfg.isActiveOnStart()) - .append("\n"); - - CacheConfiguration[] ccfgs = cfg.getCacheConfiguration(); - - if (ccfgs != null) { - for (CacheConfiguration ccfg : ccfgs) - strPlanBuilder.append(" cache - ") - .append(ccfg.getName()) - .append("\n"); - } - } - - return this; - } - - /** - * - */ - public JoinNodeTestPlanBuilder nodeConfiguration(IgniteConfiguration cfg) { - nodeCfg = cfg; - - strPlanBuilder.append("Join node:\n") - .append(cfg.getIgniteInstanceName()) - .append(cfg.isClientMode() != null && cfg.isClientMode() ? " (client)" : "") - .append(" activeOnStart - ") - .append(cfg.isActiveOnStart()) - .append("\n"); - - CacheConfiguration[] ccfgs = cfg.getCacheConfiguration(); - - if (ccfgs != null) - for (CacheConfiguration ccfg : ccfgs) - strPlanBuilder.append(" cache - ").append(ccfg.getName()).append("\n"); - - return this; - } - - /** - * @param func Func. - */ - public JoinNodeTestPlanBuilder nodeConfiguration( - IgniteClosure func - ) { - - nodeCfg = func.apply(nodeCfg); - - return this; - } - - /** - * - */ - public JoinNodeTestPlanBuilder afterClusterStarted(Runnable r) { - strPlanBuilder.append("Check after cluster start\n"); - - afterClusterStarted = r; - - return this; - } - - /** - * - */ - public JoinNodeTestPlanBuilder afterNodeJoin(Runnable r) { - strPlanBuilder.append("Check after node join") - .append("\n"); - - afterNodeJoin = r; - - return this; - } - - /** - * - */ - public JoinNodeTestPlanBuilder stateAfterJoin(boolean state) { - strPlanBuilder.append("Check state on all nodes after join, must be ") - .append(state ? "<>" : "<>") - .append(" \n"); - - this.state = state; - - return this; - } - - /** - * - */ - public JoinNodeTestPlanBuilder afterActivate(Runnable r) { - strPlanBuilder.append("Check after activate") - .append("\n"); - - afterActivate = r; - - return this; - } - - /** - * - */ - public JoinNodeTestPlanBuilder afterDeActivate(Runnable r) { - strPlanBuilder.append("Check after deActivate") - .append("\n"); - - afterDeActivate = r; - - return this; - } - - public JoinNodeTestPlanBuilder dynamicCacheStart(IgniteCallable> caches){ - strPlanBuilder.append("Dynamic caches start") - .append("\n"); - - dynamicCacheStart = caches; - - return this; - } - - public JoinNodeTestPlanBuilder afterDynamicCacheStarted(Runnable r){ - strPlanBuilder.append("Check after dynamic caches start") - .append("\n"); - - afterDynamicCacheStarted = r; - - return this; - } - - public JoinNodeTestPlanBuilder dynamicCacheStop(IgniteCallable> caches){ - strPlanBuilder.append("Dynamic caches stop") - .append("\n"); - - dynamicCacheStop = caches; - - return this; - } - - public JoinNodeTestPlanBuilder afterDynamicCacheStopped(Runnable r){ - strPlanBuilder.append("Check after dynamic caches stop") - .append("\n"); - - afterDynamicCacheStopped = r; - - return this; - } - - /** - * @param end End. - */ - public JoinNodeTestPlanBuilder setEnd(Runnable end) { - strPlanBuilder.append("Check before stop") - .append("\n"); - - this.end = end; - - return this; - } - - /** - * - */ - public void execute() throws Exception { - try { - if (state == stateDefault) - fail("State after join must be specific. See JoinNodeTestPlanBuilder.stateAfterJoin(boolean)."); - - System.out.println(strPlanBuilder.append("********************").toString()); - - IgniteConfiguration[] cfgs = clusterCfg; - - System.out.println(">>> Start cluster"); - - for (IgniteConfiguration cfg : cfgs) { - startGrid(cfg); - - nodes.add(cfg.getIgniteInstanceName()); - } - - System.out.println(">>> Check after cluster started"); - - afterClusterStarted.run(); - - System.out.println(">>> Start new node"); - - startGrid(nodeCfg); - - nodes.add(nodeCfg.getIgniteInstanceName()); - - System.out.println(">>> Check after new node join in cluster"); - - afterNodeJoin.run(); - - System.out.println(">>> Check cluster state on all nodes"); - - IgniteEx crd = grid(nodes.get(0)); - - for (IgniteEx ig : grids()) - assertEquals((boolean)state, ig.active()); - - if (!state) { - System.out.println(">>> Activate cluster"); - - crd.active(true); - - System.out.println(">>> Check after cluster activated"); - - afterActivate.run(); - } - else { - System.out.println(">>> DeActivate cluster"); - - crd.active(false); - - System.out.println(">>> Check after cluster deActivated"); - - afterDeActivate.run(); - - System.out.println(">>> Activate cluster"); - - crd.active(true); - } - - AffinityTopologyVersion next0Ver = nextMinorVersion(crd); - - crd.createCaches(dynamicCacheStart.call()); - - awaitTopologyVersion(next0Ver); - - afterDynamicCacheStarted.run(); - - onAllNode(new CI1() { - @Override public void apply(IgniteEx ig) { - if (ig.context().discovery().localNode().isClient()) - return; - - Assert.assertNotNull(ig.context().cache().cache(cache4)); - Assert.assertNotNull(ig.context().cache().cache(cache5)); - - } - }); - - AffinityTopologyVersion next1Ver = nextMinorVersion(crd); - - crd.destroyCaches(dynamicCacheStop.call()); - - afterDynamicCacheStopped.run(); - - awaitTopologyVersion(next1Ver); - - onAllNode(new CI1() { - @Override public void apply(IgniteEx ig) { - if (ig.context().discovery().localNode().isClient()) - return; - - Assert.assertNull(ig.context().cache().cache(cache4)); - Assert.assertNull(ig.context().cache().cache(cache5)); - - } - }); - - System.out.println(">>> Finish check"); - - end.run(); - } - finally { - stopAllGrids(); - } - } - - private AffinityTopologyVersion nextMinorVersion(IgniteEx ig){ - AffinityTopologyVersion cur = ig.context().discovery().topologyVersionEx(); - - return new AffinityTopologyVersion(cur.topologyVersion(), cur.minorTopologyVersion() + 1); - } - - private void awaitTopologyVersion(final AffinityTopologyVersion ver){ - onAllNode(new CI1() { - @Override public void apply(IgniteEx ig) { - while (true) { - AffinityTopologyVersion locTopVer = ig.context().cache().context() - .exchange().readyAffinityVersion(); - - if (locTopVer.compareTo(ver) < 0){ - System.out.println("Top ready " + locTopVer + " on " + ig.localNode().id()); - - try { - Thread.sleep(100); - } - catch (InterruptedException e) { - break; - } - } - else - break; - } - } - }).run(); - - } - - /** - * - */ - protected List grids() { - List res = new ArrayList<>(); - - for (String name : nodes) - res.add(grid(name)); - - return res; - } - - /** - * - */ - public static JoinNodeTestPlanBuilder builder() { - return new JoinNodeTestPlanBuilder(); - } - - /** - * - */ - public Runnable checkCacheOnlySystem() { - return onAllNode(new IgniteInClosure() { - @Override public void apply(IgniteEx ig) { - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(2, desc.size()); - - Assert.assertNull(ig.context().cache().cache(cache1)); - Assert.assertNull(ig.context().cache().cache(cache2)); - - Map caches = caches(ig); - - Assert.assertEquals(2, caches.size()); - } - }); - } - - /** - * - */ - public Runnable checkCacheEmpty() { - return onAllNode(new IgniteInClosure() { - @Override public void apply(IgniteEx ig) { - Map desc = cacheDescriptors(ig); - - Assert.assertTrue(desc.isEmpty()); - - Assert.assertNull(ig.context().cache().cache(cache1)); - Assert.assertNull(ig.context().cache().cache(cache2)); - - Map caches = caches(ig); - - Assert.assertEquals(0, caches.size()); - } - }); - } - - /** - * - */ - public Runnable checkCacheNotEmpty() { - return onAllNode(new IgniteInClosure() { - @Override public void apply(IgniteEx ig) { - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(4, desc.size()); - - Assert.assertNotNull(ig.context().cache().cache(cache1)); - Assert.assertNotNull(ig.context().cache().cache(cache2)); - - Map caches = caches(ig); - - Assert.assertEquals(4, caches.size()); - } - }); - } - - /** - * @param cls Closure. - */ - private Runnable onAllNode(final IgniteInClosure cls) { - return new Runnable() { - @Override public void run() { - for (IgniteEx ig : grids()) { - try { - cls.apply(ig); - } - catch (AssertionError e) { - System.out.println("Assertion on " + ig.name()); - - throw e; - } - } - } - }; - } - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateAbstractTest.java index d16b845796c26..4ccc8ed4008b2 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteChangeGlobalStateAbstractTest.java @@ -152,6 +152,8 @@ protected Ignite backUpClient(int idx) { protected void startPrimaryNodes(int cnt) throws Exception { for (int i = 0; i < cnt; i++) startPrimary(i); + + grid("node0" + primarySuffix).active(true); } /** @@ -164,7 +166,6 @@ protected void startPrimary(int idx) throws Exception { IgniteConfiguration cfg = getConfiguration(name); cfg.setConsistentId(node); - cfg.setActiveOnStart(true); ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(primaryIpFinder); Ignite ig = startGrid(name, cfg); @@ -190,7 +191,6 @@ protected void startBackUp(int idx) throws Exception { IgniteConfiguration cfg = getConfiguration(name); cfg.setConsistentId(node); - cfg.setActiveOnStart(false); ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(backUpIpFinder); Ignite ig = startGrid(name, cfg); @@ -242,7 +242,7 @@ protected void startBackUpClientNodes(int cnt) throws Exception { /** * */ - protected Iterable allBackUpNodes(){ + protected Iterable allBackUpNodes() { List r = new ArrayList<>(); for (String name : this.nodes.keySet()) @@ -261,9 +261,9 @@ protected Ignite randomBackUp(boolean includeClient) { List igs = new ArrayList<>(); for (String name : this.nodes.keySet()) - if (name.contains(backUpSuffix)){ + if (name.contains(backUpSuffix)) { if (includeClient) - igs.add(this.nodes.get(name)); + igs.add(this.nodes.get(name)); else { if (name.contains(clientSuffix)) continue; @@ -277,7 +277,6 @@ protected Ignite randomBackUp(boolean includeClient) { return igs.get(idx); } - /** * @param i Idx. */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java deleted file mode 100644 index 2d704db44d137..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java +++ /dev/null @@ -1,213 +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.persistence.standbycluster; - -import java.util.Arrays; -import java.util.Map; -import org.apache.ignite.cluster.ClusterNode; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.configuration.PersistentStoreConfiguration; -import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; -import org.apache.ignite.internal.processors.cache.GridCacheAdapter; -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; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import org.junit.Assert; - -/** - * - */ -public class IgniteStandByClusterTest extends GridCommonAbstractTest { - private static final TcpDiscoveryIpFinder vmIpFinder = new TcpDiscoveryVmIpFinder(true); - - @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); - - cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(vmIpFinder)); - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); - cfg.setConsistentId(igniteInstanceName); - - return cfg; - } - - public void testNotStartDynamicCachesOnClientAfterActivation() throws Exception { - final String cacheName0 = "cache0"; - final String cacheName = "cache"; - - IgniteConfiguration cfg1 = getConfiguration("serv1"); - IgniteConfiguration cfg2 = getConfiguration("serv2"); - - IgniteConfiguration cfg3 = getConfiguration("client"); - cfg3.setCacheConfiguration(new CacheConfiguration(cacheName0)); - - cfg3.setClientMode(true); - - IgniteEx ig1 = startGrid(cfg1); - IgniteEx ig2 = startGrid(cfg2); - IgniteEx ig3 = startGrid(cfg3); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!ig3.active()); - - ig3.active(true); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(ig3.active()); - - ig3.createCache(new CacheConfiguration<>(cacheName)); - - assertNotNull(ig3.cache(cacheName)); - assertNotNull(ig1.cache(cacheName)); - assertNotNull(ig2.cache(cacheName)); - - assertNotNull(ig1.cache(cacheName0)); - assertNotNull(ig3.cache(cacheName0)); - assertNotNull(ig2.cache(cacheName0)); - - ig3.active(false); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!ig3.active()); - - ig3.active(true); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(ig3.active()); - - assertNotNull(ig1.cache(cacheName)); - assertNotNull(ig2.cache(cacheName)); - - Map> caches = U.field(ig3.context().cache(), "caches"); - - // Only system caches and cache0 - assertTrue(caches.size() == 3); - - assertNull(caches.get(cacheName)); - - assertNotNull(caches.get(cacheName0)); - - assertNotNull(ig3.cache(cacheName)); - } - - public void testStaticCacheStartAfterActivationWithCacheFilter() throws Exception { - String cache1 = "cache1"; - String cache2 = "cache2"; - String cache3 = "cache3"; - - IgniteConfiguration cfg1 = getConfiguration("node1"); - - cfg1.setCacheConfiguration( - new CacheConfiguration(cache1).setNodeFilter(new NodeFilterIgnoreByName("node2"))); - - IgniteConfiguration cfg2 = getConfiguration("node2"); - - cfg2.setCacheConfiguration( - new CacheConfiguration(cache2).setNodeFilter(new NodeFilterIgnoreByName("node3"))); - - IgniteConfiguration cfg3 = getConfiguration("node3"); - - cfg3.setCacheConfiguration( - new CacheConfiguration(cache3).setNodeFilter(new NodeFilterIgnoreByName("node1"))); - - IgniteEx ig1 = startGrid(cfg1); - IgniteEx ig2 = startGrid(cfg2); - IgniteEx ig3 = startGrid(cfg3); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!ig3.active()); - - for (IgniteEx ig: Arrays.asList(ig1,ig2,ig3)){ - Map desc = U.field(U.field(ig.context().cache(), "cachesInfo"), "registeredCaches"); - - assertEquals(0, desc.size()); - } - - ig3.active(true); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(ig3.active()); - - for (IgniteEx ig: Arrays.asList(ig1,ig2,ig3)){ - Map desc = U.field( - U.field(ig.context().cache(), "cachesInfo"), "registeredCaches"); - - assertEquals(5, desc.size()); - - Map> caches = U.field(ig.context().cache(), "caches"); - - assertEquals(4, caches.keySet().size()); - } - - Map> caches1 = U.field(ig1.context().cache(), "caches"); - - Assert.assertNotNull(caches1.get(cache1)); - Assert.assertNotNull(caches1.get(cache2)); - Assert.assertNull(caches1.get(cache3)); - - Map> caches2 = U.field(ig2.context().cache(), "caches"); - - Assert.assertNull(caches2.get(cache1)); - Assert.assertNotNull(caches2.get(cache2)); - Assert.assertNotNull(caches2.get(cache3)); - - Map> caches3 = U.field(ig3.context().cache(), "caches"); - - Assert.assertNotNull(caches3.get(cache1)); - Assert.assertNull(caches3.get(cache2)); - Assert.assertNotNull(caches3.get(cache3)); - } - - private static class NodeFilterIgnoreByName implements IgnitePredicate{ - private final String name; - - private NodeFilterIgnoreByName(String name) { - this.name = name; - } - - @Override public boolean apply(ClusterNode node) { - return !name.equals(node.consistentId()); - } - } - - @Override protected void beforeTest() throws Exception { - super.beforeTest(); - - stopAllGrids(); - - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); - } - - @Override protected void afterTest() throws Exception { - super.beforeTest(); - - stopAllGrids(); - - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToActiveCluster.java deleted file mode 100644 index fc9d307e3ba73..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToActiveCluster.java +++ /dev/null @@ -1,431 +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.persistence.standbycluster.join; - -import java.util.Map; -import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; -import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; -import org.apache.ignite.internal.processors.cache.GridCacheAdapter; -import org.junit.Assert; - -/** - * - */ -public class JoinActiveNodeToActiveCluster extends AbstractNodeJoinTemplate { - /** - * - */ - @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)).setActiveOnStart(true), - cfg(name(1)).setActiveOnStart(true), - cfg(name(2)).setActiveOnStart(true) - ).afterClusterStarted( - b.checkCacheOnlySystem() - ).nodeConfiguration( - cfg(name(3)).setActiveOnStart(true) - ).afterNodeJoin( - b.checkCacheOnlySystem() - ).stateAfterJoin( - true - ).afterDeActivate( - b.checkCacheEmpty() - ).setEnd( - b.checkCacheOnlySystem() - ); - - return b; - } - - /** - * - */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)).setActiveOnStart(true), - cfg(name(1)).setActiveOnStart(true), - cfg(name(2)).setActiveOnStart(true) - ).afterClusterStarted( - b.checkCacheOnlySystem() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(true) - .setCacheConfiguration(allCacheConfigurations()) - ).afterNodeJoin( - b.checkCacheNotEmpty() - ).stateAfterJoin( - true - ).afterDeActivate( - b.checkCacheEmpty() - ).setEnd( - b.checkCacheNotEmpty() - ); - - return b; - } - - /** - * - */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(true) - .setCacheConfiguration(allCacheConfigurations()), - cfg(name(1)).setActiveOnStart(true), - cfg(name(2)).setActiveOnStart(true) - ).afterClusterStarted( - b.checkCacheNotEmpty() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(true) - ).afterNodeJoin( - b.checkCacheNotEmpty() - ).stateAfterJoin( - true - ).afterDeActivate( - b.checkCacheEmpty() - ).setEnd( - b.checkCacheNotEmpty() - ); - - return b; - } - - /** - * - */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(true) - .setCacheConfiguration(allCacheConfigurations()), - cfg(name(1)).setActiveOnStart(true), - cfg(name(2)).setActiveOnStart(true) - ).afterClusterStarted( - b.checkCacheNotEmpty() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(true) - .setCacheConfiguration(allCacheConfigurations()) - ).afterNodeJoin( - b.checkCacheNotEmpty() - ).stateAfterJoin( - true - ).afterDeActivate( - b.checkCacheEmpty() - ).setEnd( - b.checkCacheNotEmpty() - ); - - return b; - } - - /** - * - */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(true) - .setCacheConfiguration(atomicCfg()), - cfg(name(1)).setActiveOnStart(true), - cfg(name(2)).setActiveOnStart(true) - ).afterClusterStarted( - new Runnable() { - @Override public void run() { - for (int i = 0; i < 3; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(3, desc.size()); - - Assert.assertNotNull(ig.context().cache().cache(cache1)); - Assert.assertNull(ig.context().cache().cache(cache2)); - - Map caches = caches(ig); - - Assert.assertEquals(3, caches.size()); - } - } - } - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(true) - .setCacheConfiguration(transactionCfg()) - ).afterNodeJoin( - b.checkCacheNotEmpty() - ).stateAfterJoin( - true - ).afterDeActivate( - b.checkCacheEmpty() - ).setEnd( - b.checkCacheNotEmpty() - ); - - return b; - } - - // Server node join. - - /** {@inheritDoc} */ - @Override public void testJoinWithOutConfiguration() throws Exception { - withOutConfigurationTemplate().execute(); - } - - /** - * - */ - @Override public void testStaticCacheConfigurationOnJoin() throws Exception { - staticCacheConfigurationOnJoinTemplate().execute(); - } - - /** - * - */ - @Override public void testStaticCacheConfigurationInCluster() throws Exception { - staticCacheConfigurationInClusterTemplate().execute(); - } - - /** - * - */ - @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { - staticCacheConfigurationSameOnBothTemplate().execute(); - } - - /** - * - */ - @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { - staticCacheConfigurationDifferentOnBothTemplate().execute(); - } - - // Client node join. - - /** - * - */ - @Override public void testJoinClientWithOutConfiguration() throws Exception { - joinClientWithOutConfigurationTemplate().execute(); - } - - /** - * - */ - @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { - joinClientStaticCacheConfigurationOnJoinTemplate().execute(); - } - - /** - * - */ - @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { - joinClientStaticCacheConfigurationInClusterTemplate().execute(); - } - - /** - * - */ - @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { - joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); - } - - /** - * - */ - @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { - joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); - } - - @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { - return withOutConfigurationTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { - return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { - return staticCacheConfigurationInClusterTemplate() - .nodeConfiguration(setClient) - .afterActivate(new Runnable() { - @Override public void run() { - for (int i = 0; i < 3; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(4, desc.size()); - - if (!ig.context().discovery().localNode().isClient()) { - Assert.assertNotNull(ig.context().cache().cache(cache1)); - Assert.assertNotNull(ig.context().cache().cache(cache2)); - } - else { - Assert.assertNull(ig.context().cache().cache(cache1)); - Assert.assertNull(ig.context().cache().cache(cache2)); - } - - Map caches = caches(ig); - - Assert.assertEquals(4, caches.size()); - } - } - }).afterNodeJoin( - new Runnable() { - @Override public void run() { - for (int i = 0; i < 3; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(4, desc.size()); - - if (!ig.context().discovery().localNode().isClient()) { - Assert.assertNotNull(ig.context().cache().cache(cache1)); - Assert.assertNotNull(ig.context().cache().cache(cache2)); - } - else { - Assert.assertNull(ig.context().cache().cache(cache1)); - Assert.assertNull(ig.context().cache().cache(cache2)); - } - - Map caches = caches(ig); - - Assert.assertEquals(4, caches.size()); - } - } - }).setEnd(new Runnable() { - @Override public void run() { - for (int i = 0; i < 3; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(4, desc.size()); - - if (!ig.context().discovery().localNode().isClient()) { - Assert.assertNotNull(ig.context().cache().cache(cache1)); - Assert.assertNotNull(ig.context().cache().cache(cache2)); - } - else { - Assert.assertNull(ig.context().cache().cache(cache1)); - Assert.assertNull(ig.context().cache().cache(cache2)); - } - - Map caches = caches(ig); - - Assert.assertEquals(4, caches.size()); - } - } - }); - } - - @Override - public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { - return staticCacheConfigurationDifferentOnBothTemplate() - .nodeConfiguration(setClient) - .afterActivate(new Runnable() { - @Override public void run() { - for (int i = 0; i < 3; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(4, desc.size()); - - if (!ig.context().discovery().localNode().isClient()) { - Assert.assertNotNull(ig.context().cache().cache(cache1)); - Assert.assertNotNull(ig.context().cache().cache(cache2)); - } - else { - Assert.assertNull(ig.context().cache().cache(cache1)); - Assert.assertNotNull(ig.context().cache().cache(cache2)); - } - - Map caches = caches(ig); - - Assert.assertEquals(4, caches.size()); - } - } - }) - .afterNodeJoin(new Runnable() { - @Override public void run() { - for (int i = 0; i < 4; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(4, desc.size()); - - if (!ig.context().discovery().localNode().isClient()) - Assert.assertNotNull(ig.context().cache().cache(cache1)); - - Assert.assertNotNull(ig.context().cache().cache(cache2)); - - Map caches = caches(ig); - - if (!ig.context().discovery().localNode().isClient()) - Assert.assertEquals(4, caches.size()); - else - Assert.assertEquals(3, caches.size()); - } - } - }) - .setEnd(new Runnable() { - @Override public void run() { - for (int i = 0; i < 4; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(4, desc.size()); - - if (!ig.context().discovery().localNode().isClient()) - Assert.assertNotNull(ig.context().cache().cache(cache1)); - - Assert.assertNotNull(ig.context().cache().cache(cache2)); - - Map caches = caches(ig); - - if (!ig.context().discovery().localNode().isClient()) - Assert.assertEquals(4, caches.size()); - else - Assert.assertEquals(3, caches.size()); - } - } - }); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { - return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToInActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToInActiveCluster.java deleted file mode 100644 index b248b210804f3..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToInActiveCluster.java +++ /dev/null @@ -1,227 +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.persistence.standbycluster.join; - -import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; - -/** - * - */ -public class JoinActiveNodeToInActiveCluster extends AbstractNodeJoinTemplate { - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)).setActiveOnStart(false), - cfg(name(1)).setActiveOnStart(false), - cfg(name(2)).setActiveOnStart(false) - ).afterClusterStarted( - b.checkCacheEmpty() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(true) - ).afterNodeJoin( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterActivate( - b.checkCacheOnlySystem() - ); - - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)).setActiveOnStart(false), - cfg(name(1)).setActiveOnStart(false), - cfg(name(2)).setActiveOnStart(false) - ).afterClusterStarted( - b.checkCacheEmpty() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(true) - .setCacheConfiguration(allCacheConfigurations()) - ).afterNodeJoin( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterActivate( - b.checkCacheNotEmpty() - ); - - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(false) - .setCacheConfiguration(allCacheConfigurations()), - cfg(name(1)).setActiveOnStart(false), - cfg(name(2)).setActiveOnStart(false) - ).afterClusterStarted( - b.checkCacheEmpty() - ).nodeConfiguration( - cfg(name(3)).setActiveOnStart(true) - ).afterNodeJoin( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterActivate( - b.checkCacheNotEmpty() - ); - - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(false) - .setCacheConfiguration(allCacheConfigurations()), - cfg(name(1)).setActiveOnStart(false), - cfg(name(2)).setActiveOnStart(false) - ).afterClusterStarted( - b.checkCacheEmpty() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(true) - .setCacheConfiguration(allCacheConfigurations()) - ).afterNodeJoin( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterActivate( - b.checkCacheNotEmpty() - ); - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(false) - .setCacheConfiguration(atomicCfg()), - cfg(name(1)).setActiveOnStart(false), - cfg(name(2)).setActiveOnStart(false) - ).afterClusterStarted( - b.checkCacheEmpty() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(true) - .setCacheConfiguration(transactionCfg()) - ).afterNodeJoin( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterActivate( - b.checkCacheNotEmpty() - ); - - return b; - } - - // Server node join. - - /** {@inheritDoc} */ - @Override public void testJoinWithOutConfiguration() throws Exception { - withOutConfigurationTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationOnJoin() throws Exception { - staticCacheConfigurationOnJoinTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationInCluster() throws Exception { - staticCacheConfigurationInClusterTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { - staticCacheConfigurationSameOnBothTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { - staticCacheConfigurationDifferentOnBothTemplate().execute(); - } - - // Client node join. - - /** {@inheritDoc} */ - @Override public void testJoinClientWithOutConfiguration() throws Exception { - joinClientWithOutConfigurationTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { - joinClientStaticCacheConfigurationOnJoinTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { - joinClientStaticCacheConfigurationInClusterTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { - joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { - joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); - } - - @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { - return withOutConfigurationTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { - return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { - return staticCacheConfigurationInClusterTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { - return staticCacheConfigurationDifferentOnBothTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { - return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); - } - -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToActiveCluster.java deleted file mode 100644 index 6ba3a2020d171..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToActiveCluster.java +++ /dev/null @@ -1,356 +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.persistence.standbycluster.join; - -import java.util.Map; -import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; -import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; -import org.apache.ignite.internal.processors.cache.GridCacheAdapter; -import org.junit.Assert; - -/** - * - */ -public class JoinInActiveNodeToActiveCluster extends AbstractNodeJoinTemplate { - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)).setActiveOnStart(true), - cfg(name(1)).setActiveOnStart(true), - cfg(name(2)).setActiveOnStart(true) - ).afterClusterStarted( - b.checkCacheOnlySystem() - ).nodeConfiguration( - cfg(name(3)).setActiveOnStart(false) - ).afterNodeJoin( - b.checkCacheOnlySystem() - ).stateAfterJoin( - true - ).afterDeActivate( - b.checkCacheEmpty() - ).setEnd( - b.checkCacheOnlySystem() - ); - - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)).setActiveOnStart(true), - cfg(name(1)).setActiveOnStart(true), - cfg(name(2)).setActiveOnStart(true) - ).afterClusterStarted( - b.checkCacheOnlySystem() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(false) - .setCacheConfiguration(allCacheConfigurations()) - ).afterNodeJoin( - b.checkCacheNotEmpty() - ).stateAfterJoin( - true - ).afterDeActivate( - b.checkCacheEmpty() - ).setEnd( - b.checkCacheNotEmpty() - ); - - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(true) - .setCacheConfiguration(allCacheConfigurations()), - cfg(name(1)).setActiveOnStart(true), - cfg(name(2)).setActiveOnStart(true) - ).afterClusterStarted( - b.checkCacheNotEmpty() - ).nodeConfiguration( - cfg(name(3)).setActiveOnStart(false) - ).afterNodeJoin( - b.checkCacheNotEmpty() - ).stateAfterJoin( - true - ).afterDeActivate( - b.checkCacheEmpty() - ).setEnd( - b.checkCacheNotEmpty() - ); - - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(true) - .setCacheConfiguration(allCacheConfigurations()), - cfg(name(1)).setActiveOnStart(true), - cfg(name(2)).setActiveOnStart(true) - ).afterClusterStarted( - b.checkCacheNotEmpty() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(false) - .setCacheConfiguration(allCacheConfigurations()) - ).afterNodeJoin( - b.checkCacheNotEmpty() - ).stateAfterJoin( - true - ).afterDeActivate( - b.checkCacheEmpty() - ).setEnd( - b.checkCacheNotEmpty() - ); - - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(true) - .setCacheConfiguration(atomicCfg()), - cfg(name(1)).setActiveOnStart(true), - cfg(name(2)).setActiveOnStart(true) - ).afterClusterStarted( - new Runnable() { - @Override public void run() { - for (int i = 0; i < 3; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(3, desc.size()); - - Assert.assertNotNull(ig.context().cache().cache(cache1)); - Assert.assertNull(ig.context().cache().cache(cache2)); - - Map caches = caches(ig); - - Assert.assertEquals(3, caches.size()); - } - } - } - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(false) - .setCacheConfiguration(transactionCfg()) - ).afterNodeJoin( - b.checkCacheNotEmpty() - ).stateAfterJoin( - true - ).afterDeActivate( - b.checkCacheEmpty() - ).setEnd( - b.checkCacheNotEmpty() - ); - - return b; - } - - // Server node join. - - /** {@inheritDoc} */ - @Override public void testJoinWithOutConfiguration() throws Exception { - withOutConfigurationTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationOnJoin() throws Exception { - staticCacheConfigurationOnJoinTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationInCluster() throws Exception { - staticCacheConfigurationInClusterTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { - staticCacheConfigurationSameOnBothTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { - staticCacheConfigurationDifferentOnBothTemplate().execute(); - } - - // Client node join. - - /** {@inheritDoc} */ - @Override public void testJoinClientWithOutConfiguration() throws Exception { - joinClientWithOutConfigurationTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { - joinClientStaticCacheConfigurationOnJoinTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { - joinClientStaticCacheConfigurationInClusterTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { - joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { - joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); - } - - @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { - return withOutConfigurationTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { - return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { - return staticCacheConfigurationInClusterTemplate() - .nodeConfiguration(setClient) - .afterNodeJoin(new Runnable() { - @Override public void run() { - for (int i = 0; i < 3; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(4, desc.size()); - - if (!ig.context().discovery().localNode().isClient()) { - Assert.assertNotNull(ig.context().cache().cache(cache1)); - Assert.assertNotNull(ig.context().cache().cache(cache2)); - } - else { - Assert.assertNull(ig.context().cache().cache(cache1)); - Assert.assertNull(ig.context().cache().cache(cache2)); - } - - Map caches = caches(ig); - - Assert.assertEquals(4, caches.size()); - } - } - }).setEnd(new Runnable() { - @Override public void run() { - for (int i = 0; i < 3; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(4, desc.size()); - - if (!ig.context().discovery().localNode().isClient()) { - Assert.assertNotNull(ig.context().cache().cache(cache1)); - Assert.assertNotNull(ig.context().cache().cache(cache2)); - } - else { - Assert.assertNull(ig.context().cache().cache(cache1)); - Assert.assertNull(ig.context().cache().cache(cache2)); - } - - Map caches = caches(ig); - - Assert.assertEquals(4, caches.size()); - } - } - }); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { - return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { - return staticCacheConfigurationDifferentOnBothTemplate() - .nodeConfiguration(setClient) - .afterNodeJoin( - new Runnable() { - @Override public void run() { - for (int i = 0; i < 4; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(4, desc.size()); - - if (!ig.context().discovery().localNode().isClient()) - Assert.assertNotNull(ig.context().cache().cache(cache1)); - - Assert.assertNotNull(ig.context().cache().cache(cache2)); - - Map caches = caches(ig); - - if (!ig.context().discovery().localNode().isClient()) - Assert.assertEquals(4, caches.size()); - else - Assert.assertEquals(3, caches.size()); - } - } - } - ).setEnd( - new Runnable() { - @Override public void run() { - for (int i = 0; i < 4; i++) { - IgniteEx ig = grid(name(i)); - - Map desc = cacheDescriptors(ig); - - Assert.assertEquals(4, desc.size()); - - if (!ig.context().discovery().localNode().isClient()) - Assert.assertNotNull(ig.context().cache().cache(cache1)); - - Assert.assertNotNull(ig.context().cache().cache(cache2)); - - Map caches = caches(ig); - - if (!ig.context().discovery().localNode().isClient()) - Assert.assertEquals(4, caches.size()); - else - Assert.assertEquals(3, caches.size()); - } - } - } - ); - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToInActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToInActiveCluster.java deleted file mode 100644 index 244001bf1c486..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToInActiveCluster.java +++ /dev/null @@ -1,226 +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.persistence.standbycluster.join; - -import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; - -/** - * - */ -public class JoinInActiveNodeToInActiveCluster extends AbstractNodeJoinTemplate { - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)).setActiveOnStart(false), - cfg(name(1)).setActiveOnStart(false), - cfg(name(2)).setActiveOnStart(false) - ).afterClusterStarted( - b.checkCacheEmpty() - ).nodeConfiguration( - cfg(name(3)).setActiveOnStart(false) - ).afterNodeJoin( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterActivate( - b.checkCacheOnlySystem() - ); - - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)).setActiveOnStart(false), - cfg(name(1)).setActiveOnStart(false), - cfg(name(2)).setActiveOnStart(false) - ).afterClusterStarted( - b.checkCacheEmpty() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(false) - .setCacheConfiguration(allCacheConfigurations()) - ).afterNodeJoin( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterActivate( - b.checkCacheNotEmpty() - ); - - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(false) - .setCacheConfiguration(allCacheConfigurations()), - cfg(name(1)).setActiveOnStart(false), - cfg(name(2)).setActiveOnStart(false) - ).afterClusterStarted( - b.checkCacheEmpty() - ).nodeConfiguration( - cfg(name(3)).setActiveOnStart(false) - ).afterNodeJoin( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterActivate( - b.checkCacheNotEmpty() - ); - - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(false) - .setCacheConfiguration(allCacheConfigurations()), - cfg(name(1)).setActiveOnStart(false), - cfg(name(2)).setActiveOnStart(false) - ).afterClusterStarted( - b.checkCacheEmpty() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(false) - .setCacheConfiguration(allCacheConfigurations()) - ).afterNodeJoin( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterActivate( - b.checkCacheNotEmpty() - ); - - return b; - } - - /** {@inheritDoc} */ - @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { - JoinNodeTestPlanBuilder b = builder(); - - b.clusterConfiguration( - cfg(name(0)) - .setActiveOnStart(false) - .setCacheConfiguration(transactionCfg()), - cfg(name(1)).setActiveOnStart(false), - cfg(name(2)).setActiveOnStart(false) - ).afterClusterStarted( - b.checkCacheEmpty() - ).nodeConfiguration( - cfg(name(3)) - .setActiveOnStart(false) - .setCacheConfiguration(atomicCfg()) - ).afterNodeJoin( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterActivate( - b.checkCacheNotEmpty() - ); - - return b; - } - - // Server node join. - - /** {@inheritDoc} */ - @Override public void testJoinWithOutConfiguration() throws Exception { - withOutConfigurationTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationOnJoin() throws Exception { - staticCacheConfigurationOnJoinTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationInCluster() throws Exception { - staticCacheConfigurationInClusterTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { - staticCacheConfigurationSameOnBothTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { - staticCacheConfigurationDifferentOnBothTemplate().execute(); - } - - // Client node join. - - /** {@inheritDoc} */ - @Override public void testJoinClientWithOutConfiguration() throws Exception { - joinClientWithOutConfigurationTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { - joinClientStaticCacheConfigurationOnJoinTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { - joinClientStaticCacheConfigurationInClusterTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { - joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); - } - - /** {@inheritDoc} */ - @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { - joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); - } - - @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { - return withOutConfigurationTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { - return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { - return staticCacheConfigurationInClusterTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { - return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); - } - - @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { - return staticCacheConfigurationDifferentOnBothTemplate().nodeConfiguration(setClient); - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java deleted file mode 100644 index 54087ba883e1d..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java +++ /dev/null @@ -1,98 +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.persistence.standbycluster.join.persistence; - -import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinActiveNodeToActiveCluster; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; - -/** - * - */ -public class JoinActiveNodeToActiveClusterWithPersistence extends JoinActiveNodeToActiveCluster { - /** {@inheritDoc} */ - @Override protected IgniteConfiguration cfg(String name) throws Exception { - return persistentCfg(super.cfg(name)); - } - - private AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder persistent(AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b) { - b.afterClusterStarted( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterNodeJoin( - b.checkCacheEmpty() - ).afterActivate( - b.checkCacheNotEmpty() - ); - - return b; - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { - AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.withOutConfigurationTemplate()); - - b.afterActivate(b.checkCacheOnlySystem()); - - return b; - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { - AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.joinClientWithOutConfigurationTemplate()); - - b.afterActivate(b.checkCacheOnlySystem()); - - return b; - } - - @Override public void testJoinWithOutConfiguration() throws Exception { - withOutConfigurationTemplate().execute(); - } - - @Override public void testJoinClientWithOutConfiguration() throws Exception { - joinClientWithOutConfigurationTemplate().execute(); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { - return persistent(super.staticCacheConfigurationOnJoinTemplate()); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { - return persistent(super.staticCacheConfigurationInClusterTemplate()); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { - return persistent(super.staticCacheConfigurationSameOnBothTemplate()); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { - return persistent(super.staticCacheConfigurationDifferentOnBothTemplate()); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { - return persistent(super.joinClientStaticCacheConfigurationOnJoinTemplate()); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { - return persistent(super.joinClientStaticCacheConfigurationInClusterTemplate()); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { - return persistent(super.joinClientStaticCacheConfigurationDifferentOnBothTemplate()); - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java deleted file mode 100644 index 305255c95c214..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java +++ /dev/null @@ -1,31 +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.persistence.standbycluster.join.persistence; - -import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinActiveNodeToInActiveCluster; -import org.apache.ignite.configuration.IgniteConfiguration; - -/** - * - */ -public class JoinActiveNodeToInActiveClusterWithPersistence extends JoinActiveNodeToInActiveCluster { - /** {@inheritDoc} */ - @Override protected IgniteConfiguration cfg(String name) throws Exception { - return persistentCfg(super.cfg(name)); - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java deleted file mode 100644 index a138d8dcdb8cd..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java +++ /dev/null @@ -1,86 +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.persistence.standbycluster.join.persistence; - -import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinInActiveNodeToActiveCluster; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; - -/** - * - */ -public class JoinInActiveNodeToActiveClusterWithPersistence extends JoinInActiveNodeToActiveCluster { - /** {@inheritDoc} */ - @Override protected IgniteConfiguration cfg(String name) throws Exception { - return persistentCfg(super.cfg(name)); - } - - private AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder persistent(AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b) { - b.afterClusterStarted( - b.checkCacheEmpty() - ).stateAfterJoin( - false - ).afterNodeJoin( - b.checkCacheEmpty() - ).afterActivate( - b.checkCacheNotEmpty() - ); - - return b; - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { - AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.withOutConfigurationTemplate()); - - b.afterActivate(b.checkCacheOnlySystem()); - - return b; - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { - AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.joinClientWithOutConfigurationTemplate()); - - b.afterActivate(b.checkCacheOnlySystem()); - - return b; - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception{ - return persistent(super.joinClientStaticCacheConfigurationInClusterTemplate()); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { - return persistent(super.joinClientStaticCacheConfigurationDifferentOnBothTemplate()); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { - return persistent(super.staticCacheConfigurationOnJoinTemplate()); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { - return persistent(super.staticCacheConfigurationInClusterTemplate()); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { - return persistent(super.staticCacheConfigurationSameOnBothTemplate()); - } - - @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { - return persistent(super.staticCacheConfigurationDifferentOnBothTemplate()); - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java deleted file mode 100644 index b3db10d045e34..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java +++ /dev/null @@ -1,31 +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.persistence.standbycluster.join.persistence; - -import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinInActiveNodeToInActiveCluster; -import org.apache.ignite.configuration.IgniteConfiguration; - -/** - * - */ -public class JoinInActiveNodeToInActiveClusterWithPersistence extends JoinInActiveNodeToInActiveCluster { - /** {@inheritDoc} */ - @Override protected IgniteConfiguration cfg(String name) throws Exception { - return persistentCfg(super.cfg(name)); - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java deleted file mode 100644 index eec267b5ed208..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java +++ /dev/null @@ -1,336 +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.persistence.standbycluster.reconnect; - -import com.google.common.collect.Sets; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import org.apache.ignite.cluster.ClusterNode; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.configuration.PersistentStoreConfiguration; -import org.apache.ignite.events.Event; -import org.apache.ignite.events.EventType; -import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; -import org.apache.ignite.internal.util.typedef.internal.CU; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.lang.IgnitePredicate; -import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage; -import org.apache.ignite.spi.discovery.DiscoverySpiListener; -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.jetbrains.annotations.Nullable; -import org.junit.Assert; - -import static org.apache.ignite.events.EventType.EVT_CLIENT_NODE_DISCONNECTED; - -/** - * - */ -public abstract class IgniteAbstractStandByClientReconnectTest extends GridCommonAbstractTest { - - private static final TcpDiscoveryVmIpFinder vmIpFinder = new TcpDiscoveryVmIpFinder(true); - - private static final TcpDiscoveryVmIpFinder clientIpFinder = new TcpDiscoveryVmIpFinder(true); - - protected final String node1 = "node1"; - protected final String node2 = "node2"; - protected final String nodeClient = "nodeClient"; - - protected final String ccfg1staticName = "cache1static"; - protected final String ccfg2staticName = "cache2static"; - protected final String ccfg3staticName = "cache3static"; - - protected final String ccfg1staticWithFilterName = "ccfg1staticWithFilter"; - protected final String ccfg2staticWithFilterName = "ccfg2staticWithFilter"; - protected final String ccfg3staticWithFilterName = "ccfg3staticWithFilter"; - - protected final String ccfgDynamicName = "ccfgDynamic"; - protected final String ccfgDynamicWithFilterName = "ccfgDynamicWithFilter"; - - protected final CacheConfiguration ccfg1static = new CacheConfiguration(ccfg1staticName); - protected final CacheConfiguration ccfg2static = new CacheConfiguration(ccfg2staticName); - protected final CacheConfiguration ccfg3static = new CacheConfiguration(ccfg3staticName); - - protected final CacheConfiguration ccfg1staticWithFilter = - new CacheConfiguration(ccfg1staticWithFilterName).setNodeFilter(new FilterNode(node2)); - - protected final CacheConfiguration ccfg2staticWithFilter = - new CacheConfiguration(ccfg2staticWithFilterName).setNodeFilter(new FilterNode(nodeClient)); - - protected final CacheConfiguration ccfg3staticWithFilter = - new CacheConfiguration(ccfg3staticWithFilterName).setNodeFilter(new FilterNode(node1)); - - protected final CacheConfiguration ccfgDynamic = new CacheConfiguration(ccfgDynamicName); - - protected final CacheConfiguration ccfgDynamicWithFilter = - new CacheConfiguration(ccfgDynamicWithFilterName).setNodeFilter(new FilterNode(node2)); - - protected final Set staticCacheNames = Sets.newHashSet( - ccfg1staticName, ccfg2staticName, ccfg3staticName, - ccfg1staticWithFilterName, ccfg2staticWithFilterName, ccfg3staticWithFilterName - ); - - protected final Set allCacheNames = Sets.newHashSet( - ccfg1staticName, ccfg2staticName, ccfg3staticName, - ccfg1staticWithFilterName, ccfg2staticWithFilterName, ccfg3staticWithFilterName, - ccfgDynamicName, ccfgDynamicWithFilterName - ); - - @Override protected IgniteConfiguration getConfiguration(String name) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(name); - - if (!nodeClient.equals(name)) - cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(vmIpFinder)); - else { - clientIpFinder.setAddresses(Collections.singletonList("127.0.0.1:47501")); - - cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(clientIpFinder)); - } - - cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); - cfg.setConsistentId(name); - - return cfg; - } - - protected void addDisconnectListener( - final CountDownLatch disconnectedLatch, - final CountDownLatch reconnectedLatch - ) { - grid(nodeClient).events().localListen(new IgnitePredicate() { - @Override public boolean apply(Event event) { - switch (event.type()) { - case EventType.EVT_CLIENT_NODE_DISCONNECTED: - info("Client disconnected"); - - disconnectedLatch.countDown(); - - break; - case EventType.EVT_CLIENT_NODE_RECONNECTED: - info("Client reconnected"); - - reconnectedLatch.countDown(); - } - - return true; - } - }, EventType.EVT_CLIENT_NODE_DISCONNECTED, EventType.EVT_CLIENT_NODE_RECONNECTED); - } - - protected void checkDescriptors(IgniteEx ig, Set cacheNames) { - Collection descs = ig.context().cache().cacheDescriptors().values(); - - assertEquals("Node name: " + ig.name(), cacheNames.size() + 2, descs.size()); - - int systemCnt = 0; - - for (DynamicCacheDescriptor desc : descs) - if (!CU.isSystemCache(desc.cacheName())) - assertTrue(desc.cacheName(), cacheNames.contains(desc.cacheName())); - else - systemCnt++; - - assertEquals(2, systemCnt); - } - - protected void startNodes(CountDownLatch activateLatch) throws Exception { - IgniteConfiguration cfg1 = getConfiguration(node1) - .setCacheConfiguration(ccfg1static, ccfg1staticWithFilter); - - IgniteConfiguration cfg2 = getConfiguration(node2) - .setCacheConfiguration(ccfg2static, ccfg2staticWithFilter); - - IgniteConfiguration cfg3 = getConfiguration(nodeClient) - .setCacheConfiguration(ccfg3static, ccfg3staticWithFilter); - - if (activateLatch != null) - cfg3.setDiscoverySpi( - new AwaitTcpDiscoverySpi(activateLatch) - .setIpFinder(clientIpFinder) - ); - - cfg3.setClientMode(true); - - IgniteEx ig1 = startGrid(cfg1); - IgniteEx ig2 = startGrid(cfg2); - IgniteEx client = startGrid(cfg3); - } - - protected void checkStaticCaches() { - IgniteEx ig1 = grid(node1); - IgniteEx ig2 = grid(node2); - IgniteEx client = grid(nodeClient); - - Assert.assertNotNull(ig1.cache(ccfg1staticName)); - Assert.assertNotNull(ig1.cache(ccfg2staticName)); - Assert.assertNotNull(ig1.cache(ccfg3staticName)); - - Assert.assertNotNull(ig1.cache(ccfg1staticWithFilterName)); - Assert.assertNotNull(ig1.cache(ccfg2staticWithFilterName)); - - Assert.assertNotNull(ig2.cache(ccfg1staticName)); - Assert.assertNotNull(ig2.cache(ccfg2staticName)); - Assert.assertNotNull(ig2.cache(ccfg3staticName)); - - Assert.assertNotNull(ig2.cache(ccfg3staticWithFilterName)); - Assert.assertNotNull(ig2.cache(ccfg2staticWithFilterName)); - - Assert.assertNotNull(client.cache(ccfg1staticName)); - Assert.assertNotNull(client.cache(ccfg2staticName)); - Assert.assertNotNull(client.cache(ccfg3staticName)); - - Assert.assertNotNull(client.cache(ccfg3staticWithFilterName)); - Assert.assertNotNull(client.cache(ccfg1staticWithFilterName)); - } - - protected void checkAllCaches() { - IgniteEx ig1 = grid(node1); - IgniteEx ig2 = grid(node2); - IgniteEx client = grid(nodeClient); - - checkStaticCaches(); - - Assert.assertNotNull(ig1.cache(ccfgDynamicName)); - Assert.assertNotNull(ig1.cache(ccfgDynamicWithFilterName)); - - Assert.assertNotNull(ig2.cache(ccfgDynamicName)); - - Assert.assertNotNull(client.cache(ccfgDynamicName)); - Assert.assertNotNull(client.cache(ccfgDynamicWithFilterName)); - } - - protected void checkOnlySystemCaches() { - IgniteEx ig1 = grid(node1); - IgniteEx ig2 = grid(node2); - IgniteEx client = grid(nodeClient); - - Assert.assertNull(ig1.cache(ccfg1staticName)); - Assert.assertNull(ig1.cache(ccfg2staticName)); - Assert.assertNull(ig1.cache(ccfg3staticName)); - - Assert.assertNull(ig1.cache(ccfg1staticWithFilterName)); - Assert.assertNull(ig1.cache(ccfg2staticWithFilterName)); - - Assert.assertNull(ig2.cache(ccfg1staticName)); - Assert.assertNull(ig2.cache(ccfg2staticName)); - Assert.assertNull(ig2.cache(ccfg3staticName)); - - Assert.assertNull(ig2.cache(ccfg3staticWithFilterName)); - Assert.assertNull(ig2.cache(ccfg2staticWithFilterName)); - - Assert.assertNull(client.cache(ccfg1staticName)); - Assert.assertNull(client.cache(ccfg2staticName)); - Assert.assertNull(client.cache(ccfg3staticName)); - - Assert.assertNull(client.cache(ccfg3staticWithFilterName)); - Assert.assertNull(client.cache(ccfg1staticWithFilterName)); - - checkDescriptors(ig1,Collections.emptySet()); - checkDescriptors(ig2,Collections.emptySet()); - checkDescriptors(client, Collections.emptySet()); - } - - private static class FilterNode implements IgnitePredicate { - - private final String consistentId; - - private FilterNode(String id) { - consistentId = id; - } - - @Override public boolean apply(ClusterNode node) { - return !consistentId.equals(node.consistentId()); - } - } - - private static class AwaitTcpDiscoverySpi extends TcpDiscoverySpi { - - private final CountDownLatch latch; - - private AwaitTcpDiscoverySpi(CountDownLatch latch) { - this.latch = latch; - } - - @Override public void setListener(@Nullable DiscoverySpiListener lsnr) { - super.setListener(new AwaitDiscoverySpiListener(latch, lsnr)); - } - } - - private static class AwaitDiscoverySpiListener implements DiscoverySpiListener { - - private final CountDownLatch latch; - - private final DiscoverySpiListener delegate; - - private AwaitDiscoverySpiListener( - CountDownLatch latch, - DiscoverySpiListener delegate - ) { - this.latch = latch; - this.delegate = delegate; - } - - @Override public void onLocalNodeInitialized(ClusterNode locNode) { - delegate.onLocalNodeInitialized(locNode); - } - - @Override public void onDiscovery( - int type, - long topVer, - ClusterNode node, - Collection topSnapshot, - @Nullable Map> topHist, - @Nullable DiscoverySpiCustomMessage data - ) { - delegate.onDiscovery(type, topVer, node, topSnapshot, topHist, data); - - if (type == EVT_CLIENT_NODE_DISCONNECTED) - try { - System.out.println("Await cluster change state"); - - latch.await(); - } - catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - } - - @Override protected void beforeTest() throws Exception { - super.beforeTest(); - - stopAllGrids(); - - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); - } - - @Override protected void afterTest() throws Exception { - super.beforeTest(); - - stopAllGrids(); - - deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); - } - -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectTest.java deleted file mode 100644 index 02f7d000e5853..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectTest.java +++ /dev/null @@ -1,283 +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.persistence.standbycluster.reconnect; - -import java.util.concurrent.CountDownLatch; -import org.apache.ignite.internal.IgniteEx; - -/** - * - */ -public class IgniteStandByClientReconnectTest extends IgniteAbstractStandByClientReconnectTest { - - public void testActiveClientReconnectToActiveCluster() throws Exception { - CountDownLatch activateLatch = new CountDownLatch(1); - - startNodes(activateLatch); - - info(">>>> star grid"); - - IgniteEx ig1 = grid(node1); - IgniteEx ig2 = grid(node2); - IgniteEx client = grid(nodeClient); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - client.active(true); - - info(">>>> activate grid"); - - checkDescriptors(ig1, staticCacheNames); - checkDescriptors(ig2, staticCacheNames); - checkDescriptors(client, staticCacheNames); - - checkStaticCaches(); - - client.createCache(ccfgDynamic); - - client.createCache(ccfgDynamicWithFilter); - - info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - checkDescriptors(ig1, allCacheNames); - checkDescriptors(ig2, allCacheNames); - checkDescriptors(client, allCacheNames); - - final CountDownLatch disconnectedLatch = new CountDownLatch(1); - final CountDownLatch reconnectedLatch = new CountDownLatch(1); - - addDisconnectListener(disconnectedLatch, reconnectedLatch); - - info(">>>> stop servers"); - - stopGrid(node2); - - disconnectedLatch.await(); - - ig2 = startGrid(getConfiguration(node2)); - - info(">>>> activate new servers"); - - ig1.active(true); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - - activateLatch.countDown(); - - info(">>>> reconnect client"); - - reconnectedLatch.await(); - - info(">>>> client reconnected"); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - checkDescriptors(ig1, allCacheNames); - checkDescriptors(ig2, allCacheNames); - checkDescriptors(client, allCacheNames); - - checkAllCaches(); - } - - public void testActiveClientReconnectToInActiveCluster() throws Exception { - CountDownLatch activateLatch = new CountDownLatch(1); - - startNodes(activateLatch); - - info(">>>> star grid"); - - IgniteEx ig1 = grid(node1); - IgniteEx ig2 = grid(node2); - IgniteEx client = grid(nodeClient); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - info(">>>> activate grid"); - - client.active(true); - - checkStaticCaches(); - - checkDescriptors(ig1, staticCacheNames); - checkDescriptors(ig2, staticCacheNames); - checkDescriptors(client, staticCacheNames); - - info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); - - client.createCache(ccfgDynamic); - - client.createCache(ccfgDynamicWithFilter); - - checkDescriptors(ig1, allCacheNames); - checkDescriptors(ig2, allCacheNames); - checkDescriptors(client, allCacheNames); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - final CountDownLatch disconnectedLatch = new CountDownLatch(1); - final CountDownLatch reconnectedLatch = new CountDownLatch(1); - - addDisconnectListener(disconnectedLatch, reconnectedLatch); - - info(">>>> stop " + node2); - - stopGrid(node2); - - disconnectedLatch.await(); - - ig1.active(false); - - activateLatch.countDown(); - - info(">>>> restart " + node2); - - ig2 = startGrid(getConfiguration(node2)); - - reconnectedLatch.await(); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - client.active(true); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - checkDescriptors(ig1, allCacheNames); - checkDescriptors(ig2, allCacheNames); - checkDescriptors(client, allCacheNames); - - checkAllCaches(); - } - - public void testInActiveClientReconnectToActiveCluster() throws Exception { - CountDownLatch activateLatch = new CountDownLatch(1); - - startNodes(activateLatch); - - IgniteEx ig1 = grid(node1); - IgniteEx ig2 = grid(node2); - IgniteEx client = grid(nodeClient); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - final CountDownLatch disconnectedLatch = new CountDownLatch(1); - final CountDownLatch reconnectedLatch = new CountDownLatch(1); - - addDisconnectListener(disconnectedLatch, reconnectedLatch); - - stopGrid(node2); - - disconnectedLatch.await(); - - ig2 = startGrid(getConfiguration(node2)); - - ig1.active(true); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - - checkDescriptors(ig1, staticCacheNames); - checkDescriptors(ig2, staticCacheNames); - - activateLatch.countDown(); - - reconnectedLatch.await(); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - checkDescriptors(ig1, staticCacheNames); - checkDescriptors(ig2, staticCacheNames); - - client.createCache(ccfgDynamic); - - client.createCache(ccfgDynamicWithFilter); - - checkDescriptors(ig1, allCacheNames); - checkDescriptors(ig2, allCacheNames); - checkDescriptors(client, allCacheNames); - - checkAllCaches(); - } - - public void testInActiveClientReconnectToInActiveCluster() throws Exception { - startNodes(null); - - IgniteEx ig1 = grid(node1); - IgniteEx ig2 = grid(node2); - IgniteEx client = grid(nodeClient); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - final CountDownLatch disconnectedLatch = new CountDownLatch(1); - final CountDownLatch reconnectedLatch = new CountDownLatch(1); - - addDisconnectListener(disconnectedLatch, reconnectedLatch); - - stopGrid(node2); - - disconnectedLatch.await(); - - ig2 = startGrid(getConfiguration(node2)); - - reconnectedLatch.await(); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - client.active(true); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - checkStaticCaches(); - - client.createCache(ccfgDynamic); - - client.createCache(ccfgDynamicWithFilter); - - checkDescriptors(ig1, allCacheNames); - checkDescriptors(ig2, allCacheNames); - checkDescriptors(client, allCacheNames); - - checkAllCaches(); - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java deleted file mode 100644 index 2bcc177796dd6..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java +++ /dev/null @@ -1,289 +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.persistence.standbycluster.reconnect; - -import com.google.common.collect.Sets; -import java.util.Collections; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import org.apache.ignite.internal.IgniteEx; - -/** - * - */ -public class IgniteStandByClientReconnectToNewClusterTest extends IgniteAbstractStandByClientReconnectTest { - - public void testActiveClientReconnectToActiveCluster() throws Exception { - CountDownLatch activateLatch = new CountDownLatch(1); - - startNodes(activateLatch); - - info(">>>> star grid"); - - IgniteEx ig1 = grid(node1); - IgniteEx ig2 = grid(node2); - IgniteEx client = grid(nodeClient); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - info(">>>> activate grid"); - - client.active(true); - - checkDescriptors(ig1, staticCacheNames); - checkDescriptors(ig2, staticCacheNames); - checkDescriptors(client, staticCacheNames); - - checkStaticCaches(); - - info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); - - client.createCache(ccfgDynamic); - - client.createCache(ccfgDynamicWithFilter); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - checkDescriptors(ig1, allCacheNames); - checkDescriptors(ig2, allCacheNames); - checkDescriptors(client, allCacheNames); - - final CountDownLatch disconnectedLatch = new CountDownLatch(1); - final CountDownLatch reconnectedLatch = new CountDownLatch(1); - - addDisconnectListener(disconnectedLatch, reconnectedLatch); - - info(">>>> stop servers"); - - stopGrid(node1); - stopGrid(node2); - - disconnectedLatch.await(); - - ig1 = startGrid(getConfiguration(node1)); - ig2 = startGrid(getConfiguration(node2)); - - info(">>>> activate new servers"); - - ig1.active(true); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - - activateLatch.countDown(); - - info(">>>> reconnect client"); - - reconnectedLatch.await(); - - info(">>>> client reconnected"); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - checkAllCaches(); - } - - public void testActiveClientReconnectToInActiveCluster() throws Exception { - startNodes(null); - - info(">>>> star grid"); - - IgniteEx ig1 = grid(node1); - IgniteEx ig2 = grid(node2); - IgniteEx client = grid(nodeClient); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - info(">>>> activate grid"); - - client.active(true); - - checkStaticCaches(); - - checkDescriptors(ig1, staticCacheNames); - checkDescriptors(ig2, staticCacheNames); - checkDescriptors(client, staticCacheNames); - - info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); - - client.createCache(ccfgDynamic); - - client.createCache(ccfgDynamicWithFilter); - - checkDescriptors(ig1, allCacheNames); - checkDescriptors(ig2, allCacheNames); - checkDescriptors(client, allCacheNames); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - final CountDownLatch disconnectedLatch = new CountDownLatch(1); - final CountDownLatch reconnectedLatch = new CountDownLatch(1); - - addDisconnectListener(disconnectedLatch, reconnectedLatch); - - info(">>>> stop servers"); - - stopGrid(node1); - stopGrid(node2); - - assertTrue(client.active()); - - System.out.println("Await disconnected"); - - disconnectedLatch.await(); - - ig1 = startGrid(getConfiguration("node1")); - ig2 = startGrid(getConfiguration("node2")); - - info(">>>> reconnect client"); - - reconnectedLatch.await(); - - info(">>>> client reconnected"); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - info(">>>> activate new servers"); - - client.active(true); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - checkAllCaches(); - } - - public void testInActiveClientReconnectToActiveCluster() throws Exception { - CountDownLatch activateLatch = new CountDownLatch(1); - - startNodes(activateLatch); - - IgniteEx ig1 = grid(node1); - IgniteEx ig2 = grid(node2); - IgniteEx client = grid(nodeClient); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - final CountDownLatch disconnectedLatch = new CountDownLatch(1); - final CountDownLatch reconnectedLatch = new CountDownLatch(1); - - addDisconnectListener(disconnectedLatch, reconnectedLatch); - - stopGrid(node1); - stopGrid(node2); - - disconnectedLatch.await(); - - ig1 = startGrid(getConfiguration(node1)); - ig2 = startGrid(getConfiguration(node2)); - - ig1.active(true); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - - checkDescriptors(ig1, Collections.emptySet()); - checkDescriptors(ig2, Collections.emptySet()); - - activateLatch.countDown(); - - reconnectedLatch.await(); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - checkOnlySystemCaches(); - - client.createCache(ccfgDynamic); - - client.createCache(ccfgDynamicWithFilter); - - Set exp2 = Sets.newHashSet(ccfgDynamicName, ccfgDynamicWithFilterName); - - checkDescriptors(ig1, exp2); - checkDescriptors(ig2, exp2); - checkDescriptors(client, exp2); - } - - public void testInActiveClientReconnectToInActiveCluster() throws Exception { - startNodes(null); - - IgniteEx ig1 = grid(node1); - IgniteEx ig2 = grid(node2); - IgniteEx client = grid(nodeClient); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - final CountDownLatch disconnectedLatch = new CountDownLatch(1); - final CountDownLatch reconnectedLatch = new CountDownLatch(1); - - addDisconnectListener(disconnectedLatch, reconnectedLatch); - - stopGrid(node1); - stopGrid(node2); - - assertTrue(!client.active()); - - disconnectedLatch.await(); - - ig1 = startGrid(getConfiguration(node1)); - ig2 = startGrid(getConfiguration(node2)); - - reconnectedLatch.await(); - - assertTrue(!ig1.active()); - assertTrue(!ig2.active()); - assertTrue(!client.active()); - - client.active(true); - - assertTrue(ig1.active()); - assertTrue(ig2.active()); - assertTrue(client.active()); - - checkOnlySystemCaches(); - - client.createCache(ccfgDynamic); - - client.createCache(ccfgDynamicWithFilter); - - Set exp2 = Sets.newHashSet(ccfgDynamicName, ccfgDynamicWithFilterName); - - checkDescriptors(ig1, exp2); - checkDescriptors(ig2, exp2); - checkDescriptors(client, exp2); - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java index 2245a4dc79d64..d50b8e863ab1d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbAbstractTest.java @@ -181,6 +181,10 @@ protected boolean withClientNearCache() { client = false; } + assert gridCount() > 0; + + grid(0).active(true); + awaitPartitionMapExchange(); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbDynamicCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbDynamicCacheSelfTest.java index 8655ba9aa8bf2..e7454826ca82e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbDynamicCacheSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbDynamicCacheSelfTest.java @@ -87,6 +87,8 @@ public void testCreate() throws Exception { Ignite ignite = ignite(0); + ignite.active(true); + CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME); ccfg.setName("cache1"); @@ -120,6 +122,8 @@ public void testMultipleDynamicCaches() throws Exception { Ignite ignite = ignite(0); + ignite.active(true); + CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME); ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); From 67c957805e8563f209a861d47353eb4942b1b99a Mon Sep 17 00:00:00 2001 From: devozerov Date: Tue, 13 Jun 2017 09:55:46 +0300 Subject: [PATCH 273/311] Correct NPE fix. --- .../ignite/internal/binary/BinaryCachingMetadataHandler.java | 4 +++- .../java/org/apache/ignite/internal/binary/BinaryContext.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java index 27cccaa876331..26dc4c44db5d1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java @@ -70,7 +70,9 @@ private BinaryCachingMetadataHandler() { /** {@inheritDoc} */ @Override public synchronized BinaryMetadata metadata0(int typeId) throws BinaryObjectException { - return ((BinaryTypeImpl)metas.get(typeId)).metadata(); + BinaryTypeImpl type = (BinaryTypeImpl)metas.get(typeId); + + return type != null ? type.metadata() : null; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java index 26cf2ab086693..76c5a5059cd5a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java @@ -1247,7 +1247,7 @@ public String affinityKeyFieldName(int typeId) { String res = affKeyFieldNames.get(typeId); if (res == null) { - BinaryType meta = metaHnd.metadata(typeId); + BinaryMetadata meta = metaHnd.metadata0(typeId); if (meta != null) res = meta.affinityKeyFieldName(); From 18be14a6f9a9a4fac35a406e5c51fc9acee6dff7 Mon Sep 17 00:00:00 2001 From: devozerov Date: Tue, 13 Jun 2017 10:20:00 +0300 Subject: [PATCH 274/311] Fixing tests. --- ...faultBinaryMappersBinaryMetaDataSelfTest.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridDefaultBinaryMappersBinaryMetaDataSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridDefaultBinaryMappersBinaryMetaDataSelfTest.java index 0e3f79973b473..06fb3f4c00757 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridDefaultBinaryMappersBinaryMetaDataSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridDefaultBinaryMappersBinaryMetaDataSelfTest.java @@ -150,22 +150,6 @@ else if (expectedTypeName(TestObject2.class.getName()).equals(meta.typeName())) else assert false : meta.typeName(); } - - grid().cache(DEFAULT_CACHE_NAME).put(new AffinityKey<>(1, 1), 1); - - metas = binaries().types(); - - assertEquals(3, metas.size()); - - for (BinaryType meta : metas) { - if (AffinityKey.class.getSimpleName().equals(meta.typeName())) { - assertEquals("affKey", meta.affinityKeyFieldName()); - - return; - } - } - - fail("Failed to find metadata for AffinityKey"); } /** From 6646233163c4354e6c72a6da9682378e081da96b Mon Sep 17 00:00:00 2001 From: devozerov Date: Tue, 13 Jun 2017 10:51:09 +0300 Subject: [PATCH 275/311] Fixed 150 clients test. --- .../cache/distributed/IgniteCache150ClientsTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCache150ClientsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCache150ClientsTest.java index 3864fc562926c..181ddce849842 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCache150ClientsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCache150ClientsTest.java @@ -26,6 +26,7 @@ import org.apache.ignite.IgniteCache; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.SqlConnectorConfiguration; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.util.typedef.G; import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; @@ -71,6 +72,8 @@ public class IgniteCache150ClientsTest extends GridCommonAbstractTest { cfg.setClientFailureDetectionTimeout(200000); cfg.setClientMode(!igniteInstanceName.equals(getTestIgniteInstanceName(0))); + cfg.setSqlConnectorConfiguration(new SqlConnectorConfiguration().setPortRange(1000)); + CacheConfiguration[] ccfgs = new CacheConfiguration[CACHES]; for (int i = 0 ; i < ccfgs.length; i++) { From d38dfcd5c4a49b6ec4be1cfdb4f28f7d152cd14a Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 13 Jun 2017 13:01:16 +0300 Subject: [PATCH 276/311] ignite-5267-merge remove pds dependency, restore data structures only in snapshot operation --- examples/pom.xml | 7 ------- .../internal/processors/cache/GridCacheProcessor.java | 2 +- modules/yardstick/pom.xml | 6 ------ 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/examples/pom.xml b/examples/pom.xml index f749d7cb7a170..58da3421bb784 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -67,13 +67,6 @@ ${project.version} - - org.apache.ignite - ignite-pds - ${project.version} - - - com.google.code.simple-spring-memcached spymemcached 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 55b49982d769d..7404d3670a824 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 @@ -2023,7 +2023,7 @@ public void onExchangeDone( } } - if (exchActions != null && exchActions.systemCachesStarting()) + if (exchActions != null && exchActions.systemCachesStarting() && exchActions.newClusterState() == null) ctx.dataStructures().restoreStructuresState(ctx); if (exchActions != null && (err == null || forceClose)) { diff --git a/modules/yardstick/pom.xml b/modules/yardstick/pom.xml index 6e8bf9b65a067..f496e02344a0e 100644 --- a/modules/yardstick/pom.xml +++ b/modules/yardstick/pom.xml @@ -60,12 +60,6 @@ ${project.version} - - org.apache.ignite - ignite-pds - ${project.version} - - org.apache.ignite ignite-log4j From cf886fd5816534b46a1247d3bdc41061087608e4 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 13 Jun 2017 13:22:30 +0300 Subject: [PATCH 277/311] ignite-2.1.1 fix java doc --- .../src/main/java/org/apache/ignite/PersistenceMetrics.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java b/modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java index 3f00b019a3685..067da1a6086ca 100644 --- a/modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java +++ b/modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java @@ -17,9 +17,12 @@ package org.apache.ignite; import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; /** + * Persistence metrics used to obtain statistics on persistence. * + * Use {@link IgniteCacheDatabaseSharedManager#persistentStoreMetrics()} to obtain persistent metrics. */ public interface PersistenceMetrics { /** From d2dcc1d032c7f9692ddfe50fa8a80e375e8d4c9b Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 13 Jun 2017 13:45:11 +0300 Subject: [PATCH 278/311] ignite-2.1.1 fix import --- .../src/main/java/org/apache/ignite/PersistenceMetrics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java b/modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java index 067da1a6086ca..f3f763c22e51b 100644 --- a/modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java +++ b/modules/core/src/main/java/org/apache/ignite/PersistenceMetrics.java @@ -17,7 +17,7 @@ package org.apache.ignite; import org.apache.ignite.configuration.PersistentStoreConfiguration; -import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager; /** * Persistence metrics used to obtain statistics on persistence. From b65ca6854828c0f2368edab202ba00f31365a3e3 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Tue, 13 Jun 2017 13:50:31 +0300 Subject: [PATCH 279/311] ignite-2.1.1 fixing pds tests --- modules/core/pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/core/pom.xml b/modules/core/pom.xml index 17e850d0a7fe8..4710059fe20af 100644 --- a/modules/core/pom.xml +++ b/modules/core/pom.xml @@ -225,6 +225,13 @@ ${javassist.version} test + + + org.apache.ignite + ignite-indexing + ${project.version} + test + From 6ae00bc4ca43ead20ef7aaf3f3b447a89e86b307 Mon Sep 17 00:00:00 2001 From: devozerov Date: Tue, 13 Jun 2017 14:18:13 +0300 Subject: [PATCH 280/311] Fixed affintiy key calculation for QueryEntity. --- .../configuration/CacheConfiguration.java | 51 +++++++++++++++++++ .../ignite/internal/binary/BinaryContext.java | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java index 9c9361fd29ca4..670046f508436 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java @@ -66,6 +66,7 @@ import org.apache.ignite.cache.store.CacheStore; import org.apache.ignite.cache.store.CacheStoreSessionListener; import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.binary.BinaryContext; import org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor; import org.apache.ignite.internal.processors.query.QueryUtils; import org.apache.ignite.internal.util.tostring.GridToStringExclude; @@ -1783,6 +1784,37 @@ public CacheConfiguration setIndexedTypes(Class... indexedTypes) { if (!dup) qryEntities.add(converted); + + // Set key configuration if needed. + String affFieldName = desc.affinityFieldName(); + + if (affFieldName != null) { + CacheKeyConfiguration newKeyCfg = new CacheKeyConfiguration(converted.getKeyType(), affFieldName); + + if (F.isEmpty(keyCfg)) + keyCfg = new CacheKeyConfiguration[] { newKeyCfg }; + else { + boolean keyCfgDup = false; + + for (CacheKeyConfiguration oldKeyCfg : keyCfg) { + if (F.eq(oldKeyCfg.getTypeName(), newKeyCfg.getTypeName())) { + keyCfgDup = true; + + break; + } + } + + if (!keyCfgDup) { + CacheKeyConfiguration[] keyCfg0 = new CacheKeyConfiguration[keyCfg.length + 1]; + + System.arraycopy(keyCfg, 0, keyCfg0, 0, keyCfg.length); + + keyCfg0[keyCfg0.length - 1] = newKeyCfg; + + keyCfg = keyCfg0; + } + } + } } return this; @@ -2110,6 +2142,8 @@ static TypeDescriptor processKeyAndValueClasses( d.keyClass(keyCls); d.valueClass(valCls); + d.affinityFieldName(BinaryContext.affinityFieldName(keyCls)); + processAnnotationsInClass(true, d.keyCls, d, null); processAnnotationsInClass(false, d.valCls, d, null); @@ -2374,6 +2408,9 @@ private static class TypeDescriptor { /** */ private boolean valTextIdx; + /** Affinity field name. */ + private String affFieldName; + /** * @return Indexes. */ @@ -2474,6 +2511,20 @@ void keyClass(Class keyCls) { this.keyCls = keyCls; } + /** + * @return Affinity field name. + */ + @Nullable public String affinityFieldName() { + return affFieldName; + } + + /** + * @param affFieldName Affinity field name. + */ + private void affinityFieldName(@Nullable String affFieldName) { + this.affFieldName = affFieldName; + } + /** * Adds property to the type descriptor. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java index 76c5a5059cd5a..fa051f56913c7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java @@ -1026,7 +1026,7 @@ public String userTypeName(String clsName) { * @param cls Class to get affinity field for. * @return Affinity field name or {@code null} if field name was not found. */ - private String affinityFieldName(Class cls) { + public static String affinityFieldName(Class cls) { for (; cls != Object.class && cls != null; cls = cls.getSuperclass()) { for (Field f : cls.getDeclaredFields()) { if (f.getAnnotation(AffinityKeyMapped.class) != null) From be909d083655a50bc375e15155c0dd062d3e20c2 Mon Sep 17 00:00:00 2001 From: devozerov Date: Tue, 13 Jun 2017 14:34:03 +0300 Subject: [PATCH 281/311] Minors. --- .../processors/query/h2/DmlStatementsProcessor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java index 40ff38b8c671a..98d123f4f9dec 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java @@ -633,7 +633,7 @@ private UpdateResult doUpdate(UpdatePlan plan, Iterable> cursor, int pag if (bin && hasProps) { assert newVal instanceof BinaryObjectBuilder; - newVal = ((BinaryObjectBuilder)newVal).build(); + newVal = ((BinaryObjectBuilder) newVal).build(); } Object srcVal = e.get(1); @@ -1005,10 +1005,10 @@ private static PageProcessingResult processPage(GridCacheContext cctx, if (cctx.binaryMarshaller()) { if (key instanceof BinaryObjectBuilder) - key = ((BinaryObjectBuilder)key).build(); + key = ((BinaryObjectBuilder) key).build(); if (val instanceof BinaryObjectBuilder) - val = ((BinaryObjectBuilder)val).build(); + val = ((BinaryObjectBuilder) val).build(); } return new IgniteBiTuple<>(key, val); From 1181b478d7810d4485da43204c9f64757be6a8e4 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Tue, 13 Jun 2017 14:51:25 +0300 Subject: [PATCH 282/311] ignite-2.1.1 fixing pds tests --- modules/core/pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/core/pom.xml b/modules/core/pom.xml index 4710059fe20af..17e850d0a7fe8 100644 --- a/modules/core/pom.xml +++ b/modules/core/pom.xml @@ -225,13 +225,6 @@ ${javassist.version} test - - - org.apache.ignite - ignite-indexing - ${project.version} - test - From 68739b7cffae5b4bb3714dfe12bcf93327f136b8 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Tue, 13 Jun 2017 19:27:32 +0700 Subject: [PATCH 283/311] IGNITE-5267 Snapshots support. --- .../org/apache/ignite/internal/IgniteEx.java | 2 +- .../pagemem/snapshot/SnapshotOperation.java | 31 +++- .../snapshot/SnapshotOperationType.java | 19 ++- ...tartSnapshotOperationDiscoveryMessage.java | 2 +- .../processors/cache/GridCacheProcessor.java | 19 ++- .../processors/cache/GridCacheUtils.java | 3 +- .../visor/VisorDataTransferObject.java | 14 ++ .../visor/compute/VisorGatewayTask.java | 13 +- .../resources/META-INF/classnames.properties | 155 +++++++++--------- .../agent/handlers/ClusterListener.java | 31 +++- 10 files changed, 176 insertions(+), 113 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java index 775f49341d133..0a449879193dd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java @@ -160,4 +160,4 @@ public IgniteBiTuple, Boolean> getOrCreateCache0(CacheC * @return Kernal context. */ public GridKernalContext context(); -} \ No newline at end of file +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java index 2ec4db094a017..5dbb24b36d02e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperation.java @@ -32,9 +32,7 @@ public class SnapshotOperation implements Serializable { /** */ private final SnapshotOperationType type; - /** - * Snapshot ID (the timestamp of snapshot creation). - */ + /** Snapshot ID (the timestamp of snapshot creation). */ private final long snapshotId; /** Cache group ids. */ @@ -49,6 +47,9 @@ public class SnapshotOperation implements Serializable { /** Additional parameter. */ private final Object extraParam; + /** Optional list of dependent snapshot IDs. */ + private final Set dependentSnapshotIds; + /** * @param type Type. * @param snapshotId Snapshot id. @@ -56,6 +57,7 @@ public class SnapshotOperation implements Serializable { * @param cacheNames Cache names. * @param msg Extra user message. * @param extraParam Additional parameter. + * @param dependentSnapshotIds Optional list of dependent snapshot IDs. */ public SnapshotOperation( SnapshotOperationType type, @@ -63,7 +65,8 @@ public SnapshotOperation( Set cacheGrpIds, Set cacheNames, String msg, - Object extraParam + Object extraParam, + Set dependentSnapshotIds ) { this.type = type; this.snapshotId = snapshotId; @@ -71,6 +74,7 @@ public SnapshotOperation( this.cacheNames = cacheNames; this.msg = msg; this.extraParam = extraParam; + this.dependentSnapshotIds = dependentSnapshotIds; } /** @@ -119,6 +123,12 @@ public Object extraParameter() { return extraParam; } + /** + * @return Optional dependent snapshot IDs. + */ + public Set dependentSnapshotIds() { + return dependentSnapshotIds; + } /** * @param op Op. @@ -154,6 +164,7 @@ public static File getMovingPathParameter(SnapshotOperation op) { @Override public boolean equals(Object o) { if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; @@ -161,20 +172,25 @@ public static File getMovingPathParameter(SnapshotOperation op) { if (snapshotId != operation.snapshotId) return false; + if (type != operation.type) return false; - if (msg != null ? !msg.equals(operation.msg) : operation.msg != null) + + if (cacheGrpIds != null ? !cacheGrpIds.equals(operation.cacheGrpIds) : operation.cacheGrpIds != null) + return false; + + if (cacheNames != null ? !cacheNames.equals(operation.cacheNames) : operation.cacheNames != null) return false; return extraParam != null ? extraParam.equals(operation.extraParam) : operation.extraParam == null; - } /** {@inheritDoc} */ @Override public int hashCode() { int res = type.hashCode(); res = 31 * res + (int)(snapshotId ^ (snapshotId >>> 32)); - res = 31 * res + (msg != null ? msg.hashCode() : 0); + res = 31 * res + (cacheGrpIds != null ? cacheGrpIds.hashCode() : 0); + res = 31 * res + (cacheNames != null ? cacheNames.hashCode() : 0); res = 31 * res + (extraParam != null ? extraParam.hashCode() : 0); return res; } @@ -188,6 +204,7 @@ public static File getMovingPathParameter(SnapshotOperation op) { ", cacheGroupIds=" + cacheGrpIds + ", msg='" + msg + '\'' + ", extraParam=" + extraParam + + ", dependentSnapshotIds=" + dependentSnapshotIds + '}'; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java index c3b3a2ff738c2..cc1aeea037bf8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/SnapshotOperationType.java @@ -17,6 +17,8 @@ */ package org.apache.ignite.internal.pagemem.snapshot; +import org.jetbrains.annotations.Nullable; + /** */ public enum SnapshotOperationType { /** Create. */ @@ -30,5 +32,18 @@ public enum SnapshotOperationType { /** Delete. */ DELETE, /** Check. */ - CHECK -} \ No newline at end of file + CHECK; + + /** Enumerated values. */ + private static final SnapshotOperationType[] VALS = values(); + + /** + * Efficiently gets enumerated value from its ordinal. + * + * @param ord Ordinal value. + * @return Enumerated value or {@code null} if ordinal out of range. + */ + @Nullable public static SnapshotOperationType fromOrdinal(int ord) { + return ord >= 0 && ord < VALS.length ? VALS[ord] : null; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java index 18bca36b183ad..4c9deb593ddfe 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/snapshot/StartSnapshotOperationDiscoveryMessage.java @@ -116,7 +116,7 @@ public UUID initiatorNodeId() { } /** - * + * @return Operation ID. */ public IgniteUuid operationId() { return operationId; 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 7404d3670a824..f15573e174757 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 @@ -701,8 +701,9 @@ private void addCacheOnJoin(StoredCacheData cacheData, Map caches, Map templates) throws IgniteCheckedException { CacheConfiguration cfg = cacheData.config(); + String cacheName = cfg.getName(); - CU.validateCacheName(cfg.getName()); + CU.validateCacheName(cacheName); cloneCheckSerializable(cfg); @@ -711,28 +712,28 @@ private void addCacheOnJoin(StoredCacheData cacheData, // Initialize defaults. initialize(cfg, cacheObjCtx); - boolean template = cfg.getName().endsWith("*"); + boolean template = cacheName.endsWith("*"); if (!template) { - if (caches.containsKey(cfg.getName())) { + if (caches.containsKey(cacheName)) { throw new IgniteCheckedException("Duplicate cache name found (check configuration and " + - "assign unique name to each cache): " + cfg.getName()); + "assign unique name to each cache): " + cacheName); } - CacheType cacheType = cacheType(cfg.getName()); + CacheType cacheType = cacheType(cacheName); if (cacheType != CacheType.USER && cfg.getMemoryPolicyName() == null) cfg.setMemoryPolicyName(sharedCtx.database().systemMemoryPolicyName()); if (!cacheType.userCache()) - stopSeq.addLast(cfg.getName()); + stopSeq.addLast(cacheName); else - stopSeq.addFirst(cfg.getName()); + stopSeq.addFirst(cacheName); - caches.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cacheData, cacheType, cacheData.sql(), 0)); + caches.put(cacheName, new CacheJoinNodeDiscoveryData.CacheInfo(cacheData, cacheType, cacheData.sql(), 0)); } else - templates.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cacheData, CacheType.USER, false, 0)); + templates.put(cacheName, new CacheJoinNodeDiscoveryData.CacheInfo(cacheData, CacheType.USER, false, 0)); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java index 7123c0be2f8a0..ddfd68ee11593 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java @@ -1104,8 +1104,7 @@ public static boolean isAtomicsCache(String cacheName) { * @return {@code True} if system cache. */ public static boolean isSystemCache(String cacheName) { - return isUtilityCache(cacheName) || isHadoopSystemCache(cacheName) || - isAtomicsCache(cacheName); + return isUtilityCache(cacheName) || isHadoopSystemCache(cacheName) || isAtomicsCache(cacheName); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java index bdf01e72406a3..c56266271207f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java @@ -23,7 +23,9 @@ import java.io.ObjectOutput; import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import org.jetbrains.annotations.Nullable; /** @@ -45,6 +47,18 @@ public abstract class VisorDataTransferObject implements Externalizable { return null; } + /** + * @param col Source collection. + * @param Collection type. + * @return List based on passed collection. + */ + @Nullable protected static Set toSet(Collection col) { + if (col != null) + return new LinkedHashSet<>(col); + + return null; + } + /** * @return Transfer object version. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorGatewayTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorGatewayTask.java index f1fb79b811f44..48c3abbae5ab6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorGatewayTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorGatewayTask.java @@ -160,16 +160,17 @@ private static class VisorGatewayJob extends ComputeJobAdapter { boolean isList = cls == Collection.class || cls == List.class; if (isList || cls == Set.class) { + String items = argument(startIdx + 1); + + if (items == null || "null".equals(items)) + return null; + Class itemsCls = Class.forName(arg); Collection res = isList ? new ArrayList<>() : new HashSet<>(); - String items = argument(startIdx + 1); - - if (items != null) { - for (String item : items.split(";")) - res.add(toObject(itemsCls, item)); - } + for (String item : items.split(";")) + res.add(toObject(itemsCls, item)); return res; } diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index 36b087e2f0549..ba2c649b5d30a 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -139,8 +139,10 @@ org.apache.ignite.configuration.IgniteReflectionFactory org.apache.ignite.configuration.MemoryConfiguration org.apache.ignite.configuration.MemoryPolicyConfiguration org.apache.ignite.configuration.NearCacheConfiguration +org.apache.ignite.configuration.PersistentStoreConfiguration org.apache.ignite.configuration.TopologyValidator org.apache.ignite.configuration.TransactionConfiguration +org.apache.ignite.configuration.WALMode org.apache.ignite.events.CacheEvent org.apache.ignite.events.CacheQueryExecutedEvent org.apache.ignite.events.CacheQueryReadEvent @@ -215,6 +217,11 @@ org.apache.ignite.internal.IgniteClientDisconnectedCheckedException org.apache.ignite.internal.IgniteComponentType org.apache.ignite.internal.IgniteComputeImpl org.apache.ignite.internal.IgniteDeploymentCheckedException +org.apache.ignite.internal.IgniteDiagnosticMessage +org.apache.ignite.internal.IgniteDiagnosticMessage$BaseClosure +org.apache.ignite.internal.IgniteDiagnosticMessage$ExchangeInfoClosure +org.apache.ignite.internal.IgniteDiagnosticMessage$TxEntriesInfoClosure +org.apache.ignite.internal.IgniteDiagnosticMessage$TxInfoClosure org.apache.ignite.internal.IgniteEventsImpl org.apache.ignite.internal.IgniteEventsImpl$1 org.apache.ignite.internal.IgniteFutureCancelledCheckedException @@ -333,7 +340,6 @@ org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationAckDiscoveryMe org.apache.ignite.internal.pagemem.snapshot.StartSnapshotOperationDiscoveryMessage org.apache.ignite.internal.pagemem.wal.StorageException org.apache.ignite.internal.pagemem.wal.WALIterator -org.apache.ignite.internal.pagemem.wal.record.StoreOperationRecord$StoreOperationType org.apache.ignite.internal.pagemem.wal.record.TxRecord$TxAction org.apache.ignite.internal.pagemem.wal.record.WALRecord$RecordType org.apache.ignite.internal.pagemem.wal.record.delta.DeltaApplicationException @@ -359,6 +365,10 @@ org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$7 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$8 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$9 org.apache.ignite.internal.processors.cache.CacheAtomicUpdateTimeoutCheckedException +org.apache.ignite.internal.processors.cache.CacheClientReconnectDiscoveryData +org.apache.ignite.internal.processors.cache.CacheClientReconnectDiscoveryData$CacheGroupInfo +org.apache.ignite.internal.processors.cache.CacheClientReconnectDiscoveryData$CacheInfo +org.apache.ignite.internal.processors.cache.CacheData org.apache.ignite.internal.processors.cache.CacheDefaultBinaryAffinityKeyMapper org.apache.ignite.internal.processors.cache.CacheEntryImpl org.apache.ignite.internal.processors.cache.CacheEntryImplEx @@ -370,11 +380,17 @@ org.apache.ignite.internal.processors.cache.CacheEntryPredicateHasValue org.apache.ignite.internal.processors.cache.CacheEntryPredicateNoValue org.apache.ignite.internal.processors.cache.CacheEntrySerializablePredicate org.apache.ignite.internal.processors.cache.CacheEvictionEntry +org.apache.ignite.internal.processors.cache.CacheGroupContext$2 +org.apache.ignite.internal.processors.cache.CacheGroupContext$3 +org.apache.ignite.internal.processors.cache.CacheGroupData org.apache.ignite.internal.processors.cache.CacheInvalidStateException org.apache.ignite.internal.processors.cache.CacheInvokeDirectResult org.apache.ignite.internal.processors.cache.CacheInvokeEntry$Operation org.apache.ignite.internal.processors.cache.CacheInvokeResult +org.apache.ignite.internal.processors.cache.CacheJoinNodeDiscoveryData +org.apache.ignite.internal.processors.cache.CacheJoinNodeDiscoveryData$CacheInfo org.apache.ignite.internal.processors.cache.CacheMetricsSnapshot +org.apache.ignite.internal.processors.cache.CacheNodeCommonDiscoveryData org.apache.ignite.internal.processors.cache.CacheObject org.apache.ignite.internal.processors.cache.CacheObjectAdapter org.apache.ignite.internal.processors.cache.CacheObjectByteArrayImpl @@ -389,6 +405,7 @@ org.apache.ignite.internal.processors.cache.CacheWeakQueryIteratorsHolder$WeakQu org.apache.ignite.internal.processors.cache.CacheWeakQueryIteratorsHolder$WeakQueryFutureIterator org.apache.ignite.internal.processors.cache.CacheWeakQueryIteratorsHolder$WeakReferenceCloseableIterator org.apache.ignite.internal.processors.cache.ChangeGlobalStateMessage +org.apache.ignite.internal.processors.cache.ClusterCachesInfo$1$1 org.apache.ignite.internal.processors.cache.ClusterState org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest @@ -399,28 +416,28 @@ org.apache.ignite.internal.processors.cache.GridCacheAdapter$11 org.apache.ignite.internal.processors.cache.GridCacheAdapter$12 org.apache.ignite.internal.processors.cache.GridCacheAdapter$13 org.apache.ignite.internal.processors.cache.GridCacheAdapter$14 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$15 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$16$1 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$15$1 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$16 org.apache.ignite.internal.processors.cache.GridCacheAdapter$17 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$18 org.apache.ignite.internal.processors.cache.GridCacheAdapter$2 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$26$1 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$28 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$29$1 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$25$1 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$27 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$28$1 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$29 org.apache.ignite.internal.processors.cache.GridCacheAdapter$3 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$30 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$32 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$31 org.apache.ignite.internal.processors.cache.GridCacheAdapter$4 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$47 org.apache.ignite.internal.processors.cache.GridCacheAdapter$48 org.apache.ignite.internal.processors.cache.GridCacheAdapter$49 org.apache.ignite.internal.processors.cache.GridCacheAdapter$50 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$51 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$52 org.apache.ignite.internal.processors.cache.GridCacheAdapter$53 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$53$1 org.apache.ignite.internal.processors.cache.GridCacheAdapter$54 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$54$1 org.apache.ignite.internal.processors.cache.GridCacheAdapter$55 -org.apache.ignite.internal.processors.cache.GridCacheAdapter$56 org.apache.ignite.internal.processors.cache.GridCacheAdapter$6 +org.apache.ignite.internal.processors.cache.GridCacheAdapter$8 org.apache.ignite.internal.processors.cache.GridCacheAdapter$9 org.apache.ignite.internal.processors.cache.GridCacheAdapter$AsyncOp$1 org.apache.ignite.internal.processors.cache.GridCacheAdapter$AsyncOp$1$1 @@ -450,9 +467,7 @@ org.apache.ignite.internal.processors.cache.GridCacheAdapter$UpdateRemoveTimeSta org.apache.ignite.internal.processors.cache.GridCacheAdapter$UpdateTimeStatClosure org.apache.ignite.internal.processors.cache.GridCacheAttributes org.apache.ignite.internal.processors.cache.GridCacheConcurrentMapImpl$1 -org.apache.ignite.internal.processors.cache.GridCacheConcurrentMapImpl$3 -org.apache.ignite.internal.processors.cache.GridCacheConcurrentMapImpl$4 -org.apache.ignite.internal.processors.cache.GridCacheConcurrentMapImpl$5 +org.apache.ignite.internal.processors.cache.GridCacheConcurrentMapImpl$2 org.apache.ignite.internal.processors.cache.GridCacheContext org.apache.ignite.internal.processors.cache.GridCacheContext$4 org.apache.ignite.internal.processors.cache.GridCacheContext$5 @@ -466,6 +481,8 @@ org.apache.ignite.internal.processors.cache.GridCacheExplicitLockSpan org.apache.ignite.internal.processors.cache.GridCacheExplicitLockSpan$1 org.apache.ignite.internal.processors.cache.GridCacheFilterFailedException org.apache.ignite.internal.processors.cache.GridCacheGateway$State +org.apache.ignite.internal.processors.cache.GridCacheGroupIdMessage +org.apache.ignite.internal.processors.cache.GridCacheIdMessage org.apache.ignite.internal.processors.cache.GridCacheIndexUpdateException org.apache.ignite.internal.processors.cache.GridCacheIoManager$1$1 org.apache.ignite.internal.processors.cache.GridCacheIoManager$1$2 @@ -484,21 +501,19 @@ org.apache.ignite.internal.processors.cache.GridCacheMvccManager$6 org.apache.ignite.internal.processors.cache.GridCacheMvccManager$7 org.apache.ignite.internal.processors.cache.GridCacheMvccManager$FinishLockFuture$1 org.apache.ignite.internal.processors.cache.GridCacheOperation -org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$1$1 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$2 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$3 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$4 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$5 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$6 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$7 -org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$8 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeFutureSet org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$MessageHandler -org.apache.ignite.internal.processors.cache.GridCacheProcessor$2 +org.apache.ignite.internal.processors.cache.GridCacheProcessor$1 +org.apache.ignite.internal.processors.cache.GridCacheProcessor$10 org.apache.ignite.internal.processors.cache.GridCacheProcessor$3 org.apache.ignite.internal.processors.cache.GridCacheProcessor$4 org.apache.ignite.internal.processors.cache.GridCacheProcessor$5 -org.apache.ignite.internal.processors.cache.GridCacheProcessor$7 org.apache.ignite.internal.processors.cache.GridCacheProcessor$8 org.apache.ignite.internal.processors.cache.GridCacheProcessor$9 org.apache.ignite.internal.processors.cache.GridCacheProcessor$LocalAffinityFunction @@ -521,9 +536,6 @@ org.apache.ignite.internal.processors.cache.GridCacheUtils$18 org.apache.ignite.internal.processors.cache.GridCacheUtils$19 org.apache.ignite.internal.processors.cache.GridCacheUtils$2 org.apache.ignite.internal.processors.cache.GridCacheUtils$20 -org.apache.ignite.internal.processors.cache.GridCacheUtils$21 -org.apache.ignite.internal.processors.cache.GridCacheUtils$22 -org.apache.ignite.internal.processors.cache.GridCacheUtils$24 org.apache.ignite.internal.processors.cache.GridCacheUtils$3 org.apache.ignite.internal.processors.cache.GridCacheUtils$4 org.apache.ignite.internal.processors.cache.GridCacheUtils$5 @@ -541,7 +553,6 @@ org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$3 org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$4 org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$5 org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$6 -org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$7 org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$8 org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$CacheDataStoreImpl$1 org.apache.ignite.internal.processors.cache.IgniteCacheProxy @@ -558,6 +569,7 @@ org.apache.ignite.internal.processors.cache.IgniteRebalanceIterator org.apache.ignite.internal.processors.cache.KeyCacheObject org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl org.apache.ignite.internal.processors.cache.QueryCursorImpl$State +org.apache.ignite.internal.processors.cache.StoredCacheData org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityProxy org.apache.ignite.internal.processors.cache.binary.BinaryMetadataHolder org.apache.ignite.internal.processors.cache.binary.BinaryMetadataKey @@ -570,11 +582,6 @@ org.apache.ignite.internal.processors.cache.binary.MetadataUpdateAcceptedMessage org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage$ProposalStatus org.apache.ignite.internal.processors.cache.binary.MetadataUpdateResult$ResultType -org.apache.ignite.internal.processors.cache.database.CacheDataRowAdapter$RowData -org.apache.ignite.internal.processors.cache.database.tree.BPlusTree$Bool -org.apache.ignite.internal.processors.cache.database.tree.BPlusTree$DestroyBag -org.apache.ignite.internal.processors.cache.database.tree.BPlusTree$Result -org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO$EntryPart org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager$BlockSetCallable org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager$QueueHeaderPredicate org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager$RemoveSetDataCallable @@ -605,11 +612,12 @@ org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssig org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentResponse org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCache org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter -org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter$1 +org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter$2 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter$3 -org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter$5 +org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter$4 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter$6 -org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter$PartitionEntryIterator +org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter$7 +org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter$MessageHandler org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry$1 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry$2 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtGetFuture$1 @@ -630,6 +638,8 @@ org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactional org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$1 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$10 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$11 +org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$12 +org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$13 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$2 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$3 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$4 @@ -679,6 +689,7 @@ org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomic org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$17 org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$18 org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$19 +org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$2 org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$20 org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$21 org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$22 @@ -693,6 +704,7 @@ org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomic org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$30 org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$31 org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$32 +org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$33 org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$4 org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$5 org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$6 @@ -723,13 +735,13 @@ org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomi org.apache.ignite.internal.processors.cache.distributed.dht.atomic.NearCacheUpdates org.apache.ignite.internal.processors.cache.distributed.dht.atomic.UpdateErrors org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache +org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache$1 org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache$2 org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache$3 -org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache$4 -org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache$5$1 +org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache$4$1 +org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache$6 org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache$7 org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache$8 -org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache$9 org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedLockFuture$1 org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedLockFuture$2 org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedLockFuture$3 @@ -762,14 +774,8 @@ org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPar org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleRequest +org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$1 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$2 -org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$3 -org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$4 -org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$5 -org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$6 -org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$7 -org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$8 -org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader$MessageHandler org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloaderAssignments org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionCountersMap org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionHistorySuppliersMap @@ -807,6 +813,7 @@ org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticT org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticTxPrepareFuture$2 org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticTxPrepareFuture$3 org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticTxPrepareFuture$4 +org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticTxPrepareFuture$5 org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticTxPrepareFuture$MiniFuture$1 org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticTxPrepareFutureAdapter$1 org.apache.ignite.internal.processors.cache.distributed.near.GridNearPessimisticTxPrepareFuture$1 @@ -858,6 +865,20 @@ org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$4 org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$5 org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$8 org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$9 +org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter$RowData +org.apache.ignite.internal.processors.cache.persistence.FullPageIdIterableComparator +org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager$8 +org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager$CheckpointEntryType +org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager$RebalanceIteratorAdapter +org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl$Segment +org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree$Bool +org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree$DestroyBag +org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree$Result +org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO$EntryPart +org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager$FileArchiver$1 +org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager$RecordsIterator +org.apache.ignite.internal.processors.cache.persistence.wal.SegmentEofException +org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException org.apache.ignite.internal.processors.cache.query.CacheQueryType org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryFuture$1 org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryFuture$3 @@ -903,12 +924,12 @@ org.apache.ignite.internal.processors.cache.query.GridCacheSqlIndexMetadata org.apache.ignite.internal.processors.cache.query.GridCacheSqlMetadata org.apache.ignite.internal.processors.cache.query.GridCacheSqlQuery org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryBatchAck +org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryDeployableObject org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryEntry org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryEvent org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandler org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandler$1$1 org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandler$ContinuousQueryAsyncClosure$1 -org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandler$DeployableObject org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandlerV2 org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager$1 org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager$2 @@ -1008,8 +1029,11 @@ org.apache.ignite.internal.processors.closure.GridClosureProcessor$T8 org.apache.ignite.internal.processors.closure.GridClosureProcessor$T9 org.apache.ignite.internal.processors.closure.GridClosureProcessor$TaskNoReduceAdapter org.apache.ignite.internal.processors.closure.GridPeerDeployAwareTaskAdapter +org.apache.ignite.internal.processors.cluster.ClusterProcessor$3 +org.apache.ignite.internal.processors.cluster.ClusterProcessor$4 +org.apache.ignite.internal.processors.cluster.ClusterProcessor$4$1 org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$1$1 -org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$2 +org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$3 org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$4 org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$6 org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$ClientChangeGlobalStateComputeRequest @@ -1228,7 +1252,6 @@ org.apache.ignite.internal.processors.marshaller.MappingProposedMessage$Proposal org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem org.apache.ignite.internal.processors.marshaller.MissingMappingRequestMessage org.apache.ignite.internal.processors.marshaller.MissingMappingResponseMessage -org.apache.ignite.internal.processors.odbc.OdbcProtocolVersion org.apache.ignite.internal.processors.odbc.odbc.escape.OdbcEscapeType org.apache.ignite.internal.processors.platform.PlatformAbstractConfigurationClosure org.apache.ignite.internal.processors.platform.PlatformAbstractPredicate @@ -1301,7 +1324,9 @@ org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils$FutureL org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils$InternalFutureListenable$1 org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionLockProcessor org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionSetAndUnlockProcessor +org.apache.ignite.internal.processors.query.DynamicTableAffinityKeyMapper org.apache.ignite.internal.processors.query.GridQueryFieldMetadata +org.apache.ignite.internal.processors.query.GridQueryProcessor$10 org.apache.ignite.internal.processors.query.GridQueryProcessor$4 org.apache.ignite.internal.processors.query.GridQueryProcessor$5 org.apache.ignite.internal.processors.query.GridQueryProcessor$6 @@ -1480,6 +1505,7 @@ org.apache.ignite.internal.util.GridLogThrottle$LogLevel$3 org.apache.ignite.internal.util.GridLongList org.apache.ignite.internal.util.GridMessageCollection org.apache.ignite.internal.util.GridMutex +org.apache.ignite.internal.util.GridPartitionStateMap org.apache.ignite.internal.util.GridRandom org.apache.ignite.internal.util.GridReflectionCache org.apache.ignite.internal.util.GridSerializableCollection @@ -1517,6 +1543,7 @@ org.apache.ignite.internal.util.IgniteUtils$8 org.apache.ignite.internal.util.IgniteUtils$9 org.apache.ignite.internal.util.StripedCompositeReadWriteLock$ReadLock org.apache.ignite.internal.util.UUIDCollectionMessage +org.apache.ignite.internal.util.future.AsyncFutureListener org.apache.ignite.internal.util.future.GridCompoundFuture$1 org.apache.ignite.internal.util.future.GridEmbeddedFuture$1 org.apache.ignite.internal.util.future.GridEmbeddedFuture$2 @@ -1632,6 +1659,7 @@ org.apache.ignite.internal.util.lang.gridfunc.TransformMapView2$1 org.apache.ignite.internal.util.nio.GridNioEmbeddedFuture$1 org.apache.ignite.internal.util.nio.GridNioException org.apache.ignite.internal.util.nio.GridNioMessageTracker +org.apache.ignite.internal.util.nio.GridNioServer$1 org.apache.ignite.internal.util.nio.GridNioServer$NioOperation org.apache.ignite.internal.util.nio.GridNioServer$RandomBalancer org.apache.ignite.internal.util.nio.GridNioServer$ReadWriteSizeBasedBalancer @@ -1744,7 +1772,6 @@ org.apache.ignite.internal.visor.cache.VisorCacheResetMetricsTask$VisorCacheRese org.apache.ignite.internal.visor.cache.VisorCacheResetMetricsTaskArg org.apache.ignite.internal.visor.cache.VisorCacheSqlIndexMetadata org.apache.ignite.internal.visor.cache.VisorCacheSqlMetadata -org.apache.ignite.internal.visor.cache.VisorCacheStartArg org.apache.ignite.internal.visor.cache.VisorCacheStartTask org.apache.ignite.internal.visor.cache.VisorCacheStartTask$VisorCacheStartJob org.apache.ignite.internal.visor.cache.VisorCacheStartTaskArg @@ -1777,7 +1804,6 @@ org.apache.ignite.internal.visor.event.VisorGridEventsLost org.apache.ignite.internal.visor.event.VisorGridJobEvent org.apache.ignite.internal.visor.event.VisorGridTaskEvent org.apache.ignite.internal.visor.file.VisorFileBlock -org.apache.ignite.internal.visor.file.VisorFileBlockArg org.apache.ignite.internal.visor.file.VisorFileBlockTask org.apache.ignite.internal.visor.file.VisorFileBlockTask$VisorFileBlockJob org.apache.ignite.internal.visor.file.VisorFileBlockTaskArg @@ -1807,7 +1833,6 @@ org.apache.ignite.internal.visor.igfs.VisorIgfsSamplingStateTask org.apache.ignite.internal.visor.igfs.VisorIgfsSamplingStateTask$VisorIgfsSamplingStateJob org.apache.ignite.internal.visor.igfs.VisorIgfsSamplingStateTaskArg org.apache.ignite.internal.visor.log.VisorLogFile -org.apache.ignite.internal.visor.log.VisorLogSearchArg org.apache.ignite.internal.visor.log.VisorLogSearchResult org.apache.ignite.internal.visor.log.VisorLogSearchTask org.apache.ignite.internal.visor.log.VisorLogSearchTask$VisorLogSearchJob @@ -1825,6 +1850,7 @@ org.apache.ignite.internal.visor.misc.VisorNopTask org.apache.ignite.internal.visor.misc.VisorNopTask$VisorNopJob org.apache.ignite.internal.visor.misc.VisorResolveHostNameTask org.apache.ignite.internal.visor.misc.VisorResolveHostNameTask$VisorResolveHostNameJob +org.apache.ignite.internal.visor.node.VisorAffinityTopologyVersion org.apache.ignite.internal.visor.node.VisorAtomicConfiguration org.apache.ignite.internal.visor.node.VisorBasicConfiguration org.apache.ignite.internal.visor.node.VisorBinaryConfiguration @@ -1874,7 +1900,6 @@ org.apache.ignite.internal.visor.node.VisorSpisConfiguration org.apache.ignite.internal.visor.node.VisorSqlConnectorConfiguration org.apache.ignite.internal.visor.node.VisorSuppressedError org.apache.ignite.internal.visor.node.VisorTransactionConfiguration -org.apache.ignite.internal.visor.query.VisorQueryArg org.apache.ignite.internal.visor.query.VisorQueryCancelTask org.apache.ignite.internal.visor.query.VisorQueryCancelTask$VisorCancelQueriesJob org.apache.ignite.internal.visor.query.VisorQueryCancelTaskArg @@ -1908,7 +1933,6 @@ org.apache.ignite.internal.visor.query.VisorRunningQueriesCollectorTask org.apache.ignite.internal.visor.query.VisorRunningQueriesCollectorTask$VisorCollectRunningQueriesJob org.apache.ignite.internal.visor.query.VisorRunningQueriesCollectorTaskArg org.apache.ignite.internal.visor.query.VisorRunningQuery -org.apache.ignite.internal.visor.query.VisorScanQueryArg org.apache.ignite.internal.visor.query.VisorScanQueryTask org.apache.ignite.internal.visor.query.VisorScanQueryTask$VisorScanQueryJob org.apache.ignite.internal.visor.query.VisorScanQueryTaskArg @@ -1975,12 +1999,13 @@ org.apache.ignite.spi.checkpoint.sharedfs.SharedFsCheckpointData org.apache.ignite.spi.collision.jobstealing.JobStealingRequest org.apache.ignite.spi.collision.priorityqueue.PriorityQueueCollisionSpi$PriorityGridCollisionJobContextComparator org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$1 -org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$10 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$11 +org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$12 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$2$ConnectClosure org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$2$ConnectClosure$1 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$2$ConnectClosureNew org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$2$ConnectClosureNew$1 +org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$5 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$HandshakeClosure org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$HandshakeMessage org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$HandshakeMessage2 @@ -2023,6 +2048,7 @@ org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeFailedMessage org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeLeftMessage org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryPingRequest org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryPingResponse +org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryRingLatencyCheckMessage org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryStatusCheckMessage org.apache.ignite.ssl.SslContextFactory org.apache.ignite.startup.BasicWarmupClosure @@ -2044,32 +2070,3 @@ org.apache.ignite.transactions.TransactionRollbackException org.apache.ignite.transactions.TransactionState org.apache.ignite.transactions.TransactionTimeoutException org.apache.ignite.util.AttributeNodeFilter -org.apache.ignite.internal.util.GridPartitionStateMap -org.gridgain.grid.cache.db.GridCacheOffheapManager$RebalanceIteratorAdapter -org.gridgain.grid.cache.db.wal.FileWriteAheadLogManager$FileArchiver$1 -org.gridgain.grid.cache.db.wal.FileWriteAheadLogManager$Mode -org.gridgain.grid.cache.db.wal.FileWriteAheadLogManager$RecordsIterator -org.gridgain.grid.internal.processors.cache.database.CollectDependantSnapshotSetTask -org.gridgain.grid.internal.processors.cache.database.CollectDependantSnapshotSetTask$CollectDependantSnapshotSetJob -org.gridgain.grid.internal.processors.cache.database.CollectSnapshotInfoTask -org.gridgain.grid.internal.processors.cache.database.CollectSnapshotInfoTask$CollectSnapshotInfoJob -org.gridgain.grid.internal.processors.cache.database.CollectSnapshotInfoTaskResult -org.gridgain.grid.internal.processors.cache.database.FullPageIdIterableComparator -org.gridgain.grid.internal.processors.cache.database.GetOngoingOperationTask -org.gridgain.grid.internal.processors.cache.database.GetOngoingOperationTask$GetOngoingOperationJob -org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$13 -org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$15 -org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$18 -org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$CheckpointEntryType -org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$Checkpointer$2 -org.gridgain.grid.internal.processors.cache.database.GridCacheDatabaseSharedManager$FullPageIdComparator -org.gridgain.grid.internal.processors.cache.database.SnapshotOperationFuture$1 -org.gridgain.grid.internal.processors.cache.database.SnapshotTaskBase -org.gridgain.grid.internal.processors.cache.database.messages.CheckSnapshotFinishedMessage -org.gridgain.grid.internal.processors.cache.database.messages.CheckSnapshotMetadataMessage -org.gridgain.grid.internal.processors.cache.database.messages.ClusterWideSnapshotOperationFinishedMessage -org.gridgain.grid.internal.processors.cache.database.messages.SnapshotIssueMessage -org.gridgain.grid.internal.processors.cache.database.messages.SnapshotOperationFinishedMessage -org.gridgain.grid.internal.processors.cache.database.messages.SnapshotProgressMessage -org.gridgain.grid.internal.visor.database.VisorCheckpointMetrics -org.gridgain.grid.internal.visor.database.VisorMemoryPoolMetrics diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/ClusterListener.java b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/ClusterListener.java index 0da4469dfb6ca..bf8322a180d36 100644 --- a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/ClusterListener.java +++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/ClusterListener.java @@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.socket.client.Socket; import io.socket.emitter.Emitter; -import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -190,12 +189,12 @@ public Emitter.Listener stop() { } /** */ - private class TopologySnapshot { + private static class TopologySnapshot { /** */ private Collection nids; /** */ - private String clusterVersion; + private String clusterVer; /** * @param nodes Nodes. @@ -210,7 +209,21 @@ private class TopologySnapshot { } }); - clusterVersion = Collections.min(vers).toString(); + clusterVer = Collections.min(vers).toString(); + } + + /** + * @return Cluster version. + */ + public String getClusterVersion() { + return clusterVer; + } + + /** + * @return Cluster nodes IDs. + */ + public Collection getNids() { + return nids; } /** */ @@ -256,7 +269,10 @@ private class WatchTask implements Runnable { clusterDisconnect(); } } - catch (IOException ignore) { + catch (Exception e) { + if (log.isDebugEnabled()) + log.debug("WatchTask failed", e); + clusterDisconnect(); } } @@ -296,7 +312,10 @@ private class BroadcastTask implements Runnable { clusterDisconnect(); } } - catch (IOException ignore) { + catch (Exception e) { + if (log.isDebugEnabled()) + log.debug("BroadcastTask failed", e); + clusterDisconnect(); watch(); From 4a86cae203ed9aed953cd6093884cf8cab4531e3 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 13 Jun 2017 15:48:39 +0300 Subject: [PATCH 284/311] ignite-2.1.1 fix state processor, skip if daemon --- .../processors/cluster/GridClusterStateProcessor.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java index e0751f92b1f7f..abcbe9eafcaa4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java @@ -238,8 +238,15 @@ public void cacheProcessorStarted(CacheJoinNodeDiscoveryData data) { @Override public void onKernalStart() throws IgniteCheckedException { super.onKernalStart(); + if (ctx.isDaemon()) + return; + + List nodes = ctx.discovery().serverNodes(AffinityTopologyVersion.NONE); + + assert localCacheData != null; + // First node started (coordinator). - if (ctx.discovery().serverNodes(AffinityTopologyVersion.NONE).get(0).isLocal()) + if (nodes.isEmpty() || nodes.get(0).isLocal()) cacheData.putAll(localCacheData.caches()); } From 5c567aeb5458159bc41dbd251dfa8a65701f4861 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Tue, 13 Jun 2017 16:06:42 +0300 Subject: [PATCH 285/311] ignite-2.1.1 moving pds tests that depend on indexing to separate suite --- .../ignite/testsuites/IgnitePdsTestSuite.java | 5 -- .../testsuites/IgnitePdsTestSuite2.java | 8 --- .../IgnitePdsWithIndexingCoreTestSuite.java | 54 +++++++++++++++++++ 3 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java index 59e7ae9f3ed91..123673808d971 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java @@ -58,7 +58,6 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(PageMemoryImplTest.class); // Checkpointing smoke-test. - suite.addTestSuite(IgnitePdsCacheIntegrationTest.class); suite.addTestSuite(ignitePdsCheckpointSimulationTest.class); // BTree tests with store page memory. @@ -73,15 +72,11 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(IgniteDbClientNearCachePutGetTest.class); // Persistence-enabled. - suite.addTestSuite(IgnitePdsMultiNodePutGetRestartTest.class); suite.addTestSuite(IgnitePdsSingleNodePutGetPersistenceTest.class); - suite.addTestSuite(IgnitePdsPageEvictionTest.class); suite.addTestSuite(IgnitePdsDynamicCacheTest.class); suite.addTestSuite(IgniteWalDirectoriesConfigurationTest.class); suite.addTestSuite(IgnitePdsClientNearCachePutGetTest.class); - suite.addTestSuite(IgnitePersistentStoreCacheGroupsTest.class); - return suite; } } diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java index f645dba2b14b3..351f52eb904c2 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java @@ -54,14 +54,8 @@ public static TestSuite suite() throws Exception { // Metrics test. suite.addTestSuite(IgnitePersistenceMetricsSelfTest.class); - // WAL recovery test. - suite.addTestSuite(WalRecoveryTxLogicalRecordsTest.class); - suite.addTestSuite(IgniteWalRecoveryTest.class); - suite.addTestSuite(IgnitePdsTransactionsHangTest.class); - suite.addTestSuite(IgnitePdsNoActualWalHistoryTest.class); - suite.addTestSuite(IgnitePdsRebalancingOnNotStableTopologyTest.class); suite.addTestSuite(IgnitePdsWholeClusterRestartTest.class); @@ -69,8 +63,6 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(IgnitePdsPageEvictionDuringPartitionClearTest.class); // Rebalancing test - suite.addTestSuite(IgnitePdsAtomicCacheRebalancingTest.class); - suite.addTestSuite(IgnitePdsTxCacheRebalancingTest.class); suite.addTestSuite(IgniteWalHistoryReservationsTest.class); suite.addTestSuite(IgnitePdsContinuousRestartTest.class); 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 new file mode 100644 index 0000000000000..c7b010bd8f45c --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java @@ -0,0 +1,54 @@ +/* +* 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.testsuites; + +import junit.framework.TestSuite; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsAtomicCacheRebalancingTest; +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; +import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsPageEvictionTest; +import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsCacheIntegrationTest; +import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsNoActualWalHistoryTest; +import org.apache.ignite.internal.processors.cache.persistence.db.wal.IgniteWalRecoveryTest; +import org.apache.ignite.internal.processors.cache.persistence.db.wal.WalRecoveryTxLogicalRecordsTest; + +/** + * Test suite for tests that cover core PDS features and depend on indexing module. + */ +public class IgnitePdsWithIndexingCoreTestSuite extends TestSuite { + /** + * @return Test suite. + * @throws Exception Thrown in case of the failure. + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("Ignite Persistent Store With Indexing Test Suite"); + + suite.addTestSuite(IgnitePdsCacheIntegrationTest.class); + suite.addTestSuite(IgnitePdsMultiNodePutGetRestartTest.class); + suite.addTestSuite(IgnitePdsPageEvictionTest.class); + suite.addTestSuite(IgnitePersistentStoreCacheGroupsTest.class); + + suite.addTestSuite(WalRecoveryTxLogicalRecordsTest.class); + suite.addTestSuite(IgniteWalRecoveryTest.class); + suite.addTestSuite(IgnitePdsNoActualWalHistoryTest.class); + suite.addTestSuite(IgnitePdsAtomicCacheRebalancingTest.class); + suite.addTestSuite(IgnitePdsTxCacheRebalancingTest.class); + + return suite; + } +} From 5e9d9ebc1140f9647fc1b325ba81d0ad6c2c69f3 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 13 Jun 2017 16:21:20 +0300 Subject: [PATCH 286/311] ignite-2.1.1 Added description to MX bean --- .../java/org/apache/ignite/mxbean/PersistenceMetricsMXBean.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/mxbean/PersistenceMetricsMXBean.java b/modules/core/src/main/java/org/apache/ignite/mxbean/PersistenceMetricsMXBean.java index 30ccab465c494..40c2235e373e1 100644 --- a/modules/core/src/main/java/org/apache/ignite/mxbean/PersistenceMetricsMXBean.java +++ b/modules/core/src/main/java/org/apache/ignite/mxbean/PersistenceMetricsMXBean.java @@ -21,7 +21,7 @@ import org.apache.ignite.configuration.PersistentStoreConfiguration; /** - * + * An MX bean allowing to monitor and tune persistence metrics. */ public interface PersistenceMetricsMXBean extends PersistenceMetrics { /** {@inheritDoc} */ From 9141b3698d0ec98e512efbc78864cc06781fd8c7 Mon Sep 17 00:00:00 2001 From: devozerov Date: Tue, 13 Jun 2017 16:32:28 +0300 Subject: [PATCH 287/311] IGNITE-5267: Fixed too early StoredCacheData initialization. --- .../processors/cache/GridCacheProcessor.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 f15573e174757..466163f485051 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 @@ -692,15 +692,15 @@ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near } /** - * @param cacheData Cache data. + * @param cfg Cache configuration. + * @param sql SQL flag. * @param caches Caches map. * @param templates Templates map. * @throws IgniteCheckedException If failed. */ - private void addCacheOnJoin(StoredCacheData cacheData, + private void addCacheOnJoin(CacheConfiguration cfg, boolean sql, Map caches, Map templates) throws IgniteCheckedException { - CacheConfiguration cfg = cacheData.config(); String cacheName = cfg.getName(); CU.validateCacheName(cacheName); @@ -712,6 +712,10 @@ private void addCacheOnJoin(StoredCacheData cacheData, // Initialize defaults. initialize(cfg, cacheObjCtx); + StoredCacheData cacheData = new StoredCacheData(cfg); + + cacheData.sql(sql); + boolean template = cacheName.endsWith("*"); if (!template) { @@ -754,10 +758,8 @@ private void addCacheOnJoinFromConfig( // Replace original configuration value. cfgs[i] = cfg; - StoredCacheData cacheData = new StoredCacheData(cfg); - cacheData.sql(false); - addCacheOnJoin(cacheData, caches, templates); + addCacheOnJoin(cfg, false, caches, templates); } } From 2d8c6519d36e2d7890a45b258d3b7439942dca66 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 13 Jun 2017 16:39:13 +0300 Subject: [PATCH 288/311] ignite-2.1.1 Add joining node tests --- .../AbstractNodeJoinTemplate.java | 743 ++++++++++++++++++ .../IgniteStandByClusterTest.java | 213 +++++ .../join/JoinActiveNodeToActiveCluster.java | 431 ++++++++++ .../join/JoinActiveNodeToInActiveCluster.java | 227 ++++++ .../join/JoinInActiveNodeToActiveCluster.java | 356 +++++++++ .../JoinInActiveNodeToInActiveCluster.java | 226 ++++++ ...iveNodeToActiveClusterWithPersistence.java | 98 +++ ...eNodeToInActiveClusterWithPersistence.java | 31 + ...iveNodeToActiveClusterWithPersistence.java | 86 ++ ...eNodeToInActiveClusterWithPersistence.java | 31 + ...iteAbstractStandByClientReconnectTest.java | 336 ++++++++ .../IgniteStandByClientReconnectTest.java | 283 +++++++ ...tandByClientReconnectToNewClusterTest.java | 289 +++++++ 13 files changed, 3350 insertions(+) create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToActiveCluster.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToInActiveCluster.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToActiveCluster.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToInActiveCluster.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectTest.java create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java new file mode 100644 index 0000000000000..76a5260a90a5a --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java @@ -0,0 +1,743 @@ +/* + * 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.standbycluster; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; +import org.apache.ignite.internal.util.typedef.CI1; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteCallable; +import org.apache.ignite.lang.IgniteClosure; +import org.apache.ignite.lang.IgniteInClosure; +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.junits.common.GridCommonAbstractTest; +import org.junit.Assert; + +import static org.apache.ignite.internal.util.IgniteUtils.field; + +/** + * + */ +public abstract class AbstractNodeJoinTemplate extends GridCommonAbstractTest { + /** Cache 1. */ + protected static final String cache1 = "cache1"; + + /** Cache 2. */ + protected static final String cache2 = "cache2"; + + //Todo Cache with node filter. + protected static final String cache3 = "cache3"; + + protected static final String cache4 = "cache4"; + + protected static final String cache5 = "cache5"; + + /** Caches info. */ + public static final String CACHES_INFO = "cachesInfo"; + + /** Registered caches. */ + public static final String REGISTERED_CACHES = "registeredCaches"; + + /** Caches. */ + public static final String CACHES = "caches"; + + /** + * @param ig Ig. + */ + protected static Map cacheDescriptors(IgniteEx ig) { + return field(field(ig.context().cache(), CACHES_INFO), REGISTERED_CACHES); + } + + /** + * @param ig Ig. + */ + protected static Map caches(IgniteEx ig){ + return field(ig.context().cache(), CACHES); + } + + /** + * + */ + public abstract JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception; + + /** + * + */ + public abstract JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception; + + /** + * + */ + public abstract JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception; + + /** + * + */ + public abstract JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception; + + /** + * + */ + public abstract JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception; + + // Client node join. + + public abstract JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception; + + public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception; + + public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception; + + public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception; + + public abstract JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception; + + /** + * + */ + public abstract void testJoinWithOutConfiguration() throws Exception; + + /** + * + */ + public abstract void testStaticCacheConfigurationOnJoin() throws Exception; + + /** + * + */ + public abstract void testStaticCacheConfigurationInCluster() throws Exception; + + /** + * + */ + public abstract void testStaticCacheConfigurationSameOnBoth() throws Exception; + + /** + * + */ + public abstract void testStaticCacheConfigurationDifferentOnBoth() throws Exception; + + /** + * + */ + public abstract void testJoinClientWithOutConfiguration() throws Exception; + + /** + * + */ + public abstract void testJoinClientStaticCacheConfigurationOnJoin() throws Exception; + + /** + * + */ + public abstract void testJoinClientStaticCacheConfigurationInCluster() throws Exception; + + /** + * + */ + public abstract void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception; + + /** + * + */ + public abstract void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception; + + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false)); + } + + /** + * @param idx Index. + */ + protected String name(int idx) { + return getTestIgniteInstanceName(idx); + } + + /** + * @param name Name. + */ + protected IgniteConfiguration cfg(String name) throws Exception { + try { + return getConfiguration(name); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * + */ + protected JoinNodeTestPlanBuilder builder() { + return JoinNodeTestPlanBuilder.builder(); + } + + /** + * @param cfgs Cfgs. + */ + protected static T[] buildConfiguration(T... cfgs) { + return cfgs; + } + + /** + * + */ + protected CacheConfiguration atomicCfg() { + return new CacheConfiguration(cache1) + .setAtomicityMode(CacheAtomicityMode.ATOMIC); + } + + /** + * + */ + protected CacheConfiguration transactionCfg() { + return new CacheConfiguration(cache2) + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + } + + /** + * + */ + protected CacheConfiguration[] allCacheConfigurations() { + return buildConfiguration(atomicCfg(), transactionCfg()); + } + + /** Set client. */ + protected final IgniteClosure setClient = + new IgniteClosure() { + @Override public IgniteConfiguration apply(IgniteConfiguration cfg) { + return cfg.setClientMode(true); + } + }; + + /** Ip finder. */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String name) throws Exception { + return super.getConfiguration(name) + .setDiscoverySpi( + new TcpDiscoverySpi() + .setIpFinder(ipFinder) + ); + } + + /** {@inheritDoc} */ + protected IgniteConfiguration persistentCfg(IgniteConfiguration cfg) throws Exception { + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + + return cfg; + } + + /** + * + */ + public static class JoinNodeTestPlanBuilder extends GridCommonAbstractTest { + /** String plan builder. */ + private final StringBuilder strPlanBuilder = new StringBuilder().append("**** Execution plan ****\n"); + + /** Nodes. */ + protected List nodes = new ArrayList<>(4); + + /** Cluster config. */ + private IgniteConfiguration[] clusterCfg; + + /** Node config. */ + private IgniteConfiguration nodeCfg; + + /** State default. */ + private static final Boolean stateDefault = new Boolean(true); + + /** State. */ + private Boolean state = stateDefault; + + /** Noop. */ + private static final Runnable Noop = new Runnable() { + @Override public void run() { + } + }; + + /** After cluster started. */ + private Runnable afterClusterStarted = Noop; + + /** After node join. */ + private Runnable afterNodeJoin = Noop; + + /** After activate. */ + private Runnable afterActivate = Noop; + + /** After de activate. */ + private Runnable afterDeActivate = Noop; + + private IgniteCallable> dynamicCacheStart = + new IgniteCallable>() { + @Override public List call() throws Exception { + return Arrays.asList(new CacheConfiguration(cache4), new CacheConfiguration(cache5)); + } + }; + + private IgniteCallable> dynamicCacheStop = + new IgniteCallable>() { + @Override public List call() throws Exception { + return Arrays.asList(cache4, cache5); + } + }; + + private Runnable afterDynamicCacheStarted = Noop; + + private Runnable afterDynamicCacheStopped = Noop; + + /** End. */ + private Runnable end = Noop; + + /** + * + */ + public JoinNodeTestPlanBuilder clusterConfiguration(IgniteConfiguration... cfgs) throws Exception { + clusterCfg = cfgs; + + strPlanBuilder.append("Start cluster:\n"); + + for (IgniteConfiguration cfg : cfgs) { + strPlanBuilder.append("node: ") + .append(cfg.getIgniteInstanceName()) + .append(" activeOnStart - ") + .append(cfg.isActiveOnStart()) + .append("\n"); + + CacheConfiguration[] ccfgs = cfg.getCacheConfiguration(); + + if (ccfgs != null) { + for (CacheConfiguration ccfg : ccfgs) + strPlanBuilder.append(" cache - ") + .append(ccfg.getName()) + .append("\n"); + } + } + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder nodeConfiguration(IgniteConfiguration cfg) { + nodeCfg = cfg; + + strPlanBuilder.append("Join node:\n") + .append(cfg.getIgniteInstanceName()) + .append(cfg.isClientMode() != null && cfg.isClientMode() ? " (client)" : "") + .append(" activeOnStart - ") + .append(cfg.isActiveOnStart()) + .append("\n"); + + CacheConfiguration[] ccfgs = cfg.getCacheConfiguration(); + + if (ccfgs != null) + for (CacheConfiguration ccfg : ccfgs) + strPlanBuilder.append(" cache - ").append(ccfg.getName()).append("\n"); + + return this; + } + + /** + * @param func Func. + */ + public JoinNodeTestPlanBuilder nodeConfiguration( + IgniteClosure func + ) { + + nodeCfg = func.apply(nodeCfg); + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder afterClusterStarted(Runnable r) { + strPlanBuilder.append("Check after cluster start\n"); + + afterClusterStarted = r; + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder afterNodeJoin(Runnable r) { + strPlanBuilder.append("Check after node join") + .append("\n"); + + afterNodeJoin = r; + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder stateAfterJoin(boolean state) { + strPlanBuilder.append("Check state on all nodes after join, must be ") + .append(state ? "<>" : "<>") + .append(" \n"); + + this.state = state; + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder afterActivate(Runnable r) { + strPlanBuilder.append("Check after activate") + .append("\n"); + + afterActivate = r; + + return this; + } + + /** + * + */ + public JoinNodeTestPlanBuilder afterDeActivate(Runnable r) { + strPlanBuilder.append("Check after deActivate") + .append("\n"); + + afterDeActivate = r; + + return this; + } + + public JoinNodeTestPlanBuilder dynamicCacheStart(IgniteCallable> caches){ + strPlanBuilder.append("Dynamic caches start") + .append("\n"); + + dynamicCacheStart = caches; + + return this; + } + + public JoinNodeTestPlanBuilder afterDynamicCacheStarted(Runnable r){ + strPlanBuilder.append("Check after dynamic caches start") + .append("\n"); + + afterDynamicCacheStarted = r; + + return this; + } + + public JoinNodeTestPlanBuilder dynamicCacheStop(IgniteCallable> caches){ + strPlanBuilder.append("Dynamic caches stop") + .append("\n"); + + dynamicCacheStop = caches; + + return this; + } + + public JoinNodeTestPlanBuilder afterDynamicCacheStopped(Runnable r){ + strPlanBuilder.append("Check after dynamic caches stop") + .append("\n"); + + afterDynamicCacheStopped = r; + + return this; + } + + /** + * @param end End. + */ + public JoinNodeTestPlanBuilder setEnd(Runnable end) { + strPlanBuilder.append("Check before stop") + .append("\n"); + + this.end = end; + + return this; + } + + /** + * + */ + public void execute() throws Exception { + try { + if (state == stateDefault) + fail("State after join must be specific. See JoinNodeTestPlanBuilder.stateAfterJoin(boolean)."); + + System.out.println(strPlanBuilder.append("********************").toString()); + + IgniteConfiguration[] cfgs = clusterCfg; + + System.out.println(">>> Start cluster"); + + for (IgniteConfiguration cfg : cfgs) { + startGrid(cfg); + + nodes.add(cfg.getIgniteInstanceName()); + } + + System.out.println(">>> Check after cluster started"); + + afterClusterStarted.run(); + + System.out.println(">>> Start new node"); + + startGrid(nodeCfg); + + nodes.add(nodeCfg.getIgniteInstanceName()); + + System.out.println(">>> Check after new node join in cluster"); + + afterNodeJoin.run(); + + System.out.println(">>> Check cluster state on all nodes"); + + IgniteEx crd = grid(nodes.get(0)); + + for (IgniteEx ig : grids()) + assertEquals((boolean)state, ig.active()); + + if (!state) { + System.out.println(">>> Activate cluster"); + + crd.active(true); + + System.out.println(">>> Check after cluster activated"); + + afterActivate.run(); + } + else { + System.out.println(">>> DeActivate cluster"); + + crd.active(false); + + System.out.println(">>> Check after cluster deActivated"); + + afterDeActivate.run(); + + System.out.println(">>> Activate cluster"); + + crd.active(true); + } + + AffinityTopologyVersion next0Ver = nextMinorVersion(crd); + + crd.createCaches(dynamicCacheStart.call()); + + awaitTopologyVersion(next0Ver); + + afterDynamicCacheStarted.run(); + + onAllNode(new CI1() { + @Override public void apply(IgniteEx ig) { + if (ig.context().discovery().localNode().isClient()) + return; + + Assert.assertNotNull(ig.context().cache().cache(cache4)); + Assert.assertNotNull(ig.context().cache().cache(cache5)); + + } + }); + + AffinityTopologyVersion next1Ver = nextMinorVersion(crd); + + crd.destroyCaches(dynamicCacheStop.call()); + + afterDynamicCacheStopped.run(); + + awaitTopologyVersion(next1Ver); + + onAllNode(new CI1() { + @Override public void apply(IgniteEx ig) { + if (ig.context().discovery().localNode().isClient()) + return; + + Assert.assertNull(ig.context().cache().cache(cache4)); + Assert.assertNull(ig.context().cache().cache(cache5)); + + } + }); + + System.out.println(">>> Finish check"); + + end.run(); + } + finally { + stopAllGrids(); + } + } + + private AffinityTopologyVersion nextMinorVersion(IgniteEx ig){ + AffinityTopologyVersion cur = ig.context().discovery().topologyVersionEx(); + + return new AffinityTopologyVersion(cur.topologyVersion(), cur.minorTopologyVersion() + 1); + } + + private void awaitTopologyVersion(final AffinityTopologyVersion ver){ + onAllNode(new CI1() { + @Override public void apply(IgniteEx ig) { + while (true) { + AffinityTopologyVersion locTopVer = ig.context().cache().context() + .exchange().readyAffinityVersion(); + + if (locTopVer.compareTo(ver) < 0){ + System.out.println("Top ready " + locTopVer + " on " + ig.localNode().id()); + + try { + Thread.sleep(100); + } + catch (InterruptedException e) { + break; + } + } + else + break; + } + } + }).run(); + + } + + /** + * + */ + protected List grids() { + List res = new ArrayList<>(); + + for (String name : nodes) + res.add(grid(name)); + + return res; + } + + /** + * + */ + public static JoinNodeTestPlanBuilder builder() { + return new JoinNodeTestPlanBuilder(); + } + + /** + * + */ + public Runnable checkCacheOnlySystem() { + return onAllNode(new IgniteInClosure() { + @Override public void apply(IgniteEx ig) { + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(2, desc.size()); + + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + Assert.assertEquals(2, caches.size()); + } + }); + } + + /** + * + */ + public Runnable checkCacheEmpty() { + return onAllNode(new IgniteInClosure() { + @Override public void apply(IgniteEx ig) { + Map desc = cacheDescriptors(ig); + + Assert.assertTrue(desc.isEmpty()); + + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + Assert.assertEquals(0, caches.size()); + } + }); + } + + /** + * + */ + public Runnable checkCacheNotEmpty() { + return onAllNode(new IgniteInClosure() { + @Override public void apply(IgniteEx ig) { + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + }); + } + + /** + * @param cls Closure. + */ + private Runnable onAllNode(final IgniteInClosure cls) { + return new Runnable() { + @Override public void run() { + for (IgniteEx ig : grids()) { + try { + cls.apply(ig); + } + catch (AssertionError e) { + System.out.println("Assertion on " + ig.name()); + + throw e; + } + } + } + }; + } + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java new file mode 100644 index 0000000000000..2d704db44d137 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java @@ -0,0 +1,213 @@ +/* + * 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.standbycluster; + +import java.util.Arrays; +import java.util.Map; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; +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; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Assert; + +/** + * + */ +public class IgniteStandByClusterTest extends GridCommonAbstractTest { + private static final TcpDiscoveryIpFinder vmIpFinder = new TcpDiscoveryVmIpFinder(true); + + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(vmIpFinder)); + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setConsistentId(igniteInstanceName); + + return cfg; + } + + public void testNotStartDynamicCachesOnClientAfterActivation() throws Exception { + final String cacheName0 = "cache0"; + final String cacheName = "cache"; + + IgniteConfiguration cfg1 = getConfiguration("serv1"); + IgniteConfiguration cfg2 = getConfiguration("serv2"); + + IgniteConfiguration cfg3 = getConfiguration("client"); + cfg3.setCacheConfiguration(new CacheConfiguration(cacheName0)); + + cfg3.setClientMode(true); + + IgniteEx ig1 = startGrid(cfg1); + IgniteEx ig2 = startGrid(cfg2); + IgniteEx ig3 = startGrid(cfg3); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + ig3.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + ig3.createCache(new CacheConfiguration<>(cacheName)); + + assertNotNull(ig3.cache(cacheName)); + assertNotNull(ig1.cache(cacheName)); + assertNotNull(ig2.cache(cacheName)); + + assertNotNull(ig1.cache(cacheName0)); + assertNotNull(ig3.cache(cacheName0)); + assertNotNull(ig2.cache(cacheName0)); + + ig3.active(false); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + ig3.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + assertNotNull(ig1.cache(cacheName)); + assertNotNull(ig2.cache(cacheName)); + + Map> caches = U.field(ig3.context().cache(), "caches"); + + // Only system caches and cache0 + assertTrue(caches.size() == 3); + + assertNull(caches.get(cacheName)); + + assertNotNull(caches.get(cacheName0)); + + assertNotNull(ig3.cache(cacheName)); + } + + public void testStaticCacheStartAfterActivationWithCacheFilter() throws Exception { + String cache1 = "cache1"; + String cache2 = "cache2"; + String cache3 = "cache3"; + + IgniteConfiguration cfg1 = getConfiguration("node1"); + + cfg1.setCacheConfiguration( + new CacheConfiguration(cache1).setNodeFilter(new NodeFilterIgnoreByName("node2"))); + + IgniteConfiguration cfg2 = getConfiguration("node2"); + + cfg2.setCacheConfiguration( + new CacheConfiguration(cache2).setNodeFilter(new NodeFilterIgnoreByName("node3"))); + + IgniteConfiguration cfg3 = getConfiguration("node3"); + + cfg3.setCacheConfiguration( + new CacheConfiguration(cache3).setNodeFilter(new NodeFilterIgnoreByName("node1"))); + + IgniteEx ig1 = startGrid(cfg1); + IgniteEx ig2 = startGrid(cfg2); + IgniteEx ig3 = startGrid(cfg3); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!ig3.active()); + + for (IgniteEx ig: Arrays.asList(ig1,ig2,ig3)){ + Map desc = U.field(U.field(ig.context().cache(), "cachesInfo"), "registeredCaches"); + + assertEquals(0, desc.size()); + } + + ig3.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(ig3.active()); + + for (IgniteEx ig: Arrays.asList(ig1,ig2,ig3)){ + Map desc = U.field( + U.field(ig.context().cache(), "cachesInfo"), "registeredCaches"); + + assertEquals(5, desc.size()); + + Map> caches = U.field(ig.context().cache(), "caches"); + + assertEquals(4, caches.keySet().size()); + } + + Map> caches1 = U.field(ig1.context().cache(), "caches"); + + Assert.assertNotNull(caches1.get(cache1)); + Assert.assertNotNull(caches1.get(cache2)); + Assert.assertNull(caches1.get(cache3)); + + Map> caches2 = U.field(ig2.context().cache(), "caches"); + + Assert.assertNull(caches2.get(cache1)); + Assert.assertNotNull(caches2.get(cache2)); + Assert.assertNotNull(caches2.get(cache3)); + + Map> caches3 = U.field(ig3.context().cache(), "caches"); + + Assert.assertNotNull(caches3.get(cache1)); + Assert.assertNull(caches3.get(cache2)); + Assert.assertNotNull(caches3.get(cache3)); + } + + private static class NodeFilterIgnoreByName implements IgnitePredicate{ + private final String name; + + private NodeFilterIgnoreByName(String name) { + this.name = name; + } + + @Override public boolean apply(ClusterNode node) { + return !name.equals(node.consistentId()); + } + } + + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); + } + + @Override protected void afterTest() throws Exception { + super.beforeTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToActiveCluster.java new file mode 100644 index 0000000000000..fc9d307e3ba73 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToActiveCluster.java @@ -0,0 +1,431 @@ +/* + * 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.standbycluster.join; + +import java.util.Map; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; +import org.junit.Assert; + +/** + * + */ +public class JoinActiveNodeToActiveCluster extends AbstractNodeJoinTemplate { + /** + * + */ + @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(true), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheOnlySystem() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(true) + ).afterNodeJoin( + b.checkCacheOnlySystem() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheOnlySystem() + ); + + return b; + } + + /** + * + */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(true), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheOnlySystem() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** + * + */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheNotEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** + * + */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheNotEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** + * + */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(atomicCfg()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(3, desc.size()); + + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + Assert.assertEquals(3, caches.size()); + } + } + } + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(transactionCfg()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + // Server node join. + + /** {@inheritDoc} */ + @Override public void testJoinWithOutConfiguration() throws Exception { + withOutConfigurationTemplate().execute(); + } + + /** + * + */ + @Override public void testStaticCacheConfigurationOnJoin() throws Exception { + staticCacheConfigurationOnJoinTemplate().execute(); + } + + /** + * + */ + @Override public void testStaticCacheConfigurationInCluster() throws Exception { + staticCacheConfigurationInClusterTemplate().execute(); + } + + /** + * + */ + @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { + staticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** + * + */ + @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { + staticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + // Client node join. + + /** + * + */ + @Override public void testJoinClientWithOutConfiguration() throws Exception { + joinClientWithOutConfigurationTemplate().execute(); + } + + /** + * + */ + @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { + joinClientStaticCacheConfigurationOnJoinTemplate().execute(); + } + + /** + * + */ + @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { + joinClientStaticCacheConfigurationInClusterTemplate().execute(); + } + + /** + * + */ + @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { + joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** + * + */ + @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { + joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + return withOutConfigurationTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { + return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { + return staticCacheConfigurationInClusterTemplate() + .nodeConfiguration(setClient) + .afterActivate(new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }).afterNodeJoin( + new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }).setEnd(new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }); + } + + @Override + public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return staticCacheConfigurationDifferentOnBothTemplate() + .nodeConfiguration(setClient) + .afterActivate(new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }) + .afterNodeJoin(new Runnable() { + @Override public void run() { + for (int i = 0; i < 4; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertNotNull(ig.context().cache().cache(cache1)); + + Assert.assertNotNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertEquals(4, caches.size()); + else + Assert.assertEquals(3, caches.size()); + } + } + }) + .setEnd(new Runnable() { + @Override public void run() { + for (int i = 0; i < 4; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertNotNull(ig.context().cache().cache(cache1)); + + Assert.assertNotNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertEquals(4, caches.size()); + else + Assert.assertEquals(3, caches.size()); + } + } + }); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { + return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToInActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToInActiveCluster.java new file mode 100644 index 0000000000000..b248b210804f3 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinActiveNodeToInActiveCluster.java @@ -0,0 +1,227 @@ +/* + * 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.standbycluster.join; + +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; + +/** + * + */ +public class JoinActiveNodeToInActiveCluster extends AbstractNodeJoinTemplate { + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(false), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheOnlySystem() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(false), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(true) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(atomicCfg()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(true) + .setCacheConfiguration(transactionCfg()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + // Server node join. + + /** {@inheritDoc} */ + @Override public void testJoinWithOutConfiguration() throws Exception { + withOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationOnJoin() throws Exception { + staticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationInCluster() throws Exception { + staticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { + staticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { + staticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + // Client node join. + + /** {@inheritDoc} */ + @Override public void testJoinClientWithOutConfiguration() throws Exception { + joinClientWithOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { + joinClientStaticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { + joinClientStaticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { + joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { + joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + return withOutConfigurationTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { + return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { + return staticCacheConfigurationInClusterTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return staticCacheConfigurationDifferentOnBothTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { + return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); + } + +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToActiveCluster.java new file mode 100644 index 0000000000000..6ba3a2020d171 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToActiveCluster.java @@ -0,0 +1,356 @@ +/* + * 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.standbycluster.join; + +import java.util.Map; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; +import org.junit.Assert; + +/** + * + */ +public class JoinInActiveNodeToActiveCluster extends AbstractNodeJoinTemplate { + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(true), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheOnlySystem() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(false) + ).afterNodeJoin( + b.checkCacheOnlySystem() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheOnlySystem() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(true), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheOnlySystem() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheNotEmpty() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(false) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + b.checkCacheNotEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(true) + .setCacheConfiguration(atomicCfg()), + cfg(name(1)).setActiveOnStart(true), + cfg(name(2)).setActiveOnStart(true) + ).afterClusterStarted( + new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(3, desc.size()); + + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + Assert.assertEquals(3, caches.size()); + } + } + } + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(transactionCfg()) + ).afterNodeJoin( + b.checkCacheNotEmpty() + ).stateAfterJoin( + true + ).afterDeActivate( + b.checkCacheEmpty() + ).setEnd( + b.checkCacheNotEmpty() + ); + + return b; + } + + // Server node join. + + /** {@inheritDoc} */ + @Override public void testJoinWithOutConfiguration() throws Exception { + withOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationOnJoin() throws Exception { + staticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationInCluster() throws Exception { + staticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { + staticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { + staticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + // Client node join. + + /** {@inheritDoc} */ + @Override public void testJoinClientWithOutConfiguration() throws Exception { + joinClientWithOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { + joinClientStaticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { + joinClientStaticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { + joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { + joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + return withOutConfigurationTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { + return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { + return staticCacheConfigurationInClusterTemplate() + .nodeConfiguration(setClient) + .afterNodeJoin(new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }).setEnd(new Runnable() { + @Override public void run() { + for (int i = 0; i < 3; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) { + Assert.assertNotNull(ig.context().cache().cache(cache1)); + Assert.assertNotNull(ig.context().cache().cache(cache2)); + } + else { + Assert.assertNull(ig.context().cache().cache(cache1)); + Assert.assertNull(ig.context().cache().cache(cache2)); + } + + Map caches = caches(ig); + + Assert.assertEquals(4, caches.size()); + } + } + }); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { + return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return staticCacheConfigurationDifferentOnBothTemplate() + .nodeConfiguration(setClient) + .afterNodeJoin( + new Runnable() { + @Override public void run() { + for (int i = 0; i < 4; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertNotNull(ig.context().cache().cache(cache1)); + + Assert.assertNotNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertEquals(4, caches.size()); + else + Assert.assertEquals(3, caches.size()); + } + } + } + ).setEnd( + new Runnable() { + @Override public void run() { + for (int i = 0; i < 4; i++) { + IgniteEx ig = grid(name(i)); + + Map desc = cacheDescriptors(ig); + + Assert.assertEquals(4, desc.size()); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertNotNull(ig.context().cache().cache(cache1)); + + Assert.assertNotNull(ig.context().cache().cache(cache2)); + + Map caches = caches(ig); + + if (!ig.context().discovery().localNode().isClient()) + Assert.assertEquals(4, caches.size()); + else + Assert.assertEquals(3, caches.size()); + } + } + } + ); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToInActiveCluster.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToInActiveCluster.java new file mode 100644 index 0000000000000..244001bf1c486 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/JoinInActiveNodeToInActiveCluster.java @@ -0,0 +1,226 @@ +/* + * 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.standbycluster.join; + +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; + +/** + * + */ +public class JoinInActiveNodeToInActiveCluster extends AbstractNodeJoinTemplate { + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(false), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(false) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheOnlySystem() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)).setActiveOnStart(false), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)).setActiveOnStart(false) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(allCacheConfigurations()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + /** {@inheritDoc} */ + @Override public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + JoinNodeTestPlanBuilder b = builder(); + + b.clusterConfiguration( + cfg(name(0)) + .setActiveOnStart(false) + .setCacheConfiguration(transactionCfg()), + cfg(name(1)).setActiveOnStart(false), + cfg(name(2)).setActiveOnStart(false) + ).afterClusterStarted( + b.checkCacheEmpty() + ).nodeConfiguration( + cfg(name(3)) + .setActiveOnStart(false) + .setCacheConfiguration(atomicCfg()) + ).afterNodeJoin( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + // Server node join. + + /** {@inheritDoc} */ + @Override public void testJoinWithOutConfiguration() throws Exception { + withOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationOnJoin() throws Exception { + staticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationInCluster() throws Exception { + staticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationSameOnBoth() throws Exception { + staticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testStaticCacheConfigurationDifferentOnBoth() throws Exception { + staticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + // Client node join. + + /** {@inheritDoc} */ + @Override public void testJoinClientWithOutConfiguration() throws Exception { + joinClientWithOutConfigurationTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationOnJoin() throws Exception { + joinClientStaticCacheConfigurationOnJoinTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationInCluster() throws Exception { + joinClientStaticCacheConfigurationInClusterTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationSameOnBoth() throws Exception { + joinClientStaticCacheConfigurationSameOnBothTemplate().execute(); + } + + /** {@inheritDoc} */ + @Override public void testJoinClientStaticCacheConfigurationDifferentOnBoth() throws Exception { + joinClientStaticCacheConfigurationDifferentOnBothTemplate().execute(); + } + + @Override public JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + return withOutConfigurationTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { + return staticCacheConfigurationOnJoinTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { + return staticCacheConfigurationInClusterTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationSameOnBothTemplate() throws Exception { + return staticCacheConfigurationSameOnBothTemplate().nodeConfiguration(setClient); + } + + @Override public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return staticCacheConfigurationDifferentOnBothTemplate().nodeConfiguration(setClient); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java new file mode 100644 index 0000000000000..54087ba883e1d --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToActiveClusterWithPersistence.java @@ -0,0 +1,98 @@ +/* + * 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.standbycluster.join.persistence; + +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinActiveNodeToActiveCluster; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; + +/** + * + */ +public class JoinActiveNodeToActiveClusterWithPersistence extends JoinActiveNodeToActiveCluster { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration cfg(String name) throws Exception { + return persistentCfg(super.cfg(name)); + } + + private AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder persistent(AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b) { + b.afterClusterStarted( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterNodeJoin( + b.checkCacheEmpty() + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.withOutConfigurationTemplate()); + + b.afterActivate(b.checkCacheOnlySystem()); + + return b; + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.joinClientWithOutConfigurationTemplate()); + + b.afterActivate(b.checkCacheOnlySystem()); + + return b; + } + + @Override public void testJoinWithOutConfiguration() throws Exception { + withOutConfigurationTemplate().execute(); + } + + @Override public void testJoinClientWithOutConfiguration() throws Exception { + joinClientWithOutConfigurationTemplate().execute(); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + return persistent(super.staticCacheConfigurationOnJoinTemplate()); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + return persistent(super.staticCacheConfigurationInClusterTemplate()); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + return persistent(super.staticCacheConfigurationSameOnBothTemplate()); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return persistent(super.staticCacheConfigurationDifferentOnBothTemplate()); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationOnJoinTemplate() throws Exception { + return persistent(super.joinClientStaticCacheConfigurationOnJoinTemplate()); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception { + return persistent(super.joinClientStaticCacheConfigurationInClusterTemplate()); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return persistent(super.joinClientStaticCacheConfigurationDifferentOnBothTemplate()); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java new file mode 100644 index 0000000000000..305255c95c214 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinActiveNodeToInActiveClusterWithPersistence.java @@ -0,0 +1,31 @@ +/* + * 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.standbycluster.join.persistence; + +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinActiveNodeToInActiveCluster; +import org.apache.ignite.configuration.IgniteConfiguration; + +/** + * + */ +public class JoinActiveNodeToInActiveClusterWithPersistence extends JoinActiveNodeToInActiveCluster { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration cfg(String name) throws Exception { + return persistentCfg(super.cfg(name)); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java new file mode 100644 index 0000000000000..a138d8dcdb8cd --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToActiveClusterWithPersistence.java @@ -0,0 +1,86 @@ +/* + * 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.standbycluster.join.persistence; + +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinInActiveNodeToActiveCluster; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.AbstractNodeJoinTemplate; + +/** + * + */ +public class JoinInActiveNodeToActiveClusterWithPersistence extends JoinInActiveNodeToActiveCluster { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration cfg(String name) throws Exception { + return persistentCfg(super.cfg(name)); + } + + private AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder persistent(AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b) { + b.afterClusterStarted( + b.checkCacheEmpty() + ).stateAfterJoin( + false + ).afterNodeJoin( + b.checkCacheEmpty() + ).afterActivate( + b.checkCacheNotEmpty() + ); + + return b; + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder withOutConfigurationTemplate() throws Exception { + AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.withOutConfigurationTemplate()); + + b.afterActivate(b.checkCacheOnlySystem()); + + return b; + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientWithOutConfigurationTemplate() throws Exception { + AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder b = persistent(super.joinClientWithOutConfigurationTemplate()); + + b.afterActivate(b.checkCacheOnlySystem()); + + return b; + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception{ + return persistent(super.joinClientStaticCacheConfigurationInClusterTemplate()); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return persistent(super.joinClientStaticCacheConfigurationDifferentOnBothTemplate()); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationOnJoinTemplate() throws Exception { + return persistent(super.staticCacheConfigurationOnJoinTemplate()); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationInClusterTemplate() throws Exception { + return persistent(super.staticCacheConfigurationInClusterTemplate()); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationSameOnBothTemplate() throws Exception { + return persistent(super.staticCacheConfigurationSameOnBothTemplate()); + } + + @Override public AbstractNodeJoinTemplate.JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception { + return persistent(super.staticCacheConfigurationDifferentOnBothTemplate()); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java new file mode 100644 index 0000000000000..b3db10d045e34 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/join/persistence/JoinInActiveNodeToInActiveClusterWithPersistence.java @@ -0,0 +1,31 @@ +/* + * 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.standbycluster.join.persistence; + +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinInActiveNodeToInActiveCluster; +import org.apache.ignite.configuration.IgniteConfiguration; + +/** + * + */ +public class JoinInActiveNodeToInActiveClusterWithPersistence extends JoinInActiveNodeToInActiveCluster { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration cfg(String name) throws Exception { + return persistentCfg(super.cfg(name)); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java new file mode 100644 index 0000000000000..eec267b5ed208 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteAbstractStandByClientReconnectTest.java @@ -0,0 +1,336 @@ +/* + * 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.standbycluster.reconnect; + +import com.google.common.collect.Sets; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.PersistentStoreConfiguration; +import org.apache.ignite.events.Event; +import org.apache.ignite.events.EventType; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage; +import org.apache.ignite.spi.discovery.DiscoverySpiListener; +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.jetbrains.annotations.Nullable; +import org.junit.Assert; + +import static org.apache.ignite.events.EventType.EVT_CLIENT_NODE_DISCONNECTED; + +/** + * + */ +public abstract class IgniteAbstractStandByClientReconnectTest extends GridCommonAbstractTest { + + private static final TcpDiscoveryVmIpFinder vmIpFinder = new TcpDiscoveryVmIpFinder(true); + + private static final TcpDiscoveryVmIpFinder clientIpFinder = new TcpDiscoveryVmIpFinder(true); + + protected final String node1 = "node1"; + protected final String node2 = "node2"; + protected final String nodeClient = "nodeClient"; + + protected final String ccfg1staticName = "cache1static"; + protected final String ccfg2staticName = "cache2static"; + protected final String ccfg3staticName = "cache3static"; + + protected final String ccfg1staticWithFilterName = "ccfg1staticWithFilter"; + protected final String ccfg2staticWithFilterName = "ccfg2staticWithFilter"; + protected final String ccfg3staticWithFilterName = "ccfg3staticWithFilter"; + + protected final String ccfgDynamicName = "ccfgDynamic"; + protected final String ccfgDynamicWithFilterName = "ccfgDynamicWithFilter"; + + protected final CacheConfiguration ccfg1static = new CacheConfiguration(ccfg1staticName); + protected final CacheConfiguration ccfg2static = new CacheConfiguration(ccfg2staticName); + protected final CacheConfiguration ccfg3static = new CacheConfiguration(ccfg3staticName); + + protected final CacheConfiguration ccfg1staticWithFilter = + new CacheConfiguration(ccfg1staticWithFilterName).setNodeFilter(new FilterNode(node2)); + + protected final CacheConfiguration ccfg2staticWithFilter = + new CacheConfiguration(ccfg2staticWithFilterName).setNodeFilter(new FilterNode(nodeClient)); + + protected final CacheConfiguration ccfg3staticWithFilter = + new CacheConfiguration(ccfg3staticWithFilterName).setNodeFilter(new FilterNode(node1)); + + protected final CacheConfiguration ccfgDynamic = new CacheConfiguration(ccfgDynamicName); + + protected final CacheConfiguration ccfgDynamicWithFilter = + new CacheConfiguration(ccfgDynamicWithFilterName).setNodeFilter(new FilterNode(node2)); + + protected final Set staticCacheNames = Sets.newHashSet( + ccfg1staticName, ccfg2staticName, ccfg3staticName, + ccfg1staticWithFilterName, ccfg2staticWithFilterName, ccfg3staticWithFilterName + ); + + protected final Set allCacheNames = Sets.newHashSet( + ccfg1staticName, ccfg2staticName, ccfg3staticName, + ccfg1staticWithFilterName, ccfg2staticWithFilterName, ccfg3staticWithFilterName, + ccfgDynamicName, ccfgDynamicWithFilterName + ); + + @Override protected IgniteConfiguration getConfiguration(String name) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(name); + + if (!nodeClient.equals(name)) + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(vmIpFinder)); + else { + clientIpFinder.setAddresses(Collections.singletonList("127.0.0.1:47501")); + + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(clientIpFinder)); + } + + cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()); + cfg.setConsistentId(name); + + return cfg; + } + + protected void addDisconnectListener( + final CountDownLatch disconnectedLatch, + final CountDownLatch reconnectedLatch + ) { + grid(nodeClient).events().localListen(new IgnitePredicate() { + @Override public boolean apply(Event event) { + switch (event.type()) { + case EventType.EVT_CLIENT_NODE_DISCONNECTED: + info("Client disconnected"); + + disconnectedLatch.countDown(); + + break; + case EventType.EVT_CLIENT_NODE_RECONNECTED: + info("Client reconnected"); + + reconnectedLatch.countDown(); + } + + return true; + } + }, EventType.EVT_CLIENT_NODE_DISCONNECTED, EventType.EVT_CLIENT_NODE_RECONNECTED); + } + + protected void checkDescriptors(IgniteEx ig, Set cacheNames) { + Collection descs = ig.context().cache().cacheDescriptors().values(); + + assertEquals("Node name: " + ig.name(), cacheNames.size() + 2, descs.size()); + + int systemCnt = 0; + + for (DynamicCacheDescriptor desc : descs) + if (!CU.isSystemCache(desc.cacheName())) + assertTrue(desc.cacheName(), cacheNames.contains(desc.cacheName())); + else + systemCnt++; + + assertEquals(2, systemCnt); + } + + protected void startNodes(CountDownLatch activateLatch) throws Exception { + IgniteConfiguration cfg1 = getConfiguration(node1) + .setCacheConfiguration(ccfg1static, ccfg1staticWithFilter); + + IgniteConfiguration cfg2 = getConfiguration(node2) + .setCacheConfiguration(ccfg2static, ccfg2staticWithFilter); + + IgniteConfiguration cfg3 = getConfiguration(nodeClient) + .setCacheConfiguration(ccfg3static, ccfg3staticWithFilter); + + if (activateLatch != null) + cfg3.setDiscoverySpi( + new AwaitTcpDiscoverySpi(activateLatch) + .setIpFinder(clientIpFinder) + ); + + cfg3.setClientMode(true); + + IgniteEx ig1 = startGrid(cfg1); + IgniteEx ig2 = startGrid(cfg2); + IgniteEx client = startGrid(cfg3); + } + + protected void checkStaticCaches() { + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + Assert.assertNotNull(ig1.cache(ccfg1staticName)); + Assert.assertNotNull(ig1.cache(ccfg2staticName)); + Assert.assertNotNull(ig1.cache(ccfg3staticName)); + + Assert.assertNotNull(ig1.cache(ccfg1staticWithFilterName)); + Assert.assertNotNull(ig1.cache(ccfg2staticWithFilterName)); + + Assert.assertNotNull(ig2.cache(ccfg1staticName)); + Assert.assertNotNull(ig2.cache(ccfg2staticName)); + Assert.assertNotNull(ig2.cache(ccfg3staticName)); + + Assert.assertNotNull(ig2.cache(ccfg3staticWithFilterName)); + Assert.assertNotNull(ig2.cache(ccfg2staticWithFilterName)); + + Assert.assertNotNull(client.cache(ccfg1staticName)); + Assert.assertNotNull(client.cache(ccfg2staticName)); + Assert.assertNotNull(client.cache(ccfg3staticName)); + + Assert.assertNotNull(client.cache(ccfg3staticWithFilterName)); + Assert.assertNotNull(client.cache(ccfg1staticWithFilterName)); + } + + protected void checkAllCaches() { + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + checkStaticCaches(); + + Assert.assertNotNull(ig1.cache(ccfgDynamicName)); + Assert.assertNotNull(ig1.cache(ccfgDynamicWithFilterName)); + + Assert.assertNotNull(ig2.cache(ccfgDynamicName)); + + Assert.assertNotNull(client.cache(ccfgDynamicName)); + Assert.assertNotNull(client.cache(ccfgDynamicWithFilterName)); + } + + protected void checkOnlySystemCaches() { + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + Assert.assertNull(ig1.cache(ccfg1staticName)); + Assert.assertNull(ig1.cache(ccfg2staticName)); + Assert.assertNull(ig1.cache(ccfg3staticName)); + + Assert.assertNull(ig1.cache(ccfg1staticWithFilterName)); + Assert.assertNull(ig1.cache(ccfg2staticWithFilterName)); + + Assert.assertNull(ig2.cache(ccfg1staticName)); + Assert.assertNull(ig2.cache(ccfg2staticName)); + Assert.assertNull(ig2.cache(ccfg3staticName)); + + Assert.assertNull(ig2.cache(ccfg3staticWithFilterName)); + Assert.assertNull(ig2.cache(ccfg2staticWithFilterName)); + + Assert.assertNull(client.cache(ccfg1staticName)); + Assert.assertNull(client.cache(ccfg2staticName)); + Assert.assertNull(client.cache(ccfg3staticName)); + + Assert.assertNull(client.cache(ccfg3staticWithFilterName)); + Assert.assertNull(client.cache(ccfg1staticWithFilterName)); + + checkDescriptors(ig1,Collections.emptySet()); + checkDescriptors(ig2,Collections.emptySet()); + checkDescriptors(client, Collections.emptySet()); + } + + private static class FilterNode implements IgnitePredicate { + + private final String consistentId; + + private FilterNode(String id) { + consistentId = id; + } + + @Override public boolean apply(ClusterNode node) { + return !consistentId.equals(node.consistentId()); + } + } + + private static class AwaitTcpDiscoverySpi extends TcpDiscoverySpi { + + private final CountDownLatch latch; + + private AwaitTcpDiscoverySpi(CountDownLatch latch) { + this.latch = latch; + } + + @Override public void setListener(@Nullable DiscoverySpiListener lsnr) { + super.setListener(new AwaitDiscoverySpiListener(latch, lsnr)); + } + } + + private static class AwaitDiscoverySpiListener implements DiscoverySpiListener { + + private final CountDownLatch latch; + + private final DiscoverySpiListener delegate; + + private AwaitDiscoverySpiListener( + CountDownLatch latch, + DiscoverySpiListener delegate + ) { + this.latch = latch; + this.delegate = delegate; + } + + @Override public void onLocalNodeInitialized(ClusterNode locNode) { + delegate.onLocalNodeInitialized(locNode); + } + + @Override public void onDiscovery( + int type, + long topVer, + ClusterNode node, + Collection topSnapshot, + @Nullable Map> topHist, + @Nullable DiscoverySpiCustomMessage data + ) { + delegate.onDiscovery(type, topVer, node, topSnapshot, topHist, data); + + if (type == EVT_CLIENT_NODE_DISCONNECTED) + try { + System.out.println("Await cluster change state"); + + latch.await(); + } + catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); + } + + @Override protected void afterTest() throws Exception { + super.beforeTest(); + + stopAllGrids(); + + deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true)); + } + +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectTest.java new file mode 100644 index 0000000000000..02f7d000e5853 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectTest.java @@ -0,0 +1,283 @@ +/* + * 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.standbycluster.reconnect; + +import java.util.concurrent.CountDownLatch; +import org.apache.ignite.internal.IgniteEx; + +/** + * + */ +public class IgniteStandByClientReconnectTest extends IgniteAbstractStandByClientReconnectTest { + + public void testActiveClientReconnectToActiveCluster() throws Exception { + CountDownLatch activateLatch = new CountDownLatch(1); + + startNodes(activateLatch); + + info(">>>> star grid"); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + client.active(true); + + info(">>>> activate grid"); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + checkDescriptors(client, staticCacheNames); + + checkStaticCaches(); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + info(">>>> stop servers"); + + stopGrid(node2); + + disconnectedLatch.await(); + + ig2 = startGrid(getConfiguration(node2)); + + info(">>>> activate new servers"); + + ig1.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + + activateLatch.countDown(); + + info(">>>> reconnect client"); + + reconnectedLatch.await(); + + info(">>>> client reconnected"); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + checkAllCaches(); + } + + public void testActiveClientReconnectToInActiveCluster() throws Exception { + CountDownLatch activateLatch = new CountDownLatch(1); + + startNodes(activateLatch); + + info(">>>> star grid"); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + info(">>>> activate grid"); + + client.active(true); + + checkStaticCaches(); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + checkDescriptors(client, staticCacheNames); + + info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + info(">>>> stop " + node2); + + stopGrid(node2); + + disconnectedLatch.await(); + + ig1.active(false); + + activateLatch.countDown(); + + info(">>>> restart " + node2); + + ig2 = startGrid(getConfiguration(node2)); + + reconnectedLatch.await(); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + client.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + checkAllCaches(); + } + + public void testInActiveClientReconnectToActiveCluster() throws Exception { + CountDownLatch activateLatch = new CountDownLatch(1); + + startNodes(activateLatch); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + stopGrid(node2); + + disconnectedLatch.await(); + + ig2 = startGrid(getConfiguration(node2)); + + ig1.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + + activateLatch.countDown(); + + reconnectedLatch.await(); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + checkAllCaches(); + } + + public void testInActiveClientReconnectToInActiveCluster() throws Exception { + startNodes(null); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + stopGrid(node2); + + disconnectedLatch.await(); + + ig2 = startGrid(getConfiguration(node2)); + + reconnectedLatch.await(); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + client.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkStaticCaches(); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + checkAllCaches(); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java new file mode 100644 index 0000000000000..2bcc177796dd6 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/reconnect/IgniteStandByClientReconnectToNewClusterTest.java @@ -0,0 +1,289 @@ +/* + * 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.standbycluster.reconnect; + +import com.google.common.collect.Sets; +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import org.apache.ignite.internal.IgniteEx; + +/** + * + */ +public class IgniteStandByClientReconnectToNewClusterTest extends IgniteAbstractStandByClientReconnectTest { + + public void testActiveClientReconnectToActiveCluster() throws Exception { + CountDownLatch activateLatch = new CountDownLatch(1); + + startNodes(activateLatch); + + info(">>>> star grid"); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + info(">>>> activate grid"); + + client.active(true); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + checkDescriptors(client, staticCacheNames); + + checkStaticCaches(); + + info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + info(">>>> stop servers"); + + stopGrid(node1); + stopGrid(node2); + + disconnectedLatch.await(); + + ig1 = startGrid(getConfiguration(node1)); + ig2 = startGrid(getConfiguration(node2)); + + info(">>>> activate new servers"); + + ig1.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + + activateLatch.countDown(); + + info(">>>> reconnect client"); + + reconnectedLatch.await(); + + info(">>>> client reconnected"); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkAllCaches(); + } + + public void testActiveClientReconnectToInActiveCluster() throws Exception { + startNodes(null); + + info(">>>> star grid"); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + info(">>>> activate grid"); + + client.active(true); + + checkStaticCaches(); + + checkDescriptors(ig1, staticCacheNames); + checkDescriptors(ig2, staticCacheNames); + checkDescriptors(client, staticCacheNames); + + info(">>>> dynamic start [" + ccfgDynamicName + ", " + ccfgDynamicWithFilterName + "]"); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + checkDescriptors(ig1, allCacheNames); + checkDescriptors(ig2, allCacheNames); + checkDescriptors(client, allCacheNames); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + info(">>>> stop servers"); + + stopGrid(node1); + stopGrid(node2); + + assertTrue(client.active()); + + System.out.println("Await disconnected"); + + disconnectedLatch.await(); + + ig1 = startGrid(getConfiguration("node1")); + ig2 = startGrid(getConfiguration("node2")); + + info(">>>> reconnect client"); + + reconnectedLatch.await(); + + info(">>>> client reconnected"); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + info(">>>> activate new servers"); + + client.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkAllCaches(); + } + + public void testInActiveClientReconnectToActiveCluster() throws Exception { + CountDownLatch activateLatch = new CountDownLatch(1); + + startNodes(activateLatch); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + stopGrid(node1); + stopGrid(node2); + + disconnectedLatch.await(); + + ig1 = startGrid(getConfiguration(node1)); + ig2 = startGrid(getConfiguration(node2)); + + ig1.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + + checkDescriptors(ig1, Collections.emptySet()); + checkDescriptors(ig2, Collections.emptySet()); + + activateLatch.countDown(); + + reconnectedLatch.await(); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkOnlySystemCaches(); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + Set exp2 = Sets.newHashSet(ccfgDynamicName, ccfgDynamicWithFilterName); + + checkDescriptors(ig1, exp2); + checkDescriptors(ig2, exp2); + checkDescriptors(client, exp2); + } + + public void testInActiveClientReconnectToInActiveCluster() throws Exception { + startNodes(null); + + IgniteEx ig1 = grid(node1); + IgniteEx ig2 = grid(node2); + IgniteEx client = grid(nodeClient); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + final CountDownLatch disconnectedLatch = new CountDownLatch(1); + final CountDownLatch reconnectedLatch = new CountDownLatch(1); + + addDisconnectListener(disconnectedLatch, reconnectedLatch); + + stopGrid(node1); + stopGrid(node2); + + assertTrue(!client.active()); + + disconnectedLatch.await(); + + ig1 = startGrid(getConfiguration(node1)); + ig2 = startGrid(getConfiguration(node2)); + + reconnectedLatch.await(); + + assertTrue(!ig1.active()); + assertTrue(!ig2.active()); + assertTrue(!client.active()); + + client.active(true); + + assertTrue(ig1.active()); + assertTrue(ig2.active()); + assertTrue(client.active()); + + checkOnlySystemCaches(); + + client.createCache(ccfgDynamic); + + client.createCache(ccfgDynamicWithFilter); + + Set exp2 = Sets.newHashSet(ccfgDynamicName, ccfgDynamicWithFilterName); + + checkDescriptors(ig1, exp2); + checkDescriptors(ig2, exp2); + checkDescriptors(client, exp2); + } +} From d369dfc4973c179861d1d2ff37fbe8c6c0543d1a Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Tue, 13 Jun 2017 16:47:22 +0300 Subject: [PATCH 289/311] ignite-2.1.1 IgniteSpringDataTestSuite - added vm ip finder --- .../ignite/springdata/IgniteSpringDataCrudSelfTest.java | 1 - .../ignite/springdata/misc/ApplicationConfiguration.java | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/spring-data/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCrudSelfTest.java b/modules/spring-data/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCrudSelfTest.java index 14d6844260763..0199f6b75ec08 100644 --- a/modules/spring-data/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCrudSelfTest.java +++ b/modules/spring-data/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCrudSelfTest.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.TreeMap; import java.util.TreeSet; import org.apache.ignite.springdata.misc.ApplicationConfiguration; import org.apache.ignite.springdata.misc.Person; diff --git a/modules/spring-data/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java b/modules/spring-data/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java index 731e6d966b852..e460cdabb48c6 100644 --- a/modules/spring-data/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java +++ b/modules/spring-data/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java @@ -21,6 +21,8 @@ import org.apache.ignite.Ignition; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.apache.ignite.springdata.repository.config.EnableIgniteRepositories; @@ -41,6 +43,12 @@ public Ignite igniteInstance() { cfg.setCacheConfiguration(ccfg); + TcpDiscoverySpi spi = new TcpDiscoverySpi(); + + spi.setIpFinder(new TcpDiscoveryVmIpFinder(true)); + + cfg.setDiscoverySpi(spi); + return Ignition.start(cfg); } } From ab62ce847cb73854f31f1232144f487786a6a3d1 Mon Sep 17 00:00:00 2001 From: Pavel Kovalenko Date: Fri, 9 Jun 2017 00:30:41 +0300 Subject: [PATCH 290/311] IGNITE-5267 Remove entry from on-heap locks map if it was removed from off-heap --- .../processors/cache/distributed/dht/GridDhtLocalPartition.java | 2 ++ 1 file changed, 2 insertions(+) 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 f0d5bf181964a..8e42351a88c00 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 @@ -999,6 +999,8 @@ public void clearAll() throws NodeStoppingException { ctx.database().checkpointReadLock(); try {if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry)cached).clearInternal(clearVer, extras)) { + removeEntry(cached); + if (rec) { hld.cctx.events().addEvent(cached.partition(), cached.key(), From 33a9cc4cf9b32d93e34c5855d52ce208a3fd8228 Mon Sep 17 00:00:00 2001 From: Pavel Kovalenko Date: Fri, 9 Jun 2017 00:33:30 +0300 Subject: [PATCH 291/311] IGNITE-5267 Deserialize binary object explicitly instead of calling cache. Small refactoring. --- .../binary/BinaryObjectExceptionSelfTest.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java index 35756a4f609f1..a3ee93af88014 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java @@ -20,9 +20,7 @@ import java.math.BigDecimal; import java.sql.Timestamp; import java.util.Date; -import java.util.Iterator; import java.util.UUID; -import javax.cache.Cache; import org.apache.ignite.IgniteCache; import org.apache.ignite.binary.BinaryBasicNameMapper; import org.apache.ignite.binary.BinaryObjectException; @@ -60,9 +58,8 @@ public class BinaryObjectExceptionSelfTest extends GridCommonAbstractTest { .setCopyOnRead(true) ); - BinaryConfiguration bcfg = new BinaryConfiguration(); - - bcfg.setNameMapper(new BinaryBasicNameMapper(false)); + BinaryConfiguration bcfg = new BinaryConfiguration() + .setNameMapper(new BinaryBasicNameMapper(false)); cfg.setBinaryConfiguration(bcfg); @@ -112,10 +109,7 @@ public void testUnexpectedFieldType() throws Exception { a[i] = -1; try { - Iterator> it = cache.iterator(); - - while (it.hasNext()) - it.next(); + b.deserialize(); } catch (Exception ex) { Throwable root = ex; From 95257a16aef0bc0bbacdee03503ee483ffc75bda Mon Sep 17 00:00:00 2001 From: Pavel Kovalenko Date: Fri, 9 Jun 2017 00:34:37 +0300 Subject: [PATCH 292/311] IGNITE-5267 Small test refactoring and speeding up --- .../dht/GridCachePartitionedUnloadEventsSelfTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedUnloadEventsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedUnloadEventsSelfTest.java index 2f15b7229eb67..8dc2835153919 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedUnloadEventsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedUnloadEventsSelfTest.java @@ -47,6 +47,9 @@ public class GridCachePartitionedUnloadEventsSelfTest extends GridCommonAbstract /** */ private TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + /** */ + private static final int EVENTS_COUNT = 40; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); @@ -78,11 +81,11 @@ protected CacheConfiguration cacheConfiguration() { public void testUnloadEvents() throws Exception { final Ignite g1 = startGrid("g1"); - Collection allKeys = new ArrayList<>(100); + Collection allKeys = new ArrayList<>(EVENTS_COUNT); IgniteCache cache = g1.cache(DEFAULT_CACHE_NAME); - for (int i = 0; i < 100; i++) { + for (int i = 0; i < EVENTS_COUNT; i++) { cache.put(i, "val"); allKeys.add(i); } @@ -97,8 +100,6 @@ public void testUnloadEvents() throws Exception { assertNotNull(g2Keys); assertFalse("There are no keys assigned to g2", g2Keys.isEmpty()); - Thread.sleep(5000); - Collection objEvts = g1.events().localQuery(F.alwaysTrue(), EVT_CACHE_REBALANCE_OBJECT_UNLOADED); From e2354cb5ea8965276c3696895c86e51315765571 Mon Sep 17 00:00:00 2001 From: Pavel Kovalenko Date: Fri, 9 Jun 2017 00:37:38 +0300 Subject: [PATCH 293/311] IGNITE-5267 Fixed and simplified test --- ...eMarshallerCacheClassNameConflictTest.java | 101 ++++++++++-------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteMarshallerCacheClassNameConflictTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteMarshallerCacheClassNameConflictTest.java index 6545a4e127780..c8a0e76bca04d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteMarshallerCacheClassNameConflictTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteMarshallerCacheClassNameConflictTest.java @@ -25,8 +25,10 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.ignite.Ignite; import org.apache.ignite.Ignition; +import org.apache.ignite.binary.BinaryBasicIdMapper; import org.apache.ignite.cache.CachePeekMode; import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.BinaryConfiguration; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; @@ -36,7 +38,6 @@ 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.config.GridTestProperties; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.jetbrains.annotations.Nullable; @@ -90,6 +91,11 @@ public class IgniteMarshallerCacheClassNameConflictTest extends GridCommonAbstra cfg.setCacheConfiguration(ccfg); + // Use case sensitive mapper + BinaryConfiguration binaryCfg = new BinaryConfiguration().setIdMapper(new BinaryBasicIdMapper(false)); + + cfg.setBinaryConfiguration(binaryCfg); + return cfg; } @@ -97,6 +103,7 @@ public class IgniteMarshallerCacheClassNameConflictTest extends GridCommonAbstra @Override protected void afterTest() throws Exception { stopAllGrids(); } + /** * @throws Exception If failed. */ @@ -108,8 +115,9 @@ public void testCachePutGetClassesWithNameConflict() throws Exception { final AtomicInteger trickCompilerVar = new AtomicInteger(1); - final Organization aOrg1 = new Organization(1, "Microsoft", "One Microsoft Way Redmond, WA 98052-6399, USA"); - final Organization_D4pss2X99lE bOrg2 = new Organization_D4pss2X99lE(2, "Apple", "1 Infinite Loop, Cupertino, CA 95014, USA"); + // "Aa" and "BB" have same hash code + final Aa aOrg1 = new Aa(1, "Microsoft", "One Microsoft Way Redmond, WA 98052-6399, USA"); + final BB bOrg2 = new BB(2, "Apple", "1 Infinite Loop, Cupertino, CA 95014, USA"); exec1.submit(new Runnable() { @Override public void run() { @@ -205,9 +213,9 @@ private DiscoverySpiListenerWrapper(DiscoverySpiListener delegate) { String conflClsName = U.field(customMsg, "conflictingClsName"); if (conflClsName != null && !conflClsName.isEmpty()) { rejectObserved = true; - if (conflClsName.contains("Organization")) + if (conflClsName.contains(Aa.class.getSimpleName())) bbClsRejected = true; - else if (conflClsName.contains("Organization_D4pss2X99lE")) + else if (conflClsName.contains(BB.class.getSimpleName())) aaClsRejected = true; } } @@ -227,53 +235,54 @@ else if (conflClsName.contains("Organization_D4pss2X99lE")) } } - /** - * Class name is chosen to be in conflict with other class name this test put to cache. - */ - private static class Organization { - /** */ - private final int id; +} - /** */ - private final String name; +/** + * Class name is chosen to be in conflict with other class name this test put to cache. + */ +class Aa { + /** */ + private final int id; - /** */ - private final String addr; - - /** - * @param id Id. - * @param name Name. - * @param addr Address. - */ - Organization(int id, String name, String addr) { - this.id = id; - this.name = name; - this.addr = addr; - } - } + /** */ + private final String name; + + /** */ + private final String addr; /** - * Class name is chosen to be in conflict with other class name this test put to cache. + * @param id Id. + * @param name Name. + * @param addr Address. */ - private static class Organization_D4pss2X99lE { - /** */ - private final int id; + Aa(int id, String name, String addr) { + this.id = id; + this.name = name; + this.addr = addr; + } +} - /** */ - private final String name; +/** + * Class name is chosen to be in conflict with other class name this test put to cache. + */ +class BB { + /** */ + private final int id; - /** */ - private final String addr; - - /** - * @param id Id. - * @param name Name. - * @param addr Address. - */ - Organization_D4pss2X99lE(int id, String name, String addr) { - this.id = id; - this.name = name; - this.addr = addr; - } + /** */ + private final String name; + + /** */ + private final String addr; + + /** + * @param id Id. + * @param name Name. + * @param addr Address. + */ + BB(int id, String name, String addr) { + this.id = id; + this.name = name; + this.addr = addr; } } From 41cea0bc2f887881a78436e54143313af27e7fa8 Mon Sep 17 00:00:00 2001 From: Pavel Kovalenko Date: Fri, 9 Jun 2017 00:38:55 +0300 Subject: [PATCH 294/311] IGNITE-5267 Make partitionMapExchange timeout configurable --- .../junits/common/GridCommonAbstractTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 625fb7d6d8d58..563d91d042cf8 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 @@ -532,6 +532,13 @@ protected void awaitPartitionMapExchange( awaitPartitionMapExchange(waitEvicts, waitNode2PartUpdate, nodes, false); } + /** + * @return Maximum time of awaiting PartitionMapExchange operation (in milliseconds) + */ + protected long getPartitionMapExchangeTimeout() { + return 30_000; + } + /** * @param waitEvicts If {@code true} will wait for evictions finished. * @param waitNode2PartUpdate If {@code true} will wait for nodes node2part info update finished. @@ -546,7 +553,7 @@ protected void awaitPartitionMapExchange( @Nullable Collection nodes, boolean printPartState ) throws InterruptedException { - long timeout = 30_000; + long timeout = getPartitionMapExchangeTimeout(); long startTime = -1; From 8e1439782b993c8ccb974bcdbd55d4f2b28a5489 Mon Sep 17 00:00:00 2001 From: Pavel Kovalenko Date: Fri, 9 Jun 2017 00:40:53 +0300 Subject: [PATCH 295/311] IGNITE-5267 Use owners instead of nodes to properly check finishing of partitionMapExchange --- .../testframework/junits/common/GridCommonAbstractTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 563d91d042cf8..3f87c766232b4 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 @@ -642,7 +642,7 @@ protected void awaitPartitionMapExchange( GridDhtTopologyFuture topFut = top.topologyVersionFuture(); Collection owners = (topFut != null && topFut.isDone()) ? - top.nodes(p, AffinityTopologyVersion.NONE) : Collections.emptyList(); + top.owners(p, AffinityTopologyVersion.NONE) : Collections.emptyList(); int ownerNodesCnt = owners.size(); From ef732dae02673c2ce79575b57454a573f0d1d591 Mon Sep 17 00:00:00 2001 From: Pavel Kovalenko Date: Fri, 9 Jun 2017 00:42:00 +0300 Subject: [PATCH 296/311] IGNITE-5267 Provide entry key explicitly in cache queries. Fixed test. --- .../cache/IgniteCacheDistributedJoinNoIndexTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheDistributedJoinNoIndexTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheDistributedJoinNoIndexTest.java index 08e5244bb9572..7cd39b3762baf 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheDistributedJoinNoIndexTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheDistributedJoinNoIndexTest.java @@ -179,11 +179,11 @@ public void testJoin() throws Exception { "where p.orgName = o.name"); checkNoIndexError(personCache, "select o.name, p._key, p.orgName " + - "from \"org\".Organization o, (select * from \"person\".Person) p " + + "from \"org\".Organization o, (select *, _key from \"person\".Person) p " + "where p.orgName = o.name"); checkNoIndexError(personCache, "select o.name, p._key, p.orgName " + - "from (select * from \"org\".Organization) o, (select * from \"person\".Person) p " + + "from (select * from \"org\".Organization) o, (select *, _key from \"person\".Person) p " + "where p.orgName = o.name"); checkNoIndexError(personCache, "select o.name, p._key, p.orgName " + From 5eb40528bd6e52b4c13a4c21ecca74407b081898 Mon Sep 17 00:00:00 2001 From: Pavel Kovalenko Date: Fri, 9 Jun 2017 00:42:34 +0300 Subject: [PATCH 297/311] IGNITE-5267 Explicitly fail test with known issue --- .../cache/IgniteCacheJoinPartitionedAndReplicatedTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java index af94686e6dfa7..6c5bfa34871eb 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java @@ -232,6 +232,8 @@ public void testJoin() throws Exception { /** */ public void testReplicatedToPartitionedLeftJoin() { + fail("https://issues.apache.org/jira/browse/IGNITE-5016"); + Ignite client = grid(2); IgniteCache personCache = client.cache(PERSON_CACHE); From fd7050c72c8125ed1dd213ef781bdb9971d00413 Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Tue, 13 Jun 2017 17:02:54 +0300 Subject: [PATCH 298/311] ignite-2.1.1 Add joining node tests in suit --- .../testsuites/IgniteStandByClusterSuite.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java index b120c62b69039..6418eefb8c417 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteStandByClusterSuite.java @@ -23,6 +23,17 @@ import org.apache.ignite.internal.processors.cache.persistence.standbycluster.IgniteChangeGlobalStateDataStructureTest; import org.apache.ignite.internal.processors.cache.persistence.standbycluster.IgniteChangeGlobalStateFailOverTest; import org.apache.ignite.internal.processors.cache.persistence.standbycluster.IgniteChangeGlobalStateTest; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.IgniteStandByClusterTest; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinActiveNodeToActiveCluster; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinActiveNodeToInActiveCluster; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinInActiveNodeToActiveCluster; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.JoinInActiveNodeToInActiveCluster; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.persistence.JoinActiveNodeToActiveClusterWithPersistence; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.persistence.JoinActiveNodeToInActiveClusterWithPersistence; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.persistence.JoinInActiveNodeToActiveClusterWithPersistence; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.join.persistence.JoinInActiveNodeToInActiveClusterWithPersistence; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.reconnect.IgniteStandByClientReconnectTest; +import org.apache.ignite.internal.processors.cache.persistence.standbycluster.reconnect.IgniteStandByClientReconnectToNewClusterTest; /** * @@ -34,6 +45,20 @@ public class IgniteStandByClusterSuite extends TestSuite { public static TestSuite suite() { TestSuite suite = new TestSuite("Ignite Activate/DeActivate Cluster Test Suit"); + suite.addTestSuite(IgniteStandByClusterTest.class); + suite.addTestSuite(IgniteStandByClientReconnectTest.class); + suite.addTestSuite(IgniteStandByClientReconnectToNewClusterTest.class); + + suite.addTestSuite(JoinActiveNodeToActiveCluster.class); + suite.addTestSuite(JoinActiveNodeToInActiveCluster.class); + suite.addTestSuite(JoinInActiveNodeToActiveCluster.class); + suite.addTestSuite(JoinInActiveNodeToInActiveCluster.class); + + suite.addTestSuite(JoinActiveNodeToActiveClusterWithPersistence.class); + suite.addTestSuite(JoinActiveNodeToInActiveClusterWithPersistence.class); + suite.addTestSuite(JoinInActiveNodeToActiveClusterWithPersistence.class); + suite.addTestSuite(JoinInActiveNodeToInActiveClusterWithPersistence.class); + suite.addTestSuite(IgniteChangeGlobalStateTest.class); suite.addTestSuite(IgniteChangeGlobalStateCacheTest.class); suite.addTestSuite(IgniteChangeGlobalStateDataStructureTest.class); From 3e509aa604ca342b3f42a73e771a5a4f678d7132 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Tue, 13 Jun 2017 17:13:43 +0300 Subject: [PATCH 299/311] ignite-2.1.1 Fixing compilation in tests --- .../persistence/standbycluster/AbstractNodeJoinTemplate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java index 76a5260a90a5a..0a4d0cd6c8770 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/AbstractNodeJoinTemplate.java @@ -72,7 +72,7 @@ public abstract class AbstractNodeJoinTemplate extends GridCommonAbstractTest { * @param ig Ig. */ protected static Map cacheDescriptors(IgniteEx ig) { - return field(field(ig.context().cache(), CACHES_INFO), REGISTERED_CACHES); + return field((Object)field(ig.context().cache(), CACHES_INFO), REGISTERED_CACHES); } /** From dea416fa65874d4e33b37b46368f9e476a3904f4 Mon Sep 17 00:00:00 2001 From: dpavlov Date: Tue, 13 Jun 2017 18:00:32 +0300 Subject: [PATCH 300/311] Merge fix: 4.ea2 into 5267: remove node is loopback check --- .../communication/tcp/TcpCommunicationSpi.java | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java index b569aa2e8b3e3..8b8c18cd397af 100755 --- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java @@ -2917,22 +2917,9 @@ protected GridCommunicationClient createTcpClient(ClusterNode node, int connIdx) // Try to connect first on bound addresses. if (isRmtAddrsExist) { - boolean sameHost = U.sameMacs(getSpiContext().localNode(), node); - - List addrs0; - - Collection socketAddrs = U.toSocketAddresses(rmtAddrs0, rmtHostNames0, boundPort); - - if (sameHost) - addrs0 = new ArrayList<>(socketAddrs); - else { - addrs0 = new ArrayList<>(socketAddrs.size()); + List addrs0 = new ArrayList<>(U.toSocketAddresses(rmtAddrs0, rmtHostNames0, boundPort)); - for (InetSocketAddress addr0 : socketAddrs) { - if (!addr0.getAddress().isLoopbackAddress()) - addrs0.add(addr0); - } - } + boolean sameHost = U.sameMacs(getSpiContext().localNode(), node); Collections.sort(addrs0, U.inetAddressesComparator(sameHost)); From fb2e6d4ab00e3e443bdd896918e812d6fa6119ba Mon Sep 17 00:00:00 2001 From: sboikov Date: Tue, 13 Jun 2017 18:10:18 +0300 Subject: [PATCH 301/311] Merge remote-tracking branch 'remotes/origin/master' into ignite-2.1.1 # Conflicts: # modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticAware.java # modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticMessage.java # modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxImplicitSingleStateImpl.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java # modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java # modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java # modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java # modules/core/src/test/java/org/apache/ignite/internal/managers/IgniteDiagnosticMessagesTest.java # modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/ClusterListener.java --- .../internal/IgniteDiagnosticMessage.java | 2 +- .../apache/ignite/internal/IgniteKernal.java | 2 - .../managers/communication/GridIoManager.java | 2 +- .../communication/GridIoMessageFactory.java | 5 - .../GridCachePartitionExchangeManager.java | 17 +-- .../GridDhtPartitionsExchangeFuture.java | 4 + .../processors/cluster/ClusterProcessor.java | 116 ------------------ .../tcp/TcpCommunicationSpi.java | 5 +- 8 files changed, 12 insertions(+), 141 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticMessage.java index 4f37f537fbdcd..fd72d63590395 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticMessage.java @@ -222,7 +222,7 @@ public boolean request() { /** {@inheritDoc} */ @Override public short directType() { - return -55; + return -61; } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index ff5b482cc1f46..c3e998150ddb6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -951,8 +951,6 @@ public void start( provider.start(ctx.plugins().pluginContextForProvider(provider)); } - ctx.cluster().initListeners(); - // Start platform plugins. if (ctx.config().getPlatformConfiguration() != null) startProcessor(new PlatformPluginProcessor(ctx)); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java index cc6f3a2675051..7813b2ef43e33 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java @@ -2296,7 +2296,7 @@ public void dumpStats() { CommunicationSpi spi = getSpi(); if (spi instanceof TcpCommunicationSpi) - ((TcpCommunicationSpi)spi).dumpDiagnosticInfo(); + ((TcpCommunicationSpi)spi).dumpStats(); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java index 46c212532b386..3dac18e2bb7fb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java @@ -177,11 +177,6 @@ public GridIoMessageFactory(MessageFactory[] ext) { Message msg = null; switch (type) { - case -55: - msg = new IgniteDiagnosticMessage(); - - break; - // -54 is reserved for SQL. // -46 ... -51 - snapshot messages. case -61: 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 3632667a76852..dd1d47cc35fa3 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 @@ -1541,7 +1541,8 @@ public void dumpLongRunningOperations(long timeout) { U.warn(diagnosticLog, "Found long running cache operations, dump IO statistics."); // Dump IO manager statistics. - if (IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_IO_DUMP_ON_TIMEOUT, false))cctx.gridIO().dumpStats();} + if (IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_IO_DUMP_ON_TIMEOUT, false)) + cctx.gridIO().dumpStats();} } else { nextLongRunningOpsDumpTime = 0; @@ -1603,22 +1604,14 @@ private void dumpPendingObjects(@Nullable AffinityTopologyVersion exchTopVer, U.warn(diagnosticLog, "Pending cache futures:"); - for (GridCacheFuture fut : mvcc.activeFutures()) { + for (GridCacheFuture fut : mvcc.activeFutures()) dumpDiagnosticInfo(fut, diagCtx); - if (fut instanceof IgniteDiagnosticAware) - ((IgniteDiagnosticAware)fut).dumpDiagnosticInfo(); - } - U.warn(diagnosticLog, "Pending atomic cache futures:"); - for (GridCacheFuture fut : mvcc.atomicFutures()) { + for (GridCacheFuture fut : mvcc.atomicFutures()) dumpDiagnosticInfo(fut, diagCtx); - if (fut instanceof IgniteDiagnosticAware) - ((IgniteDiagnosticAware)fut).dumpDiagnosticInfo(); - } - U.warn(diagnosticLog, "Pending data streamer futures:"); for (IgniteInternalFuture fut : mvcc.dataStreamerFutures()) @@ -1889,8 +1882,6 @@ void dumpExchangeDebugInfo() { } nextDumpTime = U.currentTimeMillis() + nextDumpTimeout(dumpCnt++, futTimeout); - - exchFut.dumpDiagnosticInfo(); } } catch (Exception e) { 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 71d1a6acaf6d1..f62cafeec67ae 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 @@ -112,6 +112,9 @@ @SuppressWarnings({"TypeMayBeWeakened", "unchecked"}) public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter implements Comparable, GridDhtTopologyFuture, CachePartitionExchangeWorkerTask, IgniteDiagnosticAware { + /** */ + public static final String EXCHANGE_LOG = "org.apache.ignite.internal.exchange.time"; + /** Dummy flag. */ private final boolean dummy; @@ -191,6 +194,7 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter futs = diagnosticFutMap.get(); - - if (futs != null) { - for (InternalDiagnosticFuture fut : futs.values()) { - if (fut.nodeId.equals(nodeId)) - fut.onDone("Target node failed: " + nodeId); - } - } - } - }, - EVT_NODE_FAILED, EVT_NODE_LEFT); - - ctx.io().addMessageListener(GridTopic.TOPIC_INTERNAL_DIAGNOSTIC, new GridMessageListener() { - @Override public void onMessage(UUID nodeId, Object msg) { - if (msg instanceof IgniteDiagnosticMessage) { - IgniteDiagnosticMessage msg0 = (IgniteDiagnosticMessage)msg; - - if (msg0.request()) { - ClusterNode node = ctx.discovery().node(nodeId); - - if (node == null) { - if (diagnosticLog.isDebugEnabled()) { - diagnosticLog.debug("Skip diagnostic request, sender node left " + - "[node=" + nodeId + ", msg=" + msg + ']'); - } - - return; - } - - String resMsg; - - IgniteClosure c; - - try { - c = msg0.unmarshalClosure(ctx); - - resMsg = c.apply(ctx); - } - catch (Exception e) { - U.error(diagnosticLog, "Failed to run diagnostic closure: " + e, e); - - resMsg = "Failed to run diagnostic closure: " + e; - } - - IgniteDiagnosticMessage res = IgniteDiagnosticMessage.createResponse(resMsg, msg0.futureId()); - - try { - ctx.io().sendToGridTopic(node, GridTopic.TOPIC_INTERNAL_DIAGNOSTIC, res, GridIoPolicy.SYSTEM_POOL); - } - catch (ClusterTopologyCheckedException ignore) { - if (diagnosticLog.isDebugEnabled()) { - diagnosticLog.debug("Failed to send diagnostic response, node left " + - "[node=" + nodeId + ", msg=" + msg + ']'); - } - } - catch (IgniteCheckedException e) { - U.error(diagnosticLog, "Failed to send diagnostic response [msg=" + msg0 + "]", e); - } - } - else { - InternalDiagnosticFuture fut = diagnosticFuturesMap().get(msg0.futureId()); - - if (fut != null) - fut.onResponse(msg0); - else - U.warn(diagnosticLog, "Failed to find diagnostic message future [msg=" + msg0 + ']'); - } - } - else - U.warn(diagnosticLog, "Received unexpected message: " + msg); - } - }); - } - - /** - * @return Logger for diagnostic category. - */ - public IgniteLogger diagnosticLog() { - return diagnosticLog; } /** diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java index 09861f303c816..d606cb0390eac 100755 --- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java @@ -60,7 +60,6 @@ import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.events.Event; import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException; -import org.apache.ignite.internal.IgniteDiagnosticAware; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; @@ -240,7 +239,7 @@ */ @IgniteSpiMultipleInstancesSupport(true) @IgniteSpiConsistencyChecked(optional = false) -public class TcpCommunicationSpi extends IgniteSpiAdapter implements CommunicationSpi, IgniteDiagnosticAware { +public class TcpCommunicationSpi extends IgniteSpiAdapter implements CommunicationSpi { /** IPC error message. */ public static final String OUT_OF_RESOURCES_TCP_MSG = "Failed to allocate shared memory segment " + "(switching to TCP, may be slower)."; @@ -4925,7 +4924,7 @@ private class TcpCommunicationSpiMBeanImpl extends IgniteSpiMBeanAdapter impleme /** {@inheritDoc} */ @Override public void dumpStats() { - TcpCommunicationSpi.this.dumpDiagnosticInfo(); + TcpCommunicationSpi.this.dumpStats(); } /** {@inheritDoc} */ From 2101132fb553c83a2936bbd8501dbdb696ddd054 Mon Sep 17 00:00:00 2001 From: mcherkasov Date: Tue, 13 Jun 2017 18:36:54 +0300 Subject: [PATCH 302/311] IGNITE-5364 Remove contention on DataStructure creation or removing --- ...tionKey.java => DataStructureInfoKey.java} | 46 +-- ...heKey.java => DataStructuresCacheKey.java} | 32 +- .../DataStructuresProcessor.java | 373 +++--------------- 3 files changed, 84 insertions(+), 367 deletions(-) rename modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/{CacheDataStructuresConfigurationKey.java => DataStructureInfoKey.java} (50%) rename modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/{CacheDataStructuresCacheKey.java => DataStructuresCacheKey.java} (60%) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/CacheDataStructuresConfigurationKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructureInfoKey.java similarity index 50% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/CacheDataStructuresConfigurationKey.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructureInfoKey.java index f33181160e30e..5d6a337299689 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/CacheDataStructuresConfigurationKey.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructureInfoKey.java @@ -17,48 +17,40 @@ package org.apache.ignite.internal.processors.datastructures; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import org.apache.ignite.internal.processors.cache.GridCacheInternal; +import java.io.Serializable; /** - * Key used to store in utility cache information about all created data structures. + * Key used to store in utility cache information about created data structures. */ -public class CacheDataStructuresConfigurationKey implements GridCacheInternal, Externalizable { +public class DataStructureInfoKey implements Serializable { /** */ private static final long serialVersionUID = 0L; + /** Data structure name. */ + private String name; + /** - * + * @param name Data structure name. */ - public CacheDataStructuresConfigurationKey() { - // No-op. + public DataStructureInfoKey(String name) { + this.name = name; } /** {@inheritDoc} */ - @Override public int hashCode() { - return getClass().getName().hashCode(); - } + @Override public boolean equals(Object o) { + if (this == o) + return true; - /** {@inheritDoc} */ - @Override public boolean equals(Object obj) { - return obj == this || (obj instanceof CacheDataStructuresConfigurationKey); - } + if (o == null || getClass() != o.getClass()) + return false; - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - // No-op. - } + DataStructureInfoKey key2 = (DataStructureInfoKey)o; - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - // No-op. + return name != null ? name.equals(key2.name) : key2.name == null; } /** {@inheritDoc} */ - @Override public String toString() { - return "CacheDataStructuresConfigurationKey []"; + @Override public int hashCode() { + return name != null ? name.hashCode() : 0; } -} \ No newline at end of file +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/CacheDataStructuresCacheKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresCacheKey.java similarity index 60% rename from modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/CacheDataStructuresCacheKey.java rename to modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresCacheKey.java index c7676a556ac26..ef2e7ea2980ba 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/CacheDataStructuresCacheKey.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresCacheKey.java @@ -17,26 +17,15 @@ package org.apache.ignite.internal.processors.datastructures; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import org.apache.ignite.internal.processors.cache.GridCacheInternal; +import java.io.Serializable; /** * Internal key for data structures processor. */ -public class CacheDataStructuresCacheKey implements GridCacheInternal, Externalizable { +public class DataStructuresCacheKey implements Serializable { /** */ private static final long serialVersionUID = 0L; - /** - * - */ - public CacheDataStructuresCacheKey() { - // No-op. - } - /** {@inheritDoc} */ @Override public int hashCode() { return getClass().getName().hashCode(); @@ -44,21 +33,10 @@ public CacheDataStructuresCacheKey() { /** {@inheritDoc} */ @Override public boolean equals(Object obj) { - return obj == this || (obj instanceof CacheDataStructuresCacheKey); - } - - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - // No-op. + return obj == this || (obj instanceof DataStructuresCacheKey); } - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - // No-op. - } - - /** {@inheritDoc} */ @Override public String toString() { - return "CacheDataStructuresCacheKey []"; + return "DataStructuresCacheKey []"; } -} \ No newline at end of file +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java index 369a90970d7fa..2959f061540a8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java @@ -34,7 +34,6 @@ import javax.cache.event.CacheEntryUpdatedListener; import javax.cache.event.EventType; import javax.cache.processor.EntryProcessor; -import javax.cache.processor.EntryProcessorException; import javax.cache.processor.MutableEntry; import org.apache.ignite.IgniteAtomicLong; import org.apache.ignite.IgniteAtomicReference; @@ -74,7 +73,6 @@ import org.apache.ignite.internal.util.typedef.CI1; import org.apache.ignite.internal.util.typedef.CIX1; import org.apache.ignite.internal.util.typedef.CX1; -import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.X; import org.apache.ignite.internal.util.typedef.internal.A; import org.apache.ignite.internal.util.typedef.internal.CU; @@ -106,12 +104,8 @@ */ public final class DataStructuresProcessor extends GridProcessorAdapter implements IgniteChangeGlobalStateSupport { /** */ - public static final CacheDataStructuresConfigurationKey DATA_STRUCTURES_KEY = - new CacheDataStructuresConfigurationKey(); - - /** */ - private static final CacheDataStructuresCacheKey DATA_STRUCTURES_CACHE_KEY = - new CacheDataStructuresCacheKey(); + private static final DataStructuresCacheKey DATA_STRUCTURES_CACHE_KEY = + new DataStructuresCacheKey(); /** Initial capacity. */ private static final int INITIAL_CAPACITY = 10; @@ -156,10 +150,7 @@ public final class DataStructuresProcessor extends GridProcessorAdapter implemen private final AtomicConfiguration atomicCfg; /** */ - private IgniteInternalCache> utilityCache; - - /** */ - private IgniteInternalCache> utilityDataCache; + private IgniteInternalCache utilityCache; /** */ private volatile UUID qryId; @@ -219,9 +210,7 @@ public DataStructuresProcessor(GridKernalContext ctx) { * */ private void onKernalStart0(){ - utilityCache = (IgniteInternalCache)ctx.cache().utilityCache(); - - utilityDataCache = (IgniteInternalCache)ctx.cache().utilityCache(); + utilityCache = ctx.cache().utilityCache(); assert utilityCache != null; @@ -589,15 +578,17 @@ public final IgniteAtomicLong atomicLong(final String name, Class cls) throws IgniteCheckedException { - Map dsMap = utilityCache.get(DATA_STRUCTURES_KEY); + final DataStructureInfoKey dsKey = new DataStructureInfoKey(dsInfo.name); - if (!create && (dsMap == null || !dsMap.containsKey(dsInfo.name))) - return null; + DataStructureInfo cached = utilityCache.get(dsKey); - IgniteCheckedException err = validateDataStructure(dsMap, dsInfo, create); + if (cached != null) { + IgniteCheckedException err = cached.validate(dsInfo, create); - if (err != null) - throw err; + if (err != null) + throw err; + } else if (!create) + return null; final GridCacheInternalKey key = new GridCacheInternalKeyImpl(dsInfo.name); @@ -613,11 +604,16 @@ public final IgniteAtomicLong atomicLong(final String name, return c.applyx(); try (GridNearTxLocal tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { - IgniteCheckedException err = - utilityCache.invoke(DATA_STRUCTURES_KEY, new AddAtomicProcessor(dsInfo)).get(); + DataStructureInfo oldInfo = utilityCache.get(dsKey); - if (err != null) - throw err; + if (oldInfo == null) + utilityCache.put(dsKey, dsInfo); + else { + IgniteCheckedException err = oldInfo.validate(dsInfo, true); + + if (err != null) + throw err; + } T dataStructure = c.applyx(); @@ -670,14 +666,16 @@ private void removeDataStructure(final IgniteOutClosureX c, @Nullable final IgniteInClosureX afterRmv) throws IgniteCheckedException { - Map dsMap = utilityCache.get(DATA_STRUCTURES_KEY); + final DataStructureInfoKey dsKey = new DataStructureInfoKey(name); - if (dsMap == null || !dsMap.containsKey(name)) + DataStructureInfo cached = utilityCache.get(dsKey); + + if (cached == null) return; final DataStructureInfo dsInfo = new DataStructureInfo(name, type, null); - IgniteCheckedException err = validateDataStructure(dsMap, dsInfo, false); + IgniteCheckedException err = cached.validate(dsInfo, false); if (err != null) throw err; @@ -685,20 +683,17 @@ private void removeDataStructure(final IgniteOutClosureX c, retryTopologySafe(new IgniteOutClosureX() { @Override public Void applyx() throws IgniteCheckedException { try (GridNearTxLocal tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { - T2 res = - utilityCache.invoke(DATA_STRUCTURES_KEY, new RemoveDataStructureProcessor(dsInfo)).get(); - - IgniteCheckedException err = res.get2(); - - if (err != null) - throw err; + DataStructureInfo oldInfo = utilityCache.get(dsKey); - assert res.get1() != null; + if (oldInfo == null) + return null; - boolean exists = res.get1(); + IgniteCheckedException err = oldInfo.validate(dsInfo, false); - if (!exists) - return null; + if (err == null) + utilityCache.remove(dsKey); + else + throw err; T rmvInfo = c.applyx(); @@ -985,6 +980,9 @@ private CacheConfiguration cacheConfiguration(CollectionConfiguration cfg, Strin * @throws IgniteCheckedException If failed. */ private String compatibleConfiguration(CollectionConfiguration cfg) throws IgniteCheckedException { + IgniteInternalCache> utilityDataCache = + ctx.cache().utilityCache(); + List caches = utilityDataCache.context().affinityNode() ? utilityDataCache.localPeek(DATA_STRUCTURES_CACHE_KEY, null, null) : utilityDataCache.get(DATA_STRUCTURES_CACHE_KEY); @@ -1063,22 +1061,23 @@ public void removeQueue(final String name, final GridCacheContext cctx) throws I { awaitInitialization(); - Map dsMap = utilityCache.get(DATA_STRUCTURES_KEY); + final DataStructureInfoKey dsKey = new DataStructureInfoKey(dsInfo.name); - if (!create && (dsMap == null || !dsMap.containsKey(dsInfo.name))) - return null; + DataStructureInfo cached = utilityCache.get(dsKey); - IgniteCheckedException err = validateDataStructure(dsMap, dsInfo, create); + if (cached != null) { + IgniteCheckedException err = cached.validate(dsInfo, create); - if (err != null) - throw err; + if (err != null) + throw err; - if (!create) { - DataStructureInfo oldInfo = dsMap.get(dsInfo.name); + } else if (!create) + return null; - assert oldInfo.info instanceof CollectionInfo : oldInfo.info; + if (!create) { + assert cached.info instanceof CollectionInfo : cached.info; - String cacheName = ((CollectionInfo)oldInfo.info).cacheName; + String cacheName = ((CollectionInfo)cached.info).cacheName; GridCacheContext cacheCtx = ctx.cache().getOrStartCache(cacheName).context(); @@ -1088,17 +1087,20 @@ public void removeQueue(final String name, final GridCacheContext cctx) throws I return retryTopologySafe(new IgniteOutClosureX() { @Override public T applyx() throws IgniteCheckedException { try (GridNearTxLocal tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { - T2 res = - utilityCache.invoke(DATA_STRUCTURES_KEY, new AddCollectionProcessor(dsInfo)).get(); + DataStructureInfo oldInfo = utilityCache.get(dsKey); - IgniteCheckedException err = res.get2(); + if (oldInfo == null) + utilityCache.put(dsKey, dsInfo); + else { + IgniteCheckedException err = oldInfo.validate(dsInfo, true); - if (err != null) - throw err; + if (err != null) + throw err; + } - String cacheName = res.get1(); + CollectionInfo colInfo = (CollectionInfo)dsInfo.info; - final GridCacheContext cacheCtx = ctx.cache().internalCache(cacheName).context(); + final GridCacheContext cacheCtx = ctx.cache().internalCache(colInfo.cacheName).context(); T col = c.applyx(cacheCtx); @@ -1128,28 +1130,6 @@ private void awaitInitialization() { } } - /** - * @param dsMap Map with data structure information. - * @param info New data structure information. - * @param create Create flag. - * @return {@link IgniteException} if validation failed. - */ - @Nullable private static IgniteCheckedException validateDataStructure( - @Nullable Map dsMap, - DataStructureInfo info, - boolean create) - { - if (dsMap == null) - return null; - - DataStructureInfo oldInfo = dsMap.get(info.name); - - if (oldInfo != null) - return oldInfo.validate(info, create); - - return null; - } - /** * Gets or creates count down latch. If count down latch is not found in cache, * it is created using provided name and count parameter. @@ -2128,171 +2108,11 @@ public DataStructureInfo() { } } - /** - * - */ - static class AddAtomicProcessor implements - EntryProcessor, IgniteCheckedException>, - Externalizable { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private DataStructureInfo info; - - /** - * @param info Data structure information. - */ - AddAtomicProcessor(DataStructureInfo info) { - assert info != null; - - this.info = info; - } - - /** - * Required by {@link Externalizable}. - */ - public AddAtomicProcessor() { - // No-op. - } - - /** {@inheritDoc} */ - @Override public IgniteCheckedException process( - MutableEntry> entry, - Object... args) - throws EntryProcessorException - { - Map map = entry.getValue(); - - if (map == null) { - map = new HashMap<>(); - - map.put(info.name, info); - - entry.setValue(map); - - return null; - } - - DataStructureInfo oldInfo = map.get(info.name); - - if (oldInfo == null) { - map = new HashMap<>(map); - - map.put(info.name, info); - - entry.setValue(map); - - return null; - } - - return oldInfo.validate(info, true); - } - - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - info.writeExternal(out); - } - - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - info = new DataStructureInfo(); - - info.readExternal(in); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(AddAtomicProcessor.class, this); - } - } - - /** - * - */ - static class AddCollectionProcessor implements - EntryProcessor, - T2>, Externalizable { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private DataStructureInfo info; - - /** - * @param info Data structure information. - */ - AddCollectionProcessor(DataStructureInfo info) { - assert info != null; - assert info.info instanceof CollectionInfo; - - this.info = info; - } - - /** - * Required by {@link Externalizable}. - */ - public AddCollectionProcessor() { - // No-op. - } - - /** {@inheritDoc} */ - @Override public T2 process( - MutableEntry> entry, - Object... args) - { - Map map = entry.getValue(); - - CollectionInfo colInfo = (CollectionInfo)info.info; - - if (map == null) { - map = new HashMap<>(); - - map.put(info.name, info); - - entry.setValue(map); - - return new T2<>(colInfo.cacheName, null); - } - - DataStructureInfo oldInfo = map.get(info.name); - - if (oldInfo == null) { - map = new HashMap<>(map); - - map.put(info.name, info); - - entry.setValue(map); - - return new T2<>(colInfo.cacheName, null); - } - - return new T2<>(colInfo.cacheName, oldInfo.validate(info, true)); - } - - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - info.writeExternal(out); - } - - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - info = new DataStructureInfo(); - - info.readExternal(in); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(AddCollectionProcessor.class, this); - } - } - /** * */ static class AddDataCacheProcessor implements - EntryProcessor, String>, Externalizable { + EntryProcessor, String>, Externalizable { /** Cache name prefix. */ private static final String CACHE_NAME_PREFIX = "datastructures_"; @@ -2318,7 +2138,7 @@ public AddDataCacheProcessor() { /** {@inheritDoc} */ @Override public String process( - MutableEntry> entry, + MutableEntry> entry, Object... args) { List list = entry.getValue(); @@ -2365,77 +2185,4 @@ public AddDataCacheProcessor() { } } - /** - * - */ - static class RemoveDataStructureProcessor implements - EntryProcessor, - T2>, Externalizable { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private DataStructureInfo info; - - /** - * @param info Data structure information. - */ - RemoveDataStructureProcessor(DataStructureInfo info) { - assert info != null; - - this.info = info; - } - - /** - * Required by {@link Externalizable}. - */ - public RemoveDataStructureProcessor() { - // No-op. - } - - /** {@inheritDoc} */ - @Override public T2 process( - MutableEntry> entry, - Object... args) - { - Map map = entry.getValue(); - - if (map == null) - return new T2<>(false, null); - - DataStructureInfo oldInfo = map.get(info.name); - - if (oldInfo == null) - return new T2<>(false, null); - - IgniteCheckedException err = oldInfo.validate(info, false); - - if (err == null) { - map = new HashMap<>(map); - - map.remove(info.name); - - entry.setValue(map); - } - - return new T2<>(true, err); - } - - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - info.writeExternal(out); - } - - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - info = new DataStructureInfo(); - - info.readExternal(in); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(RemoveDataStructureProcessor.class, this); - } - } } From c49daaecc8db6c0d71927cc149274e9b51e37911 Mon Sep 17 00:00:00 2001 From: Ivan Rakov Date: Tue, 13 Jun 2017 18:44:54 +0300 Subject: [PATCH 303/311] ignite-2.1.1 Activate nodes after start --- .../IgnitePdsRecoveryAfterFileCorruptionTest.java | 2 ++ .../db/file/ignitePdsCheckpointSimulationTest.java | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRecoveryAfterFileCorruptionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRecoveryAfterFileCorruptionTest.java index 098ea317aea98..68aadcae7bc4b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRecoveryAfterFileCorruptionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRecoveryAfterFileCorruptionTest.java @@ -169,6 +169,8 @@ public void testPageRecoveryAfterFileCorruption() throws Exception { ig = startGrid(0); + ig.active(true); + checkRestore(ig, pages); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/ignitePdsCheckpointSimulationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/ignitePdsCheckpointSimulationTest.java index b9daabaae0802..2716cdcaabd7d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/ignitePdsCheckpointSimulationTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/file/ignitePdsCheckpointSimulationTest.java @@ -181,6 +181,8 @@ public void testCheckpointSimulationMultiThreaded() throws Exception { ig = startGrid(0); + ig.active(true); + shared = ig.context().cache().context(); dbMgr = (GridCacheDatabaseSharedManager)shared.database(); @@ -253,6 +255,8 @@ public void testGetForInitialWrite() throws Exception { ig = startGrid(0); + ig.active(true); + shared = ig.context().cache().context(); dbMgr = (GridCacheDatabaseSharedManager)shared.database(); @@ -341,6 +345,8 @@ public void testDataWalEntries() throws Exception { ig = startGrid(0); + ig.active(true); + sharedCtx = ig.context().cache().context(); cctx = sharedCtx.cache().cache(cacheName).context(); @@ -465,6 +471,8 @@ public void testPageWalEntries() throws Exception { ig = startGrid(0); + ig.active(true); + sharedCtx = ig.context().cache().context(); db = (GridCacheDatabaseSharedManager)sharedCtx.database(); From 2b030c0dd40db0e0d400fd3652ffb609bcd9ac06 Mon Sep 17 00:00:00 2001 From: Pavel Kovalenko Date: Tue, 13 Jun 2017 19:41:55 +0300 Subject: [PATCH 304/311] ignite-2.1.1 Extract Ignite updates checker to separate class. Fixed GridUpdateNotifier test. --- .../cluster/GridUpdateNotifier.java | 50 +++++++------- .../cluster/HttpIgniteUpdatesChecker.java | 65 +++++++++++++++++++ .../cluster/GridUpdateNotifierSelfTest.java | 10 ++- 3 files changed, 97 insertions(+), 28 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/HttpIgniteUpdatesChecker.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java index b7c824140fe52..eacc42f180738 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java @@ -64,8 +64,8 @@ class GridUpdateNotifier { /** Sleep milliseconds time for worker thread. */ private static final int WORKER_THREAD_SLEEP_TIME = 5000; - /** Url for request version. */ - private final static String UPDATE_NOTIFIER_URL = "https://ignite.run/update_status_ignite-plain-text.php"; + /** Default url for request Ignite updates. */ + private final static String DEFAULT_IGNITE_UPDATES_URL = "https://ignite.run/update_status_ignite-plain-text.php"; /** Grid version. */ private final String ver; @@ -103,6 +103,9 @@ class GridUpdateNotifier { /** Worker thread to process http request. */ private final Thread workerThread; + /** Http client for getting Ignite updates */ + private final HttpIgniteUpdatesChecker updatesChecker; + /** * Creates new notifier with default values. * @@ -111,14 +114,16 @@ class GridUpdateNotifier { * @param gw Kernal gateway. * @param pluginProviders Kernal gateway. * @param reportOnlyNew Whether or not to report only new version. + * @param updatesChecker Service for getting Ignite updates * @throws IgniteCheckedException If failed. */ GridUpdateNotifier(String igniteInstanceName, String ver, GridKernalGateway gw, Collection pluginProviders, - boolean reportOnlyNew) throws IgniteCheckedException { + boolean reportOnlyNew, HttpIgniteUpdatesChecker updatesChecker) throws IgniteCheckedException { try { this.ver = ver; this.igniteInstanceName = igniteInstanceName == null ? "null" : igniteInstanceName; this.gw = gw; + this.updatesChecker = updatesChecker; SB pluginsBuilder = new SB(); @@ -159,6 +164,14 @@ class GridUpdateNotifier { } } + /** + * Creates new notifier with default Ignite updates URL + */ + GridUpdateNotifier(String igniteInstanceName, String ver, GridKernalGateway gw, Collection pluginProviders, + boolean reportOnlyNew) throws IgniteCheckedException { + this(igniteInstanceName, ver, gw, pluginProviders, reportOnlyNew, new HttpIgniteUpdatesChecker(DEFAULT_IGNITE_UPDATES_URL, CHARSET)); + } + /** * Gets system properties. * @@ -313,34 +326,17 @@ private class UpdateChecker extends GridWorker { (!F.isEmpty(vmProps) ? "&vmProps=" + encode(vmProps, CHARSET) : "") + pluginsVers; - URLConnection conn = new URL(UPDATE_NOTIFIER_URL).openConnection(); - if (!isCancelled()) { - conn.setDoOutput(true); - conn.setRequestProperty("Accept-Charset", CHARSET); - conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + CHARSET); - - conn.setConnectTimeout(3000); - conn.setReadTimeout(3000); - try { - try (OutputStream os = conn.getOutputStream()) { - os.write(postParams.getBytes(CHARSET)); - } - - try (InputStream in = conn.getInputStream()) { - if (in == null) - return; - - BufferedReader reader = new BufferedReader(new InputStreamReader(in, CHARSET)); + String updatesResponse = updatesChecker.getUpdates(postParams); - for (String line; (line = reader.readLine()) != null; ) { - if (line.contains("version")) - latestVer = obtainVersionFrom(line); - else if (line.contains("downloadUrl")) - downloadUrl = obtainDownloadUrlFrom(line); - } + String[] lines = updatesResponse.split("\n"); + for (String line : lines) { + if (line.contains("version")) + latestVer = obtainVersionFrom(line); + else if (line.contains("downloadUrl")) + downloadUrl = obtainDownloadUrlFrom(line); } } catch (IOException e) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/HttpIgniteUpdatesChecker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/HttpIgniteUpdatesChecker.java new file mode 100644 index 0000000000000..c052c0997fe2a --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/HttpIgniteUpdatesChecker.java @@ -0,0 +1,65 @@ +package org.apache.ignite.internal.processors.cluster; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.URL; +import java.net.URLConnection; + +/** + * This class is responsible for getting Ignite updates information via HTTP + */ +public class HttpIgniteUpdatesChecker { + /** Url for request updates. */ + private final String url; + + /** Charset for encoding requests/responses */ + private final String charset; + + /** + * Creates new HTTP Ignite updates checker with following parameters + * @param url URL for getting Ignite updates information + * @param charset Charset for encoding + */ + HttpIgniteUpdatesChecker(String url, String charset) { + this.url = url; + this.charset = charset; + } + + /** + * Gets information about Ignite updates via HTTP + * @param updateRequest HTTP Request parameters + * @return Information about Ignite updates separated by line endings + * @throws IOException If HTTP request was failed + */ + public String getUpdates(String updateRequest) throws IOException { + URLConnection conn = new URL(url).openConnection(); + conn.setDoOutput(true); + conn.setRequestProperty("Accept-Charset", charset); + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset); + + conn.setConnectTimeout(3000); + conn.setReadTimeout(3000); + + try (OutputStream os = conn.getOutputStream()) { + os.write(updateRequest.getBytes(charset)); + } + + try (InputStream in = conn.getInputStream()) { + if (in == null) + return null; + + BufferedReader reader = new BufferedReader(new InputStreamReader(in, charset)); + + StringBuilder response = new StringBuilder(); + + for (String line; (line = reader.readLine()) != null; ) { + response.append(line).append('\n'); + } + + return response.toString(); + } + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifierSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifierSelfTest.java index 21b91b6b3c53e..1a20f261550ba 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifierSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifierSelfTest.java @@ -29,6 +29,8 @@ import org.apache.ignite.plugin.PluginProvider; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.apache.ignite.testframework.junits.common.GridCommonTest; +import org.mockito.Matchers; +import org.mockito.Mockito; /** * Update notifier test. @@ -73,8 +75,14 @@ public class GridUpdateNotifierSelfTest extends GridCommonAbstractTest { public void testNotifier() throws Exception { String nodeVer = IgniteProperties.get("ignite.version"); + HttpIgniteUpdatesChecker updatesCheckerMock = Mockito.mock(HttpIgniteUpdatesChecker.class); + + // Return current node version and some other info + Mockito.when(updatesCheckerMock.getUpdates(Matchers.anyString())) + .thenReturn("meta=meta" + "\n" + "version=" + nodeVer + "\n" + "downloadUrl=url"); + GridUpdateNotifier ntf = new GridUpdateNotifier(null, nodeVer, - TEST_GATEWAY, Collections.emptyList(), false); + TEST_GATEWAY, Collections.emptyList(), false, updatesCheckerMock); ntf.checkForNewVersion(log); From b3adc5127dd897dd035224e419b020e6f7a1357d Mon Sep 17 00:00:00 2001 From: oleg-ostanin Date: Tue, 13 Jun 2017 22:28:24 +0300 Subject: [PATCH 305/311] IGNITE-GG-12267 skiped upload ignite-benchmarks and apache-ignite pom.xml to maven repo --- modules/benchmarks/pom.xml | 7 +++++++ pom.xml | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/modules/benchmarks/pom.xml b/modules/benchmarks/pom.xml index b33931ca79e50..af3e05469034f 100644 --- a/modules/benchmarks/pom.xml +++ b/modules/benchmarks/pom.xml @@ -95,6 +95,13 @@ maven-shade-plugin 2.2 + + org.apache.maven.plugins + maven-deploy-plugin + + true + + diff --git a/pom.xml b/pom.xml index 7fa3eef39820b..2b7bba6a30207 100644 --- a/pom.xml +++ b/pom.xml @@ -897,6 +897,13 @@ + + org.apache.maven.plugins + maven-deploy-plugin + + true + + From 4d201dba5a66a3771d4a2d7076d6bc95a0def9fc Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Wed, 14 Jun 2017 11:41:01 +0700 Subject: [PATCH 306/311] IGNITE-4758 - Added missing fields and fixed typos. --- .../configuration/MemoryConfiguration.java | 4 +- .../visor/node/VisorMemoryConfiguration.java | 40 +++++++++++++++---- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/MemoryConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/MemoryConfiguration.java index 2d71e99a4b395..5cf6cb76707e0 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/MemoryConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/MemoryConfiguration.java @@ -241,7 +241,7 @@ public int getConcurrencyLevel() { /** * Sets the number of concurrent segments in Ignite internal page mapping tables. * - * @param concLvl Mapping table oncurrency level. + * @param concLvl Mapping table concurrency level. */ public MemoryConfiguration setConcurrencyLevel(int concLvl) { this.concLvl = concLvl; @@ -252,7 +252,7 @@ public MemoryConfiguration setConcurrencyLevel(int concLvl) { /** * Gets a size for default memory policy overridden by user. * - * @return default memory policy size overridden by user or {@link #DFLT_MEMORY_POLICY_MAX_SIZE} if nothing was specified. + * @return Default memory policy size overridden by user or {@link #DFLT_MEMORY_POLICY_MAX_SIZE} if nothing was specified. */ public long getDefaultMemoryPolicySize() { return dfltMemPlcSize; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryConfiguration.java index b75693869656b..ccb23ac7f39a8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryConfiguration.java @@ -36,8 +36,11 @@ public class VisorMemoryConfiguration extends VisorDataTransferObject { /** */ private static final long serialVersionUID = 0L; + /** Size of a memory chunk reserved for system cache initially. */ + private long sysCacheInitSize; + /** Size of memory for system cache. */ - private long sysCacheMemSize; + private long sysCacheMaxSize; /** Page size. */ private int pageSize; @@ -48,6 +51,9 @@ public class VisorMemoryConfiguration extends VisorDataTransferObject { /** Name of MemoryPolicy to be used as default. */ private String dfltMemPlcName; + /** Size of memory (in bytes) to use for default MemoryPolicy. */ + private long dfltMemPlcSize; + /** Memory policies. */ private List memPlcs; @@ -66,10 +72,12 @@ public VisorMemoryConfiguration() { public VisorMemoryConfiguration(MemoryConfiguration memCfg) { assert memCfg != null; - sysCacheMemSize = memCfg.getSystemCacheInitialSize(); + sysCacheInitSize = memCfg.getSystemCacheInitialSize(); + sysCacheMaxSize = memCfg.getSystemCacheMaxSize(); pageSize = memCfg.getPageSize(); concLvl = memCfg.getConcurrencyLevel(); dfltMemPlcName = memCfg.getDefaultMemoryPolicyName(); + dfltMemPlcSize = memCfg.getDefaultMemoryPolicySize(); MemoryPolicyConfiguration[] plcs = memCfg.getMemoryPolicies(); @@ -89,10 +97,17 @@ public int getConcurrencyLevel() { } /** - * @return Size of memory for system cache. + * @return Initial size of a memory region reserved for system cache. + */ + public long getSystemCacheInitialSize() { + return sysCacheInitSize; + } + + /** + * @return Maximum memory region size reserved for system cache. */ - public long getSystemCacheMemorySize() { - return sysCacheMemSize; + public long getSystemCacheMaxSize() { + return sysCacheMaxSize; } /** @@ -109,6 +124,13 @@ public String getDefaultMemoryPolicyName() { return dfltMemPlcName; } + /** + * @return Default memory policy size. + */ + public long getDefaultMemoryPolicySize() { + return dfltMemPlcSize; + } + /** * @return Collection of MemoryPolicyConfiguration objects. */ @@ -118,19 +140,23 @@ public List getMemoryPolicies() { /** {@inheritDoc} */ @Override protected void writeExternalData(ObjectOutput out) throws IOException { - out.writeLong(sysCacheMemSize); + out.writeLong(sysCacheInitSize); + out.writeLong(sysCacheMaxSize); out.writeInt(pageSize); out.writeInt(concLvl); U.writeString(out, dfltMemPlcName); + out.writeLong(dfltMemPlcSize); U.writeCollection(out, memPlcs); } /** {@inheritDoc} */ @Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException { - sysCacheMemSize = in.readLong(); + sysCacheInitSize = in.readLong(); + sysCacheMaxSize = in.readLong(); pageSize = in.readInt(); concLvl = in.readInt(); dfltMemPlcName = U.readString(in); + dfltMemPlcSize = in.readLong(); memPlcs = U.readList(in); } From 9ebdc1106555d9233d5d328fd6cc71f7a1402490 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Wed, 14 Jun 2017 14:58:20 +0700 Subject: [PATCH 307/311] IGNITE-5239 Web Console show full stack trace on Queries screen. --- .../visor/util/VisorExceptionWrapper.java | 11 ++++++- .../http/jetty/GridJettyObjectMapper.java | 33 +++++++++++++++---- .../app/modules/agent/AgentManager.service.js | 2 +- .../app/modules/sql/sql.controller.js | 18 ++++++---- .../agent/handlers/ClusterListener.java | 4 +++ 5 files changed, 52 insertions(+), 16 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorExceptionWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorExceptionWrapper.java index c47c3c913a854..15e9557004bb2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorExceptionWrapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorExceptionWrapper.java @@ -17,6 +17,8 @@ package org.apache.ignite.internal.visor.util; +import org.apache.ignite.internal.util.typedef.F; + /** * Exception wrapper for safe for transferring to Visor. */ @@ -53,6 +55,13 @@ public VisorExceptionWrapper(Throwable cause) { if (cause.getCause() != null) initCause(new VisorExceptionWrapper(cause.getCause())); + + Throwable[] suppressed = cause.getSuppressed(); + + if (!F.isEmpty(suppressed)) { + for (Throwable sup : suppressed) + addSuppressed(new VisorExceptionWrapper(sup)); + } } /** @@ -78,4 +87,4 @@ public String getClassName() { @Override public String toString() { return (detailMsg != null) ? (clsName + ": " + detailMsg) : clsName; } -} \ No newline at end of file +} diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java index 5a9431551aba5..b4f89f2ae2287 100644 --- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java +++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java @@ -34,6 +34,7 @@ import java.util.Locale; import org.apache.ignite.internal.processors.cache.query.GridCacheSqlIndexMetadata; import org.apache.ignite.internal.processors.cache.query.GridCacheSqlMetadata; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.visor.util.VisorExceptionWrapper; import org.apache.ignite.lang.IgniteBiTuple; import org.apache.ignite.lang.IgniteUuid; @@ -118,10 +119,12 @@ private static class CustomSerializerProvider extends DefaultSerializerProvider /** Custom serializer for {@link Throwable} */ private static final JsonSerializer THROWABLE_SERIALIZER = new JsonSerializer() { - /** {@inheritDoc} */ - @Override public void serialize(Throwable e, JsonGenerator gen, SerializerProvider ser) throws IOException { - gen.writeStartObject(); - + /** + * @param e Exception to write. + * @param gen JSON generator. + * @throws IOException If failed to write. + */ + private void writeException(Throwable e, JsonGenerator gen) throws IOException { if (e instanceof VisorExceptionWrapper) { VisorExceptionWrapper wrapper = (VisorExceptionWrapper)e; @@ -133,15 +136,31 @@ private static class CustomSerializerProvider extends DefaultSerializerProvider if (e.getMessage() != null) gen.writeStringField("message", e.getMessage()); - if (e.getCause() != null) - gen.writeObjectField("cause", e.getCause()); - if (e instanceof SQLException) { SQLException sqlE = (SQLException)e; gen.writeNumberField("errorCode", sqlE.getErrorCode()); gen.writeStringField("SQLState", sqlE.getSQLState()); } + } + + /** {@inheritDoc} */ + @Override public void serialize(Throwable e, JsonGenerator gen, SerializerProvider ser) throws IOException { + gen.writeStartObject(); + + writeException(e, gen); + + if (e.getCause() != null) + gen.writeObjectField("cause", e.getCause()); + + if (!F.isEmpty(e.getSuppressed())) { + gen.writeArrayFieldStart("suppressed"); + + for (Throwable sup : e.getSuppressed()) + gen.writeObject(sup); + + gen.writeEndArray(); + } gen.writeEndObject(); } diff --git a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js index 2fcacd873b927..4cf0b18dd2eb8 100644 --- a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js +++ b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js @@ -559,7 +559,7 @@ export default class IgniteAgentManager { */ queryClose(nid, queryId) { if (this.ignite2x) { - return this.visorTask('queryClose', nid, 'java.util.Map', 'java.util.UUID', 'java.util.Collection', + return this.visorTask('queryCloseX2', nid, 'java.util.Map', 'java.util.UUID', 'java.util.Collection', nid + '=' + queryId); } diff --git a/modules/web-console/frontend/app/modules/sql/sql.controller.js b/modules/web-console/frontend/app/modules/sql/sql.controller.js index c8fcf8f024476..7101a96ac4e51 100644 --- a/modules/web-console/frontend/app/modules/sql/sql.controller.js +++ b/modules/web-console/frontend/app/modules/sql/sql.controller.js @@ -1774,17 +1774,21 @@ export default ['$rootScope', '$scope', '$http', '$q', '$timeout', '$interval', scope.title = 'Error details'; scope.content = []; - let cause = paragraph.error.root; - const tab = '    '; - while (_.nonNil(cause)) { - const clsName = _.isEmpty(cause.className) ? '' : '[' + JavaTypes.shortClassName(cause.className) + '] '; + const addToTrace = (item) => { + if (_.nonNil(item)) { + const clsName = _.isEmpty(item.className) ? '' : '[' + JavaTypes.shortClassName(item.className) + '] '; - scope.content.push((scope.content.length > 0 ? tab : '') + clsName + cause.message); + scope.content.push((scope.content.length > 0 ? tab : '') + clsName + item.message); - cause = cause.cause; - } + addToTrace(item.cause); + + _.forEach(item.suppressed, (sup) => addToTrace(sup)); + } + }; + + addToTrace(paragraph.error.root); // Show a basic modal from a controller $modal({scope, templateUrl: messageTemplateUrl, show: true}); diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/ClusterListener.java b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/ClusterListener.java index 6651f0158d869..b811a2de4929c 100644 --- a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/ClusterListener.java +++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/ClusterListener.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.socket.client.Socket; import io.socket.emitter.Emitter; +import java.net.ConnectException; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -269,6 +270,9 @@ private class WatchTask implements Runnable { clusterDisconnect(); } } + catch (ConnectException ignored) { + clusterDisconnect(); + } catch (Exception e) { log.error("WatchTask failed", e); From 87c6bf2b761f585dee095f9a56641b4741d0db3b Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Wed, 14 Jun 2017 15:04:11 +0700 Subject: [PATCH 308/311] IGNITE-5366 Web Console: Added user notifications. --- .../backend/app/browsersHandler.js | 67 +++++++++++++------ modules/web-console/backend/app/mongo.js | 20 ++++-- modules/web-console/backend/index.js | 6 +- modules/web-console/backend/routes/admin.js | 11 ++- .../backend/services/notifications.js | 52 ++++++++++++++ modules/web-console/frontend/app/app.js | 5 ++ .../user-notifications/controller.js | 55 +++++++++++++++ .../components/user-notifications/index.js | 26 +++++++ .../components/user-notifications/service.js | 58 ++++++++++++++++ .../components/user-notifications/style.scss | 55 +++++++++++++++ .../user-notifications/template.tpl.pug | 42 ++++++++++++ .../web-console-header/component.js | 6 +- .../components/web-console-header/style.scss | 6 +- .../web-console-header/template.pug | 6 +- .../app/directives/btn-ignite-link.js | 27 ++++++++ .../app/modules/agent/AgentManager.service.js | 11 ++- .../app/modules/states/admin.state.js | 14 +++- .../frontend/app/primitives/btn/index.scss | 59 +++++++++++++++- .../frontend/app/primitives/modal/index.scss | 24 ++++--- .../frontend/public/stylesheets/style.scss | 39 ++++++----- .../frontend/views/settings/admin.tpl.pug | 10 ++- 21 files changed, 523 insertions(+), 76 deletions(-) create mode 100644 modules/web-console/backend/services/notifications.js create mode 100644 modules/web-console/frontend/app/components/user-notifications/controller.js create mode 100644 modules/web-console/frontend/app/components/user-notifications/index.js create mode 100644 modules/web-console/frontend/app/components/user-notifications/service.js create mode 100644 modules/web-console/frontend/app/components/user-notifications/style.scss create mode 100644 modules/web-console/frontend/app/components/user-notifications/template.tpl.pug create mode 100644 modules/web-console/frontend/app/directives/btn-ignite-link.js diff --git a/modules/web-console/backend/app/browsersHandler.js b/modules/web-console/backend/app/browsersHandler.js index f5937fe131c75..c4ea5324fa8c6 100644 --- a/modules/web-console/backend/app/browsersHandler.js +++ b/modules/web-console/backend/app/browsersHandler.js @@ -24,15 +24,13 @@ */ module.exports = { implements: 'browsers-handler', - inject: ['require(lodash)', 'require(socket.io)', 'configure', 'errors'] + inject: ['require(lodash)', 'require(socket.io)', 'configure', 'errors', 'mongo'] }; -module.exports.factory = (_, socketio, configure, errors) => { +module.exports.factory = (_, socketio, configure, errors, mongo) => { class BrowserSockets { constructor() { this.sockets = new Map(); - - this.agentHnd = null; } /** @@ -74,7 +72,7 @@ module.exports.factory = (_, socketio, configure, errors) => { } } - return class BrowsersHandler { + class BrowsersHandler { /** * @constructor */ @@ -128,6 +126,22 @@ module.exports.factory = (_, socketio, configure, errors) => { .then((stat) => _.forEach(socks, (sock) => sock.emit('agents:stat', stat))); } + emitNotification(sock) { + sock.emit('user:notifications', this.notification); + } + + /** + * @param {String} notification Notification message. + */ + updateNotification(notification) { + this.notification = notification; + + for (const socks of this._browserSockets.sockets.values()) { + for (const sock of socks) + this.emitNotification(sock); + } + } + executeOnAgent(token, demo, event, ...args) { const cb = _.last(args); @@ -256,29 +270,38 @@ module.exports.factory = (_, socketio, configure, errors) => { if (this.io) throw 'Browser server already started!'; - const io = socketio(server); + mongo.Notifications.findOne().sort('-date').exec() + .then((notification) => { + this.notification = notification; + }) + .then(() => { + const io = socketio(server); - configure.socketio(io); + configure.socketio(io); - // Handle browser connect event. - io.sockets.on('connection', (sock) => { - this._browserSockets.add(sock); + // Handle browser connect event. + io.sockets.on('connection', (sock) => { + this._browserSockets.add(sock); - // Handle browser disconnect event. - sock.on('disconnect', () => { - this._browserSockets.remove(sock); + // Handle browser disconnect event. + sock.on('disconnect', () => { + this._browserSockets.remove(sock); - const demo = sock.request._query.IgniteDemoMode === 'true'; + const demo = sock.request._query.IgniteDemoMode === 'true'; - // Stop demo if latest demo tab for this token. - demo && agentHnd.tryStopDemo(sock); - }); + // Stop demo if latest demo tab for this token. + demo && agentHnd.tryStopDemo(sock); + }); - this.agentListeners(sock); - this.nodeListeners(sock); + this.agentListeners(sock); + this.nodeListeners(sock); - this.agentStats(sock.request.user.token, [sock]); - }); + this.agentStats(sock.request.user.token, [sock]); + this.emitNotification(sock); + }); + }); } - }; + } + + return new BrowsersHandler(); }; diff --git a/modules/web-console/backend/app/mongo.js b/modules/web-console/backend/app/mongo.js index e3ae30da8a6a2..d2968fb8c8457 100644 --- a/modules/web-console/backend/app/mongo.js +++ b/modules/web-console/backend/app/mongo.js @@ -1009,11 +1009,6 @@ module.exports.factory = function(passportMongo, settings, pluginMongo, mongoose // Define Notebook model. result.Notebook = mongoose.model('Notebook', NotebookSchema); - result.handleError = function(res, err) { - // TODO IGNITE-843 Send error to admin - res.status(err.code || 500).send(err.message); - }; - // Define Activities schema. const ActivitiesSchema = new Schema({ owner: {type: ObjectId, ref: 'Account'}, @@ -1028,11 +1023,26 @@ module.exports.factory = function(passportMongo, settings, pluginMongo, mongoose // Define Activities model. result.Activities = mongoose.model('Activities', ActivitiesSchema); + // Define Notifications schema. + const NotificationsSchema = new Schema({ + owner: {type: ObjectId, ref: 'Account'}, + date: Date, + message: String + }); + + // Define Notifications model. + result.Notifications = mongoose.model('Notifications', NotificationsSchema); + // Registering the routes of all plugin modules for (const name in pluginMongo) { if (pluginMongo.hasOwnProperty(name)) pluginMongo[name].register(mongoose, result); } + result.handleError = function(res, err) { + // TODO IGNITE-843 Send error to admin + res.status(err.code || 500).send(err.message); + }; + return result; }; diff --git a/modules/web-console/backend/index.js b/modules/web-console/backend/index.js index 7db51c89f8179..85e137cd32d98 100644 --- a/modules/web-console/backend/index.js +++ b/modules/web-console/backend/index.js @@ -77,9 +77,9 @@ const _onListening = (addr) => { * @param settings * @param {ApiServer} apiSrv * @param {AgentsHandler} agentsHnd - * @param {BrowsersHandler} BrowsersHandler + * @param {BrowsersHandler} browsersHnd */ -const init = ([settings, apiSrv, agentsHnd, BrowsersHandler]) => { +const init = ([settings, apiSrv, agentsHnd, browsersHnd]) => { // Start rest server. const srv = settings.server.SSLOptions ? https.createServer(settings.server.SSLOptions) : http.createServer(); @@ -90,8 +90,6 @@ const init = ([settings, apiSrv, agentsHnd, BrowsersHandler]) => { apiSrv.attach(srv); - const browsersHnd = new BrowsersHandler(); - agentsHnd.attach(srv, browsersHnd); browsersHnd.attach(srv, agentsHnd); diff --git a/modules/web-console/backend/routes/admin.js b/modules/web-console/backend/routes/admin.js index 5b0896ac69437..c00b17a0e1901 100644 --- a/modules/web-console/backend/routes/admin.js +++ b/modules/web-console/backend/routes/admin.js @@ -21,7 +21,7 @@ module.exports = { implements: 'routes/admin', - inject: ['require(lodash)', 'require(express)', 'settings', 'mongo', 'services/spaces', 'services/mails', 'services/sessions', 'services/users'] + inject: ['require(lodash)', 'require(express)', 'settings', 'mongo', 'services/spaces', 'services/mails', 'services/sessions', 'services/users', 'services/notifications'] }; /** @@ -35,7 +35,7 @@ module.exports = { * @param {UsersService} usersService * @returns {Promise} */ -module.exports.factory = function(_, express, settings, mongo, spacesService, mailsService, sessionsService, usersService) { +module.exports.factory = function(_, express, settings, mongo, spacesService, mailsService, sessionsService, usersService, notificationsService) { return new Promise((factoryResolve) => { const router = new express.Router(); @@ -78,6 +78,13 @@ module.exports.factory = function(_, express, settings, mongo, spacesService, ma .catch(res.api.error); }); + // Revert to your identity. + router.put('/notifications', (req, res) => { + notificationsService.merge(req.user._id, req.body.message) + .then(res.api.ok) + .catch(res.api.error); + }); + factoryResolve(router); }); }; diff --git a/modules/web-console/backend/services/notifications.js b/modules/web-console/backend/services/notifications.js new file mode 100644 index 0000000000000..f1860e759ce2c --- /dev/null +++ b/modules/web-console/backend/services/notifications.js @@ -0,0 +1,52 @@ +/* + * 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. + */ + +'use strict'; + +// Fire me up! + +module.exports = { + implements: 'services/notifications', + inject: ['require(lodash)', 'mongo', 'browsers-handler'] +}; + +/** + * @param _ + * @param mongo + * @param browsersHnd + * @returns {NotificationsService} + */ +module.exports.factory = (_, mongo, browsersHnd) => { + class NotificationsService { + /** + * Update notifications. + * + * @param {String} owner - User ID + * @param {String} message - Message to users. + * @param {Date} [date] - Optional date to save in notifications. + * @returns {Promise.} that resolve activity + */ + static merge(owner, message, date = new Date()) { + return mongo.Notifications.create({owner, message, date}) + .then(({message, date}) => { + browsersHnd.updateNotification({message, date}); + }); + } + } + + return NotificationsService; +}; diff --git a/modules/web-console/frontend/app/app.js b/modules/web-console/frontend/app/app.js index ff089bb902cb9..3bfe822ceef64 100644 --- a/modules/web-console/frontend/app/app.js +++ b/modules/web-console/frontend/app/app.js @@ -75,6 +75,7 @@ import igniteUiAcePom from './directives/ui-ace-pom/ui-ace-pom.directive'; import igniteUiAceDocker from './directives/ui-ace-docker/ui-ace-docker.directive'; import igniteUiAceTabs from './directives/ui-ace-tabs.directive'; import igniteRetainSelection from './directives/retain-selection.directive'; +import btnIgniteLink from './directives/btn-ignite-link'; // Services. import ChartColors from './services/ChartColors.service'; @@ -116,6 +117,7 @@ import webConsoleHeader from './components/web-console-header'; import webConsoleFooter from './components/web-console-footer'; import igniteIcon from './components/ignite-icon'; import versionPicker from './components/version-picker'; +import userNotifications from './components/user-notifications'; // Inject external modules. import IgniteModules from 'IgniteModules/index'; @@ -177,6 +179,7 @@ angular webConsoleFooter.name, igniteIcon.name, versionPicker.name, + userNotifications.name, // Ignite modules. IgniteModules.name ]) @@ -204,6 +207,8 @@ angular .directive('igniteRestoreInputFocus', igniteRestoreInputFocus) .directive('igniteListOfRegisteredUsers', igniteListOfRegisteredUsers) .directive('igniteClusterSelect', clusterSelect) +.directive('btnIgniteLinkDashedSuccess', btnIgniteLink) +.directive('btnIgniteLinkDashedSecondary', btnIgniteLink) // Services. .service('IgniteErrorPopover', ErrorPopover) .service('JavaTypes', JavaTypes) diff --git a/modules/web-console/frontend/app/components/user-notifications/controller.js b/modules/web-console/frontend/app/components/user-notifications/controller.js new file mode 100644 index 0000000000000..be63c68f279e7 --- /dev/null +++ b/modules/web-console/frontend/app/components/user-notifications/controller.js @@ -0,0 +1,55 @@ +/* + * 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. + */ + +export default class UserNotificationsController { + static $inject = ['deferred', 'message']; + + constructor(deferred, message) { + this.deferred = deferred; + this.message = message; + } + + onLoad(editor) { + editor.setHighlightActiveLine(false); + editor.setAutoScrollEditorIntoView(true); + editor.$blockScrolling = Infinity; + + // TODO IGNITE-5366 Ace hangs when it reaches max lines. + // const session = editor.getSession(); + // + // session.setUseWrapMode(true); + // session.setOption('indentedSoftWrap', false); + + const renderer = editor.renderer; + + renderer.setPadding(7); + renderer.setScrollMargin(7, 12); + renderer.setHighlightGutterLine(false); + renderer.setShowPrintMargin(false); + renderer.setShowGutter(false); + renderer.setOption('fontFamily', 'monospace'); + renderer.setOption('fontSize', '14px'); + renderer.setOption('minLines', '3'); + renderer.setOption('maxLines', '5'); + + editor.focus(); + } + + submit() { + this.deferred.resolve(this.message); + } +} diff --git a/modules/web-console/frontend/app/components/user-notifications/index.js b/modules/web-console/frontend/app/components/user-notifications/index.js new file mode 100644 index 0000000000000..633890fa55d26 --- /dev/null +++ b/modules/web-console/frontend/app/components/user-notifications/index.js @@ -0,0 +1,26 @@ +/* + * 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. + */ + +import angular from 'angular'; + +import userNotifications from './service'; + +import './style.scss'; + +export default angular + .module('ignite-console.user-notifications', []) + .service('UserNotifications', userNotifications); diff --git a/modules/web-console/frontend/app/components/user-notifications/service.js b/modules/web-console/frontend/app/components/user-notifications/service.js new file mode 100644 index 0000000000000..576060205166f --- /dev/null +++ b/modules/web-console/frontend/app/components/user-notifications/service.js @@ -0,0 +1,58 @@ +/* + * 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. + */ + +import controller from './controller'; +import templateUrl from './template.tpl.pug'; + +export default class UserNotificationsService { + static $inject = ['$http', '$modal', '$q', 'IgniteMessages']; + + constructor($http, $modal, $q, Messages) { + Object.assign(this, {$http, $modal, $q, Messages}); + + this.message = null; + } + + set notification(notification) { + this.message = _.get(notification, 'message'); + } + + editor() { + const deferred = this.$q.defer(); + + const modal = this.$modal({ + templateUrl, + resolve: { + deferred: () => deferred, + message: () => this.message + }, + controller, + controllerAs: '$ctrl' + }); + + const modalHide = modal.hide; + + modal.hide = () => deferred.reject('cancelled'); + + return deferred.promise + .finally(modalHide) + .then((newMsg) => { + this.$http.put('/api/v1/admin/notifications', {message: newMsg}) + .catch((err) => this.Messages.showError(err)); + }); + } +} diff --git a/modules/web-console/frontend/app/components/user-notifications/style.scss b/modules/web-console/frontend/app/components/user-notifications/style.scss new file mode 100644 index 0000000000000..269cde679c395 --- /dev/null +++ b/modules/web-console/frontend/app/components/user-notifications/style.scss @@ -0,0 +1,55 @@ +/* + * 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. + */ + +@import 'public/stylesheets/variables'; + +$disabled-color: #c5c5c5; + +.modal-body { + p { + margin-bottom: 25px; + } + + > .ignite-form-field { + display: flex; + flex-direction: column; + + > .ignite-form-field__label { + color: $gray-light; + font-size: 12px; + + margin-left: 10px; + margin-bottom: 5px; + } + + > .ignite-form-field__control { + width: 100%; + + .ace_editor { + border-radius: 4px; + box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5); + border: solid 1px $disabled-color; + + margin: 0; + + .ace_content { + padding-left: 2px; + } + } + } + } +} \ No newline at end of file diff --git a/modules/web-console/frontend/app/components/user-notifications/template.tpl.pug b/modules/web-console/frontend/app/components/user-notifications/template.tpl.pug new file mode 100644 index 0000000000000..78dcbfb4e7cf2 --- /dev/null +++ b/modules/web-console/frontend/app/components/user-notifications/template.tpl.pug @@ -0,0 +1,42 @@ +//- + 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. + +include /app/helpers/jade/mixins + +.modal.modal--ignite(tabindex='-1' role='dialog') + .modal-dialog + .modal-content + .modal-header + h4.modal-title + svg(ignite-icon='gear') + | Set user notifications + button.close(type='button' aria-label='Close' ng-click='$hide()') + svg(ignite-icon='cross') + .modal-body.modal-body-with-scroll(id='user-notifications-dialog') + p + | Enter the text, which will show for all users of the Web Console about an important event or + | warning about ongoing technical works. It will appear #[b on the yellow bar] in the header. + + .ignite-form-field + +ignite-form-field__label('Your notification:', 'notification', true) + + .ignite-form-field__control + .input-tip + div(ignite-ace='{onLoad: $ctrl.onLoad, mode: "xml"}' ng-trim='true' ng-model='$ctrl.message') + + .modal-footer + button.btn-ignite.btn-ignite--link-success(id='btn-cancel' ng-click='$hide()') Cancel + button.btn-ignite.btn-ignite--success(id='btn-submit' ng-click='$ctrl.submit()') Submit diff --git a/modules/web-console/frontend/app/components/web-console-header/component.js b/modules/web-console/frontend/app/components/web-console-header/component.js index 364037fd3b4c4..d4c5c4bd65bbd 100644 --- a/modules/web-console/frontend/app/components/web-console-header/component.js +++ b/modules/web-console/frontend/app/components/web-console-header/component.js @@ -21,7 +21,7 @@ import './style.scss'; export default { template, controller: class { - static $inject = ['$rootScope', '$scope', '$state', 'IgniteBranding']; + static $inject = ['$rootScope', '$scope', '$state', 'IgniteBranding', 'UserNotifications']; static webAgentDownloadVisibleStates = [ 'base.configuration', @@ -29,8 +29,8 @@ export default { 'base.settings' ]; - constructor($rootScope, $scope, $state, branding) { - Object.assign(this, {$rootScope, $scope, $state, branding}); + constructor($rootScope, $scope, $state, branding, UserNotifications) { + Object.assign(this, {$rootScope, $scope, $state, branding, UserNotifications}); } $onInit() { diff --git a/modules/web-console/frontend/app/components/web-console-header/style.scss b/modules/web-console/frontend/app/components/web-console-header/style.scss index 00ef141f0fcc8..deef5a89b7899 100644 --- a/modules/web-console/frontend/app/components/web-console-header/style.scss +++ b/modules/web-console/frontend/app/components/web-console-header/style.scss @@ -123,18 +123,18 @@ web-console-header { } } - .wch-revert-identity { + .wch-notification { font-size: $font-size-base; line-height: 16px; padding: 4px; background: $brand-warning; text-align: center; - .link-info { + a { color: $brand-info; } - &+.wch-revert-identity { + &+.wch-notification { border-top: 1px solid darken($brand-warning, 15%); } } diff --git a/modules/web-console/frontend/app/components/web-console-header/template.pug b/modules/web-console/frontend/app/components/web-console-header/template.pug index fa1a9fe66c72e..3971cec8ddd85 100644 --- a/modules/web-console/frontend/app/components/web-console-header/template.pug +++ b/modules/web-console/frontend/app/components/web-console-header/template.pug @@ -14,8 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. -.wch-revert-identity(ng-show='$ctrl.$rootScope.user.becomeUsed') - | You are currently viewing user #[strong {{$ctrl.$rootScope.user.firstName}} {{$ctrl.$rootScope.user.lastName}}] as administrator. #[a.link-info(ng-click='$ctrl.$rootScope.revertIdentity()') Revert to your identity?] +.wch-notification(ng-show='$ctrl.UserNotifications.message' ng-bind-html='$ctrl.UserNotifications.message') + +.wch-notification(ng-show='$ctrl.$rootScope.user.becomeUsed') + | You are currently viewing user #[strong {{$ctrl.$rootScope.user.firstName}} {{$ctrl.$rootScope.user.lastName}}] as administrator. #[a(ng-click='$ctrl.$rootScope.revertIdentity()') Revert to your identity?] .wch-content.container a(ui-sref='signin') diff --git a/modules/web-console/frontend/app/directives/btn-ignite-link.js b/modules/web-console/frontend/app/directives/btn-ignite-link.js new file mode 100644 index 0000000000000..5180c62b1bc9b --- /dev/null +++ b/modules/web-console/frontend/app/directives/btn-ignite-link.js @@ -0,0 +1,27 @@ +/* + * 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. + */ + +export default () => ({ + restrict: 'C', + link: (scope, $element) => { + $element.contents() + .filter(function() { + return this.nodeType === 3; + }) + .wrap(''); + } +}); diff --git a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js index 4cf0b18dd2eb8..e14b57a0f270e 100644 --- a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js +++ b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js @@ -28,9 +28,9 @@ const State = { }; export default class IgniteAgentManager { - static $inject = ['$rootScope', '$q', 'igniteSocketFactory', 'AgentModal']; + static $inject = ['$rootScope', '$q', 'igniteSocketFactory', 'AgentModal', 'UserNotifications']; - constructor($root, $q, socketFactory, AgentModal) { + constructor($root, $q, socketFactory, AgentModal, UserNotifications) { this.$root = $root; this.$q = $q; this.socketFactory = socketFactory; @@ -40,6 +40,11 @@ export default class IgniteAgentManager { */ this.AgentModal = AgentModal; + /** + * @type {UserNotifications} + */ + this.UserNotifications = UserNotifications; + this.promises = new Set(); $root.$on('$stateChangeSuccess', () => this.stopWatch()); @@ -131,6 +136,8 @@ export default class IgniteAgentManager { else self.connectionState.next(State.CLUSTER_DISCONNECTED); }); + + self.socket.on('user:notifications', (notification) => this.UserNotifications.notification = notification); } saveToStorage(cluster = this.cluster) { diff --git a/modules/web-console/frontend/app/modules/states/admin.state.js b/modules/web-console/frontend/app/modules/states/admin.state.js index cbd43f5e3809c..7189508b574bb 100644 --- a/modules/web-console/frontend/app/modules/states/admin.state.js +++ b/modules/web-console/frontend/app/modules/states/admin.state.js @@ -34,7 +34,19 @@ angular template }, '@base.settings.admin': { - templateUrl + templateUrl, + controller: class { + static $inject = ['UserNotifications']; + + constructor(UserNotifications) { + this.UserNotifications = UserNotifications; + } + + changeUserNotifications() { + this.UserNotifications.editor(); + } + }, + controllerAs: 'ctrl' } }, // templateUrl, diff --git a/modules/web-console/frontend/app/primitives/btn/index.scss b/modules/web-console/frontend/app/primitives/btn/index.scss index bba4eccc84f53..d0969f3c316b6 100644 --- a/modules/web-console/frontend/app/primitives/btn/index.scss +++ b/modules/web-console/frontend/app/primitives/btn/index.scss @@ -182,11 +182,66 @@ } } - @include active-focus-shadows($active: ()); - &[disabled] { color: change-color($accent-color, $saturation: 57%, $lightness: 68%); } + +} + +@mixin btn-ignite--link-dashed( + $color, + $activeHover, + $disabled +) { + background: transparent; + color: $color; + + span { + background: + linear-gradient(to right, $color, transparent), + linear-gradient(to right, $color 70%, transparent 0%) repeat-x left bottom; + background-size: 0, 8px 1px, 0, 0; + } + + &:hover, &.hover, + &:active, &.active { + &:not([disabled]) { + color: $activeHover; + + span { + background: + linear-gradient(to right, $activeHover, transparent), + linear-gradient(to right, $activeHover 70%, transparent 0%) repeat-x left bottom; + background-size: 0, 8px 1px, 0, 0; + } + } + } + + &[disabled] { + color: $disabled; + + span { + background: + linear-gradient(to right, $disabled, transparent), + linear-gradient(to right, $disabled 70%, transparent 0%) repeat-x left bottom; + background-size: 0, 8px 1px, 0, 0; + } + } + + @include active-focus-shadows($active: ()); +} + +.btn-ignite--link-dashed-success { + $color: $ignite-brand-success; + $activeHover: change-color($color, $lightness: 26%); + $disabled: change-color($color, $saturation: 57%, $lightness: 68%); + + @include btn-ignite--link-dashed($color, $activeHover, $disabled); +} + +.btn-ignite--link-dashed-secondary { + $activeHover: change-color($ignite-brand-success, $lightness: 26%); + @include btn-ignite--link-dashed($text-color, $activeHover, $gray-light); } .btn-ignite--secondary { diff --git a/modules/web-console/frontend/app/primitives/modal/index.scss b/modules/web-console/frontend/app/primitives/modal/index.scss index e223504fd2c81..7dc30d6af6007 100644 --- a/modules/web-console/frontend/app/primitives/modal/index.scss +++ b/modules/web-console/frontend/app/primitives/modal/index.scss @@ -100,23 +100,21 @@ margin: 0; } -.modal.center .modal-dialog { - position: fixed; - top: 50%; - left: 50%; - -webkit-transform: translateX(-50%) translateY(-50%); - transform: translateX(-50%) translateY(-50%); -} - .modal--ignite { + font-family: Roboto; + + &.center { + display: flex !important; + flex-direction: column; + justify-content: center; + } + .close { position: absolute; top: 20px; right: 20px; display: block; - width: 12px; - height: 12px; opacity: 1; background: none; @@ -159,7 +157,7 @@ margin-top: 1px; margin-bottom: -1px; - i { + svg, i { margin-right: 8px; color: #424242; @@ -177,6 +175,10 @@ padding: 10px 20px; border-top: 1px solid $table-border-color; + + button + button { + margin-left: 20px; + } } } } diff --git a/modules/web-console/frontend/public/stylesheets/style.scss b/modules/web-console/frontend/public/stylesheets/style.scss index 3ecb30050c581..df8de20678296 100644 --- a/modules/web-console/frontend/public/stylesheets/style.scss +++ b/modules/web-console/frontend/public/stylesheets/style.scss @@ -545,14 +545,6 @@ button.form-control { .sql-editor { padding: 5px 0; - .ace_cursor { - opacity: 1; - } - - .ace_hidden-cursors { - opacity: 1; - } - .ace_gutter-cell, .ace_folding-enabled > .ace_gutter-cell { padding-right: 5px; } @@ -1526,14 +1518,6 @@ th[st-sort] { padding-left: 5px; } -.ace_hidden-cursors { - opacity: 0; -} - -.ace_cursor { - opacity: 0; -} - .ace_editor { margin: 10px 5px 10px 0; @@ -1548,6 +1532,16 @@ th[st-sort] { } } +.preview-panel { + .ace_hidden-cursors { + opacity: 0; + } + + .ace_cursor { + opacity: 0; + } +} + .preview-highlight-1 { position: absolute; background-color: #f7faff; @@ -2201,6 +2195,19 @@ html,body,.splash-screen { } .admin-page { + .docs-header { + display: flex; + flex-direction: row; + align-items: baseline; + + margin: 40px 0 20px 0; + + h1 { + font-size: 24px; + margin: 0 10px 0 0; + } + } + .panel-heading { height: 38px; diff --git a/modules/web-console/frontend/views/settings/admin.tpl.pug b/modules/web-console/frontend/views/settings/admin.tpl.pug index 3c49eb68adbfa..3dc7bfa2d51fb 100644 --- a/modules/web-console/frontend/views/settings/admin.tpl.pug +++ b/modules/web-console/frontend/views/settings/admin.tpl.pug @@ -14,11 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. -.admin-page.row +.admin-page .docs-content - header + .docs-header h1 Admin panel + + button.btn-ignite.btn-ignite--link-dashed-secondary(ng-click='ctrl.changeUserNotifications()') + svg.icon-left(ignite-icon='gear') + | Set user notifications .docs-body .row .col-xs-12 - ignite-list-of-registered-users(data-options='ctrl.data') + ignite-list-of-registered-users From b7a19ae7b54f05a0f2fe8223397e59f34b4f63cf Mon Sep 17 00:00:00 2001 From: Vasiliy Sisko Date: Wed, 14 Jun 2017 15:32:00 +0700 Subject: [PATCH 309/311] IGNITE-5240 Fixed repository name. --- modules/web-console/docker/compose/docker-compose.yml | 4 ++-- .../docker/compose/frontend/DockerfileBuild | 2 +- modules/web-console/docker/standalone/Dockerfile | 10 ++++++---- .../web-console/docker/standalone/docker-compose.yml | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/web-console/docker/compose/docker-compose.yml b/modules/web-console/docker/compose/docker-compose.yml index 8b9b86ac4e4d0..89ffe98b399b8 100644 --- a/modules/web-console/docker/compose/docker-compose.yml +++ b/modules/web-console/docker/compose/docker-compose.yml @@ -22,7 +22,7 @@ mongodb: - ./data/mongo:/data/db backend: - image: ignite/web-console-backend + image: apacheignite/web-console-backend links: # Link mongodb container as with mongodb hostname. - mongodb:mongodb @@ -44,7 +44,7 @@ backend: - mail_auth_pass= frontend: - image: ignite/web-console-frontend + image: apacheignite/web-console-frontend links: # Link backend container to proxy backend requests throught nginx container. - backend:backend diff --git a/modules/web-console/docker/compose/frontend/DockerfileBuild b/modules/web-console/docker/compose/frontend/DockerfileBuild index 2d61f4ca2c98a..90c56c829cbf3 100644 --- a/modules/web-console/docker/compose/frontend/DockerfileBuild +++ b/modules/web-console/docker/compose/frontend/DockerfileBuild @@ -23,7 +23,7 @@ WORKDIR /opt/web-console-frontend COPY src . -RUN npm install --no-optional +RUN npm install --no-optional --prod VOLUME /opt/web-console-frontend/build diff --git a/modules/web-console/docker/standalone/Dockerfile b/modules/web-console/docker/standalone/Dockerfile index 0bcd07d18f1a7..30c8b3211bb90 100644 --- a/modules/web-console/docker/standalone/Dockerfile +++ b/modules/web-console/docker/standalone/Dockerfile @@ -25,15 +25,17 @@ RUN set -ex && \ for key in \ 9554F04D7259F04124DE6B476D5A82AC7E37093B \ 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ - 0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \ FD3A5288F042B6850C66B31F09FE44734EB7990E \ 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ DD8F2338BAE7501E3DD5AC78C273792F7D83545D \ B9AE9905FFD7803F25714661B63B535A4C206CA9 \ C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ + 56730D5401028683275BD23C23EFEFE93C4CFFFE \ ; do \ - gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ - done + gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" || \ + gpg --keyserver pgp.mit.edu --recv-keys "$key" || \ + gpg --keyserver keyserver.pgp.com --recv-keys "$key" ; \ + done RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 && \ echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list @@ -61,7 +63,7 @@ WORKDIR /opt/web-console COPY build . # Install node modules. -RUN cd /opt/web-console/frontend && npm install --no-optional && npm run build +RUN cd /opt/web-console/frontend && npm install --no-optional --prod && npm run build RUN cd /opt/web-console/backend && npm install --only=production --no-optional # Returns to base path. diff --git a/modules/web-console/docker/standalone/docker-compose.yml b/modules/web-console/docker/standalone/docker-compose.yml index eb59e8a880f61..c6b73d9a1d018 100644 --- a/modules/web-console/docker/standalone/docker-compose.yml +++ b/modules/web-console/docker/standalone/docker-compose.yml @@ -16,7 +16,7 @@ # webconsole: - image: ignite/web-console-standalone + image: apacheignite/web-console-standalone ports: - 80:80 restart: always From 42c04ddb17f560f4120636431da20e6e0b1422a9 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Wed, 14 Jun 2017 15:46:40 +0700 Subject: [PATCH 310/311] IGNITE-5481 Reworked rebalance detection. --- .../internal/visor/cache/VisorCache.java | 90 ++---------------- .../cache/VisorCacheAggregatedMetrics.java | 2 +- .../visor/cache/VisorCacheMetrics.java | 92 +++++++++++++++++-- .../visor/debug/VisorThreadMonitorInfo.java | 1 + .../visor/event/VisorGridDeploymentEvent.java | 1 + .../visor/event/VisorGridDiscoveryEvent.java | 1 + .../visor/event/VisorGridJobEvent.java | 1 + .../visor/event/VisorGridTaskEvent.java | 1 + .../visor/node/VisorNodeDataCollectorJob.java | 2 +- .../node/VisorNodeDataCollectorTaskArg.java | 22 ----- .../commands/cache/VisorCacheCommand.scala | 4 +- 11 files changed, 97 insertions(+), 120 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java index 4a35795f5809d..e1d3a8737c4ee 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java @@ -28,14 +28,10 @@ import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; -import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology; -import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.visor.VisorDataTransferObject; import org.apache.ignite.lang.IgniteUuid; -import org.jetbrains.annotations.Nullable; /** * Data transfer object for {@link IgniteCache}. @@ -48,9 +44,6 @@ public class VisorCache extends VisorDataTransferObject { private static final CachePeekMode[] PEEK_NO_NEAR = new CachePeekMode[] {CachePeekMode.PRIMARY, CachePeekMode.BACKUP}; - /** Default cache size sampling. */ - private static final int DFLT_CACHE_SIZE_SAMPLING = 10; - /** Cache name. */ private String name; @@ -90,9 +83,6 @@ public class VisorCache extends VisorDataTransferObject { /** Cache metrics. */ private VisorCacheMetrics metrics; - /** Cache partitions states. */ - private VisorPartitionMap parts; - /** * Create data transfer object for given cache. */ @@ -104,86 +94,27 @@ public VisorCache() { * Create data transfer object for given cache. * * @param ca Internal cache. - * @param sample Sample size. * @throws IgniteCheckedException If failed to create data transfer object. */ - public VisorCache(IgniteEx ignite, GridCacheAdapter ca, int sample) throws IgniteCheckedException { + public VisorCache(IgniteEx ignite, GridCacheAdapter ca) throws IgniteCheckedException { assert ca != null; - name = ca.name(); - GridCacheContext cctx = ca.context(); - CacheConfiguration cfg = ca.configuration(); - mode = cfg.getCacheMode(); - - boolean partitioned = (mode == CacheMode.PARTITIONED || mode == CacheMode.REPLICATED) - && cctx.affinityNode(); - - if (partitioned) { - GridDhtCacheAdapter dca = null; - - if (ca instanceof GridNearCacheAdapter) - dca = ((GridNearCacheAdapter)ca).dht(); - else if (ca instanceof GridDhtCacheAdapter) - dca = (GridDhtCacheAdapter)ca; - - if (dca != null) { - GridDhtPartitionTopology top = dca.topology(); - - if (cfg.getCacheMode() != CacheMode.LOCAL && cfg.getBackups() > 0) - parts = new VisorPartitionMap(top.localPartitionMap()); - } - } - + name = ca.name(); dynamicDeploymentId = cctx.dynamicDeploymentId(); + mode = cfg.getCacheMode(); size = ca.localSizeLong(PEEK_NO_NEAR); primarySize = ca.primarySizeLong(); - backupSize = size - primarySize; // This is backup size. + backupSize = size - primarySize; nearSize = ca.nearSize(); - onHeapEntriesCnt = 0; // TODO GG-11148 Need to rename on ON-heap entries count, see partitions = ca.affinity().partitions(); - metrics = new VisorCacheMetrics(ignite, name); // TODO: GG-11683 Move to separate thing near = cctx.isNear(); - estimateMemorySize(ignite, ca, sample); - } + onHeapEntriesCnt = 0; // TODO GG-11148 How to get this metric? - /** - * Estimate memory size used by cache. - * - * @param ca Cache adapter. - * @param sample Sample size. - */ - protected void estimateMemorySize(IgniteEx ignite, GridCacheAdapter ca, int sample) { - /* TODO Fix after GG-11739 implemented. - int size = ca.size(); - - Iterable set = ca.context().isNear() - ? ((GridNearCacheAdapter)ca).dht().entries() - : ca.entries(); - - long memSz = 0; - - Iterator it = set.iterator(); - - int sz = sample > 0 ? sample : DFLT_CACHE_SIZE_SAMPLING; - - int cnt = 0; - - while (it.hasNext() && cnt < sz) { - memSz += it.next().memorySize(); - - cnt++; - } - - if (cnt > 0) - memSz = (long)((double)memSz / cnt * size); - - memorySize = memSz; - */ - memorySize = 0; + metrics = new VisorCacheMetrics(ignite, name); } /** @@ -301,13 +232,6 @@ public VisorCacheMetrics getMetrics() { return metrics; } - /** - * @return Cache partitions states. - */ - @Nullable public VisorPartitionMap getPartitionMap() { - return parts; - } - /** * @return {@code true} if cache has near cache. */ @@ -330,7 +254,6 @@ public boolean isNear() { out.writeInt(partitions); out.writeBoolean(near); out.writeObject(metrics); - out.writeObject(parts); } /** {@inheritDoc} */ @@ -348,7 +271,6 @@ public boolean isNear() { partitions = in.readInt(); near = in.readBoolean(); metrics = (VisorCacheMetrics)in.readObject(); - parts = (VisorPartitionMap)in.readObject(); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java index 21a2806daa536..6812274f7d3bb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java @@ -211,7 +211,7 @@ public long getMaximumHeapSize() { * @return Off heap entries count. */ private long getOffHeapEntriesCount(VisorCacheMetrics metric) { - return metric.offHeapEntriesCount(); + return metric.getOffHeapEntriesCount(); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java index 11b1fde5c5170..5c1dfcb3f26ba 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java @@ -24,7 +24,6 @@ import org.apache.ignite.cache.CacheMetrics; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheProcessor; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; @@ -113,9 +112,6 @@ public class VisorCacheMetrics extends VisorDataTransferObject { /** Rollbacks per second. */ private int rollbacksPerSec; - /** Gets query metrics for cache. */ - private VisorQueryMetrics qryMetrics; - /** Current size of evict queue used to batch up evictions. */ private int dhtEvictQueueCurrSize; @@ -167,6 +163,24 @@ public class VisorCacheMetrics extends VisorDataTransferObject { /** Number of cache entries stored in off-heap memory. */ private long offHeapEntriesCnt; + /** Total number of partitions on current node. */ + private int totalPartsCnt; + + /** Number of currently rebalancing partitions on current node. */ + private int rebalancingPartsCnt; + + /** Estimated number of keys to be rebalanced on current node. */ + private long keysToRebalanceLeft; + + /** Estimated rebalancing speed in keys. */ + private long rebalancingKeysRate; + + /** Estimated rebalancing speed in bytes. */ + private long rebalancingBytesRate; + + /** Gets query metrics for cache. */ + private VisorQueryMetrics qryMetrics; + /** * Calculate rate of metric per second. * @@ -229,8 +243,6 @@ public VisorCacheMetrics(IgniteEx ignite, String cacheName) { commitsPerSec = perSecond(m.getAverageTxCommitTime()); rollbacksPerSec = perSecond(m.getAverageTxRollbackTime()); - qryMetrics = new VisorQueryMetrics(c.queryMetrics()); - dhtEvictQueueCurrSize = m.getDhtEvictQueueCurrentSize(); txThreadMapSize = m.getTxThreadMapSize(); txXidMapSize = m.getTxXidMapSize(); @@ -247,10 +259,16 @@ public VisorCacheMetrics(IgniteEx ignite, String cacheName) { txDhtCommittedVersionsSize = m.getTxDhtCommittedVersionsSize(); txDhtRolledbackVersionsSize = m.getTxDhtRolledbackVersionsSize(); - GridCacheAdapter ca = cacheProcessor.internalCache(cacheName); + offHeapAllocatedSize = m.getOffHeapAllocatedSize(); + offHeapEntriesCnt = m.getOffHeapEntriesCount(); + + totalPartsCnt = m.getTotalPartitionsCount(); + rebalancingPartsCnt = m.getRebalancingPartitionsCount(); + keysToRebalanceLeft = m.getKeysToRebalanceLeft(); + rebalancingKeysRate = m.getRebalancingKeysRate(); + rebalancingBytesRate = m.getRebalancingBytesRate(); - offHeapAllocatedSize = ca.offHeapAllocatedSize(); - offHeapEntriesCnt = ca.offHeapEntriesCount(); + qryMetrics = new VisorQueryMetrics(c.queryMetrics()); } /** @@ -552,14 +570,50 @@ public long getOffHeapAllocatedSize() { /** * @return Number of cache entries stored in off-heap memory. */ - public long offHeapEntriesCount() { + public long getOffHeapEntriesCount() { return offHeapEntriesCnt; } + /** + * @return Total number of partitions on current node. + */ + public int getTotalPartitionsCount() { + return totalPartsCnt; + } + + /** + * @return Number of currently rebalancing partitions on current node. + */ + public int getRebalancingPartitionsCount() { + return rebalancingPartsCnt; + } + + /** + * @return Estimated number of keys to be rebalanced on current node. + */ + public long getKeysToRebalanceLeft() { + return keysToRebalanceLeft; + } + + /** + * @return Estimated rebalancing speed in keys. + */ + public long getRebalancingKeysRate() { + return rebalancingKeysRate; + } + + /** + * @return Estimated rebalancing speed in bytes. + */ + public long getRebalancingBytesRate() { + return rebalancingBytesRate; + } + /** {@inheritDoc} */ @Override protected void writeExternalData(ObjectOutput out) throws IOException { U.writeString(out, name); U.writeEnum(out, mode); + out.writeBoolean(sys); out.writeInt(size); out.writeInt(keySize); @@ -583,6 +637,7 @@ public long offHeapEntriesCount() { out.writeInt(commitsPerSec); out.writeInt(rollbacksPerSec); out.writeInt(dhtEvictQueueCurrSize); + out.writeInt(txThreadMapSize); out.writeInt(txXidMapSize); out.writeInt(txCommitQueueSize); @@ -597,8 +652,16 @@ public long offHeapEntriesCount() { out.writeInt(txDhtStartVerCountsSize); out.writeInt(txDhtCommittedVersionsSize); out.writeInt(txDhtRolledbackVersionsSize); + out.writeLong(offHeapAllocatedSize); out.writeLong(offHeapEntriesCnt); + + out.writeInt(totalPartsCnt); + out.writeInt(rebalancingPartsCnt); + out.writeLong(keysToRebalanceLeft); + out.writeLong(rebalancingKeysRate); + out.writeLong(rebalancingBytesRate); + out.writeObject(qryMetrics); } @@ -629,6 +692,7 @@ public long offHeapEntriesCount() { commitsPerSec = in.readInt(); rollbacksPerSec = in.readInt(); dhtEvictQueueCurrSize = in.readInt(); + txThreadMapSize = in.readInt(); txXidMapSize = in.readInt(); txCommitQueueSize = in.readInt(); @@ -643,8 +707,16 @@ public long offHeapEntriesCount() { txDhtStartVerCountsSize = in.readInt(); txDhtCommittedVersionsSize = in.readInt(); txDhtRolledbackVersionsSize = in.readInt(); + offHeapAllocatedSize = in.readLong(); offHeapEntriesCnt = in.readLong(); + + totalPartsCnt = in.readInt(); + rebalancingPartsCnt = in.readInt(); + keysToRebalanceLeft = in.readLong(); + rebalancingKeysRate = in.readLong(); + rebalancingBytesRate = in.readLong(); + qryMetrics = (VisorQueryMetrics)in.readObject(); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/debug/VisorThreadMonitorInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/debug/VisorThreadMonitorInfo.java index e6171edfbc2f3..f8ddc68a31e3a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/debug/VisorThreadMonitorInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/debug/VisorThreadMonitorInfo.java @@ -80,6 +80,7 @@ public StackTraceElement getStackFrame() { @Override protected void writeExternalData(ObjectOutput out) throws IOException { try (VisorDataTransferObjectOutput dtout = new VisorDataTransferObjectOutput(out)) { dtout.writeByte(super.getProtocolVersion()); + super.writeExternalData(dtout); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridDeploymentEvent.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridDeploymentEvent.java index 1d41e190d188d..8b0c2110368b9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridDeploymentEvent.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridDeploymentEvent.java @@ -88,6 +88,7 @@ public String getAlias() { @Override protected void writeExternalData(ObjectOutput out) throws IOException { try (VisorDataTransferObjectOutput dtout = new VisorDataTransferObjectOutput(out)) { dtout.writeByte(super.getProtocolVersion()); + super.writeExternalData(dtout); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridDiscoveryEvent.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridDiscoveryEvent.java index b4afed9c6c294..ec2220d1fd7ba 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridDiscoveryEvent.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridDiscoveryEvent.java @@ -128,6 +128,7 @@ public long getTopologyVersion() { @Override protected void writeExternalData(ObjectOutput out) throws IOException { try (VisorDataTransferObjectOutput dtout = new VisorDataTransferObjectOutput(out)) { dtout.writeByte(super.getProtocolVersion()); + super.writeExternalData(dtout); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridJobEvent.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridJobEvent.java index 2e4c62700e939..734d85fa11cb7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridJobEvent.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridJobEvent.java @@ -127,6 +127,7 @@ public IgniteUuid getJobId() { @Override protected void writeExternalData(ObjectOutput out) throws IOException { try (VisorDataTransferObjectOutput dtout = new VisorDataTransferObjectOutput(out)) { dtout.writeByte(super.getProtocolVersion()); + super.writeExternalData(dtout); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridTaskEvent.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridTaskEvent.java index 0f3eee479bd3a..11c9a17d38dd5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridTaskEvent.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/event/VisorGridTaskEvent.java @@ -127,6 +127,7 @@ public boolean isInternal() { @Override protected void writeExternalData(ObjectOutput out) throws IOException { try (VisorDataTransferObjectOutput dtout = new VisorDataTransferObjectOutput(out)) { dtout.writeByte(super.getProtocolVersion()); + super.writeExternalData(dtout); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorJob.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorJob.java index 573cc8343eaea..02d3b6594216e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorJob.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorJob.java @@ -169,7 +169,7 @@ protected void caches(VisorNodeDataCollectorJobResult res, VisorNodeDataCollecto if (ca == null || !ca.context().started()) continue; - res.getCaches().add(new VisorCache(ignite, ca, arg.getSample())); + res.getCaches().add(new VisorCache(ignite, ca)); } catch(IllegalStateException | IllegalArgumentException e) { if (debug && ignite.log() != null) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorTaskArg.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorTaskArg.java index 825560b67c288..c39318ab76afb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorTaskArg.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorTaskArg.java @@ -40,9 +40,6 @@ public class VisorNodeDataCollectorTaskArg extends VisorDataTransferObject { /** Visor unique key to get lost events throttle counter from node local storage. */ private String evtThrottleCntrKey; - /** Cache sample size. */ - private int sample; - /** If {@code true} then collect information about system caches. */ private boolean sysCaches; @@ -59,20 +56,17 @@ public VisorNodeDataCollectorTaskArg() { * @param taskMonitoringEnabled If {@code true} then Visor should collect information about tasks. * @param evtOrderKey Event order key, unique for Visor instance. * @param evtThrottleCntrKey Event throttle counter key, unique for Visor instance. - * @param sample How many entries use in sampling. * @param sysCaches If {@code true} then collect information about system caches. */ public VisorNodeDataCollectorTaskArg( boolean taskMonitoringEnabled, String evtOrderKey, String evtThrottleCntrKey, - int sample, boolean sysCaches ) { this.taskMonitoringEnabled = taskMonitoringEnabled; this.evtOrderKey = evtOrderKey; this.evtThrottleCntrKey = evtThrottleCntrKey; - this.sample = sample; this.sysCaches = sysCaches; } @@ -118,20 +112,6 @@ public void setEventsThrottleCounterKey(String evtThrottleCntrKey) { this.evtThrottleCntrKey = evtThrottleCntrKey; } - /** - * @return Number of items to evaluate cache size. - */ - public int getSample() { - return sample; - } - - /** - * @param sample Number of items to evaluate cache size. - */ - public void setSample(int sample) { - this.sample = sample; - } - /** * @return {@code true} if Visor should collect metrics for system caches. */ @@ -151,7 +131,6 @@ public void setSystemCaches(boolean sysCaches) { out.writeBoolean(taskMonitoringEnabled); U.writeString(out, evtOrderKey); U.writeString(out, evtThrottleCntrKey); - out.writeInt(sample); out.writeBoolean(sysCaches); } @@ -160,7 +139,6 @@ public void setSystemCaches(boolean sysCaches) { taskMonitoringEnabled = in.readBoolean(); evtOrderKey = U.readString(in); evtThrottleCntrKey = U.readString(in); - sample = in.readInt(); sysCaches = in.readBoolean(); } diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala index 10350f218b998..505f353a5cc39 100755 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala @@ -408,9 +408,9 @@ class VisorCacheCommand { formatDouble(nm.getCurrentCpuLoad * 100d) + " %", X.timeSpan2HMSM(nm.getUpTime), ( - "Total: " + (cm.getKeySize + cm.offHeapEntriesCount()), + "Total: " + (cm.getKeySize + cm.getOffHeapEntriesCount()), " Heap: " + cm.getKeySize, - " Off-Heap: " + cm.offHeapEntriesCount(), + " Off-Heap: " + cm.getOffHeapEntriesCount(), " Off-Heap Memory: " + formatMemory(cm.getOffHeapAllocatedSize) ), ( From 29df01dd2196fda7ed927e67e5e8bad194ce6f34 Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Wed, 14 Jun 2017 15:55:03 +0700 Subject: [PATCH 311/311] IGNITE-5402 Web Console: Fixed near cache generation for client mode. --- .../modules/configuration/generator/JavaTransformer.service.js | 2 +- .../configuration/generator/SpringTransformer.service.js | 2 +- .../modules/states/configuration/caches/near-cache-client.pug | 2 +- .../app/modules/states/configuration/summary/summary.worker.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/web-console/frontend/app/modules/configuration/generator/JavaTransformer.service.js b/modules/web-console/frontend/app/modules/configuration/generator/JavaTransformer.service.js index bf1a667e810b2..fad61d6c12216 100644 --- a/modules/web-console/frontend/app/modules/configuration/generator/JavaTransformer.service.js +++ b/modules/web-console/frontend/app/modules/configuration/generator/JavaTransformer.service.js @@ -1042,7 +1042,7 @@ export default class IgniteJavaTransformer extends AbstractTransformer { const cfg = this.generator.igniteConfiguration(cluster, targetVer, client); const clientNearCaches = client ? _.filter(cluster.caches, (cache) => - cache.mode === 'PARTITIONED' && _.get(cache, 'clientNearConfiguration.enabled')) : []; + cache.cacheMode === 'PARTITIONED' && _.get(cache, 'clientNearConfiguration.enabled')) : []; return this.igniteConfiguration(cfg, pkg, clsName, clientNearCaches); } diff --git a/modules/web-console/frontend/app/modules/configuration/generator/SpringTransformer.service.js b/modules/web-console/frontend/app/modules/configuration/generator/SpringTransformer.service.js index 41aea0a2ff30d..eda590c1e696c 100644 --- a/modules/web-console/frontend/app/modules/configuration/generator/SpringTransformer.service.js +++ b/modules/web-console/frontend/app/modules/configuration/generator/SpringTransformer.service.js @@ -320,7 +320,7 @@ export default class IgniteSpringTransformer extends AbstractTransformer { const cfg = this.generator.igniteConfiguration(cluster, targetVer, client); const clientNearCaches = client ? _.filter(cluster.caches, (cache) => - cache.mode === 'PARTITIONED' && _.get(cache, 'clientNearConfiguration.enabled')) : []; + cache.cacheMode === 'PARTITIONED' && _.get(cache, 'clientNearConfiguration.enabled')) : []; return this.igniteConfiguration(cfg, clientNearCaches); } diff --git a/modules/web-console/frontend/app/modules/states/configuration/caches/near-cache-client.pug b/modules/web-console/frontend/app/modules/states/configuration/caches/near-cache-client.pug index 499dd2de230b2..aeae30dc0e6e9 100644 --- a/modules/web-console/frontend/app/modules/states/configuration/caches/near-cache-client.pug +++ b/modules/web-console/frontend/app/modules/states/configuration/caches/near-cache-client.pug @@ -40,7 +40,7 @@ include /app/helpers/jade/mixins +number('Start size:', `${nearCfg}.nearStartSize`, '"clientNearStartSize"', enabled, '375000', '0', 'Initial cache size for near cache which will be used to pre-create internal hash table after start') .settings-row - +evictionPolicy(`${nearCfg}.nearEvictionPolic`, '"clientNearCacheEvictionPolicy"', enabled, 'false', + +evictionPolicy(`${nearCfg}.nearEvictionPolicy`, '"clientNearCacheEvictionPolicy"', enabled, 'false', 'Near cache eviction policy\
    \
  • Least Recently Used (LRU) - Eviction policy based on LRU algorithm and supports batch eviction
  • \ diff --git a/modules/web-console/frontend/app/modules/states/configuration/summary/summary.worker.js b/modules/web-console/frontend/app/modules/states/configuration/summary/summary.worker.js index 6bf1182fb019a..91c2afa9e4d00 100644 --- a/modules/web-console/frontend/app/modules/states/configuration/summary/summary.worker.js +++ b/modules/web-console/frontend/app/modules/states/configuration/summary/summary.worker.js @@ -72,7 +72,7 @@ onmessage = function(e) { const cfg = generator.igniteConfiguration(cluster, targetVer.ignite, false); const clientCfg = generator.igniteConfiguration(cluster, targetVer.ignite, true); const clientNearCaches = _.filter(cluster.caches, (cache) => - cache.mode === 'PARTITIONED' && _.get(cache, 'clientNearConfiguration.enabled')); + cache.cacheMode === 'PARTITIONED' && _.get(cache, 'clientNearConfiguration.enabled')); const secProps = properties.generate(cfg);