You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/05/26 06:30:31 UTC
[01/17] ignite git commit: ignite-2528 Removed cache blocking
operations from kernal write lock.
Repository: ignite
Updated Branches:
refs/heads/ignite-3116 [created] a9fa8b3d1
ignite-2528 Removed cache blocking operations from kernal write lock.
This closes #730
(cherry picked from commit f83a5f7)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/997824d5
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/997824d5
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/997824d5
Branch: refs/heads/ignite-3116
Commit: 997824d5e408b4a4a36cc0a594dd1d82aa03917d
Parents: 27564aa
Author: sboikov <sb...@gridgain.com>
Authored: Mon May 23 09:52:43 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon May 23 10:03:13 2016 +0300
----------------------------------------------------------------------
.../apache/ignite/internal/IgniteKernal.java | 11 +--
...eConcurrentEntryProcessorAccessStopTest.java | 82 ++++++++++++++++++++
.../testsuites/IgniteKernalSelfTestSuite.java | 2 +
3 files changed, 90 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/997824d5/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 194d12b..d1f3ef5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -1854,11 +1854,6 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
Thread.currentThread().interrupt();
try {
- GridCacheProcessor cache = ctx.cache();
-
- if (cache != null)
- cache.blockGateways();
-
assert gw.getState() == STARTED || gw.getState() == STARTING || gw.getState() == DISCONNECTED;
// No more kernal calls from this point on.
@@ -1873,6 +1868,12 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
gw.writeUnlock();
}
+ // Stopping cache operations.
+ GridCacheProcessor cache = ctx.cache();
+
+ if (cache != null)
+ cache.blockGateways();
+
// Unregister MBeans.
if (!(
unregisterMBean(pubExecSvcMBean) &
http://git-wip-us.apache.org/repos/asf/ignite/blob/997824d5/modules/core/src/test/java/org/apache/ignite/internal/IgniteConcurrentEntryProcessorAccessStopTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteConcurrentEntryProcessorAccessStopTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteConcurrentEntryProcessorAccessStopTest.java
new file mode 100644
index 0000000..864c9dc
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteConcurrentEntryProcessorAccessStopTest.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Tests node stop while it is being accessed from EntryProcessor.
+ */
+public class IgniteConcurrentEntryProcessorAccessStopTest extends GridCommonAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGrid();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /**
+ * Tests concurrent instance shutdown.
+ *
+ * @throws Exception If failed.
+ */
+ public void testConcurrentAccess() throws Exception {
+ CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
+
+ Ignite ignite = grid();
+
+ final IgniteCache<Object, Object> dfltCache = ignite.getOrCreateCache(ccfg);
+
+ dfltCache.put("1", "1");
+
+ Thread invoker = new Thread(new Runnable() {
+ @Override public void run() {
+ dfltCache.invoke("1", new EntryProcessor<Object, Object, Object>() {
+ @Override public Object process(MutableEntry<Object, Object> e, Object... args) {
+ int i = 100_000;
+
+ while (i-- >= 0)
+ grid().cluster().nodes();
+
+ e.remove();
+
+ return null;
+ }
+ });
+ }
+ });
+
+ invoker.setName("ConcurrentEntryProcessorActionThread");
+
+ invoker.start();
+
+ stopGrid();
+
+ invoker.join();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/997824d5/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java
index 28974ea..cfb9f1c 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java
@@ -26,6 +26,7 @@ import org.apache.ignite.internal.GridDiscoverySelfTest;
import org.apache.ignite.internal.GridFailedInputParametersSelfTest;
import org.apache.ignite.internal.GridHomePathSelfTest;
import org.apache.ignite.internal.GridKernalConcurrentAccessStopSelfTest;
+import org.apache.ignite.internal.IgniteConcurrentEntryProcessorAccessStopTest;
import org.apache.ignite.internal.GridListenActorSelfTest;
import org.apache.ignite.internal.GridLocalEventListenerSelfTest;
import org.apache.ignite.internal.GridNodeFilterSelfTest;
@@ -117,6 +118,7 @@ public class IgniteKernalSelfTestSuite extends TestSuite {
suite.addTestSuite(GridListenActorSelfTest.class);
suite.addTestSuite(GridNodeLocalSelfTest.class);
suite.addTestSuite(GridKernalConcurrentAccessStopSelfTest.class);
+ suite.addTestSuite(IgniteConcurrentEntryProcessorAccessStopTest.class);
suite.addTestSuite(GridUpdateNotifierSelfTest.class);
suite.addTestSuite(IgniteUpdateNotifierPerClusterSettingSelfTest.class);
suite.addTestSuite(GridLocalEventListenerSelfTest.class);
[07/17] ignite git commit: IGNITE-2865 Continuous query event passed
to filter should be immutable for users. This closes #744. (cherry picked
from commit 046657b)
Posted by sb...@apache.org.
IGNITE-2865 Continuous query event passed to filter should be immutable for users. This closes #744.
(cherry picked from commit 046657b)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/85790249
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/85790249
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/85790249
Branch: refs/heads/ignite-3116
Commit: 857902494a75219ae0d7b91fb40f75bdc72a5320
Parents: 9a48b4b
Author: sboikov <sb...@gridgain.com>
Authored: Tue May 24 14:31:43 2016 +0300
Committer: tledkov-gridgain <tl...@gridgain.com>
Committed: Tue May 24 14:45:02 2016 +0300
----------------------------------------------------------------------
.../ignite/codegen/MessageCodeGenerator.java | 133 ++++++------
.../ignite/internal/GridCodegenConverter.java | 56 +++++
.../continuous/CacheContinuousQueryEntry.java | 24 ++-
...eCacheContinuousQueryImmutableEntryTest.java | 205 +++++++++++++++++++
.../IgniteCacheQuerySelfTestSuite3.java | 2 +
5 files changed, 351 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/85790249/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java b/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
index 587ad06..a6ae0da 100644
--- a/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
+++ b/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
@@ -39,6 +39,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
+import org.apache.ignite.internal.GridCodegenConverter;
import org.apache.ignite.internal.GridDirectCollection;
import org.apache.ignite.internal.GridDirectMap;
import org.apache.ignite.internal.GridDirectTransient;
@@ -544,8 +545,14 @@ public class MessageCodeGenerator {
indent++;
- returnFalseIfWriteFailed(field.getType(), field.getName(), colAnn != null ? colAnn.value() : null,
- mapAnn != null ? mapAnn.keyType() : null, mapAnn != null ? mapAnn.valueType() : null, false);
+ GridCodegenConverter fldPreproc = field.getAnnotation(GridCodegenConverter.class);
+
+ String getExp = (fldPreproc != null && !fldPreproc.get().isEmpty())? fldPreproc.get(): field.getName();
+ Class<?> writeType = (fldPreproc != null && !fldPreproc.type().equals(GridCodegenConverter.Default.class))?
+ fldPreproc.type(): field.getType();
+
+ returnFalseIfWriteFailed(writeType, field.getName(), colAnn != null ? colAnn.value() : null,
+ mapAnn != null ? mapAnn.keyType() : null, mapAnn != null ? mapAnn.valueType() : null, false, getExp);
write.add(EMPTY);
write.add(builder().a("writer.incrementState();").toString());
@@ -569,8 +576,13 @@ public class MessageCodeGenerator {
indent++;
- returnFalseIfReadFailed(field.getType(), field.getName(), colAnn != null ? colAnn.value() : null,
- mapAnn != null ? mapAnn.keyType() : null, mapAnn != null ? mapAnn.valueType() : null);
+ GridCodegenConverter fldPreproc = field.getAnnotation(GridCodegenConverter.class);
+ String setExp = (fldPreproc != null && !fldPreproc.get().isEmpty())? fldPreproc.set(): "";
+ Class<?> writeType = (fldPreproc != null && !fldPreproc.type().equals(GridCodegenConverter.Default.class))?
+ fldPreproc.type(): field.getType();
+
+ returnFalseIfReadFailed(writeType, field.getName(), colAnn != null ? colAnn.value() : null,
+ mapAnn != null ? mapAnn.keyType() : null, mapAnn != null ? mapAnn.valueType() : null, setExp);
read.add(EMPTY);
read.add(builder().a("reader.incrementState();").toString());
@@ -588,74 +600,74 @@ public class MessageCodeGenerator {
* @param raw Raw write flag.
*/
private void returnFalseIfWriteFailed(Class<?> type, String name, @Nullable Class<?> colItemType,
- @Nullable Class<?> mapKeyType, @Nullable Class<?> mapValType, boolean raw) {
+ @Nullable Class<?> mapKeyType, @Nullable Class<?> mapValType, boolean raw, String getExpr) {
assert type != null;
assert name != null;
String field = raw ? "null" : '"' + name + '"';
if (type == byte.class)
- returnFalseIfFailed(write, "writer.writeByte", field, name);
+ returnFalseIfFailed(write, "writer.writeByte", field, getExpr);
else if (type == short.class)
- returnFalseIfFailed(write, "writer.writeShort", field, name);
+ returnFalseIfFailed(write, "writer.writeShort", field, getExpr);
else if (type == int.class)
- returnFalseIfFailed(write, "writer.writeInt", field, name);
+ returnFalseIfFailed(write, "writer.writeInt", field, getExpr);
else if (type == long.class)
- returnFalseIfFailed(write, "writer.writeLong", field, name);
+ returnFalseIfFailed(write, "writer.writeLong", field, getExpr);
else if (type == float.class)
- returnFalseIfFailed(write, "writer.writeFloat", field, name);
+ returnFalseIfFailed(write, "writer.writeFloat", field, getExpr);
else if (type == double.class)
- returnFalseIfFailed(write, "writer.writeDouble", field, name);
+ returnFalseIfFailed(write, "writer.writeDouble", field, getExpr);
else if (type == char.class)
- returnFalseIfFailed(write, "writer.writeChar", field, name);
+ returnFalseIfFailed(write, "writer.writeChar", field, getExpr);
else if (type == boolean.class)
- returnFalseIfFailed(write, "writer.writeBoolean", field, name);
+ returnFalseIfFailed(write, "writer.writeBoolean", field, getExpr);
else if (type == byte[].class)
- returnFalseIfFailed(write, "writer.writeByteArray", field, name);
+ returnFalseIfFailed(write, "writer.writeByteArray", field, getExpr);
else if (type == short[].class)
- returnFalseIfFailed(write, "writer.writeShortArray", field, name);
+ returnFalseIfFailed(write, "writer.writeShortArray", field, getExpr);
else if (type == int[].class)
- returnFalseIfFailed(write, "writer.writeIntArray", field, name);
+ returnFalseIfFailed(write, "writer.writeIntArray", field, getExpr);
else if (type == long[].class)
- returnFalseIfFailed(write, "writer.writeLongArray", field, name);
+ returnFalseIfFailed(write, "writer.writeLongArray", field, getExpr);
else if (type == float[].class)
- returnFalseIfFailed(write, "writer.writeFloatArray", field, name);
+ returnFalseIfFailed(write, "writer.writeFloatArray", field, getExpr);
else if (type == double[].class)
- returnFalseIfFailed(write, "writer.writeDoubleArray", field, name);
+ returnFalseIfFailed(write, "writer.writeDoubleArray", field, getExpr);
else if (type == char[].class)
- returnFalseIfFailed(write, "writer.writeCharArray", field, name);
+ returnFalseIfFailed(write, "writer.writeCharArray", field, getExpr);
else if (type == boolean[].class)
- returnFalseIfFailed(write, "writer.writeBooleanArray", field, name);
+ returnFalseIfFailed(write, "writer.writeBooleanArray", field, getExpr);
else if (type == String.class)
- returnFalseIfFailed(write, "writer.writeString", field, name);
+ returnFalseIfFailed(write, "writer.writeString", field, getExpr);
else if (type == BitSet.class)
- returnFalseIfFailed(write, "writer.writeBitSet", field, name);
+ returnFalseIfFailed(write, "writer.writeBitSet", field, getExpr);
else if (type == UUID.class)
- returnFalseIfFailed(write, "writer.writeUuid", field, name);
+ returnFalseIfFailed(write, "writer.writeUuid", field, getExpr);
else if (type == IgniteUuid.class)
- returnFalseIfFailed(write, "writer.writeIgniteUuid", field, name);
+ returnFalseIfFailed(write, "writer.writeIgniteUuid", field, getExpr);
else if (type.isEnum()) {
- String arg = name + " != null ? (byte)" + name + ".ordinal() : -1";
+ String arg = getExpr + " != null ? (byte)" + getExpr + ".ordinal() : -1";
returnFalseIfFailed(write, "writer.writeByte", field, arg);
}
else if (BASE_CLS.isAssignableFrom(type))
- returnFalseIfFailed(write, "writer.writeMessage", field, name);
+ returnFalseIfFailed(write, "writer.writeMessage", field, getExpr);
else if (type.isArray()) {
- returnFalseIfFailed(write, "writer.writeObjectArray", field, name,
+ returnFalseIfFailed(write, "writer.writeObjectArray", field, getExpr,
"MessageCollectionItemType." + typeEnum(type.getComponentType()));
}
else if (Collection.class.isAssignableFrom(type) && !Set.class.isAssignableFrom(type)) {
assert colItemType != null;
- returnFalseIfFailed(write, "writer.writeCollection", field, name,
+ returnFalseIfFailed(write, "writer.writeCollection", field, getExpr,
"MessageCollectionItemType." + typeEnum(colItemType));
}
else if (Map.class.isAssignableFrom(type)) {
assert mapKeyType != null;
assert mapValType != null;
- returnFalseIfFailed(write, "writer.writeMap", field, name,
+ returnFalseIfFailed(write, "writer.writeMap", field, getExpr,
"MessageCollectionItemType." + typeEnum(mapKeyType),
"MessageCollectionItemType." + typeEnum(mapValType));
}
@@ -671,75 +683,75 @@ public class MessageCodeGenerator {
* @param mapValType Map value type.
*/
private void returnFalseIfReadFailed(Class<?> type, @Nullable String name, @Nullable Class<?> colItemType,
- @Nullable Class<?> mapKeyType, @Nullable Class<?> mapValType) {
+ @Nullable Class<?> mapKeyType, @Nullable Class<?> mapValType, String setExpr) {
assert type != null;
String field = '"' + name + '"';
if (type == byte.class)
- returnFalseIfReadFailed(name, "reader.readByte", field);
+ returnFalseIfReadFailed(name, "reader.readByte", setExpr, field);
else if (type == short.class)
- returnFalseIfReadFailed(name, "reader.readShort", field);
+ returnFalseIfReadFailed(name, "reader.readShort", setExpr, field);
else if (type == int.class)
- returnFalseIfReadFailed(name, "reader.readInt", field);
+ returnFalseIfReadFailed(name, "reader.readInt", setExpr, field);
else if (type == long.class)
- returnFalseIfReadFailed(name, "reader.readLong", field);
+ returnFalseIfReadFailed(name, "reader.readLong", setExpr, field);
else if (type == float.class)
- returnFalseIfReadFailed(name, "reader.readFloat", field);
+ returnFalseIfReadFailed(name, "reader.readFloat", setExpr, field);
else if (type == double.class)
- returnFalseIfReadFailed(name, "reader.readDouble", field);
+ returnFalseIfReadFailed(name, "reader.readDouble", setExpr, field);
else if (type == char.class)
- returnFalseIfReadFailed(name, "reader.readChar", field);
+ returnFalseIfReadFailed(name, "reader.readChar", setExpr, field);
else if (type == boolean.class)
- returnFalseIfReadFailed(name, "reader.readBoolean", field);
+ returnFalseIfReadFailed(name, "reader.readBoolean", setExpr, field);
else if (type == byte[].class)
- returnFalseIfReadFailed(name, "reader.readByteArray", field);
+ returnFalseIfReadFailed(name, "reader.readByteArray", setExpr, field);
else if (type == short[].class)
- returnFalseIfReadFailed(name, "reader.readShortArray", field);
+ returnFalseIfReadFailed(name, "reader.readShortArray", setExpr, field);
else if (type == int[].class)
- returnFalseIfReadFailed(name, "reader.readIntArray", field);
+ returnFalseIfReadFailed(name, "reader.readIntArray", setExpr, field);
else if (type == long[].class)
- returnFalseIfReadFailed(name, "reader.readLongArray", field);
+ returnFalseIfReadFailed(name, "reader.readLongArray", setExpr, field);
else if (type == float[].class)
- returnFalseIfReadFailed(name, "reader.readFloatArray", field);
+ returnFalseIfReadFailed(name, "reader.readFloatArray", setExpr, field);
else if (type == double[].class)
- returnFalseIfReadFailed(name, "reader.readDoubleArray", field);
+ returnFalseIfReadFailed(name, "reader.readDoubleArray", setExpr, field);
else if (type == char[].class)
- returnFalseIfReadFailed(name, "reader.readCharArray", field);
+ returnFalseIfReadFailed(name, "reader.readCharArray", setExpr, field);
else if (type == boolean[].class)
- returnFalseIfReadFailed(name, "reader.readBooleanArray", field);
+ returnFalseIfReadFailed(name, "reader.readBooleanArray", setExpr, field);
else if (type == String.class)
- returnFalseIfReadFailed(name, "reader.readString", field);
+ returnFalseIfReadFailed(name, "reader.readString", setExpr, field);
else if (type == BitSet.class)
- returnFalseIfReadFailed(name, "reader.readBitSet", field);
+ returnFalseIfReadFailed(name, "reader.readBitSet", setExpr, field);
else if (type == UUID.class)
- returnFalseIfReadFailed(name, "reader.readUuid", field);
+ returnFalseIfReadFailed(name, "reader.readUuid", setExpr, field);
else if (type == IgniteUuid.class)
- returnFalseIfReadFailed(name, "reader.readIgniteUuid", field);
+ returnFalseIfReadFailed(name, "reader.readIgniteUuid", setExpr, field);
else if (type.isEnum()) {
String loc = name + "Ord";
read.add(builder().a("byte ").a(loc).a(";").toString());
read.add(EMPTY);
- returnFalseIfReadFailed(loc, "reader.readByte", field);
+ returnFalseIfReadFailed(loc, "reader.readByte", setExpr, field);
read.add(EMPTY);
read.add(builder().a(name).a(" = ").a(type.getSimpleName()).a(".fromOrdinal(").a(loc).a(");").toString());
}
else if (BASE_CLS.isAssignableFrom(type))
- returnFalseIfReadFailed(name, "reader.readMessage", field);
+ returnFalseIfReadFailed(name, "reader.readMessage", setExpr, field);
else if (type.isArray()) {
Class<?> compType = type.getComponentType();
- returnFalseIfReadFailed(name, "reader.readObjectArray", field,
+ returnFalseIfReadFailed(name, "reader.readObjectArray", field, setExpr,
"MessageCollectionItemType." + typeEnum(compType),
compType.getSimpleName() + ".class");
}
else if (Collection.class.isAssignableFrom(type) && !Set.class.isAssignableFrom(type)) {
assert colItemType != null;
- returnFalseIfReadFailed(name, "reader.readCollection", field,
+ returnFalseIfReadFailed(name, "reader.readCollection", field, setExpr,
"MessageCollectionItemType." + typeEnum(colItemType));
}
else if (Map.class.isAssignableFrom(type)) {
@@ -748,7 +760,7 @@ public class MessageCodeGenerator {
boolean linked = type.equals(LinkedHashMap.class);
- returnFalseIfReadFailed(name, "reader.readMap", field,
+ returnFalseIfReadFailed(name, "reader.readMap", field, setExpr,
"MessageCollectionItemType." + typeEnum(mapKeyType),
"MessageCollectionItemType." + typeEnum(mapValType),
linked ? "true" : "false");
@@ -762,7 +774,7 @@ public class MessageCodeGenerator {
* @param mtd Method name.
* @param args Method arguments.
*/
- private void returnFalseIfReadFailed(String var, String mtd, @Nullable String... args) {
+ private void returnFalseIfReadFailed(String var, String mtd, String setConverter, @Nullable String... args) {
assert mtd != null;
String argsStr = "";
@@ -774,7 +786,12 @@ public class MessageCodeGenerator {
argsStr = argsStr.substring(0, argsStr.length() - 2);
}
- read.add(builder().a(var).a(" = ").a(mtd).a("(").a(argsStr).a(");").toString());
+ if (setConverter.isEmpty())
+ read.add(builder().a(var).a(" = ").a(mtd).a("(").a(argsStr).a(");").toString());
+ else {
+ read.add(builder().a(var).a(" = ").a(setConverter
+ .replace("$val$", new SB().a(mtd).a("(").a(argsStr).a(")").toString())).a(";").toString());
+ }
read.add(EMPTY);
read.add(builder().a("if (!reader.isLastRead())").toString());
http://git-wip-us.apache.org/repos/asf/ignite/blob/85790249/modules/core/src/main/java/org/apache/ignite/internal/GridCodegenConverter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridCodegenConverter.java b/modules/core/src/main/java/org/apache/ignite/internal/GridCodegenConverter.java
new file mode 100644
index 0000000..7baccda
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridCodegenConverter.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotates fields that required custom reading / writing.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface GridCodegenConverter {
+ /**
+ * Converter code. Replace original field value by converted.
+ *
+ * @return Code to get field value.
+ */
+ String get() default "";
+
+ /**
+ * Converter code. A raw read value is available at $val$ placeholder
+ *
+ * @return Code to set field value.
+ */
+ String set() default "";
+
+ /**
+ * @return Result type. Use this type to read / write the converted value.
+ */
+ Class<?> type() default Default.class;
+
+ /**
+ * Used as the default value for converter type
+ */
+ class Default {
+ // No-op.
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/85790249/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java
index d105271..63dc4cb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.cache.query.continuous;
import java.nio.ByteBuffer;
import javax.cache.event.EventType;
import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridCodegenConverter;
import org.apache.ignite.internal.GridDirectTransient;
import org.apache.ignite.internal.managers.deployment.GridDeploymentInfo;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
@@ -61,18 +62,26 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
}
/** */
+ @GridCodegenConverter(
+ type = byte.class,
+ get = "evtType != null ? (byte)evtType.ordinal() : -1",
+ set = "eventTypeFromOrdinal($val$)"
+ )
private EventType evtType;
/** Key. */
@GridToStringInclude
+ @GridCodegenConverter(get = "isFiltered() ? null : key")
private KeyCacheObject key;
/** New value. */
@GridToStringInclude
+ @GridCodegenConverter(get = "isFiltered() ? null : newVal")
private CacheObject newVal;
/** Old value. */
@GridToStringInclude
+ @GridCodegenConverter(get = "isFiltered() ? null : oldVal")
private CacheObject oldVal;
/** Cache name. */
@@ -187,9 +196,6 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
*/
void markFiltered() {
flags |= FILTERED_ENTRY;
- newVal = null;
- oldVal = null;
- key = null;
depInfo = null;
}
@@ -345,19 +351,19 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
writer.incrementState();
case 5:
- if (!writer.writeMessage("key", key))
+ if (!writer.writeMessage("key", isFiltered() ? null : key))
return false;
writer.incrementState();
case 6:
- if (!writer.writeMessage("newVal", newVal))
+ if (!writer.writeMessage("newVal", isFiltered() ? null : newVal))
return false;
writer.incrementState();
case 7:
- if (!writer.writeMessage("oldVal", oldVal))
+ if (!writer.writeMessage("oldVal", isFiltered() ? null : oldVal))
return false;
writer.incrementState();
@@ -402,15 +408,11 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
reader.incrementState();
case 1:
- byte evtTypeOrd;
-
- evtTypeOrd = reader.readByte("evtType");
+ evtType = eventTypeFromOrdinal(reader.readByte("evtType"));
if (!reader.isLastRead())
return false;
- evtType = eventTypeFromOrdinal(evtTypeOrd);
-
reader.incrementState();
case 2:
http://git-wip-us.apache.org/repos/asf/ignite/blob/85790249/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java
new file mode 100644
index 0000000..66d727c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.query.continuous;
+
+import java.io.Serializable;
+import java.nio.ByteBuffer;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import javax.cache.configuration.Factory;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryEventFilter;
+import javax.cache.event.CacheEntryUpdatedListener;
+import javax.cache.event.EventType;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.direct.DirectMessageReader;
+import org.apache.ignite.internal.direct.DirectMessageWriter;
+import org.apache.ignite.internal.managers.communication.GridIoMessageFactory;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
+import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
+import org.apache.ignite.internal.util.GridLongList;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class IgniteCacheContinuousQueryImmutableEntryTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /** Keys count. */
+ private static final int KEYS_COUNT = 10;
+
+ /** Grid count. */
+ private static final int GRID_COUNT = 3;
+
+ /** Events. */
+ private static final ConcurrentLinkedQueue<CacheEntryEvent<?, ?>> events = new ConcurrentLinkedQueue<>();
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ CacheConfiguration ccfg = new CacheConfiguration();
+ ccfg.setCacheMode(PARTITIONED);
+ ccfg.setAtomicityMode(ATOMIC);
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+ cfg.setCacheConfiguration(ccfg);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ events.clear();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testEventAvailabilityScope() throws Exception {
+ startGrids(GRID_COUNT);
+
+ final CacheEventListener lsnr = new CacheEventListener();
+
+ ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
+ qry.setLocalListener(lsnr);
+ qry.setRemoteFilterFactory(new FilterFactory());
+
+ Object keys[] = new Object[GRID_COUNT];
+
+ // Add initial values.
+ for (int i = 0; i < GRID_COUNT; ++i) {
+ keys[i] = primaryKey(grid(i).cache(null));
+
+ grid(0).cache(null).put(keys[i], -1);
+ }
+
+ try (QueryCursor<?> cur = grid(0).cache(null).query(qry)) {
+ // Replace values on the keys.
+ for (int i = 0; i < KEYS_COUNT; i++) {
+ log.info("Put key: " + i);
+
+ grid(i % GRID_COUNT).cache(null).put(keys[i % GRID_COUNT], i);
+ }
+ }
+
+ assertTrue("There are not filtered events", !events.isEmpty());
+
+ for (CacheEntryEvent<?, ?> event : events) {
+ assertNotNull("Key is null", event.getKey());
+ assertNotNull("Value is null", event.getValue());
+ assertNotNull("Old value is null", event.getOldValue());
+ }
+ }
+
+ /**
+ *
+ */
+ public void testCacheContinuousQueryEntrySerialization() {
+ CacheContinuousQueryEntry e0 = new CacheContinuousQueryEntry(
+ 1,
+ EventType.UPDATED,
+ new KeyCacheObjectImpl(1, new byte[] {0, 0, 0, 1}),
+ new CacheObjectImpl(2, new byte[] {0, 0, 0, 2}),
+ new CacheObjectImpl(2, new byte[] {0, 0, 0, 3}),
+ true,
+ 1,
+ 1L,
+ new AffinityTopologyVersion(1L));
+
+ e0.filteredEvents(new GridLongList(new long[]{1L, 2L}));
+ e0.markFiltered();
+
+ ByteBuffer buf = ByteBuffer.allocate(4096);
+ DirectMessageWriter writer = new DirectMessageWriter((byte)1);
+
+ // Skip write class header.
+ writer.onHeaderWritten();
+ e0.writeTo(buf, writer);
+
+ CacheContinuousQueryEntry e1 = new CacheContinuousQueryEntry();
+ e1.readFrom(ByteBuffer.wrap(buf.array()), new DirectMessageReader(new GridIoMessageFactory(null), (byte)1));
+
+ assertEquals(e0.cacheId(), e1.cacheId());
+ assertEquals(e0.eventType(), e1.eventType());
+ assertEquals(e0.isFiltered(), e1.isFiltered());
+ assertEquals(GridLongList.asList(e0.filteredEvents()), GridLongList.asList(e1.filteredEvents()));
+ assertEquals(e0.isBackup(), e1.isBackup());
+ assertEquals(e0.isKeepBinary(), e1.isKeepBinary());
+ assertEquals(e0.partition(), e1.partition());
+ assertEquals(e0.updateCounter(), e1.updateCounter());
+
+ // Key and value shouldn't be serialized in case an event is filtered.
+ assertNull(e1.key());
+ assertNotNull(e0.key());
+ assertNull(e1.oldValue());
+ assertNotNull(e0.oldValue());
+ assertNull(e1.value());
+ assertNotNull(e0.value());
+ }
+
+ /**
+ *
+ */
+ private static class FilterFactory implements Factory<CacheEntryEventFilter<Object, Object>> {
+ /** {@inheritDoc} */
+ @Override public CacheEntryEventFilter<Object, Object> create() {
+ return new CacheEventFilter();
+ }
+ }
+
+ /**
+ *
+ */
+ private static class CacheEventFilter implements CacheEntryEventFilter<Object, Object>, Serializable {
+ /** {@inheritDoc} */
+ @Override public boolean evaluate(CacheEntryEvent<?, ?> evt) {
+ events.add(evt);
+
+ return false;
+ }
+ }
+
+ /**
+ *
+ */
+ private static class CacheEventListener implements CacheEntryUpdatedListener<Object, Object> {
+ /** {@inheritDoc} */
+ @Override public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
+ // No-op
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/85790249/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 a781fd9..416ca31 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
@@ -54,6 +54,7 @@ import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheCon
import org.apache.ignite.internal.processors.cache.query.continuous.IgniteCacheContinuousQueryClientReconnectTest;
import org.apache.ignite.internal.processors.cache.query.continuous.IgniteCacheContinuousQueryClientTest;
import org.apache.ignite.internal.processors.cache.query.continuous.IgniteCacheContinuousQueryClientTxReconnectTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.IgniteCacheContinuousQueryImmutableEntryTest;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_DISCOVERY_HISTORY_SIZE;
@@ -107,6 +108,7 @@ public class IgniteCacheQuerySelfTestSuite3 extends TestSuite {
suite.addTestSuite(CacheContinuousBatchForceServerModeAckTest.class);
suite.addTestSuite(CacheContinuousQueryExecuteInPrimaryTest.class);
suite.addTestSuite(CacheContinuousQueryLostPartitionTest.class);
+ suite.addTestSuite(IgniteCacheContinuousQueryImmutableEntryTest.class);
return suite;
}
[16/17] ignite git commit: Merge remote-tracking branch
'community/gridgain-7.5.23' into gridgain-7.5.23
Posted by sb...@apache.org.
Merge remote-tracking branch 'community/gridgain-7.5.23' into gridgain-7.5.23
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/fc3b1543
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/fc3b1543
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/fc3b1543
Branch: refs/heads/ignite-3116
Commit: fc3b154368e60b531f15f26ae7215987ddaef737
Parents: 65a90b3 384a74c
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Wed May 25 14:16:18 2016 +0300
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Wed May 25 14:16:18 2016 +0300
----------------------------------------------------------------------
.../main/java/org/apache/ignite/Ignition.java | 19 +-
.../org/apache/ignite/internal/IgnitionEx.java | 60 +++-
.../internal/processors/igfs/IgfsImpl.java | 60 +++-
.../ignite/internal/GridGetOrStartSelfTest.java | 132 +++++++
.../ignite/testsuites/IgniteBasicTestSuite.java | 2 +
.../org/apache/ignite/spark/IgniteContext.scala | 63 ++--
.../apache/ignite/spark/JavaIgniteContext.scala | 14 +-
.../spark/JavaEmbeddedIgniteRDDSelfTest.java | 343 ++++++++++++++++++
.../ignite/spark/JavaIgniteRDDSelfTest.java | 358 -------------------
.../spark/JavaStandaloneIgniteRDDSelfTest.java | 358 +++++++++++++++++++
.../ignite/testsuites/IgniteRDDTestSuite.java | 40 +++
.../ignite/internal/GridFactorySelfTest.java | 2 +-
12 files changed, 1037 insertions(+), 414 deletions(-)
----------------------------------------------------------------------
[14/17] ignite git commit: IGNITE-2941, IGNITE-2942 backport to 1.5.23
Posted by sb...@apache.org.
IGNITE-2941, IGNITE-2942 backport to 1.5.23
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/384a74c4
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/384a74c4
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/384a74c4
Branch: refs/heads/ignite-3116
Commit: 384a74c43a4b3f8ff7000aefb3c5f6868a0061a3
Parents: 341b842
Author: Anton Vinogradov <av...@apache.org>
Authored: Wed May 25 13:14:25 2016 +0300
Committer: Anton Vinogradov <av...@apache.org>
Committed: Wed May 25 13:14:25 2016 +0300
----------------------------------------------------------------------
.../main/java/org/apache/ignite/Ignition.java | 19 +-
.../org/apache/ignite/internal/IgnitionEx.java | 60 +++-
.../ignite/internal/GridGetOrStartSelfTest.java | 132 +++++++
.../ignite/testsuites/IgniteBasicTestSuite.java | 2 +
.../org/apache/ignite/spark/IgniteContext.scala | 63 ++--
.../apache/ignite/spark/JavaIgniteContext.scala | 14 +-
.../spark/JavaEmbeddedIgniteRDDSelfTest.java | 343 ++++++++++++++++++
.../ignite/spark/JavaIgniteRDDSelfTest.java | 358 -------------------
.../spark/JavaStandaloneIgniteRDDSelfTest.java | 358 +++++++++++++++++++
.../ignite/testsuites/IgniteRDDTestSuite.java | 40 +++
.../ignite/internal/GridFactorySelfTest.java | 2 +-
11 files changed, 992 insertions(+), 399 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/384a74c4/modules/core/src/main/java/org/apache/ignite/Ignition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignition.java b/modules/core/src/main/java/org/apache/ignite/Ignition.java
index 99ee1d9..b4c01f9 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignition.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignition.java
@@ -309,7 +309,7 @@ public class Ignition {
}
/**
- * Starts grid with given configuration. Note that this method is no-op if grid with the name
+ * Starts grid with given configuration. Note that this method will throw an exception if grid with the name
* provided in given configuration is already started.
*
* @param cfg Grid configuration. This cannot be {@code null}.
@@ -401,6 +401,23 @@ public class Ignition {
}
}
+
+ /**
+ * Gets or starts new grid instance if it hasn't been started yet.
+ *
+ * @param cfg Grid configuration. This cannot be {@code null}.
+ * @return Grid instance.
+ * @throws IgniteException If grid could not be started.
+ */
+ public static Ignite getOrStart(IgniteConfiguration cfg) throws IgniteException {
+ try {
+ return IgnitionEx.start(cfg, false);
+ }
+ catch (IgniteCheckedException e) {
+ throw U.convertException(e);
+ }
+ }
+
/**
* Loads Spring bean by its name from given Spring XML configuration file. If bean
* with such name doesn't exist, exception is thrown.
http://git-wip-us.apache.org/repos/asf/ignite/blob/384a74c4/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index e2c4751..29d7ff6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -501,7 +501,7 @@ public class IgnitionEx {
U.warn(null, "Default Spring XML file not found (is IGNITE_HOME set?): " + DFLT_CFG);
- return start0(new GridStartContext(new IgniteConfiguration(), null, springCtx)).grid();
+ return start0(new GridStartContext(new IgniteConfiguration(), null, springCtx), true).grid();
}
/**
@@ -514,11 +514,25 @@ public class IgnitionEx {
* also if named grid has already been started.
*/
public static Ignite start(IgniteConfiguration cfg) throws IgniteCheckedException {
- return start(cfg, null);
+ return start(cfg, null, true);
}
/**
- * Starts grid with given configuration. Note that this method is no-op if grid with the name
+ * Starts a grid with given configuration. If the grid is already started and failIfStarted set to TRUE
+ * an exception will be thrown.
+ *
+ * @param cfg Grid configuration. This cannot be {@code null}.
+ * failIfStarted Throw or not an exception if grid is already started.
+ * @return Started grid.
+ * @throws IgniteCheckedException If grid could not be started. This exception will be thrown
+ * also if named grid has already been started.
+ */
+ public static Ignite start(IgniteConfiguration cfg, boolean failIfStarted) throws IgniteCheckedException {
+ return start(cfg, null, failIfStarted);
+ }
+
+ /**
+ * Starts grid with given configuration. Note that this method will throw and exception if grid with the name
* provided in given configuration is already started.
*
* @param cfg Grid configuration. This cannot be {@code null}.
@@ -533,7 +547,27 @@ public class IgnitionEx {
public static Ignite start(IgniteConfiguration cfg, @Nullable GridSpringResourceContext springCtx) throws IgniteCheckedException {
A.notNull(cfg, "cfg");
- return start0(new GridStartContext(cfg, null, springCtx)).grid();
+ return start0(new GridStartContext(cfg, null, springCtx), true).grid();
+ }
+
+ /**
+ * Starts grid with given configuration. If the grid is already started and failIfStarted set to TRUE
+ * an exception will be thrown.
+ *
+ * @param cfg Grid configuration. This cannot be {@code null}.
+ * @param springCtx Optional Spring application context, possibly {@code null}.
+ * Spring bean definitions for bean injection are taken from this context.
+ * If provided, this context can be injected into grid tasks and grid jobs using
+ * {@link SpringApplicationContextResource @SpringApplicationContextResource} annotation.
+ * @param failIfStarted Throw or not an exception if grid is already started.
+ * @return Started grid.
+ * @throws IgniteCheckedException If grid could not be started. This exception will be thrown
+ * also if named grid has already been started.
+ */
+ public static Ignite start(IgniteConfiguration cfg, @Nullable GridSpringResourceContext springCtx, boolean failIfStarted) throws IgniteCheckedException {
+ A.notNull(cfg, "cfg");
+
+ return start0(new GridStartContext(cfg, null, springCtx), failIfStarted).grid();
}
/**
@@ -929,7 +963,7 @@ public class IgnitionEx {
// Use either user defined context or our one.
IgniteNamedInstance grid = start0(
- new GridStartContext(cfg, springCfgUrl, springCtx == null ? cfgMap.get2() : springCtx));
+ new GridStartContext(cfg, springCfgUrl, springCtx == null ? cfgMap.get2() : springCtx), true);
// Add it if it was not stopped during startup.
if (grid != null)
@@ -960,10 +994,11 @@ public class IgnitionEx {
* Starts grid with given configuration.
*
* @param startCtx Start context.
+ * @param failIfStarted Throw or not an exception if grid is already started.
* @return Started grid.
* @throws IgniteCheckedException If grid could not be started.
*/
- private static IgniteNamedInstance start0(GridStartContext startCtx) throws IgniteCheckedException {
+ private static IgniteNamedInstance start0(GridStartContext startCtx, boolean failIfStarted ) throws IgniteCheckedException {
assert startCtx != null;
String name = startCtx.config().getGridName();
@@ -986,12 +1021,15 @@ public class IgnitionEx {
}
}
- if (old != null) {
- if (name == null)
- throw new IgniteCheckedException("Default grid instance has already been started.");
+ if (old != null)
+ if (failIfStarted) {
+ if (name == null)
+ throw new IgniteCheckedException("Default Ignite instance has already been started.");
+ else
+ throw new IgniteCheckedException("Ignite instance with this name has already been started: " + name);
+ }
else
- throw new IgniteCheckedException("Ignite instance with this name has already been started: " + name);
- }
+ return old;
if (startCtx.config().getWarmupClosure() != null)
startCtx.config().getWarmupClosure().apply(startCtx.config());
http://git-wip-us.apache.org/repos/asf/ignite/blob/384a74c4/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
new file mode 100644
index 0000000..211d413
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+
+/**
+ * The GridGetOrStartSelfTest tests get or start semantics.
+ */
+
+@GridCommonTest(group = "Kernal Self")
+public class GridGetOrStartSelfTest extends GridCommonAbstractTest {
+ /** Concurrency. */
+ public static final int CONCURRENCY = 10;
+
+ /**
+ * Default constructor.
+ */
+ public GridGetOrStartSelfTest() {
+ super(false);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * Tests default grid
+ */
+ public void testDefaultGridGetOrStart() throws Exception {
+ IgniteConfiguration cfg = getConfiguration(null);
+
+ try (Ignite ignite = Ignition.getOrStart(cfg)) {
+ try {
+ Ignition.start(cfg);
+
+ fail("Expected exception after grid started");
+ }
+ catch (IgniteException ignored) {
+ }
+
+ Ignite ignite2 = Ignition.getOrStart(cfg);
+
+ assertEquals("Must return same instance", ignite, ignite2);
+ }
+
+ assertTrue(G.allGrids().isEmpty());
+ }
+
+ /**
+ * Tests named grid
+ */
+ public void testNamedGridGetOrStart() throws Exception {
+ IgniteConfiguration cfg = getConfiguration("test");
+ try (Ignite ignite = Ignition.getOrStart(cfg)) {
+ try {
+ Ignition.start(cfg);
+
+ fail("Expected exception after grid started");
+ }
+ catch (IgniteException ignored) {
+ // No-op.
+ }
+
+ Ignite ignite2 = Ignition.getOrStart(cfg);
+
+ assertEquals("Must return same instance", ignite, ignite2);
+ }
+
+ assertTrue(G.allGrids().isEmpty());
+ }
+
+ /**
+ * Tests concurrent grid initialization
+ */
+ public void testConcurrentGridGetOrStartCon() throws Exception {
+ final IgniteConfiguration cfg = getConfiguration(null);
+
+ final AtomicReference<Ignite> ref = new AtomicReference<>();
+
+ try {
+ GridTestUtils.runMultiThreaded(new Runnable() {
+ @Override public void run() {
+ // must return same instance in each thread
+
+ try {
+ Ignite ignite = Ignition.getOrStart(cfg);
+
+ boolean set = ref.compareAndSet(null, ignite);
+
+ if (!set)
+ assertEquals(ref.get(), ignite);
+ }
+ catch (IgniteException e) {
+ throw new RuntimeException("Ignite error", e);
+ }
+ }
+ }, CONCURRENCY, "GridCreatorThread");
+ }
+ catch (Exception ignored) {
+ fail("Exception is not expected");
+ }
+
+ G.stopAll(true);
+
+ assertTrue(G.allGrids().isEmpty());
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/384a74c4/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index fede0ab..98a876f 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -23,6 +23,7 @@ import org.apache.ignite.GridSuppressedExceptionSelfTest;
import org.apache.ignite.internal.ClusterGroupHostsSelfTest;
import org.apache.ignite.internal.ClusterGroupSelfTest;
import org.apache.ignite.internal.GridFailFastNodeFailureDetectionSelfTest;
+import org.apache.ignite.internal.GridGetOrStartSelfTest;
import org.apache.ignite.internal.GridLifecycleAwareSelfTest;
import org.apache.ignite.internal.GridLifecycleBeanSelfTest;
import org.apache.ignite.internal.GridProjectionForCachesSelfTest;
@@ -121,6 +122,7 @@ public class IgniteBasicTestSuite extends TestSuite {
GridTestUtils.addTestIfNeeded(suite, DynamicProxySerializationMultiJvmSelfTest.class, ignoredTests);
+ GridTestUtils.addTestIfNeeded(suite, GridGetOrStartSelfTest.class, ignoredTests);
return suite;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/384a74c4/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteContext.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteContext.scala b/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteContext.scala
index 6e48017..bd61974 100644
--- a/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteContext.scala
+++ b/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteContext.scala
@@ -20,7 +20,7 @@ package org.apache.ignite.spark
import org.apache.ignite.internal.IgnitionEx
import org.apache.ignite.internal.util.IgniteUtils
-import org.apache.ignite.{IgniteSystemProperties, Ignition, Ignite}
+import org.apache.ignite.{IgniteException, IgniteSystemProperties, Ignition, Ignite}
import org.apache.ignite.configuration.{CacheConfiguration, IgniteConfiguration}
import org.apache.spark.{Logging, SparkContext}
import org.apache.spark.sql.SQLContext
@@ -36,15 +36,13 @@ import org.apache.spark.sql.SQLContext
class IgniteContext[K, V](
@transient val sparkContext: SparkContext,
cfgF: () \u21d2 IgniteConfiguration,
- client: Boolean = true
-) extends Serializable with Logging {
- @transient private val driver = true
-
+ standalone: Boolean = true
+ ) extends Serializable with Logging {
private val cfgClo = new Once(cfgF)
private val igniteHome = IgniteUtils.getIgniteHome
- if (!client) {
+ if (!standalone) {
// Get required number of executors with default equals to number of available executors.
val workers = sparkContext.getConf.getInt("spark.executor.instances",
sparkContext.getExecutorStorageStatus.length)
@@ -55,7 +53,7 @@ class IgniteContext[K, V](
logInfo("Will start Ignite nodes on " + workers + " workers")
// Start ignite server node on each worker in server mode.
- sparkContext.parallelize(1 to workers, workers).foreach(it \u21d2 ignite())
+ sparkContext.parallelize(1 to workers, workers).foreachPartition(it \u21d2 ignite())
}
// Make sure to start Ignite on context creation.
@@ -71,7 +69,7 @@ class IgniteContext[K, V](
sc: SparkContext,
springUrl: String,
client: Boolean
- ) {
+ ) {
this(sc, () \u21d2 IgnitionEx.loadConfiguration(springUrl).get1(), client)
}
@@ -84,7 +82,7 @@ class IgniteContext[K, V](
def this(
sc: SparkContext,
springUrl: String
- ) {
+ ) {
this(sc, () \u21d2 IgnitionEx.loadConfiguration(springUrl).get1())
}
@@ -124,10 +122,8 @@ class IgniteContext[K, V](
}
/**
- * Gets an Ignite instance supporting this context. Ignite instance will be started
- * if it has not been started yet.
- *
- * @return Ignite instance.
+ * Get or start Ignite instance it it's not started yet.
+ * @return
*/
def ignite(): Ignite = {
val home = IgniteUtils.getIgniteHome
@@ -142,19 +138,17 @@ class IgniteContext[K, V](
val igniteCfg = cfgClo()
+ // check if called from driver
+ if (sparkContext != null) igniteCfg.setClientMode(true)
+
try {
- Ignition.ignite(igniteCfg.getGridName)
+ Ignition.getOrStart(igniteCfg)
}
catch {
- case e: Exception \u21d2
- try {
- igniteCfg.setClientMode(client || driver)
-
- Ignition.start(igniteCfg)
- }
- catch {
- case e: Exception \u21d2 Ignition.ignite(igniteCfg.getGridName)
- }
+ case e: IgniteException \u21d2
+ logError("Failed to start Ignite.", e)
+
+ throw e
}
}
@@ -162,7 +156,25 @@ class IgniteContext[K, V](
* Stops supporting ignite instance. If ignite instance has been already stopped, this operation will be
* a no-op.
*/
- def close() = {
+ def close(shutdownIgniteOnWorkers: Boolean = false) = {
+ // additional check if called from driver
+ if (sparkContext != null && shutdownIgniteOnWorkers) {
+ // Get required number of executors with default equals to number of available executors.
+ val workers = sparkContext.getConf.getInt("spark.executor.instances",
+ sparkContext.getExecutorStorageStatus.length)
+
+ if (workers > 0) {
+ logInfo("Will stop Ignite nodes on " + workers + " workers")
+
+ // Start ignite server node on each worker in server mode.
+ sparkContext.parallelize(1 to workers, workers).foreachPartition(it \u21d2 doClose())
+ }
+ }
+
+ doClose()
+ }
+
+ private def doClose() = {
val igniteCfg = cfgClo()
Ignition.stop(igniteCfg.getGridName, false)
@@ -179,8 +191,11 @@ private class Once(clo: () \u21d2 IgniteConfiguration) extends Serializable {
def apply(): IgniteConfiguration = {
if (res == null) {
+
this.synchronized {
+
if (res == null)
+
res = clo()
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/384a74c4/modules/spark/src/main/scala/org/apache/ignite/spark/JavaIgniteContext.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/main/scala/org/apache/ignite/spark/JavaIgniteContext.scala b/modules/spark/src/main/scala/org/apache/ignite/spark/JavaIgniteContext.scala
index e2d57bf..44b1cd9 100644
--- a/modules/spark/src/main/scala/org/apache/ignite/spark/JavaIgniteContext.scala
+++ b/modules/spark/src/main/scala/org/apache/ignite/spark/JavaIgniteContext.scala
@@ -34,10 +34,16 @@ import scala.reflect.ClassTag
* @tparam V Value type.
*/
class JavaIgniteContext[K, V](
- @scala.transient val sc: JavaSparkContext,
- val cfgF: IgniteOutClosure[IgniteConfiguration]) extends Serializable {
+ @transient val sc: JavaSparkContext,
+ val cfgF: IgniteOutClosure[IgniteConfiguration],
+ standalone: Boolean = true
+ ) extends Serializable {
- @transient val ic: IgniteContext[K, V] = new IgniteContext[K, V](sc.sc, () => cfgF.apply())
+ @transient val ic: IgniteContext[K, V] = new IgniteContext[K, V](sc.sc, () => cfgF.apply(), standalone)
+
+ def this(sc: JavaSparkContext, cfgF: IgniteOutClosure[IgniteConfiguration]) {
+ this(sc, cfgF, true)
+ }
def this(sc: JavaSparkContext, springUrl: String) {
this(sc, new IgniteOutClosure[IgniteConfiguration] {
@@ -53,7 +59,7 @@ class JavaIgniteContext[K, V](
def ignite(): Ignite = ic.ignite()
- def close() = ic.close()
+ def close(shutdownIgniteOnWorkers:Boolean = false) = ic.close(shutdownIgniteOnWorkers)
private[spark] def fakeClassTag[T]: ClassTag[T] = ClassTag.AnyRef.asInstanceOf[ClassTag[T]]
http://git-wip-us.apache.org/repos/asf/ignite/blob/384a74c4/modules/spark/src/test/java/org/apache/ignite/spark/JavaEmbeddedIgniteRDDSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/java/org/apache/ignite/spark/JavaEmbeddedIgniteRDDSelfTest.java b/modules/spark/src/test/java/org/apache/ignite/spark/JavaEmbeddedIgniteRDDSelfTest.java
new file mode 100644
index 0000000..5ceaca7
--- /dev/null
+++ b/modules/spark/src/test/java/org/apache/ignite/spark/JavaEmbeddedIgniteRDDSelfTest.java
@@ -0,0 +1,343 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT 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.spark;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgniteOutClosure;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.spark.SparkConf;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.api.java.function.Function;
+import org.apache.spark.api.java.function.Function2;
+import org.apache.spark.api.java.function.PairFunction;
+import org.apache.spark.sql.Column;
+import org.apache.spark.sql.DataFrame;
+import org.apache.spark.sql.Row;
+import scala.Tuple2;
+
+/**
+ * Tests for {@link JavaIgniteRDD} (embedded mode).
+ */
+public class JavaEmbeddedIgniteRDDSelfTest extends GridCommonAbstractTest {
+ /** For grid names generation */
+ private static AtomicInteger cntr = new AtomicInteger(1);
+
+ /** Grid names. */
+ private static ThreadLocal<Integer> gridNames = new ThreadLocal<Integer>() {
+ @Override protected Integer initialValue() {
+ return cntr.getAndIncrement();
+ }
+ };
+
+ /** Grid count. */
+ private static final int GRID_CNT = 3;
+
+ /** Keys count. */
+ private static final int KEYS_CNT = 10000;
+
+ /** Cache name. */
+ private static final String PARTITIONED_CACHE_NAME = "partitioned";
+
+ /** Sum function. */
+ private static final Function2<Integer, Integer, Integer> SUM_F = new Function2<Integer, Integer, Integer>() {
+ public Integer call(Integer x, Integer y) {
+ return x + y;
+ }
+ };
+
+ /** To pair function. */
+ private static final PairFunction<Integer, String, String> TO_PAIR_F = new PairFunction<Integer, String, String>() {
+ /** {@inheritDoc} */
+ @Override public Tuple2<String, String> call(Integer i) {
+ return new Tuple2<>(String.valueOf(i), "val" + i);
+ }
+ };
+
+ /** (String, Integer); pair to Integer value function. */
+ private static final Function<Tuple2<String, Integer>, Integer> STR_INT_PAIR_TO_INT_F = new PairToValueFunction<>();
+
+ /** (String, Entity) pair to Entity value function. */
+ private static final Function<Tuple2<String, Entity>, Entity> STR_ENTITY_PAIR_TO_ENTITY_F =
+ new PairToValueFunction<>();
+
+ /** Integer to entity function. */
+ private static final PairFunction<Integer, String, Entity> INT_TO_ENTITY_F =
+ new PairFunction<Integer, String, Entity>() {
+ @Override public Tuple2<String, Entity> call(Integer i) throws Exception {
+ return new Tuple2<>(String.valueOf(i), new Entity(i, "name" + i, i * 100));
+ }
+ };
+
+ /**
+ * Default constructor.
+ */
+ public JavaEmbeddedIgniteRDDSelfTest() {
+ super(false);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * Creates default spark context
+ */
+ private JavaSparkContext createContext() {
+ SparkConf conf = new SparkConf();
+
+ conf.set("spark.executor.instances", String.valueOf(GRID_CNT));
+
+ return new JavaSparkContext("local[" + GRID_CNT + "]", "test", conf);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testStoreDataToIgnite() throws Exception {
+ JavaSparkContext sc = createContext();
+
+ JavaIgniteContext<String, String> ic = null;
+
+ try {
+ ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider(), false);
+
+ ic.fromCache(PARTITIONED_CACHE_NAME)
+ .savePairs(sc.parallelize(F.range(0, KEYS_CNT), GRID_CNT).mapToPair(TO_PAIR_F));
+
+ Ignite ignite = ic.ignite();
+
+ IgniteCache<String, String> cache = ignite.cache(PARTITIONED_CACHE_NAME);
+
+ for (int i = 0; i < KEYS_CNT; i++) {
+ String val = cache.get(String.valueOf(i));
+
+ assertNotNull("Value was not put to cache for key: " + i, val);
+ assertEquals("Invalid value stored for key: " + i, "val" + i, val);
+ }
+ }
+ finally {
+ if (ic != null)
+ ic.close(true);
+
+ sc.stop();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testReadDataFromIgnite() throws Exception {
+ JavaSparkContext sc = createContext();
+
+ JavaIgniteContext<String, Integer> ic = null;
+
+ try {
+ ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider(), false);
+
+ Ignite ignite = ic.ignite();
+
+ IgniteCache<String, Integer> cache = ignite.cache(PARTITIONED_CACHE_NAME);
+
+ for (int i = 0; i < KEYS_CNT; i++)
+ cache.put(String.valueOf(i), i);
+
+ JavaRDD<Integer> values = ic.fromCache(PARTITIONED_CACHE_NAME).map(STR_INT_PAIR_TO_INT_F);
+
+ int sum = values.fold(0, SUM_F);
+
+ int expSum = (KEYS_CNT * KEYS_CNT + KEYS_CNT) / 2 - KEYS_CNT;
+
+ assertEquals(expSum, sum);
+ }
+ finally {
+ if (ic != null)
+ ic.close(true);
+
+ sc.stop();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testQueryObjectsFromIgnite() throws Exception {
+ fail("IGNITE-3009");
+
+ JavaSparkContext sc = createContext();
+
+ JavaIgniteContext<String, Entity> ic = null;
+
+ try {
+ ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider(), false);
+
+ JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
+
+ int cnt = 1001;
+
+ List<Integer> numbers = F.range(0, cnt);
+
+ cache.savePairs(sc.parallelize(numbers, GRID_CNT).mapToPair(INT_TO_ENTITY_F));
+
+ List<Entity> res = cache.objectSql("Entity", "name = ? and salary = ?", "name50", 5000)
+ .map(STR_ENTITY_PAIR_TO_ENTITY_F).collect();
+
+ assertEquals("Invalid result length", 1, res.size());
+ assertEquals("Invalid result", 50, res.get(0).id());
+ assertEquals("Invalid result", "name50", res.get(0).name());
+ assertEquals("Invalid result", 5000, res.get(0).salary());
+
+// Ignite ignite = ic.ignite();
+// IgniteCache<Object, Object> underCache = ignite.cache(PARTITIONED_CACHE_NAME);
+// assertEquals("Invalid total count", cnt, underCache.size());
+
+ assertEquals("Invalid count", 500, cache.objectSql("Entity", "id > 500").count());
+ }
+ finally {
+ if (ic != null)
+ ic.close(true);
+
+ sc.stop();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testQueryFieldsFromIgnite() throws Exception {
+ JavaSparkContext sc = createContext();
+
+ JavaIgniteContext<String, Entity> ic = null;
+
+ try {
+ ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider(), false);
+
+ JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
+
+ cache.savePairs(sc.parallelize(F.range(0, 1001), GRID_CNT).mapToPair(INT_TO_ENTITY_F));
+
+ DataFrame df =
+ cache.sql("select id, name, salary from Entity where name = ? and salary = ?", "name50", 5000);
+
+ df.printSchema();
+
+ Row[] res = df.collect();
+
+ assertEquals("Invalid result length", 1, res.length);
+ assertEquals("Invalid result", 50, res[0].get(0));
+ assertEquals("Invalid result", "name50", res[0].get(1));
+ assertEquals("Invalid result", 5000, res[0].get(2));
+
+ Column exp = new Column("NAME").equalTo("name50").and(new Column("SALARY").equalTo(5000));
+
+ DataFrame df0 = cache.sql("select id, name, salary from Entity").where(exp);
+
+ df.printSchema();
+
+ Row[] res0 = df0.collect();
+
+ assertEquals("Invalid result length", 1, res0.length);
+ assertEquals("Invalid result", 50, res0[0].get(0));
+ assertEquals("Invalid result", "name50", res0[0].get(1));
+ assertEquals("Invalid result", 5000, res0[0].get(2));
+
+ assertEquals("Invalid count", 500, cache.sql("select id from Entity where id > 500").count());
+ }
+ finally {
+ if (ic != null)
+ ic.close(true);
+
+ sc.stop();
+ }
+ }
+
+ /** Finder. */
+ private static TcpDiscoveryVmIpFinder FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /**
+ * @param gridName Grid name.
+ * @param client Client.
+ */
+ private static IgniteConfiguration getConfiguration(String gridName, boolean client) throws Exception {
+ IgniteConfiguration cfg = new IgniteConfiguration();
+
+ TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+ discoSpi.setIpFinder(FINDER);
+
+ cfg.setDiscoverySpi(discoSpi);
+
+ cfg.setCacheConfiguration(cacheConfiguration());
+
+ cfg.setClientMode(client);
+
+ cfg.setGridName(gridName);
+
+ return cfg;
+ }
+
+ /**
+ * Creates cache configuration.
+ */
+ private static CacheConfiguration<Object, Object> cacheConfiguration() {
+ CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
+
+ ccfg.setBackups(1);
+
+ ccfg.setName(PARTITIONED_CACHE_NAME);
+
+ ccfg.setIndexedTypes(String.class, Entity.class);
+
+ return ccfg;
+ }
+
+ /**
+ * Ignite configiration provider.
+ */
+ static class IgniteConfigProvider implements IgniteOutClosure<IgniteConfiguration> {
+ /** {@inheritDoc} */
+ @Override public IgniteConfiguration apply() {
+ try {
+ return getConfiguration("worker-" + gridNames.get(), false);
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ /**
+ * @param <K>
+ * @param <V>
+ */
+ static class PairToValueFunction<K, V> implements Function<Tuple2<K, V>, V> {
+ /** {@inheritDoc} */
+ @Override public V call(Tuple2<K, V> t) throws Exception {
+ return t._2();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/384a74c4/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java b/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java
deleted file mode 100644
index 9892056..0000000
--- a/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java
+++ /dev/null
@@ -1,358 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.spark;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.lang.IgniteOutClosure;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.apache.spark.api.java.JavaRDD;
-import org.apache.spark.api.java.JavaSparkContext;
-import org.apache.spark.api.java.function.Function;
-import org.apache.spark.api.java.function.Function2;
-import org.apache.spark.api.java.function.PairFunction;
-import org.apache.spark.sql.Column;
-import org.apache.spark.sql.DataFrame;
-import org.apache.spark.sql.Row;
-import scala.Tuple2;
-
-import java.lang.reflect.Field;
-import java.math.BigDecimal;
-import java.util.List;
-
-/**
- * Tests for {@link JavaIgniteRDD}.
- */
-public class JavaIgniteRDDSelfTest extends GridCommonAbstractTest {
- /** Grid count. */
- private static final int GRID_CNT = 3;
-
- /** Keys count. */
- private static final int KEYS_CNT = 10000;
-
- /** Cache name. */
- private static final String PARTITIONED_CACHE_NAME = "partitioned";
-
- /** Ip finder. */
- private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
- /** Sum function. */
- private static final Function2<Integer, Integer, Integer> SUM_F = new Function2<Integer, Integer, Integer>() {
- public Integer call(Integer x, Integer y) {
- return x + y;
- }
- };
-
- /** To pair function. */
- private static final PairFunction<Integer, String, String> TO_PAIR_F = new PairFunction<Integer, String, String>() {
- /** {@inheritDoc} */
- @Override public Tuple2<String, String> call(Integer i) {
- return new Tuple2<>(String.valueOf(i), "val" + i);
- }
- };
-
- /** (String, Integer); pair to Integer value function. */
- private static final Function<Tuple2<String, Integer>, Integer> STR_INT_PAIR_TO_INT_F = new PairToValueFunction<>();
-
- /** (String, Entity) pair to Entity value function. */
- private static final Function<Tuple2<String, Entity>, Entity> STR_ENTITY_PAIR_TO_ENTITY_F =
- new PairToValueFunction<>();
-
- /** Integer to entity function. */
- private static final PairFunction<Integer, String, Entity> INT_TO_ENTITY_F =
- new PairFunction<Integer, String, Entity>() {
- @Override public Tuple2<String, Entity> call(Integer i) throws Exception {
- return new Tuple2<>(String.valueOf(i), new Entity(i, "name" + i, i * 100));
- }
- };
-
- /** */
- private static final PairFunction<Integer, String, EntityTestAllTypeFields> INT_TO_ENTITY_ALL_FIELDS_F =
- new PairFunction<Integer, String, EntityTestAllTypeFields>() {
- @Override public Tuple2<String, EntityTestAllTypeFields> call(Integer i) throws Exception {
- return new Tuple2<>(String.valueOf(i), new EntityTestAllTypeFields(i));
- }
- };
-
- /** {@inheritDoc} */
- @Override protected void beforeTest() throws Exception {
- Ignition.ignite("grid-0").cache(PARTITIONED_CACHE_NAME).removeAll();
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTest() throws Exception {
- Ignition.stop("client", false);
- }
-
- /** {@inheritDoc} */
- @Override protected void beforeTestsStarted() throws Exception {
- for (int i = 0; i < GRID_CNT; i++)
- Ignition.start(getConfiguration("grid-" + i, false));
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTestsStopped() throws Exception {
- for (int i = 0; i < GRID_CNT; i++)
- Ignition.stop("grid-" + i, false);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testStoreDataToIgnite() throws Exception {
- JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
-
- try {
- JavaIgniteContext<String, String> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
-
- ic.fromCache(PARTITIONED_CACHE_NAME)
- .savePairs(sc.parallelize(F.range(0, KEYS_CNT), 2).mapToPair(TO_PAIR_F));
-
- Ignite ignite = Ignition.ignite("grid-0");
-
- IgniteCache<String, String> cache = ignite.cache(PARTITIONED_CACHE_NAME);
-
- for (int i = 0; i < KEYS_CNT; i++) {
- String val = cache.get(String.valueOf(i));
-
- assertNotNull("Value was not put to cache for key: " + i, val);
- assertEquals("Invalid value stored for key: " + i, "val" + i, val);
- }
- }
- finally {
- sc.stop();
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testReadDataFromIgnite() throws Exception {
- JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
-
- try {
- JavaIgniteContext<String, Integer> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
-
- Ignite ignite = Ignition.ignite("grid-0");
-
- IgniteCache<String, Integer> cache = ignite.cache(PARTITIONED_CACHE_NAME);
-
- for (int i = 0; i < KEYS_CNT; i++)
- cache.put(String.valueOf(i), i);
-
- JavaRDD<Integer> values = ic.fromCache(PARTITIONED_CACHE_NAME).map(STR_INT_PAIR_TO_INT_F);
-
- int sum = values.fold(0, SUM_F);
-
- int expSum = (KEYS_CNT * KEYS_CNT + KEYS_CNT) / 2 - KEYS_CNT;
-
- assertEquals(expSum, sum);
- }
- finally {
- sc.stop();
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testQueryObjectsFromIgnite() throws Exception {
- JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
-
- try {
- JavaIgniteContext<String, Entity> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
-
- JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
-
- cache.savePairs(sc.parallelize(F.range(0, 1001), 2).mapToPair(INT_TO_ENTITY_F));
-
- List<Entity> res = cache.objectSql("Entity", "name = ? and salary = ?", "name50", 5000)
- .map(STR_ENTITY_PAIR_TO_ENTITY_F).collect();
-
- assertEquals("Invalid result length", 1, res.size());
- assertEquals("Invalid result", 50, res.get(0).id());
- assertEquals("Invalid result", "name50", res.get(0).name());
- assertEquals("Invalid result", 5000, res.get(0).salary());
- assertEquals("Invalid count", 500, cache.objectSql("Entity", "id > 500").count());
- }
- finally {
- sc.stop();
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testQueryFieldsFromIgnite() throws Exception {
- JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
-
- try {
- JavaIgniteContext<String, Entity> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
-
- JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
-
- cache.savePairs(sc.parallelize(F.range(0, 1001), 2).mapToPair(INT_TO_ENTITY_F));
-
- DataFrame df =
- cache.sql("select id, name, salary from Entity where name = ? and salary = ?", "name50", 5000);
-
- df.printSchema();
-
- Row[] res = df.collect();
-
- assertEquals("Invalid result length", 1, res.length);
- assertEquals("Invalid result", 50, res[0].get(0));
- assertEquals("Invalid result", "name50", res[0].get(1));
- assertEquals("Invalid result", 5000, res[0].get(2));
-
- Column exp = new Column("NAME").equalTo("name50").and(new Column("SALARY").equalTo(5000));
-
- DataFrame df0 = cache.sql("select id, name, salary from Entity").where(exp);
-
- df.printSchema();
-
- Row[] res0 = df0.collect();
-
- assertEquals("Invalid result length", 1, res0.length);
- assertEquals("Invalid result", 50, res0[0].get(0));
- assertEquals("Invalid result", "name50", res0[0].get(1));
- assertEquals("Invalid result", 5000, res0[0].get(2));
-
- assertEquals("Invalid count", 500, cache.sql("select id from Entity where id > 500").count());
- }
- finally {
- sc.stop();
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testAllFieldsTypes() throws Exception {
- JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
-
- final int cnt = 100;
-
- try {
- JavaIgniteContext<String, EntityTestAllTypeFields> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
-
- JavaIgniteRDD<String, EntityTestAllTypeFields> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
-
- cache.savePairs(sc.parallelize(F.range(0, cnt), 2).mapToPair(INT_TO_ENTITY_ALL_FIELDS_F));
-
- EntityTestAllTypeFields e = new EntityTestAllTypeFields(cnt / 2);
- for(Field f : EntityTestAllTypeFields.class.getDeclaredFields()) {
- String fieldName = f.getName();
-
- Object val = GridTestUtils.getFieldValue(e, fieldName);
-
- DataFrame df = cache.sql(
- String.format("select %s from EntityTestAllTypeFields where %s = ?", fieldName, fieldName),
- val);
-
- if (val instanceof BigDecimal) {
- Object res = df.collect()[0].get(0);
-
- assertTrue(String.format("+++ Fail on %s field", fieldName),
- ((Comparable<BigDecimal>)val).compareTo((BigDecimal)res) == 0);
- }
- else if (val.getClass().isArray())
- assertTrue(String.format("+++ Fail on %s field", fieldName), 1 <= df.count());
- else
- assertEquals(String.format("+++ Fail on %s field", fieldName), val, df.collect()[0].get(0));
-
- info(String.format("+++ Query on the filed: %s : %s passed", fieldName, f.getType().getSimpleName()));
- }
- }
- finally {
- sc.stop();
- }
- }
-
- /**
- * @param gridName Grid name.
- * @param client Client.
- */
- private static IgniteConfiguration getConfiguration(String gridName, boolean client) throws Exception {
- IgniteConfiguration cfg = new IgniteConfiguration();
-
- TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
-
- discoSpi.setIpFinder(IP_FINDER);
-
- cfg.setDiscoverySpi(discoSpi);
-
- cfg.setCacheConfiguration(cacheConfiguration());
-
- cfg.setClientMode(client);
-
- cfg.setGridName(gridName);
-
- return cfg;
- }
-
- /**
- * Creates cache configuration.
- */
- private static CacheConfiguration<Object, Object> cacheConfiguration() {
- CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
-
- ccfg.setBackups(1);
-
- ccfg.setName(PARTITIONED_CACHE_NAME);
-
- ccfg.setIndexedTypes(String.class, Entity.class,
- String.class, EntityTestAllTypeFields.class);
-
- return ccfg;
- }
-
- /**
- * Ignite configiration provider.
- */
- static class IgniteConfigProvider implements IgniteOutClosure<IgniteConfiguration> {
- /** {@inheritDoc} */
- @Override public IgniteConfiguration apply() {
- try {
- return getConfiguration("client", true);
- }
- catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- /**
- * @param <K>
- * @param <V>
- */
- static class PairToValueFunction<K, V> implements Function<Tuple2<K, V>, V> {
- /** {@inheritDoc} */
- @Override public V call(Tuple2<K, V> t) throws Exception {
- return t._2();
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/384a74c4/modules/spark/src/test/java/org/apache/ignite/spark/JavaStandaloneIgniteRDDSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/java/org/apache/ignite/spark/JavaStandaloneIgniteRDDSelfTest.java b/modules/spark/src/test/java/org/apache/ignite/spark/JavaStandaloneIgniteRDDSelfTest.java
new file mode 100644
index 0000000..e600c6c
--- /dev/null
+++ b/modules/spark/src/test/java/org/apache/ignite/spark/JavaStandaloneIgniteRDDSelfTest.java
@@ -0,0 +1,358 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT 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.spark;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgniteOutClosure;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.api.java.function.Function;
+import org.apache.spark.api.java.function.Function2;
+import org.apache.spark.api.java.function.PairFunction;
+import org.apache.spark.sql.Column;
+import org.apache.spark.sql.DataFrame;
+import org.apache.spark.sql.Row;
+import scala.Tuple2;
+
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * Tests for {@link JavaIgniteRDD} (standalone mode).
+ */
+public class JavaStandaloneIgniteRDDSelfTest extends GridCommonAbstractTest {
+ /** Grid count. */
+ private static final int GRID_CNT = 3;
+
+ /** Keys count. */
+ private static final int KEYS_CNT = 10000;
+
+ /** Cache name. */
+ private static final String PARTITIONED_CACHE_NAME = "partitioned";
+
+ /** Ip finder. */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** Sum function. */
+ private static final Function2<Integer, Integer, Integer> SUM_F = new Function2<Integer, Integer, Integer>() {
+ public Integer call(Integer x, Integer y) {
+ return x + y;
+ }
+ };
+
+ /** To pair function. */
+ private static final PairFunction<Integer, String, String> TO_PAIR_F = new PairFunction<Integer, String, String>() {
+ /** {@inheritDoc} */
+ @Override public Tuple2<String, String> call(Integer i) {
+ return new Tuple2<>(String.valueOf(i), "val" + i);
+ }
+ };
+
+ /** (String, Integer); pair to Integer value function. */
+ private static final Function<Tuple2<String, Integer>, Integer> STR_INT_PAIR_TO_INT_F = new PairToValueFunction<>();
+
+ /** (String, Entity) pair to Entity value function. */
+ private static final Function<Tuple2<String, Entity>, Entity> STR_ENTITY_PAIR_TO_ENTITY_F =
+ new PairToValueFunction<>();
+
+ /** Integer to entity function. */
+ private static final PairFunction<Integer, String, Entity> INT_TO_ENTITY_F =
+ new PairFunction<Integer, String, Entity>() {
+ @Override public Tuple2<String, Entity> call(Integer i) throws Exception {
+ return new Tuple2<>(String.valueOf(i), new Entity(i, "name" + i, i * 100));
+ }
+ };
+
+ /** */
+ private static final PairFunction<Integer, String, EntityTestAllTypeFields> INT_TO_ENTITY_ALL_FIELDS_F =
+ new PairFunction<Integer, String, EntityTestAllTypeFields>() {
+ @Override public Tuple2<String, EntityTestAllTypeFields> call(Integer i) throws Exception {
+ return new Tuple2<>(String.valueOf(i), new EntityTestAllTypeFields(i));
+ }
+ };
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ Ignition.ignite("grid-0").cache(PARTITIONED_CACHE_NAME).removeAll();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ Ignition.stop("client", false);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ for (int i = 0; i < GRID_CNT; i++)
+ Ignition.start(getConfiguration("grid-" + i, false));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ for (int i = 0; i < GRID_CNT; i++)
+ Ignition.stop("grid-" + i, false);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testStoreDataToIgnite() throws Exception {
+ JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
+
+ try {
+ JavaIgniteContext<String, String> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
+
+ ic.fromCache(PARTITIONED_CACHE_NAME)
+ .savePairs(sc.parallelize(F.range(0, KEYS_CNT), 2).mapToPair(TO_PAIR_F));
+
+ Ignite ignite = Ignition.ignite("grid-0");
+
+ IgniteCache<String, String> cache = ignite.cache(PARTITIONED_CACHE_NAME);
+
+ for (int i = 0; i < KEYS_CNT; i++) {
+ String val = cache.get(String.valueOf(i));
+
+ assertNotNull("Value was not put to cache for key: " + i, val);
+ assertEquals("Invalid value stored for key: " + i, "val" + i, val);
+ }
+ }
+ finally {
+ sc.stop();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testReadDataFromIgnite() throws Exception {
+ JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
+
+ try {
+ JavaIgniteContext<String, Integer> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
+
+ Ignite ignite = Ignition.ignite("grid-0");
+
+ IgniteCache<String, Integer> cache = ignite.cache(PARTITIONED_CACHE_NAME);
+
+ for (int i = 0; i < KEYS_CNT; i++)
+ cache.put(String.valueOf(i), i);
+
+ JavaRDD<Integer> values = ic.fromCache(PARTITIONED_CACHE_NAME).map(STR_INT_PAIR_TO_INT_F);
+
+ int sum = values.fold(0, SUM_F);
+
+ int expSum = (KEYS_CNT * KEYS_CNT + KEYS_CNT) / 2 - KEYS_CNT;
+
+ assertEquals(expSum, sum);
+ }
+ finally {
+ sc.stop();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testQueryObjectsFromIgnite() throws Exception {
+ JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
+
+ try {
+ JavaIgniteContext<String, Entity> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
+
+ JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
+
+ cache.savePairs(sc.parallelize(F.range(0, 1001), 2).mapToPair(INT_TO_ENTITY_F));
+
+ List<Entity> res = cache.objectSql("Entity", "name = ? and salary = ?", "name50", 5000)
+ .map(STR_ENTITY_PAIR_TO_ENTITY_F).collect();
+
+ assertEquals("Invalid result length", 1, res.size());
+ assertEquals("Invalid result", 50, res.get(0).id());
+ assertEquals("Invalid result", "name50", res.get(0).name());
+ assertEquals("Invalid result", 5000, res.get(0).salary());
+ assertEquals("Invalid count", 500, cache.objectSql("Entity", "id > 500").count());
+ }
+ finally {
+ sc.stop();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testQueryFieldsFromIgnite() throws Exception {
+ JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
+
+ try {
+ JavaIgniteContext<String, Entity> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
+
+ JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
+
+ cache.savePairs(sc.parallelize(F.range(0, 1001), 2).mapToPair(INT_TO_ENTITY_F));
+
+ DataFrame df =
+ cache.sql("select id, name, salary from Entity where name = ? and salary = ?", "name50", 5000);
+
+ df.printSchema();
+
+ Row[] res = df.collect();
+
+ assertEquals("Invalid result length", 1, res.length);
+ assertEquals("Invalid result", 50, res[0].get(0));
+ assertEquals("Invalid result", "name50", res[0].get(1));
+ assertEquals("Invalid result", 5000, res[0].get(2));
+
+ Column exp = new Column("NAME").equalTo("name50").and(new Column("SALARY").equalTo(5000));
+
+ DataFrame df0 = cache.sql("select id, name, salary from Entity").where(exp);
+
+ df.printSchema();
+
+ Row[] res0 = df0.collect();
+
+ assertEquals("Invalid result length", 1, res0.length);
+ assertEquals("Invalid result", 50, res0[0].get(0));
+ assertEquals("Invalid result", "name50", res0[0].get(1));
+ assertEquals("Invalid result", 5000, res0[0].get(2));
+
+ assertEquals("Invalid count", 500, cache.sql("select id from Entity where id > 500").count());
+ }
+ finally {
+ sc.stop();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAllFieldsTypes() throws Exception {
+ JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
+
+ final int cnt = 100;
+
+ try {
+ JavaIgniteContext<String, EntityTestAllTypeFields> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
+
+ JavaIgniteRDD<String, EntityTestAllTypeFields> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
+
+ cache.savePairs(sc.parallelize(F.range(0, cnt), 2).mapToPair(INT_TO_ENTITY_ALL_FIELDS_F));
+
+ EntityTestAllTypeFields e = new EntityTestAllTypeFields(cnt / 2);
+ for(Field f : EntityTestAllTypeFields.class.getDeclaredFields()) {
+ String fieldName = f.getName();
+
+ Object val = GridTestUtils.getFieldValue(e, fieldName);
+
+ DataFrame df = cache.sql(
+ String.format("select %s from EntityTestAllTypeFields where %s = ?", fieldName, fieldName),
+ val);
+
+ if (val instanceof BigDecimal) {
+ Object res = df.collect()[0].get(0);
+
+ assertTrue(String.format("+++ Fail on %s field", fieldName),
+ ((Comparable<BigDecimal>)val).compareTo((BigDecimal)res) == 0);
+ }
+ else if (val.getClass().isArray())
+ assertTrue(String.format("+++ Fail on %s field", fieldName), 1 <= df.count());
+ else
+ assertEquals(String.format("+++ Fail on %s field", fieldName), val, df.collect()[0].get(0));
+
+ info(String.format("+++ Query on the filed: %s : %s passed", fieldName, f.getType().getSimpleName()));
+ }
+ }
+ finally {
+ sc.stop();
+ }
+ }
+
+ /**
+ * @param gridName Grid name.
+ * @param client Client.
+ */
+ private static IgniteConfiguration getConfiguration(String gridName, boolean client) throws Exception {
+ IgniteConfiguration cfg = new IgniteConfiguration();
+
+ TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+ discoSpi.setIpFinder(IP_FINDER);
+
+ cfg.setDiscoverySpi(discoSpi);
+
+ cfg.setCacheConfiguration(cacheConfiguration());
+
+ cfg.setClientMode(client);
+
+ cfg.setGridName(gridName);
+
+ return cfg;
+ }
+
+ /**
+ * Creates cache configuration.
+ */
+ private static CacheConfiguration<Object, Object> cacheConfiguration() {
+ CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
+
+ ccfg.setBackups(1);
+
+ ccfg.setName(PARTITIONED_CACHE_NAME);
+
+ ccfg.setIndexedTypes(String.class, Entity.class,
+ String.class, EntityTestAllTypeFields.class);
+
+ return ccfg;
+ }
+
+ /**
+ * Ignite configiration provider.
+ */
+ static class IgniteConfigProvider implements IgniteOutClosure<IgniteConfiguration> {
+ /** {@inheritDoc} */
+ @Override public IgniteConfiguration apply() {
+ try {
+ return getConfiguration("client", true);
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ /**
+ * @param <K>
+ * @param <V>
+ */
+ static class PairToValueFunction<K, V> implements Function<Tuple2<K, V>, V> {
+ /** {@inheritDoc} */
+ @Override public V call(Tuple2<K, V> t) throws Exception {
+ return t._2();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/384a74c4/modules/spark/src/test/java/org/apache/ignite/testsuites/IgniteRDDTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/java/org/apache/ignite/testsuites/IgniteRDDTestSuite.java b/modules/spark/src/test/java/org/apache/ignite/testsuites/IgniteRDDTestSuite.java
new file mode 100644
index 0000000..a4177f0
--- /dev/null
+++ b/modules/spark/src/test/java/org/apache/ignite/testsuites/IgniteRDDTestSuite.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.spark.JavaEmbeddedIgniteRDDSelfTest;
+import org.apache.ignite.spark.JavaStandaloneIgniteRDDSelfTest;
+
+/**
+ * Test suit for Ignite RDD
+ */
+public class IgniteRDDTestSuite extends TestSuite {
+ /**
+ * @return Java Ignite RDD test suit.
+ * @throws Exception If failed.
+ */
+ public static TestSuite suite() throws Exception {
+ TestSuite suite = new TestSuite("Java Ignite RDD tests (standalone and embedded modes");
+
+ suite.addTest(new TestSuite(JavaEmbeddedIgniteRDDSelfTest.class));
+ suite.addTest(new TestSuite(JavaStandaloneIgniteRDDSelfTest.class));
+
+ return suite;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/384a74c4/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
index d72b577..cca3e8b 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
@@ -469,7 +469,7 @@ public class GridFactorySelfTest extends GridCommonAbstractTest {
String msg = e.getMessage();
if (msg != null &&
- (msg.contains("Default grid instance has already been started.") ||
+ (msg.contains("Default Ignite instance has already been started.") ||
msg.contains("Ignite instance with this name has already been started:")))
info("Caught expected exception: " + msg);
else
[04/17] ignite git commit: ignite-2899 Fixed issues with 'keepBinary'
handling, added test.
Posted by sb...@apache.org.
ignite-2899 Fixed issues with 'keepBinary' handling, added test.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e47440dc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e47440dc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e47440dc
Branch: refs/heads/ignite-3116
Commit: e47440dc2b4a7160fb1e2c2dfba1000df8c57993
Parents: dc97379
Author: sboikov <sb...@gridgain.com>
Authored: Mon May 23 21:08:14 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon May 23 21:08:14 2016 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheAdapter.java | 71 +++-
.../CacheKeepBinaryWithInterceptorTest.java | 419 +++++++++++++++++++
.../testsuites/IgniteBinaryCacheTestSuite.java | 2 +
3 files changed, 471 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e47440dc/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 5aa3448..29ca32c 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
@@ -1392,10 +1392,18 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
long start = statsEnabled ? System.nanoTime() : 0L;
- V val = get(key, !ctx.keepBinary(), false);
+ boolean keeyBinary = ctx.keepBinary();
+
+ if (keeyBinary)
+ key = (K)ctx.toCacheKeyObject(key);
+
+ V val = get(key, !keeyBinary, false);
+
+ if (ctx.config().getInterceptor() != null) {
+ key = keeyBinary ? (K) ctx.unwrapBinaryIfNeeded(key, true, false) : key;
- if (ctx.config().getInterceptor() != null)
val = (V)ctx.config().getInterceptor().onGet(key, val);
+ }
if (statsEnabled)
metrics0().addGetTimeNanos(System.nanoTime() - start);
@@ -1411,18 +1419,22 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
long start = statsEnabled ? System.nanoTime() : 0L;
- if (ctx.keepBinary())
+ boolean keepBinary = ctx.keepBinary();
+
+ if (keepBinary)
key = (K)ctx.toCacheKeyObject(key);
- T2<V, GridCacheVersion> t = (T2<V, GridCacheVersion>)get(key, !ctx.keepBinary(), true);
+ T2<V, GridCacheVersion> t = (T2<V, GridCacheVersion>)get(key, !keepBinary, true);
CacheEntry<K, V> val = t != null ? new CacheEntryImplEx<>(
- ctx.keepBinary() ? (K)ctx.unwrapBinaryIfNeeded(key, true, false) : key,
+ keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key, true, false) : key,
t.get1(),
t.get2())
: null;
if (ctx.config().getInterceptor() != null) {
+ key = keepBinary ? (K) ctx.unwrapBinaryIfNeeded(key, true, false) : key;
+
V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null);
val = (val0 != null) ? new CacheEntryImplEx<>(key, val0, t != null ? t.get2() : null) : null;
@@ -1442,11 +1454,17 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
final long start = statsEnabled ? System.nanoTime() : 0L;
- IgniteInternalFuture<V> fut = getAsync(key, !ctx.keepBinary(), false);
+ final boolean keepBinary = ctx.keepBinary();
+
+ final K key0 = keepBinary ? (K)ctx.toCacheKeyObject(key) : key;
+
+ IgniteInternalFuture<V> fut = getAsync(key, !keepBinary, false);
if (ctx.config().getInterceptor() != null)
fut = fut.chain(new CX1<IgniteInternalFuture<V>, V>() {
@Override public V applyx(IgniteInternalFuture<V> f) throws IgniteCheckedException {
+ K key = keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key0, true, false) : key0;
+
return (V)ctx.config().getInterceptor().onGet(key, f.get());
}
});
@@ -1465,10 +1483,12 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
final long start = statsEnabled ? System.nanoTime() : 0L;
- final K key0 = ctx.keepBinary() ? (K)ctx.toCacheKeyObject(key) : key;
+ final boolean keepBinary = ctx.keepBinary();
+
+ final K key0 = keepBinary ? (K)ctx.toCacheKeyObject(key) : key;
IgniteInternalFuture<T2<V, GridCacheVersion>> fut =
- (IgniteInternalFuture<T2<V, GridCacheVersion>>)getAsync(key0, !ctx.keepBinary(), true);
+ (IgniteInternalFuture<T2<V, GridCacheVersion>>)getAsync(key0, !keepBinary, true);
final boolean intercept = ctx.config().getInterceptor() != null;
@@ -1478,19 +1498,21 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
throws IgniteCheckedException {
T2<V, GridCacheVersion> t = f.get();
- CacheEntry val = t != null ? new CacheEntryImplEx<>(
- ctx.keepBinary() ? (K)ctx.unwrapBinaryIfNeeded(key0, true, false) : key0,
- t.get1(),
- t.get2())
- : null;
+ K key = keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key0, true, false) : key0;
- if (intercept) {
- V val0 = (V)ctx.config().getInterceptor().onGet(key0, t != null ? val.getValue() : null);
+ CacheEntry val = t != null ? new CacheEntryImplEx<>(
+ key,
+ t.get1(),
+ t.get2())
+ : null;
- return val0 != null ? new CacheEntryImplEx(key0, val0, t != null ? t.get2() : null) : null;
- }
- else
- return val;
+ if (intercept) {
+ V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null);
+
+ return val0 != null ? new CacheEntryImplEx(key, val0, t != null ? t.get2() : null) : null;
+ }
+ else
+ return val;
}
});
@@ -2889,16 +2911,23 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
if (keyCheck)
validateCacheKey(key);
+ final boolean keepBinary = ctx.keepBinary();
+
V prevVal = syncOp(new SyncOp<V>(true) {
@Override public V op(IgniteTxLocalAdapter tx) throws IgniteCheckedException {
+ K key0 = keepBinary ? (K)ctx.toCacheKeyObject(key) : key;
+
V ret = tx.removeAllAsync(ctx,
- Collections.singletonList(key),
+ Collections.singletonList(key0),
/*retval*/true,
CU.empty0(),
/*singleRmv*/false).get().value();
- if (ctx.config().getInterceptor() != null)
+ if (ctx.config().getInterceptor() != null) {
+ K key = keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key0, true, false) : key0;
+
return (V)ctx.config().getInterceptor().onBeforeRemove(new CacheEntryImpl(key, ret)).get2();
+ }
return ret;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e47440dc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/CacheKeepBinaryWithInterceptorTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/CacheKeepBinaryWithInterceptorTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/CacheKeepBinaryWithInterceptorTest.java
new file mode 100644
index 0000000..60b48a8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/CacheKeepBinaryWithInterceptorTest.java
@@ -0,0 +1,419 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.binary;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheInterceptor;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+import javax.cache.Cache;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+
+/**
+ *
+ */
+@SuppressWarnings("unchecked")
+public class CacheKeepBinaryWithInterceptorTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+ cfg.setMarshaller(null);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ startGrid(0);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testKeepBinaryWithInterceptor() throws Exception {
+ keepBinaryWithInterceptor(cacheConfiguration(ATOMIC, false));
+ keepBinaryWithInterceptor(cacheConfiguration(TRANSACTIONAL, false));
+
+ keepBinaryWithInterceptorPrimitives(cacheConfiguration(ATOMIC, true));
+ keepBinaryWithInterceptorPrimitives(cacheConfiguration(TRANSACTIONAL, true));
+
+ startGridsMultiThreaded(1, 3);
+
+ keepBinaryWithInterceptor(cacheConfiguration(ATOMIC, false));
+ keepBinaryWithInterceptor(cacheConfiguration(TRANSACTIONAL, false));
+
+ keepBinaryWithInterceptorPrimitives(cacheConfiguration(ATOMIC, true));
+ keepBinaryWithInterceptorPrimitives(cacheConfiguration(TRANSACTIONAL, true));
+ }
+
+ /**
+ * @param ccfg Cache configuration.
+ */
+ private void keepBinaryWithInterceptor(CacheConfiguration ccfg) {
+ ignite(0).createCache(ccfg);
+
+ try {
+ TestInterceptor1.onAfterRmv = 0;
+ TestInterceptor1.onBeforeRmv = 0;
+ TestInterceptor1.onAfterPut = 0;
+ TestInterceptor1.onBeforePut = 0;
+ TestInterceptor1.onGet = 0;
+
+ IgniteCache cache = ignite(0).cache(null).withKeepBinary();
+
+ IgniteCache asyncCache = cache.withAsync();
+
+ cache.put(new TestKey(1), new TestValue(10));
+
+ cache.put(new TestKey(1), new TestValue(10));
+
+ BinaryObject obj = (BinaryObject)cache.get(new TestKey(1));
+ assertEquals(10, obj.field("val"));
+
+ asyncCache.get(new TestKey(1));
+ obj = (BinaryObject)asyncCache.future().get();
+ assertEquals(10, obj.field("val"));
+
+ Cache.Entry<BinaryObject, BinaryObject> e = (Cache.Entry)cache.getEntry(new TestKey(1));
+ assertEquals(1, e.getKey().field("key"));
+ assertEquals(10, e.getValue().field("val"));
+
+ asyncCache.getEntry(new TestKey(1));
+ e = (Cache.Entry)asyncCache.future().get();
+ assertEquals(1, e.getKey().field("key"));
+ assertEquals(10, e.getValue().field("val"));
+
+ obj = (BinaryObject)cache.getAndRemove(new TestKey(1));
+ assertEquals(10, obj.field("val"));
+
+ cache.put(new TestKey(1), new TestValue(10));
+
+ assertTrue(cache.remove(new TestKey(1)));
+
+ assertTrue(TestInterceptor1.onAfterRmv > 0);
+ assertTrue(TestInterceptor1.onBeforeRmv > 0);
+ assertTrue(TestInterceptor1.onAfterPut > 0);
+ assertTrue(TestInterceptor1.onBeforePut > 0);
+ assertTrue(TestInterceptor1.onGet > 0);
+ }
+ finally {
+ ignite(0).destroyCache(ccfg.getName());
+ }
+ }
+
+ /**
+ * @param ccfg Cache configuration.
+ */
+ private void keepBinaryWithInterceptorPrimitives(CacheConfiguration ccfg) {
+ ignite(0).createCache(ccfg);
+
+ try {
+ TestInterceptor2.onAfterRmv = 0;
+ TestInterceptor2.onBeforeRmv = 0;
+ TestInterceptor2.onAfterPut = 0;
+ TestInterceptor2.onBeforePut = 0;
+ TestInterceptor2.onGet = 0;
+
+ IgniteCache cache = ignite(0).cache(null).withKeepBinary();
+
+ IgniteCache asyncCache = cache.withAsync();
+
+ cache.put(1, 10);
+
+ cache.put(1, 10);
+
+ Integer obj = (Integer)cache.get(1);
+ assertEquals((Integer)10, obj);
+
+ asyncCache.get(1);
+ obj = (Integer)asyncCache.future().get();
+ assertEquals((Integer)10, obj);
+
+ Cache.Entry<Integer, Integer> e = (Cache.Entry)cache.getEntry(1);
+ assertEquals((Integer)1, e.getKey());
+ assertEquals((Integer)10, e.getValue());
+
+ asyncCache.getEntry(1);
+ e = (Cache.Entry)asyncCache.future().get();
+ assertEquals((Integer)1, e.getKey());
+ assertEquals((Integer)10, e.getValue());
+
+ obj = (Integer)cache.getAndRemove(1);
+ assertEquals((Integer)10, obj);
+
+ cache.put(1, 10);
+
+ assertTrue(cache.remove(1));
+
+ assertTrue(TestInterceptor2.onAfterRmv > 0);
+ assertTrue(TestInterceptor2.onBeforeRmv > 0);
+ assertTrue(TestInterceptor2.onAfterPut > 0);
+ assertTrue(TestInterceptor2.onBeforePut > 0);
+ assertTrue(TestInterceptor2.onGet > 0);
+ }
+ finally {
+ ignite(0).destroyCache(ccfg.getName());
+ }
+ }
+
+ /**
+ * @param atomicityMode Cache atomicity mode.
+ * @param testPrimitives {@code True} if test interceptor with primitive values.
+ * @return Cache configuration.
+ */
+ private CacheConfiguration cacheConfiguration(CacheAtomicityMode atomicityMode, boolean testPrimitives) {
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setAtomicityMode(atomicityMode);
+ ccfg.setInterceptor(testPrimitives ? new TestInterceptor2() : new TestInterceptor1());
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+ ccfg.setBackups(1);
+
+ return ccfg;
+ }
+
+ /**
+ *
+ */
+ static class TestInterceptor1 implements CacheInterceptor<BinaryObject, BinaryObject> {
+ /** */
+ static int onGet;
+
+ /** */
+ static int onBeforePut;
+
+ /** */
+ static int onAfterPut;
+
+ /** */
+ static int onBeforeRmv;
+
+ /** */
+ static int onAfterRmv;
+
+ /** {@inheritDoc} */
+ @Nullable @Override public BinaryObject onGet(BinaryObject key, @Nullable BinaryObject val) {
+ System.out.println("Get [key=" + key + ", val=" + val + ']');
+
+ onGet++;
+
+ assertEquals(1, key.field("key"));
+ assertEquals(10, val.field("val"));
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public BinaryObject onBeforePut(Cache.Entry<BinaryObject, BinaryObject> entry, BinaryObject newVal) {
+ System.out.println("Before put [e=" + entry + ", newVal=" + newVal + ']');
+
+ onBeforePut++;
+
+ if (entry.getValue() != null)
+ assertEquals(10, entry.getValue().field("val"));
+
+ assertEquals(1, entry.getKey().field("key"));
+ assertEquals(10, newVal.field("val"));
+
+ return newVal;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onAfterPut(Cache.Entry<BinaryObject, BinaryObject> entry) {
+ System.out.println("After put [e=" + entry + ']');
+
+ onAfterPut++;
+
+ assertEquals(1, entry.getKey().field("key"));
+ assertEquals(10, entry.getValue().field("val"));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public IgniteBiTuple<Boolean, BinaryObject> onBeforeRemove(Cache.Entry<BinaryObject, BinaryObject> entry) {
+ assertEquals(1, entry.getKey().field("key"));
+ assertEquals(10, entry.getValue().field("val"));
+
+ onBeforeRmv++;
+
+ return new IgniteBiTuple<>(false, entry.getValue());
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onAfterRemove(Cache.Entry<BinaryObject, BinaryObject> entry) {
+ System.out.println("After remove [e=" + entry + ']');
+
+ onAfterRmv++;
+
+ assertEquals(1, entry.getKey().field("key"));
+ assertEquals(10, entry.getValue().field("val"));
+ }
+ }
+
+ /**
+ *
+ */
+ static class TestInterceptor2 implements CacheInterceptor<Integer, Integer> {
+ /** */
+ static int onGet;
+
+ /** */
+ static int onBeforePut;
+
+ /** */
+ static int onAfterPut;
+
+ /** */
+ static int onBeforeRmv;
+
+ /** */
+ static int onAfterRmv;
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Integer onGet(Integer key, @Nullable Integer val) {
+ System.out.println("Get [key=" + key + ", val=" + val + ']');
+
+ onGet++;
+
+ assertEquals((Integer)1, key);
+ assertEquals((Integer)10, val);
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Integer onBeforePut(Cache.Entry<Integer, Integer> entry, Integer newVal) {
+ System.out.println("Before put [e=" + entry + ", newVal=" + newVal + ']');
+
+ onBeforePut++;
+
+ if (entry.getValue() != null)
+ assertEquals((Integer)10, entry.getValue());
+
+ assertEquals((Integer)1, entry.getKey());
+ assertEquals((Integer)10, newVal);
+
+ return newVal;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onAfterPut(Cache.Entry<Integer, Integer> entry) {
+ System.out.println("After put [e=" + entry + ']');
+
+ onAfterPut++;
+
+ assertEquals((Integer)1, entry.getKey());
+ assertEquals((Integer)10, entry.getValue());
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public IgniteBiTuple<Boolean, Integer> onBeforeRemove(Cache.Entry<Integer, Integer> entry) {
+ assertEquals((Integer)1, entry.getKey());
+ assertEquals((Integer)10, entry.getValue());
+
+ onBeforeRmv++;
+
+ return new IgniteBiTuple<>(false, entry.getValue());
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onAfterRemove(Cache.Entry<Integer, Integer> entry) {
+ System.out.println("After remove [e=" + entry + ']');
+
+ onAfterRmv++;
+
+ assertEquals((Integer)1, entry.getKey());
+ assertEquals((Integer)10, entry.getValue());
+ }
+ }
+
+ /**
+ *
+ */
+ static class TestKey {
+ /** */
+ private int key;
+
+ /**
+ * @param key Key.
+ */
+ public TestKey(int key) {
+ this.key = key;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestKey testKey = (TestKey)o;
+
+ return key == testKey.key;
+
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return key;
+ }
+ }
+
+ /**
+ *
+ */
+ static class TestValue {
+ /** */
+ private int val;
+
+ /**
+ * @param val Value.
+ */
+ public TestValue(int val) {
+ this.val = val;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e47440dc/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheTestSuite.java
index 69ca67e..2668598 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheTestSuite.java
@@ -27,6 +27,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredAtomicS
import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionAtomicSelfTest;
import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.CacheKeepBinaryWithInterceptorTest;
import org.apache.ignite.internal.processors.cache.expiry.IgniteCacheAtomicLocalExpiryPolicyTest;
import org.apache.ignite.internal.processors.cache.binary.GridBinaryCacheEntryMemorySizeSelfTest;
import org.apache.ignite.internal.processors.cache.binary.datastreaming.DataStreamProcessorBinarySelfTest;
@@ -97,6 +98,7 @@ public class IgniteBinaryCacheTestSuite extends TestSuite {
suite.addTestSuite(GridCacheAffinityRoutingBinarySelfTest.class);
suite.addTestSuite(GridBinaryCacheEntryMemorySizeSelfTest.class);
+ suite.addTestSuite(CacheKeepBinaryWithInterceptorTest.class);
return suite;
}
[11/17] ignite git commit: IGNITE-2538 - IgniteRDD count() and
isEmpty() method use IgniteCache API
Posted by sb...@apache.org.
IGNITE-2538 - IgniteRDD count() and isEmpty() method use IgniteCache API
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e98dc920
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e98dc920
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e98dc920
Branch: refs/heads/ignite-3116
Commit: e98dc920a9a5a504669571f5cc83814a1d7dbc86
Parents: 78be02f
Author: MaBiao <ma...@gmail.com>
Authored: Wed May 25 12:54:40 2016 +0300
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Wed May 25 12:59:02 2016 +0300
----------------------------------------------------------------------
.../org/apache/ignite/spark/IgniteRDD.scala | 20 +++++++++++++++
.../org/apache/ignite/spark/IgniteRDDSpec.scala | 27 ++++++++++++++++++++
2 files changed, 47 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e98dc920/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala b/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
index 9112040..0d8e730 100644
--- a/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
+++ b/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
@@ -95,6 +95,26 @@ class IgniteRDD[K, V] (
}
/**
+ * Tells whether this IgniteRDD is empty or not.
+ *
+ * @return Whether this IgniteRDD is empty or not.
+ */
+ override def isEmpty(): Boolean = {
+ count() == 0
+ }
+
+ /**
+ * Gets number of tuples in this IgniteRDD.
+ *
+ * @return Number of tuples in this IgniteRDD.
+ */
+ override def count(): Long = {
+ val cache = ensureCache()
+
+ cache.size()
+ }
+
+ /**
* Runs an object SQL on corresponding Ignite cache.
*
* @param typeName Type name to run SQL against.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e98dc920/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala b/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
index 071897a..4cc539b 100644
--- a/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
+++ b/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
@@ -165,6 +165,33 @@ class IgniteRDDSpec extends FunSpec with Matchers with BeforeAndAfterAll with Be
sc.stop()
}
}
+
+ it("should properly count RDD size") {
+ val sc = new SparkContext("local[*]", "test")
+
+ try {
+ val ic = new IgniteContext[Integer, WithObjectField](sc,
+ () \u21d2 configuration("client", client = true))
+
+ val cache: IgniteRDD[Integer, WithObjectField] = ic.fromCache(PARTITIONED_CACHE_NAME)
+
+ assert(cache.count() == 0)
+ assert(cache.isEmpty())
+
+ cache.savePairs(sc.parallelize(0 until 1000, 2).map(i \u21d2 (i:java.lang.Integer, new WithObjectField(i, new Entity(i, "", i)))))
+
+ assert(cache.count() == 1000)
+ assert(!cache.isEmpty())
+
+ cache.clear()
+
+ assert(cache.count() == 0)
+ assert(cache.isEmpty())
+ }
+ finally {
+ sc.stop()
+ }
+ }
}
override protected def beforeEach() = {
[17/17] ignite git commit: ignite-3116 Cancel force key futures when
node stops
Posted by sb...@apache.org.
ignite-3116 Cancel force key futures when node stops
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a9fa8b3d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a9fa8b3d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a9fa8b3d
Branch: refs/heads/ignite-3116
Commit: a9fa8b3d1adba0fb9e64637782c6d3ceb36ca865
Parents: fc3b154
Author: sboikov <sb...@gridgain.com>
Authored: Thu May 26 09:28:59 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Thu May 26 09:28:59 2016 +0300
----------------------------------------------------------------------
.../processors/cache/distributed/dht/GridDhtCacheAdapter.java | 7 +++++++
.../processors/cache/distributed/dht/GridDhtGetFuture.java | 3 ---
2 files changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/a9fa8b3d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
index 26800ad..a74cf26 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
@@ -35,6 +35,7 @@ import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.NodeStoppingException;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.CacheObject;
import org.apache.ignite.internal.processors.cache.CacheOperationContext;
@@ -791,6 +792,9 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
req.addDeploymentInfo());
}
}
+ catch (NodeStoppingException e) {
+ return;
+ }
catch (IgniteCheckedException e) {
U.error(log, "Failed processing get request: " + req, e);
@@ -856,6 +860,9 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
res.entries(entries);
}
+ catch (NodeStoppingException e) {
+ return;
+ }
catch (IgniteCheckedException e) {
U.error(log, "Failed processing get request: " + req, e);
http://git-wip-us.apache.org/repos/asf/ignite/blob/a9fa8b3d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java
index 4d4c303..cae1dda 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java
@@ -182,9 +182,6 @@ public final class GridDhtGetFuture<K, V> extends GridCompoundIdentityFuture<Col
try {
fut.get();
}
- catch (NodeStoppingException e) {
- return;
- }
catch (IgniteCheckedException e) {
if (log.isDebugEnabled())
log.debug("Failed to request keys from preloader [keys=" + keys + ", err=" + e + ']');
[09/17] ignite git commit: IGNITE-3168 Added idle timeout property.
Posted by sb...@apache.org.
IGNITE-3168 Added idle timeout property.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/327f0dd6
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/327f0dd6
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/327f0dd6
Branch: refs/heads/ignite-3116
Commit: 327f0dd6745c0f274df7d5f99c30694f533fd309
Parents: a0141a4
Author: nikolay_tikhonov <nt...@gridgain.com>
Authored: Wed May 25 09:47:14 2016 +0300
Committer: nikolay_tikhonov <nt...@gridgain.com>
Committed: Wed May 25 09:47:14 2016 +0300
----------------------------------------------------------------------
.../apache/ignite/mesos/ClusterProperties.java | 39 ++++++++++++++++++++
.../apache/ignite/mesos/IgniteFramework.java | 10 ++---
.../ignite/mesos/resource/JettyServer.java | 16 ++++++--
3 files changed, 55 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/327f0dd6/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
index 747fbe9..3c8f396 100644
--- a/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
@@ -200,6 +200,15 @@ public class ClusterProperties {
/** */
public static final String IGNITE_CONFIG_XML_URL = "IGNITE_CONFIG_XML_URL";
+ /** */
+ public static final String IGNITE_HTTP_SERVER_IDLE_TIMEOUT = "IGNITE_HTTP_SERVER_IDLE_TIMEOUT";
+
+ /** */
+ public static final long IGNITE_HTTP_SERVER_IDLE_TIMEOUT_DEFAULT = 30000L;
+
+ /** Jetty idle timeout. */
+ private long idleTimeout = IGNITE_HTTP_SERVER_IDLE_TIMEOUT_DEFAULT;
+
/** Url to ignite config. */
private String igniteCfgUrl = null;
@@ -400,6 +409,17 @@ public class ClusterProperties {
}
/**
+ * Sets the maximum Idle time for a http connection, which will be used for
+ * jetty server. The server provides resources for ignite mesos framework such as
+ * ignite archive, user's libs, configurations and etc.
+ *
+ * @return Http server idle timeout.
+ */
+ public long idleTimeout() {
+ return idleTimeout;
+ }
+
+ /**
* URL to ignite package. The URL should to point at valid apache ignite archive.
* This property can be useful if using own apache ignite build.
*
@@ -502,6 +522,8 @@ public class ClusterProperties {
String ptrn = getStringProperty(IGNITE_HOSTNAME_CONSTRAINT, props, null);
+ prop.idleTimeout = getLongProperty(IGNITE_HTTP_SERVER_IDLE_TIMEOUT, props, IGNITE_HTTP_SERVER_IDLE_TIMEOUT_DEFAULT);
+
if (ptrn != null) {
try {
prop.hostnameConstraint = Pattern.compile(ptrn);
@@ -540,6 +562,23 @@ public class ClusterProperties {
* @param fileProps Property file.
* @return Property value.
*/
+ private static long getLongProperty(String name, Properties fileProps, Long dfltVal) {
+ if (fileProps != null && fileProps.containsKey(name))
+ return Long.valueOf(fileProps.getProperty(name));
+
+ String prop = System.getProperty(name);
+
+ if (prop == null)
+ prop = System.getenv(name);
+
+ return prop == null ? dfltVal : Long.valueOf(prop);
+ }
+
+ /**
+ * @param name Property name.
+ * @param fileProps Property file.
+ * @return Property value.
+ */
private static String getStringProperty(String name, Properties fileProps, String dfltVal) {
if (fileProps != null && fileProps.containsKey(name))
return fileProps.getProperty(name);
http://git-wip-us.apache.org/repos/asf/ignite/blob/327f0dd6/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteFramework.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteFramework.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteFramework.java
index 0cd9efb..6054302 100644
--- a/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteFramework.java
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteFramework.java
@@ -18,8 +18,6 @@
package org.apache.ignite.mesos;
import com.google.protobuf.ByteString;
-import java.net.InetSocketAddress;
-import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.ignite.mesos.resource.IgniteProvider;
@@ -35,10 +33,10 @@ import org.apache.mesos.Scheduler;
*/
public class IgniteFramework {
/** */
- public static final Logger log = Logger.getLogger(IgniteFramework.class.getSimpleName());
+ private static final Logger log = Logger.getLogger(IgniteFramework.class.getSimpleName());
/** Framework name. */
- public static final String IGNITE_FRAMEWORK_NAME = "Ignite";
+ private static final String IGNITE_FRAMEWORK_NAME = "Ignite";
/**
* Main methods has only one optional parameter - path to properties files.
@@ -68,8 +66,8 @@ public class IgniteFramework {
JettyServer httpSrv = new JettyServer();
httpSrv.start(
- new InetSocketAddress(clusterProps.httpServerHost(), clusterProps.httpServerPort()),
- new ResourceHandler(clusterProps.userLibs(), clusterProps.igniteCfg(), clusterProps.igniteWorkDir())
+ new ResourceHandler(clusterProps.userLibs(), clusterProps.igniteCfg(), clusterProps.igniteWorkDir()),
+ clusterProps
);
ResourceProvider provider = new ResourceProvider();
http://git-wip-us.apache.org/repos/asf/ignite/blob/327f0dd6/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/JettyServer.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/JettyServer.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/JettyServer.java
index 444c751..f1f5189 100644
--- a/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/JettyServer.java
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/JettyServer.java
@@ -17,9 +17,10 @@
package org.apache.ignite.mesos.resource;
-import java.net.InetSocketAddress;
+import org.apache.ignite.mesos.ClusterProperties;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
/**
* Embedded jetty server.
@@ -31,14 +32,21 @@ public class JettyServer {
/**
* Starts jetty server.
*
- * @param address Inter socket address.
* @param handler Handler.
+ * @param props Cluster properties.
* @throws Exception If failed.
*/
- public void start(InetSocketAddress address, Handler handler) throws Exception {
+ public void start(Handler handler, ClusterProperties props) throws Exception {
if (server == null) {
- server = new Server(address);
+ server = new Server();
+ ServerConnector connector = new ServerConnector(server);
+
+ connector.setHost(props.httpServerHost());
+ connector.setPort(props.httpServerPort());
+ connector.setIdleTimeout(props.idleTimeout());
+
+ server.addConnector(connector);
server.setHandler(handler);
server.start();
[05/17] ignite git commit: ignite-2620 Fixed entry expiration
handling (cherry picked from commit 46892c7)
Posted by sb...@apache.org.
ignite-2620 Fixed entry expiration handling
(cherry picked from commit 46892c7)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/69a0afa7
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/69a0afa7
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/69a0afa7
Branch: refs/heads/ignite-3116
Commit: 69a0afa79d2bb175908f7aaf53a1f45915477e99
Parents: e47440d
Author: sboikov <sb...@gridgain.com>
Authored: Tue May 24 00:07:05 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Tue May 24 00:22:06 2016 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheEntryEx.java | 5 +-
.../processors/cache/GridCacheMapEntry.java | 393 +++++++++--------
.../processors/cache/GridCacheSwapManager.java | 11 +-
.../processors/cache/GridCacheTtlManager.java | 21 +-
.../distributed/dht/GridDhtLocalPartition.java | 2 +-
.../continuous/CacheContinuousQueryManager.java | 5 +-
...niteCacheExpireAndUpdateConsistencyTest.java | 437 +++++++++++++++++++
.../IgniteCacheExpiryPolicyAbstractTest.java | 3 +-
.../IgniteCacheExpiryPolicyTestSuite.java | 3 +
.../CacheOperationsWithExpirationTest.java | 355 +++++++++++++++
.../cache/GridCacheOffheapIndexGetSelfTest.java | 48 ++
.../IgniteCacheWithIndexingTestSuite.java | 2 +
12 files changed, 1088 insertions(+), 197 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
index 73a9dbf..31bd887 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
@@ -912,9 +912,10 @@ public interface GridCacheEntryEx {
* Callback from ttl processor to cache entry indicating that entry is expired.
*
* @param obsoleteVer Version to set obsolete if entry is expired.
- * @return {@code True} if this entry was obsolete or became obsolete as a result of this call.
+ * @throws GridCacheEntryRemovedException If entry was removed.
+ * @return {@code True} if this entry was expired as a result of this call.
*/
- public boolean onTtlExpired(GridCacheVersion obsoleteVer);
+ public boolean onTtlExpired(GridCacheVersion obsoleteVer) throws GridCacheEntryRemovedException;
/**
* @return Time to live, without accounting for transactions or removals.
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index 72e2ddd..480403e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -479,6 +479,12 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
return unswap(true);
}
+ /** {@inheritDoc} */
+ @Nullable @Override public CacheObject unswap(boolean needVal)
+ throws IgniteCheckedException, GridCacheEntryRemovedException {
+ return unswap(needVal, true);
+ }
+
/**
* Unswaps an entry.
*
@@ -486,13 +492,15 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
* @return Value.
* @throws IgniteCheckedException If failed.
*/
- @Nullable @Override public CacheObject unswap(boolean needVal)
+ @Nullable private CacheObject unswap(boolean needVal, boolean checkExpire)
throws IgniteCheckedException, GridCacheEntryRemovedException {
- boolean swapEnabled = cctx.swap().swapEnabled();
-
- if (!swapEnabled && !cctx.isOffHeapEnabled())
+ if (!cctx.isSwapOrOffheapEnabled())
return null;
+ boolean obsolete = false;
+ boolean deferred = false;
+ GridCacheVersion ver0 = null;
+
synchronized (this) {
checkObsolete();
@@ -509,7 +517,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
flags |= IS_OFFHEAP_PTR_MASK;
if (needVal) {
- CacheObject val = cctx.fromOffheap(offHeapPointer(), false);
+ CacheObject val = cctx.fromOffheap(e.offheapPointer(), false);
e.value(val);
}
@@ -528,28 +536,49 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
// If there is a value.
if (e != null) {
- long delta = e.expireTime() == 0 ? 0 : e.expireTime() - U.currentTimeMillis();
+ long delta = checkExpire ? (e.expireTime() == 0 ? 0 : e.expireTime() - U.currentTimeMillis()) : 0;
- if (delta >= 0) {
- CacheObject val = e.value();
+ CacheObject val = e.value();
- val = cctx.kernalContext().cacheObjects().prepareForCache(val, cctx);
+ val = cctx.kernalContext().cacheObjects().prepareForCache(val, cctx);
- // Set unswapped value.
- update(val, e.expireTime(), e.ttl(), e.version(), false);
+ // Set unswapped value.
+ update(val, e.expireTime(), e.ttl(), e.version(), false);
- // Must update valPtr again since update() will reset it.
- if (cctx.offheapTiered() && e.offheapPointer() > 0)
- offHeapPointer(e.offheapPointer());
+ // Must update valPtr again since update() will reset it.
+ if (cctx.offheapTiered() && e.offheapPointer() > 0)
+ offHeapPointer(e.offheapPointer());
+ if (delta >= 0)
return val;
+ else {
+ CacheObject expiredVal = rawGetOrUnmarshal(false);
+
+ if (onExpired(expiredVal, null)) {
+ if (cctx.deferredDelete()) {
+ deferred = true;
+ ver0 = ver;
+ }
+ else
+ obsolete = true;
+ }
}
- else
- clearIndex(e.value());
}
}
}
+ if (obsolete) {
+ onMarkedObsolete();
+
+ cctx.cache().removeEntry(this);
+ }
+
+ if (deferred) {
+ assert ver0 != null;
+
+ cctx.onDeferredDelete(this, ver0);
+ }
+
return null;
}
@@ -562,20 +591,9 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (cctx.isSwapOrOffheapEnabled() && !deletedUnlocked() && (hasValueUnlocked() || swapNeeded) && !detached()) {
assert Thread.holdsLock(this);
- long expireTime = expireTimeExtras();
+ boolean offheapPtr = hasOffHeapPointer();
- if (expireTime > 0 && U.currentTimeMillis() >= expireTime) { // Don't swap entry if it's expired.
- // Entry might have been updated.
- if (cctx.offheapTiered()) {
- cctx.swap().removeOffheap(key);
-
- offHeapPointer(0);
- }
-
- return;
- }
-
- if (cctx.offheapTiered() && hasOffHeapPointer() && !swapNeeded) {
+ if (cctx.offheapTiered() && offheapPtr && !swapNeeded) {
if (log.isDebugEnabled())
log.debug("Value did not change, skip write swap entry: " + this);
@@ -605,9 +623,10 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
valBytes.get2(),
ver,
ttlExtras(),
- expireTime,
+ expireTimeExtras(),
keyClsLdrId,
- valClsLdrId);
+ valClsLdrId,
+ !offheapPtr);
flags &= ~IS_SWAPPING_REQUIRED;
@@ -646,9 +665,9 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
*/
protected final void releaseSwap() throws IgniteCheckedException {
if (cctx.isSwapOrOffheapEnabled()) {
- synchronized (this) {
- cctx.swap().remove(key());
- }
+ assert Thread.holdsLock(this);
+
+ cctx.swap().remove(key(), partition());
if (log.isDebugEnabled())
log.debug("Removed swap entry [entry=" + this + ']');
@@ -758,132 +777,74 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
GridCacheMvccCandidate owner;
- CacheObject old;
- CacheObject ret = null;
+ CacheObject ret;
GridCacheVersion startVer;
GridCacheVersion resVer = null;
- boolean expired = false;
-
- CacheObject expiredVal = null;
-
- boolean hasOldBytes;
+ boolean obsolete = false;
+ boolean deferred = false;
+ GridCacheVersion ver0 = null;
synchronized (this) {
checkObsolete();
- // Cache version for optimistic check.
- startVer = ver;
-
GridCacheMvcc mvcc = mvccExtras();
owner = mvcc == null ? null : mvcc.anyOwner();
- double delta;
-
- long expireTime = expireTimeExtras();
-
- if (expireTime > 0) {
- delta = expireTime - U.currentTimeMillis();
-
- if (log.isDebugEnabled())
- log.debug("Checked expiration time for entry [timeLeft=" + delta + ", entry=" + this + ']');
-
- if (delta <= 0)
- expired = true;
- }
-
- CacheObject val = this.val;
+ boolean valid = valid(tx != null ? tx.topologyVersion() : cctx.affinity().affinityTopologyVersion());
- hasOldBytes = hasOffHeapPointer();
+ CacheObject val;
- if ((unmarshal || isOffHeapValuesOnly()) && !expired && val == null && hasOldBytes)
+ if (valid) {
val = rawGetOrUnmarshalUnlocked(tmp);
- boolean valid = valid(tx != null ? tx.topologyVersion() : cctx.affinity().affinityTopologyVersion());
-
- // Attempt to load from swap.
- if (val == null && !hasOldBytes && readSwap) {
- // Only promote when loading initial state.
- if (isNew() || !valid) {
- // If this entry is already expired (expiration time was too low),
- // we simply remove from swap and clear index.
- if (expired) {
- releaseSwap();
-
- // Previous value is guaranteed to be null
- clearIndex(null);
- }
- else {
- // Read and remove swap entry.
+ if (val == null && readSwap) {
+ if (isStartVersion()) {
if (tmp) {
- unswap(false);
+ unswap(false, false);
val = rawGetOrUnmarshalUnlocked(true);
}
else
- val = unswap();
+ val = unswap(true, false);
+ }
+ }
- // Recalculate expiration after swap read.
- if (expireTime > 0) {
- delta = expireTime - U.currentTimeMillis();
+ if (val != null) {
+ long expireTime = expireTimeExtras();
- if (log.isDebugEnabled())
- log.debug("Checked expiration time for entry [timeLeft=" + delta +
- ", entry=" + this + ']');
+ if (expireTime > 0 && (expireTime - U.currentTimeMillis() <= 0)) {
+ if (onExpired((CacheObject)cctx.unwrapTemporary(val), null)) {
+ val = null;
+ evt = false;
- if (delta <= 0)
- expired = true;
+ if (cctx.deferredDelete()) {
+ deferred = true;
+ ver0 = ver;
+ }
+ else
+ obsolete = true;
}
}
}
}
+ else
+ val = null;
- old = expired || !valid ? null : val;
-
- if (expired) {
- expiredVal = val;
+ ret = val;
- value(null);
- }
-
- if (old == null && !hasOldBytes) {
+ if (ret == null) {
if (updateMetrics && cctx.cache().configuration().isStatisticsEnabled())
cctx.cache().metrics0().onRead(false);
}
else {
if (updateMetrics && cctx.cache().configuration().isStatisticsEnabled())
cctx.cache().metrics0().onRead(true);
-
- // Set retVal here for event notification.
- ret = old;
- }
-
- if (evt && expired) {
- if (cctx.events().isRecordable(EVT_CACHE_OBJECT_EXPIRED)) {
- cctx.events().addEvent(partition(),
- key,
- tx,
- owner,
- EVT_CACHE_OBJECT_EXPIRED,
- null,
- false,
- expiredVal,
- expiredVal != null || hasOldBytes,
- subjId,
- null,
- taskName,
- keepBinary);
- }
-
- cctx.continuousQueries().onEntryExpired(this, key, expiredVal);
-
- // No more notifications.
- evt = false;
}
- if (evt && !expired && cctx.events().isRecordable(EVT_CACHE_OBJECT_READ)) {
+ if (evt && cctx.events().isRecordable(EVT_CACHE_OBJECT_READ)) {
cctx.events().addEvent(
partition(),
key,
@@ -892,8 +853,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
EVT_CACHE_OBJECT_READ,
ret,
ret != null,
- old,
- hasOldBytes || old != null,
+ ret,
+ ret != null,
subjId,
transformClo != null ? transformClo.getClass().getName() : null,
taskName,
@@ -912,18 +873,30 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (resVer == null)
ret = null;
}
+
+ // Cache version for optimistic check.
+ startVer = ver;
}
if (ret != null) {
assert tmp || !(ret instanceof BinaryObjectOffheapImpl);
+ assert !obsolete;
+ assert !deferred;
// If return value is consistent, then done.
return retVer ? new T2<>(ret, resVer) : ret;
}
- boolean loadedFromStore = false;
+ if (obsolete) {
+ onMarkedObsolete();
+
+ throw new GridCacheEntryRemovedException();
+ }
+
+ if (deferred)
+ cctx.onDeferredDelete(this, ver0);
- if (ret == null && readThrough) {
+ if (readThrough) {
IgniteInternalTx tx0 = null;
if (tx != null && tx.local()) {
@@ -939,10 +912,11 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
Object storeVal = readThrough(tx0, key, false, subjId, taskName);
ret = cctx.toCacheObject(storeVal);
-
- loadedFromStore = true;
}
+ if (ret == null && !evt)
+ return null;
+
synchronized (this) {
long ttl = ttlExtras();
@@ -958,9 +932,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
long expTime = CU.toExpireTime(ttl);
- if (loadedFromStore)
- // Update indexes before actual write to entry.
- updateIndex(ret, expTime, nextVer, prevVal);
+ // Update indexes before actual write to entry.
+ updateIndex(ret, expTime, nextVer, prevVal);
boolean hadValPtr = hasOffHeapPointer();
@@ -982,8 +955,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
EVT_CACHE_OBJECT_READ,
ret,
ret != null,
- old,
- hasOldBytes,
+ null,
+ false,
subjId,
transformClo != null ? transformClo.getClass().getName() : null,
taskName,
@@ -1143,7 +1116,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
boolean startVer = isStartVersion();
if (startVer)
- unswap(retval);
+ unswap(retval, false);
newVer = explicitVer != null ? explicitVer : tx == null ?
nextVersion() : tx.writeVersion();
@@ -1555,7 +1528,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
// Load and remove from swap if it is new.
if (isNew())
- unswap(retval);
+ unswap(retval, false);
// Possibly get old value form store.
old = needVal ? rawGetOrUnmarshalUnlocked(!retval && !isOffHeapValuesOnly()) : val;
@@ -1918,8 +1891,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
checkObsolete();
// Load and remove from swap if it is new.
- if (isNew())
- unswap(retval);
+ if (isStartVersion())
+ unswap(retval, false);
Object transformClo = null;
@@ -2777,19 +2750,31 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
}
/** {@inheritDoc} */
- @Override public boolean markObsoleteIfEmpty(@Nullable GridCacheVersion ver) throws IgniteCheckedException {
+ @Override public boolean markObsoleteIfEmpty(@Nullable GridCacheVersion obsoleteVer) throws IgniteCheckedException {
boolean obsolete = false;
boolean deferred = false;
+ GridCacheVersion ver0 = null;
try {
synchronized (this) {
if (obsoleteVersionExtras() != null)
return false;
- if (!hasValueUnlocked() || checkExpired()) {
- if (ver == null)
- ver = nextVersion();
+ if (hasValueUnlocked()) {
+ long expireTime = expireTimeExtras();
+ if (expireTime > 0 && (expireTime - U.currentTimeMillis() <= 0)) {
+ if (onExpired(rawGetOrUnmarshal(false), obsoleteVer)) {
+ if (cctx.deferredDelete()) {
+ deferred = true;
+ ver0 = ver;
+ }
+ else
+ obsolete = true;
+ }
+ }
+ }
+ else {
if (cctx.deferredDelete() && !isStartVersion() && !detached() && !isInternal()) {
if (!deletedUnlocked()) {
update(null, 0L, 0L, ver, true);
@@ -2797,10 +2782,15 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
deletedUnlocked(true);
deferred = true;
+ ver0 = ver;
}
}
- else
- obsolete = markObsolete0(ver, true, null);
+ else {
+ if (obsoleteVer == null)
+ obsoleteVer = nextVersion();
+
+ obsolete = markObsolete0(obsoleteVer, true, null);
+ }
}
}
}
@@ -2809,7 +2799,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
onMarkedObsolete();
if (deferred)
- cctx.onDeferredDelete(this, ver);
+ cctx.onDeferredDelete(this, ver0);
}
return obsolete;
@@ -3434,7 +3424,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
throws IgniteCheckedException, GridCacheEntryRemovedException {
boolean isNew = isStartVersion();
- CacheObject val = isNew ? unswap(true) : rawGetOrUnmarshalUnlocked(false);
+ CacheObject val = isNew ? unswap(true, false) : rawGetOrUnmarshalUnlocked(false);
return new GridCachePlainVersionedEntry<>(cctx.unwrapBinaryIfNeeded(key, keepBinary, true),
cctx.unwrapBinaryIfNeeded(val, keepBinary, true),
@@ -3677,57 +3667,34 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
}
/** {@inheritDoc} */
- @Override public boolean onTtlExpired(GridCacheVersion obsoleteVer) {
+ @Override public boolean onTtlExpired(GridCacheVersion obsoleteVer) throws GridCacheEntryRemovedException {
+ assert obsoleteVer != null;
+
boolean obsolete = false;
boolean deferred = false;
GridCacheVersion ver0 = null;
try {
synchronized (this) {
- CacheObject expiredVal = saveOldValueUnlocked(false);
-
- boolean hasOldBytes = hasOffHeapPointer();
-
- boolean expired = checkExpired();
-
- if (expired) {
- if (!obsolete()) {
- if (cctx.deferredDelete() && !detached() && !isInternal()) {
- if (!deletedUnlocked()) {
- update(null, 0L, 0L, ver0 = ver, true);
+ checkObsolete();
- deletedUnlocked(true);
+ if (isStartVersion())
+ unswap(true, false);
- deferred = true;
- }
- }
- else {
- if (markObsolete0(obsoleteVer, true, null))
- obsolete = true; // Success, will return "true".
- }
- }
+ long expireTime = expireTimeExtras();
- clearIndex(expiredVal);
+ if (expireTime == 0 || (expireTime - U.currentTimeMillis() > 0))
+ return false;
- releaseSwap();
+ CacheObject expiredVal = rawGetOrUnmarshal(false);
- if (cctx.events().isRecordable(EVT_CACHE_OBJECT_EXPIRED)) {
- cctx.events().addEvent(partition(),
- key,
- cctx.localNodeId(),
- null,
- EVT_CACHE_OBJECT_EXPIRED,
- null,
- false,
- expiredVal,
- expiredVal != null || hasOldBytes,
- null,
- null,
- null,
- true);
+ if (onExpired(expiredVal, obsoleteVer)) {
+ if (cctx.deferredDelete()) {
+ deferred = true;
+ ver0 = ver;
}
-
- cctx.continuousQueries().onEntryExpired(this, key, expiredVal);
+ else
+ obsolete = true;
}
}
}
@@ -3751,7 +3718,63 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
cctx.cache().metrics0().onEvict();
}
- return obsolete;
+ return true;
+ }
+
+ /**
+ * @param expiredVal Expired value.
+ * @param obsoleteVer Version.
+ * @return {@code True} if entry was marked as removed.
+ * @throws IgniteCheckedException If failed.
+ */
+ private boolean onExpired(CacheObject expiredVal, GridCacheVersion obsoleteVer) throws IgniteCheckedException {
+ assert expiredVal != null;
+
+ boolean rmvd = false;
+
+ if (mvccExtras() != null)
+ return false;
+
+ if (cctx.deferredDelete() && !detached() && !isInternal()) {
+ if (!deletedUnlocked() && !isStartVersion()) {
+ update(null, 0L, 0L, ver, true);
+
+ deletedUnlocked(true);
+
+ rmvd = true;
+ }
+ }
+ else {
+ if (obsoleteVer == null)
+ obsoleteVer = nextVersion();
+
+ if (markObsolete0(obsoleteVer, true, null))
+ rmvd = true;
+ }
+
+ clearIndex(expiredVal);
+
+ releaseSwap();
+
+ if (cctx.events().isRecordable(EVT_CACHE_OBJECT_EXPIRED)) {
+ cctx.events().addEvent(partition(),
+ key,
+ cctx.localNodeId(),
+ null,
+ EVT_CACHE_OBJECT_EXPIRED,
+ null,
+ false,
+ expiredVal,
+ expiredVal != null,
+ null,
+ null,
+ null,
+ true);
+ }
+
+ cctx.continuousQueries().onEntryExpired(this, key, expiredVal);
+
+ return rmvd;
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index 127f1be..a060c8a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -1224,9 +1224,10 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
/**
* @param key Key to remove.
+ * @param part Partition.
* @throws IgniteCheckedException If failed.
*/
- public void remove(final KeyCacheObject key) throws IgniteCheckedException {
+ public void remove(final KeyCacheObject key, int part) throws IgniteCheckedException {
if (!offheapEnabled && !swapEnabled)
return;
@@ -1234,8 +1235,6 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
final GridCacheQueryManager qryMgr = cctx.queries();
- int part = cctx.affinity().partition(key);
-
// First try offheap.
if (offheapEnabled) {
byte[] keyBytes = key.valueBytes(cctx.cacheObjectContext());
@@ -1282,6 +1281,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
* @param expireTime Swap entry expiration time.
* @param keyClsLdrId Class loader ID for entry key.
* @param valClsLdrId Class loader ID for entry value.
+ * @param wasUnswapped {@code True} if currently value is removed from swap.
* @throws IgniteCheckedException If failed.
*/
void write(KeyCacheObject key,
@@ -1291,7 +1291,8 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
long ttl,
long expireTime,
@Nullable IgniteUuid keyClsLdrId,
- @Nullable IgniteUuid valClsLdrId)
+ @Nullable IgniteUuid valClsLdrId,
+ boolean wasUnswapped)
throws IgniteCheckedException {
if (!offheapEnabled && !swapEnabled)
return;
@@ -1323,7 +1324,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
GridCacheQueryManager qryMgr = cctx.queries();
- if (qryMgr.enabled())
+ if (wasUnswapped && qryMgr.enabled())
qryMgr.onSwap(key);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
index 4e1fc6d..3e4561b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
@@ -128,7 +128,26 @@ public class GridCacheTtlManager extends GridCacheManagerAdapter {
if (log.isTraceEnabled())
log.trace("Trying to remove expired entry from cache: " + e);
- e.entry.onTtlExpired(obsoleteVer);
+ GridCacheEntryEx entry = e.entry;
+
+ boolean touch = false;
+
+ while (true) {
+ try {
+ if (entry.onTtlExpired(obsoleteVer))
+ touch = false;
+
+ break;
+ }
+ catch (GridCacheEntryRemovedException e0) {
+ entry = entry.context().cache().entryEx(entry.key());
+
+ touch = true;
+ }
+ }
+
+ if (touch)
+ entry.context().evicts().touch(entry, null);
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
index c4312b5..2c33fa2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
@@ -569,7 +569,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
KeyCacheObject key = cctx.toCacheKeyObject(keyBytes);
- cctx.swap().remove(key);
+ cctx.swap().remove(key, id);
if (isLocStore)
cctx.store().remove(null, key.value(cctx.cacheObjectContext(), false));
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/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 fafb830..b042249 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
@@ -363,8 +363,9 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
if (F.isEmpty(lsnrCol))
return;
- if (cctx.isReplicated() || cctx.affinity().primary(cctx.localNode(), key, AffinityTopologyVersion.NONE)) {
- boolean primary = cctx.affinity().primary(cctx.localNode(), key, AffinityTopologyVersion.NONE);
+ boolean primary = cctx.affinity().primary(cctx.localNode(), e.partition(), AffinityTopologyVersion.NONE);
+
+ if (cctx.isReplicated() || primary) {
boolean recordIgniteEvt = cctx.gridEvents().isRecordable(EVT_CACHE_QUERY_OBJECT_READ);
boolean initialized = false;
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheExpireAndUpdateConsistencyTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheExpireAndUpdateConsistencyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheExpireAndUpdateConsistencyTest.java
new file mode 100644
index 0000000..7f54a83
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheExpireAndUpdateConsistencyTest.java
@@ -0,0 +1,437 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryUpdatedListener;
+import javax.cache.expiry.CreatedExpiryPolicy;
+import javax.cache.expiry.Duration;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteTransactions;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMemoryMode;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.PA;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteInClosure;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
+import static org.apache.ignite.cache.CacheMemoryMode.ONHEAP_TIERED;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+
+/**
+ *
+ */
+public class IgniteCacheExpireAndUpdateConsistencyTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private boolean client;
+
+ /** */
+ private static final int NODES = 5;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+ cfg.setClientMode(client);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ startGridsMultiThreaded(4);
+
+ client = true;
+
+ Ignite client = startGrid(4);
+
+ assertTrue(client.configuration().isClientMode());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAtomic1() throws Exception {
+ updateAndEventConsistencyTest(cacheConfiguration(ATOMIC, ONHEAP_TIERED, 0));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAtomic2() throws Exception {
+ updateAndEventConsistencyTest(cacheConfiguration(ATOMIC, ONHEAP_TIERED, 1));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAtomic3() throws Exception {
+ updateAndEventConsistencyTest(cacheConfiguration(ATOMIC, ONHEAP_TIERED, 2));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAtomicOffheap() throws Exception {
+ updateAndEventConsistencyTest(cacheConfiguration(ATOMIC, OFFHEAP_TIERED, 1));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTx1() throws Exception {
+ updateAndEventConsistencyTest(cacheConfiguration(TRANSACTIONAL, ONHEAP_TIERED, 0));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTx2() throws Exception {
+ updateAndEventConsistencyTest(cacheConfiguration(TRANSACTIONAL, ONHEAP_TIERED, 1));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTx3() throws Exception {
+ updateAndEventConsistencyTest(cacheConfiguration(TRANSACTIONAL, ONHEAP_TIERED, 2));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTxOffheap() throws Exception {
+ updateAndEventConsistencyTest(cacheConfiguration(TRANSACTIONAL, OFFHEAP_TIERED, 1));
+ }
+
+ /**
+ * @param ccfg Cache configuration.
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
+ private void updateAndEventConsistencyTest(CacheConfiguration<TestKey, TestValue> ccfg) throws Exception {
+ ignite(0).createCache(ccfg);
+
+ try {
+ List<ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>>> nodesEvts = new ArrayList<>();
+
+ for (int i = 0; i < NODES; i++) {
+ Ignite ignite = ignite(i);
+
+ IgniteCache<TestKey, TestValue> cache = ignite.cache(ccfg.getName());
+
+ ContinuousQuery<TestKey, TestValue> qry = new ContinuousQuery<>();
+
+ final ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>> allEvts = new ConcurrentHashMap<>();
+
+ qry.setLocalListener(new CacheEntryUpdatedListener<TestKey, TestValue>() {
+ @Override public void onUpdated(Iterable<CacheEntryEvent<? extends TestKey, ? extends TestValue>> evts) {
+ for (CacheEntryEvent<? extends TestKey, ? extends TestValue> e : evts) {
+ List<T2<TestValue, TestValue>> keyEvts = allEvts.get(e.getKey());
+
+ if (keyEvts == null) {
+ List<T2<TestValue, TestValue>> old =
+ allEvts.putIfAbsent(e.getKey(), keyEvts = new ArrayList<>());
+
+ assertNull(old);
+ }
+
+ synchronized (keyEvts) {
+ keyEvts.add(new T2<>(e.getValue(), e.getOldValue()));
+ }
+ }
+ }
+ });
+
+ cache.query(qry);
+
+ nodesEvts.add(allEvts);
+ }
+
+ final AtomicInteger keyVal = new AtomicInteger();
+
+ for (int i = 0; i < NODES; i++) {
+ Ignite ignite = ignite(i);
+
+ log.info("Test with node: " + ignite.name());
+
+ updateAndEventConsistencyTest(ignite, ccfg.getName(), keyVal, nodesEvts, false);
+
+ if (ccfg.getAtomicityMode() == TRANSACTIONAL)
+ updateAndEventConsistencyTest(ignite, ccfg.getName(), keyVal, nodesEvts, true);
+ }
+ }
+ finally {
+ ignite(0).destroyCache(ccfg.getName());
+ }
+ }
+
+ /**
+ * @param node Node.
+ * @param cacheName Cache name.
+ * @param keyVal Key counter.
+ * @param nodesEvts Events map.
+ * @param useTx If {@code true} executes update with explicit transaction.
+ * @throws Exception If failed.
+ */
+ private void updateAndEventConsistencyTest(final Ignite node,
+ String cacheName,
+ final AtomicInteger keyVal,
+ List<ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>>> nodesEvts,
+ final boolean useTx) throws Exception {
+ final ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>> updates = new ConcurrentHashMap<>();
+
+ final int THREADS = 5;
+ final int KEYS_PER_THREAD = 100;
+
+ final IgniteCache<TestKey, TestValue> cache = node.cache(cacheName);
+
+ final IgniteCache<TestKey, TestValue> expPlcCache =
+ cache.withExpiryPolicy(new CreatedExpiryPolicy(new Duration(SECONDS, 2)));
+
+ GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {
+ @Override public void apply(Integer idx) {
+ List<TestKey> keys = new ArrayList<>();
+
+ for (int i = 0; i < KEYS_PER_THREAD; i++)
+ keys.add(new TestKey(keyVal.incrementAndGet()));
+
+ for (TestKey key : keys) {
+ expPlcCache.put(key, new TestValue(0));
+
+ List<T2<TestValue, TestValue>> keyUpdates = new ArrayList<>();
+
+ keyUpdates.add(new T2<>(new TestValue(0), (TestValue)null));
+
+ updates.put(key, keyUpdates);
+ }
+
+ long stopTime = U.currentTimeMillis() + 10_000;
+
+ int val = 0;
+
+ Set<TestKey> expired = new HashSet<>();
+
+ IgniteTransactions txs = node.transactions();
+
+ while (U.currentTimeMillis() < stopTime) {
+ val++;
+
+ TestValue newVal = new TestValue(val);
+
+ for (TestKey key : keys) {
+ Transaction tx = useTx ? txs.txStart(PESSIMISTIC, REPEATABLE_READ) : null;
+
+ TestValue oldVal = cache.getAndPut(key, newVal);
+
+ if (tx != null)
+ tx.commit();
+
+ List<T2<TestValue, TestValue>> keyUpdates = updates.get(key);
+
+ keyUpdates.add(new T2<>(newVal, oldVal));
+
+ if (oldVal == null)
+ expired.add(key);
+ }
+
+ if (expired.size() == keys.size())
+ break;
+ }
+
+ assertEquals(keys.size(), expired.size());
+ }
+ }, THREADS, "update-thread");
+
+ for (ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>> evts : nodesEvts)
+ checkEvents(updates, evts);
+
+ nodesEvts.clear();
+ }
+
+ /**
+ * @param updates Cache update.
+ * @param evts Received events.
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
+ private void checkEvents(ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>> updates,
+ final ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>> evts) throws Exception {
+ for (final TestKey key : updates.keySet()) {
+ final List<T2<TestValue, TestValue>> keyUpdates = updates.get(key);
+
+ assert(!F.isEmpty(keyUpdates));
+
+ GridTestUtils.waitForCondition(new PA() {
+ @Override public boolean apply() {
+ List<T2<TestValue, TestValue>> keyEvts = evts.get(key);
+
+ if (keyEvts == null)
+ return false;
+
+ synchronized (keyEvts) {
+ return keyEvts.size() == keyUpdates.size();
+ }
+ }
+ }, 5000);
+
+ List<T2<TestValue, TestValue>> keyEvts = evts.get(key);
+
+ assertNotNull(keyEvts);
+
+ for (int i = 0; i < keyUpdates.size(); i++) {
+ T2<TestValue, TestValue> update = keyUpdates.get(i);
+ T2<TestValue, TestValue> evt = keyEvts.get(i);
+
+ assertEquals(update.get1(), evt.get1());
+ assertEquals(update.get2(), evt.get2());
+ }
+ }
+ }
+
+ /**
+ * @param atomicityMode Cache atomicity mode.
+ * @param memoryMode Cache memory mode.
+ * @param backups Number of backups.
+ * @return Cache configuration.
+ */
+ private CacheConfiguration<TestKey, TestValue> cacheConfiguration(CacheAtomicityMode atomicityMode,
+ CacheMemoryMode memoryMode,
+ int backups) {
+ CacheConfiguration<TestKey, TestValue> ccfg = new CacheConfiguration<>();
+
+ ccfg.setCacheMode(PARTITIONED);
+ ccfg.setAtomicityMode(atomicityMode);
+ ccfg.setMemoryMode(memoryMode);
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+ ccfg.setBackups(backups);
+
+ return ccfg;
+ }
+
+ /**
+ *
+ */
+ static class TestKey implements Serializable {
+ /** */
+ private int key;
+
+ /**
+ * @param key Key.
+ */
+ public TestKey(int key) {
+ this.key = key;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestKey testKey = (TestKey)o;
+
+ return key == testKey.key;
+
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return key;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(TestKey.class, this);
+ }
+ }
+
+ /**
+ *
+ */
+ static class TestValue implements Serializable {
+ /** */
+ private int val;
+
+ /**
+ * @param val Value.
+ */
+ public TestValue(int val) {
+ this.val = val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(TestValue.class, this);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestValue testVal = (TestValue)o;
+
+ return val == testVal.val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java
index f4cc025..794519a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java
@@ -1124,7 +1124,8 @@ public abstract class IgniteCacheExpiryPolicyAbstractTest extends IgniteCacheAbs
if (e != null && e.deleted()) {
assertEquals(0, e.ttl());
- assertFalse(cache.affinity().isPrimaryOrBackup(grid.localNode(), key));
+ assertFalse("Invalid entry [e=" + e + ", node=" + i + ']',
+ cache.affinity().isPrimaryOrBackup(grid.localNode(), key));
continue;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java
index e6e2a0e..44dc8ed 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.cache.expiry;
import junit.framework.TestSuite;
import org.apache.ignite.cache.store.IgniteCacheExpiryStoreLoadSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheExpireAndUpdateConsistencyTest;
/**
*
@@ -65,6 +66,8 @@ public class IgniteCacheExpiryPolicyTestSuite extends TestSuite {
suite.addTestSuite(IgniteCacheClientNearCacheExpiryTest.class);
+ suite.addTestSuite(IgniteCacheExpireAndUpdateConsistencyTest.class);
+
return suite;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheOperationsWithExpirationTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheOperationsWithExpirationTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheOperationsWithExpirationTest.java
new file mode 100644
index 0000000..6c60586
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheOperationsWithExpirationTest.java
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.ThreadLocalRandom;
+import javax.cache.expiry.Duration;
+import javax.cache.expiry.ModifiedExpiryPolicy;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMemoryMode;
+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.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteInClosure;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.PRIMARY;
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
+import static org.apache.ignite.cache.CacheMemoryMode.ONHEAP_TIERED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
+
+/**
+ *
+ */
+public class CacheOperationsWithExpirationTest extends GridCommonAbstractTest {
+ /** */
+ private static final int KEYS = 10_000;
+
+ /**
+ * @param atomicityMode Atomicity mode.
+ * @param memoryMode Memory mode.
+ * @param offheapMem Offheap memory size.
+ * @param idx Indexing enabled flag.
+ * @return Cache configuration.
+ */
+ private CacheConfiguration<String, TestIndexedType> cacheConfiguration(CacheAtomicityMode atomicityMode,
+ CacheMemoryMode memoryMode,
+ long offheapMem,
+ boolean idx) {
+ CacheConfiguration<String, TestIndexedType> ccfg = new CacheConfiguration<>();
+
+ ccfg.setAtomicityMode(atomicityMode);
+ ccfg.setMemoryMode(memoryMode);
+ ccfg.setOffHeapMaxMemory(offheapMem);
+ ccfg.setSwapEnabled(false);
+ ccfg.setBackups(1);
+ ccfg.setAtomicWriteOrderMode(PRIMARY);
+ ccfg.setWriteSynchronizationMode(PRIMARY_SYNC);
+ ccfg.setStatisticsEnabled(true);
+
+ if (idx)
+ ccfg.setIndexedTypes(String.class, TestIndexedType.class);
+
+ return ccfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ startGrid(0);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAtomicOffheapLimitedIndexEnabled() throws Exception {
+ concurrentPutGetRemoveExpireAndQuery(cacheConfiguration(ATOMIC, OFFHEAP_TIERED, 1024 * 1024, true));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAtomicOffheapIndexEnabled() throws Exception {
+ concurrentPutGetRemoveExpireAndQuery(cacheConfiguration(ATOMIC, OFFHEAP_TIERED, 0, true));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAtomicIndexEnabled() throws Exception {
+ concurrentPutGetRemoveExpireAndQuery(cacheConfiguration(ATOMIC, ONHEAP_TIERED, 0, true));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTxOffheapLimitedIndexEnabled() throws Exception {
+ concurrentPutGetRemoveExpireAndQuery(cacheConfiguration(TRANSACTIONAL, OFFHEAP_TIERED, 1024 * 1024, true));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTxOffheapIndexEnabled() throws Exception {
+ concurrentPutGetRemoveExpireAndQuery(cacheConfiguration(TRANSACTIONAL, OFFHEAP_TIERED, 0, true));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAtomicOffheapLimited() throws Exception {
+ concurrentPutGetRemoveExpireAndQuery(cacheConfiguration(ATOMIC, OFFHEAP_TIERED, 1024 * 1024, false));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAtomicOffheap() throws Exception {
+ concurrentPutGetRemoveExpireAndQuery(cacheConfiguration(ATOMIC, OFFHEAP_TIERED, 0, false));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAtomic() throws Exception {
+ concurrentPutGetRemoveExpireAndQuery(cacheConfiguration(ATOMIC, ONHEAP_TIERED, 0, false));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTxOffheapLimited() throws Exception {
+ concurrentPutGetRemoveExpireAndQuery(cacheConfiguration(TRANSACTIONAL, OFFHEAP_TIERED, 1024 * 1024, false));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTxOffheap() throws Exception {
+ concurrentPutGetRemoveExpireAndQuery(cacheConfiguration(TRANSACTIONAL, OFFHEAP_TIERED, 0, false));
+ }
+
+ /**
+ * @param ccfg Cache configuration.
+ * @throws Exception If failed.
+ */
+ private void concurrentPutGetRemoveExpireAndQuery(CacheConfiguration<String, TestIndexedType> ccfg)
+ throws Exception {
+ Ignite ignite = ignite(0);
+
+ final IgniteCache<String, TestIndexedType> cache = ignite.createCache(ccfg);
+
+ final boolean qryEnabled = !F.isEmpty(ccfg.getQueryEntities());
+
+ try {
+ final long stopTime = U.currentTimeMillis() + 30_000;
+
+ GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {
+ @Override public void apply(Integer idx) {
+ while (U.currentTimeMillis() < stopTime) {
+ if (!qryEnabled || idx % 2 == 0)
+ putGet(cache);
+ else
+ query(cache);
+ }
+ }
+
+ void putGet(IgniteCache<String, TestIndexedType> cache) {
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ cache = cache.withExpiryPolicy(new ModifiedExpiryPolicy(
+ new Duration(MILLISECONDS, rnd.nextLong(100) + 1)));
+
+ for (int i = 0; i < KEYS; i++) {
+ String key = String.valueOf(rnd.nextInt(KEYS));
+
+ cache.put(key, testValue(rnd));
+ }
+
+ Set<String> s = new TreeSet<>();
+
+ for (int i = 0; i < 1000; i++) {
+ String key = String.valueOf(rnd.nextInt(KEYS));
+
+ s.add(key);
+ }
+
+ cache.getAll(s);
+
+ cache.removeAll(s);
+ }
+
+ void query(IgniteCache<String, TestIndexedType> cache) {
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ String k = String.valueOf(rnd.nextInt(KEYS));
+
+ SqlFieldsQuery qry1;
+
+ if (rnd.nextBoolean()) {
+ qry1 = new SqlFieldsQuery("select _key, _val from TestIndexedType where key1=? and intVal=?");
+
+ qry1.setArgs(k, k);
+ }
+ else
+ qry1 = new SqlFieldsQuery("select _key, _val from TestIndexedType");
+
+ List res = cache.query(qry1).getAll();
+
+ assertNotNull(res);
+ }
+ }, 10, "test-thread");
+ }
+ finally {
+ ignite.destroyCache(cache.getName());
+ }
+ }
+
+ /**
+ * @param rnd Random.
+ * @return Test value.
+ */
+ private TestIndexedType testValue(ThreadLocalRandom rnd) {
+ StringBuilder builder = new StringBuilder();
+
+ for (int i = 0; i < rnd.nextInt(100); i++)
+ builder.append("string");
+
+ return new TestIndexedType(rnd.nextInt(KEYS), builder.toString());
+ }
+
+ /**
+ *
+ */
+ public enum EnumType1 {
+ /** */
+ TYPE1,
+ /** */
+ TYPE2,
+ /** */
+ TYPE3;
+
+ /** */
+ static final EnumType1[] vals = EnumType1.values();
+ }
+
+ /**
+ *
+ */
+ public enum EnumType2 {
+ /** */
+ TYPE1,
+ /** */
+ TYPE2,
+ /** */
+ TYPE3,
+ /** */
+ TYPE4;
+
+ /** */
+ static final EnumType2[] vals = EnumType2.values();
+ }
+
+ /**
+ *
+ */
+ public static class TestIndexedType implements Serializable {
+ /** */
+ private static final long serialVersionUID = 1L;
+
+ /** */
+ @QuerySqlField
+ private final String key;
+
+ /** */
+ @QuerySqlField(index = true)
+ private final String key1;
+
+ /** */
+ @QuerySqlField(index = true)
+ private final String key2;
+
+ /** */
+ @QuerySqlField(index = true)
+ private final String key3;
+
+ /** */
+ @QuerySqlField(index = true)
+ private final int intVal;
+
+ /** */
+ private final EnumType1 type1;
+
+ /** */
+ @QuerySqlField(index = true)
+ private final EnumType2 type2;
+
+ /** */
+ @QuerySqlField(index = true)
+ private final Date date1;
+
+ /** */
+ @QuerySqlField(index = true)
+ private final Date date2;
+
+ /** */
+ private final Byte byteVal1;
+
+ /** */
+ private final Byte byteVal2;
+
+ /**
+ * @param rnd Random value.
+ * @param strVal Random string value.
+ */
+ public TestIndexedType(int rnd, String strVal) {
+ intVal = rnd;
+ key = String.valueOf(rnd);
+ key1 = key;
+ key2 = strVal;
+ key3 = strVal;
+ date1 = new Date(rnd);
+ date2 = new Date(U.currentTimeMillis());
+ type1 = EnumType1.vals[rnd % EnumType1.vals.length];
+ type2 = EnumType2.vals[rnd % EnumType2.vals.length];
+ byteVal1 = (byte)rnd;
+ byteVal2 = (byte)rnd;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffheapIndexGetSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffheapIndexGetSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffheapIndexGetSelfTest.java
index 02c4312..2fbde41 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffheapIndexGetSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffheapIndexGetSelfTest.java
@@ -22,6 +22,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.cache.Cache;
+import javax.cache.expiry.Duration;
+import javax.cache.expiry.ExpiryPolicy;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.cache.query.annotations.QuerySqlField;
@@ -156,6 +158,52 @@ public class GridCacheOffheapIndexGetSelfTest extends GridCommonAbstractTest {
}
/**
+ * @throws Exception If failed.
+ */
+ public void testWithExpiryPolicy() throws Exception {
+ IgniteCache<Long, Long> cache = grid(0).cache(null);
+
+ cache = cache.withExpiryPolicy(new TestExiryPolicy());
+
+ for (long i = 0; i < 100; i++)
+ cache.put(i, i);
+
+ for (long i = 0; i < 100; i++)
+ assertEquals((Long)i, cache.get(i));
+
+ SqlQuery<Long, Long> qry = new SqlQuery<>(Long.class, "_val >= 90");
+
+ List<Cache.Entry<Long, Long>> res = cache.query(qry).getAll();
+
+ assertEquals(10, res.size());
+
+ for (Cache.Entry<Long, Long> e : res) {
+ assertNotNull(e.getKey());
+ assertNotNull(e.getValue());
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestExiryPolicy implements ExpiryPolicy {
+ /** {@inheritDoc} */
+ @Override public Duration getExpiryForCreation() {
+ return Duration.ONE_MINUTE;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Duration getExpiryForAccess() {
+ return Duration.FIVE_MINUTES;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Duration getExpiryForUpdate() {
+ return Duration.TWENTY_MINUTES;
+ }
+ }
+
+ /**
* Test entry class.
*/
private static class TestEntity implements Serializable {
http://git-wip-us.apache.org/repos/asf/ignite/blob/69a0afa7/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
index 929fb37..a85b7a6 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
@@ -20,6 +20,7 @@ package org.apache.ignite.testsuites;
import junit.framework.TestSuite;
import org.apache.ignite.internal.processors.cache.CacheConfigurationP2PTest;
import org.apache.ignite.internal.processors.cache.CacheIndexStreamerTest;
+import org.apache.ignite.internal.processors.cache.CacheOperationsWithExpirationTest;
import org.apache.ignite.internal.processors.cache.CacheRandomOperationsMultithreadedTest;
import org.apache.ignite.internal.processors.cache.GridCacheOffHeapAndSwapSelfTest;
import org.apache.ignite.internal.processors.cache.GridCacheOffHeapSelfTest;
@@ -74,6 +75,7 @@ public class IgniteCacheWithIndexingTestSuite extends TestSuite {
suite.addTestSuite(IgniteClientReconnectQueriesTest.class);
suite.addTestSuite(CacheRandomOperationsMultithreadedTest.class);
suite.addTestSuite(IgniteCacheStarvationOnRebalanceTest.class);
+ suite.addTestSuite(CacheOperationsWithExpirationTest.class);
return suite;
}
[10/17] ignite git commit: Added trace logging for entry/offheap
updates.
Posted by sb...@apache.org.
Added trace logging for entry/offheap updates.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/78be02fe
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/78be02fe
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/78be02fe
Branch: refs/heads/ignite-3116
Commit: 78be02fea89b82c6e16ec9af15af0a8416956b4d
Parents: 327f0dd
Author: sboikov <sb...@gridgain.com>
Authored: Wed May 25 10:06:43 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed May 25 10:06:43 2016 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheMapEntry.java | 204 ++++++++++++++++---
.../processors/cache/GridCacheSwapManager.java | 6 +
.../distributed/dht/GridDhtCacheEntry.java | 8 +
.../dht/GridDhtOffHeapCacheEntry.java | 8 +
.../atomic/GridDhtAtomicOffHeapCacheEntry.java | 8 +
.../GridDhtColocatedOffHeapCacheEntry.java | 8 +
.../offheap/GridOffHeapProcessor.java | 12 ++
7 files changed, 224 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/78be02fe/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index b369df1..f442202 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -454,6 +454,13 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (cctx.swap().onOffheapEvict(key, entry, partition(), evictVer)) {
assert !hasValueUnlocked() : this;
+ if (log.isTraceEnabled()) {
+ log.trace("onOffheapEvict evicted [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
+
obsolete = markObsolete0(obsoleteVer, false, null);
assert obsolete : this;
@@ -464,8 +471,16 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
clearIndex(val);
}
}
- else
+ else {
obsolete = false;
+
+ if (log.isTraceEnabled()) {
+ log.trace("onOffheapEvict not evicted [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
+ }
}
if (obsolete)
@@ -514,6 +529,21 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (cctx.offheapTiered()) {
e = cctx.swap().readOffheapPointer(this);
+ if (log.isTraceEnabled()) {
+ if (e != null) {
+ log.trace("Read offheap pointer [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + e.offheapPointer() +
+ ']');
+ }
+ else {
+ log.trace("Read offheap pointer [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", val=" + null +
+ ']');
+ }
+ }
+
if (e != null) {
if (e.offheapPointer() > 0) {
offHeapPointer(e.offheapPointer());
@@ -530,11 +560,16 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
offHeapPointer(0);
}
}
- else
+ else {
e = cctx.swap().readAndRemove(this);
- if (log.isDebugEnabled())
- log.debug("Read swap entry [swapEntry=" + e + ", cacheEntry=" + this + ']');
+ if (log.isTraceEnabled()) {
+ log.trace("unswap readAndRemove [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", found=" + (e != null) +
+ ']');
+ }
+ }
flags |= IS_UNSWAPPED_MASK;
@@ -598,11 +633,20 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
boolean offheapPtr = hasOffHeapPointer();
if (cctx.offheapTiered() && offheapPtr && !swapNeeded) {
- if (log.isDebugEnabled())
- log.debug("Value did not change, skip write swap entry: " + this);
+ if (cctx.swap().offheapEvictionEnabled()) {
+ if (log.isTraceEnabled()) {
+ log.trace("enableOffheapEviction [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
- if (cctx.swap().offheapEvictionEnabled())
cctx.swap().enableOffheapEviction(key(), partition());
+ }
+ else {
+ if (log.isTraceEnabled())
+ log.trace("Value did not change, skip write swap entry: " + this);
+ }
return;
}
@@ -622,6 +666,13 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
IgniteBiTuple<byte[], Byte> valBytes = valueBytes0();
+ if (log.isTraceEnabled()) {
+ log.trace("writeToOffheap [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
+
cctx.swap().write(key(),
ByteBuffer.wrap(valBytes.get1()),
valBytes.get2(),
@@ -633,9 +684,6 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
!offheapPtr);
flags &= ~IS_SWAPPING_REQUIRED;
-
- if (log.isDebugEnabled())
- log.debug("Wrote swap entry: " + this);
}
}
@@ -671,10 +719,14 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (cctx.isSwapOrOffheapEnabled()) {
assert Thread.holdsLock(this);
- cctx.swap().remove(key(), partition());
+ if (log.isTraceEnabled()) {
+ log.trace("removeFromSwap [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
- if (log.isDebugEnabled())
- log.debug("Removed swap entry [entry=" + this + ']');
+ cctx.swap().remove(key(), partition());
}
}
@@ -943,8 +995,15 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
update(ret, expTime, ttl, nextVer, true);
- if (hadValPtr && cctx.offheapTiered())
+ if (hadValPtr && cctx.offheapTiered()) {
+ if (log.isTraceEnabled()) {
+ log.trace("innerGet removeOffheap [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() + ']');
+ }
+
cctx.swap().removeOffheap(key);
+ }
if (cctx.deferredDelete() && deletedUnlocked() && !isInternal() && !detached())
deletedUnlocked(false);
@@ -1014,10 +1073,17 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
// If version matched, set value.
if (startVer.equals(ver)) {
- releaseSwap();
-
CacheObject old = rawGetOrUnmarshalUnlocked(false);
+ if (log.isTraceEnabled()) {
+ log.trace("innerReload releaseSwap [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", old=" + old +
+ ", ptr=" + offHeapPointer() + ']');
+ }
+
+ releaseSwap();
+
long expTime = CU.toExpireTime(ttl);
// Detach value before index update.
@@ -1319,6 +1385,13 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
boolean startVer = isStartVersion();
if (startVer) {
+ if (log.isTraceEnabled()) {
+ log.trace("innerRemove releaseSwap [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
+
// Release swap.
releaseSwap();
}
@@ -1434,6 +1507,14 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (cctx.offheapTiered() && hadValPtr) {
boolean rmv = cctx.swap().removeOffheap(key);
+ if (log.isTraceEnabled()) {
+ log.trace("innerRemove remove offheap [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", rmv=" + rmv +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
+
assert rmv;
}
@@ -1810,12 +1891,18 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(cctx, key, key0, old, old0, keepBinary));
}
- if (op != GridCacheOperation.UPDATE) {
- if (cctx.offheapTiered() && hasValPtr) {
- boolean rmv = cctx.swap().removeOffheap(key);
+ if (op != GridCacheOperation.UPDATE && cctx.offheapTiered() && hasValPtr) {
+ boolean rmv = cctx.swap().removeOffheap(key);
- assert rmv;
+ if (log.isTraceEnabled()) {
+ log.trace("innerUpdateLocal remove offheap [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", rmv=" + rmv +
+ ", ptr=" + offHeapPointer() +
+ ']');
}
+
+ assert rmv;
}
}
@@ -2309,6 +2396,13 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
// Actual update.
if (op == GridCacheOperation.UPDATE) {
+ if (log.isTraceEnabled()) {
+ log.trace("innerUpdate [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
+
if (intercept) {
updated0 = value(updated0, updated, keepBinary, false);
@@ -2510,12 +2604,18 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
oldVal = cctx.toCacheObject(cctx.unwrapTemporary(interceptRes.get2()));
}
- if (op != GridCacheOperation.UPDATE) {
- if (cctx.offheapTiered() && hasValPtr) {
- boolean rmv = cctx.swap().removeOffheap(key);
+ if (op != GridCacheOperation.UPDATE && cctx.offheapTiered() && hasValPtr) {
+ boolean rmv = cctx.swap().removeOffheap(key);
- assert rmv;
+ if (log.isTraceEnabled()) {
+ log.trace("innerUpdate remove offheap [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", rmv=" + rmv +
+ ", ptr=" + offHeapPointer() +
+ ']');
}
+
+ assert rmv;
}
}
@@ -2711,8 +2811,12 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
break;
}
- if (log.isDebugEnabled())
- log.debug("Entry has been marked obsolete: " + this);
+ if (log.isTraceEnabled()) {
+ log.trace("entry clear [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", val=" + val +
+ ", ptr=" + offHeapPointer() + ']');
+ }
clearIndex(val);
@@ -2873,6 +2977,14 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (clear)
value(null);
+
+ if (log.isTraceEnabled()) {
+ log.trace("markObsolete0 [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() +
+ ", clear=" + clear +
+ ']');
+ }
}
return obsoleteVer != null;
@@ -2910,6 +3022,14 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
ver = newVer;
+ if (log.isTraceEnabled()) {
+ log.trace("invalidate releaseSwap [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", val=" + val +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
+
releaseSwap();
clearIndex(val);
@@ -3228,10 +3348,13 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (expireTime > 0) {
long delta = expireTime - U.currentTimeMillis();
- if (log.isDebugEnabled())
- log.debug("Checked expiration time for entry [timeLeft=" + delta + ", entry=" + this + ']');
-
if (delta <= 0) {
+ if (log.isTraceEnabled()) {
+ log.trace("checkExpired clear [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() + ']');
+ }
+
releaseSwap();
clearIndex(saveValueForIndexUnlocked());
@@ -3759,6 +3882,12 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
rmvd = true;
}
+ if (log.isTraceEnabled()) {
+ log.trace("onExpired clear [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() + ']');
+ }
+
clearIndex(expiredVal);
releaseSwap();
@@ -4173,6 +4302,13 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
flags &= ~IS_OFFHEAP_PTR_MASK;
if (prevVal != null) {
+ if (log.isTraceEnabled()) {
+ log.trace("evictFailed [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
+
cctx.swap().removeOffheap(key());
value(prevVal);
@@ -4198,8 +4334,16 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (!hasReaders() && markObsolete0(obsoleteVer, false, null)) {
if (!isStartVersion() && hasValueUnlocked()) {
if (cctx.offheapTiered() && hasOffHeapPointer()) {
- if (cctx.swap().offheapEvictionEnabled())
+ if (cctx.swap().offheapEvictionEnabled()) {
+ if (log.isTraceEnabled()) {
+ log.trace("enableOffheapEviction evictInBatchInternal [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
+
cctx.swap().enableOffheapEviction(key(), partition());
+ }
return null;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/78be02fe/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index a060c8a..1f70374 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -2121,6 +2121,9 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
IgniteUuid valLdrId = swapEntry.valueClassLoaderId();
if (ldrId.equals(swapEntry.keyClassLoaderId())) {
+ if (log.isTraceEnabled())
+ log.trace("onUndeploy remove key [ldrId=" + ldrId + ']');
+
iter.removeX();
undeployCnt++;
@@ -2138,6 +2141,9 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
valLdrId = cctx.deploy().getClassLoaderId(val.getClass().getClassLoader());
}
+ if (log.isTraceEnabled())
+ log.trace("onUndeploy remove value [ldrId=" + ldrId + ']');
+
if (ldrId.equals(valLdrId)) {
iter.removeX();
http://git-wip-us.apache.org/repos/asf/ignite/blob/78be02fe/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
index ab51bdb..bf53557 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
@@ -577,6 +577,14 @@ public class GridDhtCacheEntry extends GridDistributedCacheEntry {
if (log.isDebugEnabled())
log.debug("Entry has been marked obsolete: " + this);
+ if (log.isTraceEnabled()) {
+ log.trace("clearInternal [key=" + key +
+ ", entry=" + System.identityHashCode(this) +
+ ", prev=" + prev +
+ ", ptr=" + offHeapPointer() +
+ ']');
+ }
+
clearIndex(prev);
// Give to GC.
http://git-wip-us.apache.org/repos/asf/ignite/blob/78be02fe/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtOffHeapCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtOffHeapCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtOffHeapCacheEntry.java
index 07272ae..75ee45c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtOffHeapCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtOffHeapCacheEntry.java
@@ -21,6 +21,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.CacheObject;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.util.typedef.internal.S;
/**
* Replicated cache entry for off-heap tiered or off-heap values modes.
@@ -60,4 +61,11 @@ public class GridDhtOffHeapCacheEntry extends GridDhtCacheEntry {
@Override protected void offHeapPointer(long valPtr) {
this.valPtr = valPtr;
}
+
+ /** {@inheritDoc} */
+ @Override public synchronized String toString() {
+ return S.toString(GridDhtOffHeapCacheEntry.class, this,
+ "entry", System.identityHashCode(this),
+ "super", super.toString());
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/78be02fe/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicOffHeapCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicOffHeapCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicOffHeapCacheEntry.java
index 85cfb80..c86d477 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicOffHeapCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicOffHeapCacheEntry.java
@@ -21,6 +21,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.CacheObject;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.util.typedef.internal.S;
/**
* DHT atomic cache entry for off-heap tiered or off-heap values modes.
@@ -60,4 +61,11 @@ public class GridDhtAtomicOffHeapCacheEntry extends GridDhtAtomicCacheEntry {
@Override protected void offHeapPointer(long valPtr) {
this.valPtr = valPtr;
}
+
+ /** {@inheritDoc} */
+ @Override public synchronized String toString() {
+ return S.toString(GridDhtAtomicOffHeapCacheEntry.class, this,
+ "entry", System.identityHashCode(this),
+ "super", super.toString());
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/78be02fe/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedOffHeapCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedOffHeapCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedOffHeapCacheEntry.java
index ea368d2..8080ca3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedOffHeapCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedOffHeapCacheEntry.java
@@ -21,6 +21,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.CacheObject;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.util.typedef.internal.S;
/**
* Cache entry for colocated cache for off-heap tiered or off-heap values modes.
@@ -60,4 +61,11 @@ public class GridDhtColocatedOffHeapCacheEntry extends GridDhtColocatedCacheEntr
@Override protected void offHeapPointer(long valPtr) {
this.valPtr = valPtr;
}
+
+ /** {@inheritDoc} */
+ @Override public synchronized String toString() {
+ return S.toString(GridDhtColocatedOffHeapCacheEntry.class, this,
+ "entry", System.identityHashCode(this),
+ "super", super.toString());
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/78be02fe/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
index a97427a..d9d4421 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
@@ -228,6 +228,9 @@ public class GridOffHeapProcessor extends GridProcessorAdapter {
@Nullable public byte[] remove(@Nullable String spaceName, int part, KeyCacheObject key, byte[] keyBytes) throws IgniteCheckedException {
GridOffHeapPartitionedMap m = offheap(spaceName);
+ if (log.isTraceEnabled())
+ log.trace("offheap remove [key=" + key + ']');
+
return m == null ? null : m.remove(part, U.hash(key), keyBytes(key, keyBytes));
}
@@ -249,6 +252,9 @@ public class GridOffHeapProcessor extends GridProcessorAdapter {
throw new IgniteCheckedException("Failed to write data to off-heap space, no space registered for name: " +
spaceName);
+ if (log.isTraceEnabled())
+ log.trace("offheap put [key=" + key + ']');
+
m.put(part, U.hash(key), keyBytes(key, keyBytes), valBytes);
}
@@ -266,6 +272,9 @@ public class GridOffHeapProcessor extends GridProcessorAdapter {
throws IgniteCheckedException {
GridOffHeapPartitionedMap m = offheap(spaceName);
+ if (log.isTraceEnabled())
+ log.trace("offheap removex [key=" + key + ']');
+
return m != null && m.removex(part, U.hash(key), keyBytes(key, keyBytes));
}
@@ -287,6 +296,9 @@ public class GridOffHeapProcessor extends GridProcessorAdapter {
IgniteBiPredicate<Long, Integer> p) throws IgniteCheckedException {
GridOffHeapPartitionedMap m = offheap(spaceName);
+ if (log.isTraceEnabled())
+ log.trace("offheap removex [key=" + key + ']');
+
return m != null && m.removex(part, U.hash(key), keyBytes(key, keyBytes), p);
}
[02/17] ignite git commit: IGNITE-3175 BigDecimal fields are not
supported if query is executed from IgniteRDD (cherry picked from commit
f2b390a)
Posted by sb...@apache.org.
IGNITE-3175 BigDecimal fields are not supported if query is executed from IgniteRDD
(cherry picked from commit f2b390a)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ffd28b8b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ffd28b8b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ffd28b8b
Branch: refs/heads/ignite-3116
Commit: ffd28b8b403966d85d3ada6a22d793f0500aaef2
Parents: 997824d
Author: sboikov <sb...@gridgain.com>
Authored: Mon May 23 07:28:55 2016 +0300
Committer: tledkov-gridgain <tl...@gridgain.com>
Committed: Mon May 23 10:37:50 2016 +0300
----------------------------------------------------------------------
.../org/apache/ignite/spark/IgniteRDD.scala | 1 +
.../ignite/spark/JavaIgniteRDDSelfTest.java | 60 +++++++++++++++++++-
.../ignite/spark/EntityTestAllTypeFields.scala | 57 +++++++++++++++++++
3 files changed, 116 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/ffd28b8b/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala b/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
index 2146acb..9112040 100644
--- a/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
+++ b/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
@@ -220,6 +220,7 @@ class IgniteRDD[K, V] (
case "java.lang.Long" \u21d2 LongType
case "java.lang.Float" \u21d2 FloatType
case "java.lang.Double" \u21d2 DoubleType
+ case "java.math.BigDecimal" \u21d2 DecimalType.SYSTEM_DEFAULT
case "java.lang.String" \u21d2 StringType
case "java.util.Date" \u21d2 DateType
case "java.sql.Timestamp" \u21d2 TimestampType
http://git-wip-us.apache.org/repos/asf/ignite/blob/ffd28b8b/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java b/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java
index becd90a..9892056 100644
--- a/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java
+++ b/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java
@@ -17,7 +17,6 @@
package org.apache.ignite.spark;
-import java.util.List;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
@@ -28,6 +27,7 @@ import org.apache.ignite.lang.IgniteOutClosure;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
@@ -39,6 +39,10 @@ import org.apache.spark.sql.DataFrame;
import org.apache.spark.sql.Row;
import scala.Tuple2;
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.util.List;
+
/**
* Tests for {@link JavaIgniteRDD}.
*/
@@ -85,6 +89,14 @@ public class JavaIgniteRDDSelfTest extends GridCommonAbstractTest {
}
};
+ /** */
+ private static final PairFunction<Integer, String, EntityTestAllTypeFields> INT_TO_ENTITY_ALL_FIELDS_F =
+ new PairFunction<Integer, String, EntityTestAllTypeFields>() {
+ @Override public Tuple2<String, EntityTestAllTypeFields> call(Integer i) throws Exception {
+ return new Tuple2<>(String.valueOf(i), new EntityTestAllTypeFields(i));
+ }
+ };
+
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
Ignition.ignite("grid-0").cache(PARTITIONED_CACHE_NAME).removeAll();
@@ -234,7 +246,50 @@ public class JavaIgniteRDDSelfTest extends GridCommonAbstractTest {
finally {
sc.stop();
}
+ }
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAllFieldsTypes() throws Exception {
+ JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
+
+ final int cnt = 100;
+
+ try {
+ JavaIgniteContext<String, EntityTestAllTypeFields> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
+
+ JavaIgniteRDD<String, EntityTestAllTypeFields> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
+
+ cache.savePairs(sc.parallelize(F.range(0, cnt), 2).mapToPair(INT_TO_ENTITY_ALL_FIELDS_F));
+
+ EntityTestAllTypeFields e = new EntityTestAllTypeFields(cnt / 2);
+ for(Field f : EntityTestAllTypeFields.class.getDeclaredFields()) {
+ String fieldName = f.getName();
+
+ Object val = GridTestUtils.getFieldValue(e, fieldName);
+
+ DataFrame df = cache.sql(
+ String.format("select %s from EntityTestAllTypeFields where %s = ?", fieldName, fieldName),
+ val);
+
+ if (val instanceof BigDecimal) {
+ Object res = df.collect()[0].get(0);
+
+ assertTrue(String.format("+++ Fail on %s field", fieldName),
+ ((Comparable<BigDecimal>)val).compareTo((BigDecimal)res) == 0);
+ }
+ else if (val.getClass().isArray())
+ assertTrue(String.format("+++ Fail on %s field", fieldName), 1 <= df.count());
+ else
+ assertEquals(String.format("+++ Fail on %s field", fieldName), val, df.collect()[0].get(0));
+
+ info(String.format("+++ Query on the filed: %s : %s passed", fieldName, f.getType().getSimpleName()));
+ }
+ }
+ finally {
+ sc.stop();
+ }
}
/**
@@ -269,7 +324,8 @@ public class JavaIgniteRDDSelfTest extends GridCommonAbstractTest {
ccfg.setName(PARTITIONED_CACHE_NAME);
- ccfg.setIndexedTypes(String.class, Entity.class);
+ ccfg.setIndexedTypes(String.class, Entity.class,
+ String.class, EntityTestAllTypeFields.class);
return ccfg;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/ffd28b8b/modules/spark/src/test/scala/org/apache/ignite/spark/EntityTestAllTypeFields.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/scala/org/apache/ignite/spark/EntityTestAllTypeFields.scala b/modules/spark/src/test/scala/org/apache/ignite/spark/EntityTestAllTypeFields.scala
new file mode 100644
index 0000000..a936091
--- /dev/null
+++ b/modules/spark/src/test/scala/org/apache/ignite/spark/EntityTestAllTypeFields.scala
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT 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.spark
+
+import java.lang.Boolean
+import java.sql.Timestamp
+import java.util.Date
+
+import org.apache.ignite.spark.IgniteRDDSpec.ScalarCacheQuerySqlField
+
+class EntityTestAllTypeFields(
+ @ScalarCacheQuerySqlField(index = true) val boolVal: Boolean,
+ @ScalarCacheQuerySqlField(index = true) val byteVal: Byte,
+ @ScalarCacheQuerySqlField(index = true) val shortVal: Short,
+ @ScalarCacheQuerySqlField(index = true) val intVal: Int,
+ @ScalarCacheQuerySqlField(index = true) val longVal: Long,
+ @ScalarCacheQuerySqlField(index = true) val floatVal: Float,
+ @ScalarCacheQuerySqlField(index = true) val doubleVal: Double,
+ @ScalarCacheQuerySqlField(index = true) val strVal: String,
+ @ScalarCacheQuerySqlField(index = true) val dateVal: Date,
+ @ScalarCacheQuerySqlField(index = true) val timestampVal: Timestamp,
+ @ScalarCacheQuerySqlField(index = true) val byteArrVal: Array[Byte],
+ @ScalarCacheQuerySqlField(index = true) val bigDecVal: java.math.BigDecimal
+) extends Serializable {
+ def this(
+ i: Int
+ ) {
+ this(
+ i % 2 == 0, // Boolean
+ i.toByte, // Byte
+ i.toShort, // Short
+ i, // Int
+ i.toLong, // Long
+ i, // Float
+ i, // Double
+ "name" + i, // String
+ new Date(i),
+ new Timestamp(i),
+ Array(i.toByte, i.toByte),
+ new java.math.BigDecimal(i.toString))
+ }
+}
[13/17] ignite git commit: Merge remote-tracking branch
'upstream/gridgain-7.5.23' into gridgain-7.5.23
Posted by sb...@apache.org.
Merge remote-tracking branch 'upstream/gridgain-7.5.23' into gridgain-7.5.23
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/341b8428
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/341b8428
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/341b8428
Branch: refs/heads/ignite-3116
Commit: 341b8428b6f4cff731b1ca3d119ad4a07d4cbe77
Parents: 9b81b75 e98dc92
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed May 25 13:07:32 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed May 25 13:07:32 2016 +0300
----------------------------------------------------------------------
.../org/apache/ignite/spark/IgniteRDD.scala | 20 +++++++++++++++
.../org/apache/ignite/spark/IgniteRDDSpec.scala | 27 ++++++++++++++++++++
2 files changed, 47 insertions(+)
----------------------------------------------------------------------
[06/17] ignite git commit: ignite-2620: Need override 'unswap' for
detached entry. (cherry picked from commit f7b376b)
Posted by sb...@apache.org.
ignite-2620: Need override 'unswap' for detached entry.
(cherry picked from commit f7b376b)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9a48b4b0
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9a48b4b0
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9a48b4b0
Branch: refs/heads/ignite-3116
Commit: 9a48b4b0d36324dc3e075f0baaea09410119a327
Parents: 69a0afa
Author: sboikov <sb...@gridgain.com>
Authored: Tue May 24 11:14:03 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Tue May 24 13:49:59 2016 +0300
----------------------------------------------------------------------
.../internal/processors/cache/GridCacheMapEntry.java | 12 ++++++++----
.../dht/colocated/GridDhtDetachedCacheEntry.java | 2 +-
2 files changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/9a48b4b0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index 480403e..74dfe00 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -475,12 +475,12 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
}
/** {@inheritDoc} */
- @Override public CacheObject unswap() throws IgniteCheckedException, GridCacheEntryRemovedException {
+ @Override public final CacheObject unswap() throws IgniteCheckedException, GridCacheEntryRemovedException {
return unswap(true);
}
/** {@inheritDoc} */
- @Nullable @Override public CacheObject unswap(boolean needVal)
+ @Nullable @Override public final CacheObject unswap(boolean needVal)
throws IgniteCheckedException, GridCacheEntryRemovedException {
return unswap(needVal, true);
}
@@ -489,14 +489,18 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
* Unswaps an entry.
*
* @param needVal If {@code false} then do not to deserialize value during unswap.
+ * @param checkExpire If {@code true} checks for expiration, as result entry can be obsoleted or marked deleted.
* @return Value.
* @throws IgniteCheckedException If failed.
+ * @throws GridCacheEntryRemovedException If entry was removed.
*/
- @Nullable private CacheObject unswap(boolean needVal, boolean checkExpire)
+ @Nullable protected CacheObject unswap(boolean needVal, boolean checkExpire)
throws IgniteCheckedException, GridCacheEntryRemovedException {
if (!cctx.isSwapOrOffheapEnabled())
return null;
+ assert !detached() : this;
+
boolean obsolete = false;
boolean deferred = false;
GridCacheVersion ver0 = null;
@@ -527,7 +531,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
}
}
else
- e = detached() ? cctx.swap().read(this, true, true, true, false) : cctx.swap().readAndRemove(this);
+ e = cctx.swap().readAndRemove(this);
if (log.isDebugEnabled())
log.debug("Read swap entry [swapEntry=" + e + ", cacheEntry=" + this + ']');
http://git-wip-us.apache.org/repos/asf/ignite/blob/9a48b4b0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
index c06f68b..db91134 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
@@ -57,7 +57,7 @@ public class GridDhtDetachedCacheEntry extends GridDistributedCacheEntry {
}
/** {@inheritDoc} */
- @Nullable @Override public CacheObject unswap(boolean needVal) throws IgniteCheckedException {
+ @Nullable @Override public CacheObject unswap(boolean needVal, boolean checkExpire) throws IgniteCheckedException {
return null;
}
[03/17] ignite git commit: ignite-2899 Fixed issues with 'keepBinary'
handling. This closes #593. (cherry picked from commit ee7e2c7)
Posted by sb...@apache.org.
ignite-2899 Fixed issues with 'keepBinary' handling. This closes #593.
(cherry picked from commit ee7e2c7)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/dc973794
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/dc973794
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/dc973794
Branch: refs/heads/ignite-3116
Commit: dc9737949ac38b1467dfda82277b84cf39153ac0
Parents: ffd28b8
Author: sboikov <sb...@gridgain.com>
Authored: Mon May 23 19:42:45 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon May 23 20:08:48 2016 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheAdapter.java | 34 +++++++---
.../processors/cache/GridCacheMapEntry.java | 67 +++++++++++---------
.../processors/cache/GridCacheReturn.java | 10 ++-
.../distributed/dht/GridDhtTxPrepareFuture.java | 2 +-
.../dht/atomic/GridDhtAtomicCache.java | 23 +++++--
.../dht/colocated/GridDhtColocatedCache.java | 2 +-
.../local/atomic/GridLocalAtomicCache.java | 2 +-
.../cache/transactions/IgniteTxEntry.java | 4 +-
.../transactions/IgniteTxLocalAdapter.java | 4 +-
...GetEntryOptimisticReadCommittedSeltTest.java | 2 +-
10 files changed, 95 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/dc973794/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 dd06ef8..5aa3448 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
@@ -1411,9 +1411,16 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
long start = statsEnabled ? System.nanoTime() : 0L;
+ if (ctx.keepBinary())
+ key = (K)ctx.toCacheKeyObject(key);
+
T2<V, GridCacheVersion> t = (T2<V, GridCacheVersion>)get(key, !ctx.keepBinary(), true);
- CacheEntry<K, V> val = t != null ? new CacheEntryImplEx<>(key, t.get1(), t.get2()): null;
+ CacheEntry<K, V> val = t != null ? new CacheEntryImplEx<>(
+ ctx.keepBinary() ? (K)ctx.unwrapBinaryIfNeeded(key, true, false) : key,
+ t.get1(),
+ t.get2())
+ : null;
if (ctx.config().getInterceptor() != null) {
V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null);
@@ -1458,8 +1465,10 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
final long start = statsEnabled ? System.nanoTime() : 0L;
+ final K key0 = ctx.keepBinary() ? (K)ctx.toCacheKeyObject(key) : key;
+
IgniteInternalFuture<T2<V, GridCacheVersion>> fut =
- (IgniteInternalFuture<T2<V, GridCacheVersion>>)getAsync(key, !ctx.keepBinary(), true);
+ (IgniteInternalFuture<T2<V, GridCacheVersion>>)getAsync(key0, !ctx.keepBinary(), true);
final boolean intercept = ctx.config().getInterceptor() != null;
@@ -1469,14 +1478,19 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
throws IgniteCheckedException {
T2<V, GridCacheVersion> t = f.get();
- CacheEntry<K, V> val = t != null ? new CacheEntryImplEx<>(key, t.get1(), t.get2()) : null;
- if (intercept) {
- V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null);
+ CacheEntry val = t != null ? new CacheEntryImplEx<>(
+ ctx.keepBinary() ? (K)ctx.unwrapBinaryIfNeeded(key0, true, false) : key0,
+ t.get1(),
+ t.get2())
+ : null;
- return new CacheEntryImplEx<>(key, val0, t != null ? t.get2() : null);
- }
- else
- return val;
+ if (intercept) {
+ V val0 = (V)ctx.config().getInterceptor().onGet(key0, t != null ? val.getValue() : null);
+
+ return val0 != null ? new CacheEntryImplEx(key0, val0, t != null ? t.get2() : null) : null;
+ }
+ else
+ return val;
}
});
@@ -1725,7 +1739,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
return (V)(val);
}
- return map.get(key);
+ return F.firstValue(map);
}
});
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/dc973794/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index b4a3987..72e2ddd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -1159,7 +1159,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
rawGetOrUnmarshalUnlocked(!retval && !isOffHeapValuesOnly()) : this.val;
if (intercept) {
- val0 = CU.value(val, cctx, false);
+ val0 = cctx.unwrapBinaryIfNeeded(val, keepBinary, false);
CacheLazyEntry e = new CacheLazyEntry(cctx, key, old, keepBinary);
@@ -1379,12 +1379,6 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
update(null, 0, 0, newVer, true);
- if (cctx.offheapTiered() && hadValPtr) {
- boolean rmv = cctx.swap().removeOffheap(key);
-
- assert rmv;
- }
-
if (cctx.deferredDelete() && !detached() && !isInternal()) {
if (!deletedUnlocked()) {
deletedUnlocked(true);
@@ -1457,6 +1451,15 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
deferred = cctx.deferredDelete() && !detached() && !isInternal();
+ if (intercept)
+ cctx.config().getInterceptor().onAfterRemove(entry0);
+
+ if (cctx.offheapTiered() && hadValPtr) {
+ boolean rmv = cctx.swap().removeOffheap(key);
+
+ assert rmv;
+ }
+
if (!deferred) {
// If entry is still removed.
assert newVer == ver;
@@ -1483,9 +1486,6 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
onMarkedObsolete();
}
- if (intercept)
- cctx.config().getInterceptor().onAfterRemove(entry0);
-
if (valid) {
CacheObject ret;
@@ -1674,14 +1674,14 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
CacheLazyEntry e;
if (op == GridCacheOperation.UPDATE) {
- updated0 = value(updated0, updated, false);
+ updated0 = value(updated0, updated, keepBinary, false);
e = new CacheLazyEntry(cctx, key, key0, old, old0, keepBinary);
Object interceptorVal = cctx.config().getInterceptor().onBeforePut(e, updated0);
if (interceptorVal == null)
- return new GridTuple3<>(false, cctx.unwrapTemporary(value(old0, old, false)), invokeRes);
+ return new GridTuple3<>(false, cctx.unwrapTemporary(value(old0, old, keepBinary, false)), invokeRes);
else {
updated0 = cctx.unwrapTemporary(interceptorVal);
@@ -1726,6 +1726,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (ttl == CU.TTL_ZERO)
op = GridCacheOperation.DELETE;
+ boolean hasValPtr = false;
+
// Try write-through.
if (op == GridCacheOperation.UPDATE) {
// Detach value before index update.
@@ -1770,7 +1772,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
// Must persist inside synchronization in non-tx mode.
cctx.store().remove(null, key);
- boolean hasValPtr = hasOffHeapPointer();
+ hasValPtr = hasOffHeapPointer();
if (old == null)
old = saveValueForIndexUnlocked();
@@ -1781,12 +1783,6 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
update(null, CU.TTL_ETERNAL, CU.EXPIRE_TIME_ETERNAL, ver, true);
- if (cctx.offheapTiered() && hasValPtr) {
- boolean rmv = cctx.swap().removeOffheap(key);
-
- assert rmv;
- }
-
if (evt) {
CacheObject evtOld = null;
@@ -1836,6 +1832,14 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
else
cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(cctx, key, key0, old, old0, keepBinary));
}
+
+ if (op != GridCacheOperation.UPDATE) {
+ if (cctx.offheapTiered() && hasValPtr) {
+ boolean rmv = cctx.swap().removeOffheap(key);
+
+ assert rmv;
+ }
+ }
}
return new GridTuple3<>(res,
@@ -2324,10 +2328,12 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
IgniteBiTuple<Boolean, Object> interceptRes = null;
+ boolean hasValPtr = false;
+
// Actual update.
if (op == GridCacheOperation.UPDATE) {
if (intercept) {
- updated0 = value(updated0, updated, false);
+ updated0 = value(updated0, updated, keepBinary, false);
Object interceptorVal = cctx.config().getInterceptor()
.onBeforePut(new CacheLazyEntry(cctx, key, key0, oldVal, old0, keepBinary), updated0);
@@ -2459,7 +2465,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
enqueueVer = newVer;
- boolean hasValPtr = hasOffHeapPointer();
+ hasValPtr = hasOffHeapPointer();
// Clear value on backup. Entry will be removed from cache when it got evicted from queue.
update(null, CU.TTL_ETERNAL, CU.EXPIRE_TIME_ETERNAL, newVer, true);
@@ -2467,12 +2473,6 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
assert newSysTtl == CU.TTL_NOT_CHANGED;
assert newSysExpireTime == CU.EXPIRE_TIME_CALCULATE;
- if (cctx.offheapTiered() && hasValPtr) {
- boolean rmv = cctx.swap().removeOffheap(key);
-
- assert rmv;
- }
-
clearReaders();
recordNodeId(affNodeId, topVer);
@@ -2532,6 +2532,14 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (interceptRes != null)
oldVal = cctx.toCacheObject(cctx.unwrapTemporary(interceptRes.get2()));
}
+
+ if (op != GridCacheOperation.UPDATE) {
+ if (cctx.offheapTiered() && hasValPtr) {
+ boolean rmv = cctx.swap().removeOffheap(key);
+
+ assert rmv;
+ }
+ }
}
if (log.isDebugEnabled())
@@ -2552,14 +2560,15 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
/**
* @param val Value.
* @param cacheObj Cache object.
+ * @param keepBinary Keep binary flag.
* @param cpy Copy flag.
* @return Cache object value.
*/
- @Nullable private Object value(@Nullable Object val, @Nullable CacheObject cacheObj, boolean cpy) {
+ @Nullable private Object value(@Nullable Object val, @Nullable CacheObject cacheObj, boolean keepBinary, boolean cpy) {
if (val != null)
return val;
- return cacheObj != null ? cacheObj.value(cctx.cacheObjectContext(), cpy) : null;
+ return cctx.unwrapBinaryIfNeeded(cacheObj, keepBinary, cpy);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/dc973794/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java
index a2e5ec7..4863100 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java
@@ -28,6 +28,7 @@ import java.util.HashMap;
import java.util.Map;
import javax.cache.processor.EntryProcessorResult;
import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.internal.GridDirectCollection;
import org.apache.ignite.internal.GridDirectTransient;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
@@ -216,6 +217,7 @@ public class GridCacheReturn implements Externalizable, Message {
* @param key0 Key value.
* @param res Result.
* @param err Error.
+ * @param keepBinary Keep binary.
*/
@SuppressWarnings("unchecked")
public synchronized void addEntryProcessResult(
@@ -223,7 +225,8 @@ public class GridCacheReturn implements Externalizable, Message {
KeyCacheObject key,
@Nullable Object key0,
@Nullable Object res,
- @Nullable Exception err) {
+ @Nullable Exception err,
+ boolean keepBinary) {
assert v == null || v instanceof Map : v;
assert key != null;
assert res != null || err != null;
@@ -241,7 +244,10 @@ public class GridCacheReturn implements Externalizable, Message {
CacheInvokeResult res0 = err == null ? CacheInvokeResult.fromResult(res) : CacheInvokeResult.fromError(err);
- resMap.put(key0 != null ? key0 : CU.value(key, cctx, true), res0);
+ Object resKey = key0 != null ? key0 :
+ ((keepBinary && key instanceof BinaryObject) ? key : CU.value(key, cctx, true));
+
+ resMap.put(resKey, res0);
}
else {
assert v == null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/dc973794/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
index 44d7bc6..e17cbbc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
@@ -416,7 +416,7 @@ public final class GridDhtTxPrepareFuture extends GridCompoundFuture<IgniteInter
if (retVal) {
if (err != null || procRes != null)
- ret.addEntryProcessResult(txEntry.context(), key, null, procRes, err);
+ ret.addEntryProcessResult(txEntry.context(), key, null, procRes, err, keepBinary);
else
ret.invokeResult(true);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/dc973794/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index 7361642..08f1f30 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -1721,7 +1721,10 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
if (invokeRes == null)
invokeRes = new GridCacheReturn(node.isLocal());
- invokeRes.addEntryProcessResult(ctx, entry.key(), invokeEntry.key(), computed, null);
+ computed = ctx.unwrapTemporary(computed);
+
+ invokeRes.addEntryProcessResult(ctx, entry.key(), invokeEntry.key(), computed, null,
+ req.keepBinary());
}
if (!invokeEntry.modified())
@@ -1735,7 +1738,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
if (invokeRes == null)
invokeRes = new GridCacheReturn(node.isLocal());
- invokeRes.addEntryProcessResult(ctx, entry.key(), invokeEntry.key(), null, e);
+ invokeRes.addEntryProcessResult(ctx, entry.key(), invokeEntry.key(), null, e, req.keepBinary());
updated = old;
}
@@ -1863,9 +1866,16 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
null,
req.keepBinary());
- Object val = ctx.config().getInterceptor().onBeforePut(new CacheLazyEntry(ctx, entry.key(),
- old, req.keepBinary()),
- updated.value(ctx.cacheObjectContext(), false));
+ Object val = ctx.config().getInterceptor().onBeforePut(
+ new CacheLazyEntry(
+ ctx,
+ entry.key(),
+ old,
+ req.keepBinary()),
+ ctx.unwrapBinaryIfNeeded(
+ updated,
+ req.keepBinary(),
+ false));
if (val == null)
continue;
@@ -2207,7 +2217,8 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
k,
null,
compRes.get1(),
- compRes.get2());
+ compRes.get2(),
+ req.keepBinary());
}
}
else {
http://git-wip-us.apache.org/repos/asf/ignite/blob/dc973794/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
index b954545..35831a3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
@@ -236,7 +236,7 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
return (V)(val);
}
- return (V)map.get(key);
+ return (V)F.firstValue(map);
}
});
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/dc973794/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
index 3006a70..d2d8d62 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
@@ -490,7 +490,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
assert m.isEmpty() || m.size() == 1 : m.size();
- return m.get(key);
+ return F.firstValue(m);
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/dc973794/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
index ecaf04f..90aa8d2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
@@ -930,8 +930,8 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
/**
* @param ver Entry version.
*/
- public void entryReadVersion(GridCacheVersion ver) {
- assert this.serReadVer == null;
+ public void entryReadVersion(GridCacheVersion ver) {
+ assert this.serReadVer == null: "Wrong version [serReadVer=" + serReadVer + ", ver=" + ver + "]";
assert ver != null;
this.serReadVer = ver;
http://git-wip-us.apache.org/repos/asf/ignite/blob/dc973794/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
index 312d3a8..8eea8dd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
@@ -2780,10 +2780,10 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
}
if (res != null)
- ret.addEntryProcessResult(ctx, txEntry.key(), key0, res, null);
+ ret.addEntryProcessResult(ctx, txEntry.key(), key0, res, null, txEntry.keepBinary());
}
catch (Exception e) {
- ret.addEntryProcessResult(ctx, txEntry.key(), key0, null, e);
+ ret.addEntryProcessResult(ctx, txEntry.key(), key0, null, e, txEntry.keepBinary());
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/dc973794/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryOptimisticReadCommittedSeltTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryOptimisticReadCommittedSeltTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryOptimisticReadCommittedSeltTest.java
index acc21df..c04612d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryOptimisticReadCommittedSeltTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryOptimisticReadCommittedSeltTest.java
@@ -33,4 +33,4 @@ public class CacheGetEntryOptimisticReadCommittedSeltTest extends CacheGetEntryA
@Override protected TransactionIsolation isolation() {
return TransactionIsolation.READ_COMMITTED;
}
-}
\ No newline at end of file
+}
[15/17] ignite git commit: Fixed test compilation
Posted by sb...@apache.org.
Fixed test compilation
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/65a90b38
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/65a90b38
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/65a90b38
Branch: refs/heads/ignite-3116
Commit: 65a90b38f663dd7c3e58e8b7e13e029c36caf90b
Parents: e98dc92
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Wed May 25 14:15:44 2016 +0300
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Wed May 25 14:15:44 2016 +0300
----------------------------------------------------------------------
.../src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/65a90b38/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala b/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
index 4cc539b..4e90bc8 100644
--- a/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
+++ b/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
@@ -170,15 +170,15 @@ class IgniteRDDSpec extends FunSpec with Matchers with BeforeAndAfterAll with Be
val sc = new SparkContext("local[*]", "test")
try {
- val ic = new IgniteContext[Integer, WithObjectField](sc,
+ val ic = new IgniteContext[String, Entity](sc,
() \u21d2 configuration("client", client = true))
- val cache: IgniteRDD[Integer, WithObjectField] = ic.fromCache(PARTITIONED_CACHE_NAME)
+ val cache: IgniteRDD[String, Entity] = ic.fromCache(PARTITIONED_CACHE_NAME)
assert(cache.count() == 0)
assert(cache.isEmpty())
- cache.savePairs(sc.parallelize(0 until 1000, 2).map(i \u21d2 (i:java.lang.Integer, new WithObjectField(i, new Entity(i, "", i)))))
+ cache.savePairs(sc.parallelize(0 until 1000, 2).map(i \u21d2 (String.valueOf(i), new Entity(i, "", i))))
assert(cache.count() == 1000)
assert(!cache.isEmpty())
[08/17] ignite git commit: ignite-2620 Skip empty entries in
GridCacheMapEntry.onTtlExpired
Posted by sb...@apache.org.
ignite-2620 Skip empty entries in GridCacheMapEntry.onTtlExpired
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a0141a44
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a0141a44
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a0141a44
Branch: refs/heads/ignite-3116
Commit: a0141a44f6d5f4c6a9348ff95a0807865af436ac
Parents: 8579024
Author: sboikov <sb...@gridgain.com>
Authored: Tue May 24 16:57:20 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Tue May 24 16:57:20 2016 +0300
----------------------------------------------------------------------
.../ignite/internal/processors/cache/GridCacheMapEntry.java | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/a0141a44/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index 74dfe00..b369df1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -3692,6 +3692,9 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
CacheObject expiredVal = rawGetOrUnmarshal(false);
+ if (expiredVal == null)
+ return false;
+
if (onExpired(expiredVal, obsoleteVer)) {
if (cctx.deferredDelete()) {
deferred = true;
[12/17] ignite git commit: IGNITE-3191: IGFS: Improved error logging
for operations in dual mode.
Posted by sb...@apache.org.
IGNITE-3191: IGFS: Improved error logging for operations in dual mode.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9b81b75a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9b81b75a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9b81b75a
Branch: refs/heads/ignite-3116
Commit: 9b81b75a6880131431dbcd79d270ded3d33ed116
Parents: 78be02f
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed May 25 13:07:03 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed May 25 13:07:03 2016 +0300
----------------------------------------------------------------------
.../internal/processors/igfs/IgfsImpl.java | 60 +++++++++++++++-----
1 file changed, 45 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/9b81b75a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
index 358aaf0..967d962 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
@@ -551,8 +551,16 @@ public final class IgfsImpl implements IgfsEx {
case DUAL_ASYNC:
res = meta.fileId(path) != null;
- if (!res)
- res = secondaryFs.exists(path);
+ if (!res) {
+ try {
+ res = secondaryFs.exists(path);
+ }
+ catch (Exception e) {
+ U.error(log, "Exists in DUAL mode failed [path=" + path + ']', e);
+
+ throw e;
+ }
+ }
break;
@@ -798,10 +806,17 @@ public final class IgfsImpl implements IgfsEx {
if (childrenModes.contains(DUAL_SYNC) || childrenModes.contains(DUAL_ASYNC)) {
assert secondaryFs != null;
- Collection<IgfsPath> children = secondaryFs.listPaths(path);
+ try {
+ Collection<IgfsPath> children = secondaryFs.listPaths(path);
- for (IgfsPath child : children)
- files.add(child.name());
+ for (IgfsPath child : children)
+ files.add(child.name());
+ }
+ catch (Exception e) {
+ U.error(log, "List paths in DUAL mode failed [path=" + path + ']', e);
+
+ throw e;
+ }
}
IgniteUuid fileId = meta.fileId(path);
@@ -841,12 +856,19 @@ public final class IgfsImpl implements IgfsEx {
if (childrenModes.contains(DUAL_SYNC) || childrenModes.contains(DUAL_ASYNC)) {
assert secondaryFs != null;
- Collection<IgfsFile> children = secondaryFs.listFiles(path);
+ try {
+ Collection<IgfsFile> children = secondaryFs.listFiles(path);
+
+ for (IgfsFile child : children) {
+ IgfsFileImpl impl = new IgfsFileImpl(child, data.groupBlockSize());
- for (IgfsFile child : children) {
- IgfsFileImpl impl = new IgfsFileImpl(child, data.groupBlockSize());
+ files.add(impl);
+ }
+ }
+ catch (Exception e) {
+ U.error(log, "List files in DUAL mode failed [path=" + path + ']', e);
- files.add(impl);
+ throw e;
}
}
@@ -1221,7 +1243,8 @@ public final class IgfsImpl implements IgfsEx {
if (secondaryFs != null) {
try {
secondarySpaceSize = secondaryFs.usedSpaceSize();
- } catch (IgniteException e) {
+ }
+ catch (IgniteException e) {
LT.warn(log, e, "Failed to get secondary file system consumed space size.");
secondarySpaceSize = -1;
@@ -1557,9 +1580,9 @@ public final class IgfsImpl implements IgfsEx {
* @param path Path.
* @param mode Mode.
* @return File info or {@code null} in case file is not found.
- * @throws IgniteCheckedException If failed.
+ * @throws Exception If failed.
*/
- private IgfsFileImpl resolveFileInfo(IgfsPath path, IgfsMode mode) throws IgniteCheckedException {
+ private IgfsFileImpl resolveFileInfo(IgfsPath path, IgfsMode mode) throws Exception {
assert path != null;
assert mode != null;
@@ -1576,10 +1599,17 @@ public final class IgfsImpl implements IgfsEx {
info = meta.info(meta.fileId(path));
if (info == null) {
- IgfsFile status = secondaryFs.info(path);
+ try {
+ IgfsFile status = secondaryFs.info(path);
+
+ if (status != null)
+ return new IgfsFileImpl(status, data.groupBlockSize());
+ }
+ catch (Exception e) {
+ U.error(log, "File info operation in DUAL mode failed [path=" + path + ']', e);
- if (status != null)
- return new IgfsFileImpl(status, data.groupBlockSize());
+ throw e;
+ }
}
break;