You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vk...@apache.org on 2016/07/19 01:27:10 UTC
[01/21] ignite git commit: Revert IGNITE-2949 due to broken
compatibility
Repository: ignite
Updated Branches:
refs/heads/ignite-3470 [created] 075860fe3
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-3470
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>
[06/21] ignite git commit: ignite-1088 Implemented store for multi
jvm tests (cherry picked from commit f91b699)
Posted by vk...@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-3470
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);
[09/21] ignite git commit: CacheKeepBinaryIterationSwapEnabledTest
fix.
Posted by vk...@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-3470
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());
}
}
[12/21] ignite git commit: ignite-3413 Use cache node filter for
continuous query registration
Posted by vk...@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-3470
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);
[15/21] ignite git commit: ignite-3254 - fixed
Posted by vk...@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-3470
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);
[11/21] ignite git commit: ignite-3392 Added test.
Posted by vk...@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-3470
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.
+ }
+ }
+}
[14/21] ignite git commit: IGNITE-3055: IgniteDataStreamer can't be
timed out
Posted by vk...@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-3470
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);
[02/21] ignite git commit: Merge remote-tracking branch
'community/gridgain-7.5.29' into gridgain-7.5.29
Posted by vk...@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-3470
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(-)
----------------------------------------------------------------------
[07/21] ignite git commit: IGNITE-3227 - Added method to get
partition size
Posted by vk...@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-3470
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
+}
[16/21] ignite git commit: Fixed NPE in OptimizedMarshaller when
streams pool is used
Posted by vk...@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-3470
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;
}
[03/21] ignite git commit: Backported test fixes.
Posted by vk...@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-3470
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());
}
/**
[21/21] ignite git commit: IGNITE-3470 - Support EXPIRED events in
continuous queries
Posted by vk...@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/075860fe
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/075860fe
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/075860fe
Branch: refs/heads/ignite-3470
Commit: 075860fe37112d9b42341365e4a298d1ac0e2715
Parents: 84e83c9
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Mon Jul 18 18:26:16 2016 -0700
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Mon Jul 18 18:26:16 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/075860fe/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/075860fe/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/075860fe/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/075860fe/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> {
[20/21] ignite git commit: IGNITE-3455: Entry placed on C++ side is
not found on Java side
Posted by vk...@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-3470
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());
[13/21] ignite git commit: IGNITE-3440: Ignite Services:
ServiceTopologyCallable is executed before system cache is started
Posted by vk...@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-3470
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);
}
}
[18/21] ignite git commit: Merge branch 'gridgain-7.5.30' of
https://github.com/gridgain/apache-ignite into gridgain-7.5.30
Posted by vk...@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-3470
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(-)
----------------------------------------------------------------------
[19/21] ignite git commit: IGNITE-3446 Visor CMD: improve usability
for batch mode.
Posted by vk...@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-3470
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
[10/21] ignite git commit: ignite-3239 Fix of java.io.IOException:
Resource deadlock avoided
Posted by vk...@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-3470
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();
[05/21] ignite git commit: Backported test fixes.
Posted by vk...@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-3470
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;
}
}
[08/21] ignite git commit: Clarified READ_COMMITTED behavior in cases
when a value is updated inside of a transaction
Posted by vk...@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-3470
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
[17/21] ignite git commit: IgniteDataStreamer: fixed JavaDoc
Posted by vk...@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-3470
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;
[04/21] ignite git commit: Backported test fixes.
Posted by vk...@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-3470
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();
- }
- }
}