You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by il...@apache.org on 2019/04/01 13:42:08 UTC
[ignite] branch master updated: IGNITE-11660 Choose correct closure
in DmlStatementsProcessorTest, more tests - Fixes #6379.
This is an automated email from the ASF dual-hosted git repository.
ilyak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new a309335 IGNITE-11660 Choose correct closure in DmlStatementsProcessorTest, more tests - Fixes #6379.
a309335 is described below
commit a3093358c8c71d4f7fb5e3053abc62c3ae7357cb
Author: tledkov <tl...@gridgain.com>
AuthorDate: Mon Apr 1 16:40:24 2019 +0300
IGNITE-11660 Choose correct closure in DmlStatementsProcessorTest, more tests - Fixes #6379.
Signed-off-by: Ilya Kasnacheev <il...@gmail.com>
---
.../query/h2/DmlStatementsProcessor.java | 34 ++++++++++++++---
.../processors/query/h2/dml/DmlBatchSender.java | 22 ++++++++---
.../internal/processors/query/h2/dml/DmlUtils.java | 14 ++++++-
.../query/h2/DmlStatementsProcessorTest.java | 44 +++++++++++++++++++++-
4 files changed, 100 insertions(+), 14 deletions(-)
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
index 2072622..de2cf1b 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
@@ -17,12 +17,13 @@
package org.apache.ignite.internal.processors.query.h2;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.lang.IgniteInClosure;
-
import javax.cache.processor.EntryProcessor;
import javax.cache.processor.EntryProcessorException;
import javax.cache.processor.MutableEntry;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgniteInClosure;
+import org.apache.ignite.lang.IgniteProductVersion;
/**
* Contains entry processors for DML. Should be modified very carefully to maintain binary compatibility due to
@@ -30,6 +31,10 @@ import javax.cache.processor.MutableEntry;
*/
@SuppressWarnings({"Anonymous2MethodRef", "PublicInnerClass", "unused"})
public class DmlStatementsProcessor {
+ /** The version which changed the anonymous class position of REMOVE closure. */
+ private static final IgniteProductVersion RMV_ANON_CLS_POS_CHANGED_SINCE =
+ IgniteProductVersion.fromString("2.7.0");
+
/** */
public static final class InsertEntryProcessor implements EntryProcessor<Object, Object, Boolean> {
/** Value to set. */
@@ -112,7 +117,7 @@ public class DmlStatementsProcessor {
};
/** Remove updater for compatibility with < 2.7.0. Must not be moved around to keep at anonymous position 4. */
- public static final IgniteInClosure<MutableEntry<Object, Object>> RMV_OLD =
+ private static final IgniteInClosure<MutableEntry<Object, Object>> RMV_OLD =
new IgniteInClosure<MutableEntry<Object, Object>>() {
@Override public void apply(MutableEntry<Object, Object> e) {
e.remove();
@@ -120,7 +125,7 @@ public class DmlStatementsProcessor {
};
/** Remove updater. Must not be moved around to keep at anonymous position 5. */
- public static final IgniteInClosure<MutableEntry<Object, Object>> RMV =
+ private static final IgniteInClosure<MutableEntry<Object, Object>> RMV =
new IgniteInClosure<MutableEntry<Object, Object>>() {
@Override public void apply(MutableEntry<Object, Object> e) {
e.remove();
@@ -128,6 +133,25 @@ public class DmlStatementsProcessor {
};
/**
+ * Returns the remove closure based on the version of the primary node.
+ *
+ * @param node Primary node.
+ * @param key Key.
+ * @return Remove closure.
+ */
+ public static IgniteInClosure<MutableEntry<Object, Object>> getRemoveClosure(ClusterNode node, Object key) {
+ assert node != null;
+ assert key != null;
+
+ IgniteInClosure<MutableEntry<Object, Object>> rmvC = RMV;
+
+ if (node.version().compareTo(RMV_ANON_CLS_POS_CHANGED_SINCE) < 0)
+ rmvC = RMV_OLD;
+
+ return rmvC;
+ }
+
+ /**
* Entry value updater.
*/
public static final class EntryValueUpdater implements IgniteInClosure<MutableEntry<Object, Object>> {
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlBatchSender.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlBatchSender.java
index 814a174..2015965 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlBatchSender.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlBatchSender.java
@@ -98,14 +98,10 @@ public class DmlBatchSender {
throws IgniteCheckedException {
assert key != null;
assert proc != null;
-
- ClusterNode node = cctx.affinity().primaryByKey(key, AffinityTopologyVersion.NONE);
-
- if (node == null)
- throw new IgniteCheckedException("Failed to map key to node.");
-
assert rowNum < cntPerRow.length;
+ ClusterNode node = primaryNodeByKey(key);
+
UUID nodeId = node.id();
Batch batch = batches.get(nodeId);
@@ -127,6 +123,20 @@ public class DmlBatchSender {
}
/**
+ * @param key Key.
+ * @return Primary node for given key.
+ * @throws IgniteCheckedException If primary node is not found.
+ */
+ public ClusterNode primaryNodeByKey(Object key) throws IgniteCheckedException {
+ ClusterNode node = cctx.affinity().primaryByKey(key, AffinityTopologyVersion.NONE);
+
+ if (node == null)
+ throw new IgniteCheckedException("Failed to map key to node.");
+
+ return node;
+ }
+
+ /**
* Flush any remaining entries.
*/
public void flush() {
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java
index 93cf1aa..0262ede 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java
@@ -29,8 +29,10 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import javax.cache.processor.MutableEntry;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.internal.processors.cache.CacheOperationContext;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
@@ -46,6 +48,7 @@ import org.apache.ignite.internal.util.typedef.T3;
import org.apache.ignite.internal.util.typedef.X;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.lang.IgniteInClosure;
import org.apache.ignite.transactions.TransactionDuplicateKeyException;
import org.h2.util.DateTimeUtils;
import org.h2.util.LocalDateTimeUtils;
@@ -340,9 +343,16 @@ public class DmlUtils {
if (row.size() != 2)
continue;
+ Object key = row.get(0);
+
+ ClusterNode node = sender.primaryNodeByKey(key);
+
+ IgniteInClosure<MutableEntry<Object, Object>> rmvC =
+ DmlStatementsProcessor.getRemoveClosure(node, key);
+
sender.add(
- row.get(0),
- new DmlStatementsProcessor.ModifyingEntryProcessor(row.get(1), DmlStatementsProcessor.RMV),
+ key,
+ new DmlStatementsProcessor.ModifyingEntryProcessor(row.get(1), rmvC),
0
);
}
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessorTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessorTest.java
index da57e82..63ae900 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessorTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessorTest.java
@@ -18,12 +18,15 @@
package org.apache.ignite.internal.processors.query.h2;
import javax.cache.processor.MutableEntry;
+import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.lang.IgniteInClosure;
+import org.apache.ignite.lang.IgniteProductVersion;
+import org.apache.ignite.testframework.GridTestNode;
import org.junit.Assert;
import org.junit.Test;
/**
- * Ensures that abstart classes of entry modifiers are compatible with old versions.
+ * Ensures that anonymous classes of entry modifiers are compatible with old versions.
*/
public class DmlStatementsProcessorTest {
/**
@@ -49,8 +52,47 @@ public class DmlStatementsProcessorTest {
}
/**
+ * Checks that the old remove-closure is used if the remote node version is less than 2.7.0.
+ */
+ @Test
+ public void testRemoveEntryModifierClassName() {
+ String oldClsName = DmlStatementsProcessor.class.getName() + "$" + 4;
+ String newClsName = DmlStatementsProcessor.class.getName() + "$" + 5;
+
+ checkRemoveEntryClassName("2.4.0", oldClsName);
+ checkRemoveEntryClassName("2.5.0", oldClsName);
+ checkRemoveEntryClassName("2.6.0", oldClsName);
+
+ checkRemoveEntryClassName("2.7.0", newClsName);
+ checkRemoveEntryClassName("2.8.0", newClsName);
+ }
+
+ /**
+ * Checks remove-closure class name.
+ *
+ * @param ver The version of the remote node.
+ * @param expClsName Expected class name.
+ */
+ private void checkRemoveEntryClassName(final String ver, String expClsName) {
+ ClusterNode node = new GridTestNode() {
+ @Override public IgniteProductVersion version() {
+ return IgniteProductVersion.fromString(ver);
+ }
+ };
+
+ IgniteInClosure<MutableEntry<Object, Object>> rmvC =
+ DmlStatementsProcessor.getRemoveClosure(node, 0);
+
+ Assert.assertNotNull("Check remove-closure", rmvC);
+
+ Assert.assertEquals("Check remove-closure class name for version " + ver,
+ expClsName, rmvC.getClass().getName());
+ }
+
+ /**
* Checks that remove-closure is available by anonymous class position.
*/
+ @SuppressWarnings("unchecked")
private void checkRemoveClosureByAnonymousPosition(int position) throws Exception {
Class<?> cls = Class.forName(DmlStatementsProcessor.class.getName() + "$" + position);