You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/07/22 11:29:15 UTC
[01/33] ignite git commit: Revert IGNITE-2949 due to broken
compatibility
Repository: ignite
Updated Branches:
refs/heads/ignite-3547 [created] 1fdd6e8f9
Revert IGNITE-2949 due to broken compatibility
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1b7428bd
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1b7428bd
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1b7428bd
Branch: refs/heads/ignite-3547
Commit: 1b7428bde5bac38ac3eb2a8b015d3766f68f5a50
Parents: bebf3f0
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Thu Jul 7 00:05:16 2016 -0700
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Thu Jul 7 00:05:16 2016 -0700
----------------------------------------------------------------------
assembly/LICENSE_FABRIC | 7 ++++++-
assembly/LICENSE_HADOOP | 7 ++++++-
examples/pom-standalone-lgpl.xml | 6 +++---
examples/pom-standalone.xml | 6 +++---
examples/pom.xml | 6 +++---
examples/schema-import/pom-standalone.xml | 6 +++---
examples/schema-import/pom.xml | 6 +++---
modules/cassandra/pom.xml | 2 +-
modules/core/pom.xml | 6 +++---
modules/flume/README.txt | 2 +-
parent/pom.xml | 1 +
11 files changed, 33 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/1b7428bd/assembly/LICENSE_FABRIC
----------------------------------------------------------------------
diff --git a/assembly/LICENSE_FABRIC b/assembly/LICENSE_FABRIC
index 8cb5730..b9c75b2 100644
--- a/assembly/LICENSE_FABRIC
+++ b/assembly/LICENSE_FABRIC
@@ -1,4 +1,3 @@
-
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
@@ -227,6 +226,12 @@ For details, see CC0 1.0 Universal (1.0), Public Domain Dedication,
http://creativecommons.org/publicdomain/zero/1.0/
==============================================================================
+For JSR107 API and SPI (https://github.com/jsr107/jsr107spec) javax.cache:cache-api:jar:1.0.0
+==============================================================================
+This product bundles JSR107 API and SPI which is available under a:
+JSR-000107 JCACHE 2.9 Public Review - Updated Specification License. For details, see https://raw.github.com/jsr107/jsr107spec/master/LICENSE.txt.
+
+==============================================================================
For JSch (http://www.jcraft.com/jsch/) com.jcraft:jsch:jar:0.1.50
==============================================================================
This product bundles JSch which is available under a:
http://git-wip-us.apache.org/repos/asf/ignite/blob/1b7428bd/assembly/LICENSE_HADOOP
----------------------------------------------------------------------
diff --git a/assembly/LICENSE_HADOOP b/assembly/LICENSE_HADOOP
index 0d05d52..0256b20 100644
--- a/assembly/LICENSE_HADOOP
+++ b/assembly/LICENSE_HADOOP
@@ -1,4 +1,3 @@
-
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
@@ -227,6 +226,12 @@ For details, see CC0 1.0 Universal (1.0), Public Domain Dedication,
http://creativecommons.org/publicdomain/zero/1.0/
==============================================================================
+For JSR107 API and SPI (https://github.com/jsr107/jsr107spec) javax.cache:cache-api:jar:1.0.0
+==============================================================================
+This product bundles JSR107 API and SPI which is available under a:
+JSR-000107 JCACHE 2.9 Public Review - Updated Specification License. For details, see https://raw.github.com/jsr107/jsr107spec/master/LICENSE.txt.
+
+==============================================================================
For JSch (http://www.jcraft.com/jsch/) com.jcraft:jsch:jar:0.1.50
==============================================================================
This product bundles JSch which is available under a:
http://git-wip-us.apache.org/repos/asf/ignite/blob/1b7428bd/examples/pom-standalone-lgpl.xml
----------------------------------------------------------------------
diff --git a/examples/pom-standalone-lgpl.xml b/examples/pom-standalone-lgpl.xml
index 951fab6..7e7ccc2 100644
--- a/examples/pom-standalone-lgpl.xml
+++ b/examples/pom-standalone-lgpl.xml
@@ -41,9 +41,9 @@
<dependencies>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jcache_1.0_spec</artifactId>
- <version>1.0-alpha-1</version>
+ <groupId>javax.cache</groupId>
+ <artifactId>cache-api</artifactId>
+ <version>1.0.0</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/ignite/blob/1b7428bd/examples/pom-standalone.xml
----------------------------------------------------------------------
diff --git a/examples/pom-standalone.xml b/examples/pom-standalone.xml
index 20399ee..6247ced 100644
--- a/examples/pom-standalone.xml
+++ b/examples/pom-standalone.xml
@@ -41,9 +41,9 @@
<dependencies>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jcache_1.0_spec</artifactId>
- <version>1.0-alpha-1</version>
+ <groupId>javax.cache</groupId>
+ <artifactId>cache-api</artifactId>
+ <version>1.0.0</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/ignite/blob/1b7428bd/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 1c03a24..d8a38d8 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -32,9 +32,9 @@
<dependencies>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jcache_1.0_spec</artifactId>
- <version>1.0-alpha-1</version>
+ <groupId>javax.cache</groupId>
+ <artifactId>cache-api</artifactId>
+ <version>${javax.cache.version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/ignite/blob/1b7428bd/examples/schema-import/pom-standalone.xml
----------------------------------------------------------------------
diff --git a/examples/schema-import/pom-standalone.xml b/examples/schema-import/pom-standalone.xml
index 43b76d8..e443728 100644
--- a/examples/schema-import/pom-standalone.xml
+++ b/examples/schema-import/pom-standalone.xml
@@ -36,9 +36,9 @@
<dependencies>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jcache_1.0_spec</artifactId>
- <version>1.0-alpha-1</version>
+ <groupId>javax.cache</groupId>
+ <artifactId>cache-api</artifactId>
+ <version>1.0.0</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/ignite/blob/1b7428bd/examples/schema-import/pom.xml
----------------------------------------------------------------------
diff --git a/examples/schema-import/pom.xml b/examples/schema-import/pom.xml
index eb1236d..62bb773 100644
--- a/examples/schema-import/pom.xml
+++ b/examples/schema-import/pom.xml
@@ -39,9 +39,9 @@
<dependencies>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jcache_1.0_spec</artifactId>
- <version>1.0-alpha-1</version>
+ <groupId>javax.cache</groupId>
+ <artifactId>cache-api</artifactId>
+ <version>${javax.cache.version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/ignite/blob/1b7428bd/modules/cassandra/pom.xml
----------------------------------------------------------------------
diff --git a/modules/cassandra/pom.xml b/modules/cassandra/pom.xml
index 2eff19e..3eda256 100644
--- a/modules/cassandra/pom.xml
+++ b/modules/cassandra/pom.xml
@@ -237,7 +237,7 @@
org.apache.ignite,org.springframework,org.gridgain
</excludeGroupIds>
<excludeArtifactIds>
- commons-logging,slf4j-api,geronimo-jcache_1.0_spec,slf4j-api,aopalliance
+ commons-logging,slf4j-api,cache-api,slf4j-api,aopalliance
</excludeArtifactIds>
<includeScope>runtime</includeScope>
</configuration>
http://git-wip-us.apache.org/repos/asf/ignite/blob/1b7428bd/modules/core/pom.xml
----------------------------------------------------------------------
diff --git a/modules/core/pom.xml b/modules/core/pom.xml
index fe3a477..b80a924 100644
--- a/modules/core/pom.xml
+++ b/modules/core/pom.xml
@@ -63,9 +63,9 @@
<dependencies>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jcache_1.0_spec</artifactId>
- <version>1.0-alpha-1</version>
+ <groupId>javax.cache</groupId>
+ <artifactId>cache-api</artifactId>
+ <version>${javax.cache.version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/ignite/blob/1b7428bd/modules/flume/README.txt
----------------------------------------------------------------------
diff --git a/modules/flume/README.txt b/modules/flume/README.txt
index 97d8cac..bf7e0ff 100644
--- a/modules/flume/README.txt
+++ b/modules/flume/README.txt
@@ -20,7 +20,7 @@ plugins.d/
|-- lib
| `-- ignite-flume-transformer-x.x.x.jar <-- your jar
`-- libext
- |-- geronimo-jcache_1.0_spec-1.0-alpha-1.jar
+ |-- cache-api-1.0.0.jar
|-- ignite-core-x.x.x.jar
|-- ignite-flume-x.x.x.jar <-- IgniteSink
|-- ignite-spring-x.x.x.jar
http://git-wip-us.apache.org/repos/asf/ignite/blob/1b7428bd/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 6600542..1553612 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -75,6 +75,7 @@
<jackson.version>1.9.13</jackson.version>
<jackson2.version>2.7.5</jackson2.version>
<javax.cache.bundle.version>1.0.0_1</javax.cache.bundle.version>
+ <javax.cache.version>1.0.0</javax.cache.version>
<jetty.version>9.2.11.v20150529</jetty.version>
<jms.spec.version>1.1.1</jms.spec.version>
<jsch.bundle.version>0.1.53_1</jsch.bundle.version>
[03/33] ignite git commit: Backported test fixes.
Posted by sb...@apache.org.
Backported test fixes.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5b6e7816
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5b6e7816
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5b6e7816
Branch: refs/heads/ignite-3547
Commit: 5b6e7816260addfb3ed819e63147a0873bda9baf
Parents: f52fb79
Author: sboikov <sb...@gridgain.com>
Authored: Thu Jul 7 12:37:25 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Thu Jul 7 12:37:25 2016 +0300
----------------------------------------------------------------------
.../GridEventStorageCheckAllEventsSelfTest.java | 30 ++++++++++++++++++--
...CommunicationRecoveryAckClosureSelfTest.java | 18 ++++++++++++
2 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/5b6e7816/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java
index ad15894..0619391 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java
@@ -30,10 +30,12 @@ import org.apache.ignite.compute.ComputeJob;
import org.apache.ignite.compute.ComputeJobAdapter;
import org.apache.ignite.compute.ComputeJobResult;
import org.apache.ignite.compute.ComputeTaskFuture;
+import org.apache.ignite.compute.ComputeTaskMapAsync;
import org.apache.ignite.compute.ComputeTaskSession;
import org.apache.ignite.compute.ComputeTaskSessionFullSupport;
import org.apache.ignite.compute.ComputeTaskSplitAdapter;
import org.apache.ignite.compute.ComputeTaskTimeoutException;
+import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.events.CheckpointEvent;
import org.apache.ignite.events.DeploymentEvent;
import org.apache.ignite.events.Event;
@@ -86,6 +88,16 @@ public class GridEventStorageCheckAllEventsSelfTest extends GridCommonAbstractTe
}
/** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration() throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration();
+
+ // TODO: IGNITE-3099 (hotfix the test to check the event order in common case).
+ cfg.setPublicThreadPoolSize(1);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
ignite = G.ignite(getTestGridName());
@@ -140,10 +152,23 @@ public class GridEventStorageCheckAllEventsSelfTest extends GridCommonAbstractTe
* @throws Exception If test failed.
*/
public void testTaskUndeployEvents() throws Exception {
- long tstamp = startTimestamp();
+ final long tstamp = startTimestamp();
generateEvents(null, new GridAllEventsSuccessTestJob()).get();
+ // TODO: IGNITE-3099 (hotfix the test to check the event order in common case).
+ GridTestUtils.waitForCondition(new GridAbsPredicate() {
+ @Override public boolean apply() {
+ try {
+ List<Event> evts = pullEvents(tstamp, 10);
+ return evts.get(evts.size() - 1).type() == EVT_JOB_FINISHED;
+ }
+ catch (Exception e) {
+ return false;
+ }
+ }
+ }, 500);
+
ignite.compute().undeployTask(GridAllEventsTestTask.class.getName());
ignite.compute().localDeployTask(GridAllEventsTestTask.class, GridAllEventsTestTask.class.getClassLoader());
@@ -198,7 +223,7 @@ public class GridEventStorageCheckAllEventsSelfTest extends GridCommonAbstractTe
try {
fut.get();
- assert false : "Grid with locally executed job with timeout should throw GridComputeTaskTimeoutException.";
+ assert false : "Grid with locally executed job with timeout should throw ComputeTaskTimeoutException.";
}
catch (IgniteException e) {
info("Expected exception caught [taskFuture=" + fut + ", exception=" + e + ']');
@@ -463,6 +488,7 @@ public class GridEventStorageCheckAllEventsSelfTest extends GridCommonAbstractTe
*
*/
@ComputeTaskSessionFullSupport
+ @ComputeTaskMapAsync // TODO: IGNITE-3099 (hotfix the test to check the event order in common case).
private static class GridAllEventsTestTask extends ComputeTaskSplitAdapter<Object, Object> {
/** {@inheritDoc} */
@Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/5b6e7816/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/IgniteTcpCommunicationRecoveryAckClosureSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/IgniteTcpCommunicationRecoveryAckClosureSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/IgniteTcpCommunicationRecoveryAckClosureSelfTest.java
index 7521f2e..260bbd2 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/IgniteTcpCommunicationRecoveryAckClosureSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/IgniteTcpCommunicationRecoveryAckClosureSelfTest.java
@@ -49,11 +49,13 @@ import org.apache.ignite.testframework.GridTestNode;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.IgniteTestResources;
import org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest;
+import org.apache.ignite.testframework.junits.spi.GridSpiTest;
import org.eclipse.jetty.util.ConcurrentHashSet;
/**
*
*/
+@GridSpiTest(spi = TcpCommunicationSpi.class, group = "Communication SPI")
public class IgniteTcpCommunicationRecoveryAckClosureSelfTest<T extends CommunicationSpi>
extends GridSpiAbstractTest<T> {
/** */
@@ -151,6 +153,8 @@ public class IgniteTcpCommunicationRecoveryAckClosureSelfTest<T extends Communic
int expMsgs = 0;
+ long totAcked = 0;
+
for (int i = 0; i < 5; i++) {
info("Iteration: " + i);
@@ -172,6 +176,8 @@ public class IgniteTcpCommunicationRecoveryAckClosureSelfTest<T extends Communic
expMsgs += msgPerIter;
+ final long totAcked0 = totAcked;
+
for (TcpCommunicationSpi spi : spis) {
GridNioServer srv = U.field(spi, "nioSrvr");
@@ -189,6 +195,14 @@ public class IgniteTcpCommunicationRecoveryAckClosureSelfTest<T extends Communic
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override public boolean apply() {
+ long acked = GridTestUtils.getFieldValue(recoveryDesc, "acked");
+
+ return acked > totAcked0;
+ }
+ }, 5000);
+
+ GridTestUtils.waitForCondition(new GridAbsPredicate() {
+ @Override public boolean apply() {
return recoveryDesc.messagesFutures().isEmpty();
}
}, 10_000);
@@ -218,6 +232,8 @@ public class IgniteTcpCommunicationRecoveryAckClosureSelfTest<T extends Communic
}
assertEquals(msgPerIter * 2, ackMsgs.get());
+
+ totAcked += msgPerIter;
}
}
finally {
@@ -337,6 +353,8 @@ public class IgniteTcpCommunicationRecoveryAckClosureSelfTest<T extends Communic
return expMsgs == ackMsgs.get();
}
}, 5000);
+
+ assertEquals(expMsgs, ackMsgs.get());
}
/**
[07/33] ignite git commit: IGNITE-3227 - Added method to get
partition size
Posted by sb...@apache.org.
IGNITE-3227 - Added method to get partition size
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8af30781
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8af30781
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8af30781
Branch: refs/heads/ignite-3547
Commit: 8af307819dba9f9fea4946cb09df01c4ef146f8a
Parents: 5b49dad
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Thu Jul 7 15:58:50 2016 -0700
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Thu Jul 7 15:58:50 2016 -0700
----------------------------------------------------------------------
.../java/org/apache/ignite/IgniteCache.java | 25 +
.../processors/cache/GridCacheAdapter.java | 215 ++++++++-
.../processors/cache/GridCacheProxyImpl.java | 36 ++
.../processors/cache/IgniteCacheProxy.java | 40 ++
.../processors/cache/IgniteInternalCache.java | 23 +
.../cache/IgniteCacheAtomicPeekModesTest.java | 2 +-
.../cache/IgniteCachePeekModesAbstractTest.java | 463 ++++++++++++++++++-
.../multijvm/IgniteCacheProcessProxy.java | 46 +-
8 files changed, 846 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/8af30781/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
index 3af2c44..8cefb4f 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -370,6 +370,20 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
public long sizeLong(CachePeekMode... peekModes) throws CacheException;
/**
+ * Gets the number of all entries cached in a partition as a long value. By default, if {@code peekModes} value
+ * isn't defined, only size of primary copies across all nodes will be returned. This behavior is identical to
+ * calling this method with {@link CachePeekMode#PRIMARY} peek mode.
+ * <p>
+ * NOTE: this operation is distributed and will query all participating nodes for their partition cache sizes.
+ *
+ * @param partition partition.
+ * @param peekModes Optional peek modes. If not provided, then total partition cache size is returned.
+ * @return Partion cache size across all nodes.
+ */
+ @IgniteAsyncSupported
+ public long sizeLong(int partition, CachePeekMode... peekModes) throws CacheException;
+
+ /**
* Gets the number of all entries cached on this node. By default, if {@code peekModes} value isn't defined,
* only size of primary copies will be returned. This behavior is identical to calling this method with
* {@link CachePeekMode#PRIMARY} peek mode.
@@ -390,6 +404,17 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
public long localSizeLong(CachePeekMode... peekModes);
/**
+ * Gets the number of all entries cached on this node for the partition as a long value. By default, if {@code peekModes} value isn't
+ * defined, only size of primary copies will be returned. This behavior is identical to calling this method with
+ * {@link CachePeekMode#PRIMARY} peek mode.
+ *
+ * @param partition partition.
+ * @param peekModes Optional peek modes. If not provided, then total cache size is returned.
+ * @return Cache size on this node.
+ */
+ public long localSizeLong(int partition, CachePeekMode... peekModes);
+
+ /**
* @param map Map containing keys and entry processors to be applied to values.
* @param args Additional arguments to pass to the {@link EntryProcessor}.
* @return The map of {@link EntryProcessorResult}s of the processing per key,
http://git-wip-us.apache.org/repos/asf/ignite/blob/8af30781/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 028f516..55bd81d 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
@@ -84,6 +84,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityImpl;
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.GridDhtLocalPartition;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException;
import org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo;
import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
@@ -3965,6 +3966,14 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
}
/** {@inheritDoc} */
+ @Override public long sizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException {
+ if (isLocal())
+ return localSizeLong(partition, peekModes);
+
+ return sizeLongAsync(partition, peekModes).get();
+ }
+
+ /** {@inheritDoc} */
@Override public IgniteInternalFuture<Integer> sizeAsync(final CachePeekMode[] peekModes) {
assert peekModes != null;
@@ -4007,6 +4016,36 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
}
/** {@inheritDoc} */
+ @Override public IgniteInternalFuture<Long> sizeLongAsync(final int part, final CachePeekMode[] peekModes) {
+ assert peekModes != null;
+
+ final PeekModes modes = parsePeekModes(peekModes, true);
+
+ IgniteClusterEx cluster = ctx.grid().cluster();
+ final GridCacheAffinityManager aff = ctx.affinity();
+ final AffinityTopologyVersion topVer = aff.affinityTopologyVersion();
+
+ ClusterGroup grp = cluster.forDataNodes(name());
+
+ Collection<ClusterNode> nodes = grp.forPredicate(new IgnitePredicate<ClusterNode>() {
+ /** {@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)));
+ }
+ }).nodes();
+
+ if (nodes.isEmpty())
+ return new GridFinishedFuture<>(0L);
+
+ ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
+
+ return ctx.kernalContext().task().execute(
+ new PartitionSizeLongTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), peekModes, part), null);
+ }
+
+ /** {@inheritDoc} */
@Override public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException {
return (int)localSizeLong(peekModes);
}
@@ -4060,6 +4099,50 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
}
/** {@inheritDoc} */
+ @Override public long localSizeLong(int part, CachePeekMode[] peekModes) throws IgniteCheckedException {
+ PeekModes modes = parsePeekModes(peekModes, true);
+
+ long size = 0;
+
+ AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
+
+ // Swap and offheap are disabled for near cache.
+ GridCacheSwapManager swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap();
+
+ if (ctx.isLocal()){
+ modes.primary = true;
+ modes.backup = true;
+
+ if (modes.heap)
+ size += size();
+
+ if (modes.swap)
+ size += swapMgr.swapEntriesCount(0);
+
+ if (modes.offheap)
+ size += swapMgr.offheapEntriesCount(0);
+ }
+ else {
+ GridDhtLocalPartition dhtPart = ctx.topology().localPartition(part, topVer, false);
+
+ if (dhtPart != null) {
+ if (modes.primary && dhtPart.primary(topVer) || modes.backup && dhtPart.backup(topVer)) {
+ if (modes.heap)
+ size += dhtPart.publicSize();
+
+ if (modes.swap)
+ size += swapMgr.swapEntriesCount(part);
+
+ if (modes.offheap)
+ size += swapMgr.offheapEntriesCount(part);
+ }
+ }
+ }
+
+ return size;
+ }
+
+ /** {@inheritDoc} */
@Override public int size() {
return map.publicSize();
}
@@ -5637,6 +5720,52 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
}
/**
+ * Internal callable for partition size calculation.
+ */
+ @GridInternal
+ private static class PartitionSizeLongJob extends TopologyVersionAwareJob {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Partition. */
+ private final int partition;
+
+ /** Peek modes. */
+ private final CachePeekMode[] peekModes;
+
+ /**
+ * @param cacheName Cache name.
+ * @param topVer Affinity topology version.
+ * @param peekModes Cache peek modes.
+ * @param partition partition.
+ */
+ private PartitionSizeLongJob(String cacheName, AffinityTopologyVersion topVer, CachePeekMode[] peekModes, int partition) {
+ super(cacheName, topVer);
+
+ this.peekModes = peekModes;
+ this.partition = partition;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Object localExecute(@Nullable IgniteInternalCache cache) {
+ if (cache == null)
+ return 0;
+
+ try {
+ return cache.localSizeLong(partition, peekModes);
+ }
+ catch (IgniteCheckedException e) {
+ throw U.convertException(e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return S.toString(PartitionSizeLongJob.class, this);
+ }
+ }
+
+ /**
* Internal callable for global size calculation.
*/
@GridInternal
@@ -6610,7 +6739,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
* @param topVer Affinity topology version.
* @param peekModes Cache peek modes.
*/
- public SizeLongTask(String cacheName, AffinityTopologyVersion topVer, CachePeekMode[] peekModes) {
+ private SizeLongTask(String cacheName, AffinityTopologyVersion topVer, CachePeekMode[] peekModes) {
this.cacheName = cacheName;
this.topVer = topVer;
this.peekModes = peekModes;
@@ -6655,6 +6784,90 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
}
/**
+ * Partition Size Long task.
+ */
+ private static class PartitionSizeLongTask extends ComputeTaskAdapter<Object, Long> {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** */
+ private static final IgniteProductVersion SINCE_VER = IgniteProductVersion.fromString("1.5.30");
+
+ /** Partition */
+ private final int partition;
+
+ /** Cache name. */
+ private final String cacheName;
+
+ /** Affinity topology version. */
+ private final AffinityTopologyVersion topVer;
+
+ /** Peek modes. */
+ private final CachePeekMode[] peekModes;
+
+ /**
+ * @param cacheName Cache name.
+ * @param topVer Affinity topology version.
+ * @param peekModes Cache peek modes.
+ * @param partition partition.
+ */
+ private PartitionSizeLongTask(
+ String cacheName,
+ AffinityTopologyVersion topVer,
+ CachePeekMode[] peekModes,
+ int partition
+ ) {
+ this.cacheName = cacheName;
+ this.topVer = topVer;
+ this.peekModes = peekModes;
+ this.partition = partition;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Map<? extends ComputeJob, ClusterNode> map(
+ List<ClusterNode> subgrid,
+ @Nullable Object arg
+ ) throws IgniteException {
+ Map<ComputeJob, ClusterNode> jobs = new HashMap();
+
+ for (ClusterNode node : subgrid)
+ jobs.put(new PartitionSizeLongJob(cacheName, topVer, peekModes, partition), node);
+
+ return jobs;
+ }
+
+ /** {@inheritDoc} */
+ @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
+ IgniteException e = res.getException();
+
+ if (e != null) {
+ if (e instanceof ClusterTopologyException)
+ return ComputeJobResultPolicy.WAIT;
+
+ throw new IgniteException("Remote job threw exception.", e);
+ }
+
+ return ComputeJobResultPolicy.WAIT;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Long reduce(List<ComputeJobResult> results) throws IgniteException {
+ long size = 0;
+
+ for (ComputeJobResult res : results) {
+ if (res != null) {
+ if (res.getException() == null)
+ size += res.<Long>getData();
+ else
+ throw res.getException();
+ }
+ }
+
+ return size;
+ }
+ }
+
+ /**
* Clear task.
*/
private static class ClearTask<K> extends ComputeTaskAdapter<Object, Object> {
http://git-wip-us.apache.org/repos/asf/ignite/blob/8af30781/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
index 99dd608..b46c4dc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
@@ -1483,6 +1483,18 @@ public class GridCacheProxyImpl<K, V> implements IgniteInternalCache<K, V>, Exte
}
/** {@inheritDoc} */
+ @Override public long sizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException {
+ CacheOperationContext prev = gate.enter(opCtx);
+
+ try {
+ return delegate.sizeLong(partition, peekModes);
+ }
+ finally {
+ gate.leave(prev);
+ }
+ }
+
+ /** {@inheritDoc} */
@Override public IgniteInternalFuture<Integer> sizeAsync(CachePeekMode[] peekModes) {
CacheOperationContext prev = gate.enter(opCtx);
@@ -1507,6 +1519,18 @@ public class GridCacheProxyImpl<K, V> implements IgniteInternalCache<K, V>, Exte
}
/** {@inheritDoc} */
+ @Override public IgniteInternalFuture<Long> sizeLongAsync(int partition, CachePeekMode[] peekModes) {
+ CacheOperationContext prev = gate.enter(opCtx);
+
+ try {
+ return delegate.sizeLongAsync(partition, peekModes);
+ }
+ finally {
+ gate.leave(prev);
+ }
+ }
+
+ /** {@inheritDoc} */
@Override public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException {
CacheOperationContext prev = gate.enter(opCtx);
@@ -1531,6 +1555,18 @@ public class GridCacheProxyImpl<K, V> implements IgniteInternalCache<K, V>, Exte
}
/** {@inheritDoc} */
+ @Override public long localSizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException {
+ CacheOperationContext prev = gate.enter(opCtx);
+
+ try {
+ return delegate.localSizeLong(partition, peekModes);
+ }
+ finally {
+ gate.leave(prev);
+ }
+ }
+
+ /** {@inheritDoc} */
@Override public int nearSize() {
CacheOperationContext prev = gate.enter(opCtx);
http://git-wip-us.apache.org/repos/asf/ignite/blob/8af30781/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
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 12ec8b8..92e59db 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
@@ -840,6 +840,29 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V
/** {@inheritDoc} */
+ @Override public long sizeLong(int part, CachePeekMode... peekModes) throws CacheException {
+ GridCacheGateway<K, V> gate = this.gate;
+
+ CacheOperationContext prev = onEnter(gate, opCtx);
+
+ try {
+ if (isAsync()) {
+ setFuture(delegate.sizeLongAsync(part, peekModes));
+
+ return 0;
+ }
+ else
+ return delegate.sizeLong(part, peekModes);
+ }
+ catch (IgniteCheckedException e) {
+ throw cacheException(e);
+ }
+ finally {
+ onLeave(gate, prev);
+ }
+ }
+
+ /** {@inheritDoc} */
@Override public int localSize(CachePeekMode... peekModes) {
GridCacheGateway<K, V> gate = this.gate;
@@ -874,6 +897,23 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V
}
/** {@inheritDoc} */
+ @Override public long localSizeLong(int part, CachePeekMode... peekModes) {
+ GridCacheGateway<K, V> gate = this.gate;
+
+ CacheOperationContext prev = onEnter(gate, opCtx);
+
+ try {
+ return delegate.localSizeLong(part, peekModes);
+ }
+ catch (IgniteCheckedException e) {
+ throw cacheException(e);
+ }
+ finally {
+ onLeave(gate, prev);
+ }
+ }
+
+ /** {@inheritDoc} */
@Override public V get(K key) {
try {
GridCacheGateway<K, V> gate = this.gate;
http://git-wip-us.apache.org/repos/asf/ignite/blob/8af30781/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
index d155b0e..4dc9a23f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
@@ -1453,6 +1453,14 @@ public interface IgniteInternalCache<K, V> extends Iterable<Cache.Entry<K, V>> {
public long localSizeLong(CachePeekMode[] peekModes) throws IgniteCheckedException;
/**
+ * @param partition partition.
+ * @param peekModes Peek modes.
+ * @return Local cache size as a long value.
+ * @throws IgniteCheckedException If failed.
+ */
+ public long localSizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException;
+
+ /**
* @param peekModes Peek modes.
* @return Global cache size.
* @throws IgniteCheckedException If failed.
@@ -1467,6 +1475,14 @@ public interface IgniteInternalCache<K, V> extends Iterable<Cache.Entry<K, V>> {
public long sizeLong(CachePeekMode[] peekModes) throws IgniteCheckedException;
/**
+ * @param partition partition
+ * @param peekModes Peek modes.
+ * @return Global cache size as a long value.
+ * @throws IgniteCheckedException If failed.
+ */
+ public long sizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException;
+
+ /**
* @param peekModes Peek modes.
* @return Future.
*/
@@ -1479,6 +1495,13 @@ public interface IgniteInternalCache<K, V> extends Iterable<Cache.Entry<K, V>> {
public IgniteInternalFuture<Long> sizeLongAsync(CachePeekMode[] peekModes);
/**
+ * @param partition partiton
+ * @param peekModes Peek modes.
+ * @return Future.
+ */
+ public IgniteInternalFuture<Long> sizeLongAsync(int partition, CachePeekMode[] peekModes);
+
+ /**
* Gets size of near cache key set. This method will return count of all entries in near
* cache and has O(1) complexity on base cache projection.
* <p>
http://git-wip-us.apache.org/repos/asf/ignite/blob/8af30781/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekModesTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekModesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekModesTest.java
index 4270bab..8b7859a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekModesTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekModesTest.java
@@ -48,4 +48,4 @@ public class IgniteCacheAtomicPeekModesTest extends IgniteCachePeekModesAbstract
@Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() {
return PRIMARY;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/8af30781/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
----------------------------------------------------------------------
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 c27cccb..5dc059b 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
@@ -28,6 +28,7 @@ import java.util.Set;
import javax.cache.Cache;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.CacheMemoryMode;
import org.apache.ignite.cache.CachePeekMode;
import org.apache.ignite.cache.affinity.Affinity;
@@ -38,6 +39,7 @@ import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.util.typedef.T2;
import org.apache.ignite.spi.IgniteSpiCloseableIterator;
import org.apache.ignite.spi.swapspace.SwapSpaceSpi;
@@ -501,6 +503,144 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
}
/**
+ * @throws Exception If failed.
+ */
+ public void testLocalPartitionSize() throws Exception {
+ if (cacheMode() != LOCAL)
+ return;
+
+ awaitPartitionMapExchange();
+ checkEmpty();
+ int part = 0;
+ IgniteCache<Integer, String> cache0 = jcache(0);
+
+ IgniteCache<Integer, String> cacheAsync0 = cache0.withAsync();
+
+ for (int i = 0; i < HEAP_ENTRIES; i++) {
+ cache0.put(i, String.valueOf(i));
+
+ final long size = i + 1;
+
+ assertEquals(size, cache0.localSize());
+ assertEquals(size, cache0.localSizeLong(part, PRIMARY));
+ assertEquals(size, cache0.localSizeLong(part, BACKUP));
+ assertEquals(size, cache0.localSizeLong(part, NEAR));
+ assertEquals(size, cache0.localSizeLong(part, ALL));
+
+ assertEquals(size, cache0.size());
+ assertEquals(size, cache0.sizeLong(part, PRIMARY));
+ assertEquals(size, cache0.sizeLong(part, BACKUP));
+ assertEquals(size, cache0.sizeLong(part, NEAR));
+ assertEquals(size, cache0.sizeLong(part, ALL));
+
+ cacheAsync0.size();
+
+ assertEquals(size, (long) cacheAsync0.<Integer>future().get());
+
+ cacheAsync0.sizeLong(part, PRIMARY);
+
+ assertEquals(size, cacheAsync0.future().get());
+ }
+
+ for (int i = 0; i < HEAP_ENTRIES; i++) {
+ cache0.remove(i, String.valueOf(i));
+
+ final int size = HEAP_ENTRIES - i - 1;
+
+ assertEquals(size, cache0.localSize());
+ assertEquals(size, cache0.localSizeLong(part, PRIMARY));
+ assertEquals(size, cache0.localSizeLong(part, BACKUP));
+ assertEquals(size, cache0.localSizeLong(part, NEAR));
+ assertEquals(size, cache0.localSizeLong(part, ALL));
+
+ assertEquals(size, cache0.size());
+ assertEquals(size, cache0.sizeLong(part, PRIMARY));
+ assertEquals(size, cache0.sizeLong(part, BACKUP));
+ assertEquals(size, cache0.sizeLong(part, NEAR));
+ assertEquals(size, cache0.sizeLong(part, ALL));
+
+ cacheAsync0.size();
+
+ assertEquals(size, (long) cacheAsync0.<Integer>future().get());
+ }
+ }
+
+ /**
+ * @throws InterruptedException If failed.
+ */
+ public void testLocalPartitionSizeFlags() throws InterruptedException {
+ if (cacheMode() != LOCAL)
+ return;
+
+ awaitPartitionMapExchange();
+ checkEmpty();
+ int part = 0;
+ IgniteCache<Integer, String> cache0 = jcache(0);
+
+ Set<Integer> keys = new HashSet<>();
+
+ for (int i = 0; i < 200; i++) {
+ cache0.put(i, "test_val");
+
+ keys.add(i);
+ }
+
+ try {
+ int totalKeys = 200;
+
+ T2<Integer, Integer> swapKeys = swapKeysCount(0);
+
+ T2<Integer, Integer> offheapKeys = offheapKeysCount(0);
+
+ int totalSwap = swapKeys.get1() + swapKeys.get2();
+ int totalOffheap = offheapKeys.get1() + offheapKeys.get2();
+
+ log.info("Keys [total=" + totalKeys + ", offheap=" + offheapKeys + ", swap=" + swapKeys + ']');
+
+ assertTrue(totalSwap + totalOffheap < totalKeys);
+
+ assertEquals(totalKeys, cache0.localSize());
+ assertEquals(totalKeys, cache0.localSizeLong(part, ALL));
+
+ assertEquals(totalOffheap, cache0.localSizeLong(part, OFFHEAP));
+ assertEquals(totalSwap, cache0.localSizeLong(part, SWAP));
+ assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.localSizeLong(part, ONHEAP));
+
+ assertEquals(totalOffheap, cache0.sizeLong(part, OFFHEAP));
+ assertEquals(totalSwap, cache0.sizeLong(part, SWAP));
+ assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.sizeLong(part, ONHEAP));
+
+ assertEquals(totalOffheap, cache0.localSizeLong(part, OFFHEAP, PRIMARY));
+ assertEquals(totalSwap, cache0.localSizeLong(part, SWAP, PRIMARY));
+ assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.localSizeLong(part, ONHEAP, PRIMARY));
+
+ assertEquals(totalOffheap, cache0.localSizeLong(part, OFFHEAP, BACKUP));
+ assertEquals(totalSwap, cache0.localSizeLong(part, SWAP, BACKUP));
+ assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.localSizeLong(part, ONHEAP, BACKUP));
+ }
+ finally {
+ cache0.removeAll(keys);
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testNonLocalPartitionSize() throws Exception {
+ if (cacheMode() == LOCAL)
+ return;
+
+ awaitPartitionMapExchange(true, true);
+
+ checkEmpty();
+
+ for (int i = 0; i < gridCount(); i++) {
+ checkPartitionSizeAffinityFilter(i);
+ checkPartitionSizeStorageFilter(i);
+ }
+ }
+
+ /**
* @param nodeIdx Node index.
* @throws Exception If failed.
*/
@@ -627,6 +767,164 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
}
/**
+ * @param nodeIdx Node index.
+ * @throws Exception If failed.
+ */
+ private void checkPartitionSizeAffinityFilter(int nodeIdx) throws Exception {
+ IgniteCache<Integer, String> cache0 = jcache(nodeIdx);
+
+ final int PUT_KEYS = 10;
+
+ int part = nodeIdx;
+
+ List<Integer> keys = null;
+
+ try {
+ if (cacheMode() == REPLICATED) {
+ keys = backupKeys(cache0, 10, 0);
+
+ for (Integer key : keys)
+ cache0.put(key, String.valueOf(key));
+
+ int partSize = 0;
+
+ for (Integer key : keys){
+ int keyPart = ignite(nodeIdx).affinity(null).partition(key);
+ if (keyPart == part)
+ partSize++;
+ }
+
+ assertEquals(PUT_KEYS, cache0.localSize(BACKUP));
+ assertEquals(PUT_KEYS, cache0.localSize(ALL));
+ assertEquals(partSize, cache0.localSizeLong(part, BACKUP));
+ assertEquals(partSize, cache0.localSizeLong(part, ALL));
+ assertEquals(0, cache0.localSizeLong(part, PRIMARY));
+ assertEquals(0, cache0.localSizeLong(part, NEAR));
+
+ for (int i = 0; i < gridCount(); i++) {
+ IgniteCache<Integer, String> cache = jcache(i);
+ assertEquals(0, cache.size(NEAR));
+ assertEquals(partSize, cache.sizeLong(part, PRIMARY));
+ assertEquals(partSize * (gridCount() - 1), cache.sizeLong(part, BACKUP));
+ assertEquals(partSize * gridCount(), cache.sizeLong(part, PRIMARY, BACKUP));
+ assertEquals(partSize * gridCount(), cache.sizeLong(part, ALL)); // Primary + backups.
+ }
+ }
+ else {
+ keys = nearKeys(cache0, PUT_KEYS, 0);
+
+ for (Integer key : keys)
+ cache0.put(key, String.valueOf(key));
+
+ int partSize = 0;
+
+ for (Integer key :keys){
+ int keyPart = ignite(nodeIdx).affinity(null).partition(key);
+ if(keyPart == part)
+ partSize++;
+ }
+
+ if (hasNearCache()) {
+ assertEquals(0, cache0.localSize());
+ assertEquals(0, cache0.localSizeLong(part, ALL));
+ assertEquals(0, cache0.localSizeLong(part, NEAR));
+
+ for (int i = 0; i < gridCount(); i++) {
+ IgniteCache<Integer, String> cache = jcache(i);
+
+ assertEquals(0, cache.sizeLong(part, NEAR));
+ assertEquals(partSize, cache.sizeLong(part, BACKUP));
+ assertEquals(partSize * 2, cache.sizeLong(part, PRIMARY, BACKUP));
+ assertEquals(partSize * 2, cache.sizeLong(part, ALL)); // Primary + backups + near.
+ }
+ }
+ else {
+ assertEquals(0, cache0.localSize());
+ //assertEquals(partitionSize, cache0.localSizeLong(partition, ALL));
+ assertEquals(0, cache0.localSizeLong(part, NEAR));
+
+ for (int i = 0; i < gridCount(); i++) {
+ IgniteCache<Integer, String> cache = jcache(i);
+
+ assertEquals(0, cache.size(NEAR));
+ assertEquals(partSize, cache.sizeLong(part, BACKUP));
+ assertEquals(partSize * 2, cache.sizeLong(part, PRIMARY, BACKUP));
+ assertEquals(partSize * 2, cache.sizeLong(part, ALL)); // Primary + backups.
+ }
+ }
+
+ assertEquals(0, cache0.localSize(BACKUP));
+ assertEquals(0, cache0.localSize(PRIMARY));
+ }
+
+ checkPrimarySize(PUT_KEYS);
+
+ Affinity<Integer> aff = ignite(0).affinity(null);
+
+ for (int i = 0; i < gridCount(); i++) {
+ if (i == nodeIdx)
+ continue;
+
+ ClusterNode node = ignite(i).cluster().localNode();
+
+ int primary = 0;
+ int backups = 0;
+
+ for (Integer key : keys) {
+ if (aff.isPrimary(node, key) && aff.partition(key) == part)
+ primary++;
+ else if (aff.isBackup(node, key) && aff.partition(key) == part)
+ backups++;
+ }
+
+ IgniteCache<Integer, String> cache = jcache(i);
+
+ assertEquals(primary, cache.localSizeLong(part, PRIMARY));
+ assertEquals(backups, cache.localSizeLong(part, BACKUP));
+ assertEquals(primary + backups, cache.localSizeLong(part, PRIMARY, BACKUP));
+ assertEquals(primary + backups, cache.localSizeLong(part, BACKUP, PRIMARY));
+ assertEquals(primary + backups, cache.localSizeLong(part, ALL));
+ }
+
+ cache0.remove(keys.get(0));
+
+ keys.remove(0);
+
+ checkPrimarySize(PUT_KEYS - 1);
+
+ int primary = 0;
+ int backups = 0;
+
+ ClusterNode node = ignite(nodeIdx).cluster().localNode();
+
+ for (Integer key : keys) {
+ if (aff.isPrimary(node, key) && aff.partition(key) == part)
+ primary++;
+ else if (aff.isBackup(node, key) && aff.partition(key) == part)
+ backups++;
+ }
+
+ if (cacheMode() == REPLICATED) {
+ assertEquals(primary+backups, cache0.localSizeLong(part, ALL));
+ assertEquals(primary, cache0.localSizeLong(part, PRIMARY));
+ assertEquals(backups, cache0.localSizeLong(part, BACKUP));
+ }
+ else {
+ if (hasNearCache())
+ assertEquals(0, cache0.localSizeLong(part, ALL));
+ else
+ assertEquals(0, cache0.localSizeLong(part, ALL));
+ }
+ }
+ finally {
+ if (keys != null)
+ cache0.removeAll(new HashSet<>(keys));
+ }
+
+ checkEmpty();
+ }
+
+ /**
* Checks size is zero.
*/
private void checkEmpty() {
@@ -695,6 +993,31 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
/**
* @param nodeIdx Node index.
+ * @param part Cache partition
+ * @return Tuple with number of primary and backup keys (one or both will be zero).
+ */
+ private T2<Integer, Integer> swapKeysCount(int nodeIdx, int part) throws IgniteCheckedException {
+ GridCacheContext ctx = ((IgniteEx)ignite(nodeIdx)).context().cache().internalCache().context();
+ // Swap and offheap are disabled for near cache.
+ GridCacheSwapManager swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap();
+ //First count entries...
+ int cnt = (int)swapMgr.swapEntriesCount(part);
+
+ GridCacheAffinityManager affinity = ctx.affinity();
+ AffinityTopologyVersion topVer = affinity.affinityTopologyVersion();
+
+ //And then find out whether they are primary or backup ones.
+ int primaryCnt = 0;
+ int backupCnt = 0;
+ if (affinity.primary(ctx.localNode(), part, topVer))
+ primaryCnt = cnt;
+ else if (affinity.backup(ctx.localNode(), part, topVer))
+ backupCnt = cnt;
+ return new T2<>(primaryCnt, backupCnt);
+ }
+
+ /**
+ * @param nodeIdx Node index.
* @return Tuple with primary and backup keys.
*/
private T2<List<Integer>, List<Integer>> offheapKeys(int nodeIdx) {
@@ -742,6 +1065,31 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
/**
* @param nodeIdx Node index.
+ * @param part Cache partition.
+ * @return Tuple with number of primary and backup keys (one or both will be zero).
+ */
+ private T2<Integer, Integer> offheapKeysCount(int nodeIdx, int part) throws IgniteCheckedException {
+ GridCacheContext ctx = ((IgniteEx)ignite(nodeIdx)).context().cache().internalCache().context();
+ // Swap and offheap are disabled for near cache.
+ GridCacheSwapManager swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap();
+ //First count entries...
+ int cnt = (int)swapMgr.offheapEntriesCount(part);
+
+ GridCacheAffinityManager affinity = ctx.affinity();
+ AffinityTopologyVersion topVer = affinity.affinityTopologyVersion();
+
+ //And then find out whether they are primary or backup ones.
+ int primaryCnt = 0;
+ int backupCnt = 0;
+ if (affinity.primary(ctx.localNode(), part, topVer))
+ primaryCnt = cnt;
+ else if (affinity.backup(ctx.localNode(), part, topVer))
+ backupCnt = cnt;
+ return new T2<>(primaryCnt, backupCnt);
+ }
+
+ /**
+ * @param nodeIdx Node index.
* @throws Exception If failed.
*/
private void checkSizeStorageFilter(int nodeIdx) throws Exception {
@@ -862,6 +1210,119 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
}
/**
+ * @param nodeIdx Node index.
+ * @throws Exception If failed.
+ */
+ private void checkPartitionSizeStorageFilter(int nodeIdx) throws Exception {
+ IgniteCache<Integer, String> cache0 = jcache(nodeIdx);
+
+ int part = nodeIdx;
+
+ List<Integer> primaryKeys = primaryKeys(cache0, 100, 10_000);
+ List<Integer> backupKeys = backupKeys(cache0, 100, 10_000);
+
+ try {
+ final String val = "test_value";
+
+ for (int i = 0; i < 100; i++) {
+ cache0.put(primaryKeys.get(i), val);
+ cache0.put(backupKeys.get(i), val);
+ }
+
+
+ int totalKeys = 200;
+
+ T2<Integer, Integer> swapKeys = swapKeysCount(nodeIdx, part);
+
+ T2<Integer, Integer> offheapKeys = offheapKeysCount(nodeIdx, part);
+
+ int totalSwap = swapKeys.get1() + swapKeys.get2();
+ int totalOffheap = offheapKeys.get1() + offheapKeys.get2();
+
+ log.info("Local keys [total=" + totalKeys + ", offheap=" + offheapKeys + ", swap=" + swapKeys + ']');
+
+ assertTrue(totalSwap + totalOffheap < totalKeys);
+
+ assertEquals(primaryKeys.size(), cache0.localSize());
+ assertEquals(totalKeys, cache0.localSize(ALL));
+ assertEquals(totalOffheap, cache0.localSizeLong(part, PRIMARY, BACKUP, NEAR, OFFHEAP));
+ assertEquals(totalSwap, cache0.localSizeLong(part, PRIMARY, BACKUP, NEAR, SWAP));
+ assertEquals((long)swapKeys.get1(), cache0.localSizeLong(part, SWAP, PRIMARY));
+ assertEquals((long)swapKeys.get2(), cache0.localSizeLong(part, SWAP, BACKUP));
+
+ assertEquals((long)offheapKeys.get1(), cache0.localSizeLong(part, OFFHEAP, PRIMARY));
+ assertEquals((long)offheapKeys.get2(), cache0.localSizeLong(part, OFFHEAP, BACKUP));
+
+ assertEquals(swapKeys.get1() + offheapKeys.get1(), cache0.localSizeLong(part, SWAP, OFFHEAP, PRIMARY));
+ assertEquals(swapKeys.get2() + offheapKeys.get2(), cache0.localSizeLong(part, SWAP, OFFHEAP, BACKUP));
+
+ assertEquals(totalSwap + totalOffheap, cache0.localSizeLong(part, PRIMARY, BACKUP, NEAR, SWAP, OFFHEAP));
+
+ int globalParitionSwapPrimary = 0;
+ int globalPartSwapBackup = 0;
+
+ int globalPartOffheapPrimary = 0;
+ int globalPartOffheapBackup = 0;
+
+ for (int i = 0; i < gridCount(); i++) {
+ T2<Integer, Integer> swap = swapKeysCount(i, part);
+
+ globalParitionSwapPrimary += swap.get1();
+ globalPartSwapBackup += swap.get2();
+
+ T2<Integer, Integer> offheap = offheapKeysCount(i, part);
+
+ globalPartOffheapPrimary += offheap.get1();
+ globalPartOffheapBackup += offheap.get2();
+ }
+
+ int backups;
+
+ if (cacheMode() == LOCAL)
+ backups = 0;
+ else if (cacheMode() == PARTITIONED)
+ backups = 1;
+ else // REPLICATED.
+ backups = gridCount() - 1;
+
+ int globalTotal = totalKeys + totalKeys * backups;
+ int globalPartTotalSwap = globalParitionSwapPrimary + globalPartSwapBackup;
+ int globalPartTotalOffheap = globalPartOffheapPrimary + globalPartOffheapBackup;
+
+ log.info("Global keys [total=" + globalTotal +
+ ", offheap=" + globalPartTotalOffheap +
+ ", swap=" + globalPartTotalSwap + ']');
+
+ for (int i = 0; i < gridCount(); i++) {
+ IgniteCache<Integer, String> cache = jcache(i);
+
+ assertEquals(totalKeys, cache.size(PRIMARY));
+ assertEquals(globalTotal, cache.size(ALL));
+ assertEquals(globalTotal, cache.size(PRIMARY, BACKUP, NEAR, ONHEAP, OFFHEAP, SWAP));
+ assertEquals(globalTotal, cache.size(ONHEAP, OFFHEAP, SWAP, PRIMARY, BACKUP));
+
+ assertEquals(globalPartTotalSwap, cache.sizeLong(part, PRIMARY, BACKUP, NEAR, SWAP));
+ assertEquals(globalParitionSwapPrimary, cache.sizeLong(part, SWAP, PRIMARY));
+ assertEquals(globalPartSwapBackup, cache.sizeLong(part, SWAP, BACKUP));
+
+ assertEquals(globalPartTotalOffheap, cache.sizeLong(part, PRIMARY, BACKUP, NEAR, OFFHEAP));
+ assertEquals(globalPartOffheapPrimary, cache.sizeLong(part, OFFHEAP, PRIMARY));
+ assertEquals(globalPartOffheapBackup, cache.sizeLong(part, OFFHEAP, BACKUP));
+
+ assertEquals(globalPartTotalSwap + globalPartTotalOffheap, cache.sizeLong(part, PRIMARY, BACKUP, NEAR, SWAP, OFFHEAP));
+ assertEquals(globalParitionSwapPrimary + globalPartOffheapPrimary, cache.sizeLong(part, SWAP, OFFHEAP, PRIMARY));
+ assertEquals(globalPartSwapBackup + globalPartOffheapBackup, cache.sizeLong(part, SWAP, OFFHEAP, BACKUP));
+ }
+ }
+ finally {
+ cache0.removeAll(new HashSet<>(primaryKeys));
+ cache0.removeAll(new HashSet<>(backupKeys));
+ }
+
+ checkEmpty();
+ }
+
+ /**
* @param exp Expected size.
*/
private void checkPrimarySize(int exp) {
@@ -1167,4 +1628,4 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
assertTrue("Expected entries not found: " + allExp, allExp.isEmpty());
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/8af30781/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
index f2f69dd..36a56f5 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
@@ -207,6 +207,11 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
}
/** {@inheritDoc} */
+ @Override public long sizeLong(int partition, CachePeekMode... peekModes) throws CacheException {
+ return compute.call(new PartitionSizeLongTask(cacheName, isAsync, peekModes, partition, false));
+ }
+
+ /** {@inheritDoc} */
@Override public int localSize(CachePeekMode... peekModes) {
return compute.call(new SizeTask(cacheName, isAsync, peekModes, true));
}
@@ -217,6 +222,11 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
}
/** {@inheritDoc} */
+ @Override public long localSizeLong(int partition, CachePeekMode... peekModes) {
+ return compute.call(new PartitionSizeLongTask(cacheName, isAsync, peekModes, partition, true));
+ }
+
+ /** {@inheritDoc} */
@Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(
Map<? extends K, ? extends EntryProcessor<K, V, T>> map,
Object... args)
@@ -703,6 +713,40 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
/**
*
*/
+ private static class PartitionSizeLongTask extends CacheTaskAdapter<Void, Void, Long> {
+
+ /** Partition. */
+ int partition;
+
+ /** Peek modes. */
+ private final CachePeekMode[] peekModes;
+
+ /** Local. */
+ private final boolean loc;
+
+ /**
+ * @param cacheName Cache name.
+ * @param async Async.
+ * @param peekModes Peek modes.
+ * @param partition partition.
+ * @param loc Local.
+ */
+ public PartitionSizeLongTask(String cacheName, boolean async, CachePeekMode[] peekModes, int partition, boolean loc) {
+ super(cacheName, async, null);
+ this.loc = loc;
+ this.peekModes = peekModes;
+ this.partition = partition;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Long call() throws Exception {
+ return loc ? cache().localSizeLong(partition, peekModes) : cache().sizeLong(partition, peekModes);
+ }
+ }
+
+ /**
+ *
+ */
private static class GetTask<K, V> extends CacheTaskAdapter<K, V, V> {
/** Key. */
private final K key;
@@ -1499,4 +1543,4 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
return async ? cache.withAsync() : cache;
}
}
-}
\ No newline at end of file
+}
[06/33] ignite git commit: ignite-1088 Implemented store for multi
jvm tests (cherry picked from commit f91b699)
Posted by sb...@apache.org.
ignite-1088 Implemented store for multi jvm tests
(cherry picked from commit f91b699)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5b49dadd
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5b49dadd
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5b49dadd
Branch: refs/heads/ignite-3547
Commit: 5b49dadd3741ee7d4ec92eb97919b15bcbd33482
Parents: f045558
Author: sboikov <sb...@gridgain.com>
Authored: Fri Jul 1 12:16:56 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Thu Jul 7 12:38:15 2016 +0300
----------------------------------------------------------------------
.../cache/GridCacheAbstractMetricsSelfTest.java | 2 +-
.../GridCacheInterceptorAbstractSelfTest.java | 2 +-
.../processors/cache/H2CacheStoreStrategy.java | 468 +++++++++++++++++++
.../processors/cache/MapCacheStoreStrategy.java | 145 ++++++
.../cache/TestCacheStoreStrategy.java | 96 ++++
...edOffHeapTieredMultiNodeFullApiSelfTest.java | 2 +-
.../cache/IgniteCacheQueryIndexSelfTest.java | 2 +-
7 files changed, 713 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/5b49dadd/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
index 4c04df0..113a3b2 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
@@ -906,7 +906,7 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
}
// Avoid reloading from store.
- map.remove(key);
+ storeStgy.removeFromStore(key);
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@SuppressWarnings("unchecked")
http://git-wip-us.apache.org/repos/asf/ignite/blob/5b49dadd/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java
index f50a3e0..68bfb6f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java
@@ -1444,7 +1444,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst
interceptor.disabled = true;
if (storeEnabled())
- assertEquals("Unexpected store value", expVal, map.get(key));
+ assertEquals("Unexpected store value", expVal, storeStgy.getFromStore(key));
try {
for (int i = 0; i < gridCount(); i++)
http://git-wip-us.apache.org/repos/asf/ignite/blob/5b49dadd/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/H2CacheStoreStrategy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/H2CacheStoreStrategy.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/H2CacheStoreStrategy.java
new file mode 100644
index 0000000..ccb2994
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/H2CacheStoreStrategy.java
@@ -0,0 +1,468 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.StringReader;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Map;
+import javax.cache.Cache;
+import javax.cache.configuration.Factory;
+import javax.cache.integration.CacheLoaderException;
+import javax.cache.integration.CacheWriterException;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.cache.store.CacheStoreSession;
+import org.apache.ignite.cache.store.CacheStoreSessionListener;
+import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiInClosure;
+import org.apache.ignite.resources.CacheStoreSessionResource;
+import org.h2.jdbcx.JdbcConnectionPool;
+import org.h2.tools.RunScript;
+import org.h2.tools.Server;
+
+/**
+ * {@link TestCacheStoreStrategy} backed by H2 in-memory database.
+ */
+public class H2CacheStoreStrategy implements TestCacheStoreStrategy {
+ /** Pool to get {@link Connection}s from. */
+ private final JdbcConnectionPool dataSrc;
+
+ /** Script that creates CACHE table. */
+ private static final String CREATE_CACHE_TABLE =
+ "create table if not exists CACHE(k binary not null, v binary not null, PRIMARY KEY(k));";
+
+ /** Script that creates STATS table. */
+ private static final String CREATE_STATS_TABLES =
+ "create table if not exists READS(id bigint auto_increment);\n" +
+ "create table if not exists WRITES(id bigint auto_increment);\n" +
+ "create table if not exists REMOVES(id bigint auto_increment);";
+
+ /** Script that populates STATS table */
+ private static final String POPULATE_STATS_TABLE =
+ "delete from READS;\n" +
+ "delete from WRITES;\n" +
+ "delete from REMOVES;";
+
+
+ /**
+ * @throws IgniteCheckedException If failed.
+ */
+ public H2CacheStoreStrategy() throws IgniteCheckedException {
+ try {
+ Server.createTcpServer().start();
+ dataSrc = H2CacheStoreSessionListenerFactory.createDataSource();
+
+ try (Connection conn = connection()) {
+ RunScript.execute(conn, new StringReader(CREATE_CACHE_TABLE));
+ RunScript.execute(conn, new StringReader(CREATE_STATS_TABLES));
+ RunScript.execute(conn, new StringReader(POPULATE_STATS_TABLE));
+ }
+ }
+ catch (SQLException e) {
+ throw new IgniteCheckedException(e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public int getReads() {
+ return queryStats("reads");
+ }
+
+ /** {@inheritDoc} */
+ @Override public int getWrites() {
+ return queryStats("writes");
+ }
+
+ /** {@inheritDoc} */
+ @Override public int getRemoves() {
+ return queryStats("removes");
+ }
+
+ /**
+ * @param tbl Table name.
+ * @return Update statistics.
+ */
+ private int queryStats(String tbl) {
+ return querySingleInt("select count(*) from " + tbl, "Failed to query store stats [table=" + tbl + "]");
+ }
+
+ /** {@inheritDoc} */
+ @Override public int getStoreSize() {
+ return querySingleInt("select count(*) from CACHE;", "Failed to query number of rows from CACHE table");
+ }
+
+ /** {@inheritDoc} */
+ @Override public void resetStore() {
+ try (Connection conn = connection()) {
+ RunScript.execute(conn, new StringReader("delete from CACHE;"));
+ RunScript.execute(conn, new StringReader(POPULATE_STATS_TABLE));
+ }
+ catch (SQLException e) {
+ throw new IgniteException(e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void putToStore(Object key, Object val) {
+ Connection conn = null;
+ try {
+ conn = connection();
+ H2CacheStore.putToDb(conn, key, val);
+ }
+ catch (SQLException e) {
+ throw new IgniteException(e);
+ }
+ finally {
+ U.closeQuiet(conn);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void putAllToStore(Map<?, ?> data) {
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ try {
+ conn = connection();
+ stmt = conn.prepareStatement(H2CacheStore.MERGE);
+ for (Map.Entry<?, ?> e : data.entrySet()) {
+ stmt.setBinaryStream(1, new ByteArrayInputStream(H2CacheStore.serialize(e.getKey())));
+ stmt.setBinaryStream(2, new ByteArrayInputStream(H2CacheStore.serialize(e.getValue())));
+ stmt.addBatch();
+ }
+ stmt.executeBatch();
+ }
+ catch (SQLException e) {
+ throw new IgniteException(e);
+ }
+ finally {
+ U.closeQuiet(stmt);
+ U.closeQuiet(conn);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object getFromStore(Object key) {
+ Connection conn = null;
+ try {
+ conn = connection();
+ return H2CacheStore.getFromDb(conn, key);
+ }
+ catch (SQLException e) {
+ throw new IgniteException(e);
+ }
+ finally {
+ U.closeQuiet(conn);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void removeFromStore(Object key) {
+ Connection conn = null;
+ try {
+ conn = connection();
+ H2CacheStore.removeFromDb(conn, key);
+ }
+ catch (SQLException e) {
+ throw new IgniteException(e);
+ }
+ finally {
+ U.closeQuiet(conn);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isInStore(Object key) {
+ return getFromStore(key) != null;
+ }
+
+ /**
+ * @return New {@link Connection} from {@link #dataSrc}
+ * @throws SQLException if failed
+ */
+ private Connection connection() throws SQLException {
+ return dataSrc.getConnection();
+ }
+
+ /**
+ * Retrieves single int value from {@link ResultSet} returned by given query.
+ *
+ * @param qry Query string (fully populated, with params).
+ * @param errorMsg Message for {@link IgniteException} to bear in case of failure.
+ * @return Requested value
+ */
+ private int querySingleInt(String qry, String errorMsg) {
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ conn = connection();
+ stmt = conn.prepareStatement(qry);
+ rs = stmt.executeQuery();
+ if (rs.next())
+ return rs.getInt(1);
+ else
+ throw new IgniteException(errorMsg);
+ }
+ catch (SQLException e) {
+ throw new IgniteException(e);
+ }
+ finally {
+ U.closeQuiet(rs);
+ U.closeQuiet(stmt);
+ U.closeQuiet(conn);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void updateCacheConfiguration(CacheConfiguration<Object, Object> cfg) {
+ cfg.setCacheStoreSessionListenerFactories(new H2CacheStoreSessionListenerFactory());
+ }
+
+ /** {@inheritDoc} */
+ @Override public Factory<? extends CacheStore<Object, Object>> getStoreFactory() {
+ return new H2StoreFactory();
+ }
+
+ /** Serializable H2 backed cache store factory. */
+ public static class H2StoreFactory implements Factory<CacheStore<Object, Object>> {
+ /** {@inheritDoc} */
+ @Override public CacheStore<Object, Object> create() {
+ return new H2CacheStore();
+ }
+ }
+
+ /** Serializable {@link Factory} producing H2 backed {@link CacheStoreSessionListener}s. */
+ public static class H2CacheStoreSessionListenerFactory implements Factory<CacheStoreSessionListener> {
+ /**
+ * @return Connection pool
+ */
+ static JdbcConnectionPool createDataSource() {
+ JdbcConnectionPool pool = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:TestDb;LOCK_MODE=0", "sa", "");
+ pool.setMaxConnections(100);
+ return pool;
+ }
+
+ /** {@inheritDoc} */
+ @Override public CacheStoreSessionListener create() {
+ CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();
+ lsnr.setDataSource(createDataSource());
+ return lsnr;
+ }
+ }
+
+ /** H2 backed {@link CacheStoreAdapter} implementations */
+ public static class H2CacheStore extends CacheStoreAdapter<Object, Object> {
+ /** Store session */
+ @CacheStoreSessionResource
+ private CacheStoreSession ses;
+
+ /** Template for an insert statement */
+ private static final String MERGE = "merge into CACHE(k, v) values(?, ?);";
+
+ /** {@inheritDoc} */
+ @Override public void loadCache(IgniteBiInClosure<Object, Object> clo, Object... args) {
+ Connection conn = ses.attachment();
+ assert conn != null;
+
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery("select * from CACHE");
+ while (rs.next())
+ clo.apply(deserialize(rs.getBytes(1)), deserialize(rs.getBytes(2)));
+ }
+ catch (SQLException e) {
+ throw new IgniteException(e);
+ }
+ finally {
+ U.closeQuiet(rs);
+ U.closeQuiet(stmt);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object load(Object key) throws CacheLoaderException {
+ try {
+ Connection conn = ses.attachment();
+ Object res = getFromDb(conn, key);
+ updateStats("reads");
+ return res;
+ }
+ catch (SQLException e) {
+ throw new CacheLoaderException("Failed to load object [key=" + key + ']', e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(Cache.Entry<?, ?> entry) throws CacheWriterException {
+ try {
+ Connection conn = ses.attachment();
+ putToDb(conn, entry.getKey(), entry.getValue());
+ updateStats("writes");
+ }
+ catch (SQLException e) {
+ throw new CacheWriterException("Failed to write object [key=" + entry.getKey() + ", " +
+ "val=" + entry.getValue() + ']', e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void delete(Object key) throws CacheWriterException {
+ try {
+ Connection conn = ses.attachment();
+ removeFromDb(conn, key);
+ updateStats("removes");
+ }
+ catch (SQLException e) {
+ throw new CacheWriterException("Failed to delete object [key=" + key + ']', e);
+ }
+ }
+
+ /**
+ * Selects from H2 and deserialize from bytes the value pointed by key.
+ *
+ * @param conn {@link Connection} to use.
+ * @param key Key to look for.
+ * @return Stored object or null if the key is missing from DB.
+ * @throws SQLException If failed.
+ */
+ static Object getFromDb(Connection conn, Object key) throws SQLException {
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.prepareStatement("select v from CACHE where k = ?");
+ stmt.setBinaryStream(1, new ByteArrayInputStream(H2CacheStore.serialize(key)));
+ rs = stmt.executeQuery();
+ return rs.next() ? H2CacheStore.deserialize(rs.getBytes(1)) : null;
+ }
+ finally {
+ U.closeQuiet(rs);
+ U.closeQuiet(stmt);
+ }
+ }
+
+ /**
+ * Puts key-value pair to H2.
+ *
+ * @param conn {@link Connection} to use.
+ * @param key Key.
+ * @param val Value.
+ * @throws SQLException If failed.
+ */
+ static void putToDb(Connection conn, Object key, Object val) throws SQLException {
+ PreparedStatement stmt = null;
+ try {
+ stmt = conn.prepareStatement(H2CacheStore.MERGE);
+ stmt.setBinaryStream(1, new ByteArrayInputStream(H2CacheStore.serialize(key)));
+ stmt.setBinaryStream(2, new ByteArrayInputStream(H2CacheStore.serialize(val)));
+ stmt.executeUpdate();
+ }
+ finally {
+ U.closeQuiet(stmt);
+ }
+ }
+
+ /**
+ * Removes given key and its value from H2.
+ *
+ * @param conn {@link Connection} to invoke query upon.
+ * @param key Key to remove.
+ * @throws SQLException if failed.
+ */
+ static void removeFromDb(Connection conn, Object key) throws SQLException {
+ PreparedStatement stmt = null;
+ try {
+ stmt = conn.prepareStatement("delete from CACHE where k = ?");
+ stmt.setBinaryStream(1, new ByteArrayInputStream(H2CacheStore.serialize(key)));
+ stmt.executeUpdate();
+ }
+ finally {
+ U.closeQuiet(stmt);
+ }
+ }
+
+ /**
+ * Increments stored stats for given operation.
+ *
+ * @param tblName Table name
+ */
+ private void updateStats(String tblName) {
+ Connection conn = ses.attachment();
+ assert conn != null;
+ Statement stmt = null;
+ try {
+ stmt = conn.createStatement();
+ stmt.executeUpdate("insert into " + tblName + " default values");
+ }
+ catch (SQLException e) {
+ throw new IgniteException("Failed to update H2 store usage stats", e);
+ }
+ finally {
+ U.closeQuiet(stmt);
+ }
+ }
+
+ /**
+ * Turns given arbitrary object to byte array.
+ *
+ * @param obj Object to serialize
+ * @return Bytes representation of given object.
+ */
+ static byte[] serialize(Object obj) {
+ try (ByteArrayOutputStream b = new ByteArrayOutputStream()) {
+ try (ObjectOutputStream o = new ObjectOutputStream(b)) {
+ o.writeObject(obj);
+ }
+ return b.toByteArray();
+ }
+ catch (Exception e) {
+ throw new IgniteException("Failed to serialize object to byte array [obj=" + obj, e);
+ }
+ }
+
+ /**
+ * Deserializes an object from its byte array representation.
+ *
+ * @param bytes Byte array representation of the object.
+ * @return Deserialized object.
+ */
+ public static Object deserialize(byte[] bytes) {
+ try (ByteArrayInputStream b = new ByteArrayInputStream(bytes)) {
+ try (ObjectInputStream o = new ObjectInputStream(b)) {
+ return o.readObject();
+ }
+ }
+ catch (Exception e) {
+ throw new IgniteException("Failed to deserialize object from byte array", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5b49dadd/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/MapCacheStoreStrategy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/MapCacheStoreStrategy.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/MapCacheStoreStrategy.java
new file mode 100644
index 0000000..800d781
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/MapCacheStoreStrategy.java
@@ -0,0 +1,145 @@
+/*
+ * 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.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.Cache;
+import javax.cache.configuration.Factory;
+import javax.cache.configuration.FactoryBuilder;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.lang.IgniteBiInClosure;
+import org.jsr166.ConcurrentHashMap8;
+
+/**
+ * {@link TestCacheStoreStrategy} implemented as a wrapper around {@link #map}
+ */
+public class MapCacheStoreStrategy implements TestCacheStoreStrategy {
+ /** Removes counter. */
+ private final static AtomicInteger removes = new AtomicInteger();
+
+ /** Writes counter. */
+ private final static AtomicInteger writes = new AtomicInteger();
+
+ /** Reads counter. */
+ private final static AtomicInteger reads = new AtomicInteger();
+
+ /** Store map. */
+ private final static Map<Object, Object> map = new ConcurrentHashMap8<>();
+
+ /** {@inheritDoc} */
+ @Override public int getReads() {
+ return reads.get();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int getWrites() {
+ return writes.get();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int getRemoves() {
+ return removes.get();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int getStoreSize() {
+ return map.size();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void resetStore() {
+ map.clear();
+
+ reads.set(0);
+ writes.set(0);
+ removes.set(0);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void putToStore(Object key, Object val) {
+ map.put(key, val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void putAllToStore(Map<?, ?> data) {
+ map.putAll(data);
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object getFromStore(Object key) {
+ return map.get(key);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void removeFromStore(Object key) {
+ map.remove(key);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isInStore(Object key) {
+ return map.containsKey(key);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void updateCacheConfiguration(CacheConfiguration<Object, Object> cfg) {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public Factory<? extends CacheStore<Object, Object>> getStoreFactory() {
+ return FactoryBuilder.factoryOf(MapCacheStore.class);
+ }
+
+ /** Serializable {@link #map} backed cache store factory */
+ public static class MapStoreFactory implements Factory<CacheStore<Object, Object>> {
+ /** {@inheritDoc} */
+ @Override public CacheStore<Object, Object> create() {
+ return new MapCacheStore();
+ }
+ }
+
+ /** {@link CacheStore} backed by {@link #map} */
+ public static class MapCacheStore extends CacheStoreAdapter<Object, Object> {
+ /** {@inheritDoc} */
+ @Override public void loadCache(IgniteBiInClosure<Object, Object> clo, Object... args) {
+ for (Map.Entry<Object, Object> e : map.entrySet())
+ clo.apply(e.getKey(), e.getValue());
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object load(Object key) {
+ reads.incrementAndGet();
+ return map.get(key);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(Cache.Entry<?, ?> e) {
+ writes.incrementAndGet();
+ map.put(e.getKey(), e.getValue());
+ }
+
+ /** {@inheritDoc} */
+ @Override public void delete(Object key) {
+ removes.incrementAndGet();
+ map.remove(key);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5b49dadd/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/TestCacheStoreStrategy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/TestCacheStoreStrategy.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/TestCacheStoreStrategy.java
new file mode 100644
index 0000000..9ee174a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/TestCacheStoreStrategy.java
@@ -0,0 +1,96 @@
+/*
+ * 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.Map;
+import javax.cache.configuration.Factory;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.configuration.CacheConfiguration;
+
+/**
+ * Interface for cache store backend manipulation and stats routines.
+ */
+public interface TestCacheStoreStrategy {
+ /**
+ * @return Number of reads to store.
+ */
+ public int getReads();
+
+ /**
+ * @return Number of writes to store.
+ */
+ public int getWrites();
+
+ /**
+ * @return Number of removals from store.
+ */
+ public int getRemoves();
+
+ /**
+ * @return Total number of items in the store.
+ */
+ public int getStoreSize();
+
+ /**
+ * Clear store contents.
+ */
+ public void resetStore();
+
+ /**
+ * Put entry to cache store.
+ *
+ * @param key Key.
+ * @param val Value.
+ */
+ public void putToStore(Object key, Object val);
+
+ /**
+ * @param data Items to put to store.
+ */
+ public void putAllToStore(Map<?, ?> data);
+
+ /**
+ * @param key Key to look for.
+ * @return {@link Object} pointed to by given key or {@code null} if no object is present.
+ */
+ public Object getFromStore(Object key);
+
+ /**
+ * @param key to look for
+ */
+ public void removeFromStore(Object key);
+
+ /**
+ * @param key to look for.
+ * @return {@code True} if object pointed to by key is in store, false otherwise.
+ */
+ public boolean isInStore(Object key);
+
+ /**
+ * Called from {@link GridCacheAbstractSelfTest#cacheConfiguration(String)},
+ * this method allows implementations to tune cache config.
+ *
+ * @param cfg {@link CacheConfiguration} to tune.
+ */
+ public void updateCacheConfiguration(CacheConfiguration<Object, Object> cfg);
+
+ /**
+ * @return {@link Factory} for write-through storage emulator.
+ */
+ public Factory<? extends CacheStore<Object, Object>> getStoreFactory();
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5b49dadd/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest.java
index cbcc739..0386510 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest.java
@@ -68,6 +68,6 @@ public class GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest extends G
assertEquals(5, primaryCache.localPeek(key, CachePeekMode.ONHEAP).intValue());
assertNull(primaryCache.localPeek(key, CachePeekMode.OFFHEAP));
assertEquals(5, cache.get(key).intValue());
- assertEquals(5, map.get(key));
+ assertEquals(5, storeStgy.getFromStore(key));
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/5b49dadd/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryIndexSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryIndexSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryIndexSelfTest.java
index d834eb3..73b665e 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryIndexSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryIndexSelfTest.java
@@ -74,7 +74,7 @@ public class IgniteCacheQueryIndexSelfTest extends GridCacheAbstractSelfTest {
*/
public void testWithStoreLoad() throws Exception {
for (int i = 0; i < ENTRY_CNT; i++)
- putToStore(i, new CacheValue(i));
+ storeStgy.putToStore(i, new CacheValue(i));
IgniteCache<Integer, CacheValue> cache0 = grid(0).cache(null);
[15/33] ignite git commit: IGNITE-3055: IgniteDataStreamer can't be
timed out
Posted by sb...@apache.org.
IGNITE-3055: IgniteDataStreamer can't be timed out
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/10224dfe
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/10224dfe
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/10224dfe
Branch: refs/heads/ignite-3547
Commit: 10224dfee22b497bc671f878028881f99465a4c8
Parents: 06b24a9
Author: Vladislav Pyatkov <vl...@gmail.com>
Authored: Wed Jul 13 15:24:53 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Wed Jul 13 15:24:53 2016 +0300
----------------------------------------------------------------------
.../org/apache/ignite/IgniteDataStreamer.java | 52 +++++-
.../IgniteDataStreamerTimeoutException.java | 45 +++++
.../datastreamer/DataStreamerImpl.java | 71 ++++++--
.../ignite/internal/util/IgniteUtils.java | 21 +++
.../datastreamer/DataStreamerTimeoutTest.java | 163 +++++++++++++++++++
.../ignite/testsuites/IgniteCacheTestSuite.java | 2 +
6 files changed, 335 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/10224dfe/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java b/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
index 20d0057..887443f 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
@@ -96,6 +96,9 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
/** Default per node buffer size. */
public static final int DFLT_PER_NODE_BUFFER_SIZE = 1024;
+ /** Default timeout for streamer's operations. */
+ public static final long DFLT_UNLIMIT_TIMEOUT = -1;
+
/**
* Name of cache to stream data to.
*
@@ -198,6 +201,29 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
public void perNodeParallelOperations(int parallelOps);
/**
+ * Sets the timeout that is used in the following cases:
+ * <ul>
+ * <li>any data addition method can be blocked when all per node parallel operations are exhausted.
+ * The timeout defines the max time you will be blocked waiting for a permit to add a chunk of data
+ * into the streamer;</li>
+ * <li>Total timeout time for {@link #flush()} operation;</li>
+ * <li>Total timeout time for {@link #close()} operation.</li>
+ * </ul>
+ * By default the timeout is disabled.
+ *
+ * @param timeout Timeout in milliseconds.
+ * @throws IllegalArgumentException If {@param timeout} is zero or less than {@code -1}.
+ */
+ public void timeout(long timeout);
+
+ /**
+ * Gets timeout set by {@link #timeout(long)}.
+ *
+ * @return Timeout in milliseconds.
+ */
+ public long timeout();
+
+ /**
* Gets automatic flush frequency. Essentially, this is the time after which the
* streamer will make an attempt to submit all data added so far to remote nodes.
* Note that there is no guarantee that data will be delivered after this concrete
@@ -287,10 +313,11 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
* @throws IgniteInterruptedException If thread has been interrupted.
* @throws IllegalStateException If grid has been concurrently stopped or
* {@link #close(boolean)} has already been called on streamer.
+ * @throws IgniteDataStreamerTimeoutException If {@code timeout} is exceeded.
* @see #allowOverwrite()
*/
public IgniteFuture<?> addData(K key, @Nullable V val) throws CacheException, IgniteInterruptedException,
- IllegalStateException;
+ IllegalStateException, IgniteDataStreamerTimeoutException;
/**
* Adds data for streaming on remote node. This method can be called from multiple
@@ -310,10 +337,11 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
* @throws IgniteInterruptedException If thread has been interrupted.
* @throws IllegalStateException If grid has been concurrently stopped or
* {@link #close(boolean)} has already been called on streamer.
+ * @throws IgniteDataStreamerTimeoutException If {@code timeout} is exceeded.
* @see #allowOverwrite()
*/
public IgniteFuture<?> addData(Map.Entry<K, V> entry) throws CacheException, IgniteInterruptedException,
- IllegalStateException;
+ IllegalStateException, IgniteDataStreamerTimeoutException;
/**
* Adds data for streaming on remote node. This method can be called from multiple
@@ -330,10 +358,12 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
* @param entries Collection of entries to be streamed.
* @throws IllegalStateException If grid has been concurrently stopped or
* {@link #close(boolean)} has already been called on streamer.
+ * @throws IgniteDataStreamerTimeoutException If {@code timeout} is exceeded.
* @return Future for this stream operation.
* @see #allowOverwrite()
*/
- public IgniteFuture<?> addData(Collection<? extends Map.Entry<K, V>> entries) throws IllegalStateException;
+ public IgniteFuture<?> addData(Collection<? extends Map.Entry<K, V>> entries) throws IllegalStateException,
+ IgniteDataStreamerTimeoutException;
/**
* Adds data for streaming on remote node. This method can be called from multiple
@@ -350,10 +380,12 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
* @param entries Map to be streamed.
* @throws IllegalStateException If grid has been concurrently stopped or
* {@link #close(boolean)} has already been called on streamer.
+ * @throws IgniteDataStreamerTimeoutException If {@code timeout} is exceeded.
* @return Future for this stream operation.
* @see #allowOverwrite()
*/
- public IgniteFuture<?> addData(Map<K, V> entries) throws IllegalStateException;
+ public IgniteFuture<?> addData(Map<K, V> entries) throws IllegalStateException,
+ IgniteDataStreamerTimeoutException;
/**
* Streams any remaining data, but doesn't close the streamer. Data can be still added after
@@ -368,9 +400,11 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
* @throws IgniteInterruptedException If thread has been interrupted.
* @throws IllegalStateException If grid has been concurrently stopped or
* {@link #close(boolean)} has already been called on streamer.
+ * @throws IgniteDataStreamerTimeoutException If {@code timeout} is exceeded.
* @see #tryFlush()
*/
- public void flush() throws CacheException, IgniteInterruptedException, IllegalStateException;
+ public void flush() throws CacheException, IgniteInterruptedException, IllegalStateException,
+ IgniteDataStreamerTimeoutException;
/**
* Makes an attempt to stream remaining data. This method is mostly similar to {@link #flush},
@@ -390,8 +424,10 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
* @param cancel {@code True} to cancel ongoing streaming operations.
* @throws CacheException If failed to map key to node.
* @throws IgniteInterruptedException If thread has been interrupted.
+ * @throws IgniteDataStreamerTimeoutException If {@code timeout} is exceeded, only if {@param cancel} is {@code false}.
*/
- public void close(boolean cancel) throws CacheException, IgniteInterruptedException;
+ public void close(boolean cancel) throws CacheException, IgniteInterruptedException,
+ IgniteDataStreamerTimeoutException;
/**
* Closes data streamer. This method is identical to calling {@link #close(boolean) close(false)} method.
@@ -401,7 +437,9 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
*
* @throws CacheException If failed to close data streamer.
* @throws IgniteInterruptedException If thread has been interrupted.
+ * @throws IgniteDataStreamerTimeoutException If {@code timeout} is exceeded.
*/
- @Override public void close() throws CacheException, IgniteInterruptedException;
+ @Override public void close() throws CacheException, IgniteInterruptedException,
+ IgniteDataStreamerTimeoutException;
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/10224dfe/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamerTimeoutException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamerTimeoutException.java b/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamerTimeoutException.java
new file mode 100644
index 0000000..c6c7367
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamerTimeoutException.java
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+/**
+ * Exception is thrown when timeout of some {@link IgniteDataStreamer} operations occurs.
+ */
+public class IgniteDataStreamerTimeoutException extends IgniteException {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /**
+ * Creates new timeout exception with given error message.
+ *
+ * @param msg Error message.
+ */
+ public IgniteDataStreamerTimeoutException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Creates new timeout exception with given error message and optional nested exception.
+ *
+ * @param msg Error message.
+ * @param cause Optional nested exception (can be {@code null}).
+ */
+ public IgniteDataStreamerTimeoutException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/10224dfe/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
index 9dc6a7f..21df559 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
@@ -46,6 +46,7 @@ import org.apache.ignite.IgniteDataStreamer;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteInterruptedException;
import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.IgniteDataStreamerTimeoutException;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.cluster.ClusterTopologyException;
import org.apache.ignite.configuration.CacheConfiguration;
@@ -53,6 +54,7 @@ import org.apache.ignite.events.DiscoveryEvent;
import org.apache.ignite.events.Event;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException;
+import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
@@ -147,6 +149,9 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
private int parallelOps = DFLT_MAX_PARALLEL_OPS;
/** */
+ private long timeout = DFLT_UNLIMIT_TIMEOUT;
+
+ /** */
private long autoFlushFreq;
/** Mapping. */
@@ -453,6 +458,19 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
}
/** {@inheritDoc} */
+ @Override public void timeout(long timeout) {
+ if (timeout < -1 || timeout == 0)
+ throw new IllegalArgumentException();
+
+ this.timeout = timeout;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long timeout() {
+ return this.timeout;
+ }
+
+ /** {@inheritDoc} */
@Override public long autoFlushFrequency() {
return autoFlushFreq;
}
@@ -517,6 +535,9 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
return new IgniteCacheFutureImpl<>(resFut);
}
+ catch (IgniteDataStreamerTimeoutException e) {
+ throw e;
+ }
catch (IgniteException e) {
return new IgniteFinishedFutureImpl<>(e);
}
@@ -572,7 +593,7 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
catch (Throwable e) {
resFut.onDone(e);
- if (e instanceof Error)
+ if (e instanceof Error || e instanceof IgniteDataStreamerTimeoutException)
throw e;
return new IgniteFinishedFutureImpl<>(e);
@@ -854,9 +875,20 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
boolean err = false;
+ long startTimeMillis = U.currentTimeMillis();
+
for (IgniteInternalFuture fut = q.poll(); fut != null; fut = q.poll()) {
try {
- fut.get();
+ if (timeout == DFLT_UNLIMIT_TIMEOUT)
+ fut.get();
+ else {
+ long timeRemain = timeout - U.currentTimeMillis() + startTimeMillis;
+
+ if (timeRemain <= 0)
+ throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.");
+
+ fut.get(timeRemain);
+ }
}
catch (IgniteClientDisconnectedCheckedException e) {
if (log.isDebugEnabled())
@@ -864,6 +896,12 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
throw CU.convertToCacheException(e);
}
+ catch (IgniteFutureTimeoutCheckedException e) {
+ if (log.isDebugEnabled())
+ log.debug("Failed to flush buffer: " + e);
+
+ throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.", e);
+ }
catch (IgniteCheckedException e) {
if (log.isDebugEnabled())
log.debug("Failed to flush buffer: " + e);
@@ -976,8 +1014,6 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
if (log.isDebugEnabled())
log.debug("Closing data streamer [ldr=" + this + ", cancel=" + cancel + ']');
- IgniteCheckedException e = null;
-
try {
// Assuming that no methods are called on this loader after this method is called.
if (cancel) {
@@ -993,14 +1029,12 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
ctx.io().removeMessageListener(topic);
}
- catch (IgniteCheckedException e0) {
- e = e0;
+ catch (IgniteCheckedException | IgniteDataStreamerTimeoutException e) {
+ fut.onDone(e);
+ throw e;
}
- fut.onDone(null, e != null ? e : err);
-
- if (e != null)
- throw e;
+ fut.onDone(err);
}
/**
@@ -1242,7 +1276,15 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
* @throws IgniteInterruptedCheckedException If thread has been interrupted.
*/
private void incrementActiveTasks() throws IgniteInterruptedCheckedException {
- U.acquire(sem);
+ if (timeout == DFLT_UNLIMIT_TIMEOUT)
+ U.acquire(sem);
+ else
+ if (!U.tryAcquire(sem, timeout, TimeUnit.MILLISECONDS)) {
+ if (log.isDebugEnabled())
+ log.debug("Failed to add parallel operation.");
+
+ throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout when starts parallel operation.");
+ }
}
/**
@@ -1268,7 +1310,12 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
assert !entries.isEmpty();
assert curFut != null;
- incrementActiveTasks();
+ try {
+ incrementActiveTasks();
+ } catch (IgniteDataStreamerTimeoutException e) {
+ curFut.onDone(e);
+ throw e;
+ }
IgniteInternalFuture<Object> fut;
http://git-wip-us.apache.org/repos/asf/ignite/blob/10224dfe/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
index fa18923..08c9219 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
@@ -7447,6 +7447,27 @@ public abstract class IgniteUtils {
}
/**
+ * Tries to acquire a permit from provided semaphore during {@code timeout}.
+ *
+ * @param sem Semaphore.
+ * @param timeout The maximum time to wait.
+ * @param unit The unit of the {@code time} argument.
+ * @throws org.apache.ignite.internal.IgniteInterruptedCheckedException Wrapped {@link InterruptedException}.
+ * @return {@code True} if acquires a permit, {@code false} another.
+ */
+ public static boolean tryAcquire(Semaphore sem, long timeout, TimeUnit unit)
+ throws IgniteInterruptedCheckedException {
+ try {
+ return sem.tryAcquire(timeout, unit);
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+
+ throw new IgniteInterruptedCheckedException(e);
+ }
+ }
+
+ /**
* Gets cache attributes for the node.
*
* @param n Node to get cache attributes for.
http://git-wip-us.apache.org/repos/asf/ignite/blob/10224dfe/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerTimeoutTest.java
new file mode 100644
index 0000000..4e981b7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerTimeoutTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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.datastreamer;
+
+import java.util.Collection;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteDataStreamerTimeoutException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.stream.StreamReceiver;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ * Test timeout for Data streamer.
+ */
+public class DataStreamerTimeoutTest extends GridCommonAbstractTest {
+
+ /** Cache name. */
+ public static final String CACHE_NAME = "cacheName";
+
+ /** Timeout. */
+ public static final int TIMEOUT = 1_000;
+
+ /** Amount of entries. */
+ public static final int ENTRY_AMOUNT = 100;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setCacheConfiguration(cacheConfiguration());
+
+ return cfg;
+ }
+
+ /**
+ * Gets cache configuration.
+ *
+ * @return Cache configuration.
+ */
+ private CacheConfiguration cacheConfiguration() {
+ CacheConfiguration cacheCfg = defaultCacheConfiguration();
+
+ cacheCfg.setCacheMode(PARTITIONED);
+ cacheCfg.setBackups(1);
+ cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
+ cacheCfg.setName(CACHE_NAME);
+
+ return cacheCfg;
+ }
+
+ /**
+ * Test timeout on {@code DataStreamer.addData()} method
+ * @throws Exception If fail.
+ */
+ public void testTimeoutOnCloseMethod() throws Exception {
+ Ignite ignite = startGrid(1);
+
+ boolean thrown = false;
+
+ try (IgniteDataStreamer ldr = ignite.dataStreamer(CACHE_NAME)) {
+ ldr.timeout(TIMEOUT);
+ ldr.receiver(new TestDataReceiver());
+ ldr.perNodeBufferSize(ENTRY_AMOUNT);
+
+ for (int i=0; i < ENTRY_AMOUNT; i++)
+ ldr.addData(i, i);
+
+ }
+ catch (IgniteDataStreamerTimeoutException e) {
+ assertEquals(e.getMessage(), "Data streamer exceeded timeout on flush.");
+ thrown = true;
+ }
+ finally {
+ stopAllGrids();
+ }
+
+ assertTrue(thrown);
+ }
+
+ /**
+ * Test timeout on {@code DataStreamer.close()} method
+ * @throws Exception If fail.
+ */
+ public void testTimeoutOnAddDataMethod() throws Exception {
+ Ignite ignite = startGrid(1);
+
+ boolean thrown = false;
+
+ IgniteDataStreamer ldr = ignite.dataStreamer(CACHE_NAME);
+
+ try {
+ ldr.timeout(TIMEOUT);
+ ldr.receiver(new TestDataReceiver());
+ ldr.perNodeBufferSize(ENTRY_AMOUNT/2);
+ ldr.perNodeParallelOperations(1);
+
+ try {
+ for (int i=0; i < ENTRY_AMOUNT; i++)
+ ldr.addData(i, i);
+ }
+ catch (IgniteDataStreamerTimeoutException e) {
+ assertEquals(e.getMessage(), "Data streamer exceeded timeout when starts parallel operation.");
+
+ thrown = true;
+ }
+
+ }
+ finally {
+ if (thrown)
+ ldr.close(true);
+
+ stopAllGrids();
+ }
+
+ assertTrue(thrown);
+ }
+
+ /**
+ * Test receiver for timeout expiration emulation.
+ */
+ private static class TestDataReceiver implements StreamReceiver {
+
+ /** Is first. */
+ boolean isFirst = true;
+
+ /** {@inheritDoc} */
+ @Override public void receive(IgniteCache cache, Collection collection) throws IgniteException {
+ try {
+ if (isFirst)
+ U.sleep(2 * TIMEOUT);
+
+ isFirst = false;
+ }
+ catch (IgniteInterruptedCheckedException e) {
+ throw new IgniteException(e);
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/10224dfe/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index 33aae9a..0b9345d 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -138,6 +138,7 @@ import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSel
import org.apache.ignite.internal.processors.datastreamer.DataStreamerImplSelfTest;
import org.apache.ignite.internal.processors.datastreamer.DataStreamerMultiThreadedSelfTest;
import org.apache.ignite.internal.processors.datastreamer.DataStreamerMultinodeCreateCacheTest;
+import org.apache.ignite.internal.processors.datastreamer.DataStreamerTimeoutTest;
import org.apache.ignite.internal.processors.datastreamer.DataStreamerUpdateAfterLoadTest;
import org.apache.ignite.testframework.GridTestUtils;
@@ -244,6 +245,7 @@ public class IgniteCacheTestSuite extends TestSuite {
suite.addTestSuite(DataStreamerMultiThreadedSelfTest.class);
suite.addTestSuite(DataStreamerMultinodeCreateCacheTest.class);
suite.addTestSuite(DataStreamerImplSelfTest.class);
+ suite.addTestSuite(DataStreamerTimeoutTest.class);
GridTestUtils.addTestIfNeeded(suite, GridCacheEntryMemorySizeSelfTest.class, ignoredTests);
suite.addTestSuite(GridCacheClearAllSelfTest.class);
suite.addTestSuite(GridCacheObjectToStringSelfTest.class);
[22/33] ignite git commit: IGNITE-1849 minor fixes
Posted by sb...@apache.org.
IGNITE-1849 minor fixes
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5ae31fa3
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5ae31fa3
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5ae31fa3
Branch: refs/heads/ignite-3547
Commit: 5ae31fa39758780ac279d4c1b0179b84405c11ac
Parents: 6f7df5e
Author: Alexander Paschenko <al...@gmail.com>
Authored: Mon Jul 18 14:09:46 2016 +0300
Committer: Alexander Paschenko <al...@gmail.com>
Committed: Mon Jul 18 14:09:46 2016 +0300
----------------------------------------------------------------------
...IgniteCacheInternalEventsIgnoreSelfTest.java | 61 ++++++++++++++++++++
.../IgniteCacheInternalEventsIgnoreTest.java | 53 -----------------
.../testsuites/IgniteCacheTestSuite5.java | 4 +-
3 files changed, 63 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/5ae31fa3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreSelfTest.java
new file mode 100644
index 0000000..e14a600
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreSelfTest.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.concurrent.atomic.AtomicBoolean;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.events.Event;
+import org.apache.ignite.events.EventType;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class IgniteCacheInternalEventsIgnoreSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final AtomicBoolean evtFlag = new AtomicBoolean();
+
+ /**
+ * @throws Exception if failed.
+ */
+ public void testInternalEventsIgnore() throws Exception {
+ Ignite ignite = startGrid(1);
+ ignite.events().localListen(new EventListener(), EventType.EVT_TASK_STARTED, EventType.EVT_TASK_REDUCED,
+ EventType.EVT_TASK_FINISHED);
+ IgniteCache cache = ignite.createCache(defaultCacheConfiguration().setName("myTestCache"));
+ cache.size(CachePeekMode.ALL);
+ cache.sizeLong(CachePeekMode.ALL);
+
+ assertFalse(evtFlag.get());
+ }
+
+ /**
+ *
+ */
+ private static final class EventListener implements IgnitePredicate<Event> {
+ /** {@inheritDoc} */
+ @Override public boolean apply(Event e) {
+ evtFlag.set(true);
+
+ return true;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5ae31fa3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreTest.java
deleted file mode 100644
index e87206d..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreTest.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;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CachePeekMode;
-import org.apache.ignite.events.Event;
-import org.apache.ignite.events.EventType;
-import org.apache.ignite.lang.IgnitePredicate;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-/** */
-public class IgniteCacheInternalEventsIgnoreTest extends GridCommonAbstractTest {
- /** */
- private static final AtomicBoolean evtFlag = new AtomicBoolean();
-
- /** */
- public void testInternalEventsIgnore() throws Exception {
- Ignite ignite = startGrid(1);
- ignite.events().localListen(new EvtLsnr(), EventType.EVT_TASK_STARTED, EventType.EVT_TASK_REDUCED,
- EventType.EVT_TASK_FINISHED);
- IgniteCache cache = ignite.createCache(defaultCacheConfiguration().setName("myTestCache"));
- cache.size(CachePeekMode.ALL);
- cache.sizeLong(CachePeekMode.ALL);
- assertFalse(evtFlag.get());
- }
-
- /** */
- private static final class EvtLsnr implements IgnitePredicate<Event> {
- /** {@inheritDoc} */
- @Override public boolean apply(Event e) {
- evtFlag.set(true);
- return true;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5ae31fa3/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
index af54f91..0341502 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
@@ -21,7 +21,7 @@ import junit.framework.TestSuite;
import org.apache.ignite.internal.processors.cache.CacheNearReaderUpdateTest;
import org.apache.ignite.internal.processors.cache.CacheSerializableTransactionsTest;
import org.apache.ignite.internal.processors.cache.EntryVersionConsistencyReadThroughTest;
-import org.apache.ignite.internal.processors.cache.IgniteCacheInternalEventsIgnoreTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheInternalEventsIgnoreSelfTest;
import org.apache.ignite.internal.processors.cache.IgniteCachePutStackOverflowSelfTest;
import org.apache.ignite.internal.processors.cache.IgniteCacheStoreCollectionTest;
import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheTxIteratorSelfTest;
@@ -45,7 +45,7 @@ public class IgniteCacheTestSuite5 extends TestSuite {
suite.addTestSuite(IgniteCachePutStackOverflowSelfTest.class);
suite.addTestSuite(EntryVersionConsistencyReadThroughTest.class);
suite.addTestSuite(IgniteCacheTxIteratorSelfTest.class);
- suite.addTestSuite(IgniteCacheInternalEventsIgnoreTest.class);
+ suite.addTestSuite(IgniteCacheInternalEventsIgnoreSelfTest.class);
return suite;
}
[12/33] ignite git commit: ignite-3392 Added test.
Posted by sb...@apache.org.
ignite-3392 Added test.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a056954b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a056954b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a056954b
Branch: refs/heads/ignite-3547
Commit: a056954bbb179300716961c116b51492889db356
Parents: 762c43d
Author: sboikov <sb...@gridgain.com>
Authored: Wed Jul 13 12:29:33 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Jul 13 12:29:33 2016 +0300
----------------------------------------------------------------------
.../processors/service/GridServiceProxy.java | 54 ++++++-------
...rviceDeploymentExceptionPropagationTest.java | 80 ++++++++++++++++++++
2 files changed, 107 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/a056954b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProxy.java
index 25b2915..ba140f2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProxy.java
@@ -169,38 +169,38 @@ class GridServiceProxy<T> implements Serializable {
// If service is deployed locally, then execute locally.
if (node.isLocal()) {
- ServiceContextImpl svcCtx = ctx.service().serviceContext(name);
+ ServiceContextImpl svcCtx = ctx.service().serviceContext(name);
- if (svcCtx != null) {
- Service svc = svcCtx.service();
+ if (svcCtx != null) {
+ Service svc = svcCtx.service();
- if (svc != null)
- return mtd.invoke(svc, args);
+ if (svc != null)
+ return mtd.invoke(svc, args);
+ }
+ }
+ else {
+ // Execute service remotely.
+ return ctx.closure().callAsyncNoFailover(
+ BALANCE,
+ new ServiceProxyCallable(mtd.getName(), name, mtd.getParameterTypes(), args),
+ Collections.singleton(node),
+ false
+ ).get();
}
}
- else {
- // Execute service remotely.
- return ctx.closure().callAsyncNoFailover(
- BALANCE,
- new ServiceProxyCallable(mtd.getName(), name, mtd.getParameterTypes(), args),
- Collections.singleton(node),
- false
- ).get();
+ catch (GridServiceNotFoundException | ClusterTopologyCheckedException e) {
+ if (log.isDebugEnabled())
+ log.debug("Service was not found or topology changed (will retry): " + e.getMessage());
+ }
+ catch (RuntimeException | Error e) {
+ throw e;
+ }
+ catch (IgniteCheckedException e) {
+ throw U.convertException(e);
+ }
+ catch (Exception e) {
+ throw new IgniteException(e);
}
- }
- catch (GridServiceNotFoundException | ClusterTopologyCheckedException e) {
- if (log.isDebugEnabled())
- log.debug("Service was not found or topology changed (will retry): " + e.getMessage());
- }
- catch (RuntimeException | Error e) {
- throw e;
- }
- catch (IgniteCheckedException e) {
- throw U.convertException(e);
- }
- catch (Exception e) {
- throw new IgniteException(e);
- }
// If we are here, that means that service was not found
// or topology was changed. In this case, we erase the
http://git-wip-us.apache.org/repos/asf/ignite/blob/a056954b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceDeploymentExceptionPropagationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceDeploymentExceptionPropagationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceDeploymentExceptionPropagationTest.java
new file mode 100644
index 0000000..811594f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceDeploymentExceptionPropagationTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.service;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.services.Service;
+import org.apache.ignite.services.ServiceContext;
+import org.apache.ignite.testframework.GridStringLogger;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/** */
+public class GridServiceDeploymentExceptionPropagationTest extends GridCommonAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /** */
+ @SuppressWarnings("unused")
+ public void testExceptionPropagation() throws Exception {
+ try (Ignite srv = startGrid("server")) {
+
+ GridStringLogger log = new GridStringLogger();
+
+ try (Ignite client = startGrid("client", getConfiguration("client").setGridLogger(log).setClientMode(true))) {
+
+ try {
+ client.services().deployClusterSingleton("my-service", new ServiceImpl());
+ }
+ catch (IgniteException e) {
+ assertTrue(log.toString().contains("ServiceImpl init exception"));
+
+ return; // Exception is what we expect.
+ }
+
+ // Fail explicitly if we've managed to get here though we shouldn't have.
+ fail("https://issues.apache.org/jira/browse/IGNITE-3392");
+ }
+ }
+ }
+
+ /**
+ * Simple service implementation throwing an exception on init.
+ * Doesn't even try to do anything useful because what we're testing here is failure.
+ */
+ private static class ServiceImpl implements Service {
+ /** {@inheritDoc} */
+ @Override public void cancel(ServiceContext ctx) {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void init(ServiceContext ctx) throws Exception {
+ throw new RuntimeException("ServiceImpl init exception");
+ }
+
+ /** {@inheritDoc} */
+ @Override public void execute(ServiceContext ctx) throws Exception {
+ // No-op.
+ }
+ }
+}
[21/33] ignite git commit: Merge branch 'gridgain-7.5.30' into
ignite-1849
Posted by sb...@apache.org.
Merge branch 'gridgain-7.5.30' into ignite-1849
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6f7df5eb
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6f7df5eb
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6f7df5eb
Branch: refs/heads/ignite-3547
Commit: 6f7df5ebf77d338f524c4d055fcf21c717f93e1f
Parents: a33dd1c 4897315
Author: Alexander Paschenko <al...@gmail.com>
Authored: Mon Jul 18 13:58:32 2016 +0300
Committer: Alexander Paschenko <al...@gmail.com>
Committed: Mon Jul 18 13:58:32 2016 +0300
----------------------------------------------------------------------
.../examples/IndexingBridgeMethodTest.java | 93 +++++++
.../IgniteExamplesJ8SelfTestSuite.java | 2 +
.../org/apache/ignite/IgniteDataStreamer.java | 52 +++-
.../IgniteDataStreamerTimeoutException.java | 45 +++
.../configuration/CacheConfiguration.java | 3 +
.../processors/cache/GridCacheProcessor.java | 2 +
.../continuous/CacheContinuousQueryManager.java | 4 +-
.../datastreamer/DataStreamerImpl.java | 71 ++++-
.../service/GridServiceProcessor.java | 70 ++++-
.../processors/service/GridServiceProxy.java | 54 ++--
.../ignite/internal/util/IgniteUtils.java | 21 ++
.../OptimizedObjectStreamRegistry.java | 145 +++++-----
...eContinuousQueryMultiNodesFilteringTest.java | 278 +++++++++++++++++++
...dCacheContinuousQueryNodesFilteringTest.java | 168 +++++++++++
.../datastreamer/DataStreamerTimeoutTest.java | 163 +++++++++++
...rviceDeploymentExceptionPropagationTest.java | 80 ++++++
.../OptimizedMarshallerPooledSelfTest.java | 44 +++
.../testsuites/IgniteBinaryBasicTestSuite.java | 2 +
.../ignite/testsuites/IgniteCacheTestSuite.java | 2 +
.../IgniteMarshallerSelfTestSuite.java | 2 +
.../IgniteCacheQuerySelfTestSuite3.java | 4 +
.../ignite/visor/commands/VisorConsole.scala | 5 +-
.../commands/alert/VisorAlertCommand.scala | 2 +-
.../commands/cache/VisorCacheCommand.scala | 40 ++-
.../commands/cache/VisorCacheStopCommand.scala | 2 +-
.../config/VisorConfigurationCommand.scala | 23 +-
.../commands/events/VisorEventsCommand.scala | 29 +-
.../visor/commands/gc/VisorGcCommand.scala | 11 +-
.../visor/commands/kill/VisorKillCommand.scala | 184 ++++++++----
.../visor/commands/node/VisorNodeCommand.scala | 13 +-
.../visor/commands/vvm/VisorVvmCommand.scala | 11 +-
.../scala/org/apache/ignite/visor/visor.scala | 76 +++--
32 files changed, 1470 insertions(+), 231 deletions(-)
----------------------------------------------------------------------
[02/33] ignite git commit: Merge remote-tracking branch
'community/gridgain-7.5.29' into gridgain-7.5.29
Posted by sb...@apache.org.
Merge remote-tracking branch 'community/gridgain-7.5.29' into gridgain-7.5.29
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f52fb797
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f52fb797
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f52fb797
Branch: refs/heads/ignite-3547
Commit: f52fb797b61b5f870206e54795d379a8d023279b
Parents: 1b7428b 920005d
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Thu Jul 7 00:08:47 2016 -0700
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Thu Jul 7 00:08:47 2016 -0700
----------------------------------------------------------------------
.../apache/ignite/IgniteSystemProperties.java | 8 +-
.../apache/ignite/internal/IgniteKernal.java | 21 ++
.../processors/cache/GridCacheAdapter.java | 4 +
.../processors/cache/GridCacheIoManager.java | 150 +++++++++-
.../processors/cache/GridCacheMessage.java | 9 +
.../GridCachePartitionExchangeManager.java | 147 +++++++++-
.../cache/GridCacheSharedContext.java | 68 +++++
.../processors/cache/GridCacheUtils.java | 21 ++
.../distributed/GridCacheTxRecoveryFuture.java | 70 ++++-
.../distributed/GridCacheTxRecoveryRequest.java | 8 +
.../GridCacheTxRecoveryResponse.java | 8 +
.../distributed/GridDistributedLockRequest.java | 6 +
.../GridDistributedLockResponse.java | 6 +
.../GridDistributedTxFinishRequest.java | 7 +-
.../GridDistributedTxFinishResponse.java | 8 +
.../GridDistributedTxPrepareRequest.java | 6 +
.../GridDistributedTxPrepareResponse.java | 9 +-
.../GridDistributedUnlockRequest.java | 6 +
.../distributed/dht/GridDhtLockFuture.java | 52 ++--
.../dht/GridDhtTransactionalCacheAdapter.java | 77 ++++-
.../distributed/dht/GridDhtTxFinishFuture.java | 92 +++++-
.../cache/distributed/dht/GridDhtTxLocal.java | 27 +-
.../distributed/dht/GridDhtTxPrepareFuture.java | 124 +++++++-
.../dht/atomic/GridDhtAtomicCache.java | 137 ++++++---
.../GridDhtAtomicDeferredUpdateResponse.java | 7 +
.../dht/atomic/GridDhtAtomicUpdateFuture.java | 47 +++-
.../dht/atomic/GridDhtAtomicUpdateRequest.java | 6 +
.../dht/atomic/GridDhtAtomicUpdateResponse.java | 6 +
.../dht/atomic/GridNearAtomicUpdateFuture.java | 54 +++-
.../dht/atomic/GridNearAtomicUpdateRequest.java | 6 +
.../atomic/GridNearAtomicUpdateResponse.java | 6 +
.../dht/colocated/GridDhtColocatedCache.java | 10 +
.../colocated/GridDhtColocatedLockFuture.java | 71 +++--
.../GridDhtPartitionsExchangeFuture.java | 26 +-
.../near/GridNearOptimisticTxPrepareFuture.java | 32 +++
.../GridNearPessimisticTxPrepareFuture.java | 34 ++-
.../near/GridNearTxFinishFuture.java | 97 ++++++-
.../near/GridNearTxPrepareFutureAdapter.java | 7 +-
.../cache/transactions/IgniteTxHandler.java | 281 ++++++++++++++-----
.../processors/task/GridTaskWorker.java | 2 +-
.../util/nio/GridNioRecoveryDescriptor.java | 19 +-
.../ignite/internal/util/nio/GridNioServer.java | 50 +++-
.../util/nio/GridSelectorNioSessionImpl.java | 7 +
.../visor/compute/VisorGatewayTask.java | 3 +-
.../visor/node/VisorNodeDataCollectorTask.java | 26 --
.../communication/tcp/TcpCommunicationSpi.java | 167 +++++++----
.../resources/META-INF/classnames.properties | 78 ++++-
modules/core/src/test/config/log4j-test.xml | 6 +
...gniteCacheMessageRecoveryIdleConnection.java | 154 ++++++++++
.../ignite/testsuites/IgniteCacheTestSuite.java | 2 +
50 files changed, 1886 insertions(+), 389 deletions(-)
----------------------------------------------------------------------
[29/33] ignite git commit: IGNITE-3511: .NET: Fixed
AffinityFunctionBase.cs placement, added missing Package-Info.cs files.
Posted by sb...@apache.org.
IGNITE-3511: .NET: Fixed AffinityFunctionBase.cs placement, added missing Package-Info.cs files.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/448571ba
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/448571ba
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/448571ba
Branch: refs/heads/ignite-3547
Commit: 448571ba2ca1b05197b17a38d157babf4cb4f203
Parents: 7364938
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Jul 19 16:11:23 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Jul 19 16:11:23 2016 +0300
----------------------------------------------------------------------
.../Apache.Ignite.Core.csproj | 5 +-
.../Cache/Affinity/AffinityFunctionBase.cs | 139 ------------------
.../Cache/Affinity/Fair/FairAffinityFunction.cs | 1 +
.../Cache/Affinity/Fair/Package-Info.cs | 26 ++++
.../Cache/Affinity/Package-Info.cs | 26 ++++
.../Cache/Affinity/Rendezvous/Package-Info.cs | 26 ++++
.../Rendezvous/RendezvousAffinityFunction.cs | 1 +
.../Impl/Cache/Affinity/AffinityFunctionBase.cs | 140 +++++++++++++++++++
8 files changed, 224 insertions(+), 140 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/448571ba/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
index 6793873..3736988 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
@@ -55,11 +55,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Binary\Package-Info.cs" />
- <Compile Include="Cache\Affinity\AffinityFunctionBase.cs" />
<Compile Include="Cache\Affinity\AffinityFunctionContext.cs" />
<Compile Include="Cache\Affinity\AffinityTopologyVersion.cs" />
<Compile Include="Cache\Affinity\Fair\FairAffinityFunction.cs" />
+ <Compile Include="Cache\Affinity\Fair\Package-Info.cs" />
+ <Compile Include="Cache\Affinity\Rendezvous\Package-Info.cs" />
<Compile Include="Cache\Affinity\IAffinityFunction.cs" />
+ <Compile Include="Cache\Affinity\Package-Info.cs" />
<Compile Include="Cache\Affinity\Rendezvous\RendezvousAffinityFunction.cs" />
<Compile Include="Cache\CacheAtomicUpdateTimeoutException.cs" />
<Compile Include="Cache\CacheEntryProcessorException.cs" />
@@ -114,6 +116,7 @@
<Compile Include="Common\IgniteFutureCancelledException.cs" />
<Compile Include="Common\IgniteGuid.cs" />
<Compile Include="Common\Package-Info.cs" />
+ <Compile Include="Impl\Cache\Affinity\AffinityFunctionBase.cs" />
<Compile Include="Impl\Cache\Affinity\AffinityFunctionSerializer.cs" />
<Compile Include="Impl\Cache\Affinity\PlatformAffinityFunction.cs" />
<Compile Include="Impl\Cache\Event\JavaCacheEntryEventFilter.cs" />
http://git-wip-us.apache.org/repos/asf/ignite/blob/448571ba/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionBase.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionBase.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionBase.cs
deleted file mode 100644
index ce2e5e1..0000000
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionBase.cs
+++ /dev/null
@@ -1,139 +0,0 @@
-\ufeff/*
- * 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.
- */
-
-namespace Apache.Ignite.Core.Cache.Affinity
-{
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using Apache.Ignite.Core.Cluster;
- using Apache.Ignite.Core.Common;
-
- /// <summary>
- /// Base class for predefined affinity functions.
- /// </summary>
- [Serializable]
- public abstract class AffinityFunctionBase : IAffinityFunction
- {
- /// <summary> The default value for <see cref="Partitions"/> property. </summary>
- public const int DefaultPartitions = 1024;
-
- /** */
- private int _partitions = DefaultPartitions;
-
- /** */
- private IAffinityFunction _baseFunction;
-
-
- /// <summary>
- /// Gets or sets the total number of partitions.
- /// </summary>
- [DefaultValue(DefaultPartitions)]
- public virtual int Partitions
- {
- get { return _partitions; }
- set { _partitions = value; }
- }
-
- /// <summary>
- /// Gets partition number for a given key starting from 0. Partitioned caches
- /// should make sure that keys are about evenly distributed across all partitions
- /// from 0 to <see cref="Partitions" /> for best performance.
- /// <para />
- /// Note that for fully replicated caches it is possible to segment key sets among different
- /// grid node groups. In that case each node group should return a unique partition
- /// number. However, unlike partitioned cache, mappings of keys to nodes in
- /// replicated caches are constant and a node cannot migrate from one partition
- /// to another.
- /// </summary>
- /// <param name="key">Key to get partition for.</param>
- /// <returns>
- /// Partition number for a given key.
- /// </returns>
- public virtual int GetPartition(object key)
- {
- ThrowIfUninitialized();
-
- return _baseFunction.GetPartition(key);
- }
-
- /// <summary>
- /// Removes node from affinity. This method is called when it is safe to remove
- /// disconnected node from affinity mapping.
- /// </summary>
- /// <param name="nodeId">The node identifier.</param>
- public virtual void RemoveNode(Guid nodeId)
- {
- ThrowIfUninitialized();
-
- _baseFunction.RemoveNode(nodeId);
- }
-
- /// <summary>
- /// Gets affinity nodes for a partition. In case of replicated cache, all returned
- /// nodes are updated in the same manner. In case of partitioned cache, the returned
- /// list should contain only the primary and back up nodes with primary node being
- /// always first.
- /// <pare />
- /// Note that partitioned affinity must obey the following contract: given that node
- /// <code>N</code> is primary for some key <code>K</code>, if any other node(s) leave
- /// grid and no node joins grid, node <code>N</code> will remain primary for key <code>K</code>.
- /// </summary>
- /// <param name="context">The affinity function context.</param>
- /// <returns>
- /// A collection of partitions, where each partition is a collection of nodes,
- /// where first node is a primary node, and other nodes are backup nodes.
- /// </returns>
- public virtual IEnumerable<IEnumerable<IClusterNode>> AssignPartitions(AffinityFunctionContext context)
- {
- ThrowIfUninitialized();
-
- return _baseFunction.AssignPartitions(context);
- }
-
- /// <summary>
- /// Gets or sets a value indicating whether to exclude same-host-neighbors from being backups of each other.
- /// </summary>
- public virtual bool ExcludeNeighbors { get; set; }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AffinityFunctionBase"/> class.
- /// </summary>
- internal AffinityFunctionBase()
- {
- // No-op.
- }
-
- /// <summary>
- /// Sets the base function.
- /// </summary>
- /// <param name="baseFunc">The base function.</param>
- internal void SetBaseFunction(IAffinityFunction baseFunc)
- {
- _baseFunction = baseFunc;
- }
-
- /// <summary>
- /// Gets the direct usage error.
- /// </summary>
- private void ThrowIfUninitialized()
- {
- if (_baseFunction == null)
- throw new IgniteException(GetType() + " has not yet been initialized.");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/448571ba/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/FairAffinityFunction.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/FairAffinityFunction.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/FairAffinityFunction.cs
index 4a3885f..f06937d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/FairAffinityFunction.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/FairAffinityFunction.cs
@@ -18,6 +18,7 @@
namespace Apache.Ignite.Core.Cache.Affinity.Fair
{
using System;
+ using Apache.Ignite.Core.Impl.Cache.Affinity;
/// <summary>
/// Fair affinity function which tries to ensure that all nodes get equal number of partitions with
http://git-wip-us.apache.org/repos/asf/ignite/blob/448571ba/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/Package-Info.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/Package-Info.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/Package-Info.cs
new file mode 100644
index 0000000..3bcaa59
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/Package-Info.cs
@@ -0,0 +1,26 @@
+\ufeff/*
+* 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.
+*/
+
+#pragma warning disable 1587 // invalid XML comment
+
+/// <summary>
+/// Fair affinity functionality.
+/// </summary>
+namespace Apache.Ignite.Core.Cache.Affinity.Fair
+{
+ // No-op.
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/448571ba/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Package-Info.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Package-Info.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Package-Info.cs
new file mode 100644
index 0000000..dfbdf08
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Package-Info.cs
@@ -0,0 +1,26 @@
+\ufeff/*
+* 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.
+*/
+
+#pragma warning disable 1587 // invalid XML comment
+
+/// <summary>
+/// Cache affinity API.
+/// </summary>
+namespace Apache.Ignite.Core.Cache.Affinity
+{
+ // No-op.
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/448571ba/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/Package-Info.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/Package-Info.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/Package-Info.cs
new file mode 100644
index 0000000..d3f5ef0
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/Package-Info.cs
@@ -0,0 +1,26 @@
+\ufeff/*
+* 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.
+*/
+
+#pragma warning disable 1587 // invalid XML comment
+
+/// <summary>
+/// Rendezvous affinity functionality.
+/// </summary>
+namespace Apache.Ignite.Core.Cache.Affinity.Rendezvous
+{
+ // No-op.
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/448571ba/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/RendezvousAffinityFunction.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/RendezvousAffinityFunction.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/RendezvousAffinityFunction.cs
index 98ec364..928324c 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/RendezvousAffinityFunction.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/RendezvousAffinityFunction.cs
@@ -18,6 +18,7 @@
namespace Apache.Ignite.Core.Cache.Affinity.Rendezvous
{
using System;
+ using Apache.Ignite.Core.Impl.Cache.Affinity;
/// <summary>
/// Affinity function for partitioned cache based on Highest Random Weight algorithm.
http://git-wip-us.apache.org/repos/asf/ignite/blob/448571ba/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/AffinityFunctionBase.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/AffinityFunctionBase.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/AffinityFunctionBase.cs
new file mode 100644
index 0000000..8536e4c
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/AffinityFunctionBase.cs
@@ -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.
+ */
+
+namespace Apache.Ignite.Core.Impl.Cache.Affinity
+{
+ using System;
+ using System.Collections.Generic;
+ using System.ComponentModel;
+ using Apache.Ignite.Core.Cache.Affinity;
+ using Apache.Ignite.Core.Cluster;
+ using Apache.Ignite.Core.Common;
+
+ /// <summary>
+ /// Base class for predefined affinity functions.
+ /// </summary>
+ [Serializable]
+ public abstract class AffinityFunctionBase : IAffinityFunction
+ {
+ /// <summary> The default value for <see cref="Partitions"/> property. </summary>
+ public const int DefaultPartitions = 1024;
+
+ /** */
+ private int _partitions = DefaultPartitions;
+
+ /** */
+ private IAffinityFunction _baseFunction;
+
+
+ /// <summary>
+ /// Gets or sets the total number of partitions.
+ /// </summary>
+ [DefaultValue(DefaultPartitions)]
+ public virtual int Partitions
+ {
+ get { return _partitions; }
+ set { _partitions = value; }
+ }
+
+ /// <summary>
+ /// Gets partition number for a given key starting from 0. Partitioned caches
+ /// should make sure that keys are about evenly distributed across all partitions
+ /// from 0 to <see cref="Partitions" /> for best performance.
+ /// <para />
+ /// Note that for fully replicated caches it is possible to segment key sets among different
+ /// grid node groups. In that case each node group should return a unique partition
+ /// number. However, unlike partitioned cache, mappings of keys to nodes in
+ /// replicated caches are constant and a node cannot migrate from one partition
+ /// to another.
+ /// </summary>
+ /// <param name="key">Key to get partition for.</param>
+ /// <returns>
+ /// Partition number for a given key.
+ /// </returns>
+ public virtual int GetPartition(object key)
+ {
+ ThrowIfUninitialized();
+
+ return _baseFunction.GetPartition(key);
+ }
+
+ /// <summary>
+ /// Removes node from affinity. This method is called when it is safe to remove
+ /// disconnected node from affinity mapping.
+ /// </summary>
+ /// <param name="nodeId">The node identifier.</param>
+ public virtual void RemoveNode(Guid nodeId)
+ {
+ ThrowIfUninitialized();
+
+ _baseFunction.RemoveNode(nodeId);
+ }
+
+ /// <summary>
+ /// Gets affinity nodes for a partition. In case of replicated cache, all returned
+ /// nodes are updated in the same manner. In case of partitioned cache, the returned
+ /// list should contain only the primary and back up nodes with primary node being
+ /// always first.
+ /// <pare />
+ /// Note that partitioned affinity must obey the following contract: given that node
+ /// <code>N</code> is primary for some key <code>K</code>, if any other node(s) leave
+ /// grid and no node joins grid, node <code>N</code> will remain primary for key <code>K</code>.
+ /// </summary>
+ /// <param name="context">The affinity function context.</param>
+ /// <returns>
+ /// A collection of partitions, where each partition is a collection of nodes,
+ /// where first node is a primary node, and other nodes are backup nodes.
+ /// </returns>
+ public virtual IEnumerable<IEnumerable<IClusterNode>> AssignPartitions(AffinityFunctionContext context)
+ {
+ ThrowIfUninitialized();
+
+ return _baseFunction.AssignPartitions(context);
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether to exclude same-host-neighbors from being backups of each other.
+ /// </summary>
+ public virtual bool ExcludeNeighbors { get; set; }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AffinityFunctionBase"/> class.
+ /// </summary>
+ internal AffinityFunctionBase()
+ {
+ // No-op.
+ }
+
+ /// <summary>
+ /// Sets the base function.
+ /// </summary>
+ /// <param name="baseFunc">The base function.</param>
+ internal void SetBaseFunction(IAffinityFunction baseFunc)
+ {
+ _baseFunction = baseFunc;
+ }
+
+ /// <summary>
+ /// Gets the direct usage error.
+ /// </summary>
+ private void ThrowIfUninitialized()
+ {
+ if (_baseFunction == null)
+ throw new IgniteException(GetType() + " has not yet been initialized.");
+ }
+ }
+}
[19/33] ignite git commit: Merge branch 'gridgain-7.5.30' of
https://github.com/gridgain/apache-ignite into gridgain-7.5.30
Posted by sb...@apache.org.
Merge branch 'gridgain-7.5.30' of https://github.com/gridgain/apache-ignite into gridgain-7.5.30
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6389400a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6389400a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6389400a
Branch: refs/heads/ignite-3547
Commit: 6389400a91f1fc95c9b55e78ab8eef55f99b1093
Parents: 2537e0f 27f6c58
Author: Denis Magda <dm...@gridgain.com>
Authored: Fri Jul 15 09:35:57 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Fri Jul 15 09:35:57 2016 +0300
----------------------------------------------------------------------
.../examples/IndexingBridgeMethodTest.java | 93 ++++++++++++
.../IgniteExamplesJ8SelfTestSuite.java | 2 +
.../configuration/CacheConfiguration.java | 3 +
.../OptimizedObjectStreamRegistry.java | 145 +++++++++++--------
.../OptimizedMarshallerPooledSelfTest.java | 44 ++++++
.../testsuites/IgniteBinaryBasicTestSuite.java | 2 +
.../IgniteMarshallerSelfTestSuite.java | 2 +
7 files changed, 228 insertions(+), 63 deletions(-)
----------------------------------------------------------------------
[18/33] ignite git commit: IgniteDataStreamer: fixed JavaDoc
Posted by sb...@apache.org.
IgniteDataStreamer: fixed JavaDoc
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2537e0f6
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2537e0f6
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2537e0f6
Branch: refs/heads/ignite-3547
Commit: 2537e0f62a1a1ecba315b18f4ed9bf38ff99d5df
Parents: 10224df
Author: Denis Magda <dm...@gridgain.com>
Authored: Fri Jul 15 09:35:41 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Fri Jul 15 09:35:41 2016 +0300
----------------------------------------------------------------------
.../core/src/main/java/org/apache/ignite/IgniteDataStreamer.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/2537e0f6/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java b/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
index 887443f..472c5e4 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
@@ -212,7 +212,7 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
* By default the timeout is disabled.
*
* @param timeout Timeout in milliseconds.
- * @throws IllegalArgumentException If {@param timeout} is zero or less than {@code -1}.
+ * @throws IllegalArgumentException If timeout is zero or less than {@code -1}.
*/
public void timeout(long timeout);
@@ -424,7 +424,7 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
* @param cancel {@code True} to cancel ongoing streaming operations.
* @throws CacheException If failed to map key to node.
* @throws IgniteInterruptedException If thread has been interrupted.
- * @throws IgniteDataStreamerTimeoutException If {@code timeout} is exceeded, only if {@param cancel} is {@code false}.
+ * @throws IgniteDataStreamerTimeoutException If {@code timeout} is exceeded, only if cancel is {@code false}.
*/
public void close(boolean cancel) throws CacheException, IgniteInterruptedException,
IgniteDataStreamerTimeoutException;
[26/33] ignite git commit: GG-11293: .NET: Backported affinity
functions feature to 7.5.30.
Posted by sb...@apache.org.
GG-11293: .NET: Backported affinity functions feature to 7.5.30.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5f57cc8d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5f57cc8d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5f57cc8d
Branch: refs/heads/ignite-3547
Commit: 5f57cc8d703f9e8f749c9e3c403781365642dc3a
Parents: 78d7c13
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Jul 19 14:34:35 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Jul 19 14:34:35 2016 +0300
----------------------------------------------------------------------
.../internal/binary/GridBinaryMarshaller.java | 11 +-
.../GridAffinityFunctionContextImpl.java | 9 +
.../processors/cache/GridCacheProcessor.java | 65 +++--
.../affinity/PlatformAffinityFunction.java | 277 +++++++++++++++++++
.../PlatformAffinityFunctionTarget.java | 113 ++++++++
.../cache/affinity/PlatformAffinityUtils.java | 116 ++++++++
.../callback/PlatformCallbackGateway.java | 89 ++++++
.../callback/PlatformCallbackUtils.java | 49 ++++
.../PlatformDotNetConfigurationClosure.java | 115 +++++++-
.../dotnet/PlatformDotNetAffinityFunction.java | 171 ++++++++++++
.../cpp/common/include/ignite/common/java.h | 18 ++
modules/platforms/cpp/common/src/java.cpp | 36 ++-
.../Apache.Ignite.Core.Tests.csproj | 9 +-
.../Affinity/AffinityFunctionSpringTest.cs | 184 ++++++++++++
.../Config/Cache/Affinity/affinity-function.xml | 129 +++++++++
.../Cache/Affinity/affinity-function2.xml | 49 ++++
.../Apache.Ignite.Core.Tests/TestRunner.cs | 3 +-
.../Apache.Ignite.Core.csproj | 11 +-
.../Cache/Affinity/AffinityFunctionBase.cs | 139 ++++++++++
.../Cache/Affinity/AffinityFunctionContext.cs | 120 ++++++++
.../Cache/Affinity/AffinityTopologyVersion.cs | 138 +++++++++
.../Cache/Affinity/Fair/FairAffinityFunction.cs | 32 +++
.../Cache/Affinity/IAffinityFunction.cs | 82 ++++++
.../Rendezvous/RendezvousAffinityFunction.cs | 31 +++
.../Apache.Ignite.Core/Events/EventReader.cs | 8 +-
.../dotnet/Apache.Ignite.Core/Ignition.cs | 38 ++-
.../Impl/Binary/BinaryReaderExtensions.cs | 14 +
.../Impl/Binary/Marshaller.cs | 6 +-
.../Affinity/AffinityFunctionSerializer.cs | 277 +++++++++++++++++++
.../Cache/Affinity/PlatformAffinityFunction.cs | 74 +++++
.../Impl/Common/ObjectInfoHolder.cs | 86 ++++++
.../Apache.Ignite.Core/Impl/IgniteUtils.cs | 10 +-
.../Impl/Unmanaged/UnmanagedCallbackHandlers.cs | 6 +
.../Impl/Unmanaged/UnmanagedCallbacks.cs | 133 ++++++++-
34 files changed, 2596 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
index 535207c..3a3dfd1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
@@ -305,6 +305,15 @@ public class GridBinaryMarshaller {
/**
* Push binary context and return the old one.
*
+ * @return Old binary context.
+ */
+ public BinaryContext pushContext() {
+ return pushContext(ctx);
+ }
+
+ /**
+ * Push binary context and return the old one.
+ *
* @param ctx Binary context.
* @return Old binary context.
*/
@@ -321,7 +330,7 @@ public class GridBinaryMarshaller {
*
* @param oldCtx Old binary context.
*/
- private static void popContext(@Nullable BinaryContext oldCtx) {
+ public static void popContext(@Nullable BinaryContext oldCtx) {
if (oldCtx == null)
BINARY_CTX.remove();
else
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityFunctionContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityFunctionContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityFunctionContextImpl.java
index 6c97efd..4ddee00 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityFunctionContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityFunctionContextImpl.java
@@ -80,4 +80,13 @@ public class GridAffinityFunctionContextImpl implements AffinityFunctionContext
@Override public int backups() {
return backups;
}
+
+ /**
+ * Gets the previous assignment.
+ *
+ * @return Previous assignment.
+ */
+ public List<List<ClusterNode>> prevAssignment() {
+ return prevAssignment;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 6484d4d..6761fac 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
@@ -69,10 +69,13 @@ import org.apache.ignite.internal.IgniteComponentType;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.IgniteNodeAttributes;
import org.apache.ignite.internal.IgniteTransactionsEx;
+import org.apache.ignite.internal.binary.BinaryContext;
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.processors.GridProcessorAdapter;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
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;
@@ -94,12 +97,14 @@ import org.apache.ignite.internal.processors.cache.store.CacheStoreManager;
import org.apache.ignite.internal.processors.cache.transactions.IgniteTransactionsImpl;
import org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager;
+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.util.F0;
import org.apache.ignite.internal.util.future.GridCompoundFuture;
import org.apache.ignite.internal.util.future.GridFinishedFuture;
import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.lang.IgniteOutClosureX;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.CIX1;
import org.apache.ignite.internal.util.typedef.F;
@@ -3379,32 +3384,60 @@ public class GridCacheProcessor extends GridProcessorAdapter {
* @throws IgniteCheckedException If validation failed.
* @return Configuration copy.
*/
- private CacheConfiguration cloneCheckSerializable(CacheConfiguration val) throws IgniteCheckedException {
+ private CacheConfiguration cloneCheckSerializable(final CacheConfiguration val) throws IgniteCheckedException {
if (val == null)
return null;
- if (val.getCacheStoreFactory() != null) {
- try {
- ClassLoader ldr = ctx.config().getClassLoader();
+ return withBinaryContext(new IgniteOutClosureX<CacheConfiguration>() {
+ @Override public CacheConfiguration applyx() throws IgniteCheckedException {
+ if (val.getCacheStoreFactory() != null) {
+ try {
+ ClassLoader ldr = ctx.config().getClassLoader();
- if (ldr == null)
- ldr = val.getCacheStoreFactory().getClass().getClassLoader();
+ if (ldr == null)
+ ldr = val.getCacheStoreFactory().getClass().getClassLoader();
- marshaller.unmarshal(marshaller.marshal(val.getCacheStoreFactory()),
- U.resolveClassLoader(ldr, ctx.config()));
- }
- catch (IgniteCheckedException e) {
- throw new IgniteCheckedException("Failed to validate cache configuration. " +
- "Cache store factory is not serializable. Cache name: " + U.maskName(val.getName()), e);
+ marshaller.unmarshal(marshaller.marshal(val.getCacheStoreFactory()),
+ U.resolveClassLoader(ldr, ctx.config()));
+ }
+ catch (IgniteCheckedException e) {
+ throw new IgniteCheckedException("Failed to validate cache configuration. " +
+ "Cache store factory is not serializable. Cache name: " + U.maskName(val.getName()), e);
+ }
+ }
+
+ try {
+ return marshaller.unmarshal(marshaller.marshal(val), U.resolveClassLoader(ctx.config()));
+ }
+ catch (IgniteCheckedException e) {
+ throw new IgniteCheckedException("Failed to validate cache configuration " +
+ "(make sure all objects in cache configuration are serializable): " + U.maskName(val.getName()), e);
+ }
}
+ });
+ }
+
+ /**
+ * @param c Closure.
+ * @return Closure result.
+ * @throws IgniteCheckedException If failed.
+ */
+ private <T> T withBinaryContext(IgniteOutClosureX<T> c) throws IgniteCheckedException {
+ IgniteCacheObjectProcessor objProc = ctx.cacheObjects();
+ BinaryContext oldCtx = null;
+
+ if (objProc instanceof CacheObjectBinaryProcessorImpl) {
+ GridBinaryMarshaller binMarsh = ((CacheObjectBinaryProcessorImpl)objProc).marshaller();
+
+ oldCtx = binMarsh == null ? null : binMarsh.pushContext();
}
try {
- return marshaller.unmarshal(marshaller.marshal(val), U.resolveClassLoader(ctx.config()));
+ return c.applyx();
}
- catch (IgniteCheckedException e) {
- throw new IgniteCheckedException("Failed to validate cache configuration " +
- "(make sure all objects in cache configuration are serializable): " + U.maskName(val.getName()), e);
+ finally {
+ if (objProc instanceof CacheObjectBinaryProcessorImpl)
+ GridBinaryMarshaller.popContext(oldCtx);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityFunction.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityFunction.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityFunction.java
new file mode 100644
index 0000000..6681e7a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityFunction.java
@@ -0,0 +1,277 @@
+/*
+ * 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.platform.cache.affinity;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.AffinityFunctionContext;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.processors.platform.PlatformContext;
+import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
+import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;
+import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
+import org.apache.ignite.lifecycle.LifecycleAware;
+import org.apache.ignite.resources.IgniteInstanceResource;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * Platform AffinityFunction.
+ */
+public class PlatformAffinityFunction implements AffinityFunction, Externalizable, LifecycleAware {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** */
+ private static final byte FLAG_PARTITION = 1;
+
+ /** */
+ private static final byte FLAG_REMOVE_NODE = 1 << 1;
+
+ /** */
+ private static final byte FLAG_ASSIGN_PARTITIONS = 1 << 2;
+
+ /** */
+ private Object userFunc;
+
+ /**
+ * Partition count.
+ *
+ * 1) Java calls partitions() method very early (before LifecycleAware.start) during CacheConfiguration validation.
+ * 2) Partition count never changes.
+ * Therefore, we get the value on .NET side once, and pass it along with PlatformAffinity.
+ */
+ private int partitions;
+
+ /** */
+ private AffinityFunction baseFunc;
+
+ /** */
+ private byte overrideFlags;
+
+ /** */
+ private transient Ignite ignite;
+
+ /** */
+ private transient PlatformContext ctx;
+
+ /** */
+ private transient long ptr;
+
+ /** */
+ private transient PlatformAffinityFunctionTarget baseTarget;
+
+
+ /**
+ * Ctor for serialization.
+ *
+ */
+ public PlatformAffinityFunction() {
+ partitions = -1;
+ }
+
+ /**
+ * Ctor.
+ *
+ * @param func User fun object.
+ * @param partitions Number of partitions.
+ */
+ public PlatformAffinityFunction(Object func, int partitions, byte overrideFlags, AffinityFunction baseFunc) {
+ userFunc = func;
+ this.partitions = partitions;
+ this.overrideFlags = overrideFlags;
+ this.baseFunc = baseFunc;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void reset() {
+ // userFunc is always in initial state (it is serialized only once on start).
+ if (baseFunc != null)
+ baseFunc.reset();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int partitions() {
+ // Affinity function can not return different number of partitions,
+ // so we pass this value once from the platform.
+ assert partitions > 0;
+
+ return partitions;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int partition(Object key) {
+ if ((overrideFlags & FLAG_PARTITION) == 0) {
+ assert baseFunc != null;
+
+ return baseFunc.partition(key);
+ }
+
+ assert ctx != null;
+ assert ptr != 0;
+
+ try (PlatformMemory mem = ctx.memory().allocate()) {
+ PlatformOutputStream out = mem.output();
+ BinaryRawWriterEx writer = ctx.writer(out);
+
+ writer.writeObject(key);
+
+ out.synchronize();
+
+ return ctx.gateway().affinityFunctionPartition(ptr, mem.pointer());
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) {
+ if ((overrideFlags & FLAG_ASSIGN_PARTITIONS) == 0) {
+ assert baseFunc != null;
+
+ return baseFunc.assignPartitions(affCtx);
+ }
+
+ assert ctx != null;
+ assert ptr != 0;
+ assert affCtx != null;
+
+ try (PlatformMemory outMem = ctx.memory().allocate()) {
+ try (PlatformMemory inMem = ctx.memory().allocate()) {
+ PlatformOutputStream out = outMem.output();
+ BinaryRawWriterEx writer = ctx.writer(out);
+
+ // Write previous assignment
+ PlatformAffinityUtils.writeAffinityFunctionContext(affCtx, writer, ctx);
+
+ out.synchronize();
+
+ // Call platform
+ // We can not restore original AffinityFunctionContext after the call to platform,
+ // due to DiscoveryEvent (when node leaves, we can't get it by id anymore).
+ // Secondly, AffinityFunctionContext can't be changed by the user.
+ if (baseTarget != null)
+ baseTarget.setCurrentAffinityFunctionContext(affCtx);
+
+ try {
+ ctx.gateway().affinityFunctionAssignPartitions(ptr, outMem.pointer(), inMem.pointer());
+ }
+ finally {
+ if (baseTarget != null)
+ baseTarget.setCurrentAffinityFunctionContext(null);
+ }
+
+ // Read result
+ return PlatformAffinityUtils.readPartitionAssignment(ctx.reader(inMem), ctx);
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void removeNode(UUID nodeId) {
+ if ((overrideFlags & FLAG_REMOVE_NODE) == 0) {
+ assert baseFunc != null;
+
+ baseFunc.removeNode(nodeId);
+
+ return;
+ }
+
+ assert ctx != null;
+ assert ptr != 0;
+
+ try (PlatformMemory mem = ctx.memory().allocate()) {
+ PlatformOutputStream out = mem.output();
+ BinaryRawWriterEx writer = ctx.writer(out);
+
+ writer.writeUuid(nodeId);
+
+ out.synchronize();
+
+ ctx.gateway().affinityFunctionRemoveNode(ptr, mem.pointer());
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(userFunc);
+ out.writeInt(partitions);
+ out.writeByte(overrideFlags);
+ out.writeObject(baseFunc);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ userFunc = in.readObject();
+ partitions = in.readInt();
+ overrideFlags = in.readByte();
+ baseFunc = (AffinityFunction)in.readObject();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void start() throws IgniteException {
+ // userFunc is null when there is nothing overridden
+ if (userFunc == null)
+ return;
+
+ assert ignite != null;
+ ctx = PlatformUtils.platformContext(ignite);
+ assert ctx != null;
+
+ try (PlatformMemory mem = ctx.memory().allocate()) {
+ PlatformOutputStream out = mem.output();
+ BinaryRawWriterEx writer = ctx.writer(out);
+
+ writer.writeObject(userFunc);
+
+ out.synchronize();
+
+ baseTarget = baseFunc != null
+ ? new PlatformAffinityFunctionTarget(ctx, baseFunc)
+ : null;
+
+ ptr = ctx.gateway().affinityFunctionInit(mem.pointer(), baseTarget);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void stop() throws IgniteException {
+ if (ptr == 0)
+ return;
+
+ assert ctx != null;
+
+ ctx.gateway().affinityFunctionDestroy(ptr);
+ }
+
+ /**
+ * Injects the Ignite.
+ *
+ * @param ignite Ignite.
+ */
+ @SuppressWarnings("unused")
+ @IgniteInstanceResource
+ public void setIgnite(Ignite ignite) {
+ this.ignite = ignite;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityFunctionTarget.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityFunctionTarget.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityFunctionTarget.java
new file mode 100644
index 0000000..8a07b33
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityFunctionTarget.java
@@ -0,0 +1,113 @@
+/*
+ * 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.platform.cache.affinity;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.AffinityFunctionContext;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
+import org.apache.ignite.internal.processors.platform.PlatformContext;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import java.util.List;
+
+/**
+ * Platform affinity function target:
+ * to be invoked when Platform function calls base implementation of one of the AffinityFunction methods.
+ */
+public class PlatformAffinityFunctionTarget extends PlatformAbstractTarget {
+ /** */
+ private static final int OP_PARTITION = 1;
+
+ /** */
+ private static final int OP_REMOVE_NODE = 2;
+
+ /** */
+ private static final int OP_ASSIGN_PARTITIONS = 3;
+
+ /** Inner function to delegate calls to. */
+ private final AffinityFunction baseFunc;
+
+ /** Thread local to hold the current affinity function context. */
+ private static final ThreadLocal<AffinityFunctionContext> currentAffCtx = new ThreadLocal<>();
+
+ /**
+ * Constructor.
+ *
+ * @param platformCtx Context.
+ * @param baseFunc Function to wrap.
+ */
+ protected PlatformAffinityFunctionTarget(PlatformContext platformCtx, AffinityFunction baseFunc) {
+ super(platformCtx);
+
+ assert baseFunc != null;
+ this.baseFunc = baseFunc;
+
+ try {
+ platformCtx.kernalContext().resource().injectGeneric(baseFunc);
+ }
+ catch (IgniteCheckedException e) {
+ throw U.convertException(e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException {
+ if (type == OP_PARTITION)
+ return baseFunc.partition(reader.readObjectDetached());
+ else if (type == OP_REMOVE_NODE) {
+ baseFunc.removeNode(reader.readUuid());
+
+ return 0;
+ }
+
+ return super.processInStreamOutLong(type, reader);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
+ if (type == OP_ASSIGN_PARTITIONS) {
+ AffinityFunctionContext affCtx = currentAffCtx.get();
+
+ if (affCtx == null)
+ throw new IgniteException("Thread-local AffinityFunctionContext is null. " +
+ "This may indicate an unsupported call to the base AffinityFunction.");
+
+ final List<List<ClusterNode>> partitions = baseFunc.assignPartitions(affCtx);
+
+ PlatformAffinityUtils.writePartitionAssignment(partitions, writer, platformContext());
+
+ return;
+ }
+
+ super.processOutStream(type, writer);
+ }
+
+ /**
+ * Sets the context for current operation.
+ *
+ * @param ctx Context.
+ */
+ void setCurrentAffinityFunctionContext(AffinityFunctionContext ctx) {
+ currentAffCtx.set(ctx);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityUtils.java
new file mode 100644
index 0000000..b1e1b23
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityUtils.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.platform.cache.affinity;
+
+import org.apache.ignite.binary.BinaryRawReader;
+import org.apache.ignite.cache.affinity.AffinityFunctionContext;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.cluster.IgniteClusterEx;
+import org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl;
+import org.apache.ignite.internal.processors.platform.PlatformContext;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Affinity serialization functions.
+ */
+public class PlatformAffinityUtils {
+ /**
+ * Writes the affinity function context.
+ * @param affCtx Affinity context.
+ * @param writer Writer.
+ * @param ctx Platform context.
+ */
+ public static void writeAffinityFunctionContext(AffinityFunctionContext affCtx, BinaryRawWriterEx writer,
+ PlatformContext ctx) {
+ assert affCtx != null;
+ assert writer != null;
+ assert ctx != null;
+
+ ctx.writeNodes(writer, affCtx.currentTopologySnapshot());
+
+ writer.writeInt(affCtx.backups());
+ writer.writeLong(affCtx.currentTopologyVersion().topologyVersion());
+ writer.writeInt(affCtx.currentTopologyVersion().minorTopologyVersion());
+
+ ctx.writeEvent(writer, affCtx.discoveryEvent());
+
+ // Write previous assignment
+ List<List<ClusterNode>> prevAssignment = ((GridAffinityFunctionContextImpl)affCtx).prevAssignment();
+
+ if (prevAssignment == null)
+ writer.writeInt(-1);
+ else {
+ writer.writeInt(prevAssignment.size());
+
+ for (List<ClusterNode> part : prevAssignment)
+ ctx.writeNodes(writer, part);
+ }
+ }
+
+ /**
+ * Writes the partition assignment to a stream.
+ *
+ * @param partitions Partitions.
+ * @param writer Writer.
+ */
+ public static void writePartitionAssignment(Collection<List<ClusterNode>> partitions, BinaryRawWriterEx writer,
+ PlatformContext ctx) {
+ assert partitions != null;
+ assert writer != null;
+
+ writer.writeInt(partitions.size());
+
+ for (List<ClusterNode> part : partitions)
+ ctx.writeNodes(writer, part);
+ }
+
+ /**
+ * Reads the partition assignment.
+ *
+ * @param reader Reader.
+ * @param ctx Platform context.
+ * @return Partitions.
+ */
+ public static List<List<ClusterNode>> readPartitionAssignment(BinaryRawReader reader, PlatformContext ctx) {
+ assert reader != null;
+ assert ctx != null;
+
+ int partCnt = reader.readInt();
+
+ List<List<ClusterNode>> res = new ArrayList<>(partCnt);
+
+ IgniteClusterEx cluster = ctx.kernalContext().grid().cluster();
+
+ for (int i = 0; i < partCnt; i++) {
+ int partSize = reader.readInt();
+
+ List<ClusterNode> part = new ArrayList<>(partSize);
+
+ for (int j = 0; j < partSize; j++)
+ part.add(cluster.node(reader.readUuid()));
+
+ res.add(part);
+ }
+
+ return res;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackGateway.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackGateway.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackGateway.java
index 47862a2..1759a5b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackGateway.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackGateway.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.platform.callback;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunctionTarget;
import org.apache.ignite.internal.util.GridStripedSpinBusyLock;
/**
@@ -920,6 +921,94 @@ public class PlatformCallbackGateway {
}
/**
+ * Initializes affinity function.
+ *
+ * @param memPtr Pointer to a stream with serialized affinity function.
+ * @param baseFunc Optional func for base calls.
+ * @return Affinity function pointer.
+ */
+ public long affinityFunctionInit(long memPtr, PlatformAffinityFunctionTarget baseFunc) {
+ enter();
+
+ try {
+ return PlatformCallbackUtils.affinityFunctionInit(envPtr, memPtr, baseFunc);
+ }
+ finally {
+ leave();
+ }
+ }
+
+ /**
+ * Gets the partition from affinity function.
+ *
+ * @param ptr Affinity function pointer.
+ * @param memPtr Pointer to a stream with key object.
+ * @return Partition number for a given key.
+ */
+ public int affinityFunctionPartition(long ptr, long memPtr) {
+ enter();
+
+ try {
+ return PlatformCallbackUtils.affinityFunctionPartition(envPtr, ptr, memPtr);
+ }
+ finally {
+ leave();
+ }
+ }
+
+ /**
+ * Assigns the affinity partitions.
+ *
+ * @param ptr Affinity function pointer.
+ * @param outMemPtr Pointer to a stream with affinity context.
+ * @param inMemPtr Pointer to a stream with result.
+ */
+ public void affinityFunctionAssignPartitions(long ptr, long outMemPtr, long inMemPtr){
+ enter();
+
+ try {
+ PlatformCallbackUtils.affinityFunctionAssignPartitions(envPtr, ptr, outMemPtr, inMemPtr);
+ }
+ finally {
+ leave();
+ }
+ }
+
+ /**
+ * Removes the node from affinity function.
+ *
+ * @param ptr Affinity function pointer.
+ * @param memPtr Pointer to a stream with node id.
+ */
+ public void affinityFunctionRemoveNode(long ptr, long memPtr) {
+ enter();
+
+ try {
+ PlatformCallbackUtils.affinityFunctionRemoveNode(envPtr, ptr, memPtr);
+ }
+ finally {
+ leave();
+ }
+ }
+
+ /**
+ * Destroys the affinity function.
+ *
+ * @param ptr Affinity function pointer.
+ */
+ public void affinityFunctionDestroy(long ptr) {
+ if (!lock.enterBusy())
+ return; // skip: destroy is not necessary during shutdown.
+
+ try {
+ PlatformCallbackUtils.affinityFunctionDestroy(envPtr, ptr);
+ }
+ finally {
+ leave();
+ }
+ }
+
+ /**
* Enter gateway.
*/
protected void enter() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
index 7f3ba6f..1cbbd7e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
@@ -17,6 +17,8 @@
package org.apache.ignite.internal.processors.platform.callback;
+import org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunctionTarget;
+
/**
* Platform callback utility methods. Implemented in target platform. All methods in this class must be
* package-visible and invoked only through {@link PlatformCallbackGateway}.
@@ -482,6 +484,53 @@ public class PlatformCallbackUtils {
static native long extensionCallbackInLongLongOutLong(long envPtr, int typ, long arg1, long arg2);
/**
+ * Initializes affinity function.
+ *
+ * @param envPtr Environment pointer.
+ * @param memPtr Pointer to a stream with serialized affinity function.
+ * @param baseFunc Optional func for base calls.
+ * @return Affinity function pointer.
+ */
+ static native long affinityFunctionInit(long envPtr, long memPtr, PlatformAffinityFunctionTarget baseFunc);
+
+ /**
+ * Gets the partition from affinity function.
+ *
+ * @param envPtr Environment pointer.
+ * @param ptr Affinity function pointer.
+ * @param memPtr Pointer to a stream with key object.
+ * @return Partition number for a given key.
+ */
+ static native int affinityFunctionPartition(long envPtr, long ptr, long memPtr);
+
+ /**
+ * Assigns the affinity partitions.
+ *
+ * @param envPtr Environment pointer.
+ * @param ptr Affinity function pointer.
+ * @param outMemPtr Pointer to a stream with affinity context.
+ * @param inMemPtr Pointer to a stream with result.
+ */
+ static native void affinityFunctionAssignPartitions(long envPtr, long ptr, long outMemPtr, long inMemPtr);
+
+ /**
+ * Removes the node from affinity function.
+ *
+ * @param envPtr Environment pointer.
+ * @param ptr Affinity function pointer.
+ * @param memPtr Pointer to a stream with node id.
+ */
+ static native void affinityFunctionRemoveNode(long envPtr, long ptr, long memPtr);
+
+ /**
+ * Destroys the affinity function.
+ *
+ * @param envPtr Environment pointer.
+ * @param ptr Affinity function pointer.
+ */
+ static native void affinityFunctionDestroy(long envPtr, long ptr);
+
+ /**
* Private constructor.
*/
private PlatformCallbackUtils() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
index 6b9b441..f441f4c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
@@ -19,21 +19,28 @@ package org.apache.ignite.internal.processors.platform.dotnet;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
-import org.apache.ignite.binary.BinaryIdMapper;
import org.apache.ignite.binary.BinaryBasicIdMapper;
-import org.apache.ignite.binary.BinaryNameMapper;
import org.apache.ignite.binary.BinaryBasicNameMapper;
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryNameMapper;
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.fair.FairAffinityFunction;
+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.PlatformConfiguration;
import org.apache.ignite.internal.MarshallerContextImpl;
+import org.apache.ignite.internal.binary.BinaryContext;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.binary.BinaryNoopMetadataHandler;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryReaderExImpl;
import org.apache.ignite.internal.binary.GridBinaryMarshaller;
-import org.apache.ignite.internal.binary.BinaryContext;
import org.apache.ignite.internal.processors.platform.PlatformAbstractConfigurationClosure;
+import org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction;
import org.apache.ignite.internal.processors.platform.lifecycle.PlatformLifecycleBean;
-import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl;
import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;
@@ -42,8 +49,8 @@ import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lifecycle.LifecycleBean;
import org.apache.ignite.logger.NullLogger;
import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction;
import org.apache.ignite.platform.dotnet.PlatformDotNetConfiguration;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.platform.dotnet.PlatformDotNetLifecycleBean;
import java.util.ArrayList;
@@ -183,7 +190,9 @@ public class PlatformDotNetConfigurationClosure extends PlatformAbstractConfigur
try (PlatformMemory inMem = memMgr.allocate()) {
PlatformOutputStream out = outMem.output();
- BinaryRawWriterEx writer = marshaller().writer(out);
+ final GridBinaryMarshaller marshaller = marshaller();
+
+ BinaryRawWriterEx writer = marshaller.writer(out);
PlatformUtils.writeDotNetConfiguration(writer, interopCfg.unwrap());
@@ -196,12 +205,24 @@ public class PlatformDotNetConfigurationClosure extends PlatformAbstractConfigur
writer.writeMap(bean.getProperties());
}
+ // Write .NET affinity funcs
+ List<PlatformDotNetAffinityFunction> affFuncs = affinityFunctions(igniteCfg);
+
+ writer.writeInt(affFuncs.size());
+
+ for (PlatformDotNetAffinityFunction func : affFuncs) {
+ writer.writeString(func.getTypeName());
+ writer.writeMap(func.getProperties());
+ }
+
out.synchronize();
gate.extensionCallbackInLongLongOutLong(
PlatformUtils.OP_PREPARE_DOT_NET, outMem.pointer(), inMem.pointer());
- processPrepareResult(inMem.input());
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(marshaller.context(), inMem.input(), null);
+
+ processPrepareResult(reader);
}
}
}
@@ -211,7 +232,7 @@ public class PlatformDotNetConfigurationClosure extends PlatformAbstractConfigur
*
* @param in Input stream.
*/
- private void processPrepareResult(PlatformInputStream in) {
+ private void processPrepareResult(BinaryReaderExImpl in) {
assert cfg != null;
List<PlatformDotNetLifecycleBean> beans = beans(cfg);
@@ -245,6 +266,63 @@ public class PlatformDotNetConfigurationClosure extends PlatformAbstractConfigur
cfg.setLifecycleBeans(mergedBeans);
}
}
+
+ // Process affinity functions
+ List<PlatformDotNetAffinityFunction> affFuncs = affinityFunctions(cfg);
+
+ if (!affFuncs.isEmpty()) {
+ for (PlatformDotNetAffinityFunction aff : affFuncs)
+ aff.init(readAffinityFunction(in));
+ }
+ }
+
+ /**
+ * Reads the affinity function.
+ *
+ * @param in Stream.
+ * @return Affinity function.
+ */
+ private static PlatformAffinityFunction readAffinityFunction(BinaryRawReaderEx in) {
+ byte plcTyp = in.readByte();
+
+ if (plcTyp == 0)
+ return null;
+
+ int partitions = in.readInt();
+ boolean exclNeighbours = in.readBoolean();
+ byte overrideFlags = in.readByte();
+ Object userFunc = in.readObjectDetached();
+
+ AffinityFunction baseFunc = null;
+
+ switch (plcTyp) {
+ case 1: {
+ FairAffinityFunction f = new FairAffinityFunction();
+
+ f.setPartitions(partitions);
+ f.setExcludeNeighbors(exclNeighbours);
+
+ baseFunc = f;
+
+ break;
+ }
+
+ case 2: {
+ RendezvousAffinityFunction f = new RendezvousAffinityFunction();
+
+ f.setPartitions(partitions);
+ f.setExcludeNeighbors(exclNeighbours);
+
+ baseFunc = f;
+
+ break;
+ }
+
+ default:
+ assert plcTyp == 3 : "Unknown affinity function policy type: " + plcTyp;
+ }
+
+ return new PlatformAffinityFunction(userFunc, partitions, overrideFlags, baseFunc);
}
/**
@@ -289,4 +367,25 @@ public class PlatformDotNetConfigurationClosure extends PlatformAbstractConfigur
throw U.convertException(e);
}
}
+
+ /**
+ * Find .NET affinity functions in configuration.
+ *
+ * @param cfg Configuration.
+ * @return affinity functions.
+ */
+ private static List<PlatformDotNetAffinityFunction> affinityFunctions(IgniteConfiguration cfg) {
+ List<PlatformDotNetAffinityFunction> res = new ArrayList<>();
+
+ CacheConfiguration[] cacheCfg = cfg.getCacheConfiguration();
+
+ if (cacheCfg != null) {
+ for (CacheConfiguration ccfg : cacheCfg) {
+ if (ccfg.getAffinity() instanceof PlatformDotNetAffinityFunction)
+ res.add((PlatformDotNetAffinityFunction)ccfg.getAffinity());
+ }
+ }
+
+ return res;
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/core/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetAffinityFunction.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetAffinityFunction.java b/modules/core/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetAffinityFunction.java
new file mode 100644
index 0000000..254c379
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetAffinityFunction.java
@@ -0,0 +1,171 @@
+/*
+ * 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.platform.dotnet;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.AffinityFunctionContext;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction;
+import org.apache.ignite.lifecycle.LifecycleAware;
+import org.apache.ignite.resources.IgniteInstanceResource;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * AffinityFunction implementation which can be used to configure .NET affinity function in Java Spring configuration.
+ */
+public class PlatformDotNetAffinityFunction implements AffinityFunction, Externalizable, LifecycleAware {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** .NET type name. */
+ private transient String typName;
+
+ /** Properties. */
+ private transient Map<String, ?> props;
+
+ /** Inner function. */
+ private PlatformAffinityFunction func;
+
+ /**
+ * Gets .NET type name.
+ *
+ * @return .NET type name.
+ */
+ public String getTypeName() {
+ return typName;
+ }
+
+ /**
+ * Sets .NET type name.
+ *
+ * @param typName .NET type name.
+ */
+ public void setTypeName(String typName) {
+ this.typName = typName;
+ }
+
+ /**
+ * Get properties.
+ *
+ * @return Properties.
+ */
+ public Map<String, ?> getProperties() {
+ return props;
+ }
+
+ /**
+ * Set properties.
+ *
+ * @param props Properties.
+ */
+ public void setProperties(Map<String, ?> props) {
+ this.props = props;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void reset() {
+ assert func != null;
+
+ func.reset();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int partitions() {
+ assert func != null;
+
+ return func.partitions();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int partition(Object key) {
+ assert func != null;
+
+ return func.partition(key);
+ }
+
+ /** {@inheritDoc} */
+ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) {
+ assert func != null;
+
+ return func.assignPartitions(affCtx);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void removeNode(UUID nodeId) {
+ assert func != null;
+
+ func.removeNode(nodeId);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(func);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ func = (PlatformAffinityFunction) in.readObject();
+ }
+
+ /**
+ * Initializes this instance.
+ *
+ * @param func Underlying func.
+ */
+ public void init(PlatformAffinityFunction func) {
+ assert func != null;
+
+ this.func = func;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void start() throws IgniteException {
+ assert func != null;
+
+ func.start();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void stop() throws IgniteException {
+ assert func != null;
+
+ func.stop();
+ }
+
+ /**
+ * Injects the Ignite.
+ *
+ * @param ignite Ignite.
+ */
+ @SuppressWarnings("unused")
+ @IgniteInstanceResource
+ private void setIgnite(Ignite ignite) {
+ assert func != null;
+
+ func.setIgnite(ignite);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/cpp/common/include/ignite/common/java.h
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/common/include/ignite/common/java.h b/modules/platforms/cpp/common/include/ignite/common/java.h
index e629c77..91caddd 100644
--- a/modules/platforms/cpp/common/include/ignite/common/java.h
+++ b/modules/platforms/cpp/common/include/ignite/common/java.h
@@ -103,6 +103,12 @@ namespace ignite
typedef long long(JNICALL *ExtensionCallbackInLongOutLongHandler)(void* target, int typ, long long arg1);
typedef long long(JNICALL *ExtensionCallbackInLongLongOutLongHandler)(void* target, int typ, long long arg1, long long arg2);
+ typedef long long(JNICALL *AffinityFunctionInitHandler)(void* target, long long memPtr, void* baseFunc);
+ typedef int(JNICALL *AffinityFunctionPartitionHandler)(void* target, long long ptr, long long memPtr);
+ typedef void(JNICALL *AffinityFunctionAssignPartitionsHandler)(void* target, long long ptr, long long inMemPtr, long long outMemPtr);
+ typedef void(JNICALL *AffinityFunctionRemoveNodeHandler)(void* target, long long ptr, long long memPtr);
+ typedef void(JNICALL *AffinityFunctionDestroyHandler)(void* target, long long ptr);
+
/**
* JNI handlers holder.
*/
@@ -177,6 +183,12 @@ namespace ignite
ExtensionCallbackInLongOutLongHandler extensionCallbackInLongOutLong;
ExtensionCallbackInLongLongOutLongHandler extensionCallbackInLongLongOutLong;
+
+ AffinityFunctionInitHandler affinityFunctionInit;
+ AffinityFunctionPartitionHandler affinityFunctionPartition;
+ AffinityFunctionAssignPartitionsHandler affinityFunctionAssignPartitions;
+ AffinityFunctionRemoveNodeHandler affinityFunctionRemoveNode;
+ AffinityFunctionDestroyHandler affinityFunctionDestroy;
};
/**
@@ -683,6 +695,12 @@ namespace ignite
JNIEXPORT jlong JNICALL JniExtensionCallbackInLongOutLong(JNIEnv *env, jclass cls, jlong envPtr, jint typ, jlong arg1);
JNIEXPORT jlong JNICALL JniExtensionCallbackInLongLongOutLong(JNIEnv *env, jclass cls, jlong envPtr, jint typ, jlong arg1, jlong arg2);
+
+ JNIEXPORT jlong JNICALL JniAffinityFunctionInit(JNIEnv *env, jclass cls, jlong envPtr, jlong memPtr, jobject baseFunc);
+ JNIEXPORT jint JNICALL JniAffinityFunctionPartition(JNIEnv *env, jclass cls, jlong envPtr, jlong ptr, jlong memPtr);
+ JNIEXPORT void JNICALL JniAffinityFunctionAssignPartitions(JNIEnv *env, jclass cls, jlong envPtr, jlong ptr, jlong inMemPtr, jlong outMemPtr);
+ JNIEXPORT void JNICALL JniAffinityFunctionRemoveNode(JNIEnv *env, jclass cls, jlong envPtr, jlong ptr, jlong memPtr);
+ JNIEXPORT void JNICALL JniAffinityFunctionDestroy(JNIEnv *env, jclass cls, jlong envPtr, jlong ptr);
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/cpp/common/src/java.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/common/src/java.cpp b/modules/platforms/cpp/common/src/java.cpp
index 63deba5..789b6a3 100644
--- a/modules/platforms/cpp/common/src/java.cpp
+++ b/modules/platforms/cpp/common/src/java.cpp
@@ -346,6 +346,12 @@ namespace ignite
JniMethod M_PLATFORM_CALLBACK_UTILS_EXTENSION_CALLBACK_IN_LONG_OUT_LONG = JniMethod("extensionCallbackInLongOutLong", "(JIJ)J", true);
JniMethod M_PLATFORM_CALLBACK_UTILS_EXTENSION_CALLBACK_IN_LONG_LONG_OUT_LONG = JniMethod("extensionCallbackInLongLongOutLong", "(JIJJ)J", true);
+ JniMethod M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_INIT = JniMethod("affinityFunctionInit", "(JJLorg/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityFunctionTarget;)J", true);
+ JniMethod M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_PARTITION = JniMethod("affinityFunctionPartition", "(JJJ)I", true);
+ JniMethod M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_ASSIGN_PARTITIONS = JniMethod("affinityFunctionAssignPartitions", "(JJJJ)V", true);
+ JniMethod M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_REMOVE_NODE = JniMethod("affinityFunctionRemoveNode", "(JJJ)V", true);
+ JniMethod M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_DESTROY = JniMethod("affinityFunctionDestroy", "(JJ)V", true);
+
const char* C_PLATFORM_UTILS = "org/apache/ignite/internal/processors/platform/utils/PlatformUtils";
JniMethod M_PLATFORM_UTILS_REALLOC = JniMethod("reallocate", "(JI)V", true);
JniMethod M_PLATFORM_UTILS_ERR_DATA = JniMethod("errorData", "(Ljava/lang/Throwable;)[B", true);
@@ -766,7 +772,7 @@ namespace ignite
void RegisterNatives(JNIEnv* env) {
{
- JNINativeMethod methods[52];
+ JNINativeMethod methods[57];
int idx = 0;
@@ -840,6 +846,12 @@ namespace ignite
AddNativeMethod(methods + idx++, M_PLATFORM_CALLBACK_UTILS_EXTENSION_CALLBACK_IN_LONG_OUT_LONG, reinterpret_cast<void*>(JniExtensionCallbackInLongOutLong));
AddNativeMethod(methods + idx++, M_PLATFORM_CALLBACK_UTILS_EXTENSION_CALLBACK_IN_LONG_LONG_OUT_LONG, reinterpret_cast<void*>(JniExtensionCallbackInLongLongOutLong));
+ AddNativeMethod(methods + idx++, M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_INIT, reinterpret_cast<void*>(JniAffinityFunctionInit));
+ AddNativeMethod(methods + idx++, M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_PARTITION, reinterpret_cast<void*>(JniAffinityFunctionPartition));
+ AddNativeMethod(methods + idx++, M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_ASSIGN_PARTITIONS, reinterpret_cast<void*>(JniAffinityFunctionAssignPartitions));
+ AddNativeMethod(methods + idx++, M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_REMOVE_NODE, reinterpret_cast<void*>(JniAffinityFunctionRemoveNode));
+ AddNativeMethod(methods + idx++, M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_DESTROY, reinterpret_cast<void*>(JniAffinityFunctionDestroy));
+
jint res = env->RegisterNatives(FindClass(env, C_PLATFORM_CALLBACK_UTILS), methods, idx);
if (res != JNI_OK)
@@ -2471,6 +2483,26 @@ namespace ignite
JNIEXPORT jlong JNICALL JniExtensionCallbackInLongLongOutLong(JNIEnv *env, jclass cls, jlong envPtr, jint typ, jlong arg1, jlong arg2) {
IGNITE_SAFE_FUNC(env, envPtr, ExtensionCallbackInLongLongOutLongHandler, extensionCallbackInLongLongOutLong, typ, arg1, arg2);
}
- }
+
+ JNIEXPORT jlong JNICALL JniAffinityFunctionInit(JNIEnv *env, jclass cls, jlong envPtr, jlong memPtr, jobject baseFunc) {
+ void* baseFuncRef = baseFunc ? env->NewGlobalRef(baseFunc) : nullptr;
+ IGNITE_SAFE_FUNC(env, envPtr, AffinityFunctionInitHandler, affinityFunctionInit, memPtr, baseFuncRef);
+ }
+
+ JNIEXPORT jint JNICALL JniAffinityFunctionPartition(JNIEnv *env, jclass cls, jlong envPtr, jlong ptr, jlong memPtr) {
+ IGNITE_SAFE_FUNC(env, envPtr, AffinityFunctionPartitionHandler, affinityFunctionPartition, ptr, memPtr);
+ }
+
+ JNIEXPORT void JNICALL JniAffinityFunctionAssignPartitions(JNIEnv *env, jclass cls, jlong envPtr, jlong ptr, jlong inMemPtr, jlong outMemPtr) {
+ IGNITE_SAFE_PROC(env, envPtr, AffinityFunctionAssignPartitionsHandler, affinityFunctionAssignPartitions, ptr, inMemPtr, outMemPtr);
+ }
+
+ JNIEXPORT void JNICALL JniAffinityFunctionRemoveNode(JNIEnv *env, jclass cls, jlong envPtr, jlong ptr, jlong memPtr) {
+ IGNITE_SAFE_PROC(env, envPtr, AffinityFunctionRemoveNodeHandler, affinityFunctionRemoveNode, ptr, memPtr);
+ }
+
+ JNIEXPORT void JNICALL JniAffinityFunctionDestroy(JNIEnv *env, jclass cls, jlong envPtr, jlong ptr) {
+ IGNITE_SAFE_PROC(env, envPtr, AffinityFunctionDestroyHandler, affinityFunctionDestroy, ptr);
+ } }
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index 0194450..89cd2a7 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -60,6 +60,7 @@
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Cache\Affinity\AffinityFunctionSpringTest.cs" />
<Compile Include="Cache\CacheDynamicStartTest.cs" />
<Compile Include="Cache\CacheTestAsyncWrapper.cs" />
<Compile Include="Cache\CacheAbstractTest.cs" />
@@ -175,6 +176,12 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
+ <Content Include="Config\Cache\Affinity\affinity-function2.xml">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Config\Cache\Affinity\affinity-function.xml">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="Config\Cache\Store\cache-store-session.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
@@ -262,4 +269,4 @@ copy /Y $(SolutionDir)Apache.Ignite\bin\$(PlatformName)\$(ConfigurationName)\Apa
<Target Name="AfterBuild">
</Target>
-->
-</Project>
+</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityFunctionSpringTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityFunctionSpringTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityFunctionSpringTest.cs
new file mode 100644
index 0000000..7b317ac
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityFunctionSpringTest.cs
@@ -0,0 +1,184 @@
+\ufeff/*
+ * 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.
+ */
+
+// ReSharper disable UnusedAutoPropertyAccessor.Local
+// ReSharper disable UnusedMember.Local
+namespace Apache.Ignite.Core.Tests.Cache.Affinity
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using Apache.Ignite.Core.Cache;
+ using Apache.Ignite.Core.Cache.Affinity;
+ using Apache.Ignite.Core.Cache.Affinity.Fair;
+ using Apache.Ignite.Core.Cluster;
+ using Apache.Ignite.Core.Resource;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests AffinityFunction defined in Spring XML.
+ /// </summary>
+ public class AffinityFunctionSpringTest : IgniteTestBase
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AffinityFunctionSpringTest"/> class.
+ /// </summary>
+ public AffinityFunctionSpringTest() : base(6,
+ "config\\cache\\affinity\\affinity-function.xml",
+ "config\\cache\\affinity\\affinity-function2.xml")
+ {
+ // No-op.
+ }
+
+ /// <summary>
+ /// Tests the static cache.
+ /// </summary>
+ [Test]
+ public void TestStaticCache()
+ {
+ ValidateAffinityFunction(Grid.GetCache<long, int>("cache1"));
+ ValidateAffinityFunction(Grid2.GetCache<long, int>("cache1"));
+ ValidateAffinityFunction(Grid.GetCache<long, int>("cache2"));
+ ValidateAffinityFunction(Grid2.GetCache<long, int>("cache2"));
+ }
+
+ /// <summary>
+ /// Tests the dynamic cache.
+ /// </summary>
+ [Test]
+ public void TestDynamicCache()
+ {
+ ValidateAffinityFunction(Grid.CreateCache<long, int>("dyn-cache-1"));
+ ValidateAffinityFunction(Grid2.GetCache<long, int>("dyn-cache-1"));
+
+ ValidateAffinityFunction(Grid2.CreateCache<long, int>("dyn-cache-2"));
+ ValidateAffinityFunction(Grid.GetCache<long, int>("dyn-cache-2"));
+
+ ValidateAffinityFunction(Grid.CreateCache<long, int>("dyn-cache2-1"));
+ ValidateAffinityFunction(Grid2.GetCache<long, int>("dyn-cache2-1"));
+
+ ValidateAffinityFunction(Grid2.CreateCache<long, int>("dyn-cache2-2"));
+ ValidateAffinityFunction(Grid.GetCache<long, int>("dyn-cache2-2"));
+ }
+
+ /// <summary>
+ /// Validates the affinity function.
+ /// </summary>
+ /// <param name="cache">The cache.</param>
+ private static void ValidateAffinityFunction(ICache<long, int> cache)
+ {
+ var aff = cache.Ignite.GetAffinity(cache.Name);
+
+ Assert.AreEqual(5, aff.Partitions);
+
+ // Predefined map
+ Assert.AreEqual(2, aff.GetPartition(1L));
+ Assert.AreEqual(1, aff.GetPartition(2L));
+
+ // Other keys
+ Assert.AreEqual(1, aff.GetPartition(13L));
+ Assert.AreEqual(3, aff.GetPartition(4L));
+ }
+
+ private class TestFunc : IAffinityFunction // [Serializable] is not necessary
+ {
+ [InstanceResource]
+ private readonly IIgnite _ignite = null;
+
+ private int Property1 { get; set; }
+
+ private string Property2 { get; set; }
+
+ public int Partitions
+ {
+ get { return 5; }
+ }
+
+ public int GetPartition(object key)
+ {
+ Assert.IsNotNull(_ignite);
+ Assert.AreEqual(1, Property1);
+ Assert.AreEqual("1", Property2);
+
+ var longKey = (long)key;
+ int res;
+
+ if (TestFairFunc.PredefinedParts.TryGetValue(longKey, out res))
+ return res;
+
+ return (int)(longKey * 2 % 5);
+ }
+
+ // ReSharper disable once UnusedParameter.Local
+ public void RemoveNode(Guid nodeId)
+ {
+ // No-op.
+ }
+
+ public IEnumerable<IEnumerable<IClusterNode>> AssignPartitions(AffinityFunctionContext context)
+ {
+ return Enumerable.Range(0, Partitions).Select(x => context.CurrentTopologySnapshot);
+ }
+ }
+
+ private class TestFairFunc : FairAffinityFunction // [Serializable] is not necessary
+ {
+ public static readonly Dictionary<long, int> PredefinedParts = new Dictionary<long, int>
+ {
+ {1, 2},
+ {2, 1}
+ };
+
+ [InstanceResource]
+ private readonly IIgnite _ignite = null;
+
+ private int Property1 { get; set; }
+
+ private string Property2 { get; set; }
+
+ public override int GetPartition(object key)
+ {
+ Assert.IsNotNull(_ignite);
+ Assert.AreEqual(1, Property1);
+ Assert.AreEqual("1", Property2);
+
+ Assert.IsInstanceOf<long>(key);
+
+ var basePart = base.GetPartition(key);
+ Assert.Greater(basePart, -1);
+ Assert.Less(basePart, Partitions);
+
+ var longKey = (long) key;
+ int res;
+
+ if (PredefinedParts.TryGetValue(longKey, out res))
+ return res;
+
+ return (int) (longKey * 2 % 5);
+ }
+
+ public override IEnumerable<IEnumerable<IClusterNode>> AssignPartitions(AffinityFunctionContext context)
+ {
+ var baseRes = base.AssignPartitions(context).ToList(); // test base call
+
+ Assert.AreEqual(Partitions, baseRes.Count);
+
+ return baseRes;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Cache/Affinity/affinity-function.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Cache/Affinity/affinity-function.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Cache/Affinity/affinity-function.xml
new file mode 100644
index 0000000..67ff128
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Cache/Affinity/affinity-function.xml
@@ -0,0 +1,129 @@
+\ufeff<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd">
+ <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+ <property name="localHost" value="127.0.0.1"/>
+ <property name="connectorConfiguration">
+ <null/>
+ </property>
+
+ <property name="cacheConfiguration">
+ <list>
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <property name="name" value="cache1"/>
+
+ <property name="affinity">
+ <bean class="org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction">
+ <property name="typeName" value="Apache.Ignite.Core.Tests.Cache.Affinity.AffinityFunctionSpringTest+TestFunc, Apache.Ignite.Core.Tests"/>
+ <property name="properties">
+ <map>
+ <entry key="Property1">
+ <value type="java.lang.Integer">1</value>
+ </entry>
+ <entry key="Property2" value="1"/>
+ </map>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <property name="name" value="dyn-cache-*"/>
+
+ <property name="affinity">
+ <bean class="org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction">
+ <property name="typeName" value="Apache.Ignite.Core.Tests.Cache.Affinity.AffinityFunctionSpringTest+TestFunc, Apache.Ignite.Core.Tests"/>
+ <property name="properties">
+ <map>
+ <entry key="Property1">
+ <value type="java.lang.Integer">1</value>
+ </entry>
+ <entry key="Property2" value="1"/>
+ </map>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <property name="name" value="cache2"/>
+
+ <property name="affinity">
+ <bean class="org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction">
+ <property name="typeName" value="Apache.Ignite.Core.Tests.Cache.Affinity.AffinityFunctionSpringTest+TestFairFunc, Apache.Ignite.Core.Tests"/>
+ <property name="properties">
+ <map>
+ <entry key="Property1">
+ <value type="java.lang.Integer">1</value>
+ </entry>
+ <entry key="Property2" value="1"/>
+ <entry key="Partitions">
+ <value type="java.lang.Integer">5</value>
+ </entry>
+ </map>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <property name="name" value="dyn-cache2-*"/>
+
+ <property name="affinity">
+ <bean class="org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction">
+ <property name="typeName" value="Apache.Ignite.Core.Tests.Cache.Affinity.AffinityFunctionSpringTest+TestFairFunc, Apache.Ignite.Core.Tests"/>
+ <property name="properties">
+ <map>
+ <entry key="Property1">
+ <value type="java.lang.Integer">1</value>
+ </entry>
+ <entry key="Property2" value="1"/>
+ <entry key="Partitions">
+ <value type="java.lang.Integer">5</value>
+ </entry>
+ </map>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ </list>
+ </property>
+
+ <property name="discoverySpi">
+ <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+ <property name="ipFinder">
+ <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+ <property name="addresses">
+ <list>
+ <!-- In distributed environment, replace with actual host IP address. -->
+ <value>127.0.0.1:47500</value>
+ </list>
+ </property>
+ </bean>
+ </property>
+ <property name="socketTimeout" value="300" />
+ </bean>
+ </property>
+ </bean>
+</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Cache/Affinity/affinity-function2.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Cache/Affinity/affinity-function2.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Cache/Affinity/affinity-function2.xml
new file mode 100644
index 0000000..cab34b5
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Cache/Affinity/affinity-function2.xml
@@ -0,0 +1,49 @@
+\ufeff<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd">
+ <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+ <property name="localHost" value="127.0.0.1"/>
+ <property name="connectorConfiguration"><null/></property>
+ <property name="gridName" value="grid2" />
+
+ <property name="discoverySpi">
+ <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+ <property name="ipFinder">
+ <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+ <property name="addresses">
+ <list>
+ <!-- In distributed environment, replace with actual host IP address. -->
+ <value>127.0.0.1:47500</value>
+ </list>
+ </property>
+ </bean>
+ </property>
+ <property name="socketTimeout" value="300" />
+ </bean>
+ </property>
+ </bean>
+</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestRunner.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestRunner.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestRunner.cs
index 2b0ab8e..95be6dc 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestRunner.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestRunner.cs
@@ -20,6 +20,7 @@ namespace Apache.Ignite.Core.Tests
using System;
using System.Diagnostics;
using System.Reflection;
+ using Apache.Ignite.Core.Tests.Cache.Affinity;
using Apache.Ignite.Core.Tests.Memory;
using NUnit.ConsoleRunner;
@@ -33,7 +34,7 @@ namespace Apache.Ignite.Core.Tests
//TestOne(typeof(ContinuousQueryAtomiclBackupTest), "TestInitialQuery");
- TestAll(typeof (ExecutableTest));
+ TestAll(typeof (AffinityFunctionSpringTest));
//TestAllInAssembly();
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
index 05a7fa7..6793873 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
@@ -55,6 +55,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Binary\Package-Info.cs" />
+ <Compile Include="Cache\Affinity\AffinityFunctionBase.cs" />
+ <Compile Include="Cache\Affinity\AffinityFunctionContext.cs" />
+ <Compile Include="Cache\Affinity\AffinityTopologyVersion.cs" />
+ <Compile Include="Cache\Affinity\Fair\FairAffinityFunction.cs" />
+ <Compile Include="Cache\Affinity\IAffinityFunction.cs" />
+ <Compile Include="Cache\Affinity\Rendezvous\RendezvousAffinityFunction.cs" />
<Compile Include="Cache\CacheAtomicUpdateTimeoutException.cs" />
<Compile Include="Cache\CacheEntryProcessorException.cs" />
<Compile Include="Cache\CacheException.cs" />
@@ -108,7 +114,10 @@
<Compile Include="Common\IgniteFutureCancelledException.cs" />
<Compile Include="Common\IgniteGuid.cs" />
<Compile Include="Common\Package-Info.cs" />
+ <Compile Include="Impl\Cache\Affinity\AffinityFunctionSerializer.cs" />
+ <Compile Include="Impl\Cache\Affinity\PlatformAffinityFunction.cs" />
<Compile Include="Impl\Cache\Event\JavaCacheEntryEventFilter.cs" />
+ <Compile Include="Impl\Common\ObjectInfoHolder.cs" />
<Compile Include="Impl\Common\PlatformJavaObjectFactoryProxy.cs" />
<Compile Include="Compute\ComputeExecutionRejectedException.cs" />
<Compile Include="Compute\ComputeJobAdapter.cs" />
@@ -414,4 +423,4 @@
<Target Name="AfterBuild">
</Target>
-->
-</Project>
+</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionBase.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionBase.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionBase.cs
new file mode 100644
index 0000000..ce2e5e1
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionBase.cs
@@ -0,0 +1,139 @@
+\ufeff/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Cache.Affinity
+{
+ using System;
+ using System.Collections.Generic;
+ using System.ComponentModel;
+ using Apache.Ignite.Core.Cluster;
+ using Apache.Ignite.Core.Common;
+
+ /// <summary>
+ /// Base class for predefined affinity functions.
+ /// </summary>
+ [Serializable]
+ public abstract class AffinityFunctionBase : IAffinityFunction
+ {
+ /// <summary> The default value for <see cref="Partitions"/> property. </summary>
+ public const int DefaultPartitions = 1024;
+
+ /** */
+ private int _partitions = DefaultPartitions;
+
+ /** */
+ private IAffinityFunction _baseFunction;
+
+
+ /// <summary>
+ /// Gets or sets the total number of partitions.
+ /// </summary>
+ [DefaultValue(DefaultPartitions)]
+ public virtual int Partitions
+ {
+ get { return _partitions; }
+ set { _partitions = value; }
+ }
+
+ /// <summary>
+ /// Gets partition number for a given key starting from 0. Partitioned caches
+ /// should make sure that keys are about evenly distributed across all partitions
+ /// from 0 to <see cref="Partitions" /> for best performance.
+ /// <para />
+ /// Note that for fully replicated caches it is possible to segment key sets among different
+ /// grid node groups. In that case each node group should return a unique partition
+ /// number. However, unlike partitioned cache, mappings of keys to nodes in
+ /// replicated caches are constant and a node cannot migrate from one partition
+ /// to another.
+ /// </summary>
+ /// <param name="key">Key to get partition for.</param>
+ /// <returns>
+ /// Partition number for a given key.
+ /// </returns>
+ public virtual int GetPartition(object key)
+ {
+ ThrowIfUninitialized();
+
+ return _baseFunction.GetPartition(key);
+ }
+
+ /// <summary>
+ /// Removes node from affinity. This method is called when it is safe to remove
+ /// disconnected node from affinity mapping.
+ /// </summary>
+ /// <param name="nodeId">The node identifier.</param>
+ public virtual void RemoveNode(Guid nodeId)
+ {
+ ThrowIfUninitialized();
+
+ _baseFunction.RemoveNode(nodeId);
+ }
+
+ /// <summary>
+ /// Gets affinity nodes for a partition. In case of replicated cache, all returned
+ /// nodes are updated in the same manner. In case of partitioned cache, the returned
+ /// list should contain only the primary and back up nodes with primary node being
+ /// always first.
+ /// <pare />
+ /// Note that partitioned affinity must obey the following contract: given that node
+ /// <code>N</code> is primary for some key <code>K</code>, if any other node(s) leave
+ /// grid and no node joins grid, node <code>N</code> will remain primary for key <code>K</code>.
+ /// </summary>
+ /// <param name="context">The affinity function context.</param>
+ /// <returns>
+ /// A collection of partitions, where each partition is a collection of nodes,
+ /// where first node is a primary node, and other nodes are backup nodes.
+ /// </returns>
+ public virtual IEnumerable<IEnumerable<IClusterNode>> AssignPartitions(AffinityFunctionContext context)
+ {
+ ThrowIfUninitialized();
+
+ return _baseFunction.AssignPartitions(context);
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether to exclude same-host-neighbors from being backups of each other.
+ /// </summary>
+ public virtual bool ExcludeNeighbors { get; set; }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AffinityFunctionBase"/> class.
+ /// </summary>
+ internal AffinityFunctionBase()
+ {
+ // No-op.
+ }
+
+ /// <summary>
+ /// Sets the base function.
+ /// </summary>
+ /// <param name="baseFunc">The base function.</param>
+ internal void SetBaseFunction(IAffinityFunction baseFunc)
+ {
+ _baseFunction = baseFunc;
+ }
+
+ /// <summary>
+ /// Gets the direct usage error.
+ /// </summary>
+ private void ThrowIfUninitialized()
+ {
+ if (_baseFunction == null)
+ throw new IgniteException(GetType() + " has not yet been initialized.");
+ }
+ }
+}
[08/33] ignite git commit: Clarified READ_COMMITTED behavior in cases
when a value is updated inside of a transaction
Posted by sb...@apache.org.
Clarified READ_COMMITTED behavior in cases when a value is updated inside of a transaction
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/005ce0f3
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/005ce0f3
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/005ce0f3
Branch: refs/heads/ignite-3547
Commit: 005ce0f3d05f529b0a1de64d7f6b59efb6612ee0
Parents: 8af3078
Author: Denis Magda <dm...@gridgain.com>
Authored: Fri Jul 8 12:58:43 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Fri Jul 8 12:58:43 2016 +0300
----------------------------------------------------------------------
.../main/java/org/apache/ignite/transactions/Transaction.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/005ce0f3/modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java b/modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java
index e2e7100..450b626 100644
--- a/modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java
+++ b/modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java
@@ -38,7 +38,10 @@ import org.apache.ignite.lang.IgniteUuid;
* will be provided for read operations. With this isolation level values are always read
* from cache global memory or persistent store every time a value is accessed. In other words,
* if the same key is accessed more than once within the same transaction, it may have different
- * value every time since global cache memory may be updated concurrently by other threads.
+ * value every time since global cache memory may be updated concurrently by other threads. However note that if an
+ * update happens inside of a transaction then the new value belonging to a key will be stored in the local
+ * transactional map and all subsequent reads using the key will return this new value avoiding requests to global
+ * cache memory.
* </li>
* <li>
* {@link TransactionIsolation#REPEATABLE_READ} isolation level means that if a value was read once
[04/33] ignite git commit: Backported test fixes.
Posted by sb...@apache.org.
Backported test fixes.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e2ec9fed
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e2ec9fed
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e2ec9fed
Branch: refs/heads/ignite-3547
Commit: e2ec9fede7793c164821b99da37455ac9f7c8fda
Parents: 5b6e781
Author: sboikov <sb...@gridgain.com>
Authored: Tue Jul 5 07:43:51 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Thu Jul 7 12:37:46 2016 +0300
----------------------------------------------------------------------
.../cache/GridCacheAbstractSelfTest.java | 113 +++++--------------
1 file changed, 29 insertions(+), 84 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e2ec9fed/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
index b918f28..d58e560 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
@@ -17,7 +17,6 @@
package org.apache.ignite.internal.processors.cache;
-import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import javax.cache.Cache;
import javax.cache.configuration.Factory;
@@ -30,7 +29,6 @@ import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.CachePeekMode;
import org.apache.ignite.cache.CacheWriteSynchronizationMode;
import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
@@ -43,7 +41,6 @@ import org.apache.ignite.internal.util.typedef.P1;
import org.apache.ignite.internal.util.typedef.R1;
import org.apache.ignite.internal.util.typedef.X;
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.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
@@ -52,7 +49,6 @@ import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.apache.ignite.transactions.Transaction;
import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
@@ -66,21 +62,12 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest {
/** Test timeout */
private static final long TEST_TIMEOUT = 30 * 1000;
- /** Store map. */
- protected static final Map<Object, Object> map = new ConcurrentHashMap8<>();
-
- /** Reads counter. */
- protected static final AtomicInteger reads = new AtomicInteger();
-
- /** Writes counter. */
- protected static final AtomicInteger writes = new AtomicInteger();
-
- /** Removes counter. */
- protected static final AtomicInteger removes = new AtomicInteger();
-
/** VM ip finder for TCP discovery. */
protected static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+ /** */
+ protected static TestCacheStoreStrategy storeStgy;
+
/**
* @return Grids count to start.
*/
@@ -97,6 +84,8 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest {
assert cnt >= 1 : "At least one grid must be started";
+ initStoreStrategy();
+
startGrids(cnt);
awaitPartitionMapExchange();
@@ -106,7 +95,18 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest {
@Override protected void afterTestsStopped() throws Exception {
stopAllGrids();
- map.clear();
+ if (storeStgy != null)
+ storeStgy.resetStore();
+ }
+
+ /**
+ * Initializes {@link #storeStgy} with respect to the nature of the test.
+ *
+ * @throws IgniteCheckedException If failed.
+ */
+ void initStoreStrategy() throws IgniteCheckedException {
+ if (storeStgy == null)
+ storeStgy = isMultiJvm() ? new H2CacheStoreStrategy() : new MapCacheStoreStrategy();
}
/** {@inheritDoc} */
@@ -188,28 +188,7 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest {
assert jcache().unwrap(Ignite.class).transactions().tx() == null;
assertEquals("Cache is not empty", 0, jcache().localSize(CachePeekMode.ALL));
- resetStore();
- }
-
- /**
- * Cleans up cache store.
- */
- protected void resetStore() {
- map.clear();
-
- reads.set(0);
- writes.set(0);
- removes.set(0);
- }
-
- /**
- * Put entry to cache store.
- *
- * @param key Key.
- * @param val Value.
- */
- protected void putToStore(Object key, Object val) {
- map.put(key, val);
+ storeStgy.resetStore();
}
/** {@inheritDoc} */
@@ -241,13 +220,18 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest {
protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
CacheConfiguration cfg = defaultCacheConfiguration();
- CacheStore<?, ?> store = cacheStore();
+ if (storeStgy != null) {
+ Factory<? extends CacheStore<Object, Object>> storeFactory = storeStgy.getStoreFactory();
- if (store != null) {
- cfg.setCacheStoreFactory(new TestStoreFactory());
- cfg.setReadThrough(true);
- cfg.setWriteThrough(true);
- cfg.setLoadPreviousValue(true);
+ CacheStore<?, ?> store = storeFactory.create();
+
+ if (store != null) {
+ cfg.setCacheStoreFactory(storeFactory);
+ cfg.setReadThrough(true);
+ cfg.setWriteThrough(true);
+ cfg.setLoadPreviousValue(true);
+ storeStgy.updateCacheConfiguration(cfg);
+ }
}
cfg.setSwapEnabled(swapEnabled());
@@ -303,37 +287,6 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest {
}
/**
- * @return Write through storage emulator.
- */
- protected static CacheStore<?, ?> cacheStore() {
- return new CacheStoreAdapter<Object, Object>() {
- @Override public void loadCache(IgniteBiInClosure<Object, Object> clo,
- Object... args) {
- for (Map.Entry<Object, Object> e : map.entrySet())
- clo.apply(e.getKey(), e.getValue());
- }
-
- @Override public Object load(Object key) {
- reads.incrementAndGet();
-
- return map.get(key);
- }
-
- @Override public void write(javax.cache.Cache.Entry<? extends Object, ? extends Object> e) {
- writes.incrementAndGet();
-
- map.put(e.getKey(), e.getValue());
- }
-
- @Override public void delete(Object key) {
- removes.incrementAndGet();
-
- map.remove(key);
- }
- };
- }
-
- /**
* @return {@code true} if swap should be enabled.
*/
protected boolean swapEnabled() {
@@ -575,12 +528,4 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest {
}
}
- /**
- * Serializable factory.
- */
- protected static class TestStoreFactory implements Factory<CacheStore> {
- @Override public CacheStore create() {
- return cacheStore();
- }
- }
}
[27/33] ignite git commit: IGNITE-3414: Hadoop: implemented new
weight-based map-reduce planner.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopDefaultMapReducePlannerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopDefaultMapReducePlannerSelfTest.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopDefaultMapReducePlannerSelfTest.java
index ffa6f7d..a69b72a 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopDefaultMapReducePlannerSelfTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopDefaultMapReducePlannerSelfTest.java
@@ -17,47 +17,27 @@
package org.apache.ignite.internal.processors.hadoop;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteFileSystem;
-import org.apache.ignite.IgniteSpringBean;
import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.configuration.FileSystemConfiguration;
import org.apache.ignite.hadoop.mapreduce.IgniteHadoopMapReducePlanner;
import org.apache.ignite.igfs.IgfsBlockLocation;
-import org.apache.ignite.igfs.IgfsFile;
-import org.apache.ignite.igfs.IgfsMetrics;
-import org.apache.ignite.igfs.IgfsOutputStream;
import org.apache.ignite.igfs.IgfsPath;
-import org.apache.ignite.igfs.IgfsPathSummary;
-import org.apache.ignite.igfs.mapreduce.IgfsRecordResolver;
-import org.apache.ignite.igfs.mapreduce.IgfsTask;
-import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystem;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.IgniteEx;
-import org.apache.ignite.internal.cluster.IgniteClusterEx;
-import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
-import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.processors.hadoop.planner.HadoopAbstractMapReducePlanner;
import org.apache.ignite.internal.processors.igfs.IgfsBlockLocationImpl;
-import org.apache.ignite.internal.processors.igfs.IgfsContext;
-import org.apache.ignite.internal.processors.igfs.IgfsEx;
-import org.apache.ignite.internal.processors.igfs.IgfsInputStreamAdapter;
-import org.apache.ignite.internal.processors.igfs.IgfsLocalMetrics;
-import org.apache.ignite.internal.processors.igfs.IgfsPaths;
-import org.apache.ignite.internal.processors.igfs.IgfsStatus;
+import org.apache.ignite.internal.processors.igfs.IgfsIgniteMock;
+import org.apache.ignite.internal.processors.igfs.IgfsMock;
import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.lang.IgniteFuture;
-import org.apache.ignite.lang.IgnitePredicate;
-import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.testframework.GridTestNode;
import org.apache.ignite.testframework.GridTestUtils;
-import org.jetbrains.annotations.Nullable;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
/**
*
@@ -90,12 +70,12 @@ public class HadoopDefaultMapReducePlannerSelfTest extends HadoopAbstractSelfTes
/** */
private static final String INVALID_HOST_3 = "invalid_host3";
- /** Mocked Grid. */
- private static final MockIgnite GRID = new MockIgnite();
-
/** Mocked IGFS. */
private static final IgniteFileSystem IGFS = new MockIgfs();
+ /** Mocked Grid. */
+ private static final IgfsIgniteMock GRID = new IgfsIgniteMock(null, IGFS);
+
/** Planner. */
private static final HadoopMapReducePlanner PLANNER = new IgniteHadoopMapReducePlanner();
@@ -109,15 +89,15 @@ public class HadoopDefaultMapReducePlannerSelfTest extends HadoopAbstractSelfTes
private static final ThreadLocal<HadoopMapReducePlan> PLAN = new ThreadLocal<>();
/**
- *
+ * Static initializer.
*/
static {
- GridTestUtils.setFieldValue(PLANNER, "ignite", GRID);
+ GridTestUtils.setFieldValue(PLANNER, HadoopAbstractMapReducePlanner.class, "ignite", GRID);
}
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
- GridTestUtils.setFieldValue(PLANNER, "log", log());
+ GridTestUtils.setFieldValue(PLANNER, HadoopAbstractMapReducePlanner.class, "log", log());
BLOCK_MAP.clear();
PROXY_MAP.clear();
@@ -445,7 +425,7 @@ public class HadoopDefaultMapReducePlannerSelfTest extends HadoopAbstractSelfTes
top.add(node2);
top.add(node3);
- HadoopMapReducePlan plan = PLANNER.preparePlan(new MockJob(reducers, splitList), top, null);
+ HadoopMapReducePlan plan = PLANNER.preparePlan(new HadoopPlannerMockJob(splitList, reducers), top, null);
PLAN.set(plan);
@@ -607,81 +587,17 @@ public class HadoopDefaultMapReducePlannerSelfTest extends HadoopAbstractSelfTes
}
/**
- * Mocked job.
+ * Mocked IGFS.
*/
- private static class MockJob implements HadoopJob {
- /** Reducers count. */
- private final int reducers;
-
- /** */
- private Collection<HadoopInputSplit> splitList;
-
+ private static class MockIgfs extends IgfsMock {
/**
* Constructor.
- *
- * @param reducers Reducers count.
- * @param splitList Splits.
*/
- private MockJob(int reducers, Collection<HadoopInputSplit> splitList) {
- this.reducers = reducers;
- this.splitList = splitList;
- }
-
- /** {@inheritDoc} */
- @Override public HadoopJobId id() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public HadoopJobInfo info() {
- return new HadoopDefaultJobInfo() {
- @Override public int reducers() {
- return reducers;
- }
- };
+ public MockIgfs() {
+ super("igfs");
}
/** {@inheritDoc} */
- @Override public Collection<HadoopInputSplit> input() throws IgniteCheckedException {
- return splitList;
- }
-
- /** {@inheritDoc} */
- @Override public HadoopTaskContext getTaskContext(HadoopTaskInfo info) throws IgniteCheckedException {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public void initialize(boolean external, UUID nodeId) throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void dispose(boolean external) throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void prepareTaskEnvironment(HadoopTaskInfo info) throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void cleanupTaskEnvironment(HadoopTaskInfo info) throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void cleanupStagingDirectory() {
- // No-op.
- }
- }
-
- /**
- * Mocked IGFS.
- */
- private static class MockIgfs implements IgfsEx {
- /** {@inheritDoc} */
@Override public boolean isProxy(URI path) {
return PROXY_MAP.containsKey(path) && PROXY_MAP.get(path);
}
@@ -692,331 +608,8 @@ public class HadoopDefaultMapReducePlannerSelfTest extends HadoopAbstractSelfTes
}
/** {@inheritDoc} */
- @Override public Collection<IgfsBlockLocation> affinity(IgfsPath path, long start, long len,
- long maxLen) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public void stop(boolean cancel) {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public IgfsContext context() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsPaths proxyPaths() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsInputStreamAdapter open(IgfsPath path, int bufSize, int seqReadsBeforePrefetch) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsInputStreamAdapter open(IgfsPath path) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsInputStreamAdapter open(IgfsPath path, int bufSize) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsStatus globalSpace() throws IgniteCheckedException {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public void globalSampling(@Nullable Boolean val) throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Boolean globalSampling() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsLocalMetrics localMetrics() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public long groupBlockSize() {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public String clientLogDirectory() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public void clientLogDirectory(String logDir) {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public boolean evictExclude(IgfsPath path, boolean primary) {
- return false;
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public String name() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public FileSystemConfiguration configuration() {
- return null;
- }
-
- /** {@inheritDoc} */
@Override public boolean exists(IgfsPath path) {
return true;
}
-
- /** {@inheritDoc} */
- @Nullable @Override public IgfsFile info(IgfsPath path) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsPathSummary summary(IgfsPath path) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public IgfsFile update(IgfsPath path, Map<String, String> props) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public void rename(IgfsPath src, IgfsPath dest) {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public boolean delete(IgfsPath path, boolean recursive) {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override public void mkdirs(IgfsPath path) {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void mkdirs(IgfsPath path, @Nullable Map<String, String> props) {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public Collection<IgfsPath> listPaths(IgfsPath path) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public Collection<IgfsFile> listFiles(IgfsPath path) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public long usedSpaceSize() {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsOutputStream create(IgfsPath path, boolean overwrite) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsOutputStream create(IgfsPath path, int bufSize, boolean overwrite, int replication,
- long blockSize, @Nullable Map<String, String> props) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsOutputStream create(IgfsPath path, int bufSize, boolean overwrite,
- @Nullable IgniteUuid affKey, int replication, long blockSize, @Nullable Map<String, String> props) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsOutputStream append(IgfsPath path, boolean create) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsOutputStream append(IgfsPath path, int bufSize, boolean create,
- @Nullable Map<String, String> props) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public void setTimes(IgfsPath path, long accessTime, long modificationTime) {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public IgfsMetrics metrics() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public void resetMetrics() {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public long size(IgfsPath path) {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override public void format() {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public <T, R> R execute(IgfsTask<T, R> task, @Nullable IgfsRecordResolver rslvr,
- Collection<IgfsPath> paths, @Nullable T arg) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public <T, R> R execute(IgfsTask<T, R> task, @Nullable IgfsRecordResolver rslvr,
- Collection<IgfsPath> paths, boolean skipNonExistentFiles, long maxRangeLen, @Nullable T arg) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public <T, R> R execute(Class<? extends IgfsTask<T, R>> taskCls,
- @Nullable IgfsRecordResolver rslvr, Collection<IgfsPath> paths, @Nullable T arg) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public <T, R> R execute(Class<? extends IgfsTask<T, R>> taskCls,
- @Nullable IgfsRecordResolver rslvr, Collection<IgfsPath> paths, boolean skipNonExistentFiles,
- long maxRangeLen, @Nullable T arg) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgniteUuid nextAffinityKey() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgniteFileSystem withAsync() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isAsync() {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override public <R> IgniteFuture<R> future() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public IgfsSecondaryFileSystem asSecondary() {
- return null;
- }
- }
-
- /**
- * Mocked Grid.
- */
- @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor")
- private static class MockIgnite extends IgniteSpringBean implements IgniteEx {
- /** {@inheritDoc} */
- @Override public IgniteClusterEx cluster() {
- return (IgniteClusterEx)super.cluster();
- }
-
- /** {@inheritDoc} */
- @Override public IgniteFileSystem igfsx(String name) {
- assert F.eq("igfs", name);
-
- return IGFS;
- }
-
- /** {@inheritDoc} */
- @Override public Hadoop hadoop() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public String name() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public <K extends GridCacheUtilityKey, V> IgniteInternalCache<K, V> utilityCache() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <K, V> IgniteInternalCache<K, V> cachex(@Nullable String name) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <K, V> IgniteInternalCache<K, V> cachex() {
- return null;
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override public Collection<IgniteInternalCache<?, ?>> cachesx(@Nullable IgnitePredicate<? super IgniteInternalCache<?, ?>>... p) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public boolean eventUserRecordable(int type) {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override public boolean allEventsUserRecordable(int[] types) {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isJmxRemoteEnabled() {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isRestartEnabled() {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override public ClusterNode localNode() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public String latestVersion() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public GridKernalContext context() {
- return null;
- }
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopMapReduceTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopMapReduceTest.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopMapReduceTest.java
index 1cb4f74..5d1de38 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopMapReduceTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopMapReduceTest.java
@@ -20,9 +20,7 @@ package org.apache.ignite.internal.processors.hadoop;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -395,10 +393,24 @@ public class HadoopMapReduceTest extends HadoopAbstractWordCountTest {
cfg.setLocalHost("127.0.0.1");
cfg.setConnectorConfiguration(null);
+ HadoopConfiguration hadoopCfg = createHadoopConfiguration();
+
+ if (hadoopCfg != null)
+ cfg.setHadoopConfiguration(hadoopCfg);
+
return G.start(cfg);
}
/**
+ * Creates custom Hadoop configuration.
+ *
+ * @return The Hadoop configuration.
+ */
+ protected HadoopConfiguration createHadoopConfiguration() {
+ return null;
+ }
+
+ /**
* @return IGFS configuration.
*/
@Override public FileSystemConfiguration igfsConfiguration() throws Exception {
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopPlannerMockJob.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopPlannerMockJob.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopPlannerMockJob.java
new file mode 100644
index 0000000..88d0f80
--- /dev/null
+++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopPlannerMockJob.java
@@ -0,0 +1,168 @@
+/*
+ * 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.hadoop;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+import java.util.UUID;
+
+/**
+ * Mock job for planner tests.
+ */
+public class HadoopPlannerMockJob implements HadoopJob {
+ /** Input splits. */
+ private final Collection<HadoopInputSplit> splits;
+
+ /** Reducers count. */
+ private final int reducers;
+
+ /**
+ * Constructor.
+ *
+ * @param splits Input splits.
+ * @param reducers Reducers.
+ */
+ public HadoopPlannerMockJob(Collection<HadoopInputSplit> splits, int reducers) {
+ this.splits = splits;
+ this.reducers = reducers;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<HadoopInputSplit> input() throws IgniteCheckedException {
+ return splits;
+ }
+
+ /** {@inheritDoc} */
+ @Override public HadoopJobInfo info() {
+ return new JobInfo(reducers);
+ }
+
+ /** {@inheritDoc} */
+ @Override public HadoopJobId id() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public HadoopTaskContext getTaskContext(HadoopTaskInfo info) throws IgniteCheckedException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void initialize(boolean external, UUID nodeId) throws IgniteCheckedException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void dispose(boolean external) throws IgniteCheckedException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void prepareTaskEnvironment(HadoopTaskInfo info) throws IgniteCheckedException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void cleanupTaskEnvironment(HadoopTaskInfo info) throws IgniteCheckedException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void cleanupStagingDirectory() {
+ throwUnsupported();
+ }
+
+ /**
+ * Throw {@link UnsupportedOperationException}.
+ */
+ private static void throwUnsupported() {
+ throw new UnsupportedOperationException("Should not be called!");
+ }
+
+ /**
+ * Mocked job info.
+ */
+ private static class JobInfo implements HadoopJobInfo {
+ /** Reducers. */
+ private final int reducers;
+
+ /**
+ * Constructor.
+ *
+ * @param reducers Reducers.
+ */
+ public JobInfo(int reducers) {
+ this.reducers = reducers;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int reducers() {
+ return reducers;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public String property(String name) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean hasCombiner() {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean hasReducer() {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public HadoopJob createJob(Class<? extends HadoopJob> jobCls, HadoopJobId jobId, IgniteLogger log,
+ @Nullable String[] libNames) throws IgniteCheckedException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String jobName() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String user() {
+ throwUnsupported();
+
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopWeightedMapReducePlannerTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopWeightedMapReducePlannerTest.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopWeightedMapReducePlannerTest.java
new file mode 100644
index 0000000..4e7cc50
--- /dev/null
+++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopWeightedMapReducePlannerTest.java
@@ -0,0 +1,599 @@
+/*
+ * 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.hadoop;
+
+import org.apache.ignite.cluster.ClusterMetrics;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.hadoop.mapreduce.IgniteHadoopWeightedMapReducePlanner;
+import org.apache.ignite.igfs.IgfsBlockLocation;
+import org.apache.ignite.igfs.IgfsPath;
+import org.apache.ignite.internal.IgniteNodeAttributes;
+import org.apache.ignite.internal.processors.hadoop.planner.HadoopAbstractMapReducePlanner;
+import org.apache.ignite.internal.processors.igfs.IgfsIgniteMock;
+import org.apache.ignite.internal.processors.igfs.IgfsMock;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgniteProductVersion;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.UUID;
+
+/**
+ * Tests for weighted map-reduce planned.
+ */
+public class HadoopWeightedMapReducePlannerTest extends GridCommonAbstractTest {
+ /** ID 1. */
+ private static final UUID ID_1 = new UUID(0, 1);
+
+ /** ID 2. */
+ private static final UUID ID_2 = new UUID(0, 2);
+
+ /** ID 3. */
+ private static final UUID ID_3 = new UUID(0, 3);
+
+ /** MAC 1. */
+ private static final String MAC_1 = "mac1";
+
+ /** MAC 2. */
+ private static final String MAC_2 = "mac2";
+
+ /** MAC 3. */
+ private static final String MAC_3 = "mac3";
+
+ /** Host 1. */
+ private static final String HOST_1 = "host1";
+
+ /** Host 2. */
+ private static final String HOST_2 = "host2";
+
+ /** Host 3. */
+ private static final String HOST_3 = "host3";
+
+ /** Host 4. */
+ private static final String HOST_4 = "host4";
+
+ /** Host 5. */
+ private static final String HOST_5 = "host5";
+
+ /** Standard node 1. */
+ private static final MockNode NODE_1 = new MockNode(ID_1, MAC_1, HOST_1);
+
+ /** Standard node 2. */
+ private static final MockNode NODE_2 = new MockNode(ID_2, MAC_2, HOST_2);
+
+ /** Standard node 3. */
+ private static final MockNode NODE_3 = new MockNode(ID_3, MAC_3, HOST_3);
+
+ /** Standard nodes. */
+ private static final Collection<ClusterNode> NODES;
+
+ /**
+ * Static initializer.
+ */
+ static {
+ NODES = new ArrayList<>();
+
+ NODES.add(NODE_1);
+ NODES.add(NODE_2);
+ NODES.add(NODE_3);
+ }
+
+ /**
+ * Test one IGFS split being assigned to affinity node.
+ *
+ * @throws Exception If failed.
+ */
+ public void testOneIgfsSplitAffinity() throws Exception {
+ IgfsMock igfs = LocationsBuilder.create().add(0, NODE_1).add(50, NODE_2).add(100, NODE_3).buildIgfs();
+
+ List<HadoopInputSplit> splits = new ArrayList<>();
+
+ splits.add(new HadoopFileBlock(new String[] { HOST_1 }, URI.create("igfs://igfs@/file"), 0, 50));
+
+ final int expReducers = 4;
+
+ HadoopPlannerMockJob job = new HadoopPlannerMockJob(splits, expReducers);
+
+ IgniteHadoopWeightedMapReducePlanner planner = createPlanner(igfs);
+
+ HadoopMapReducePlan plan = planner.preparePlan(job, NODES, null);
+
+ assert plan.mappers() == 1;
+ assert plan.mapperNodeIds().size() == 1;
+ assert plan.mapperNodeIds().contains(ID_1);
+
+ checkPlanMappers(plan, splits, NODES, false/*only 1 split*/);
+ checkPlanReducers(plan, NODES, expReducers, false/* because of threshold behavior.*/);
+ }
+
+ /**
+ * Test one HDFS splits.
+ *
+ * @throws Exception If failed.
+ */
+ public void testHdfsSplitsAffinity() throws Exception {
+ IgfsMock igfs = LocationsBuilder.create().add(0, NODE_1).add(50, NODE_2).add(100, NODE_3).buildIgfs();
+
+ final List<HadoopInputSplit> splits = new ArrayList<>();
+
+ splits.add(new HadoopFileBlock(new String[] { HOST_1 }, URI.create("hfds://" + HOST_1 + "/x"), 0, 50));
+ splits.add(new HadoopFileBlock(new String[] { HOST_2 }, URI.create("hfds://" + HOST_2 + "/x"), 50, 100));
+ splits.add(new HadoopFileBlock(new String[] { HOST_3 }, URI.create("hfds://" + HOST_3 + "/x"), 100, 37));
+
+ // The following splits belong to hosts that are out of Ignite topology at all.
+ // This means that these splits should be assigned to any least loaded modes:
+ splits.add(new HadoopFileBlock(new String[] { HOST_4 }, URI.create("hfds://" + HOST_4 + "/x"), 138, 2));
+ splits.add(new HadoopFileBlock(new String[] { HOST_5 }, URI.create("hfds://" + HOST_5 + "/x"), 140, 3));
+
+ final int expReducers = 7;
+
+ HadoopPlannerMockJob job = new HadoopPlannerMockJob(splits, expReducers);
+
+ IgniteHadoopWeightedMapReducePlanner planner = createPlanner(igfs);
+
+ final HadoopMapReducePlan plan = planner.preparePlan(job, NODES, null);
+
+ checkPlanMappers(plan, splits, NODES, true);
+
+ checkPlanReducers(plan, NODES, expReducers, true);
+ }
+
+ /**
+ * Test HDFS splits with Replication == 3.
+ *
+ * @throws Exception If failed.
+ */
+ public void testHdfsSplitsReplication() throws Exception {
+ IgfsMock igfs = LocationsBuilder.create().add(0, NODE_1).add(50, NODE_2).add(100, NODE_3).buildIgfs();
+
+ final List<HadoopInputSplit> splits = new ArrayList<>();
+
+ splits.add(new HadoopFileBlock(new String[] { HOST_1, HOST_2, HOST_3 }, URI.create("hfds://" + HOST_1 + "/x"), 0, 50));
+ splits.add(new HadoopFileBlock(new String[] { HOST_2, HOST_3, HOST_4 }, URI.create("hfds://" + HOST_2 + "/x"), 50, 100));
+ splits.add(new HadoopFileBlock(new String[] { HOST_3, HOST_4, HOST_5 }, URI.create("hfds://" + HOST_3 + "/x"), 100, 37));
+ // The following splits belong to hosts that are out of Ignite topology at all.
+ // This means that these splits should be assigned to any least loaded modes:
+ splits.add(new HadoopFileBlock(new String[] { HOST_4, HOST_5, HOST_1 }, URI.create("hfds://" + HOST_4 + "/x"), 138, 2));
+ splits.add(new HadoopFileBlock(new String[] { HOST_5, HOST_1, HOST_2 }, URI.create("hfds://" + HOST_5 + "/x"), 140, 3));
+
+ final int expReducers = 8;
+
+ HadoopPlannerMockJob job = new HadoopPlannerMockJob(splits, expReducers);
+
+ IgniteHadoopWeightedMapReducePlanner planner = createPlanner(igfs);
+
+ final HadoopMapReducePlan plan = planner.preparePlan(job, NODES, null);
+
+ checkPlanMappers(plan, splits, NODES, true);
+
+ checkPlanReducers(plan, NODES, expReducers, true);
+ }
+
+ /**
+ * Get all IDs.
+ *
+ * @param nodes Nodes.
+ * @return IDs.
+ */
+ private static Set<UUID> allIds(Collection<ClusterNode> nodes) {
+ Set<UUID> allIds = new HashSet<>();
+
+ for (ClusterNode n : nodes)
+ allIds.add(n.id());
+
+ return allIds;
+ }
+
+ /**
+ * Check mappers for the plan.
+ *
+ * @param plan Plan.
+ * @param splits Splits.
+ * @param nodes Nodes.
+ * @param expectUniformity WHether uniformity is expected.
+ */
+ private static void checkPlanMappers(HadoopMapReducePlan plan, List<HadoopInputSplit> splits,
+ Collection<ClusterNode> nodes, boolean expectUniformity) {
+ // Number of mappers should correspomd to the number of input splits:
+ assertEquals(splits.size(), plan.mappers());
+
+ if (expectUniformity) {
+ // mappers are assigned to all available nodes:
+ assertEquals(nodes.size(), plan.mapperNodeIds().size());
+
+
+ assertEquals(allIds(nodes), plan.mapperNodeIds());
+ }
+
+ // Check all splits are covered by mappers:
+ Set<HadoopInputSplit> set = new HashSet<>();
+
+ for (UUID id: plan.mapperNodeIds()) {
+ Collection<HadoopInputSplit> sp = plan.mappers(id);
+
+ assert sp != null;
+
+ for (HadoopInputSplit s: sp)
+ assertTrue(set.add(s));
+ }
+
+ // must be of the same size & contain same elements:
+ assertEquals(set, new HashSet<>(splits));
+ }
+
+ /**
+ * Check plan reducers.
+ *
+ * @param plan Plan.
+ * @param nodes Nodes.
+ * @param expReducers Expected reducers.
+ * @param expectUniformity Expected uniformity.
+ */
+ private static void checkPlanReducers(HadoopMapReducePlan plan,
+ Collection<ClusterNode> nodes, int expReducers, boolean expectUniformity) {
+
+ assertEquals(expReducers, plan.reducers());
+
+ if (expectUniformity)
+ assertEquals(allIds(nodes), plan.reducerNodeIds());
+
+ int sum = 0;
+ int lenSum = 0;
+
+ for (UUID uuid: plan.reducerNodeIds()) {
+ int[] rr = plan.reducers(uuid);
+
+ assert rr != null;
+
+ lenSum += rr.length;
+
+ for (int i: rr)
+ sum += i;
+ }
+
+ assertEquals(expReducers, lenSum);
+
+ // Numbers in the arrays must be consequtive integers stating from 0,
+ // check that simply calculating their total sum:
+ assertEquals((lenSum * (lenSum - 1) / 2), sum);
+ }
+
+ /**
+ * Create planner for IGFS.
+ *
+ * @param igfs IGFS.
+ * @return Planner.
+ */
+ private static IgniteHadoopWeightedMapReducePlanner createPlanner(IgfsMock igfs) {
+ IgniteHadoopWeightedMapReducePlanner planner = new IgniteHadoopWeightedMapReducePlanner();
+
+ IgfsIgniteMock ignite = new IgfsIgniteMock(null, igfs);
+
+ GridTestUtils.setFieldValue(planner, HadoopAbstractMapReducePlanner.class, "ignite", ignite);
+
+ return planner;
+ }
+
+ /**
+ * Throw {@link UnsupportedOperationException}.
+ */
+ private static void throwUnsupported() {
+ throw new UnsupportedOperationException("Should not be called!");
+ }
+
+ /**
+ * Mocked node.
+ */
+ private static class MockNode implements ClusterNode {
+ /** ID. */
+ private final UUID id;
+
+ /** MAC addresses. */
+ private final String macs;
+
+ /** Addresses. */
+ private final List<String> addrs;
+
+ /**
+ * Constructor.
+ *
+ * @param id Node ID.
+ * @param macs MAC addresses.
+ * @param addrs Addresses.
+ */
+ public MockNode(UUID id, String macs, String... addrs) {
+ assert addrs != null;
+
+ this.id = id;
+ this.macs = macs;
+
+ this.addrs = Arrays.asList(addrs);
+ }
+
+ /** {@inheritDoc} */
+ @Override public UUID id() {
+ return id;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override public <T> T attribute(String name) {
+ if (F.eq(name, IgniteNodeAttributes.ATTR_MACS))
+ return (T)macs;
+
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<String> addresses() {
+ return addrs;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object consistentId() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public ClusterMetrics metrics() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Map<String, Object> attributes() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<String> hostNames() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long order() {
+ throwUnsupported();
+
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteProductVersion version() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isLocal() {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isDaemon() {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isClient() {
+ throwUnsupported();
+
+ return false;
+ }
+ }
+
+ /**
+ * Locations builder.
+ */
+ private static class LocationsBuilder {
+ /** Locations. */
+ private final TreeMap<Long, Collection<MockNode>> locs = new TreeMap<>();
+
+ /**
+ * Create new locations builder.
+ *
+ * @return Locations builder.
+ */
+ public static LocationsBuilder create() {
+ return new LocationsBuilder();
+ }
+
+ /**
+ * Add locations.
+ *
+ * @param start Start.
+ * @param nodes Nodes.
+ * @return This builder for chaining.
+ */
+ public LocationsBuilder add(long start, MockNode... nodes) {
+ locs.put(start, Arrays.asList(nodes));
+
+ return this;
+ }
+
+ /**
+ * Build locations.
+ *
+ * @return Locations.
+ */
+ public TreeMap<Long, Collection<MockNode>> build() {
+ return locs;
+ }
+
+ /**
+ * Build IGFS.
+ *
+ * @return IGFS.
+ */
+ public MockIgfs buildIgfs() {
+ return new MockIgfs(build());
+ }
+ }
+
+ /**
+ * Mocked IGFS.
+ */
+ private static class MockIgfs extends IgfsMock {
+ /** Block locations. */
+ private final TreeMap<Long, Collection<MockNode>> locs;
+
+ /**
+ * Constructor.
+ *
+ * @param locs Block locations.
+ */
+ public MockIgfs(TreeMap<Long, Collection<MockNode>> locs) {
+ super("igfs");
+
+ this.locs = locs;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<IgfsBlockLocation> affinity(IgfsPath path, long start, long len) {
+ Collection<IgfsBlockLocation> res = new ArrayList<>();
+
+ long cur = start;
+ long remaining = len;
+
+ long prevLocStart = -1;
+ Collection<MockNode> prevLocNodes = null;
+
+ for (Map.Entry<Long, Collection<MockNode>> locEntry : locs.entrySet()) {
+ long locStart = locEntry.getKey();
+ Collection<MockNode> locNodes = locEntry.getValue();
+
+ if (prevLocNodes != null) {
+ if (cur < locStart) {
+ // Add part from previous block.
+ long prevLen = locStart - prevLocStart;
+
+ res.add(new IgfsBlockLocationMock(cur, prevLen, prevLocNodes));
+
+ cur = locStart;
+ remaining -= prevLen;
+ }
+ }
+
+ prevLocStart = locStart;
+ prevLocNodes = locNodes;
+
+ if (remaining == 0)
+ break;
+ }
+
+ // Add remainder.
+ if (remaining != 0)
+ res.add(new IgfsBlockLocationMock(cur, remaining, prevLocNodes));
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean exists(IgfsPath path) {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isProxy(URI path) {
+ return false;
+ }
+ }
+
+ /**
+ * Mocked block location.
+ */
+ private static class IgfsBlockLocationMock implements IgfsBlockLocation {
+ /** Start. */
+ private final long start;
+
+ /** Length. */
+ private final long len;
+
+ /** Node IDs. */
+ private final List<UUID> nodeIds;
+
+ /**
+ * Constructor.
+ *
+ * @param start Start.
+ * @param len Length.
+ * @param nodes Nodes.
+ */
+ public IgfsBlockLocationMock(long start, long len, Collection<MockNode> nodes) {
+ this.start = start;
+ this.len = len;
+
+ this.nodeIds = new ArrayList<>(nodes.size());
+
+ for (MockNode node : nodes)
+ nodeIds.add(node.id);
+ }
+
+ /** {@inheritDoc} */
+ @Override public long start() {
+ return start;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long length() {
+ return len;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<UUID> nodeIds() {
+ return nodeIds;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<String> names() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<String> hosts() {
+ throwUnsupported();
+
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopWeightedPlannerMapReduceTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopWeightedPlannerMapReduceTest.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopWeightedPlannerMapReduceTest.java
new file mode 100644
index 0000000..e0403c2
--- /dev/null
+++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopWeightedPlannerMapReduceTest.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.internal.processors.hadoop;
+
+import org.apache.ignite.configuration.HadoopConfiguration;
+import org.apache.ignite.hadoop.mapreduce.IgniteHadoopWeightedMapReducePlanner;
+
+/**
+ * Tests whole map-red execution Weighted planner.
+ */
+public class HadoopWeightedPlannerMapReduceTest extends HadoopMapReduceTest {
+ /** {@inheritDoc} */
+ @Override protected HadoopConfiguration createHadoopConfiguration() {
+ HadoopConfiguration hadoopCfg = new HadoopConfiguration();
+
+ // Use weighted planner with default settings:
+ IgniteHadoopWeightedMapReducePlanner planner = new IgniteHadoopWeightedMapReducePlanner();
+
+ hadoopCfg.setMapReducePlanner(planner);
+
+ return hadoopCfg;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
index e0d1142..52104a8 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
@@ -28,7 +28,6 @@ import org.apache.ignite.hadoop.cache.HadoopTxConfigCacheTest;
import org.apache.ignite.hadoop.fs.KerberosHadoopFileSystemFactorySelfTest;
import org.apache.ignite.hadoop.util.BasicUserNameMapperSelfTest;
import org.apache.ignite.hadoop.util.ChainedUserNameMapperSelfTest;
-import org.apache.ignite.hadoop.util.KerberosUserNameMapper;
import org.apache.ignite.hadoop.util.KerberosUserNameMapperSelfTest;
import org.apache.ignite.igfs.Hadoop1OverIgfsDualAsyncTest;
import org.apache.ignite.igfs.Hadoop1OverIgfsDualSyncTest;
@@ -70,6 +69,8 @@ import org.apache.ignite.internal.processors.hadoop.HadoopTasksV1Test;
import org.apache.ignite.internal.processors.hadoop.HadoopTasksV2Test;
import org.apache.ignite.internal.processors.hadoop.HadoopV2JobSelfTest;
import org.apache.ignite.internal.processors.hadoop.HadoopValidationSelfTest;
+import org.apache.ignite.internal.processors.hadoop.HadoopWeightedMapReducePlannerTest;
+import org.apache.ignite.internal.processors.hadoop.HadoopWeightedPlannerMapReduceTest;
import org.apache.ignite.internal.processors.hadoop.shuffle.collections.HadoopConcurrentHashMultimapSelftest;
import org.apache.ignite.internal.processors.hadoop.shuffle.collections.HadoopHashMapSelfTest;
import org.apache.ignite.internal.processors.hadoop.shuffle.collections.HadoopSkipListSelfTest;
@@ -108,6 +109,9 @@ public class IgniteHadoopTestSuite extends TestSuite {
TestSuite suite = new TestSuite("Ignite Hadoop MR Test Suite");
+ suite.addTest(new TestSuite(ldr.loadClass(HadoopDefaultMapReducePlannerSelfTest.class.getName())));
+ suite.addTest(new TestSuite(ldr.loadClass(HadoopWeightedMapReducePlannerTest.class.getName())));
+
suite.addTest(new TestSuite(ldr.loadClass(BasicUserNameMapperSelfTest.class.getName())));
suite.addTest(new TestSuite(ldr.loadClass(KerberosUserNameMapperSelfTest.class.getName())));
suite.addTest(new TestSuite(ldr.loadClass(ChainedUserNameMapperSelfTest.class.getName())));
@@ -154,7 +158,6 @@ public class IgniteHadoopTestSuite extends TestSuite {
suite.addTest(new TestSuite(ldr.loadClass(HadoopValidationSelfTest.class.getName())));
- suite.addTest(new TestSuite(ldr.loadClass(HadoopDefaultMapReducePlannerSelfTest.class.getName())));
suite.addTest(new TestSuite(ldr.loadClass(HadoopJobTrackerSelfTest.class.getName())));
suite.addTest(new TestSuite(ldr.loadClass(HadoopHashMapSelfTest.class.getName())));
@@ -174,6 +177,7 @@ public class IgniteHadoopTestSuite extends TestSuite {
suite.addTest(new TestSuite(ldr.loadClass(HadoopTasksV2Test.class.getName())));
suite.addTest(new TestSuite(ldr.loadClass(HadoopMapReduceTest.class.getName())));
+ suite.addTest(new TestSuite(ldr.loadClass(HadoopWeightedPlannerMapReduceTest.class.getName())));
suite.addTest(new TestSuite(ldr.loadClass(HadoopMapReduceEmbeddedSelfTest.class.getName())));
[11/33] ignite git commit: IGNITE-1849 GridCacheAdapter - made size
tasks @GridInternal
Posted by sb...@apache.org.
IGNITE-1849 GridCacheAdapter - made size tasks @GridInternal
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a33dd1c5
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a33dd1c5
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a33dd1c5
Branch: refs/heads/ignite-3547
Commit: a33dd1c5d680c6a3d9dd266f135f139cacd7772f
Parents: 762c43d
Author: Alexander Paschenko <al...@gmail.com>
Authored: Wed Jul 13 05:01:02 2016 +0300
Committer: Alexander Paschenko <al...@gmail.com>
Committed: Wed Jul 13 05:01:02 2016 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheAdapter.java | 2 +
.../IgniteCacheInternalEventsIgnoreTest.java | 53 ++++++++++++++++++++
.../testsuites/IgniteCacheTestSuite5.java | 2 +
3 files changed, 57 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/a33dd1c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 55bd81d..05fd7d8 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
@@ -6656,6 +6656,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
/**
* Size task.
*/
+ @GridInternal
private static class SizeTask extends ComputeTaskAdapter<Object, Integer> {
/** */
private static final long serialVersionUID = 0L;
@@ -6721,6 +6722,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
/**
* Size task.
*/
+ @GridInternal
private static class SizeLongTask extends ComputeTaskAdapter<Object, Long> {
/** */
private static final long serialVersionUID = 0L;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a33dd1c5/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreTest.java
new file mode 100644
index 0000000..e87206d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInternalEventsIgnoreTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.atomic.AtomicBoolean;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.events.Event;
+import org.apache.ignite.events.EventType;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/** */
+public class IgniteCacheInternalEventsIgnoreTest extends GridCommonAbstractTest {
+ /** */
+ private static final AtomicBoolean evtFlag = new AtomicBoolean();
+
+ /** */
+ public void testInternalEventsIgnore() throws Exception {
+ Ignite ignite = startGrid(1);
+ ignite.events().localListen(new EvtLsnr(), EventType.EVT_TASK_STARTED, EventType.EVT_TASK_REDUCED,
+ EventType.EVT_TASK_FINISHED);
+ IgniteCache cache = ignite.createCache(defaultCacheConfiguration().setName("myTestCache"));
+ cache.size(CachePeekMode.ALL);
+ cache.sizeLong(CachePeekMode.ALL);
+ assertFalse(evtFlag.get());
+ }
+
+ /** */
+ private static final class EvtLsnr implements IgnitePredicate<Event> {
+ /** {@inheritDoc} */
+ @Override public boolean apply(Event e) {
+ evtFlag.set(true);
+ return true;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a33dd1c5/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
index 98a3c44..af54f91 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
@@ -21,6 +21,7 @@ import junit.framework.TestSuite;
import org.apache.ignite.internal.processors.cache.CacheNearReaderUpdateTest;
import org.apache.ignite.internal.processors.cache.CacheSerializableTransactionsTest;
import org.apache.ignite.internal.processors.cache.EntryVersionConsistencyReadThroughTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheInternalEventsIgnoreTest;
import org.apache.ignite.internal.processors.cache.IgniteCachePutStackOverflowSelfTest;
import org.apache.ignite.internal.processors.cache.IgniteCacheStoreCollectionTest;
import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheTxIteratorSelfTest;
@@ -44,6 +45,7 @@ public class IgniteCacheTestSuite5 extends TestSuite {
suite.addTestSuite(IgniteCachePutStackOverflowSelfTest.class);
suite.addTestSuite(EntryVersionConsistencyReadThroughTest.class);
suite.addTestSuite(IgniteCacheTxIteratorSelfTest.class);
+ suite.addTestSuite(IgniteCacheInternalEventsIgnoreTest.class);
return suite;
}
[30/33] ignite git commit: Merge branch 'gridgain-7.5.30' into
ignite-1849
Posted by sb...@apache.org.
Merge branch 'gridgain-7.5.30' into ignite-1849
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b81dbbf2
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b81dbbf2
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b81dbbf2
Branch: refs/heads/ignite-3547
Commit: b81dbbf23b7941bfbaac18ce9004ef06b0f1f4f8
Parents: 5ae31fa 448571b
Author: Alexander Paschenko <al...@gmail.com>
Authored: Tue Jul 19 19:55:11 2016 +0300
Committer: Alexander Paschenko <al...@gmail.com>
Committed: Tue Jul 19 19:55:11 2016 +0300
----------------------------------------------------------------------
.../ignite/internal/binary/BinaryContext.java | 6 +-
.../internal/binary/BinaryObjectImpl.java | 8 +
.../internal/binary/GridBinaryMarshaller.java | 11 +-
.../GridAffinityFunctionContextImpl.java | 9 +
.../processors/cache/GridCacheProcessor.java | 65 +-
.../affinity/PlatformAffinityFunction.java | 277 ++++++
.../PlatformAffinityFunctionTarget.java | 113 +++
.../cache/affinity/PlatformAffinityUtils.java | 116 +++
.../callback/PlatformCallbackGateway.java | 89 ++
.../callback/PlatformCallbackUtils.java | 49 ++
.../PlatformDotNetConfigurationClosure.java | 115 ++-
.../dotnet/PlatformDotNetAffinityFunction.java | 171 ++++
.../binary/BinaryMarshallerSelfTest.java | 41 +
.../processors/igfs/IgfsIgniteMock.java | 492 +++++++++++
.../internal/processors/igfs/IgfsMock.java | 397 +++++++++
.../mapreduce/IgniteHadoopMapReducePlanner.java | 48 +-
.../IgniteHadoopWeightedMapReducePlanner.java | 846 +++++++++++++++++++
.../internal/processors/hadoop/HadoopUtils.java | 81 ++
.../planner/HadoopAbstractMapReducePlanner.java | 116 +++
.../planner/HadoopMapReducePlanGroup.java | 150 ++++
.../planner/HadoopMapReducePlanTopology.java | 89 ++
.../HadoopDefaultMapReducePlannerSelfTest.java | 451 +---------
.../processors/hadoop/HadoopMapReduceTest.java | 16 +-
.../processors/hadoop/HadoopPlannerMockJob.java | 168 ++++
.../HadoopWeightedMapReducePlannerTest.java | 599 +++++++++++++
.../HadoopWeightedPlannerMapReduceTest.java | 38 +
.../testsuites/IgniteHadoopTestSuite.java | 8 +-
.../cpp/common/include/ignite/common/java.h | 18 +
modules/platforms/cpp/common/src/java.cpp | 36 +-
.../Apache.Ignite.Core.Tests.csproj | 9 +-
.../Affinity/AffinityFunctionSpringTest.cs | 184 ++++
.../Config/Cache/Affinity/affinity-function.xml | 129 +++
.../Cache/Affinity/affinity-function2.xml | 49 ++
.../Apache.Ignite.Core.Tests/TestRunner.cs | 3 +-
.../Apache.Ignite.Core.csproj | 14 +-
.../Cache/Affinity/AffinityFunctionContext.cs | 120 +++
.../Cache/Affinity/AffinityTopologyVersion.cs | 138 +++
.../Cache/Affinity/Fair/FairAffinityFunction.cs | 33 +
.../Cache/Affinity/Fair/Package-Info.cs | 26 +
.../Cache/Affinity/IAffinityFunction.cs | 82 ++
.../Cache/Affinity/Package-Info.cs | 26 +
.../Cache/Affinity/Rendezvous/Package-Info.cs | 26 +
.../Rendezvous/RendezvousAffinityFunction.cs | 32 +
.../Apache.Ignite.Core/Events/EventReader.cs | 8 +-
.../dotnet/Apache.Ignite.Core/Ignition.cs | 38 +-
.../Impl/Binary/BinaryReaderExtensions.cs | 14 +
.../Impl/Binary/Marshaller.cs | 6 +-
.../Impl/Cache/Affinity/AffinityFunctionBase.cs | 140 +++
.../Affinity/AffinityFunctionSerializer.cs | 277 ++++++
.../Cache/Affinity/PlatformAffinityFunction.cs | 74 ++
.../Impl/Common/ObjectInfoHolder.cs | 86 ++
.../Apache.Ignite.Core/Impl/IgniteUtils.cs | 10 +-
.../Impl/Unmanaged/UnmanagedCallbackHandlers.cs | 6 +
.../Impl/Unmanaged/UnmanagedCallbacks.cs | 133 ++-
54 files changed, 5756 insertions(+), 530 deletions(-)
----------------------------------------------------------------------
[09/33] ignite git commit: CacheKeepBinaryIterationSwapEnabledTest
fix.
Posted by sb...@apache.org.
CacheKeepBinaryIterationSwapEnabledTest fix.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7aa609aa
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7aa609aa
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7aa609aa
Branch: refs/heads/ignite-3547
Commit: 7aa609aa54f0015649776105bf32b2a213fa031d
Parents: 005ce0f
Author: Anton Vinogradov <av...@apache.org>
Authored: Mon Jul 11 15:30:53 2016 +0300
Committer: Anton Vinogradov <av...@apache.org>
Committed: Mon Jul 11 15:30:53 2016 +0300
----------------------------------------------------------------------
.../cache/CacheEvictableEntryImpl.java | 11 ++++--
.../CacheKeepBinaryIterationTest.java | 36 ++++++++++----------
2 files changed, 27 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/7aa609aa/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
index 9f4d9d7..aef71ed 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
@@ -64,9 +64,16 @@ public class CacheEvictableEntryImpl<K, V> implements EvictableEntry<K, V> {
try {
assert ctx != null;
- assert ctx.evicts() != null;
- return ctx.evicts().evict(cached, null, false, null);
+ GridCacheEvictionManager mgr = ctx.evicts();
+
+ if (mgr == null) {
+ assert ctx.kernalContext().isStopping();
+
+ return false;
+ }
+
+ return mgr.evict(cached, null, false, null);
}
catch (IgniteCheckedException e) {
U.error(ctx.grid().log(), "Failed to evict entry from cache: " + cached, e);
http://git-wip-us.apache.org/repos/asf/ignite/blob/7aa609aa/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationTest.java
index a775d21..605181f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationTest.java
@@ -29,11 +29,9 @@ import org.apache.ignite.cache.query.QueryCursor;
import org.apache.ignite.cache.query.ScanQuery;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.binary.BinaryMarshaller;
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.spi.communication.tcp.TcpCommunicationSpi;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
@@ -221,11 +219,11 @@ public class CacheKeepBinaryIterationTest extends GridCommonAbstractTest {
/**
* @param ccfg Cache configuration.
*/
- private void doTestScanQuery(CacheConfiguration<Object, Object> ccfg, boolean keepBinary,
- boolean primitives) throws IgniteInterruptedCheckedException {
+ private void doTestScanQuery(final CacheConfiguration<Object, Object> ccfg, boolean keepBinary,
+ boolean primitives) throws Exception {
IgniteCache<Object, Object> cache = grid(0).createCache(ccfg);
- assertTrue(cache.size() == 0);
+ assertEquals(0, cache.size());
try {
for (int i = 0; i < KEYS; i++)
@@ -272,24 +270,25 @@ public class CacheKeepBinaryIterationTest extends GridCommonAbstractTest {
}
}
finally {
- cache.removeAll();
+ if (ccfg.getEvictionPolicy() != null) { // TODO: IGNITE-3462. Fixes evictionPolicy issues at cache destroy.
+ stopAllGrids();
- if (ccfg.getEvictionPolicy() != null)
- U.sleep(1000); // Fixes evictionPolicy issues at cache destroy.
-
- grid(0).destroyCache(ccfg.getName());
+ startGridsMultiThreaded(getServerNodeCount());
+ }
+ else
+ grid(0).destroyCache(ccfg.getName());
}
}
/**
* @param ccfg Cache configuration.
*/
- private void doTestLocalEntries(CacheConfiguration<Object, Object> ccfg,
+ private void doTestLocalEntries(final CacheConfiguration<Object, Object> ccfg,
boolean keepBinary,
- boolean primitives) throws IgniteInterruptedCheckedException {
+ boolean primitives) throws Exception {
IgniteCache<Object, Object> cache = grid(0).createCache(ccfg);
- assertTrue(cache.size() == 0);
+ assertEquals(0, cache.size());
try {
for (int i = 0; i < KEYS; i++)
@@ -341,12 +340,13 @@ public class CacheKeepBinaryIterationTest extends GridCommonAbstractTest {
}
}
finally {
- cache.removeAll();
+ if (ccfg.getEvictionPolicy() != null) { // TODO: IGNITE-3462. Fixes evictionPolicy issues at cache destroy.
+ stopAllGrids();
- if (ccfg.getEvictionPolicy() != null)
- U.sleep(1000); // Fixes evictionPolicy issues at cache destroy.
-
- grid(0).destroyCache(ccfg.getName());
+ startGridsMultiThreaded(getServerNodeCount());
+ }
+ else
+ grid(0).destroyCache(ccfg.getName());
}
}
[28/33] ignite git commit: IGNITE-3414: Hadoop: implemented new
weight-based map-reduce planner.
Posted by sb...@apache.org.
IGNITE-3414: Hadoop: implemented new weight-based map-reduce planner.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/73649386
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/73649386
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/73649386
Branch: refs/heads/ignite-3547
Commit: 736493865c1e3a56f864a01583d38e50d02b2c56
Parents: 5f57cc8
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Jul 19 15:16:21 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Jul 19 15:16:21 2016 +0300
----------------------------------------------------------------------
.../processors/igfs/IgfsIgniteMock.java | 492 +++++++++++
.../internal/processors/igfs/IgfsMock.java | 397 +++++++++
.../mapreduce/IgniteHadoopMapReducePlanner.java | 48 +-
.../IgniteHadoopWeightedMapReducePlanner.java | 846 +++++++++++++++++++
.../internal/processors/hadoop/HadoopUtils.java | 81 ++
.../planner/HadoopAbstractMapReducePlanner.java | 116 +++
.../planner/HadoopMapReducePlanGroup.java | 150 ++++
.../planner/HadoopMapReducePlanTopology.java | 89 ++
.../HadoopDefaultMapReducePlannerSelfTest.java | 451 +---------
.../processors/hadoop/HadoopMapReduceTest.java | 16 +-
.../processors/hadoop/HadoopPlannerMockJob.java | 168 ++++
.../HadoopWeightedMapReducePlannerTest.java | 599 +++++++++++++
.../HadoopWeightedPlannerMapReduceTest.java | 38 +
.../testsuites/IgniteHadoopTestSuite.java | 8 +-
14 files changed, 3022 insertions(+), 477 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsIgniteMock.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..0c55595
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsIgniteMock.java
@@ -0,0 +1,492 @@
+/*
+ * 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.igfs;
+
+import org.apache.ignite.IgniteAtomicLong;
+import org.apache.ignite.IgniteAtomicReference;
+import org.apache.ignite.IgniteAtomicSequence;
+import org.apache.ignite.IgniteAtomicStamped;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteCountDownLatch;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.IgniteEvents;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteFileSystem;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.IgniteMessaging;
+import org.apache.ignite.IgniteQueue;
+import org.apache.ignite.IgniteScheduler;
+import org.apache.ignite.IgniteSemaphore;
+import org.apache.ignite.IgniteServices;
+import org.apache.ignite.IgniteSet;
+import org.apache.ignite.IgniteTransactions;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cluster.ClusterGroup;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.CollectionConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.cluster.IgniteClusterEx;
+import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.processors.hadoop.Hadoop;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.lang.IgniteProductVersion;
+import org.apache.ignite.plugin.IgnitePlugin;
+import org.apache.ignite.plugin.PluginNotFoundException;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * Mocked Ignite implementation for IGFS tests.
+ */
+public class IgfsIgniteMock implements IgniteEx {
+ /** Name. */
+ private final String name;
+
+ /** IGFS. */
+ private final IgniteFileSystem igfs;
+
+ /**
+ * Constructor.
+ *
+ * @param igfs IGFS instance.
+ */
+ public IgfsIgniteMock(@Nullable String name, IgniteFileSystem igfs) {
+ this.name = name;
+ this.igfs = igfs;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K extends GridCacheUtilityKey, V> IgniteInternalCache<K, V> utilityCache() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <K, V> IgniteInternalCache<K, V> cachex(@Nullable String name) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <K, V> IgniteInternalCache<K, V> cachex() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override public Collection<IgniteInternalCache<?, ?>> cachesx(
+ @Nullable IgnitePredicate<? super IgniteInternalCache<?, ?>>... p) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean eventUserRecordable(int type) {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean allEventsUserRecordable(int[] types) {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isJmxRemoteEnabled() {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isRestartEnabled() {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public IgniteFileSystem igfsx(@Nullable String name) {
+ return F.eq(name, igfs.name()) ? igfs : null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Hadoop hadoop() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteClusterEx cluster() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public String latestVersion() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public ClusterNode localNode() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public GridKernalContext context() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String name() {
+ return name;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteLogger log() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteConfiguration configuration() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteCompute compute() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteCompute compute(ClusterGroup grp) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteMessaging message() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteMessaging message(ClusterGroup grp) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteEvents events() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteEvents events(ClusterGroup grp) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteServices services() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteServices services(ClusterGroup grp) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public ExecutorService executorService() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public ExecutorService executorService(ClusterGroup grp) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteProductVersion version() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteScheduler scheduler() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> IgniteCache<K, V> createCache(CacheConfiguration<K, V> cacheCfg) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> IgniteCache<K, V> createCache(String cacheName) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheCfg) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> IgniteCache<K, V> getOrCreateCache(String cacheName) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> void addCacheConfiguration(CacheConfiguration<K, V> cacheCfg) {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> IgniteCache<K, V> createCache(CacheConfiguration<K, V> cacheCfg,
+ NearCacheConfiguration<K, V> nearCfg) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheCfg,
+ NearCacheConfiguration<K, V> nearCfg) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> IgniteCache<K, V> createNearCache(@Nullable String cacheName,
+ NearCacheConfiguration<K, V> nearCfg) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> IgniteCache<K, V> getOrCreateNearCache(@Nullable String cacheName,
+ NearCacheConfiguration<K, V> nearCfg) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void destroyCache(String cacheName) {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> IgniteCache<K, V> cache(@Nullable String name) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<String> cacheNames() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteTransactions transactions() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> IgniteDataStreamer<K, V> dataStreamer(@Nullable String cacheName) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteFileSystem fileSystem(String name) {
+ IgniteFileSystem res = igfsx(name);
+
+ if (res == null)
+ throw new IllegalArgumentException("IGFS is not configured: " + name);
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<IgniteFileSystem> fileSystems() {
+ return Collections.singleton(igfs);
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteAtomicSequence atomicSequence(String name, long initVal, boolean create)
+ throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteAtomicLong atomicLong(String name, long initVal, boolean create) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> IgniteAtomicReference<T> atomicReference(String name, @Nullable T initVal, boolean create)
+ throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T, S> IgniteAtomicStamped<T, S> atomicStamped(String name, @Nullable T initVal,
+ @Nullable S initStamp, boolean create) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteCountDownLatch countDownLatch(String name, int cnt, boolean autoDel, boolean create)
+ throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteSemaphore semaphore(String name, int cnt, boolean failoverSafe, boolean create)
+ throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> IgniteQueue<T> queue(String name, int cap, @Nullable CollectionConfiguration cfg)
+ throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> IgniteSet<T> set(String name, @Nullable CollectionConfiguration cfg) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T extends IgnitePlugin> T plugin(String name) throws PluginNotFoundException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteBinary binary() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void close() throws IgniteException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K> Affinity<K> affinity(String cacheName) {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /**
+ * Throw {@link UnsupportedOperationException}.
+ */
+ private static void throwUnsupported() {
+ throw new UnsupportedOperationException("Should not be called!");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsMock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsMock.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsMock.java
new file mode 100644
index 0000000..dccab4a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsMock.java
@@ -0,0 +1,397 @@
+/*
+ * 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.igfs;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteFileSystem;
+import org.apache.ignite.configuration.FileSystemConfiguration;
+import org.apache.ignite.igfs.IgfsBlockLocation;
+import org.apache.ignite.igfs.IgfsFile;
+import org.apache.ignite.igfs.IgfsMetrics;
+import org.apache.ignite.igfs.IgfsOutputStream;
+import org.apache.ignite.igfs.IgfsPath;
+import org.apache.ignite.igfs.IgfsPathSummary;
+import org.apache.ignite.igfs.mapreduce.IgfsRecordResolver;
+import org.apache.ignite.igfs.mapreduce.IgfsTask;
+import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystem;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.Nullable;
+
+import java.net.URI;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Mocked IGFS implementation for IGFS tests.
+ */
+public class IgfsMock implements IgfsEx {
+ /** Name. */
+ private final String name;
+
+ /**
+ * Constructor.
+ *
+ * @param name Name.
+ */
+ public IgfsMock(@Nullable String name) {
+ this.name = name;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void stop(boolean cancel) {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsContext context() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsPaths proxyPaths() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsInputStreamAdapter open(IgfsPath path, int bufSize, int seqReadsBeforePrefetch) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsInputStreamAdapter open(IgfsPath path) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsInputStreamAdapter open(IgfsPath path, int bufSize) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsStatus globalSpace() throws IgniteCheckedException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void globalSampling(@Nullable Boolean val) throws IgniteCheckedException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Boolean globalSampling() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsLocalMetrics localMetrics() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long groupBlockSize() {
+ throwUnsupported();
+
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public String clientLogDirectory() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void clientLogDirectory(String logDir) {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean evictExclude(IgfsPath path, boolean primary) {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteUuid nextAffinityKey() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isProxy(URI path) {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsSecondaryFileSystem asSecondary() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String name() {
+ return name;
+ }
+
+ /** {@inheritDoc} */
+ @Override public FileSystemConfiguration configuration() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsPathSummary summary(IgfsPath path) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsOutputStream create(IgfsPath path, boolean overwrite) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsOutputStream create(IgfsPath path, int bufSize, boolean overwrite, int replication,
+ long blockSize, @Nullable Map<String, String> props) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsOutputStream create(IgfsPath path, int bufSize, boolean overwrite, @Nullable IgniteUuid affKey,
+ int replication, long blockSize, @Nullable Map<String, String> props) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsOutputStream append(IgfsPath path, boolean create) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsOutputStream append(IgfsPath path, int bufSize, boolean create,
+ @Nullable Map<String, String> props) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void setTimes(IgfsPath path, long accessTime, long modificationTime) throws IgniteException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<IgfsBlockLocation> affinity(IgfsPath path, long start, long len)
+ throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<IgfsBlockLocation> affinity(IgfsPath path, long start, long len, long maxLen)
+ throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsMetrics metrics() throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void resetMetrics() throws IgniteException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public long size(IgfsPath path) throws IgniteException {
+ throwUnsupported();
+
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void format() throws IgniteException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T, R> R execute(IgfsTask<T, R> task, @Nullable IgfsRecordResolver rslvr,
+ Collection<IgfsPath> paths, @Nullable T arg) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T, R> R execute(IgfsTask<T, R> task, @Nullable IgfsRecordResolver rslvr,
+ Collection<IgfsPath> paths, boolean skipNonExistentFiles, long maxRangeLen, @Nullable T arg)
+ throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T, R> R execute(Class<? extends IgfsTask<T, R>> taskCls, @Nullable IgfsRecordResolver rslvr,
+ Collection<IgfsPath> paths, @Nullable T arg) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T, R> R execute(Class<? extends IgfsTask<T, R>> taskCls, @Nullable IgfsRecordResolver rslvr,
+ Collection<IgfsPath> paths, boolean skipNonExistentFiles, long maxRangeLen, @Nullable T arg)
+ throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean exists(IgfsPath path) {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsFile update(IgfsPath path, Map<String, String> props) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void rename(IgfsPath src, IgfsPath dest) throws IgniteException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean delete(IgfsPath path, boolean recursive) throws IgniteException {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void mkdirs(IgfsPath path) throws IgniteException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void mkdirs(IgfsPath path, @Nullable Map<String, String> props) throws IgniteException {
+ throwUnsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<IgfsPath> listPaths(IgfsPath path) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<IgfsFile> listFiles(IgfsPath path) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public IgfsFile info(IgfsPath path) throws IgniteException {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long usedSpaceSize() throws IgniteException {
+ throwUnsupported();
+
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteFileSystem withAsync() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isAsync() {
+ throwUnsupported();
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <R> IgniteFuture<R> future() {
+ throwUnsupported();
+
+ return null;
+ }
+
+ /**
+ * Throw {@link UnsupportedOperationException}.
+ */
+ private static void throwUnsupported() {
+ throw new UnsupportedOperationException("Should not be called!");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/main/java/org/apache/ignite/hadoop/mapreduce/IgniteHadoopMapReducePlanner.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/mapreduce/IgniteHadoopMapReducePlanner.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/mapreduce/IgniteHadoopMapReducePlanner.java
index 287b5ec..d4a44fa 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/mapreduce/IgniteHadoopMapReducePlanner.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/mapreduce/IgniteHadoopMapReducePlanner.java
@@ -26,10 +26,9 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.UUID;
-import org.apache.ignite.Ignite;
+
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.igfs.IgfsBlockLocation;
import org.apache.ignite.igfs.IgfsPath;
@@ -38,14 +37,11 @@ import org.apache.ignite.internal.processors.hadoop.HadoopFileBlock;
import org.apache.ignite.internal.processors.hadoop.HadoopInputSplit;
import org.apache.ignite.internal.processors.hadoop.HadoopJob;
import org.apache.ignite.internal.processors.hadoop.HadoopMapReducePlan;
-import org.apache.ignite.internal.processors.hadoop.HadoopMapReducePlanner;
import org.apache.ignite.internal.processors.hadoop.igfs.HadoopIgfsEndpoint;
import org.apache.ignite.internal.processors.hadoop.planner.HadoopDefaultMapReducePlan;
+import org.apache.ignite.internal.processors.hadoop.planner.HadoopAbstractMapReducePlanner;
import org.apache.ignite.internal.processors.igfs.IgfsEx;
import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.resources.IgniteInstanceResource;
-import org.apache.ignite.resources.LoggerResource;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -54,16 +50,7 @@ import static org.apache.ignite.IgniteFileSystem.IGFS_SCHEME;
/**
* Default map-reduce planner implementation.
*/
-public class IgniteHadoopMapReducePlanner implements HadoopMapReducePlanner {
- /** Injected grid. */
- @IgniteInstanceResource
- private Ignite ignite;
-
- /** Logger. */
- @SuppressWarnings("UnusedDeclaration")
- @LoggerResource
- private IgniteLogger log;
-
+public class IgniteHadoopMapReducePlanner extends HadoopAbstractMapReducePlanner {
/** {@inheritDoc} */
@Override public HadoopMapReducePlan preparePlan(HadoopJob job, Collection<ClusterNode> top,
@Nullable HadoopMapReducePlan oldPlan) throws IgniteCheckedException {
@@ -98,7 +85,7 @@ public class IgniteHadoopMapReducePlanner implements HadoopMapReducePlanner {
Iterable<HadoopInputSplit> splits) throws IgniteCheckedException {
Map<UUID, Collection<HadoopInputSplit>> mappers = new HashMap<>();
- Map<String, Collection<UUID>> nodes = hosts(top);
+ Map<String, Collection<UUID>> nodes = groupByHost(top);
Map<UUID, Integer> nodeLoads = new HashMap<>(top.size(), 1.0f); // Track node load.
@@ -129,33 +116,6 @@ public class IgniteHadoopMapReducePlanner implements HadoopMapReducePlanner {
}
/**
- * Groups nodes by host names.
- *
- * @param top Topology to group.
- * @return Map.
- */
- private static Map<String, Collection<UUID>> hosts(Collection<ClusterNode> top) {
- Map<String, Collection<UUID>> grouped = U.newHashMap(top.size());
-
- for (ClusterNode node : top) {
- for (String host : node.hostNames()) {
- Collection<UUID> nodeIds = grouped.get(host);
-
- if (nodeIds == null) {
- // Expecting 1-2 nodes per host.
- nodeIds = new ArrayList<>(2);
-
- grouped.put(host, nodeIds);
- }
-
- nodeIds.add(node.id());
- }
- }
-
- return grouped;
- }
-
- /**
* Determine the best node for this split.
*
* @param split Split.
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/main/java/org/apache/ignite/hadoop/mapreduce/IgniteHadoopWeightedMapReducePlanner.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/mapreduce/IgniteHadoopWeightedMapReducePlanner.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/mapreduce/IgniteHadoopWeightedMapReducePlanner.java
new file mode 100644
index 0000000..27ffc19
--- /dev/null
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/mapreduce/IgniteHadoopWeightedMapReducePlanner.java
@@ -0,0 +1,846 @@
+/*
+ * 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.hadoop.mapreduce;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteFileSystem;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.igfs.IgfsBlockLocation;
+import org.apache.ignite.igfs.IgfsPath;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.hadoop.HadoopFileBlock;
+import org.apache.ignite.internal.processors.hadoop.HadoopInputSplit;
+import org.apache.ignite.internal.processors.hadoop.HadoopJob;
+import org.apache.ignite.internal.processors.hadoop.HadoopMapReducePlan;
+import org.apache.ignite.internal.processors.hadoop.HadoopUtils;
+import org.apache.ignite.internal.processors.hadoop.igfs.HadoopIgfsEndpoint;
+import org.apache.ignite.internal.processors.hadoop.planner.HadoopAbstractMapReducePlanner;
+import org.apache.ignite.internal.processors.hadoop.planner.HadoopDefaultMapReducePlan;
+import org.apache.ignite.internal.processors.hadoop.planner.HadoopMapReducePlanGroup;
+import org.apache.ignite.internal.processors.hadoop.planner.HadoopMapReducePlanTopology;
+import org.apache.ignite.internal.processors.igfs.IgfsEx;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.IdentityHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.UUID;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * Map-reduce planner which assigns mappers and reducers based on their "weights". Weight describes how much resources
+ * are required to execute particular map or reduce task.
+ * <p>
+ * Plan creation consists of two steps: assigning mappers and assigning reducers.
+ * <p>
+ * Mappers are assigned based on input split data location. For each input split we search for nodes where
+ * its data is stored. Planner tries to assign mappers to their affinity nodes first. This process is governed by two
+ * properties:
+ * <ul>
+ * <li><b>{@code localMapperWeight}</b> - weight of a map task when it is executed on an affinity node;</li>
+ * <li><b>{@code remoteMapperWeight}</b> - weight of a map task when it is executed on a non-affinity node.</li>
+ * </ul>
+ * Planning algorithm assign mappers so that total resulting weight on all nodes is minimum possible.
+ * <p>
+ * Reducers are assigned differently. First we try to distribute reducers across nodes with mappers. This approach
+ * could minimize expensive data transfer over network. Reducer assigned to a node with mapper is considered
+ * <b>{@code local}</b>. Otherwise it is considered <b>{@code remote}</b>. This process continue until certain weight
+ * threshold is reached what means that current node is already too busy and it should not have higher priority over
+ * other nodes any more. Threshold can be configured using <b>{@code preferLocalReducerThresholdWeight}</b> property.
+ * <p>
+ * When local reducer threshold is reached on all nodes, we distribute remaining reducers based on their local and
+ * remote weights in the same way as it is done for mappers. This process is governed by two
+ * properties:
+ * <ul>
+ * <li><b>{@code localReducerWeight}</b> - weight of a reduce task when it is executed on a node with mappers;</li>
+ * <li><b>{@code remoteReducerWeight}</b> - weight of a map task when it is executed on a node without mappers.</li>
+ * </ul>
+ */
+public class IgniteHadoopWeightedMapReducePlanner extends HadoopAbstractMapReducePlanner {
+ /** Default local mapper weight. */
+ public static final int DFLT_LOC_MAPPER_WEIGHT = 100;
+
+ /** Default remote mapper weight. */
+ public static final int DFLT_RMT_MAPPER_WEIGHT = 100;
+
+ /** Default local reducer weight. */
+ public static final int DFLT_LOC_REDUCER_WEIGHT = 100;
+
+ /** Default remote reducer weight. */
+ public static final int DFLT_RMT_REDUCER_WEIGHT = 100;
+
+ /** Default reducer migration threshold weight. */
+ public static final int DFLT_PREFER_LOCAL_REDUCER_THRESHOLD_WEIGHT = 200;
+
+ /** Local mapper weight. */
+ private int locMapperWeight = DFLT_LOC_MAPPER_WEIGHT;
+
+ /** Remote mapper weight. */
+ private int rmtMapperWeight = DFLT_RMT_MAPPER_WEIGHT;
+
+ /** Local reducer weight. */
+ private int locReducerWeight = DFLT_LOC_REDUCER_WEIGHT;
+
+ /** Remote reducer weight. */
+ private int rmtReducerWeight = DFLT_RMT_REDUCER_WEIGHT;
+
+ /** Reducer migration threshold weight. */
+ private int preferLocReducerThresholdWeight = DFLT_PREFER_LOCAL_REDUCER_THRESHOLD_WEIGHT;
+
+ /** {@inheritDoc} */
+ @Override public HadoopMapReducePlan preparePlan(HadoopJob job, Collection<ClusterNode> nodes,
+ @Nullable HadoopMapReducePlan oldPlan) throws IgniteCheckedException {
+ List<HadoopInputSplit> splits = HadoopUtils.sortInputSplits(job.input());
+ int reducerCnt = job.info().reducers();
+
+ if (reducerCnt < 0)
+ throw new IgniteCheckedException("Number of reducers must be non-negative, actual: " + reducerCnt);
+
+ HadoopMapReducePlanTopology top = topology(nodes);
+
+ Mappers mappers = assignMappers(splits, top);
+
+ Map<UUID, int[]> reducers = assignReducers(splits, top, mappers, reducerCnt);
+
+ return new HadoopDefaultMapReducePlan(mappers.nodeToSplits, reducers);
+ }
+
+ /**
+ * Assign mappers to nodes.
+ *
+ * @param splits Input splits.
+ * @param top Topology.
+ * @return Mappers.
+ * @throws IgniteCheckedException If failed.
+ */
+ private Mappers assignMappers(Collection<HadoopInputSplit> splits,
+ HadoopMapReducePlanTopology top) throws IgniteCheckedException {
+ Mappers res = new Mappers();
+
+ for (HadoopInputSplit split : splits) {
+ // Try getting IGFS affinity.
+ Collection<UUID> nodeIds = affinityNodesForSplit(split, top);
+
+ // Get best node.
+ UUID node = bestMapperNode(nodeIds, top);
+
+ assert node != null;
+
+ res.add(split, node);
+ }
+
+ return res;
+ }
+
+ /**
+ * Get affinity nodes for the given input split.
+ * <p>
+ * Order in the returned collection *is* significant, meaning that nodes containing more data
+ * go first. This way, the 1st nodes in the collection considered to be preferable for scheduling.
+ *
+ * @param split Split.
+ * @param top Topology.
+ * @return Affintiy nodes.
+ * @throws IgniteCheckedException If failed.
+ */
+ private Collection<UUID> affinityNodesForSplit(HadoopInputSplit split, HadoopMapReducePlanTopology top)
+ throws IgniteCheckedException {
+ Collection<UUID> igfsNodeIds = igfsAffinityNodesForSplit(split);
+
+ if (igfsNodeIds != null)
+ return igfsNodeIds;
+
+ Map<NodeIdAndLength, UUID> res = new TreeMap<>();
+
+ for (String host : split.hosts()) {
+ long len = split instanceof HadoopFileBlock ? ((HadoopFileBlock)split).length() : 0L;
+
+ HadoopMapReducePlanGroup grp = top.groupForHost(host);
+
+ if (grp != null) {
+ for (int i = 0; i < grp.nodeCount(); i++) {
+ UUID nodeId = grp.nodeId(i);
+
+ res.put(new NodeIdAndLength(nodeId, len), nodeId);
+ }
+ }
+ }
+
+ return new LinkedHashSet<>(res.values());
+ }
+
+ /**
+ * Get IGFS affinity nodes for split if possible.
+ * <p>
+ * Order in the returned collection *is* significant, meaning that nodes containing more data
+ * go first. This way, the 1st nodes in the collection considered to be preferable for scheduling.
+ *
+ * @param split Input split.
+ * @return IGFS affinity or {@code null} if IGFS is not available.
+ * @throws IgniteCheckedException If failed.
+ */
+ @Nullable private Collection<UUID> igfsAffinityNodesForSplit(HadoopInputSplit split) throws IgniteCheckedException {
+ if (split instanceof HadoopFileBlock) {
+ HadoopFileBlock split0 = (HadoopFileBlock)split;
+
+ if (IgniteFileSystem.IGFS_SCHEME.equalsIgnoreCase(split0.file().getScheme())) {
+ HadoopIgfsEndpoint endpoint = new HadoopIgfsEndpoint(split0.file().getAuthority());
+
+ IgfsEx igfs = null;
+
+ if (F.eq(ignite.name(), endpoint.grid()))
+ igfs = (IgfsEx)((IgniteEx)ignite).igfsx(endpoint.igfs());
+
+ if (igfs != null && !igfs.isProxy(split0.file())) {
+ IgfsPath path = new IgfsPath(split0.file());
+
+ if (igfs.exists(path)) {
+ Collection<IgfsBlockLocation> blocks;
+
+ try {
+ blocks = igfs.affinity(path, split0.start(), split0.length());
+ }
+ catch (IgniteException e) {
+ throw new IgniteCheckedException("Failed to get IGFS file block affinity [path=" + path +
+ ", start=" + split0.start() + ", len=" + split0.length() + ']', e);
+ }
+
+ assert blocks != null;
+
+ if (blocks.size() == 1)
+ return blocks.iterator().next().nodeIds();
+ else {
+ // The most "local" nodes go first.
+ Map<UUID, Long> idToLen = new HashMap<>();
+
+ for (IgfsBlockLocation block : blocks) {
+ for (UUID id : block.nodeIds()) {
+ Long len = idToLen.get(id);
+
+ idToLen.put(id, len == null ? block.length() : block.length() + len);
+ }
+ }
+
+ // Sort the nodes in non-ascending order by contained data lengths.
+ Map<NodeIdAndLength, UUID> res = new TreeMap<>();
+
+ for (Map.Entry<UUID, Long> idToLenEntry : idToLen.entrySet()) {
+ UUID id = idToLenEntry.getKey();
+
+ res.put(new NodeIdAndLength(id, idToLenEntry.getValue()), id);
+ }
+
+ return new LinkedHashSet<>(res.values());
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Find best mapper node.
+ *
+ * @param affIds Affinity node IDs.
+ * @param top Topology.
+ * @return Result.
+ */
+ private UUID bestMapperNode(@Nullable Collection<UUID> affIds, HadoopMapReducePlanTopology top) {
+ // Priority node.
+ UUID prioAffId = F.first(affIds);
+
+ // Find group with the least weight.
+ HadoopMapReducePlanGroup resGrp = null;
+ MapperPriority resPrio = MapperPriority.NORMAL;
+ int resWeight = Integer.MAX_VALUE;
+
+ for (HadoopMapReducePlanGroup grp : top.groups()) {
+ MapperPriority prio = groupPriority(grp, affIds, prioAffId);
+
+ int weight = grp.weight() + (prio == MapperPriority.NORMAL ? rmtMapperWeight : locMapperWeight);
+
+ if (resGrp == null || weight < resWeight || weight == resWeight && prio.value() > resPrio.value()) {
+ resGrp = grp;
+ resPrio = prio;
+ resWeight = weight;
+ }
+ }
+
+ assert resGrp != null;
+
+ // Update group weight for further runs.
+ resGrp.weight(resWeight);
+
+ // Return the best node from the group.
+ return bestMapperNodeForGroup(resGrp, resPrio, affIds, prioAffId);
+ }
+
+ /**
+ * Get best node in the group.
+ *
+ * @param grp Group.
+ * @param priority Priority.
+ * @param affIds Affinity IDs.
+ * @param prioAffId Priority affinity IDs.
+ * @return Best node ID in the group.
+ */
+ private static UUID bestMapperNodeForGroup(HadoopMapReducePlanGroup grp, MapperPriority priority,
+ @Nullable Collection<UUID> affIds, @Nullable UUID prioAffId) {
+ // Return the best node from the group.
+ int idx = 0;
+
+ // This is rare situation when several nodes are started on the same host.
+ if (!grp.single()) {
+ switch (priority) {
+ case NORMAL: {
+ // Pick any node.
+ idx = ThreadLocalRandom.current().nextInt(grp.nodeCount());
+
+ break;
+ }
+ case HIGH: {
+ // Pick any affinity node.
+ assert affIds != null;
+
+ List<Integer> cands = new ArrayList<>();
+
+ for (int i = 0; i < grp.nodeCount(); i++) {
+ UUID id = grp.nodeId(i);
+
+ if (affIds.contains(id))
+ cands.add(i);
+ }
+
+ idx = cands.get(ThreadLocalRandom.current().nextInt(cands.size()));
+
+ break;
+ }
+ default: {
+ // Find primary node.
+ assert prioAffId != null;
+
+ for (int i = 0; i < grp.nodeCount(); i++) {
+ UUID id = grp.nodeId(i);
+
+ if (F.eq(id, prioAffId)) {
+ idx = i;
+
+ break;
+ }
+ }
+
+ assert priority == MapperPriority.HIGHEST;
+ }
+ }
+ }
+
+ return grp.nodeId(idx);
+ }
+
+ /**
+ * Generate reducers.
+ *
+ * @param splits Input splits.
+ * @param top Topology.
+ * @param mappers Mappers.
+ * @param reducerCnt Reducer count.
+ * @return Reducers.
+ */
+ private Map<UUID, int[]> assignReducers(Collection<HadoopInputSplit> splits, HadoopMapReducePlanTopology top,
+ Mappers mappers, int reducerCnt) {
+ Map<UUID, Integer> reducers = assignReducers0(top, splits, mappers, reducerCnt);
+
+ int cnt = 0;
+
+ Map<UUID, int[]> res = new HashMap<>(reducers.size());
+
+ for (Map.Entry<UUID, Integer> reducerEntry : reducers.entrySet()) {
+ int[] arr = new int[reducerEntry.getValue()];
+
+ for (int i = 0; i < arr.length; i++)
+ arr[i] = cnt++;
+
+ res.put(reducerEntry.getKey(), arr);
+ }
+
+ assert reducerCnt == cnt : reducerCnt + " != " + cnt;
+
+ return res;
+ }
+
+ /**
+ * Generate reducers.
+ *
+ * @param top Topology.
+ * @param splits Input splits.
+ * @param mappers Mappers.
+ * @param reducerCnt Reducer count.
+ * @return Reducers.
+ */
+ private Map<UUID, Integer> assignReducers0(HadoopMapReducePlanTopology top, Collection<HadoopInputSplit> splits,
+ Mappers mappers, int reducerCnt) {
+ Map<UUID, Integer> res = new HashMap<>();
+
+ // Assign reducers to splits.
+ Map<HadoopInputSplit, Integer> splitToReducerCnt = assignReducersToSplits(splits, reducerCnt);
+
+ // Assign as much local reducers as possible.
+ int remaining = 0;
+
+ for (Map.Entry<HadoopInputSplit, Integer> entry : splitToReducerCnt.entrySet()) {
+ HadoopInputSplit split = entry.getKey();
+ int cnt = entry.getValue();
+
+ if (cnt > 0) {
+ int assigned = assignLocalReducers(split, cnt, top, mappers, res);
+
+ assert assigned <= cnt;
+
+ remaining += cnt - assigned;
+ }
+ }
+
+ // Assign the rest reducers.
+ if (remaining > 0)
+ assignRemoteReducers(remaining, top, mappers, res);
+
+ return res;
+ }
+
+ /**
+ * Assign local split reducers.
+ *
+ * @param split Split.
+ * @param cnt Reducer count.
+ * @param top Topology.
+ * @param mappers Mappers.
+ * @param resMap Reducers result map.
+ * @return Number of locally assigned reducers.
+ */
+ private int assignLocalReducers(HadoopInputSplit split, int cnt, HadoopMapReducePlanTopology top, Mappers mappers,
+ Map<UUID, Integer> resMap) {
+ // Dereference node.
+ UUID nodeId = mappers.splitToNode.get(split);
+
+ assert nodeId != null;
+
+ // Dereference group.
+ HadoopMapReducePlanGroup grp = top.groupForId(nodeId);
+
+ assert grp != null;
+
+ // Assign more reducers to the node until threshold is reached.
+ int res = 0;
+
+ while (res < cnt && grp.weight() < preferLocReducerThresholdWeight) {
+ res++;
+
+ grp.weight(grp.weight() + locReducerWeight);
+ }
+
+ // Update result map.
+ if (res > 0) {
+ Integer reducerCnt = resMap.get(nodeId);
+
+ resMap.put(nodeId, reducerCnt == null ? res : reducerCnt + res);
+ }
+
+ return res;
+ }
+
+ /**
+ * Assign remote reducers. Assign to the least loaded first.
+ *
+ * @param cnt Count.
+ * @param top Topology.
+ * @param mappers Mappers.
+ * @param resMap Reducers result map.
+ */
+ private void assignRemoteReducers(int cnt, HadoopMapReducePlanTopology top, Mappers mappers,
+ Map<UUID, Integer> resMap) {
+
+ TreeSet<HadoopMapReducePlanGroup> set = new TreeSet<>(new GroupWeightComparator());
+
+ set.addAll(top.groups());
+
+ while (cnt-- > 0) {
+ // The least loaded machine.
+ HadoopMapReducePlanGroup grp = set.first();
+
+ // Look for nodes with assigned splits.
+ List<UUID> splitNodeIds = null;
+
+ for (int i = 0; i < grp.nodeCount(); i++) {
+ UUID nodeId = grp.nodeId(i);
+
+ if (mappers.nodeToSplits.containsKey(nodeId)) {
+ if (splitNodeIds == null)
+ splitNodeIds = new ArrayList<>(2);
+
+ splitNodeIds.add(nodeId);
+ }
+ }
+
+ // Select best node.
+ UUID id;
+ int newWeight;
+
+ if (splitNodeIds != null) {
+ id = splitNodeIds.get(ThreadLocalRandom.current().nextInt(splitNodeIds.size()));
+
+ newWeight = grp.weight() + locReducerWeight;
+ }
+ else {
+ id = grp.nodeId(ThreadLocalRandom.current().nextInt(grp.nodeCount()));
+
+ newWeight = grp.weight() + rmtReducerWeight;
+ }
+
+ // Re-add entry with new weight.
+ boolean rmv = set.remove(grp);
+
+ assert rmv;
+
+ grp.weight(newWeight);
+
+ boolean add = set.add(grp);
+
+ assert add;
+
+ // Update result map.
+ Integer res = resMap.get(id);
+
+ resMap.put(id, res == null ? 1 : res + 1);
+ }
+ }
+
+ /**
+ * Comparator based on group's weight.
+ */
+ private static class GroupWeightComparator implements Comparator<HadoopMapReducePlanGroup> {
+ /** {@inheritDoc} */
+ @Override public int compare(HadoopMapReducePlanGroup first, HadoopMapReducePlanGroup second) {
+ int res = first.weight() - second.weight();
+
+ if (res < 0)
+ return -1;
+ else if (res > 0)
+ return 1;
+ else
+ return first.macs().compareTo(second.macs());
+ }
+ }
+
+ /**
+ * Distribute reducers between splits.
+ *
+ * @param splits Splits.
+ * @param reducerCnt Reducer count.
+ * @return Map from input split to reducer count.
+ */
+ private Map<HadoopInputSplit, Integer> assignReducersToSplits(Collection<HadoopInputSplit> splits,
+ int reducerCnt) {
+ Map<HadoopInputSplit, Integer> res = new IdentityHashMap<>(splits.size());
+
+ int base = reducerCnt / splits.size();
+ int remainder = reducerCnt % splits.size();
+
+ for (HadoopInputSplit split : splits) {
+ int val = base;
+
+ if (remainder > 0) {
+ val++;
+
+ remainder--;
+ }
+
+ res.put(split, val);
+ }
+
+ assert remainder == 0;
+
+ return res;
+ }
+
+ /**
+ * Calculate group priority.
+ *
+ * @param grp Group.
+ * @param affIds Affinity IDs.
+ * @param prioAffId Priority affinity ID.
+ * @return Group priority.
+ */
+ private static MapperPriority groupPriority(HadoopMapReducePlanGroup grp, @Nullable Collection<UUID> affIds,
+ @Nullable UUID prioAffId) {
+ assert F.isEmpty(affIds) ? prioAffId == null : prioAffId == F.first(affIds);
+ assert grp != null;
+
+ MapperPriority prio = MapperPriority.NORMAL;
+
+ if (!F.isEmpty(affIds)) {
+ for (int i = 0; i < grp.nodeCount(); i++) {
+ UUID id = grp.nodeId(i);
+
+ if (affIds.contains(id)) {
+ prio = MapperPriority.HIGH;
+
+ if (F.eq(prioAffId, id)) {
+ prio = MapperPriority.HIGHEST;
+
+ break;
+ }
+ }
+ }
+ }
+
+ return prio;
+ }
+
+ /**
+ * Get local mapper weight. This weight is added to a node when a mapper is assigned and it's input split data is
+ * located on this node (at least partially).
+ * <p>
+ * Defaults to {@link #DFLT_LOC_MAPPER_WEIGHT}.
+ *
+ * @return Remote mapper weight.
+ */
+ public int getLocalMapperWeight() {
+ return locMapperWeight;
+ }
+
+ /**
+ * Set local mapper weight. See {@link #getLocalMapperWeight()} for more information.
+ *
+ * @param locMapperWeight Local mapper weight.
+ */
+ public void setLocalMapperWeight(int locMapperWeight) {
+ this.locMapperWeight = locMapperWeight;
+ }
+
+ /**
+ * Get remote mapper weight. This weight is added to a node when a mapper is assigned, but it's input
+ * split data is not located on this node.
+ * <p>
+ * Defaults to {@link #DFLT_RMT_MAPPER_WEIGHT}.
+ *
+ * @return Remote mapper weight.
+ */
+ public int getRemoteMapperWeight() {
+ return rmtMapperWeight;
+ }
+
+ /**
+ * Set remote mapper weight. See {@link #getRemoteMapperWeight()} for more information.
+ *
+ * @param rmtMapperWeight Remote mapper weight.
+ */
+ public void setRemoteMapperWeight(int rmtMapperWeight) {
+ this.rmtMapperWeight = rmtMapperWeight;
+ }
+
+ /**
+ * Get local reducer weight. This weight is added to a node when a reducer is assigned and the node have at least
+ * one assigned mapper.
+ * <p>
+ * Defaults to {@link #DFLT_LOC_REDUCER_WEIGHT}.
+ *
+ * @return Local reducer weight.
+ */
+ public int getLocalReducerWeight() {
+ return locReducerWeight;
+ }
+
+ /**
+ * Set local reducer weight. See {@link #getLocalReducerWeight()} for more information.
+ *
+ * @param locReducerWeight Local reducer weight.
+ */
+ public void setLocalReducerWeight(int locReducerWeight) {
+ this.locReducerWeight = locReducerWeight;
+ }
+
+ /**
+ * Get remote reducer weight. This weight is added to a node when a reducer is assigned, but the node doesn't have
+ * any assigned mappers.
+ * <p>
+ * Defaults to {@link #DFLT_RMT_REDUCER_WEIGHT}.
+ *
+ * @return Remote reducer weight.
+ */
+ public int getRemoteReducerWeight() {
+ return rmtReducerWeight;
+ }
+
+ /**
+ * Set remote reducer weight. See {@link #getRemoteReducerWeight()} for more information.
+ *
+ * @param rmtReducerWeight Remote reducer weight.
+ */
+ public void setRemoteReducerWeight(int rmtReducerWeight) {
+ this.rmtReducerWeight = rmtReducerWeight;
+ }
+
+ /**
+ * Get reducer migration threshold weight. When threshold is reached, a node with mappers is no longer considered
+ * as preferred for further reducer assignments.
+ * <p>
+ * Defaults to {@link #DFLT_PREFER_LOCAL_REDUCER_THRESHOLD_WEIGHT}.
+ *
+ * @return Reducer migration threshold weight.
+ */
+ public int getPreferLocalReducerThresholdWeight() {
+ return preferLocReducerThresholdWeight;
+ }
+
+ /**
+ * Set reducer migration threshold weight. See {@link #getPreferLocalReducerThresholdWeight()} for more
+ * information.
+ *
+ * @param reducerMigrationThresholdWeight Reducer migration threshold weight.
+ */
+ public void setPreferLocalReducerThresholdWeight(int reducerMigrationThresholdWeight) {
+ this.preferLocReducerThresholdWeight = reducerMigrationThresholdWeight;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(IgniteHadoopWeightedMapReducePlanner.class, this);
+ }
+
+ /**
+ * Node ID and length.
+ */
+ private static class NodeIdAndLength implements Comparable<NodeIdAndLength> {
+ /** Node ID. */
+ private final UUID id;
+
+ /** Length. */
+ private final long len;
+
+ /**
+ * Constructor.
+ *
+ * @param id Node ID.
+ * @param len Length.
+ */
+ public NodeIdAndLength(UUID id, long len) {
+ this.id = id;
+ this.len = len;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("NullableProblems")
+ @Override public int compareTo(NodeIdAndLength obj) {
+ long res = len - obj.len;
+
+ if (res > 0)
+ return -1;
+ else if (res < 0)
+ return 1;
+ else
+ return id.compareTo(obj.id);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return id.hashCode();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return obj instanceof NodeIdAndLength && F.eq(id, ((NodeIdAndLength)obj).id);
+ }
+ }
+
+ /**
+ * Mappers.
+ */
+ private static class Mappers {
+ /** Node-to-splits map. */
+ private final Map<UUID, Collection<HadoopInputSplit>> nodeToSplits = new HashMap<>();
+
+ /** Split-to-node map. */
+ private final Map<HadoopInputSplit, UUID> splitToNode = new IdentityHashMap<>();
+
+ /**
+ * Add mapping.
+ *
+ * @param split Split.
+ * @param node Node.
+ */
+ public void add(HadoopInputSplit split, UUID node) {
+ Collection<HadoopInputSplit> nodeSplits = nodeToSplits.get(node);
+
+ if (nodeSplits == null) {
+ nodeSplits = new HashSet<>();
+
+ nodeToSplits.put(node, nodeSplits);
+ }
+
+ nodeSplits.add(split);
+
+ splitToNode.put(split, node);
+ }
+ }
+
+ /**
+ * Mapper priority enumeration.
+ */
+ private enum MapperPriority {
+ /** Normal node. */
+ NORMAL(0),
+
+ /** (likely) Affinity node. */
+ HIGH(1),
+
+ /** (likely) Affinity node with the highest priority (e.g. because it hosts more data than other nodes). */
+ HIGHEST(2);
+
+ /** Value. */
+ private final int val;
+
+ /**
+ * Constructor.
+ *
+ * @param val Value.
+ */
+ MapperPriority(int val) {
+ this.val = val;
+ }
+
+ /**
+ * @return Value.
+ */
+ public int value() {
+ return val;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopUtils.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopUtils.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopUtils.java
index 3fa963f..44d871a 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopUtils.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopUtils.java
@@ -25,8 +25,12 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.TreeSet;
import java.util.UUID;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
@@ -352,4 +356,81 @@ public class HadoopUtils {
}
}
+ /**
+ * Sort input splits by length.
+ *
+ * @param splits Splits.
+ * @return Sorted splits.
+ */
+ public static List<HadoopInputSplit> sortInputSplits(Collection<HadoopInputSplit> splits) {
+ int id = 0;
+
+ TreeSet<SplitSortWrapper> sortedSplits = new TreeSet<>();
+
+ for (HadoopInputSplit split : splits) {
+ long len = split instanceof HadoopFileBlock ? ((HadoopFileBlock)split).length() : 0;
+
+ sortedSplits.add(new SplitSortWrapper(id++, split, len));
+ }
+
+ ArrayList<HadoopInputSplit> res = new ArrayList<>(sortedSplits.size());
+
+ for (SplitSortWrapper sortedSplit : sortedSplits)
+ res.add(sortedSplit.split);
+
+ return res;
+ }
+
+ /**
+ * Split wrapper for sorting.
+ */
+ private static class SplitSortWrapper implements Comparable<SplitSortWrapper> {
+ /** Unique ID. */
+ private final int id;
+
+ /** Split. */
+ private final HadoopInputSplit split;
+
+ /** Split length. */
+ private final long len;
+
+ /**
+ * Constructor.
+ *
+ * @param id Unique ID.
+ * @param split Split.
+ * @param len Split length.
+ */
+ public SplitSortWrapper(int id, HadoopInputSplit split, long len) {
+ this.id = id;
+ this.split = split;
+ this.len = len;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("NullableProblems")
+ @Override public int compareTo(SplitSortWrapper other) {
+ assert other != null;
+
+ long res = len - other.len;
+
+ if (res > 0)
+ return -1;
+ else if (res < 0)
+ return 1;
+ else
+ return id - other.id;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return id;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return obj instanceof SplitSortWrapper && id == ((SplitSortWrapper)obj).id;
+ }
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopAbstractMapReducePlanner.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopAbstractMapReducePlanner.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopAbstractMapReducePlanner.java
new file mode 100644
index 0000000..f01f72b
--- /dev/null
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopAbstractMapReducePlanner.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.hadoop.planner;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.processors.hadoop.HadoopMapReducePlanner;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.resources.LoggerResource;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MACS;
+
+/**
+ * Base class for map-reduce planners.
+ */
+public abstract class HadoopAbstractMapReducePlanner implements HadoopMapReducePlanner {
+ /** Injected grid. */
+ @IgniteInstanceResource
+ protected Ignite ignite;
+
+ /** Logger. */
+ @SuppressWarnings("UnusedDeclaration")
+ @LoggerResource
+ protected IgniteLogger log;
+
+ /**
+ * Create plan topology.
+ *
+ * @param nodes Topology nodes.
+ * @return Plan topology.
+ */
+ protected static HadoopMapReducePlanTopology topology(Collection<ClusterNode> nodes) {
+ Map<String, HadoopMapReducePlanGroup> macsMap = new HashMap<>(nodes.size());
+
+ Map<UUID, HadoopMapReducePlanGroup> idToGrp = new HashMap<>(nodes.size());
+ Map<String, HadoopMapReducePlanGroup> hostToGrp = new HashMap<>(nodes.size());
+
+ for (ClusterNode node : nodes) {
+ String macs = node.attribute(ATTR_MACS);
+
+ HadoopMapReducePlanGroup grp = macsMap.get(macs);
+
+ if (grp == null) {
+ grp = new HadoopMapReducePlanGroup(node, macs);
+
+ macsMap.put(macs, grp);
+ }
+ else
+ grp.add(node);
+
+ idToGrp.put(node.id(), grp);
+
+ for (String host : node.addresses()) {
+ HadoopMapReducePlanGroup hostGrp = hostToGrp.get(host);
+
+ if (hostGrp == null)
+ hostToGrp.put(host, grp);
+ else
+ assert hostGrp == grp;
+ }
+ }
+
+ return new HadoopMapReducePlanTopology(new ArrayList<>(macsMap.values()), idToGrp, hostToGrp);
+ }
+
+
+ /**
+ * Groups nodes by host names.
+ *
+ * @param top Topology to group.
+ * @return Map.
+ */
+ protected static Map<String, Collection<UUID>> groupByHost(Collection<ClusterNode> top) {
+ Map<String, Collection<UUID>> grouped = U.newHashMap(top.size());
+
+ for (ClusterNode node : top) {
+ for (String host : node.hostNames()) {
+ Collection<UUID> nodeIds = grouped.get(host);
+
+ if (nodeIds == null) {
+ // Expecting 1-2 nodes per host.
+ nodeIds = new ArrayList<>(2);
+
+ grouped.put(host, nodeIds);
+ }
+
+ nodeIds.add(node.id());
+ }
+ }
+
+ return grouped;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopMapReducePlanGroup.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopMapReducePlanGroup.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopMapReducePlanGroup.java
new file mode 100644
index 0000000..2fe8682
--- /dev/null
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopMapReducePlanGroup.java
@@ -0,0 +1,150 @@
+/*
+ * 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.hadoop.planner;
+
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.util.ArrayList;
+import java.util.UUID;
+
+/**
+ * Map-reduce plan group of nodes on a single physical machine.
+ */
+public class HadoopMapReducePlanGroup {
+ /** Node. */
+ private ClusterNode node;
+
+ /** Nodes. */
+ private ArrayList<ClusterNode> nodes;
+
+ /** MAC addresses. */
+ private final String macs;
+
+ /** Weight. */
+ private int weight;
+
+ /**
+ * Constructor.
+ *
+ * @param node First node in the group.
+ * @param macs MAC addresses.
+ */
+ public HadoopMapReducePlanGroup(ClusterNode node, String macs) {
+ assert node != null;
+ assert macs != null;
+
+ this.node = node;
+ this.macs = macs;
+ }
+
+ /**
+ * Add node to the group.
+ *
+ * @param newNode New node.
+ */
+ public void add(ClusterNode newNode) {
+ if (node != null) {
+ nodes = new ArrayList<>(2);
+
+ nodes.add(node);
+
+ node = null;
+ }
+
+ nodes.add(newNode);
+ }
+
+ /**
+ * @return MAC addresses.
+ */
+ public String macs() {
+ return macs;
+ }
+
+ /**
+ * @return {@code True} if only sinle node present.
+ */
+ public boolean single() {
+ return nodeCount() == 1;
+ }
+
+ /**
+ * Get node ID by index.
+ *
+ * @param idx Index.
+ * @return Node.
+ */
+ public UUID nodeId(int idx) {
+ ClusterNode res;
+
+ if (node != null) {
+ assert idx == 0;
+
+ res = node;
+ }
+ else {
+ assert nodes != null;
+ assert idx < nodes.size();
+
+ res = nodes.get(idx);
+ }
+
+ assert res != null;
+
+ return res.id();
+ }
+
+ /**
+ * @return Node count.
+ */
+ public int nodeCount() {
+ return node != null ? 1 : nodes.size();
+ }
+
+ /**
+ * @return weight.
+ */
+ public int weight() {
+ return weight;
+ }
+
+ /**
+ * @param weight weight.
+ */
+ public void weight(int weight) {
+ this.weight = weight;
+ }
+
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return macs.hashCode();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return obj instanceof HadoopMapReducePlanGroup && F.eq(macs, ((HadoopMapReducePlanGroup)obj).macs);
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(HadoopMapReducePlanGroup.class, this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/73649386/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopMapReducePlanTopology.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopMapReducePlanTopology.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopMapReducePlanTopology.java
new file mode 100644
index 0000000..fa5c469
--- /dev/null
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/planner/HadoopMapReducePlanTopology.java
@@ -0,0 +1,89 @@
+/*
+ * 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.hadoop.planner;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Map-reduce plan topology.
+ */
+public class HadoopMapReducePlanTopology {
+ /** All groups. */
+ private final List<HadoopMapReducePlanGroup> grps;
+
+ /** Node ID to group map. */
+ private final Map<UUID, HadoopMapReducePlanGroup> idToGrp;
+
+ /** Host to group map. */
+ private final Map<String, HadoopMapReducePlanGroup> hostToGrp;
+
+ /**
+ * Constructor.
+ *
+ * @param grps All groups.
+ * @param idToGrp ID to group map.
+ * @param hostToGrp Host to group map.
+ */
+ public HadoopMapReducePlanTopology(List<HadoopMapReducePlanGroup> grps,
+ Map<UUID, HadoopMapReducePlanGroup> idToGrp, Map<String, HadoopMapReducePlanGroup> hostToGrp) {
+ assert grps != null;
+ assert idToGrp != null;
+ assert hostToGrp != null;
+
+ this.grps = grps;
+ this.idToGrp = idToGrp;
+ this.hostToGrp = hostToGrp;
+ }
+
+ /**
+ * @return All groups.
+ */
+ public List<HadoopMapReducePlanGroup> groups() {
+ return grps;
+ }
+
+ /**
+ * Get group for node ID.
+ *
+ * @param id Node ID.
+ * @return Group.
+ */
+ public HadoopMapReducePlanGroup groupForId(UUID id) {
+ return idToGrp.get(id);
+ }
+
+ /**
+ * Get group for host.
+ *
+ * @param host Host.
+ * @return Group.
+ */
+ @Nullable public HadoopMapReducePlanGroup groupForHost(String host) {
+ return hostToGrp.get(host);
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(HadoopMapReducePlanTopology.class, this);
+ }
+}
[13/33] ignite git commit: ignite-3413 Use cache node filter for
continuous query registration
Posted by sb...@apache.org.
ignite-3413 Use cache node filter for continuous query registration
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/89d64e74
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/89d64e74
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/89d64e74
Branch: refs/heads/ignite-3547
Commit: 89d64e74b697054a88c3a91433aaaf4f7fdd0284
Parents: a056954
Author: sboikov <sb...@gridgain.com>
Authored: Wed Jul 13 12:41:18 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Jul 13 12:41:18 2016 +0300
----------------------------------------------------------------------
.../continuous/CacheContinuousQueryManager.java | 4 +-
...eContinuousQueryMultiNodesFilteringTest.java | 278 +++++++++++++++++++
...dCacheContinuousQueryNodesFilteringTest.java | 168 +++++++++++
.../IgniteCacheQuerySelfTestSuite3.java | 4 +
4 files changed, 453 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/89d64e74/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
----------------------------------------------------------------------
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 c966527..195f3ae 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
@@ -642,7 +642,9 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
hnd.localCache(cctx.isLocal());
IgnitePredicate<ClusterNode> pred = (loc || cctx.config().getCacheMode() == CacheMode.LOCAL) ?
- F.nodeForNodeId(cctx.localNodeId()) : F.<ClusterNode>alwaysTrue();
+ F.nodeForNodeId(cctx.localNodeId()) : cctx.config().getNodeFilter();
+
+ assert pred != null : cctx.config();
UUID id = cctx.kernalContext().continuous().startRoutine(
hnd,
http://git-wip-us.apache.org/repos/asf/ignite/blob/89d64e74/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryMultiNodesFilteringTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryMultiNodesFilteringTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryMultiNodesFilteringTest.java
new file mode 100644
index 0000000..7000446
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryMultiNodesFilteringTest.java
@@ -0,0 +1,278 @@
+/*
+ * 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.Collections;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.configuration.Factory;
+import javax.cache.configuration.MutableCacheEntryListenerConfiguration;
+import javax.cache.event.CacheEntryCreatedListener;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryEventFilter;
+import javax.cache.event.CacheEntryListener;
+import javax.cache.event.CacheEntryListenerException;
+import javax.cache.event.CacheEntryRemovedListener;
+import javax.cache.event.CacheEntryUpdatedListener;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.lang.GridAbsPredicate;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.resources.IgniteInstanceResource;
+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.jsr166.ConcurrentHashMap8;
+
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+
+/** */
+@SuppressWarnings("unchecked")
+public class GridCacheContinuousQueryMultiNodesFilteringTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static final int SERVER_GRIDS_COUNT = 6;
+
+ /** Cache entry operations' counts. */
+ private static final ConcurrentMap<String, AtomicInteger> opCounts = new ConcurrentHashMap8<>();
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ super.afterTest();
+ }
+
+ /** */
+ public void testFiltersAndListeners() throws Exception {
+ for (int i = 1; i <= SERVER_GRIDS_COUNT; i++)
+ startGrid(i, false);
+
+ startGrid(SERVER_GRIDS_COUNT + 1, true);
+
+ for (int i = 1; i <= SERVER_GRIDS_COUNT + 1; i++) {
+ for (int j = 0; j < i; j++) {
+ jcache(i, "part" + i).put("k" + j, "v0");
+ jcache(i, "repl" + i).put("k" + j, "v0");
+
+ // Should trigger updates
+ jcache(i, "part" + i).put("k" + j, "v1");
+ jcache(i, "repl" + i).put("k" + j, "v1");
+
+ jcache(i, "part" + i).remove("k" + j);
+ jcache(i, "repl" + i).remove("k" + j);
+ }
+ }
+
+ for (int i = 1; i <= SERVER_GRIDS_COUNT + 1; i++) {
+ // For each i, we did 3 ops on 2 caches on i keys, hence expected number.
+ final int expTotal = i * 3 * 2;
+ final int i0 = i;
+
+ GridTestUtils.waitForCondition(new GridAbsPredicate() {
+ @Override public boolean apply() {
+ return opCounts.get("qry" + i0 + "_total").get() == expTotal;
+ }
+ }, 5000);
+
+ int partInserts = opCounts.get("part" + i + "_ins").get();
+ int replInserts = opCounts.get("repl" + i + "_ins").get();
+ int partUpdates = opCounts.get("part" + i + "_upd").get();
+ int replUpdates = opCounts.get("repl" + i + "_upd").get();
+ int partRemoves = opCounts.get("part" + i + "_rmv").get();
+ int replRemoves = opCounts.get("repl" + i + "_rmv").get();
+ int totalQryOps = opCounts.get("qry" + i + "_total").get();
+
+ assertEquals(i, partInserts);
+ assertEquals(i, replInserts);
+
+ assertEquals(i, partUpdates);
+ assertEquals(i, replUpdates);
+
+ assertEquals(i, partRemoves);
+ assertEquals(i, replRemoves);
+
+ assertEquals(expTotal, totalQryOps);
+
+ assertEquals(totalQryOps, partInserts + replInserts + partUpdates + replUpdates + partRemoves + replRemoves);
+ }
+ }
+
+ /** */
+ private Ignite startGrid(final int idx, boolean isClientMode) throws Exception {
+ String gridName = getTestGridName(idx);
+
+ IgniteConfiguration cfg = optimize(getConfiguration(gridName)).setClientMode(isClientMode);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+ cfg.setUserAttributes(Collections.singletonMap("idx", idx));
+
+ Ignite node = startGrid(gridName, cfg);
+
+ IgnitePredicate<ClusterNode> nodeFilter = new NodeFilter(idx);
+
+ String partCacheName = "part" + idx;
+
+ IgniteCache partCache = node.createCache(defaultCacheConfiguration().setName("part" + idx)
+ .setCacheMode(PARTITIONED).setBackups(1).setNodeFilter(nodeFilter));
+
+ opCounts.put(partCacheName + "_ins", new AtomicInteger());
+ opCounts.put(partCacheName + "_upd", new AtomicInteger());
+ opCounts.put(partCacheName + "_rmv", new AtomicInteger());
+
+ partCache.registerCacheEntryListener(new ListenerConfiguration(partCacheName, ListenerConfiguration.Op.INSERT));
+ partCache.registerCacheEntryListener(new ListenerConfiguration(partCacheName, ListenerConfiguration.Op.UPDATE));
+ partCache.registerCacheEntryListener(new ListenerConfiguration(partCacheName, ListenerConfiguration.Op.REMOVE));
+
+ String replCacheName = "repl" + idx;
+
+ IgniteCache replCache = node.createCache(defaultCacheConfiguration().setName("repl" + idx)
+ .setCacheMode(REPLICATED).setNodeFilter(nodeFilter));
+
+ opCounts.put(replCacheName + "_ins", new AtomicInteger());
+ opCounts.put(replCacheName + "_upd", new AtomicInteger());
+ opCounts.put(replCacheName + "_rmv", new AtomicInteger());
+
+ replCache.registerCacheEntryListener(new ListenerConfiguration(replCacheName, ListenerConfiguration.Op.INSERT));
+ replCache.registerCacheEntryListener(new ListenerConfiguration(replCacheName, ListenerConfiguration.Op.UPDATE));
+ replCache.registerCacheEntryListener(new ListenerConfiguration(replCacheName, ListenerConfiguration.Op.REMOVE));
+
+ opCounts.put("qry" + idx + "_total", new AtomicInteger());
+
+ ContinuousQuery qry = new ContinuousQuery();
+ qry.setRemoteFilterFactory(new EntryEventFilterFactory(idx));
+ qry.setLocalListener(new CacheEntryUpdatedListener() {
+ /** {@inheritDoc} */
+ @Override public void onUpdated(Iterable evts) {
+ opCounts.get("qry" + idx + "_total").incrementAndGet();
+ }
+ });
+
+ partCache.query(qry);
+ replCache.query(qry);
+
+ return node;
+ }
+
+ /** */
+ private final static class ListenerConfiguration extends MutableCacheEntryListenerConfiguration {
+ /** Operation. */
+ enum Op {
+ /** Insert. */
+ INSERT,
+
+ /** Update. */
+ UPDATE,
+
+ /** Remove. */
+ REMOVE
+ }
+
+ /** */
+ ListenerConfiguration(final String cacheName, final Op op) {
+ super(new Factory<CacheEntryListener>() {
+ /** {@inheritDoc} */
+ @Override public CacheEntryListener create() {
+ switch (op) {
+ case INSERT:
+ return new CacheEntryCreatedListener() {
+ /** {@inheritDoc} */
+ @Override public void onCreated(Iterable iterable) {
+ for (Object evt : iterable)
+ opCounts.get(cacheName + "_ins").getAndIncrement();
+ }
+ };
+ case UPDATE:
+ return new CacheEntryUpdatedListener() {
+ /** {@inheritDoc} */
+ @Override public void onUpdated(Iterable iterable) {
+ for (Object evt : iterable)
+ opCounts.get(cacheName + "_upd").getAndIncrement();
+ }
+ };
+ case REMOVE:
+ return new CacheEntryRemovedListener() {
+ /** {@inheritDoc} */
+ @Override public void onRemoved(Iterable iterable) {
+ for (Object evt : iterable)
+ opCounts.get(cacheName + "_rmv").getAndIncrement();
+ }
+ };
+ default:
+ throw new IgniteException(new IllegalArgumentException());
+ }
+ }
+ }, null, true, false);
+ }
+ }
+
+ /** */
+ private final static class EntryEventFilterFactory implements Factory<CacheEntryEventFilter> {
+ /** */
+ @IgniteInstanceResource
+ private Ignite ignite;
+
+ /** Grid index to determine whether node filter has been invoked. */
+ private final int idx;
+
+ /** */
+ private EntryEventFilterFactory(int idx) {
+ this.idx = idx;
+ }
+
+ /** {@inheritDoc} */
+ @Override public CacheEntryEventFilter create() {
+ return new CacheEntryEventFilter() {
+ /** {@inheritDoc} */
+ @Override public boolean evaluate(CacheEntryEvent evt) throws CacheEntryListenerException {
+ int evtNodeIdx = (Integer)(ignite.cluster().localNode().attributes().get("idx"));
+
+ assertTrue(evtNodeIdx % 2 == idx % 2);
+
+ return true;
+ }
+ };
+ }
+ }
+
+ /** */
+ private final static class NodeFilter implements IgnitePredicate<ClusterNode> {
+ /** */
+ private final int idx;
+
+ /** */
+ private NodeFilter(int idx) {
+ this.idx = idx;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean apply(ClusterNode clusterNode) {
+ return ((Integer)clusterNode.attributes().get("idx") % 2) == idx % 2;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/89d64e74/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryNodesFilteringTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryNodesFilteringTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryNodesFilteringTest.java
new file mode 100644
index 0000000..dccde65
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryNodesFilteringTest.java
@@ -0,0 +1,168 @@
+/*
+ * 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.io.Serializable;
+import java.util.Collections;
+import javax.cache.configuration.Factory;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryEventFilter;
+import javax.cache.event.CacheEntryUpdatedListener;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+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.GridStringLogger;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/** */
+@SuppressWarnings("unused")
+public class GridCacheContinuousQueryNodesFilteringTest extends GridCommonAbstractTest implements Serializable {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static final String ENTRY_FILTER_CLS_NAME = "org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilter";
+
+ /**
+ * Tests that node not matched by filter really does not try to participate in the query.
+ *
+ * @throws Exception if failed.
+ */
+ @SuppressWarnings("EmptyTryBlock")
+ public void testNodeWithoutAttributeExclusion() throws Exception {
+ try (Ignite node1 = startNodeWithCache()) {
+ try (Ignite node2 = startGrid("node2", getConfiguration("node2", false, null))) {
+ assertEquals(2, node2.cluster().nodes().size());
+ }
+ }
+ }
+
+ /**
+ * Test that node matched by filter and having filter instantiation problems fails for sure.
+ *
+ * @throws Exception if failed.
+ */
+ public void testNodeWithAttributeFailure() throws Exception {
+ try (Ignite node1 = startNodeWithCache()) {
+ GridStringLogger log = new GridStringLogger();
+
+ try (Ignite node2 = startGrid("node2", getConfiguration("node2", true, log))) {
+ fail();
+ }
+ catch (IgniteException e) {
+ assertTrue(log.toString().contains("Class not found for continuous query remote filter " +
+ "[name=org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilter]"));
+ }
+ }
+ }
+
+ /**
+ * Start first, attribute-bearing, node, create new cache and launch continuous query on it.
+ *
+ * @return Node.
+ * @throws Exception if failed.
+ */
+ private Ignite startNodeWithCache() throws Exception {
+ Ignite node1 = startGrid("node1", getConfiguration("node1", true, null));
+
+ CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>();
+ ccfg.setName("attrsTestCache");
+ ccfg.setNodeFilter(new IgnitePredicate<ClusterNode>() {
+ /** {@inheritDoc} */
+ @Override public boolean apply(ClusterNode node) {
+ return "data".equals(node.attribute("node-type"));
+ }
+ });
+
+ IgniteCache<Integer, Integer> cache = node1.createCache(ccfg);
+
+ ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
+
+ qry.setRemoteFilterFactory(new RemoteFilterFactory());
+ qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {
+ /** {@inheritDoc} */
+ @Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
+ // No-op.
+ }
+ });
+
+ RemoteFilterFactory.clsLdr = getExternalClassLoader();
+
+ cache.query(qry);
+
+ // Switch class loader before starting the second node.
+ RemoteFilterFactory.clsLdr = getClass().getClassLoader();
+
+ return node1;
+ }
+
+ /**
+ * @param name Node name.
+ * @param setAttr Flag indicating whether node user attribute should be set.
+ * @param log Logger.
+ * @return Node configuration w/specified name.
+ * @throws Exception If failed.
+ */
+ private IgniteConfiguration getConfiguration(String name, boolean setAttr, GridStringLogger log) throws Exception {
+ IgniteConfiguration cfg = optimize(getConfiguration(name));
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+ if (setAttr)
+ cfg.setUserAttributes(Collections.singletonMap("node-type", "data"));
+
+ cfg.setGridLogger(log);
+
+ return cfg;
+ }
+
+ /**
+ *
+ */
+ private static class RemoteFilterFactory implements Factory<CacheEntryEventFilter<Integer, Integer>> {
+ /** */
+ private static ClassLoader clsLdr;
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override public CacheEntryEventFilter<Integer, Integer> create() {
+ try {
+ Class<?> filterCls = clsLdr.loadClass(ENTRY_FILTER_CLS_NAME);
+
+ assert CacheEntryEventFilter.class.isAssignableFrom(filterCls);
+
+ return ((Class<CacheEntryEventFilter>)filterCls).newInstance();
+ }
+ catch (ClassNotFoundException e) {
+ throw new IgniteException("Class not found for continuous query remote filter [name=" +
+ e.getMessage() + "]");
+ }
+ catch (Exception e) { // We really don't expect anything else fancy here.
+ throw new AssertionError("Unexpected exception", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/89d64e74/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
----------------------------------------------------------------------
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 a1a32a1..abf4ac3 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
@@ -43,6 +43,8 @@ import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheCon
import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryConcurrentTest;
import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryLocalAtomicSelfTest;
import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryLocalSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryMultiNodesFilteringTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryNodesFilteringTest;
import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryPartitionAtomicOneNodeTest;
import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryPartitionTxOneNodeTest;
import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryPartitionedOnlySelfTest;
@@ -115,6 +117,8 @@ public class IgniteCacheQuerySelfTestSuite3 extends TestSuite {
suite.addTestSuite(CacheContinuousQueryExecuteInPrimaryTest.class);
suite.addTestSuite(CacheContinuousQueryLostPartitionTest.class);
suite.addTestSuite(ContinuousQueryRemoteFilterMissingInClassPathSelfTest.class);
+ suite.addTestSuite(GridCacheContinuousQueryNodesFilteringTest.class);
+ suite.addTestSuite(GridCacheContinuousQueryMultiNodesFilteringTest.class);
suite.addTestSuite(IgniteCacheContinuousQueryImmutableEntryTest.class);
suite.addTestSuite(CacheKeepBinaryIterationTest.class);
suite.addTestSuite(CacheKeepBinaryIterationStoreEnabledTest.class);
[10/33] ignite git commit: ignite-3239 Fix of java.io.IOException:
Resource deadlock avoided
Posted by sb...@apache.org.
ignite-3239 Fix of java.io.IOException: Resource deadlock avoided
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/762c43d6
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/762c43d6
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/762c43d6
Branch: refs/heads/ignite-3547
Commit: 762c43d67c2e500de1be2ae030a55658ad291574
Parents: 7aa609a
Author: agura <ag...@gridgain.com>
Authored: Thu Jun 16 13:03:03 2016 +0300
Committer: agura <ag...@gridgain.com>
Committed: Tue Jul 12 17:15:34 2016 +0300
----------------------------------------------------------------------
.../ignite/internal/MarshallerContextImpl.java | 29 ++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/762c43d6/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
index b4c9607..504ea6e 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
@@ -25,9 +25,11 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.util.List;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.locks.Lock;
import javax.cache.event.CacheEntryEvent;
import javax.cache.event.CacheEntryListenerException;
@@ -201,7 +203,7 @@ public class MarshallerContextImpl extends MarshallerContextAdapter {
File file = new File(workDir, fileName);
try (FileInputStream in = new FileInputStream(file)) {
- FileLock fileLock = in.getChannel().lock(0L, Long.MAX_VALUE, true);
+ FileLock fileLock = fileLock(in.getChannel(), true);
assert fileLock != null : fileName;
@@ -235,6 +237,26 @@ public class MarshallerContextImpl extends MarshallerContextAdapter {
}
/**
+ * @param ch File channel.
+ * @param shared Shared.
+ */
+ private static FileLock fileLock(
+ FileChannel ch,
+ boolean shared
+ ) throws IOException, IgniteInterruptedCheckedException {
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ while (true) {
+ FileLock fileLock = ch.tryLock(0L, Long.MAX_VALUE, shared);
+
+ if (fileLock == null)
+ U.sleep(rnd.nextLong(50));
+ else
+ return fileLock;
+ }
+ }
+
+ /**
*/
private static class ContinuousQueryListener implements CacheEntryUpdatedListener<Integer, String> {
/** */
@@ -270,7 +292,7 @@ public class MarshallerContextImpl extends MarshallerContextAdapter {
File file = new File(workDir, fileName);
try (FileOutputStream out = new FileOutputStream(file)) {
- FileLock fileLock = out.getChannel().lock(0L, Long.MAX_VALUE, false);
+ FileLock fileLock = fileLock(out.getChannel(), false);
assert fileLock != null : fileName;
@@ -284,6 +306,9 @@ public class MarshallerContextImpl extends MarshallerContextAdapter {
U.error(log, "Failed to write class name to file [id=" + evt.getKey() +
", clsName=" + evt.getValue() + ", file=" + file.getAbsolutePath() + ']', e);
}
+ catch (IgniteInterruptedCheckedException e) {
+ U.error(log, "Interrupted while waiting for acquiring file lock: " + file, e);
+ }
}
finally {
lock.unlock();
[24/33] ignite git commit: ignite-3465 Do not call super.toString for
not-initialized BinaryObjectImpl.
Posted by sb...@apache.org.
ignite-3465 Do not call super.toString for not-initialized BinaryObjectImpl.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/78d7c136
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/78d7c136
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/78d7c136
Branch: refs/heads/ignite-3547
Commit: 78d7c136a3860f1cb4346b37bf8853bc8b576636
Parents: 84e83c9
Author: sboikov <sb...@gridgain.com>
Authored: Tue Jul 19 13:35:59 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Tue Jul 19 13:35:59 2016 +0300
----------------------------------------------------------------------
.../org/apache/ignite/internal/binary/BinaryObjectImpl.java | 8 ++++++++
1 file changed, 8 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/78d7c136/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index 468cc25..3563fba 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -586,4 +586,12 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx) {
return reader(rCtx, null);
}
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ if (arr == null || ctx == null)
+ return "BinaryObjectImpl [arr= " + (arr != null) + ", ctx=" + (ctx != null) + ", start=" + start + "]";
+
+ return super.toString();
+ }
}
[33/33] ignite git commit: ignite-3547
Posted by sb...@apache.org.
ignite-3547
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1fdd6e8f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1fdd6e8f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1fdd6e8f
Branch: refs/heads/ignite-3547
Commit: 1fdd6e8f96a4f8e7adc57235049bc89b8ed56807
Parents: 71ef652
Author: sboikov <sb...@gridgain.com>
Authored: Fri Jul 22 14:28:59 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Fri Jul 22 14:28:59 2016 +0300
----------------------------------------------------------------------
.../internal/util/nio/GridTcpNioCommunicationClient.java | 5 ++++-
.../ignite/spi/communication/tcp/TcpCommunicationSpi.java | 6 ++++--
2 files changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fdd6e8f/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java
index 4022bc5..5fe521d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java
@@ -125,8 +125,11 @@ public class GridTcpNioCommunicationClient extends GridAbstractCommunicationClie
if (log.isDebugEnabled())
log.debug("Failed to send message [client=" + this + ", err=" + e + ']');
- if (e.getCause() instanceof IOException)
+ if (e.getCause() instanceof IOException) {
+ ses.close();
+
return true;
+ }
else
throw new IgniteCheckedException("Failed to send message [client=" + this + ']', e);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fdd6e8f/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
----------------------------------------------------------------------
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 ed29b59..7c7da6c 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
@@ -1971,17 +1971,19 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter
client.release();
- client = null;
-
if (!retry)
sentMsgsCnt.increment();
else {
+ clients.remove(node.id(), client);
+
ClusterNode node0 = getSpiContext().node(node.id());
if (node0 == null)
throw new IgniteCheckedException("Failed to send message to remote node " +
"(node has left the grid): " + node.id());
}
+
+ client = null;
}
while (retry);
}
[05/33] ignite git commit: Backported test fixes.
Posted by sb...@apache.org.
Backported test fixes.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f045558c
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f045558c
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f045558c
Branch: refs/heads/ignite-3547
Commit: f045558c6152de274f6c9a7539d69b0645fe3526
Parents: e2ec9fe
Author: sboikov <sb...@gridgain.com>
Authored: Mon Jul 4 21:08:24 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Thu Jul 7 12:38:04 2016 +0300
----------------------------------------------------------------------
.../cache/GridCacheAbstractFullApiSelfTest.java | 322 ++++++++++---------
...idCacheNearOnlyMultiNodeFullApiSelfTest.java | 170 ++++------
.../junits/common/GridCommonAbstractTest.java | 12 +-
.../multijvm/IgniteCacheProcessProxy.java | 107 +++---
4 files changed, 301 insertions(+), 310 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/f045558c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
----------------------------------------------------------------------
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 41d93b1..179e601 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
@@ -70,6 +70,7 @@ import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager;
import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
import org.apache.ignite.internal.util.lang.GridAbsPredicate;
import org.apache.ignite.internal.util.lang.GridAbsPredicateX;
+import org.apache.ignite.internal.util.lang.IgnitePair;
import org.apache.ignite.internal.util.typedef.CIX1;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.PA;
@@ -219,6 +220,8 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
+ initStoreStrategy();
+
if (cacheStartType() == CacheStartMode.STATIC)
super.beforeTestsStarted();
else {
@@ -262,17 +265,12 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
}
/**
- * Checks that skipStore flag gets overriden inside a transaction.
- *
- * @throws Exception if failed.
+ * Checks that skipStore flag gets overridden inside a transaction.
*/
public void testWriteThroughTx() {
- if(isMultiJvm())
- fail("https://issues.apache.org/jira/browse/IGNITE-1088");
-
String key = "writeThroughKey";
- map.remove(key);
+ storeStgy.removeFromStore(key);
try (final Transaction transaction = grid(0).transactions().txStart()) {
IgniteCache<String, Integer> cache = jcache(0);
@@ -289,27 +287,22 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
transaction.commit();
}
- assertEquals(2, map.get(key));
+ assertEquals(2, storeStgy.getFromStore(key));
}
/**
- * Checks that skipStore flag gets overriden inside a transaction.
- *
- * @throws Exception if failed.
+ * Checks that skipStore flag gets overridden inside a transaction.
*/
public void testNoReadThroughTx() {
- if(isMultiJvm())
- fail("https://issues.apache.org/jira/browse/IGNITE-1088");
-
String key = "writeThroughKey";
IgniteCache<String, Integer> cache = jcache(0);
- resetStore();
+ storeStgy.resetStore();
cache.put(key, 1);
- putToStore(key, 2);
+ storeStgy.putToStore(key, 2);
try (final Transaction transaction = grid(0).transactions().txStart()) {
Integer old = cache.get(key);
@@ -323,7 +316,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
transaction.commit();
}
- assertEquals(0, reads.get());
+ assertEquals(0, storeStgy.getReads());
}
/** {@inheritDoc} */
@@ -559,9 +552,6 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
* @throws Exception If failed.
*/
public void testRemoveAllSkipStore() throws Exception {
- if (isMultiJvm())
- fail("https://issues.apache.org/jira/browse/IGNITE-1088");
-
IgniteCache<String, Integer> jcache = jcache();
jcache.putAll(F.asMap("1", 1, "2", 2, "3", 3));
@@ -2063,7 +2053,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
// Check db.
if (!isMultiJvm()) {
- putToStore("key3", 3);
+ storeStgy.putToStore("key3", 3);
assertEquals((Integer)3, cache.getAndPutIfAbsent("key3", 4));
@@ -2135,7 +2125,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
// Check db.
if (!isMultiJvm()) {
- putToStore("key3", 3);
+ storeStgy.putToStore("key3", 3);
cacheAsync.getAndPutIfAbsent("key3", 4);
@@ -2184,7 +2174,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
// Check db.
if (!isMultiJvm()) {
- putToStore("key3", 3);
+ storeStgy.putToStore("key3", 3);
assertFalse(cache.putIfAbsent("key3", 4));
}
@@ -2257,7 +2247,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
// Check db.
if (!isMultiJvm()) {
- putToStore("key3", 3);
+ storeStgy.putToStore("key3", 3);
cacheAsync.putIfAbsent("key3", 4);
@@ -2361,7 +2351,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
assert cache.get("key") == 4;
if (!isMultiJvm()) {
- putToStore("key2", 5);
+ storeStgy.putToStore("key2", 5);
info("key2 5 -> 6");
@@ -2420,7 +2410,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
assert cache.get("key") == 4;
if (!isMultiJvm()) {
- putToStore("key2", 5);
+ storeStgy.putToStore("key2", 5);
assert cache.replace("key2", 6);
@@ -2496,7 +2486,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
assert cache.get("key") == 4;
if (!isMultiJvm()) {
- putToStore("key2", 5);
+ storeStgy.putToStore("key2", 5);
cacheAsync.replace("key2", 5, 6);
@@ -2558,7 +2548,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
assert cache.get("key") == 4;
if (!isMultiJvm()) {
- putToStore("key2", 5);
+ storeStgy.putToStore("key2", 5);
cacheAsync.replace("key2", 6);
@@ -2683,9 +2673,6 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
* @throws Exception If failed.
*/
public void testRemoveLoad() throws Exception {
- if (isMultiJvm())
- fail("https://issues.apache.org/jira/browse/IGNITE-1088");
-
int cnt = 10;
Set<String> keys = new HashSet<>();
@@ -2696,7 +2683,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
jcache().removeAll(keys);
for (String key : keys)
- putToStore(key, Integer.parseInt(key));
+ storeStgy.putToStore(key, Integer.parseInt(key));
for (int g = 0; g < gridCount(); g++)
grid(g).cache(null).localLoadCache(null);
@@ -3572,9 +3559,6 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
* @throws Exception If failed.
*/
private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
- if (isMultiJvm())
- fail("https://issues.apache.org/jira/browse/IGNITE-1089");
-
if (memoryMode() == OFFHEAP_TIERED)
return;
@@ -3586,22 +3570,17 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
final String key = primaryKeysForCache(jcache(), 1).get(0);
- GridCacheAdapter<String, Integer> internalCache = internalCache(fullCache());
-
- if (internalCache.isNear())
- internalCache = internalCache.context().near().dht();
-
- GridCacheEntryEx entry;
+ IgnitePair<Long> entryTtl;
if (oldEntry) {
c.put(key, 1);
- entry = internalCache.peekEx(key);
+ entryTtl = entryTtl(fullCache(), key);
- assert entry != null;
-
- assertEquals(0, entry.ttl());
- assertEquals(0, entry.expireTime());
+ assertNotNull(entryTtl.get1());
+ assertNotNull(entryTtl.get2());
+ assertEquals((Long)0L, entryTtl.get1());
+ assertEquals((Long)0L, entryTtl.get2());
}
long startTime = System.currentTimeMillis();
@@ -3618,10 +3597,10 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
}
if (oldEntry) {
- entry = internalCache.peekEx(key);
+ entryTtl = entryTtl(fullCache(), key);
- assertEquals(0, entry.ttl());
- assertEquals(0, entry.expireTime());
+ assertEquals((Long)0L, entryTtl.get1());
+ assertEquals((Long)0L, entryTtl.get2());
}
}
@@ -3643,18 +3622,14 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
- GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
-
- if (cache.context().isNear())
- cache = cache.context().near().dht();
-
- GridCacheEntryEx curEntry = cache.peekEx(key);
+ IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
- assertEquals(ttl, curEntry.ttl());
+ assertNotNull(curEntryTtl.get1());
+ assertNotNull(curEntryTtl.get2());
+ assertEquals(ttl, (long) curEntryTtl.get1());
+ assertTrue(curEntryTtl.get2() > startTime);
- assert curEntry.expireTime() > startTime;
-
- expireTimes[i] = curEntry.expireTime();
+ expireTimes[i] = curEntryTtl.get2();
}
}
@@ -3676,18 +3651,14 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
- GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
-
- if (cache.context().isNear())
- cache = cache.context().near().dht();
-
- GridCacheEntryEx curEntry = cache.peekEx(key);
+ IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
- assertEquals(ttl, curEntry.ttl());
+ assertNotNull(curEntryTtl.get1());
+ assertNotNull(curEntryTtl.get2());
+ assertEquals(ttl, (long) curEntryTtl.get1());
+ assertTrue(curEntryTtl.get2() > startTime);
- assert curEntry.expireTime() > startTime;
-
- expireTimes[i] = curEntry.expireTime();
+ expireTimes[i] = curEntryTtl.get2();
}
}
@@ -3709,18 +3680,14 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
- GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
-
- if (cache.context().isNear())
- cache = cache.context().near().dht();
-
- GridCacheEntryEx curEntry = cache.peekEx(key);
+ IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
- assertEquals(ttl, curEntry.ttl());
+ assertNotNull(curEntryTtl.get1());
+ assertNotNull(curEntryTtl.get2());
+ assertEquals(ttl, (long) curEntryTtl.get1());
+ assertTrue(curEntryTtl.get2() > startTime);
- assert curEntry.expireTime() > startTime;
-
- expireTimes[i] = curEntry.expireTime();
+ expireTimes[i] = curEntryTtl.get2();
}
}
@@ -3746,20 +3713,17 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
- GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
-
- if (cache.context().isNear())
- cache = cache.context().near().dht();
-
- GridCacheEntryEx curEntry = cache.peekEx(key);
+ IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
- assertEquals(ttl, curEntry.ttl());
- assertEquals(expireTimes[i], curEntry.expireTime());
+ assertNotNull(curEntryTtl.get1());
+ assertNotNull(curEntryTtl.get2());
+ assertEquals(ttl, (long)curEntryTtl.get1());
+ assertEquals(expireTimes[i], (long)curEntryTtl.get2());
}
}
// Avoid reloading from store.
- map.remove(key);
+ storeStgy.removeFromStore(key);
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@SuppressWarnings("unchecked")
@@ -3790,21 +3754,24 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
}
}, Math.min(ttl * 10, getTestTimeout())));
- if (internalCache.isLocal())
- return;
+ IgniteCache fullCache = fullCache();
- assert c.get(key) == null;
+ if (!isMultiJvmObject(fullCache)) {
+ GridCacheAdapter internalCache = internalCache(fullCache);
- internalCache = internalCache(fullCache());
+ if (internalCache.isLocal())
+ return;
+ }
- if (internalCache.isNear())
- internalCache = internalCache.context().near().dht();
+ assert c.get(key) == null;
// Ensure that old TTL and expire time are not longer "visible".
- entry = internalCache.peekEx(key);
+ entryTtl = entryTtl(fullCache(), key);
- assertEquals(0, entry.ttl());
- assertEquals(0, entry.expireTime());
+ assertNotNull(entryTtl.get1());
+ assertNotNull(entryTtl.get2());
+ assertEquals(0, (long)entryTtl.get1());
+ assertEquals(0, (long)entryTtl.get2());
// Ensure that next update will not pick old expire time.
@@ -3823,12 +3790,14 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
U.sleep(2000);
- entry = internalCache.peekEx(key);
+ entryTtl = entryTtl(fullCache(), key);
assertEquals((Integer)10, c.get(key));
- assertEquals(0, entry.ttl());
- assertEquals(0, entry.expireTime());
+ assertNotNull(entryTtl.get1());
+ assertNotNull(entryTtl.get2());
+ assertEquals(0, (long)entryTtl.get1());
+ assertEquals(0, (long)entryTtl.get2());
}
/**
@@ -4332,6 +4301,15 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
}
/**
+ * @param cache Cache.
+ * @param key Entry key.
+ * @return Pair [ttl, expireTime]; both values null if entry not found
+ */
+ protected IgnitePair<Long> entryTtl(IgniteCache cache, String key) {
+ return executeOnLocalOrRemoteJvm(cache, new EntryTtlTask(key, true));
+ }
+
+ /**
* @throws Exception If failed.
*/
public void testIterator() throws Exception {
@@ -4752,9 +4730,6 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
* @throws Exception If failed.
*/
public void testWithSkipStore() throws Exception {
- if(isMultiJvm())
- fail("https://issues.apache.org/jira/browse/IGNITE-1088");
-
IgniteCache<String, Integer> cache = grid(0).cache(null);
IgniteCache<String, Integer> cacheSkipStore = cache.withSkipStore();
@@ -4762,7 +4737,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
List<String> keys = primaryKeysForCache(cache, 10);
for (int i = 0; i < keys.size(); ++i)
- putToStore(keys.get(i), i);
+ storeStgy.putToStore(keys.get(i), i);
assertFalse(cacheSkipStore.iterator().hasNext());
@@ -4800,7 +4775,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
assertNotNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertEquals(i, map.get(key));
+ assertEquals(i, storeStgy.getFromStore(key));
}
for (int i = 0; i < keys.size(); ++i) {
@@ -4809,13 +4784,13 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
Integer val1 = -1;
cacheSkipStore.put(key, val1);
- assertEquals(i, map.get(key));
+ assertEquals(i, storeStgy.getFromStore(key));
assertEquals(val1, cacheSkipStore.get(key));
Integer val2 = -2;
assertEquals(val1, cacheSkipStore.invoke(key, new SetValueProcessor(val2)));
- assertEquals(i, map.get(key));
+ assertEquals(i, storeStgy.getFromStore(key));
assertEquals(val2, cacheSkipStore.get(key));
}
@@ -4824,7 +4799,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
assertNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertTrue(map.containsKey(key));
+ assertTrue(storeStgy.isInStore(key));
}
for (String key : keys) {
@@ -4832,37 +4807,37 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
assertNull(cacheSkipStore.get(key));
assertNull(cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
- map.put(key, 0);
+ storeStgy.putToStore(key, 0);
Integer val = -1;
assertNull(cacheSkipStore.invoke(key, new SetValueProcessor(val)));
- assertEquals(0, map.get(key));
+ assertEquals(0, storeStgy.getFromStore(key));
assertEquals(val, cacheSkipStore.get(key));
cache.remove(key);
- map.put(key, 0);
+ storeStgy.putToStore(key, 0);
assertTrue(cacheSkipStore.putIfAbsent(key, val));
assertEquals(val, cacheSkipStore.get(key));
- assertEquals(0, map.get(key));
+ assertEquals(0, storeStgy.getFromStore(key));
cache.remove(key);
- map.put(key, 0);
+ storeStgy.putToStore(key, 0);
assertNull(cacheSkipStore.getAndPut(key, val));
assertEquals(val, cacheSkipStore.get(key));
- assertEquals(0, map.get(key));
+ assertEquals(0, storeStgy.getFromStore(key));
cache.remove(key);
}
assertFalse(cacheSkipStore.iterator().hasNext());
- assertTrue(map.size() == 0);
+ assertTrue(storeStgy.getStoreSize() == 0);
assertTrue(cache.size(ALL) == 0);
// putAll/removeAll from multiple nodes.
@@ -4877,7 +4852,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key : keys) {
assertNotNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
}
cache.putAll(data);
@@ -4885,7 +4860,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key : keys) {
assertNotNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertTrue(map.containsKey(key));
+ assertTrue(storeStgy.isInStore(key));
}
cacheSkipStore.removeAll(data.keySet());
@@ -4893,7 +4868,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key : keys) {
assertNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertTrue(map.containsKey(key));
+ assertTrue(storeStgy.isInStore(key));
}
cacheSkipStore.putAll(data);
@@ -4901,7 +4876,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key : keys) {
assertNotNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertTrue(map.containsKey(key));
+ assertTrue(storeStgy.isInStore(key));
}
cacheSkipStore.removeAll(data.keySet());
@@ -4909,7 +4884,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key : keys) {
assertNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertTrue(map.containsKey(key));
+ assertTrue(storeStgy.isInStore(key));
}
cache.removeAll(data.keySet());
@@ -4917,24 +4892,24 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key : keys) {
assertNull(cacheSkipStore.get(key));
assertNull(cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
}
- assertTrue(map.size() == 0);
+ assertTrue(storeStgy.getStoreSize() == 0);
// Miscellaneous checks.
String newKey = "New key";
- assertFalse(map.containsKey(newKey));
+ assertFalse(storeStgy.isInStore(newKey));
cacheSkipStore.put(newKey, 1);
- assertFalse(map.containsKey(newKey));
+ assertFalse(storeStgy.isInStore(newKey));
cache.put(newKey, 1);
- assertTrue(map.containsKey(newKey));
+ assertTrue(storeStgy.isInStore(newKey));
Iterator<Cache.Entry<String, Integer>> it = cacheSkipStore.iterator();
@@ -4944,29 +4919,26 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
String rmvKey = entry.getKey();
- assertTrue(map.containsKey(rmvKey));
+ assertTrue(storeStgy.isInStore(rmvKey));
it.remove();
assertNull(cacheSkipStore.get(rmvKey));
- assertTrue(map.containsKey(rmvKey));
+ assertTrue(storeStgy.isInStore(rmvKey));
assertTrue(cache.size(ALL) == 0);
assertTrue(cacheSkipStore.size(ALL) == 0);
cache.remove(rmvKey);
- assertTrue(map.size() == 0);
+ assertTrue(storeStgy.getStoreSize() == 0);
}
/**
* @throws Exception If failed.
*/
public void testWithSkipStoreRemoveAll() throws Exception {
- if (isMultiJvm())
- fail("https://issues.apache.org/jira/browse/IGNITE-1088");
-
if (atomicityMode() == TRANSACTIONAL || (atomicityMode() == ATOMIC && nearEnabled())) // TODO IGNITE-373.
return;
@@ -4984,7 +4956,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key : data.keySet()) {
assertNotNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertTrue(map.containsKey(key));
+ assertTrue(storeStgy.isInStore(key));
}
cacheSkipStore.removeAll();
@@ -4992,7 +4964,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key : data.keySet()) {
assertNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertTrue(map.containsKey(key));
+ assertTrue(storeStgy.isInStore(key));
}
cache.removeAll();
@@ -5000,7 +4972,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key : data.keySet()) {
assertNull(cacheSkipStore.get(key));
assertNull(cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
}
}
@@ -5076,7 +5048,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key: keys) {
assertEquals(val, cacheSkipStore.get(key));
assertEquals(val, cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
}
tx.commit();
@@ -5085,10 +5057,10 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key: keys) {
assertEquals(val, cacheSkipStore.get(key));
assertEquals(val, cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
}
- assertEquals(0, map.size());
+ assertEquals(0, storeStgy.getStoreSize());
// cacheSkipStore putAll(..)/removeAll(..) check.
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
@@ -5102,10 +5074,10 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
assertEquals(val, cacheSkipStore.get(key));
assertEquals(val, cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
}
- map.putAll(data);
+ storeStgy.putAllToStore(data);
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
cacheSkipStore.removeAll(data.keySet());
@@ -5116,12 +5088,12 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key: keys) {
assertNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertTrue(map.containsKey(key));
+ assertTrue(storeStgy.isInStore(key));
cache.remove(key);
}
- assertTrue(map.size() == 0);
+ assertTrue(storeStgy.getStoreSize() == 0);
// cache putAll(..)/removeAll(..) check.
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
@@ -5130,7 +5102,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key: keys) {
assertNotNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
}
cache.removeAll(data.keySet());
@@ -5138,13 +5110,13 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key: keys) {
assertNull(cacheSkipStore.get(key));
assertNull(cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
}
tx.commit();
}
- assertTrue(map.size() == 0);
+ assertTrue(storeStgy.getStoreSize() == 0);
// putAll(..) from both cacheSkipStore and cache.
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
@@ -5165,7 +5137,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key: keys) {
assertNotNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
}
tx.commit();
@@ -5176,7 +5148,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
assertNotNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
}
for (int i = keys.size() / 2; i < keys.size(); i++) {
@@ -5184,7 +5156,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
assertNotNull(cacheSkipStore.get(key));
assertNotNull(cache.get(key));
- assertTrue(map.containsKey(key));
+ assertTrue(storeStgy.isInStore(key));
}
cache.removeAll(data.keySet());
@@ -5192,16 +5164,16 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
for (String key: keys) {
assertNull(cacheSkipStore.get(key));
assertNull(cache.get(key));
- assertFalse(map.containsKey(key));
+ assertFalse(storeStgy.isInStore(key));
}
// Check that read-through is disabled when cacheSkipStore is used.
for (int i = 0; i < keys.size(); i++)
- putToStore(keys.get(i), i);
+ storeStgy.putToStore(keys.get(i), i);
assertTrue(cacheSkipStore.size(ALL) == 0);
assertTrue(cache.size(ALL) == 0);
- assertTrue(map.size() != 0);
+ assertTrue(storeStgy.getStoreSize() != 0);
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
assertTrue(cacheSkipStore.getAll(data.keySet()).size() == 0);
@@ -5224,7 +5196,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
for (String key : data.keySet()) {
- map.put(key, 0);
+ storeStgy.putToStore(key, 0);
assertNull(cacheSkipStore.invoke(key, new SetValueProcessor(val)));
}
@@ -5233,7 +5205,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
}
for (String key : data.keySet()) {
- assertEquals(0, map.get(key));
+ assertEquals(0, storeStgy.getFromStore(key));
assertEquals(val, cacheSkipStore.get(key));
assertEquals(val, cache.get(key));
@@ -5243,7 +5215,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
for (String key : data.keySet()) {
- map.put(key, 0);
+ storeStgy.putToStore(key, 0);
assertTrue(cacheSkipStore.putIfAbsent(key, val));
}
@@ -5252,7 +5224,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
}
for (String key : data.keySet()) {
- assertEquals(0, map.get(key));
+ assertEquals(0, storeStgy.getFromStore(key));
assertEquals(val, cacheSkipStore.get(key));
assertEquals(val, cache.get(key));
@@ -5262,7 +5234,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
for (String key : data.keySet()) {
- map.put(key, 0);
+ storeStgy.putToStore(key, 0);
assertNull(cacheSkipStore.getAndPut(key, val));
}
@@ -5271,7 +5243,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
}
for (String key : data.keySet()) {
- assertEquals(0, map.get(key));
+ assertEquals(0, storeStgy.getFromStore(key));
assertEquals(val, cacheSkipStore.get(key));
assertEquals(val, cache.get(key));
@@ -5291,7 +5263,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
throws Exception {
assertTrue(cache.size(ALL) == 0);
assertTrue(cacheSkipStore.size(ALL) == 0);
- assertTrue(map.size() == 0);
+ assertTrue(storeStgy.getStoreSize() == 0);
}
/**
@@ -5631,6 +5603,40 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
/**
*
*/
+ public static class EntryTtlTask implements TestCacheCallable<String, Integer, IgnitePair<Long>> {
+ /** Entry key. */
+ private final String key;
+
+ /** Check cache for nearness, use DHT cache if it is near. */
+ private final boolean useDhtForNearCache;
+
+ /**
+ * @param key Entry key.
+ * @param useDhtForNearCache Check cache for nearness, use DHT cache if it is near.
+ */
+ public EntryTtlTask(String key, boolean useDhtForNearCache) {
+ this.key = key;
+ this.useDhtForNearCache = useDhtForNearCache;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgnitePair<Long> call(Ignite ignite, IgniteCache<String, Integer> cache) throws Exception {
+ GridCacheAdapter<?, ?> internalCache = internalCache0(cache);
+
+ if (useDhtForNearCache && internalCache.context().isNear())
+ internalCache = internalCache.context().near().dht();
+
+ GridCacheEntryEx entry = internalCache.peekEx(key);
+
+ return entry != null ?
+ new IgnitePair<>(entry.ttl(), entry.expireTime()) :
+ new IgnitePair<Long>(null, null);
+ }
+ }
+
+ /**
+ *
+ */
private static class CheckIteratorTask extends TestIgniteIdxCallable<Void> {
/**
* @param idx Index.
http://git-wip-us.apache.org/repos/asf/ignite/blob/f045558c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
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 eaab103..5fab800 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
@@ -39,10 +39,10 @@ import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.events.Event;
-import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
import org.apache.ignite.internal.util.lang.GridAbsPredicateX;
+import org.apache.ignite.internal.util.lang.IgnitePair;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.P1;
import org.apache.ignite.internal.util.typedef.internal.U;
@@ -211,6 +211,10 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
* @throws Exception If failed.
*/
public void testReaderTtlTx() throws Exception {
+ // IgniteProcessProxy#transactions is not implemented.
+ if (isMultiJvm())
+ return;
+
checkReaderTtl(true);
}
@@ -222,13 +226,19 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
}
/**
+ * @param cache Cache.
+ * @param key Entry key.
+ * @return Pair [ttl, expireTime] for near cache entry; both values null if entry not found
+ */
+ protected IgnitePair<Long> nearEntryTtl(IgniteCache cache, String key) {
+ return executeOnLocalOrRemoteJvm(cache, new EntryTtlTask(key, false));
+ }
+
+ /**
* @param inTx If {@code true} starts explicit transaction.
* @throws Exception If failed.
*/
private void checkReaderTtl(boolean inTx) throws Exception {
- if (isMultiJvm())
- fail("https://issues.apache.org/jira/browse/IGNITE-1089");
-
int ttl = 1000;
final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, ttl));
@@ -242,17 +252,14 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
info("Finished first put.");
{
- GridCacheAdapter<String, Integer> dht = internalCache(fullCache());
-
- if (dht.context().isNear())
- dht = dht.context().near().dht();
+ IgnitePair<Long> entryTtl = entryTtl(fullCache(), key);
- GridCacheEntryEx entry = dht.peekEx(key);
+ assertEquals((Integer)1, c.get(key));
- assert entry != null;
-
- assertEquals(0, entry.ttl());
- assertEquals(0, entry.expireTime());
+ assertNotNull(entryTtl.get1());
+ assertNotNull(entryTtl.get2());
+ assertEquals(0, (long)entryTtl.get1());
+ assertEquals(0, (long)entryTtl.get2());
}
long startTime = System.currentTimeMillis();
@@ -278,30 +285,19 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
for (int i = 0; i < gridCount(); i++) {
info("Checking grid: " + grid(i).localNode().id());
- GridCacheEntryEx entry = null;
-
- if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
- GridCacheAdapter<String, Integer> dht = internalCache(jcache(i));
+ IgnitePair<Long> entryTtl = null;
- if (dht.context().isNear())
- dht = dht.context().near().dht();
+ if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key))
+ entryTtl = entryTtl(jcache(i), key);
+ else if (i == nearIdx)
+ entryTtl = nearEntryTtl(jcache(i), key);
- entry = dht.peekEx(key);
-
- assert entry != null;
- }
- else if (i == nearIdx) {
- GridCacheAdapter<String, Integer> near = internalCache(jcache(i));
-
- entry = near.peekEx(key);
-
- assert entry != null;
- }
-
- if (entry != null) {
- assertEquals(ttl, entry.ttl());
- assert entry.expireTime() > startTime;
- expireTimes[i] = entry.expireTime();
+ if (entryTtl != null) {
+ assertNotNull(entryTtl.get1());
+ assertNotNull(entryTtl.get2());
+ assertEquals(ttl, (long)entryTtl.get1());
+ assertTrue(entryTtl.get2() > startTime);
+ expireTimes[i] = entryTtl.get2();
}
}
@@ -322,30 +318,19 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
}
for (int i = 0; i < gridCount(); i++) {
- GridCacheEntryEx entry = null;
-
- if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
- GridCacheAdapter<String, Integer> dht = internalCache(jcache(i));
-
- if (dht.context().isNear())
- dht = dht.context().near().dht();
-
- entry = dht.peekEx(key);
-
- assert entry != null;
- }
- else if (i == nearIdx) {
- GridCacheAdapter<String, Integer> near = internalCache(jcache(i));
-
- entry = near.peekEx(key);
-
- assert entry != null;
- }
-
- if (entry != null) {
- assertEquals(ttl, entry.ttl());
- assert entry.expireTime() > expireTimes[i];
- expireTimes[i] = entry.expireTime();
+ IgnitePair<Long> entryTtl = null;
+
+ if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key))
+ entryTtl = entryTtl(jcache(i), key);
+ else if (i == nearIdx)
+ entryTtl = nearEntryTtl(jcache(i), key);
+
+ if (entryTtl != null) {
+ assertNotNull(entryTtl.get1());
+ assertNotNull(entryTtl.get2());
+ assertEquals(ttl, (long)entryTtl.get1());
+ assertTrue(entryTtl.get2() > startTime);
+ expireTimes[i] = entryTtl.get2();
}
}
@@ -363,34 +348,23 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
}
for (int i = 0; i < gridCount(); i++) {
- GridCacheEntryEx entry = null;
-
- if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
- GridCacheAdapter<String, Integer> dht = internalCache(jcache(i));
-
- if (dht.context().isNear())
- dht = dht.context().near().dht();
-
- entry = dht.peekEx(key);
-
- assert entry != null;
- }
- else if (i == nearIdx) {
- GridCacheAdapter<String, Integer> near = internalCache(jcache(i));
-
- entry = near.peekEx(key);
-
- assert entry != null;
- }
-
- if (entry != null) {
- assertEquals(ttl, entry.ttl());
- assertEquals(expireTimes[i], entry.expireTime());
+ IgnitePair<Long> entryTtl = null;
+
+ if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key))
+ entryTtl = entryTtl(jcache(i), key);
+ else if (i == nearIdx)
+ entryTtl = nearEntryTtl(jcache(i), key);
+
+ if (entryTtl != null) {
+ assertNotNull(entryTtl.get1());
+ assertNotNull(entryTtl.get2());
+ assertEquals(ttl, (long)entryTtl.get1());
+ assertEquals(expireTimes[i], (long)entryTtl.get2());
}
}
// Avoid reloading from store.
- map.remove(key);
+ storeStgy.removeFromStore(key);
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@SuppressWarnings("unchecked")
@@ -421,17 +395,12 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
// Ensure that old TTL and expire time are not longer "visible".
{
- GridCacheAdapter<String, Integer> dht = internalCache(fullCache());
-
- if (dht.context().isNear())
- dht = dht.context().near().dht();
+ IgnitePair<Long> entryTtl = entryTtl(fullCache(), key);
- GridCacheEntryEx entry = dht.peekEx(key);
-
- assert entry != null;
-
- assertEquals(0, entry.ttl());
- assertEquals(0, entry.expireTime());
+ assertNotNull(entryTtl.get1());
+ assertNotNull(entryTtl.get2());
+ assertEquals(0, (long)entryTtl.get1());
+ assertEquals(0, (long)entryTtl.get2());
}
// Ensure that next update will not pick old expire time.
@@ -451,17 +420,12 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
U.sleep(2000);
{
- GridCacheAdapter<String, Integer> dht = internalCache(fullCache());
-
- if (dht.context().isNear())
- dht = dht.context().near().dht();
-
- GridCacheEntryEx entry = dht.peekEx(key);
-
- assert entry != null;
+ IgnitePair<Long> entryTtl = entryTtl(fullCache(), key);
- assertEquals(0, entry.ttl());
- assertEquals(0, entry.expireTime());
+ assertNotNull(entryTtl.get1());
+ assertNotNull(entryTtl.get2());
+ assertEquals(0, (long)entryTtl.get1());
+ assertEquals(0, (long)entryTtl.get2());
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/f045558c/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
index 4d40c68..18a0f6a 100644
--- 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
@@ -159,15 +159,23 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest {
* @param cache Cache.
* @return Cache.
*/
- protected <K, V> GridCacheAdapter<K, V> internalCache(IgniteCache<K, V> cache) {
+ protected static <K, V> GridCacheAdapter<K, V> internalCache0(IgniteCache<K, V> cache) {
if (isMultiJvmObject(cache))
- throw new UnsupportedOperationException("Oparetion can't be supported automatically for multi jvm " +
+ throw new UnsupportedOperationException("Operation can't be supported automatically for multi jvm " +
"(send closure instead).");
return ((IgniteKernal)cache.unwrap(Ignite.class)).internalCache(cache.getName());
}
/**
+ * @param cache Cache.
+ * @return Cache.
+ */
+ protected <K, V> GridCacheAdapter<K, V> internalCache(IgniteCache<K, V> cache) {
+ return internalCache0(cache);
+ }
+
+ /**
* @return Cache.
*/
protected <K, V> IgniteCache<K, V> jcache() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/f045558c/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
index 7286fb3..f2f69dd 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
@@ -65,6 +65,9 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
/** With async. */
private final boolean isAsync;
+ /** Expiry policy. */
+ private final ExpiryPolicy expiryPlc;
+
/** Ignite proxy. */
private final transient IgniteProcessProxy igniteProxy;
@@ -73,24 +76,26 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param proxy Ignite Process Proxy.
*/
public IgniteCacheProcessProxy(String name, IgniteProcessProxy proxy) {
- this(name, false, proxy);
+ this(name, false, null, proxy);
}
/**
* @param name Name.
* @param async Async flag.
+ * @param plc Expiry policy.
* @param proxy Ignite Process Proxy.
*/
- public IgniteCacheProcessProxy(String name, boolean async, IgniteProcessProxy proxy) {
+ private IgniteCacheProcessProxy(String name, boolean async, ExpiryPolicy plc, IgniteProcessProxy proxy) {
cacheName = name;
isAsync = async;
+ expiryPlc = plc;
igniteProxy = proxy;
compute = proxy.remoteCompute();
}
/** {@inheritDoc} */
@Override public IgniteCache<K, V> withAsync() {
- return new IgniteCacheProcessProxy<>(cacheName, true, igniteProxy);
+ return new IgniteCacheProcessProxy<>(cacheName, true, null, igniteProxy);
}
/** {@inheritDoc} */
@@ -116,7 +121,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
/** {@inheritDoc} */
@Override public IgniteCache<K, V> withExpiryPolicy(ExpiryPolicy plc) {
- throw new UnsupportedOperationException("Method should be supported.");
+ return new IgniteCacheProcessProxy<>(cacheName, isAsync, plc, igniteProxy);
}
/** {@inheritDoc} */
@@ -261,7 +266,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
/** {@inheritDoc} */
@Override public void put(K key, V val) {
- compute.call(new PutTask<>(cacheName, isAsync, key, val));
+ compute.call(new PutTask<>(cacheName, isAsync, expiryPlc, key, val));
}
/** {@inheritDoc} */
@@ -462,7 +467,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param clazz Clazz.
*/
public GetConfigurationTask(String cacheName, boolean async, Class<C> clazz) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.clazz = clazz;
}
@@ -489,7 +494,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param args Args.
*/
public LocalLoadCacheTask(String cacheName, boolean async, IgniteBiPredicate<K, V> p, Object[] args) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.p = p;
this.args = args;
}
@@ -519,7 +524,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param val Value.
*/
public GetAndPutIfAbsentTask(String cacheName, boolean async, K key, V val) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
this.val = val;
}
@@ -547,7 +552,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param byCurrThread By current thread.
*/
public IsLocalLockedTask(String cacheName, boolean async, K key, boolean byCurrThread) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
this.byCurrThread = byCurrThread;
}
@@ -571,7 +576,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param peekModes Peek modes.
*/
public LocalEntriesTask(String cacheName, boolean async, CachePeekMode[] peekModes) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.peekModes = peekModes;
}
@@ -599,7 +604,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param keys Keys.
*/
public LocalEvictTask(String cacheName, boolean async, Collection<? extends K> keys) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.keys = keys;
}
@@ -628,7 +633,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param peekModes Peek modes.
*/
public LocalPeekTask(String cacheName, boolean async, K key, CachePeekMode[] peekModes) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
this.peekModes = peekModes;
}
@@ -656,7 +661,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param loc Local.
*/
public SizeTask(String cacheName, boolean async, CachePeekMode[] peekModes, boolean loc) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.loc = loc;
this.peekModes = peekModes;
}
@@ -684,7 +689,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param loc Local.
*/
public SizeLongTask(String cacheName, boolean async, CachePeekMode[] peekModes, boolean loc) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.loc = loc;
this.peekModes = peekModes;
}
@@ -708,7 +713,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param key Key.
*/
public GetTask(String cacheName, boolean async, K key) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
}
@@ -731,7 +736,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param key Key.
*/
public GetEntryTask(String cacheName, boolean async, K key) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
}
@@ -750,7 +755,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param async Async.
*/
public RemoveAllTask(String cacheName, boolean async) {
- super(cacheName, async);
+ super(cacheName, async, null);
}
/** {@inheritDoc} */
@@ -779,11 +784,12 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
/**
* @param cacheName Cache name.
* @param async Async.
+ * @param expiryPlc Expiry policy.
* @param key Key.
* @param val Value.
*/
- public PutTask(String cacheName, boolean async, K key, V val) {
- super(cacheName, async);
+ public PutTask(String cacheName, boolean async, ExpiryPolicy expiryPlc, K key, V val) {
+ super(cacheName, async, expiryPlc);
this.key = key;
this.val = val;
}
@@ -809,7 +815,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param key Key.
*/
public ContainsKeyTask(String cacheName, boolean async, K key) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
}
@@ -828,7 +834,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param async Async.
*/
public ClearTask(String cacheName, boolean async) {
- super(cacheName, async);
+ super(cacheName, async, null);
}
/** {@inheritDoc} */
@@ -848,7 +854,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param async Async.
*/
public IteratorTask(String cacheName, boolean async) {
- super(cacheName, async);
+ super(cacheName, async, null);
}
/** {@inheritDoc} */
@@ -879,7 +885,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param val Value.
*/
public ReplaceTask(String cacheName, boolean async, K key, V val) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
this.val = val;
}
@@ -899,7 +905,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param async Async.
*/
public GetNameTask(String cacheName, boolean async) {
- super(cacheName, async);
+ super(cacheName, async, null);
}
/** {@inheritDoc} */
@@ -921,7 +927,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param key Key.
*/
public RemoveTask(String cacheName, boolean async, K key) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
}
@@ -944,7 +950,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param map Map.
*/
public PutAllTask(String cacheName, boolean async, Map<? extends K, ? extends V> map) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.map = map;
}
@@ -969,7 +975,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param keys Keys.
*/
public RemoveAllKeysTask(String cacheName, boolean async, Set<? extends K> keys) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.keys = keys;
}
@@ -994,7 +1000,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param keys Keys.
*/
public GetAllTask(String cacheName, boolean async, Set<? extends K> keys) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.keys = keys;
}
@@ -1017,7 +1023,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param keys Keys.
*/
public GetEntriesTask(String cacheName, boolean async, Set<? extends K> keys) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.keys = keys;
}
@@ -1040,7 +1046,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param keys Keys.
*/
public GetAllOutTxTask(String cacheName, boolean async, Set<? extends K> keys) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.keys = keys;
}
@@ -1063,7 +1069,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param keys Keys.
*/
public ContainsKeysTask(String cacheName, boolean async, Set<? extends K> keys) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.keys = keys;
}
@@ -1090,7 +1096,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param val Value.
*/
public GetAndPutTask(String cacheName, boolean async, K key, V val) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
this.val = val;
}
@@ -1118,7 +1124,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param val Value.
*/
public PutIfAbsentTask(String cacheName, boolean async, K key, V val) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
this.val = val;
}
@@ -1146,7 +1152,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param oldVal Old value.
*/
public RemoveIfExistsTask(String cacheName, boolean async, K key, V oldVal) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
this.oldVal = oldVal;
}
@@ -1170,7 +1176,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param key Key.
*/
public GetAndRemoveTask(String cacheName, boolean async, K key) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
}
@@ -1201,7 +1207,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param newVal New value.
*/
public ReplaceIfExistsTask(String cacheName, boolean async, K key, V oldVal, V newVal) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
this.oldVal = oldVal;
this.newVal = newVal;
@@ -1230,7 +1236,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param val Value.
*/
public GetAndReplaceTask(String cacheName, boolean async, K key, V val) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
this.val = val;
}
@@ -1257,7 +1263,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param key Key.
*/
public ClearKeyTask(String cacheName, boolean async, boolean loc, K key) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.key = key;
this.loc = loc;
}
@@ -1289,7 +1295,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param keys Keys.
*/
public ClearAllKeys(String cacheName, boolean async, boolean loc, Set<? extends K> keys) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.keys = keys;
this.loc = loc;
}
@@ -1327,7 +1333,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
*/
public InvokeTask(String cacheName, boolean async, K key, EntryProcessor<K, V, R> processor,
Object[] args) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.args = args;
this.key = key;
this.processor = processor;
@@ -1361,7 +1367,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
*/
public InvokeAllTask(String cacheName, boolean async, Set<? extends K> keys,
EntryProcessor<K, V, T> processor, Object[] args) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.args = args;
this.keys = keys;
this.processor = processor;
@@ -1382,7 +1388,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param async Async.
*/
public CloseTask(String cacheName, boolean async) {
- super(cacheName, async);
+ super(cacheName, async, null);
}
/** {@inheritDoc} */
@@ -1402,7 +1408,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param async Async.
*/
public DestroyTask(String cacheName, boolean async) {
- super(cacheName, async);
+ super(cacheName, async, null);
}
/** {@inheritDoc} */
@@ -1422,7 +1428,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param async Async.
*/
public IsClosedTask(String cacheName, boolean async) {
- super(cacheName, async);
+ super(cacheName, async, null);
}
/** {@inheritDoc} */
@@ -1444,7 +1450,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
* @param clazz Clazz.
*/
public UnwrapTask(String cacheName, boolean async, Class<R> clazz) {
- super(cacheName, async);
+ super(cacheName, async, null);
this.clazz = clazz;
}
@@ -1468,21 +1474,28 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
/** Async. */
protected final boolean async;
+ /** Expiry policy. */
+ protected final ExpiryPolicy expiryPlc;
+
/**
* @param cacheName Cache name.
* @param async Async.
+ * @param expiryPlc Optional expiry policy.
*/
- public CacheTaskAdapter(String cacheName, boolean async) {
+ public CacheTaskAdapter(String cacheName, boolean async, ExpiryPolicy expiryPlc) {
this.async = async;
this.cacheName = cacheName;
+ this.expiryPlc = expiryPlc;
}
/**
- * Returns cache instance.
+ * @return Cache instance.
*/
protected IgniteCache<K, V> cache() {
IgniteCache<K, V> cache = ignite.cache(cacheName);
+ cache = expiryPlc != null ? cache.withExpiryPolicy(expiryPlc) : cache;
+
return async ? cache.withAsync() : cache;
}
}
[20/33] ignite git commit: IGNITE-3446 Visor CMD: improve usability
for batch mode.
Posted by sb...@apache.org.
IGNITE-3446 Visor CMD: improve usability for batch mode.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4897315b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4897315b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4897315b
Branch: refs/heads/ignite-3547
Commit: 4897315b33a59e8566ffd026e99445279f27c53a
Parents: 6389400
Author: Andrey Novikov <an...@apache.org>
Authored: Fri Jul 15 16:54:21 2016 +0700
Committer: Andrey Novikov <an...@apache.org>
Committed: Fri Jul 15 16:54:21 2016 +0700
----------------------------------------------------------------------
.../ignite/visor/commands/VisorConsole.scala | 5 +-
.../commands/alert/VisorAlertCommand.scala | 2 +-
.../commands/cache/VisorCacheCommand.scala | 40 ++--
.../commands/cache/VisorCacheStopCommand.scala | 2 +-
.../config/VisorConfigurationCommand.scala | 23 ++-
.../commands/events/VisorEventsCommand.scala | 29 +--
.../visor/commands/gc/VisorGcCommand.scala | 11 +-
.../visor/commands/kill/VisorKillCommand.scala | 184 ++++++++++++++-----
.../visor/commands/node/VisorNodeCommand.scala | 13 +-
.../visor/commands/vvm/VisorVvmCommand.scala | 11 +-
.../scala/org/apache/ignite/visor/visor.scala | 76 +++++---
11 files changed, 276 insertions(+), 120 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/4897315b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala
index 6d91b05..b4d78b5 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala
@@ -146,7 +146,10 @@ class VisorConsole {
batchCommand.foreach(commands => batchStream = Some(commands.replaceAll(";", "\n")))
val inputStream = batchStream match {
- case Some(cmd) => new ByteArrayInputStream((cmd + "\nquit\n").getBytes("UTF-8"))
+ case Some(cmd) =>
+ visor.batchMode = true
+
+ new ByteArrayInputStream((cmd + "\nquit\n").getBytes("UTF-8"))
case None => new FileInputStream(FileDescriptor.in)
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/4897315b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommand.scala
index db60443..401a3f2 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommand.scala
@@ -751,7 +751,7 @@ private case class VisorSentAlert(
assert(spec != null)
def idVar: String = {
- val v = mfind(id)
+ val v = mfindHead(id)
if (v.isDefined) id + "(@" + v.get._1 + ")" else id
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/4897315b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
----------------------------------------------------------------------
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 b4ed6b8..a9f9137 100644
--- 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
@@ -73,12 +73,15 @@ import scala.language.{implicitConversions, reflectiveCalls}
*
* ====Arguments====
* {{{
- * -id=<node-id>
- * Full ID of the node to get cache statistics from.
- * Either '-id8' or '-id' can be specified.
- * If neither is specified statistics will be gathered from all nodes.
* -id8=<node-id>
* ID8 of the node to get cache statistics from.
+ * Note that either '-id8' or '-id' should be specified.
+ * You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.
+ * To specify oldest node on the same host as visor use variable '@nl'.
+ * To specify oldest node on other hosts that are not running visor use variable '@nr'.
+ * If neither is specified statistics will be gathered from all nodes.
+ * -id=<node-id>
+ * Full ID of the node to get cache statistics from.
* Either '-id8' or '-id' can be specified.
* If neither is specified statistics will be gathered from all nodes.
* -c=<cache-name>
@@ -278,7 +281,7 @@ class VisorCacheCommand {
else if (hasArgFlag("swap", argLst))
VisorCacheSwapCommand().swap(argLst, node)
else if (hasArgFlag("stop", argLst))
- VisorCacheStopCommand().scan(argLst, node)
+ VisorCacheStopCommand().stop(argLst, node)
}
else {
if (hasArgFlag("clear", argLst))
@@ -311,7 +314,12 @@ class VisorCacheCommand {
return
}
- println("Time of the snapshot: " + formatDateTime(System.currentTimeMillis))
+ node match {
+ case Some(n) =>
+ println("ID8=" + nid8(n) + ", time of the snapshot: " + formatDateTime(System.currentTimeMillis))
+ case None =>
+ println("Time of the snapshot: " + formatDateTime(System.currentTimeMillis))
+ }
val sumT = VisorTextTable()
@@ -459,12 +467,12 @@ class VisorCacheCommand {
*/
private def mkCacheName(@Nullable s: String): String = {
if (s == null) {
- val v = mfind(DFLT_CACHE_KEY)
+ val v = mfindHead(DFLT_CACHE_KEY)
DFLT_CACHE_NAME + (if (v.isDefined) "(@" + v.get._1 + ')' else "")
}
else {
- val v = mfind(s)
+ val v = mfindHead(s)
s + (if (v.isDefined) "(@" + v.get._1 + ')' else "")
}
@@ -649,7 +657,7 @@ class VisorCacheCommand {
sumT.render()
- val a = ask("\nChoose cache number ('c' to cancel) [c]: ", "c")
+ val a = ask("\nChoose cache number ('c' to cancel) [c]: ", "0")
if (a.toLowerCase == "c")
None
@@ -703,17 +711,19 @@ object VisorCacheCommand {
"cache -stop -c=<cache-name>"
),
args = Seq(
+ "-id8=<node-id>" -> Seq(
+ "ID8 of the node to get cache statistics from.",
+ "Note that either '-id8' or '-id' should be specified.",
+ "You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.",
+ "To specify oldest node on the same host as visor use variable '@nl'.",
+ "To specify oldest node on other hosts that are not running visor use variable '@nr'.",
+ "If neither is specified statistics will be gathered from all nodes."
+ ),
"-id=<node-id>" -> Seq(
"Full ID of the node to get cache statistics from.",
"Either '-id8' or '-id' can be specified.",
"If neither is specified statistics will be gathered from all nodes."
),
- "-id8=<node-id>" -> Seq(
- "ID8 of the node to get cache statistics from.",
- "Either '-id8' or '-id' can be specified.",
- "If neither is specified statistics will be gathered from all nodes.",
- "Note you can also use '@n0' ... '@nn' variables as shortcut to <node-id>."
- ),
"-c=<cache-name>" -> Seq(
"Name of the cache.",
"Note you can also use '@c0' ... '@cn' variables as shortcut to <cache-name>."
http://git-wip-us.apache.org/repos/asf/ignite/blob/4897315b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala
index bf81f73..1b55505 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala
@@ -76,7 +76,7 @@ class VisorCacheStopCommand {
*
* @param argLst Command arguments.
*/
- def scan(argLst: ArgList, node: Option[ClusterNode]) {
+ def stop(argLst: ArgList, node: Option[ClusterNode]) {
val cacheArg = argValue("c", argLst)
val cacheName = cacheArg match {
http://git-wip-us.apache.org/repos/asf/ignite/blob/4897315b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommand.scala
index 3f0f52f..1b8bbd5 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommand.scala
@@ -54,12 +54,16 @@ import scala.language.implicitConversions
*
* ====Arguments====
* {{{
+ * -id8=<node-id8>
+ * Node ID8.
+ * Note that either '-id8' or '-id' should be specified.
+ * You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.
+ * To specify oldest node on the same host as visor use variable '@nl'.
+ * To specify oldest node on other hosts that are not running visor use variable '@nr'.
+ * If neither is specified - command starts in interactive mode.
* -id=<node-id>
* Full node ID. Either '-id8' or '-id' can be specified.
* If neither is specified - command starts in interactive mode.
- * -id8=<node-id8>
- * Node ID8. Either '-id8' or '-id' can be specified.
- * If neither is specified - command starts in interactive mode.
* }}}
*
* ====Examples====
@@ -388,14 +392,17 @@ object VisorConfigurationCommand {
s"${cmd.name} {-id=<node-id>|id8=<node-id8>}"
),
args = List(
+ "-id8=<node-id8>" -> List(
+ "Node ID8.",
+ "Note that either '-id8' or '-id' should be specified.",
+ "You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.",
+ "To specify oldest node on the same host as visor use variable '@nl'.",
+ "To specify oldest node on other hosts that are not running visor use variable '@nr'.",
+ "If neither is specified - command starts in interactive mode."
+ ),
"-id=<node-id>" -> List(
"Full node ID. Either '-id8' or '-id' can be specified.",
"If neither is specified - command starts in interactive mode."
- ),
- "-id8=<node-id8>" -> List(
- "Node ID8. Either '-id8' or '-id' can be specified.",
- "If neither is specified - command starts in interactive mode.",
- "Note you can also use '@n0' ... '@nn' variables as shortcut to <node-id>."
)
),
examples = List(
http://git-wip-us.apache.org/repos/asf/ignite/blob/4897315b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala
index f7ea625..e3e73c7 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala
@@ -65,12 +65,15 @@ import scala.language.implicitConversions
*
* ====Arguments====
* {{{
- * -id=<node-id>
- * Full node ID.
- * Either '-id' or '-id8' can be specified.
- * If called without the arguments - starts in interactive mode.
* -id8
* Node ID8.
+ * Note that either '-id8' or '-id' should be specified.
+ * You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.
+ * To specify oldest node on the same host as visor use variable '@nl'.
+ * To specify oldest node on other hosts that are not running visor use variable '@nr'.
+ * If called without the arguments - starts in interactive mode.
+ * -id=<node-id>
+ * Full node ID.
* Either '-id' or '-id8' can be specified.
* If called without the arguments - starts in interactive mode.
* -e=<ch,de,di,jo,ta,ca,cr,sw>
@@ -146,7 +149,7 @@ class VisorEventsCommand extends VisorConsoleCommand {
*/
@throws[IllegalArgumentException]("In case unknown event mnemonic.")
protected def typeFilter(typeArg: Option[String]) = {
- typeArg.map(_.split(",").map(typeIds).flatten).orNull
+ typeArg.map(_.split(",").flatMap(typeIds)).orNull
}
/**
@@ -229,6 +232,8 @@ class VisorEventsCommand extends VisorConsoleCommand {
return
}
+ println("ID8=" + nid8(node))
+
if (evts == null || evts.isEmpty) {
println("No events found.")
@@ -402,17 +407,19 @@ object VisorEventsCommand {
" {-t=<num>s|m|h|d} {-s=e|t} {-r} {-c=<n>}"
),
args = List(
+ "-id8=<node-id8>" -> List(
+ "Node ID8.",
+ "Note that either '-id8' or '-id' should be specified.",
+ "You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.",
+ "To specify oldest node on the same host as visor use variable '@nl'.",
+ "To specify oldest node on other hosts that are not running visor use variable '@nr'.",
+ "If called without the arguments - starts in interactive mode."
+ ),
"-id=<node-id>" -> List(
"Full node ID.",
"Either '-id' or '-id8' can be specified.",
"If called without the arguments - starts in interactive mode."
),
- "-id8=<node-id8>" -> List(
- "Node ID8.",
- "Note that either '-id8' or '-id' can be specified and " +
- "you can also use '@n0' ... '@nn' variables as shortcut to <node-id8>.",
- "If called without the arguments - starts in interactive mode."
- ),
"-e=<ch,de,di,jo,ta,ca,cr,sw>" -> List(
"Comma separated list of event types that should be queried:",
" ch Checkpoint events.",
http://git-wip-us.apache.org/repos/asf/ignite/blob/4897315b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/gc/VisorGcCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/gc/VisorGcCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/gc/VisorGcCommand.scala
index a9bf39f..990fd00 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/gc/VisorGcCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/gc/VisorGcCommand.scala
@@ -52,7 +52,10 @@ import scala.language.{implicitConversions, reflectiveCalls}
* {{{
* -id8=<node-id8>
* ID8 of the node.
- * Note that either '-id8' or '-id' can be specified.
+ * Note that either '-id8' or '-id' should be specified.
+ * You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.
+ * To specify oldest node on the same host as visor use variable '@nl'.
+ * To specify oldest node on other hosts that are not running visor use variable '@nr'.
* -id=<node-id>
* ID of the node.
* Note that either '-id8' or '-id' can be specified.
@@ -159,8 +162,10 @@ object VisorGcCommand {
args = List(
"-id8=<node-id8>" -> List(
"ID8 of the node.",
- "Note that either '-id8' or '-id' can be specified and " +
- "you can also use '@n0' ... '@nn' variables as shortcut to <node-id8>."
+ "Note that either '-id8' or '-id' should be specified.",
+ "You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.",
+ "To specify oldest node on the same host as visor use variable '@nl'.",
+ "To specify oldest node on other hosts that are not running visor use variable '@nr'."
),
"-id=<node-id>" -> List(
"ID of the node.",
http://git-wip-us.apache.org/repos/asf/ignite/blob/4897315b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/kill/VisorKillCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/kill/VisorKillCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/kill/VisorKillCommand.scala
index dffd5f1..c705e21 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/kill/VisorKillCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/kill/VisorKillCommand.scala
@@ -46,7 +46,7 @@ import scala.util.control.Breaks._
* {{{
* kill
* kill "-in|-ih"
- * kill "{-r|-k} {-id8=<node-id8>|-id=<node-id>}"
+ * kill "{-r|-k} {-sc} {-al|-ar|-id8=<node-id8>|-id=<node-id>}"
* }}}
*
* ====Arguments====
@@ -61,17 +61,28 @@ import scala.util.control.Breaks._
* Run command in interactive mode with ability to
* choose a host where to kill or restart nodes.
* Note that either '-in' or '-ih' can be specified.
+ * -al
+ * Kill or restart all nodes on this host.
+ * Note that either '-al' or '-ar' can be specified.
+ * -ar
+ * Kill or restart all nodes on other hosts.
+ * Note that either '-al', '-ar' can be specified.
+ * -sc
+ * Skip kill or restart of client nodes for group nodes command.
* -r
* Restart node mode.
* Note that either '-r' or '-k' can be specified.
- * If no parameters provided - command starts in interactive mode.
+ * If no other parameters provided - command executes on all nodes.
* -k
* Kill (stop) node mode.
* Note that either '-r' or '-k' can be specified.
- * If no parameters provided - command starts in interactive mode.
+ * If no other parameters provided - command executes on all nodes.
* -id8=<node-id8>
* ID8 of the node to kill or restart.
- * Note that either '-id8' or '-id' can be specified.
+ * Note that either '-id8' or '-id' should be specified.
+ * You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.
+ * To specify oldest node on the same host as visor use variable '@nl'.
+ * To specify oldest node on other hosts that are not running visor use variable '@nr'.
* If no parameters provided - command starts in interactive mode.
* -id=<node-id>
* ID of the node to kill or restart.
@@ -85,6 +96,16 @@ import scala.util.control.Breaks._
* Starts command in interactive mode.
* kill "-id8=12345678 -r"
* Restart node with '12345678' ID8.
+ * kill -id8=@n0 -r" ->
+ * Restart specified node with id8 taken from 'n0' memory variable.
+ * kill -id8=@nl -r" ->
+ * Restart oldest local node with id8 taken from 'nl' memory variable.
+ * kill -id8=@nl -k" ->
+ * Kill (stop) oldest remote node with id8 taken from 'nr' memory variable.
+ * kill -r -ar" ->
+ * Restart all remote nodes.
+ * kill -k -sc -al" ->
+ * Kill (stop) all local server nodes.
* kill "-k"
* Kill (stop) all nodes.
* }}}
@@ -114,8 +135,12 @@ class VisorKillCommand extends VisorConsoleCommand {
val iNodes = hasArgFlag("in", argLst)
val iHosts = hasArgFlag("ih", argLst)
+ val skipClient = hasArgFlag("sc", argLst)
+
if (iNodes && iHosts)
scold("Only one of '-in' or '-ih' can be specified.").^^
+ else if ((iNodes || iHosts) && skipClient)
+ scold("Skip client flag is not allowed in interactive mode.").^^
else if (iNodes)
interactiveNodes().^^
else if (iHosts)
@@ -126,52 +151,94 @@ class VisorKillCommand extends VisorConsoleCommand {
val restart = hasArgFlag("r", argLst)
val kill = hasArgFlag("k", argLst)
- var node: ClusterNode = null
+ val allLocal = hasArgFlag("al", argLst)
+ val allRemote = hasArgFlag("ar", argLst)
if (kill && restart)
scold("Only one of '-k' or '-r' can be specified.")
else if (!kill && !restart)
scold("Missing '-k' or '-r' option in command: " + args)
- else if (id8.isDefined && id.isDefined)
- scold("Only one of -id8 or -id is allowed.")
+ else if (Seq(allLocal, allRemote, id8.isDefined, id.isDefined).count((v) => v) > 1)
+ scold("Only one of -al, -ar, -id8 or -id is allowed.")
+ else if ((id8.isDefined || id.isDefined) && skipClient)
+ scold("Skip client flag is allowed only for group command.")
else {
- if (id8.isDefined) {
+ val localGroup = ignite.cluster.forHost(ignite.localNode)
+
+ var nodes = if (id8.isDefined) {
val ns = nodeById8(id8.get)
if (ns.isEmpty)
scold("Unknown 'id8' value: " + id8.get).^^
- else if (ns.size != 1) {
+
+ if (ns.size != 1)
scold("'id8' resolves to more than one node (use full 'id' instead) : " + args).^^
- }
- else
- node = ns.head
+
+ ns.toSeq
}
- else if (id.isDefined)
- try {
- node = ignite.cluster.node(java.util.UUID.fromString(id.get))
+ else if (id.isDefined) {
+ var nid: UUID = null
- if (node == null)
- scold("'id' does not match any node : " + args).^^
+ try {
+ nid = UUID.fromString(id.get)
}
catch {
case e: IllegalArgumentException => scold("Invalid node 'id' in args: " + args).^^
}
- if (node == null && (id.isDefined || id8.isDefined))
- scold("Node with given ID cannot be found.").^^
+ val nodes = ignite.cluster.forNodeId(nid).nodes()
+
+ if (nodes.isEmpty)
+ scold("'id' does not match any node : " + args).^^
+
+ nodes.toSeq
+ } else if (allLocal) {
+ if (skipClient)
+ localGroup.forServers().nodes().toSeq
+ else
+ localGroup.nodes().toSeq
+ }
+ else if (allRemote) {
+ val remoteGroup = ignite.cluster.forOthers(localGroup)
+
+ if (skipClient)
+ remoteGroup.forServers().nodes().toSeq
+ else
+ remoteGroup.nodes().toSeq
+ }
+ else {
+ if (skipClient)
+ ignite.cluster.forServers().nodes().toSeq
+ else
+ ignite.cluster.nodes().toSeq
+ }
+
+ if (nodes.isEmpty) {
+ if (id.isDefined || id8.isDefined)
+ scold("Node with given ID cannot be found.").^^
+ else if (allLocal)
+ scold("Local nodes cannot be found.").^^
+ else if (allRemote)
+ scold("Remote nodes cannot be found.").^^
+ }
+
+ if (restart) {
+ val excludeNodes = nodes.filter(_.attribute[String](ATTR_RESTART_ENABLED) == "false")
+
+ nodes = nodes.filter(_.attribute[String](ATTR_RESTART_ENABLED) == "true")
- try
// In case of the restart - check that target node supports it.
- if (restart && node != null && node.attribute[String](ATTR_RESTART_ENABLED) != "true")
- scold("Node doesn't support restart: " + nid8(node)).^^
- catch {
- case e: IgniteException => scold("Failed to restart the node. " + e.getMessage).^^
+ if (excludeNodes.nonEmpty)
+ scold("Node(s) doesn't support restart: " + excludeNodes.map(nid8).mkString("[", ", ", "]")).^^
+
+ if (nodes.isEmpty)
+ break
}
val op = if (restart) "restart" else "kill"
try
- killOrRestart(if (node == null) ignite.cluster.nodes().map(_.id()) else Collections.singleton(node.id()), restart)
+ killOrRestart(nodes.map(_.id()), restart)
catch {
case _: IgniteException => scold("Failed to " + op + " due to system error.").^^
}
@@ -205,29 +272,31 @@ class VisorKillCommand extends VisorConsoleCommand {
val op = if (restart) "restart" else "kill"
- if (nodes.size == ignite.cluster.nodes().size())
- ask("Are you sure you want to " + op + " ALL nodes? (y/n) [n]: ", "n") match {
- case "y" | "Y" => ask("You are about to " + op + " ALL nodes. " +
- "Are you 100% sure? (y/n) [n]: ", "n") match {
+ if (!batchMode) {
+ if (nodes.size == ignite.cluster.nodes().size())
+ ask("Are you sure you want to " + op + " ALL nodes? (y/n) [n]: ", "n") match {
+ case "y" | "Y" => ask("You are about to " + op + " ALL nodes. " +
+ "Are you 100% sure? (y/n) [n]: ", "n") match {
case "y" | "Y" => ()
case "n" | "N" => break()
case x => nl(); warn("Invalid answer: " + x); break()
}
- case "n" | "N" => break()
- case x => nl(); warn("Invalid answer: " + x); break()
- }
- else if (nodes.size > 1)
- ask("Are you sure you want to " + op + " several nodes? (y/n) [n]: ", "n") match {
- case "y" | "Y" => ()
- case "n" | "N" => break()
- case x => nl(); warn("Invalid answer: " + x); break()
- }
- else
- ask("Are you sure you want to " + op + " this node? (y/n) [n]: ", "n") match {
- case "y" | "Y" => ()
- case "n" | "N" => break()
- case x => nl(); warn("Invalid answer: " + x); break()
- }
+ case "n" | "N" => break()
+ case x => nl(); warn("Invalid answer: " + x); break()
+ }
+ else if (nodes.size > 1)
+ ask("Are you sure you want to " + op + " several nodes? (y/n) [n]: ", "n") match {
+ case "y" | "Y" => ()
+ case "n" | "N" => break()
+ case x => nl(); warn("Invalid answer: " + x); break()
+ }
+ else
+ ask("Are you sure you want to " + op + " " + nid8(nodes.head) + " node? (y/n) [n]: ", "n") match {
+ case "y" | "Y" => ()
+ case "n" | "N" => break()
+ case x => nl(); warn("Invalid answer: " + x); break()
+ }
+ }
if (restart)
ignite.cluster.restartNodes(nodes)
@@ -278,7 +347,7 @@ object VisorKillCommand {
spec = List(
cmd.name,
s"${cmd.name} -in|-ih",
- s"${cmd.name} {-r|-k} {-id8=<node-id8>|-id=<node-id>}"
+ s"${cmd.name} {-r|-k} {-sc} {-al|-ar|-id8=<node-id8>|-id=<node-id>}"
),
args = List(
"-in" -> List(
@@ -293,6 +362,17 @@ object VisorKillCommand {
"choose a host where to kill or restart nodes.",
"Note that either '-in' or '-ih' can be specified."
),
+ "-al" -> List(
+ "Kill (stop) all local nodes.",
+ "Note that either '-al' or '-ar' can be specified."
+ ),
+ "-ar" -> List(
+ "Kill (stop) all remote nodes.",
+ "Note that either '-al' or '-ar' can be specified."
+ ),
+ "-sc" -> List(
+ "Skip kill or restart of client nodes for group nodes command."
+ ),
"-r" -> List(
"Restart node mode.",
"Note that either '-r' or '-k' can be specified.",
@@ -305,8 +385,10 @@ object VisorKillCommand {
),
"-id8=<node-id8>" -> List(
"ID8 of the node to kill or restart.",
- "Note that either '-id8' or '-id' can be specified and " +
- "you can also use '@n0' ... '@nn' variables as shortcut to <node-id8>.",
+ "Note that either '-id8' or '-id' should be specified.",
+ "You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.",
+ "To specify oldest node on the same host as visor use variable '@nl'.",
+ "To specify oldest node on other hosts that are not running visor use variable '@nr'.",
"If no parameters provided - command starts in interactive mode."
),
"-id=<node-id>" -> List(
@@ -322,6 +404,14 @@ object VisorKillCommand {
"Restart node with id8.",
s"${cmd.name} -id8=@n0 -r" ->
"Restart specified node with id8 taken from 'n0' memory variable.",
+ s"${cmd.name} -id8=@nl -r" ->
+ "Restart oldest local node with id8 taken from 'nl' memory variable.",
+ s"${cmd.name} -id8=@nl -k" ->
+ "Kill (stop) oldest remote node with id8 taken from 'nr' memory variable.",
+ s"${cmd.name} -r -ar" ->
+ "Restart all remote nodes.",
+ s"${cmd.name} -k -sc -al" ->
+ "Kill (stop) all local server nodes.",
s"${cmd.name} -k" ->
"Kill (stop) all nodes."
),
http://git-wip-us.apache.org/repos/asf/ignite/blob/4897315b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
index 9ba0129..899e495 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
@@ -57,7 +57,11 @@ import scala.util.control.Breaks._
* ====Arguments====
* {{{
* -id8=<node-id8>
- * ID8 of node. Either '-id8' or '-id' can be specified.
+ * ID8 of node.
+ * Note that either '-id8' or '-id' should be specified.
+ * You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.
+ * To specify oldest node on the same host as visor use variable '@nl'.
+ * To specify oldest node on other hosts that are not running visor use variable '@nr'.
* If neither specified - command starts in interactive mode.
* -id=<node-id>
* Full ID of node. Either '-id8' or '-id' can be specified.
@@ -295,8 +299,11 @@ object VisorNodeCommand {
),
args = List(
"-id8=<node-id8>" -> List(
- "Note that either '-id8' or '-id' can be specified and " +
- "you can also use '@n0' ... '@nn' variables as shortcut to <node-id8>.",
+ "ID8 of node.",
+ "Note that either '-id8' or '-id' should be specified.",
+ "You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.",
+ "To specify oldest node on the same host as visor use variable '@nl'.",
+ "To specify oldest node on other hosts that are not running visor use variable '@nr'.",
"If neither specified - command starts in interactive mode."
),
"-id=<node-id>" -> List(
http://git-wip-us.apache.org/repos/asf/ignite/blob/4897315b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala
index ff5cf82..e935256 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala
@@ -60,7 +60,10 @@ import scala.util.control.Breaks._
* If not specified, PATH and JAVA_HOME will be searched.
* -id8=<node-id8>
* ID8 of node.
- * Either '-id8' or '-id' can be specified.
+ * Note that either '-id8' or '-id' should be specified.
+ * You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.
+ * To specify oldest node on the same host as visor use variable '@nl'.
+ * To specify oldest node on other hosts that are not running visor use variable '@nr'.
* -id=<node-id>
* Full ID of node.
* Either '-id8' or '-id' can be specified.
@@ -260,8 +263,10 @@ object VisorVvmCommand {
),
"-id8=<node-id8>" -> List(
"ID8 of node.",
- "Note that either '-id8' or '-id' can be specified and " +
- "you can also use '@n0' ... '@nn' variables as shortcut to <node-id8>."
+ "Note that either '-id8' or '-id' should be specified.",
+ "You can also use '@n0' ... '@nn' variables as a shortcut for <node-id8>.",
+ "To specify oldest node on the same host as visor use variable '@nl'.",
+ "To specify oldest node on other hosts that are not running visor use variable '@nr'."
),
"-id=<node-id>" -> List(
"Full ID of node.",
http://git-wip-us.apache.org/repos/asf/ignite/blob/4897315b/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
index 7f7d1f9..1e8b634 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
@@ -234,6 +234,8 @@ object visor extends VisorTag {
private var reader: ConsoleReader = null
+ var batchMode: Boolean = false
+
def reader(reader: ConsoleReader) {
assert(reader != null)
@@ -661,12 +663,18 @@ object visor extends VisorTag {
}
/**
- * Finds variable by its value.
+ * Finds variables by its value.
*
* @param v Value to find by.
*/
- def mfind(@Nullable v: String): Option[(String, String)] =
- mem find(t => t._2 == v)
+ def mfind(@Nullable v: String) = mem.filter(t => t._2 == v).toSeq
+
+ /**
+ * Finds variable by its value.
+ *
+ * @param v Value to find by.
+ */
+ def mfindHead(@Nullable v: String) = mfind(v).filterNot(entry => Seq("nl", "nr").contains(entry._1)).headOption
/**
* Sets Visor console memory variable. Note that this method '''does not'''
@@ -872,7 +880,7 @@ object visor extends VisorTag {
case _ => Left("'id8' resolves to more than one node (use full 'id' instead): " + id8.get)
}
}
- else if (id.isDefined)
+ else if (id.isDefined) {
try {
val node = Option(ignite.cluster.node(java.util.UUID.fromString(id.get)))
@@ -884,6 +892,7 @@ object visor extends VisorTag {
catch {
case e: IllegalArgumentException => Left("Invalid node 'id': " + id.get)
}
+ }
else
Right(None)
}
@@ -1522,15 +1531,27 @@ object visor extends VisorTag {
setVarIfAbsent(ip.get, "h")
})
+ val onHost = ignite.cluster.forHost(ignite.localNode())
+
+ Option(onHost.forServers().forOldest().node()).foreach(n => msetOpt("nl", nid8(n)))
+ Option(ignite.cluster.forOthers(onHost).forServers.forOldest().node()).foreach(n => msetOpt("nr", nid8(n)))
+
nodeJoinLsnr = new IgnitePredicate[Event]() {
override def apply(e: Event): Boolean = {
e match {
case de: DiscoveryEvent =>
- setVarIfAbsent(nid8(de.eventNode()), "n")
+ val n = nid8(de.eventNode())
+
+ setVarIfAbsent(n, "n")
val node = ignite.cluster.node(de.eventNode().id())
if (node != null) {
+ val alias = if (U.sameMacs(ignite.localNode(), node)) "nl" else "nr"
+
+ if (mgetOpt(alias).isEmpty)
+ msetOpt(alias, n)
+
val ip = sortAddresses(node.addresses).headOption
if (ip.isDefined)
@@ -1551,29 +1572,25 @@ object visor extends VisorTag {
ignite.events().localListen(nodeJoinLsnr, EVT_NODE_JOINED)
- nodeLeftLsnr = new IgnitePredicate[Event]() {
- override def apply(e: Event): Boolean = {
- e match {
- case (de: DiscoveryEvent) =>
- val nv = mfind(nid8(de.eventNode()))
+ val mclear = (node: ClusterNode) => {
+ mfind(nid8(node)).foreach(nv => mem.remove(nv._1))
- if (nv.isDefined)
- mem.remove(nv.get._1)
+ val onHost = ignite.cluster.forHost(ignite.localNode())
- val ip = sortAddresses(de.eventNode().addresses).headOption
+ if (mgetOpt("nl").isEmpty)
+ Option(onHost.forServers().forOldest().node()).foreach(n => msetOpt("nl", nid8(n)))
- if (ip.isDefined) {
- val last = !ignite.cluster.nodes().exists(n =>
- n.addresses.size > 0 && sortAddresses(n.addresses).head == ip.get
- )
+ if (mgetOpt("nr").isEmpty)
+ Option(ignite.cluster.forOthers(onHost).forServers.forOldest().node()).foreach(n => msetOpt("nr", nid8(n)))
- if (last) {
- val hv = mfind(ip.get)
+ if (onHost.nodes().isEmpty)
+ sortAddresses(node.addresses).headOption.foreach((ip) => mfind(ip).foreach(hv => mem.remove(hv._1)))
+ }
- if (hv.isDefined)
- mem.remove(hv.get._1)
- }
- }
+ nodeLeftLsnr = new IgnitePredicate[Event]() {
+ override def apply(e: Event): Boolean = {
+ e match {
+ case (de: DiscoveryEvent) => mclear(de.eventNode())
}
true
@@ -1594,6 +1611,8 @@ object visor extends VisorTag {
close()
}
+ else
+ mclear(de.eventNode())
}
true
@@ -1658,7 +1677,7 @@ object visor extends VisorTag {
val n = ignite.cluster.node(id)
val id8 = nid8(id)
- val v = mfind(id8)
+ val v = mfindHead(id8)
id8 +
(if (v.isDefined) "(@" + v.get._1 + ")" else "") +
@@ -1678,7 +1697,7 @@ object visor extends VisorTag {
assert(isCon)
val id8 = nid8(id)
- val v = mfind(id8)
+ val v = mfindHead(id8)
id8 + (if (v.isDefined) "(@" + v.get._1 + ")" else "")
}
@@ -1846,7 +1865,7 @@ object visor extends VisorTag {
t.render()
- val a = ask("\nChoose node number ('c' to cancel) [c]: ", "c")
+ val a = ask("\nChoose node number ('c' to cancel) [0]: ", "0")
if (a.toLowerCase == "c")
None
@@ -1929,7 +1948,7 @@ object visor extends VisorTag {
t.render()
- val a = ask("\nChoose host number ('c' to cancel) [c]: ", "c")
+ val a = ask("\nChoose host number ('c' to cancel) [0]: ", "0")
if (a.toLowerCase == "c")
None
@@ -2000,6 +2019,9 @@ object visor extends VisorTag {
assert(prompt != null)
assert(dflt != null)
+ if (batchMode)
+ return dflt
+
readLineOpt(prompt, if (passwd) Some('*') else None) match {
case None => dflt
case Some(s) if s.length == 0 => dflt
[25/33] ignite git commit: GG-11293: .NET: Backported affinity
functions feature to 7.5.30.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionContext.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionContext.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionContext.cs
new file mode 100644
index 0000000..6067af4
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityFunctionContext.cs
@@ -0,0 +1,120 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Cache.Affinity
+{
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using Apache.Ignite.Core.Binary;
+ using Apache.Ignite.Core.Cluster;
+ using Apache.Ignite.Core.Events;
+ using Apache.Ignite.Core.Impl;
+
+ /// <summary>
+ /// Affinity function context.
+ /// </summary>
+ public class AffinityFunctionContext
+ {
+ /** */
+ private readonly List<List<IClusterNode>> _previousAssignment;
+
+ /** */
+ private readonly int _backups;
+
+ /** */
+ private readonly ICollection<IClusterNode> _currentTopologySnapshot;
+
+ /** */
+ private readonly AffinityTopologyVersion _currentTopologyVersion;
+
+ /** */
+ private readonly DiscoveryEvent _discoveryEvent;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AffinityFunctionContext"/> class.
+ /// </summary>
+ /// <param name="reader">The reader.</param>
+ internal AffinityFunctionContext(IBinaryRawReader reader)
+ {
+ Debug.Assert(reader != null);
+
+ _currentTopologySnapshot = IgniteUtils.ReadNodes(reader);
+ _backups = reader.ReadInt();
+ _currentTopologyVersion = new AffinityTopologyVersion(reader.ReadLong(), reader.ReadInt());
+ _discoveryEvent = EventReader.Read<DiscoveryEvent>(reader);
+
+ // Prev assignment
+ var cnt = reader.ReadInt();
+
+ if (cnt > 0)
+ {
+ _previousAssignment = new List<List<IClusterNode>>(cnt);
+
+ for (var i = 0; i < cnt; i++)
+ _previousAssignment.Add(IgniteUtils.ReadNodes(reader));
+ }
+ }
+
+ /// <summary>
+ /// Gets the affinity assignment for given partition on previous topology version.
+ /// First node in returned list is a primary node, other nodes are backups.
+ /// </summary>
+ /// <param name="partition">The partition to get previous assignment for.</param>
+ /// <returns>
+ /// List of nodes assigned to a given partition on previous topology version or <code>null</code>
+ /// if this information is not available.
+ /// </returns>
+ public ICollection<IClusterNode> GetPreviousAssignment(int partition)
+ {
+ return _previousAssignment == null ? null : _previousAssignment[partition];
+ }
+
+ /// <summary>
+ /// Gets number of backups for new assignment.
+ /// </summary>
+ public int Backups
+ {
+ get { return _backups; }
+ }
+
+ /// <summary>
+ /// Gets the current topology snapshot. Snapshot will contain only nodes on which the particular
+ /// cache is configured. List of passed nodes is guaranteed to be sorted in a same order
+ /// on all nodes on which partition assignment is performed.
+ /// </summary>
+ public ICollection<IClusterNode> CurrentTopologySnapshot
+ {
+ get { return _currentTopologySnapshot; }
+ }
+
+ /// <summary>
+ /// Gets the current topology version.
+ /// </summary>
+ public AffinityTopologyVersion CurrentTopologyVersion
+ {
+ get { return _currentTopologyVersion; }
+ }
+
+ /// <summary>
+ /// Gets the discovery event that caused the topology change.
+ /// </summary>
+ public DiscoveryEvent DiscoveryEvent
+ {
+ get { return _discoveryEvent; }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityTopologyVersion.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityTopologyVersion.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityTopologyVersion.cs
new file mode 100644
index 0000000..9bfdfb4
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/AffinityTopologyVersion.cs
@@ -0,0 +1,138 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Cache.Affinity
+{
+ using System;
+ using Apache.Ignite.Core.Cluster;
+
+ /// <summary>
+ /// Affinity topology version.
+ /// </summary>
+ public struct AffinityTopologyVersion : IEquatable<AffinityTopologyVersion>
+ {
+ /** */
+ private readonly long _version;
+
+ /** */
+ private readonly int _minorVersion;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AffinityTopologyVersion"/> struct.
+ /// </summary>
+ /// <param name="version">The version.</param>
+ /// <param name="minorVersion">The minor version.</param>
+ public AffinityTopologyVersion(long version, int minorVersion)
+ {
+ _version = version;
+ _minorVersion = minorVersion;
+ }
+
+ /// <summary>
+ /// Gets the major version, same as <see cref="ICluster.TopologyVersion"/>.
+ /// </summary>
+ public long Version
+ {
+ get { return _version; }
+ }
+
+ /// <summary>
+ /// Gets the minor version, which is increased when new caches start.
+ /// </summary>
+ public int MinorVersion
+ {
+ get { return _minorVersion; }
+ }
+
+ /// <summary>
+ /// Indicates whether the current object is equal to another object of the same type.
+ /// </summary>
+ /// <param name="other">An object to compare with this object.</param>
+ /// <returns>
+ /// true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
+ /// </returns>
+ public bool Equals(AffinityTopologyVersion other)
+ {
+ return _version == other._version && _minorVersion == other._minorVersion;
+ }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
+ /// </summary>
+ /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
+ /// <returns>
+ /// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise,
+ /// <c>false</c>.
+ /// </returns>
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is AffinityTopologyVersion && Equals((AffinityTopologyVersion) obj);
+ }
+
+ /// <summary>
+ /// Returns a hash code for this instance.
+ /// </summary>
+ /// <returns>
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ /// </returns>
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ return (_version.GetHashCode()*397) ^ _minorVersion;
+ }
+ }
+
+ /// <summary>
+ /// Implements the operator ==.
+ /// </summary>
+ /// <param name="left">The left.</param>
+ /// <param name="right">The right.</param>
+ /// <returns>
+ /// The result of the operator.
+ /// </returns>
+ public static bool operator ==(AffinityTopologyVersion left, AffinityTopologyVersion right)
+ {
+ return left.Equals(right);
+ }
+
+ /// <summary>
+ /// Implements the operator !=.
+ /// </summary>
+ /// <param name="left">The left.</param>
+ /// <param name="right">The right.</param>
+ /// <returns>
+ /// The result of the operator.
+ /// </returns>
+ public static bool operator !=(AffinityTopologyVersion left, AffinityTopologyVersion right)
+ {
+ return !left.Equals(right);
+ }
+
+ /// <summary>
+ /// Returns a <see cref="string" /> that represents this instance.
+ /// </summary>
+ /// <returns>
+ /// A <see cref="string" /> that represents this instance.
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("AffinityTopologyVersion [Version={0}, MinorVersion={1}]", _version, _minorVersion);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/FairAffinityFunction.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/FairAffinityFunction.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/FairAffinityFunction.cs
new file mode 100644
index 0000000..4a3885f
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Fair/FairAffinityFunction.cs
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Cache.Affinity.Fair
+{
+ using System;
+
+ /// <summary>
+ /// Fair affinity function which tries to ensure that all nodes get equal number of partitions with
+ /// minimum amount of reassignments between existing nodes.
+ /// </summary>
+ [Serializable]
+ public class FairAffinityFunction : AffinityFunctionBase
+ {
+ // No-op.
+ // Actual implementation is in Java, see AffinityFunctionSerializer.Write method.
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/IAffinityFunction.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/IAffinityFunction.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/IAffinityFunction.cs
new file mode 100644
index 0000000..b6c190c
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/IAffinityFunction.cs
@@ -0,0 +1,82 @@
+\ufeff/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Cache.Affinity
+{
+ using System;
+ using System.Collections.Generic;
+ using Apache.Ignite.Core.Cache.Affinity.Fair;
+ using Apache.Ignite.Core.Cache.Affinity.Rendezvous;
+ using Apache.Ignite.Core.Cluster;
+
+ /// <summary>
+ /// Represents a function that maps cache keys to cluster nodes.
+ /// <para />
+ /// Predefined implementations:
+ /// <see cref="RendezvousAffinityFunction"/>, <see cref="FairAffinityFunction"/>.
+ /// </summary>
+ public interface IAffinityFunction
+ {
+ /// <summary>
+ /// Gets the total number of partitions.
+ /// <para />
+ /// All caches should always provide correct partition count which should be the same on all
+ /// participating nodes. Note that partitions should always be numbered from 0 inclusively
+ /// to N exclusively without any gaps.
+ /// </summary>
+ int Partitions { get; }
+
+ /// <summary>
+ /// Gets partition number for a given key starting from 0. Partitioned caches
+ /// should make sure that keys are about evenly distributed across all partitions
+ /// from 0 to <see cref="Partitions"/> for best performance.
+ /// <para />
+ /// Note that for fully replicated caches it is possible to segment key sets among different
+ /// grid node groups. In that case each node group should return a unique partition
+ /// number. However, unlike partitioned cache, mappings of keys to nodes in
+ /// replicated caches are constant and a node cannot migrate from one partition
+ /// to another.
+ /// </summary>
+ /// <param name="key">Key to get partition for.</param>
+ /// <returns>Partition number for a given key.</returns>
+ int GetPartition(object key);
+
+ /// <summary>
+ /// Removes node from affinity. This method is called when it is safe to remove
+ /// disconnected node from affinity mapping.
+ /// </summary>
+ /// <param name="nodeId">The node identifier.</param>
+ void RemoveNode(Guid nodeId);
+
+ /// <summary>
+ /// Gets affinity nodes for a partition. In case of replicated cache, all returned
+ /// nodes are updated in the same manner. In case of partitioned cache, the returned
+ /// list should contain only the primary and back up nodes with primary node being
+ /// always first.
+ /// <pare />
+ /// Note that partitioned affinity must obey the following contract: given that node
+ /// <code>N</code> is primary for some key <code>K</code>, if any other node(s) leave
+ /// grid and no node joins grid, node <code>N</code> will remain primary for key <code>K</code>.
+ /// </summary>
+ /// <param name="context">The affinity function context.</param>
+ /// <returns>
+ /// A collection of partitions, where each partition is a collection of nodes,
+ /// where first node is a primary node, and other nodes are backup nodes.
+ /// </returns>
+ IEnumerable<IEnumerable<IClusterNode>> AssignPartitions(AffinityFunctionContext context);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/RendezvousAffinityFunction.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/RendezvousAffinityFunction.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/RendezvousAffinityFunction.cs
new file mode 100644
index 0000000..98ec364
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Affinity/Rendezvous/RendezvousAffinityFunction.cs
@@ -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.
+ */
+
+namespace Apache.Ignite.Core.Cache.Affinity.Rendezvous
+{
+ using System;
+
+ /// <summary>
+ /// Affinity function for partitioned cache based on Highest Random Weight algorithm.
+ /// </summary>
+ [Serializable]
+ public class RendezvousAffinityFunction : AffinityFunctionBase
+ {
+ // No-op.
+ // Actual implementation is in Java, see AffinityFunctionSerializer.Write method.
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Events/EventReader.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Events/EventReader.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Events/EventReader.cs
index cb1c715..ee1c837 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Events/EventReader.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Events/EventReader.cs
@@ -32,16 +32,14 @@ namespace Apache.Ignite.Core.Events
/// <param name="reader">Reader.</param>
/// <returns>Deserialized event.</returns>
/// <exception cref="System.InvalidCastException">Incompatible event type.</exception>
- public static T Read<T>(IBinaryReader reader) where T : IEvent
+ public static T Read<T>(IBinaryRawReader reader) where T : IEvent
{
- var r = reader.GetRawReader();
-
- var clsId = r.ReadInt();
+ var clsId = reader.ReadInt();
if (clsId == -1)
return default(T);
- return (T) CreateInstance(clsId, r);
+ return (T) CreateInstance(clsId, reader);
}
/// <summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
index 7a3fafc..f6fab5d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
@@ -26,10 +26,12 @@ namespace Apache.Ignite.Core
using System.Runtime;
using System.Threading;
using Apache.Ignite.Core.Binary;
+ using Apache.Ignite.Core.Cache.Affinity;
using Apache.Ignite.Core.Common;
using Apache.Ignite.Core.Impl;
using Apache.Ignite.Core.Impl.Binary;
using Apache.Ignite.Core.Impl.Binary.IO;
+ using Apache.Ignite.Core.Impl.Cache.Affinity;
using Apache.Ignite.Core.Impl.Common;
using Apache.Ignite.Core.Impl.Handle;
using Apache.Ignite.Core.Impl.Memory;
@@ -233,6 +235,8 @@ namespace Apache.Ignite.Core
PrepareConfiguration(reader);
PrepareLifecycleBeans(reader, outStream, handleRegistry);
+
+ PrepareAffinityFunctions(reader, outStream);
}
catch (Exception e)
{
@@ -282,7 +286,7 @@ namespace Apache.Ignite.Core
int cnt = reader.ReadInt();
for (int i = 0; i < cnt; i++)
- beans.Add(new LifecycleBeanHolder(CreateLifecycleBean(reader)));
+ beans.Add(new LifecycleBeanHolder(CreateObject<ILifecycleBean>(reader)));
// 2. Append beans definied in local configuration.
ICollection<ILifecycleBean> nativeBeans = _startup.Configuration.LifecycleBeans;
@@ -306,21 +310,33 @@ namespace Apache.Ignite.Core
}
/// <summary>
- /// Create lifecycle bean.
+ /// Prepares the affinity functions.
/// </summary>
- /// <param name="reader">Reader.</param>
- /// <returns>Lifecycle bean.</returns>
- private static ILifecycleBean CreateLifecycleBean(BinaryReader reader)
+ private static void PrepareAffinityFunctions(BinaryReader reader, PlatformMemoryStream outStream)
{
- // 1. Instantiate.
- var bean = IgniteUtils.CreateInstance<ILifecycleBean>(reader.ReadString());
+ var cnt = reader.ReadInt();
+
+ var writer = reader.Marshaller.StartMarshal(outStream);
- // 2. Set properties.
- var props = reader.ReadDictionaryAsGeneric<string, object>();
+ for (var i = 0; i < cnt; i++)
+ {
+ var objHolder = new ObjectInfoHolder(reader);
+ AffinityFunctionSerializer.Write(writer, objHolder.CreateInstance<IAffinityFunction>(), objHolder);
+ }
+ }
+
+ /// <summary>
+ /// Creates an object and sets the properties.
+ /// </summary>
+ /// <param name="reader">Reader.</param>
+ /// <returns>Resulting object.</returns>
+ private static T CreateObject<T>(IBinaryRawReader reader)
+ {
+ var res = IgniteUtils.CreateInstance<T>(reader.ReadString());
- IgniteUtils.SetProperties(bean, props);
+ IgniteUtils.SetProperties(res, reader.ReadDictionaryAsGeneric<string, object>());
- return bean;
+ return res;
}
/// <summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReaderExtensions.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReaderExtensions.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReaderExtensions.cs
index c3dcc3a..a5446ac 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReaderExtensions.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReaderExtensions.cs
@@ -19,6 +19,7 @@ namespace Apache.Ignite.Core.Impl.Binary
{
using System.Collections.Generic;
using Apache.Ignite.Core.Binary;
+ using Apache.Ignite.Core.Impl.Common;
/// <summary>
/// Reader extensions.
@@ -48,5 +49,18 @@ namespace Apache.Ignite.Core.Impl.Binary
{
return (Dictionary<TKey, TValue>) reader.ReadDictionary(size => new Dictionary<TKey, TValue>(size));
}
+
+ /// <summary>
+ /// Reads the object either as a normal object or as a [typeName+props] wrapper.
+ /// </summary>
+ public static T ReadObjectEx<T>(this IBinaryRawReader reader)
+ {
+ var obj = reader.ReadObject<object>();
+
+ if (obj == null)
+ return default(T);
+
+ return obj is T ? (T)obj : ((ObjectInfoHolder)obj).CreateInstance<T>();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
index 81fc195..a63e8f4 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
@@ -506,12 +506,15 @@ namespace Apache.Ignite.Core.Impl.Binary
/// <summary>
/// Adds a predefined system type.
/// </summary>
- private void AddSystemType<T>(byte typeId, Func<BinaryReader, T> ctor) where T : IBinaryWriteAware
+ private void AddSystemType<T>(int typeId, Func<BinaryReader, T> ctor) where T : IBinaryWriteAware
{
var type = typeof(T);
var serializer = new BinarySystemTypeSerializer<T>(ctor);
+ if (typeId == 0)
+ typeId = BinaryUtils.TypeId(type.Name, null, null);
+
AddType(type, typeId, BinaryUtils.GetTypeName(type), false, false, null, null, serializer, null, false);
}
@@ -536,6 +539,7 @@ namespace Apache.Ignite.Core.Impl.Binary
AddSystemType(BinaryUtils.TypeMessageListenerHolder, w => new MessageListenerHolder(w));
AddSystemType(BinaryUtils.TypeStreamReceiverHolder, w => new StreamReceiverHolder(w));
AddSystemType(BinaryUtils.TypePlatformJavaObjectFactoryProxy, w => new PlatformJavaObjectFactoryProxy());
+ AddSystemType(0, w => new ObjectInfoHolder(w));
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/AffinityFunctionSerializer.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/AffinityFunctionSerializer.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/AffinityFunctionSerializer.cs
new file mode 100644
index 0000000..888445a
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/AffinityFunctionSerializer.cs
@@ -0,0 +1,277 @@
+\ufeff/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Impl.Cache.Affinity
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.IO;
+ using System.Linq;
+ using Apache.Ignite.Core.Binary;
+ using Apache.Ignite.Core.Cache.Affinity;
+ using Apache.Ignite.Core.Cache.Affinity.Fair;
+ using Apache.Ignite.Core.Cache.Affinity.Rendezvous;
+ using Apache.Ignite.Core.Cluster;
+ using Apache.Ignite.Core.Common;
+ using Apache.Ignite.Core.Impl.Binary;
+ using Apache.Ignite.Core.Impl.Binary.IO;
+ using Apache.Ignite.Core.Impl.Memory;
+
+ /// <summary>
+ /// Affinity function read/write methods.
+ /// </summary>
+ internal static class AffinityFunctionSerializer
+ {
+ /** */
+ private const byte TypeCodeNull = 0;
+
+ /** */
+ private const byte TypeCodeFair = 1;
+
+ /** */
+ private const byte TypeCodeRendezvous = 2;
+
+ /** */
+ private const byte TypeCodeUser = 3;
+
+ /// <summary>
+ /// Writes the instance.
+ /// </summary>
+ internal static void Write(IBinaryRawWriter writer, IAffinityFunction fun, object userFuncOverride = null)
+ {
+ Debug.Assert(writer != null);
+
+ if (fun == null)
+ {
+ writer.WriteByte(TypeCodeNull);
+ return;
+ }
+
+ // 1) Type code
+ // 2) Partitions
+ // 3) ExcludeNeighbors
+ // 4) Override flags
+ // 5) User object
+
+ var p = fun as AffinityFunctionBase;
+
+ if (p != null)
+ {
+ writer.WriteByte(p is FairAffinityFunction ? TypeCodeFair : TypeCodeRendezvous);
+ writer.WriteInt(p.Partitions);
+ writer.WriteBoolean(p.ExcludeNeighbors);
+
+ var overrideFlags = GetOverrideFlags(p.GetType());
+ writer.WriteByte((byte) overrideFlags);
+
+ // Do not write user func if there is nothing overridden
+ WriteUserFunc(writer, overrideFlags != UserOverrides.None ? fun : null, userFuncOverride);
+ }
+ else
+ {
+ writer.WriteByte(TypeCodeUser);
+ writer.WriteInt(fun.Partitions);
+ writer.WriteBoolean(false); // Exclude neighbors
+ writer.WriteByte((byte) UserOverrides.All);
+ WriteUserFunc(writer, fun, userFuncOverride);
+ }
+ }
+
+ /// <summary>
+ /// Reads the instance.
+ /// </summary>
+ internal static IAffinityFunction Read(IBinaryRawReader reader)
+ {
+ Debug.Assert(reader != null);
+
+ var typeCode = reader.ReadByte();
+
+ if (typeCode == TypeCodeNull)
+ return null;
+
+ var partitions = reader.ReadInt();
+ var exclNeighbors = reader.ReadBoolean();
+ var overrideFlags = (UserOverrides)reader.ReadByte();
+ var userFunc = reader.ReadObjectEx<IAffinityFunction>();
+
+ if (userFunc != null)
+ {
+ Debug.Assert(overrideFlags != UserOverrides.None);
+
+ var fair = userFunc as FairAffinityFunction;
+ if (fair != null)
+ {
+ fair.Partitions = partitions;
+ fair.ExcludeNeighbors = exclNeighbors;
+ }
+
+ var rendezvous = userFunc as RendezvousAffinityFunction;
+ if (rendezvous != null)
+ {
+ rendezvous.Partitions = partitions;
+ rendezvous.ExcludeNeighbors = exclNeighbors;
+ }
+
+ return userFunc;
+ }
+
+ Debug.Assert(overrideFlags == UserOverrides.None);
+ AffinityFunctionBase fun;
+
+ switch (typeCode)
+ {
+ case TypeCodeFair:
+ fun = new FairAffinityFunction();
+ break;
+ case TypeCodeRendezvous:
+ fun = new RendezvousAffinityFunction();
+ break;
+ default:
+ throw new InvalidOperationException("Invalid AffinityFunction type code: " + typeCode);
+ }
+
+ fun.Partitions = partitions;
+ fun.ExcludeNeighbors = exclNeighbors;
+
+ return fun;
+ }
+
+
+ /// <summary>
+ /// Writes the partitions assignment to a stream.
+ /// </summary>
+ /// <param name="parts">The parts.</param>
+ /// <param name="stream">The stream.</param>
+ /// <param name="marsh">The marshaller.</param>
+ internal static void WritePartitions(IEnumerable<IEnumerable<IClusterNode>> parts,
+ PlatformMemoryStream stream, Marshaller marsh)
+ {
+ Debug.Assert(parts != null);
+ Debug.Assert(stream != null);
+ Debug.Assert(marsh != null);
+
+ IBinaryRawWriter writer = marsh.StartMarshal(stream);
+
+ var partCnt = 0;
+ writer.WriteInt(partCnt); // reserve size
+
+ foreach (var part in parts)
+ {
+ if (part == null)
+ throw new IgniteException("IAffinityFunction.AssignPartitions() returned invalid partition: null");
+
+ partCnt++;
+
+ var nodeCnt = 0;
+ var cntPos = stream.Position;
+ writer.WriteInt(nodeCnt); // reserve size
+
+ foreach (var node in part)
+ {
+ nodeCnt++;
+ writer.WriteGuid(node.Id);
+ }
+
+ var endPos = stream.Position;
+ stream.Seek(cntPos, SeekOrigin.Begin);
+ stream.WriteInt(nodeCnt);
+ stream.Seek(endPos, SeekOrigin.Begin);
+ }
+
+ stream.SynchronizeOutput();
+ stream.Seek(0, SeekOrigin.Begin);
+ writer.WriteInt(partCnt);
+ }
+
+ /// <summary>
+ /// Reads the partitions assignment from a stream.
+ /// </summary>
+ /// <param name="stream">The stream.</param>
+ /// <param name="marsh">The marshaller.</param>
+ /// <returns>Partitions assignment.</returns>
+ internal static IEnumerable<IEnumerable<IClusterNode>> ReadPartitions(IBinaryStream stream, Marshaller marsh)
+ {
+ Debug.Assert(stream != null);
+ Debug.Assert(marsh != null);
+
+ IBinaryRawReader reader = marsh.StartUnmarshal(stream);
+
+ var partCnt = reader.ReadInt();
+
+ var res = new List<IEnumerable<IClusterNode>>(partCnt);
+
+ for (var i = 0; i < partCnt; i++)
+ res.Add(IgniteUtils.ReadNodes(reader));
+
+ return res;
+ }
+
+ /// <summary>
+ /// Gets the override flags.
+ /// </summary>
+ private static UserOverrides GetOverrideFlags(Type funcType)
+ {
+ var res = UserOverrides.None;
+
+ var methods = new[] {UserOverrides.GetPartition, UserOverrides.AssignPartitions, UserOverrides.RemoveNode};
+
+ var map = funcType.GetInterfaceMap(typeof(IAffinityFunction));
+
+ foreach (var method in methods)
+ {
+ // Find whether user type overrides IAffinityFunction method from AffinityFunctionBase.
+ var methodName = method.ToString();
+
+ if (map.TargetMethods.Single(x => x.Name == methodName).DeclaringType != typeof(AffinityFunctionBase))
+ res |= method;
+ }
+
+ return res;
+ }
+
+ /// <summary>
+ /// Writes the user function.
+ /// </summary>
+ private static void WriteUserFunc(IBinaryRawWriter writer, IAffinityFunction func, object funcOverride)
+ {
+ if (funcOverride != null)
+ {
+ writer.WriteObject(funcOverride);
+ return;
+ }
+
+ if (func != null && !func.GetType().IsSerializable)
+ throw new IgniteException("AffinityFunction should be serializable.");
+
+ writer.WriteObject(func);
+ }
+
+ /// <summary>
+ /// Overridden function flags.
+ /// </summary>
+ [Flags]
+ private enum UserOverrides : byte
+ {
+ None = 0,
+ GetPartition = 1,
+ RemoveNode = 1 << 1,
+ AssignPartitions = 1 << 2,
+ All = GetPartition | RemoveNode | AssignPartitions
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/PlatformAffinityFunction.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/PlatformAffinityFunction.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/PlatformAffinityFunction.cs
new file mode 100644
index 0000000..d335804
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Affinity/PlatformAffinityFunction.cs
@@ -0,0 +1,74 @@
+\ufeff/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Impl.Cache.Affinity
+{
+ using System;
+ using System.Collections.Generic;
+ using Apache.Ignite.Core.Cache.Affinity;
+ using Apache.Ignite.Core.Cluster;
+ using Apache.Ignite.Core.Impl.Binary;
+ using Apache.Ignite.Core.Impl.Unmanaged;
+
+ /// <summary>
+ /// Affinity function that delegates to Java.
+ /// </summary>
+ internal class PlatformAffinityFunction : PlatformTarget, IAffinityFunction
+ {
+ /** Opcodes. */
+ private enum Op
+ {
+ Partition = 1,
+ RemoveNode = 2,
+ AssignPartitions = 3
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PlatformAffinityFunction"/> class.
+ /// </summary>
+ /// <param name="target">Target.</param>
+ /// <param name="marsh">Marshaller.</param>
+ public PlatformAffinityFunction(IUnmanagedTarget target, Marshaller marsh) : base(target, marsh)
+ {
+ // No-op.
+ }
+
+ /** <inheritdoc /> */
+ public int Partitions
+ {
+ get { throw new NotSupportedException("PlatformAffinityFunction.Partitions is not supported."); }
+ }
+
+ /** <inheritdoc /> */
+ public int GetPartition(object key)
+ {
+ return (int) DoOutOp((int) Op.Partition, w => w.WriteObject(key));
+ }
+
+ /** <inheritdoc /> */
+ public void RemoveNode(Guid nodeId)
+ {
+ DoOutOp((int) Op.RemoveNode, w => w.WriteGuid(nodeId));
+ }
+
+ /** <inheritdoc /> */
+ public IEnumerable<IEnumerable<IClusterNode>> AssignPartitions(AffinityFunctionContext context)
+ {
+ return DoInOp((int) Op.AssignPartitions, s => AffinityFunctionSerializer.ReadPartitions(s, Marshaller));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/ObjectInfoHolder.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/ObjectInfoHolder.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/ObjectInfoHolder.cs
new file mode 100644
index 0000000..407fe0c
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/ObjectInfoHolder.cs
@@ -0,0 +1,86 @@
+\ufeff/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Impl.Common
+{
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using Apache.Ignite.Core.Binary;
+ using Apache.Ignite.Core.Impl.Binary;
+
+ /// <summary>
+ /// Holds the information to instantiate an object and set its properties.
+ /// Typically used for .NET objects defined in Spring XML.
+ /// </summary>
+ internal class ObjectInfoHolder : IBinaryWriteAware
+ {
+ /** Type name. */
+ private readonly string _typeName;
+
+ /** Properties. */
+ private readonly Dictionary<string, object> _properties;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ObjectInfoHolder"/> class.
+ /// </summary>
+ /// <param name="reader">The reader.</param>
+ public ObjectInfoHolder(IBinaryRawReader reader)
+ {
+ Debug.Assert(reader != null);
+
+ _typeName = reader.ReadString();
+ _properties = reader.ReadDictionaryAsGeneric<string, object>();
+
+ Debug.Assert(!string.IsNullOrEmpty(_typeName));
+ }
+
+ /// <summary>
+ /// Gets the name of the type.
+ /// </summary>
+ public string TypeName
+ {
+ get { return _typeName; }
+ }
+
+ /// <summary>
+ /// Gets the properties.
+ /// </summary>
+ public Dictionary<string, object> Properties
+ {
+ get { return _properties; }
+ }
+
+ /// <summary>
+ /// Creates an instance according to type name and properties.
+ /// </summary>
+ public T CreateInstance<T>()
+ {
+ return IgniteUtils.CreateInstance<T>(TypeName, Properties);
+ }
+
+ /** <inheritdoc /> */
+ public void WriteBinary(IBinaryWriter writer)
+ {
+ Debug.Assert(writer != null);
+
+ var w = writer.GetRawWriter();
+
+ w.WriteString(_typeName);
+ w.WriteDictionary(_properties);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
index 7929a5d..5d0d989 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
@@ -128,8 +128,9 @@ namespace Apache.Ignite.Core.Impl
/// Create new instance of specified class.
/// </summary>
/// <param name="typeName">Class name</param>
+ /// <param name="props">Properties to set.</param>
/// <returns>New Instance.</returns>
- public static T CreateInstance<T>(string typeName)
+ public static T CreateInstance<T>(string typeName, IEnumerable<KeyValuePair<string, object>> props = null)
{
IgniteArgumentCheck.NotNullOrEmpty(typeName, "typeName");
@@ -138,7 +139,12 @@ namespace Apache.Ignite.Core.Impl
if (type == null)
throw new IgniteException("Failed to create class instance [className=" + typeName + ']');
- return (T) Activator.CreateInstance(type);
+ var res = (T)Activator.CreateInstance(type);
+
+ if (props != null)
+ SetProperties(res, props);
+
+ return res;
}
/// <summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbackHandlers.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbackHandlers.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbackHandlers.cs
index 8147e9d..dd16d03 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbackHandlers.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbackHandlers.cs
@@ -95,5 +95,11 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
internal void* extensionCbInLongOutLong;
internal void* extensionCbInLongLongOutLong;
+
+ internal void* affinityFunctionInit;
+ internal void* affinityFunctionPartition;
+ internal void* affinityFunctionAssignPartitions;
+ internal void* affinityFunctionRemoveNode;
+ internal void* affinityFunctionDestroy;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f57cc8d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs
index e554cfc..f4b3db9 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs
@@ -21,14 +21,16 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+ using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
-
+ using Apache.Ignite.Core.Cache.Affinity;
using Apache.Ignite.Core.Cluster;
using Apache.Ignite.Core.Common;
using Apache.Ignite.Core.Impl.Binary;
using Apache.Ignite.Core.Impl.Binary.IO;
using Apache.Ignite.Core.Impl.Cache;
+ using Apache.Ignite.Core.Impl.Cache.Affinity;
using Apache.Ignite.Core.Impl.Cache.Query.Continuous;
using Apache.Ignite.Core.Impl.Cache.Store;
using Apache.Ignite.Core.Impl.Common;
@@ -161,6 +163,12 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
private delegate long ExtensionCallbackInLongOutLongDelegate(void* target, int typ, long arg1);
private delegate long ExtensionCallbackInLongLongOutLongDelegate(void* target, int typ, long arg1, long arg2);
+ private delegate long AffinityFunctionInitDelegate(void* target, long memPtr, void* baseFunc);
+ private delegate int AffinityFunctionPartitionDelegate(void* target, long ptr, long memPtr);
+ private delegate void AffinityFunctionAssignPartitionsDelegate(void* target, long ptr, long inMemPtr, long outMemPtr);
+ private delegate void AffinityFunctionRemoveNodeDelegate(void* target, long ptr, long memPtr);
+ private delegate void AffinityFunctionDestroyDelegate(void* target, long ptr);
+
/// <summary>
/// constructor.
/// </summary>
@@ -240,7 +248,13 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
error = CreateFunctionPointer((ErrorCallbackDelegate)Error),
extensionCbInLongOutLong = CreateFunctionPointer((ExtensionCallbackInLongOutLongDelegate)ExtensionCallbackInLongOutLong),
- extensionCbInLongLongOutLong = CreateFunctionPointer((ExtensionCallbackInLongLongOutLongDelegate)ExtensionCallbackInLongLongOutLong)
+ extensionCbInLongLongOutLong = CreateFunctionPointer((ExtensionCallbackInLongLongOutLongDelegate)ExtensionCallbackInLongLongOutLong),
+
+ affinityFunctionInit = CreateFunctionPointer((AffinityFunctionInitDelegate)AffinityFunctionInit),
+ affinityFunctionPartition = CreateFunctionPointer((AffinityFunctionPartitionDelegate)AffinityFunctionPartition),
+ affinityFunctionAssignPartitions = CreateFunctionPointer((AffinityFunctionAssignPartitionsDelegate)AffinityFunctionAssignPartitions),
+ affinityFunctionRemoveNode = CreateFunctionPointer((AffinityFunctionRemoveNodeDelegate)AffinityFunctionRemoveNode),
+ affinityFunctionDestroy = CreateFunctionPointer((AffinityFunctionDestroyDelegate)AffinityFunctionDestroy)
};
_cbsPtr = Marshal.AllocHGlobal(UU.HandlersSize());
@@ -1057,7 +1071,120 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
}
#endregion
-
+
+ #region AffinityFunction
+
+ private long AffinityFunctionInit(void* target, long memPtr, void* baseFunc)
+ {
+ return SafeCall(() =>
+ {
+ using (var stream = IgniteManager.Memory.Get(memPtr).GetStream())
+ {
+ var reader = _ignite.Marshaller.StartUnmarshal(stream);
+
+ var func = reader.ReadObjectEx<IAffinityFunction>();
+
+ ResourceProcessor.Inject(func, _ignite);
+
+ var affBase = func as AffinityFunctionBase;
+
+ if (affBase != null)
+ affBase.SetBaseFunction(new PlatformAffinityFunction(
+ _ignite.InteropProcessor.ChangeTarget(baseFunc), _ignite.Marshaller));
+
+ return _handleRegistry.Allocate(func);
+ }
+ });
+ }
+
+ private int AffinityFunctionPartition(void* target, long ptr, long memPtr)
+ {
+ return SafeCall(() =>
+ {
+ using (var stream = IgniteManager.Memory.Get(memPtr).GetStream())
+ {
+ var key = _ignite.Marshaller.Unmarshal<object>(stream);
+
+ return _handleRegistry.Get<IAffinityFunction>(ptr, true).GetPartition(key);
+ }
+ });
+ }
+
+ private void AffinityFunctionAssignPartitions(void* target, long ptr, long inMemPtr, long outMemPtr)
+ {
+ SafeCall(() =>
+ {
+ using (var inStream = IgniteManager.Memory.Get(inMemPtr).GetStream())
+ {
+ var ctx = new AffinityFunctionContext(_ignite.Marshaller.StartUnmarshal(inStream));
+ var func = _handleRegistry.Get<IAffinityFunction>(ptr, true);
+ var parts = func.AssignPartitions(ctx);
+
+ if (parts == null)
+ throw new IgniteException(func.GetType() + ".AssignPartitions() returned invalid result: null");
+
+ using (var outStream = IgniteManager.Memory.Get(outMemPtr).GetStream())
+ {
+ var writer = _ignite.Marshaller.StartMarshal(outStream);
+
+ var partCnt = 0;
+ writer.WriteInt(partCnt); // reserve size
+
+ foreach (var part in parts)
+ {
+ if (part == null)
+ throw new IgniteException(func.GetType() +
+ ".AssignPartitions() returned invalid partition: null");
+
+ partCnt++;
+
+ var nodeCnt = 0;
+ var cntPos = outStream.Position;
+ writer.WriteInt(nodeCnt); // reserve size
+
+ foreach (var node in part)
+ {
+ nodeCnt++;
+ writer.WriteGuid(node.Id);
+ }
+
+ var endPos = outStream.Position;
+ outStream.Seek(cntPos, SeekOrigin.Begin);
+ outStream.WriteInt(nodeCnt);
+ outStream.Seek(endPos, SeekOrigin.Begin);
+ }
+
+ outStream.SynchronizeOutput();
+ outStream.Seek(0, SeekOrigin.Begin);
+ writer.WriteInt(partCnt);
+ }
+ }
+ });
+ }
+
+ private void AffinityFunctionRemoveNode(void* target, long ptr, long memPtr)
+ {
+ SafeCall(() =>
+ {
+ using (var stream = IgniteManager.Memory.Get(memPtr).GetStream())
+ {
+ var nodeId = _ignite.Marshaller.Unmarshal<Guid>(stream);
+
+ _handleRegistry.Get<IAffinityFunction>(ptr, true).RemoveNode(nodeId);
+ }
+ });
+ }
+
+ private void AffinityFunctionDestroy(void* target, long ptr)
+ {
+ SafeCall(() =>
+ {
+ _handleRegistry.Release(ptr);
+ });
+ }
+
+ #endregion
+
#region HELPERS
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
[31/33] ignite git commit: IGNITE-3470 - Support EXPIRED events in
continuous queries
Posted by sb...@apache.org.
IGNITE-3470 - Support EXPIRED events in continuous queries
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/aedfde69
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/aedfde69
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/aedfde69
Branch: refs/heads/ignite-3547
Commit: aedfde69af6e91277616052ab60fa0037693c2c6
Parents: b81dbbf
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Tue Jul 19 16:01:32 2016 -0700
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Tue Jul 19 16:01:32 2016 -0700
----------------------------------------------------------------------
.../ignite/cache/query/ContinuousQuery.java | 47 +++++++++++++++----
.../processors/cache/IgniteCacheProxy.java | 3 +-
.../continuous/CacheContinuousQueryManager.java | 9 ++--
...ridCacheContinuousQueryAbstractSelfTest.java | 48 +++++++++++++++++++-
4 files changed, 91 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/aedfde69/modules/core/src/main/java/org/apache/ignite/cache/query/ContinuousQuery.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/ContinuousQuery.java b/modules/core/src/main/java/org/apache/ignite/cache/query/ContinuousQuery.java
index bbfe8cc..49d471e 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/query/ContinuousQuery.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/query/ContinuousQuery.java
@@ -21,6 +21,7 @@ import javax.cache.Cache;
import javax.cache.configuration.Factory;
import javax.cache.event.CacheEntryEventFilter;
import javax.cache.event.CacheEntryUpdatedListener;
+import javax.cache.event.EventType;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
import org.apache.ignite.configuration.IgniteConfiguration;
@@ -142,6 +143,9 @@ public final class ContinuousQuery<K, V> extends Query<Cache.Entry<K, V>> {
/** Automatic unsubscription flag. */
private boolean autoUnsubscribe = DFLT_AUTO_UNSUBSCRIBE;
+ /** Whether to notify about {@link EventType#EXPIRED} events. */
+ private boolean includeExpired;
+
/**
* Creates new continuous query.
*/
@@ -324,6 +328,38 @@ public final class ContinuousQuery<K, V> extends Query<Cache.Entry<K, V>> {
return this;
}
+ /**
+ * Gets automatic unsubscription flag value.
+ *
+ * @return Automatic unsubscription flag.
+ */
+ public boolean isAutoUnsubscribe() {
+ return autoUnsubscribe;
+ }
+
+ /**
+ * Sets the flag value defining whether to notify about {@link EventType#EXPIRED} events.
+ * If {@code true}, then the remote listener will get notifications about entries
+ * expired in cache. Otherwise, only {@link EventType#CREATED}, {@link EventType#UPDATED}
+ * and {@link EventType#REMOVED} events will be fired in the remote listener.
+ * <p>
+ * This flag is {@code false} by default, so {@link EventType#EXPIRED} events are disabled.
+ *
+ * @param includeExpired Whether to notify about {@link EventType#EXPIRED} events.
+ */
+ public void setIncludeExpired(boolean includeExpired) {
+ this.includeExpired = includeExpired;
+ }
+
+ /**
+ * Gets the flag value defining whether to notify about {@link EventType#EXPIRED} events.
+ *
+ * @return Whether to notify about {@link EventType#EXPIRED} events.
+ */
+ public boolean isIncludeExpired() {
+ return includeExpired;
+ }
+
/** {@inheritDoc} */
@Override public ContinuousQuery<K, V> setPageSize(int pageSize) {
return (ContinuousQuery<K, V>)super.setPageSize(pageSize);
@@ -333,13 +369,4 @@ public final class ContinuousQuery<K, V> extends Query<Cache.Entry<K, V>> {
@Override public ContinuousQuery<K, V> setLocal(boolean loc) {
return (ContinuousQuery<K, V>)super.setLocal(loc);
}
-
- /**
- * Gets automatic unsubscription flag value.
- *
- * @return Automatic unsubscription flag.
- */
- public boolean isAutoUnsubscribe() {
- return autoUnsubscribe;
- }
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/aedfde69/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
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 92e59db..249cfae 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
@@ -598,7 +598,8 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V
qry.getTimeInterval(),
qry.isAutoUnsubscribe(),
loc,
- keepBinary);
+ keepBinary,
+ qry.isIncludeExpired());
final QueryCursor<Cache.Entry<K, V>> cur =
qry.getInitialQuery() != null ? query(qry.getInitialQuery()) : null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/aedfde69/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
----------------------------------------------------------------------
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 195f3ae..a8e5a6b 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
@@ -421,7 +421,8 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
long timeInterval,
boolean autoUnsubscribe,
boolean loc,
- final boolean keepBinary) throws IgniteCheckedException
+ final boolean keepBinary,
+ final boolean includeExpired) throws IgniteCheckedException
{
IgniteClosure<Boolean, CacheContinuousQueryHandler> clsr;
@@ -438,7 +439,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
rmtFilterFactory,
true,
false,
- true,
+ !includeExpired,
false,
null);
else {
@@ -456,7 +457,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
(CacheEntryEventSerializableFilter)fltr,
true,
false,
- true,
+ !includeExpired,
false);
}
@@ -473,7 +474,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
rmtFilter,
true,
false,
- true,
+ !includeExpired,
false);
}
};
http://git-wip-us.apache.org/repos/asf/ignite/blob/aedfde69/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java
index 3d238af..08acc42 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java
@@ -34,6 +34,9 @@ import javax.cache.Cache;
import javax.cache.configuration.Factory;
import javax.cache.event.CacheEntryEvent;
import javax.cache.event.CacheEntryUpdatedListener;
+import javax.cache.event.EventType;
+import javax.cache.expiry.CreatedExpiryPolicy;
+import javax.cache.expiry.Duration;
import javax.cache.integration.CacheWriterException;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
@@ -71,7 +74,6 @@ import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.jetbrains.annotations.Nullable;
import org.jsr166.ConcurrentHashMap8;
-import org.jsr166.ConcurrentLinkedDeque8;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -1094,6 +1096,50 @@ public abstract class GridCacheContinuousQueryAbstractSelfTest extends GridCommo
}
/**
+ * @throws Exception If failed.
+ */
+ public void testExpired() throws Exception {
+ IgniteCache<Object, Object> cache = grid(0).cache(null).
+ withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, 1000)));
+
+ final Map<Object, Object> map = new ConcurrentHashMap8<>();
+ final CountDownLatch latch = new CountDownLatch(2);
+
+ ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
+
+ qry.setIncludeExpired(true);
+
+ qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
+ @Override public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
+ for (CacheEntryEvent<?, ?> e : evts) {
+ if (e.getEventType() == EventType.EXPIRED) {
+ assertNull(e.getValue());
+
+ map.put(e.getKey(), e.getOldValue());
+
+ latch.countDown();
+ }
+ }
+ }
+ });
+
+ try (QueryCursor<Cache.Entry<Object, Object>> ignored = cache.query(qry)) {
+ cache.put(1, 1);
+ cache.put(2, 2);
+
+ // Wait for expiration.
+ Thread.sleep(2000);
+
+ assert latch.await(LATCH_TIMEOUT, MILLISECONDS);
+
+ assertEquals(2, map.size());
+
+ assertEquals(1, (int)map.get(1));
+ assertEquals(2, (int)map.get(2));
+ }
+ }
+
+ /**
*
*/
private static class StoreFactory implements Factory<CacheStore> {
[17/33] ignite git commit: Fixed NPE in OptimizedMarshaller when
streams pool is used
Posted by sb...@apache.org.
Fixed NPE in OptimizedMarshaller when streams pool is used
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/27f6c586
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/27f6c586
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/27f6c586
Branch: refs/heads/ignite-3547
Commit: 27f6c5862940948669b6445a6839501327dacbb2
Parents: 4d2be72
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Wed Jul 13 14:37:23 2016 -0700
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Wed Jul 13 14:37:23 2016 -0700
----------------------------------------------------------------------
.../OptimizedObjectStreamRegistry.java | 145 +++++++++++--------
.../OptimizedMarshallerPooledSelfTest.java | 44 ++++++
.../testsuites/IgniteBinaryBasicTestSuite.java | 2 +
.../IgniteMarshallerSelfTestSuite.java | 2 +
4 files changed, 130 insertions(+), 63 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/27f6c586/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamRegistry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamRegistry.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamRegistry.java
index e0e4872..fd1b917 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamRegistry.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamRegistry.java
@@ -33,8 +33,11 @@ class OptimizedObjectStreamRegistry {
/** Holders. */
private static final ThreadLocal<StreamHolder> holders = new ThreadLocal<>();
- /** Holders pool. */
- private static BlockingQueue<StreamHolder> pool;
+ /** Output streams pool. */
+ private static BlockingQueue<OptimizedObjectOutputStream> outPool;
+
+ /** Input streams pool. */
+ private static BlockingQueue<OptimizedObjectInputStream> inPool;
/**
* Ensures singleton.
@@ -50,16 +53,18 @@ class OptimizedObjectStreamRegistry {
*/
static void poolSize(int size) {
if (size > 0) {
- pool = new LinkedBlockingQueue<>(size);
+ outPool = new LinkedBlockingQueue<>(size);
+ inPool = new LinkedBlockingQueue<>(size);
for (int i = 0; i < size; i++) {
- boolean b = pool.offer(new StreamHolder());
-
- assert b;
+ outPool.offer(createOut());
+ inPool.offer(createIn());
}
}
- else
- pool = null;
+ else {
+ outPool = null;
+ inPool = null;
+ }
}
/**
@@ -69,7 +74,17 @@ class OptimizedObjectStreamRegistry {
* @throws org.apache.ignite.internal.IgniteInterruptedCheckedException If thread is interrupted while trying to take holder from pool.
*/
static OptimizedObjectOutputStream out() throws IgniteInterruptedCheckedException {
- return holder().acquireOut();
+ if (outPool != null) {
+ try {
+ return outPool.take();
+ }
+ catch (InterruptedException e) {
+ throw new IgniteInterruptedCheckedException(
+ "Failed to take output object stream from pool (thread interrupted).", e);
+ }
+ }
+ else
+ return holder().acquireOut();
}
/**
@@ -79,7 +94,17 @@ class OptimizedObjectStreamRegistry {
* @throws org.apache.ignite.internal.IgniteInterruptedCheckedException If thread is interrupted while trying to take holder from pool.
*/
static OptimizedObjectInputStream in() throws IgniteInterruptedCheckedException {
- return holder().acquireIn();
+ if (inPool != null) {
+ try {
+ return inPool.take();
+ }
+ catch (InterruptedException e) {
+ throw new IgniteInterruptedCheckedException(
+ "Failed to take input object stream from pool (thread interrupted).", e);
+ }
+ }
+ else
+ return holder().acquireIn();
}
/**
@@ -90,17 +115,17 @@ class OptimizedObjectStreamRegistry {
static void closeOut(OptimizedObjectOutputStream out) {
U.close(out, null);
- StreamHolder holder = holders.get();
-
- holder.releaseOut();
-
- if (pool != null) {
- holders.remove();
-
- boolean b = pool.offer(holder);
+ if (outPool != null) {
+ boolean b = outPool.offer(out);
assert b;
}
+ else {
+ StreamHolder holder = holders.get();
+
+ if (holder != null)
+ holder.releaseOut();
+ }
}
/**
@@ -112,17 +137,17 @@ class OptimizedObjectStreamRegistry {
static void closeIn(OptimizedObjectInputStream in) {
U.close(in, null);
- StreamHolder holder = holders.get();
-
- holder.releaseIn();
-
- if (pool != null) {
- holders.remove();
-
- boolean b = pool.offer(holder);
+ if (inPool != null) {
+ boolean b = inPool.offer(in);
assert b;
}
+ else {
+ StreamHolder holder = holders.get();
+
+ if (holder != null)
+ holder.releaseIn();
+ }
}
/**
@@ -134,19 +159,41 @@ class OptimizedObjectStreamRegistry {
private static StreamHolder holder() throws IgniteInterruptedCheckedException {
StreamHolder holder = holders.get();
- if (holder == null) {
- try {
- holders.set(holder = pool != null ? pool.take() : new StreamHolder());
- }
- catch (InterruptedException e) {
- throw new IgniteInterruptedCheckedException("Failed to take object stream from pool (thread interrupted).", e);
- }
- }
+ if (holder == null)
+ holders.set(holder = new StreamHolder());
return holder;
}
/**
+ * Creates output stream.
+ *
+ * @return Object output stream.
+ */
+ private static OptimizedObjectOutputStream createOut() {
+ try {
+ return new OptimizedObjectOutputStream(new GridUnsafeDataOutput(4 * 1024));
+ }
+ catch (IOException e) {
+ throw new IgniteException("Failed to create object output stream.", e);
+ }
+ }
+
+ /**
+ * Creates input stream.
+ *
+ * @return Object input stream.
+ */
+ private static OptimizedObjectInputStream createIn() {
+ try {
+ return new OptimizedObjectInputStream(new GridUnsafeDataInput());
+ }
+ catch (IOException e) {
+ throw new IgniteException("Failed to create object input stream.", e);
+ }
+ }
+
+ /**
* Streams holder.
*/
private static class StreamHolder {
@@ -193,33 +240,5 @@ class OptimizedObjectStreamRegistry {
void releaseIn() {
inAcquireCnt--;
}
-
- /**
- * Creates output stream.
- *
- * @return Object output stream.
- */
- private OptimizedObjectOutputStream createOut() {
- try {
- return new OptimizedObjectOutputStream(new GridUnsafeDataOutput(4 * 1024));
- }
- catch (IOException e) {
- throw new IgniteException("Failed to create object output stream.", e);
- }
- }
-
- /**
- * Creates input stream.
- *
- * @return Object input stream.
- */
- private OptimizedObjectInputStream createIn() {
- try {
- return new OptimizedObjectInputStream(new GridUnsafeDataInput());
- }
- catch (IOException e) {
- throw new IgniteException("Failed to create object input stream.", e);
- }
- }
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/27f6c586/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerPooledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerPooledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerPooledSelfTest.java
new file mode 100644
index 0000000..a883270
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerPooledSelfTest.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.marshaller.optimized;
+
+import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+
+/**
+ * Optimized marshaller self test.
+ */
+@GridCommonTest(group = "Marshaller")
+public class OptimizedMarshallerPooledSelfTest extends OptimizedMarshallerSelfTest {
+ /** {@inheritDoc} */
+ @Override protected Marshaller marshaller() {
+ OptimizedMarshaller m = new OptimizedMarshaller(false);
+
+ m.setPoolSize(8);
+
+ return m;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ super.afterTestsStopped();
+
+ // Reset static registry.
+ new OptimizedMarshaller().setPoolSize(0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/27f6c586/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java
index 2aabf4f..734e199 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java
@@ -40,6 +40,7 @@ import org.apache.ignite.marshaller.DynamicProxySerializationMultiJvmSelfTest;
import org.apache.ignite.marshaller.jdk.GridJdkMarshallerSelfTest;
import org.apache.ignite.marshaller.optimized.OptimizedMarshallerEnumSelfTest;
import org.apache.ignite.marshaller.optimized.OptimizedMarshallerNodeFailoverTest;
+import org.apache.ignite.marshaller.optimized.OptimizedMarshallerPooledSelfTest;
import org.apache.ignite.marshaller.optimized.OptimizedMarshallerSelfTest;
import org.apache.ignite.marshaller.optimized.OptimizedMarshallerSerialPersistentFieldsSelfTest;
import org.apache.ignite.marshaller.optimized.OptimizedMarshallerTest;
@@ -88,6 +89,7 @@ public class IgniteBinaryBasicTestSuite extends TestSuite {
ignoredTests.add(GridDeploymentMessageCountSelfTest.class);
ignoredTests.add(DynamicProxySerializationMultiJvmSelfTest.class);
ignoredTests.add(GridHandleTableSelfTest.class);
+ ignoredTests.add(OptimizedMarshallerPooledSelfTest.class);
// TODO: check and delete if pass.
ignoredTests.add(IgniteDaemonNodeMarshallerCacheTest.class);
http://git-wip-us.apache.org/repos/asf/ignite/blob/27f6c586/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java
index ec0ec23..99cbf60 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java
@@ -24,6 +24,7 @@ import org.apache.ignite.internal.util.io.GridUnsafeDataOutputArraySizingSelfTes
import org.apache.ignite.marshaller.jdk.GridJdkMarshallerSelfTest;
import org.apache.ignite.marshaller.optimized.OptimizedMarshallerEnumSelfTest;
import org.apache.ignite.marshaller.optimized.OptimizedMarshallerNodeFailoverTest;
+import org.apache.ignite.marshaller.optimized.OptimizedMarshallerPooledSelfTest;
import org.apache.ignite.marshaller.optimized.OptimizedMarshallerSelfTest;
import org.apache.ignite.marshaller.optimized.OptimizedMarshallerSerialPersistentFieldsSelfTest;
import org.apache.ignite.marshaller.optimized.OptimizedMarshallerTest;
@@ -59,6 +60,7 @@ public class IgniteMarshallerSelfTestSuite extends TestSuite {
GridTestUtils.addTestIfNeeded(suite, OptimizedMarshallerNodeFailoverTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite, OptimizedMarshallerSerialPersistentFieldsSelfTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite, GridHandleTableSelfTest.class, ignoredTests);
+ GridTestUtils.addTestIfNeeded(suite, OptimizedMarshallerPooledSelfTest.class, ignoredTests);
return suite;
}
[23/33] ignite git commit: IGNITE-3455: Entry placed on C++ side is
not found on Java side
Posted by sb...@apache.org.
IGNITE-3455: Entry placed on C++ side is not found on Java side
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/84e83c96
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/84e83c96
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/84e83c96
Branch: refs/heads/ignite-3547
Commit: 84e83c96127a06f9d6b2ccc68d23db8f6dc089b1
Parents: 4897315
Author: Denis Magda <dm...@gridgain.com>
Authored: Mon Jul 18 15:21:46 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Mon Jul 18 15:21:46 2016 +0300
----------------------------------------------------------------------
.../ignite/internal/binary/BinaryContext.java | 6 ++-
.../binary/BinaryMarshallerSelfTest.java | 41 ++++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/84e83c96/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
----------------------------------------------------------------------
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 27e9440..d78c126 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
@@ -1127,13 +1127,17 @@ public class BinaryContext {
mapper,
serializer,
true,
- false
+ true
);
fieldsMeta = desc.fieldsMeta();
schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
descByCls.put(cls, desc);
+
+ // Registering in order to support the interoperability between Java, C++ and .Net.
+ // https://issues.apache.org/jira/browse/IGNITE-3455
+ predefinedTypes.put(id, desc);
}
metaHnd.addMeta(id, new BinaryMetadata(id, typeName, fieldsMeta, affKeyFieldName, schemas, isEnum).wrap(this));
http://git-wip-us.apache.org/repos/asf/ignite/blob/84e83c96/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
index a504650..b3058de 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
@@ -1798,6 +1798,47 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
/**
* @throws Exception If failed.
*/
+ public void testCustomTypeRegistration() throws Exception {
+ BinaryTypeConfiguration customType = new BinaryTypeConfiguration(Value.class.getName());
+
+ BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(customType));
+
+ BinaryContext ctx = binaryContext(marsh);
+
+ int typeId = ctx.typeId(Value.class.getName());
+
+ BinaryClassDescriptor descriptor = ctx.descriptorForTypeId(true, typeId, null, false);
+
+ assertEquals(Value.class, descriptor.describedClass());
+ assertEquals(true, descriptor.registered());
+ assertEquals(true, descriptor.userType());
+
+ // Custom explicit types must be registered in 'predefinedTypes' in order not to break the interoperability.
+ Field field = ctx.getClass().getDeclaredField("predefinedTypes");
+
+ field.setAccessible(true);
+
+ Map<Integer, BinaryClassDescriptor> map = (Map<Integer, BinaryClassDescriptor>)field.get(ctx);
+
+ assertTrue(map.size() > 0);
+
+ assertNotNull(map.get(typeId));
+
+ // Custom explicit types must NOT be registered in 'predefinedTypeNames'.
+ field = ctx.getClass().getDeclaredField("predefinedTypeNames");
+
+ field.setAccessible(true);
+
+ Map<String, Integer> map2 = (Map<String, Integer>)field.get(ctx);
+
+ assertTrue(map2.size() > 0);
+
+ assertNull(map2.get(ctx.userTypeName(Value.class.getName())));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
public void testFieldIdMapping() throws Exception {
BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration(Value.class.getName());
[16/33] ignite git commit: ignite-3254 - fixed
Posted by sb...@apache.org.
ignite-3254 - fixed
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4d2be722
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4d2be722
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4d2be722
Branch: refs/heads/ignite-3547
Commit: 4d2be722935da42c82310ce70db996c5752f72f6
Parents: 10224df
Author: Sergi Vladykin <se...@gmail.com>
Authored: Wed Jul 13 20:19:25 2016 +0300
Committer: Sergi Vladykin <se...@gmail.com>
Committed: Wed Jul 13 20:19:25 2016 +0300
----------------------------------------------------------------------
.../examples/IndexingBridgeMethodTest.java | 93 ++++++++++++++++++++
.../IgniteExamplesJ8SelfTestSuite.java | 2 +
.../configuration/CacheConfiguration.java | 3 +
3 files changed, 98 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/4d2be722/examples/src/test/java8/org/apache/ignite/java8/examples/IndexingBridgeMethodTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java8/org/apache/ignite/java8/examples/IndexingBridgeMethodTest.java b/examples/src/test/java8/org/apache/ignite/java8/examples/IndexingBridgeMethodTest.java
new file mode 100644
index 0000000..2837ed6
--- /dev/null
+++ b/examples/src/test/java8/org/apache/ignite/java8/examples/IndexingBridgeMethodTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.java8.examples;
+
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+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.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Test covering bridge methods changes in Java 8.
+ */
+public class IndexingBridgeMethodTest extends GridCommonAbstractTest {
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBridgeMethod() throws Exception {
+ Ignite ignite = startGrid();
+
+ CacheConfiguration<Integer, MyType> ccfg = new CacheConfiguration<>();
+
+ ccfg.setName("mytype");
+ ccfg.setIndexedTypes(Integer.class, MyType.class);
+
+ IgniteCache<Integer,MyType> c = ignite.getOrCreateCache(ccfg);
+
+ for (int i = 0; i < 100; i++)
+ c.put(i, new MyType(i));
+
+ assertEquals(100L, c.query(new SqlFieldsQuery(
+ "select count(*) from MyType")).getAll().get(0).get(0));
+ assertEquals(15, c.query(new SqlFieldsQuery(
+ "select id from MyType where _key = 15")).getAll().get(0).get(0));
+ assertEquals(25, c.query(new SqlFieldsQuery(
+ "select _key from MyType where id = 25")).getAll().get(0).get(0));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * Classes implementing this method, will have bridge method.
+ */
+ private static interface HasId<T extends Number> {
+ /**
+ * @return ID.
+ */
+ public T getId();
+ }
+
+ /**
+ *
+ */
+ private static class MyType implements HasId<Integer> {
+ /** */
+ private int id;
+
+ /**
+ * @param id Id.
+ */
+ private MyType(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return ID.
+ */
+ @QuerySqlField(index = true)
+ @Override public Integer getId() {
+ return id;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/4d2be722/examples/src/test/java8/org/apache/ignite/java8/testsuites/IgniteExamplesJ8SelfTestSuite.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java8/org/apache/ignite/java8/testsuites/IgniteExamplesJ8SelfTestSuite.java b/examples/src/test/java8/org/apache/ignite/java8/testsuites/IgniteExamplesJ8SelfTestSuite.java
index 57e48f9..949324c 100644
--- a/examples/src/test/java8/org/apache/ignite/java8/testsuites/IgniteExamplesJ8SelfTestSuite.java
+++ b/examples/src/test/java8/org/apache/ignite/java8/testsuites/IgniteExamplesJ8SelfTestSuite.java
@@ -24,6 +24,7 @@ import org.apache.ignite.java8.examples.CacheExamplesMultiNodeSelfTest;
import org.apache.ignite.java8.examples.CacheExamplesSelfTest;
import org.apache.ignite.java8.examples.EventsExamplesMultiNodeSelfTest;
import org.apache.ignite.java8.examples.EventsExamplesSelfTest;
+import org.apache.ignite.java8.examples.IndexingBridgeMethodTest;
import org.apache.ignite.java8.examples.MessagingExamplesSelfTest;
import org.apache.ignite.testframework.GridTestUtils;
@@ -45,6 +46,7 @@ public class IgniteExamplesJ8SelfTestSuite extends TestSuite {
TestSuite suite = new TestSuite("Ignite Examples Test Suite");
+ suite.addTest(new TestSuite(IndexingBridgeMethodTest.class));
suite.addTest(new TestSuite(CacheExamplesSelfTest.class));
suite.addTest(new TestSuite(BasicExamplesSelfTest.class));
// suite.addTest(new TestSuite(ContinuationExamplesSelfTest.class));
http://git-wip-us.apache.org/repos/asf/ignite/blob/4d2be722/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.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 07542de..3276627 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
@@ -2292,6 +2292,9 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
}
for (Method mtd : c.getDeclaredMethods()) {
+ if (mtd.isBridge())
+ continue;
+
QuerySqlField sqlAnn = mtd.getAnnotation(QuerySqlField.class);
QueryTextField txtAnn = mtd.getAnnotation(QueryTextField.class);
[32/33] ignite git commit: IGNITE-3446 Visor CMD: improve usability
for batch mode.
Posted by sb...@apache.org.
IGNITE-3446 Visor CMD: improve usability for batch mode.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/71ef6527
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/71ef6527
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/71ef6527
Branch: refs/heads/ignite-3547
Commit: 71ef6527f1b90cf795072174378d9c401714df96
Parents: aedfde6
Author: Andrey Novikov <an...@apache.org>
Authored: Fri Jul 22 18:03:50 2016 +0700
Committer: Andrey Novikov <an...@apache.org>
Committed: Fri Jul 22 18:03:50 2016 +0700
----------------------------------------------------------------------
.../ignite/visor/commands/cache/VisorCacheStopCommand.scala | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ef6527/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala
index 1b55505..22fb89d 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala
@@ -19,7 +19,6 @@ package org.apache.ignite.visor.commands.cache
import org.apache.ignite.cluster.{ClusterGroupEmptyException, ClusterNode}
import org.apache.ignite.visor.visor._
-
import org.apache.ignite.internal.visor.cache.VisorCacheStopTask
import org.apache.ignite.internal.visor.util.VisorTaskUtils._
@@ -102,7 +101,9 @@ class VisorCacheStopCommand {
return
}
- ask(s"Are you sure you want to stop cache: ${escapeName(cacheName)}? (y/n) [n]: ", "n") match {
+ val dflt = if (batchMode) "y" else "n"
+
+ ask(s"Are you sure you want to stop cache: ${escapeName(cacheName)}? (y/n) [$dflt]: ", dflt) match {
case "y" | "Y" =>
try {
executeRandom(grp, classOf[VisorCacheStopTask], cacheName)
[14/33] ignite git commit: IGNITE-3440: Ignite Services:
ServiceTopologyCallable is executed before system cache is started
Posted by sb...@apache.org.
IGNITE-3440: Ignite Services: ServiceTopologyCallable is executed before system cache is started
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/06b24a9b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/06b24a9b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/06b24a9b
Branch: refs/heads/ignite-3547
Commit: 06b24a9b3952598604e02d80d1ed76a52d85e743
Parents: 89d64e7
Author: Denis Magda <dm...@gridgain.com>
Authored: Wed Jul 13 14:19:51 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Wed Jul 13 14:19:51 2016 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheProcessor.java | 2 +
.../service/GridServiceProcessor.java | 70 +++++++++++++++++++-
2 files changed, 71 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/06b24a9b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 414a915..6484d4d 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
@@ -797,6 +797,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
if (!ctx.config().isDaemon())
ctx.cacheObjects().onUtilityCacheStarted();
+ ctx.service().onUtilityCacheStarted();
+
// Wait for caches in SYNC preload mode.
for (CacheConfiguration cfg : ctx.config().getCacheConfiguration()) {
GridCacheAdapter cache = caches.get(maskNull(cfg.getName()));
http://git-wip-us.apache.org/repos/asf/ignite/blob/06b24a9b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
----------------------------------------------------------------------
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 53eaeb5..b418ba2 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
@@ -38,8 +38,10 @@ import javax.cache.event.CacheEntryEvent;
import javax.cache.event.CacheEntryUpdatedListener;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
import org.apache.ignite.cluster.ClusterGroup;
import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJobContext;
import org.apache.ignite.configuration.DeploymentMode;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.events.DiscoveryEvent;
@@ -81,6 +83,8 @@ import org.apache.ignite.lang.IgniteProductVersion;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.resources.JobContextResource;
+import org.apache.ignite.resources.LoggerResource;
import org.apache.ignite.services.Service;
import org.apache.ignite.services.ServiceConfiguration;
import org.apache.ignite.services.ServiceDescriptor;
@@ -125,6 +129,9 @@ public class GridServiceProcessor extends GridProcessorAdapter {
/** Deployment futures. */
private final ConcurrentMap<String, GridFutureAdapter<?>> undepFuts = new ConcurrentHashMap8<>();
+ /** Pending compute job contexts that waiting for utility cache initialization. */
+ private final List<ComputeJobContext> pendingJobCtxs = new ArrayList<>(0);
+
/** Deployment executor service. */
private final ExecutorService depExe;
@@ -1304,6 +1311,23 @@ public class GridServiceProcessor extends GridProcessorAdapter {
}
/**
+ * Called right after utility cache is started and ready for the usage.
+ */
+ public void onUtilityCacheStarted() {
+ synchronized (pendingJobCtxs) {
+ if (pendingJobCtxs.size() == 0)
+ return;
+
+ Iterator<ComputeJobContext> iter = pendingJobCtxs.iterator();
+
+ while (iter.hasNext()) {
+ iter.next().callcc();
+ iter.remove();
+ }
+ }
+ }
+
+ /**
* Service deployment listener.
*/
@SuppressWarnings("unchecked")
@@ -1783,9 +1807,20 @@ public class GridServiceProcessor extends GridProcessorAdapter {
private final String svcName;
/** */
+ private boolean waitedCacheInit;
+
+ /** */
@IgniteInstanceResource
private IgniteEx ignite;
+ /** */
+ @JobContextResource
+ private ComputeJobContext jCtx;
+
+ /** */
+ @LoggerResource
+ private IgniteLogger log;
+
/**
* @param svcName Service name.
*/
@@ -1795,7 +1830,40 @@ public class GridServiceProcessor extends GridProcessorAdapter {
/** {@inheritDoc} */
@Override public Map<UUID, Integer> call() throws Exception {
- return serviceTopology(ignite.context().cache().utilityCache(), svcName);
+ IgniteInternalCache<Object, Object> cache = ignite.context().cache().utilityCache();
+
+ if (cache == null) {
+ List<ComputeJobContext> pendingCtxs = ignite.context().service().pendingJobCtxs;
+
+ synchronized (pendingCtxs) {
+ // Double check cache reference after lock acqusition.
+ cache = ignite.context().cache().utilityCache();
+
+ if (cache == null) {
+ if (!waitedCacheInit) {
+ log.debug("Utility cache hasn't been initialized yet. Waiting.");
+
+ // waiting for a minute for cache initialization.
+ jCtx.holdcc(60 * 1000);
+
+ pendingCtxs.add(jCtx);
+
+ waitedCacheInit = true;
+
+ return null;
+ }
+ else {
+ log.error("Failed to gather service topology. Utility " +
+ "cache initialization is stuck.");
+
+ throw new IgniteCheckedException("Failed to gather service topology. Utility " +
+ "cache initialization is stuck.");
+ }
+ }
+ }
+ }
+
+ return serviceTopology(cache, svcName);
}
}