You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by dg...@apache.org on 2019/01/05 16:33:24 UTC
[ignite] branch master updated: IGNITE-10290 Fix Map.Entry
interface for key cache may lead to incorrect hash code calculation - Fixes
#5405.
This is an automated email from the ASF dual-hosted git repository.
dgovorukhin 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 25d914e IGNITE-10290 Fix Map.Entry interface for key cache may lead to incorrect hash code calculation - Fixes #5405.
25d914e is described below
commit 25d914ef88be744f22a41efd5edf86fb0f9d36f3
Author: DmitriyGovorukhin <dm...@gmail.com>
AuthorDate: Sat Jan 5 19:32:17 2019 +0300
IGNITE-10290 Fix Map.Entry interface for key cache may lead to incorrect hash code calculation - Fixes #5405.
Signed-off-by: Dmitriy Govorukhin <dm...@gmail.com>
---
.../distributed/dht/GridPartitionedGetFuture.java | 6 +-
.../dht/GridPartitionedSingleGetFuture.java | 6 +-
.../cache/CacheLocalGetSerializationTest.java | 68 ++++++++++++++++++++++
.../ignite/testsuites/IgniteBasicTestSuite.java | 3 +
4 files changed, 79 insertions(+), 4 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
index 0629754..55fae44 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
@@ -482,9 +482,11 @@ public class GridPartitionedGetFuture<K, V> extends CacheDistributedGetFutureAda
GridCacheVersion ver = null;
if (readNoEntry) {
+ KeyCacheObject key0 = (KeyCacheObject)cctx.cacheObjects().prepareForCache(key, cctx);
+
CacheDataRow row = cctx.mvccEnabled() ?
- cctx.offheap().mvccRead(cctx, key, mvccSnapshot()) :
- cctx.offheap().read(cctx, key);
+ cctx.offheap().mvccRead(cctx, key0, mvccSnapshot()) :
+ cctx.offheap().read(cctx, key0);
if (row != null) {
long expireTime = row.expireTime();
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
index 0d69485..8878414 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
@@ -440,9 +440,11 @@ public class GridPartitionedSingleGetFuture extends GridCacheFutureAdapter<Objec
boolean skipEntry = readNoEntry;
if (readNoEntry) {
+ KeyCacheObject key0 = (KeyCacheObject)cctx.cacheObjects().prepareForCache(key, cctx);
+
CacheDataRow row = mvccSnapshot != null ?
- cctx.offheap().mvccRead(cctx, key, mvccSnapshot) :
- cctx.offheap().read(cctx, key);
+ cctx.offheap().mvccRead(cctx, key0, mvccSnapshot) :
+ cctx.offheap().read(cctx, key0);
if (row != null) {
long expireTime = row.expireTime();
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheLocalGetSerializationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheLocalGetSerializationTest.java
new file mode 100644
index 0000000..bfcc413
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheLocalGetSerializationTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.Map;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ *
+ */
+@RunWith(JUnit4.class)
+public class CacheLocalGetSerializationTest extends GridCommonAbstractTest {
+ /**
+ * Check correct Map.Entry serialization key on local get/put operation.
+ * https://issues.apache.org/jira/browse/IGNITE-10290
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void test() throws Exception {
+ Ignite ig = startGrid();
+
+ IgniteCache<Map.Entry<Integer, Integer>, Long> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME);
+
+ // Try use Map.Entry as key in destributed map.
+ Map.Entry<Integer, Integer> key = new Map.Entry<Integer, Integer>() {
+ @Override public Integer getKey() {
+ return 123;
+ }
+
+ @Override public Integer getValue() {
+ return 123;
+ }
+
+ @Override public Integer setValue(Integer value) {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ cache.put(key, Long.MAX_VALUE);
+
+ Long val = cache.get(key);
+
+ Assert.assertNotNull(val);
+ Assert.assertEquals(Long.MAX_VALUE, (long)val);
+ }
+}
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 276dbc5..369a0b5 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
@@ -47,6 +47,7 @@ import org.apache.ignite.internal.managers.IgniteDiagnosticMessagesMultipleConne
import org.apache.ignite.internal.managers.IgniteDiagnosticMessagesTest;
import org.apache.ignite.internal.processors.affinity.GridAffinityProcessorMemoryLeakTest;
import org.apache.ignite.internal.processors.affinity.GridAffinityProcessorRendezvousSelfTest;
+import org.apache.ignite.internal.processors.cache.CacheLocalGetSerializationTest;
import org.apache.ignite.internal.processors.cache.CacheRebalanceConfigValidationTest;
import org.apache.ignite.internal.processors.cache.GridLocalIgniteSerializationTest;
import org.apache.ignite.internal.processors.cache.GridProjectionForCachesOnDaemonNodeSelfTest;
@@ -219,6 +220,8 @@ public class IgniteBasicTestSuite {
suite.addTest(new JUnit4TestAdapter(ListeningTestLoggerTest.class));
+ suite.addTest(new JUnit4TestAdapter(CacheLocalGetSerializationTest.class));
+
return suite;
}
}