From f4e882e6dc4d829e1e143ee050108c21e55afac4 Mon Sep 17 00:00:00 2001 From: Sergey Chernolyas Date: Mon, 25 Sep 2017 10:47:03 +0300 Subject: [PATCH 01/13] IGNITE-6286: fix org.h2.jdbc.JdbcSQLException changes: 1) develop test for check all supported types for parameterized queries 2) add support BigDecimal type as type of paraameter's value --- .../processors/query/h2/IgniteH2Indexing.java | 4 + .../IgniteSqlParameterizedQueryTest.java | 382 ++++++++++++++++++ 2 files changed, 386 insertions(+) create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index 03e2391fb3db0..c746b36e075b7 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -19,6 +19,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Connection; import java.sql.DriverManager; @@ -508,10 +509,13 @@ public void executeStatement(String schema, String sql) throws IgniteCheckedExce */ private void bindObject(PreparedStatement stmt, int idx, @Nullable Object obj) throws IgniteCheckedException { try { + log.info("bindObject [idx=" +idx + ", obj=" + obj.getClass() + ']'); if (obj == null) stmt.setNull(idx, Types.VARCHAR); else if (obj instanceof BigInteger) stmt.setObject(idx, obj, Types.JAVA_OBJECT); + else if (obj instanceof BigDecimal) + stmt.setObject(idx, obj, Types.DECIMAL); else stmt.setObject(idx, obj); } diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java new file mode 100644 index 0000000000000..8273dcdefafb5 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java @@ -0,0 +1,382 @@ +/* + * Hibernate OGM, Domain model persistence for NoSQL datastores + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.apache.ignite.internal.processors.query; + +import java.io.Serializable; +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.query.QueryCursor; +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.configuration.IgniteConfiguration; +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; + +/** + * Test sql queries with parameters for all types The test fix IGNITE-6286 + * + * @author Sergey Chernolyas &sergey_chernolyas@gmail.com& + * @see IGNITE-6286 + */ +public class IgniteSqlParameterizedQueryTest extends GridCommonAbstractTest { + /** IP finder. */ + private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + private static String CACHE_BOOKMARK = "Bookmark"; + private static String NODE_CLIENT = "client"; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration c = super.getConfiguration(gridName); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(IP_FINDER); + + c.setDiscoverySpi(disco); + + c.setCacheConfiguration(buildCacheConfiguration(CACHE_BOOKMARK)); + if (gridName.equals(NODE_CLIENT)) + c.setClientMode(true); + + return c; + } + + private CacheConfiguration buildCacheConfiguration(String name) { + CacheConfiguration ccfg = new CacheConfiguration(name); + QueryEntity bookmarkQueryEntity = new QueryEntity(String.class.getName(), Bookmark.class.getName()); + + for (Field currentField : Bookmark.class.getDeclaredFields()) { + bookmarkQueryEntity.addQueryField(currentField.getName(), currentField.getType().getName(), null); + } + log.info("createEntityCacheConfiguration. full QueryEntity info : :"+bookmarkQueryEntity.toString()); + List queryEntities = new ArrayList<>(); + queryEntities.add(bookmarkQueryEntity); + ccfg.setQueryEntities(queryEntities); + return ccfg; + + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + startGrid(0); + startGrid(NODE_CLIENT); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + + private Bookmark searchBookmarkBy(String field, Object value) { + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + SqlFieldsQuery query = new SqlFieldsQuery("SELECT _val from Bookmark where "+field+"=?"); + query.setArgs(value); + + QueryCursor> cursor = cache.query(query); + List> results = cursor.getAll(); + assertEquals(1, results.size()); + List row0 = results.get(0); + return (Bookmark)row0.get(0); + } + + public void testStringSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setDescription("description"); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("description", "description"); + assertEquals("String value does not match", bookmark.getDescription(), loadedBookmark.getDescription()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testIntegerSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setStockCount(Integer.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("stockCount", Integer.MAX_VALUE); + assertEquals("Integer value does not match", bookmark.getStockCount(), loadedBookmark.getStockCount()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testShortSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setUrlPort(Short.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("urlPort", Short.MAX_VALUE); + assertEquals("Short value does not match", bookmark.getUrlPort(), loadedBookmark.getUrlPort()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testLongSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setUserId(Long.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("userId", Long.MAX_VALUE); + assertEquals("Long value does not match", bookmark.getUserId(), loadedBookmark.getUserId()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testFloatSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setVisitRatio(Float.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("visitRatio", Float.MAX_VALUE); + assertEquals("Float value does not match", bookmark.getVisitRatio(), loadedBookmark.getVisitRatio()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testDoubleSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setTaxPercentage(Double.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("taxPercentage", Double.MAX_VALUE); + assertEquals("Double value does not match", bookmark.getTaxPercentage(), loadedBookmark.getTaxPercentage()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testBooleanSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setFavourite(true); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("favourite", true); + assertEquals("Boolean value does not match", bookmark.getFavourite(), loadedBookmark.getFavourite()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testByteSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setDisplayMask(Byte.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("displayMask", Byte.MAX_VALUE); + assertEquals("Byte value does not match", bookmark.getDisplayMask(), loadedBookmark.getDisplayMask()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testUUIDSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + final UUID uuid = UUID.randomUUID(); + bookmark.setSerialNumber(uuid); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("serialNumber", uuid); + assertEquals("UUID value does not match", bookmark.getSerialNumber(), loadedBookmark.getSerialNumber()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + public void testBigIntegerSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + BigInteger bi = new BigInteger("1000000000000000"); + bookmark.setVisitCount(bi); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("visitCount", bi); + assertEquals("BigInteger value does not match", bookmark.getVisitCount(), loadedBookmark.getVisitCount()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + public void testBigDecimalSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + BigDecimal bd = new BigDecimal("1000000000000000.001"); + bookmark.setSiteWeight(bd); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("siteWeight", bd); + assertEquals("BigDecimal value does not match", bookmark.getSiteWeight(), loadedBookmark.getSiteWeight()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + /** + * Object with all types that supported in H2 + * @see H2 types + */ + + public static class Bookmark implements Serializable { + private String id; + + // basic types + private String description; + private Integer stockCount; + private Short urlPort; + private Long userId; + private Float visitRatio; + private Double taxPercentage; + private Boolean favourite; + private Byte displayMask; + + // "special" types + //http://www.h2database.com/html/datatypes.html#uuid_type + private UUID serialNumber; + private BigDecimal siteWeight; + private BigInteger visitCount; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + + public Integer getStockCount() { + return stockCount; + } + + public void setStockCount(Integer stockCount) { + this.stockCount = stockCount; + } + + public Short getUrlPort() { + return urlPort; + } + + public void setUrlPort(Short urlPort) { + this.urlPort = urlPort; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Float getVisitRatio() { + return visitRatio; + } + + public void setVisitRatio(Float visitRatio) { + this.visitRatio = visitRatio; + } + + public Double getTaxPercentage() { + return taxPercentage; + } + + public void setTaxPercentage(Double taxPercentage) { + this.taxPercentage = taxPercentage; + } + + public Boolean getFavourite() { + return favourite; + } + + public void setFavourite(Boolean favourite) { + this.favourite = favourite; + } + + public Byte getDisplayMask() { + return displayMask; + } + + public void setDisplayMask(Byte displayMask) { + this.displayMask = displayMask; + } + + public UUID getSerialNumber() { + return serialNumber; + } + + public void setSerialNumber(UUID serialNumber) { + this.serialNumber = serialNumber; + } + + public BigDecimal getSiteWeight() { + return siteWeight; + } + + public void setSiteWeight(BigDecimal siteWeight) { + this.siteWeight = siteWeight; + } + + public BigInteger getVisitCount() { + return visitCount; + } + + public void setVisitCount(BigInteger visitCount) { + this.visitCount = visitCount; + } + + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Bookmark bookmark = (Bookmark)o; + return Objects.equals(id, bookmark.id); + } + + @Override public int hashCode() { + return Objects.hash(id); + } + } + +} + + From 5e577e91b04601276c3b3d2a17df2cac4d22ae9f Mon Sep 17 00:00:00 2001 From: Sergey Chernolyas Date: Mon, 25 Sep 2017 11:27:57 +0300 Subject: [PATCH 02/13] IGNITE-6286: correct header of class --- .../query/IgniteSqlParameterizedQueryTest.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java index 8273dcdefafb5..e2d3f9ad26831 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java @@ -1,9 +1,20 @@ /* - * Hibernate OGM, Domain model persistence for NoSQL datastores + * 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 * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or . + * 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.query; import java.io.Serializable; From 6f1ca419fab840b920d408336ced69abaa4147cf Mon Sep 17 00:00:00 2001 From: Pavel Tupitsyn Date: Mon, 25 Sep 2017 13:05:32 +0300 Subject: [PATCH 03/13] IGNITE-6486 .NET: Update IsActiveOnStart documentation This closes #2729 --- .../configuration/IgniteConfiguration.java | 6 +++ .../Cache/PersistentStoreTest.cs | 47 +++---------------- .../Apache.Ignite.Core/IgniteConfiguration.cs | 3 ++ 3 files changed, 15 insertions(+), 41 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index 6e91b10438aa4..a79d4360d5185 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -2207,6 +2207,9 @@ public IgniteConfiguration setPersistentStoreConfiguration(PersistentStoreConfig * significantly speed up large topology startup time. *

* Default value is {@link #DFLT_ACTIVE_ON_START}. + *

+ * This flag is ignored when {@link PersistentStoreConfiguration} is present: + * cluster is always inactive on start when Ignite Persistence is enabled. * * @return Active on start flag value. */ @@ -2217,6 +2220,9 @@ public boolean isActiveOnStart() { /** * Sets flag indicating whether the cluster will be active on start. This value should be the same on all * nodes in the cluster. + *

+ * This flag is ignored when {@link PersistentStoreConfiguration} is present: + * cluster is always inactive on start when Ignite Persistence is enabled. * * @param activeOnStart Active on start flag value. * @return {@code this} instance. diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PersistentStoreTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PersistentStoreTest.cs index d321639751b4b..a592859d996b1 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PersistentStoreTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PersistentStoreTest.cs @@ -18,7 +18,6 @@ namespace Apache.Ignite.Core.Tests.Cache { using System.IO; - using Apache.Ignite.Core.Cache.Configuration; using Apache.Ignite.Core.Common; using Apache.Ignite.Core.Impl; using Apache.Ignite.Core.PersistentStore; @@ -52,15 +51,14 @@ public void TearDown() [Test] public void TestCacheDataSurvivesNodeRestart() { - var cfg = new IgniteConfiguration(GetTestConfiguration()) + var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { PersistentStoreConfiguration = new PersistentStoreConfiguration { PersistentStorePath = Path.Combine(_tempDir, "Store"), WalStorePath = Path.Combine(_tempDir, "WalStore"), WalArchivePath = Path.Combine(_tempDir, "WalArchive"), - MetricsEnabled = true, - CheckpointingPageBufferSize = 1024 * 1024 // TODO: Use default (IGNITE-5717) + MetricsEnabled = true } }; @@ -115,14 +113,12 @@ public void TestCacheDataSurvivesNodeRestart() [Test] public void TestGridActivationWithPersistence() { - var cfg = new IgniteConfiguration(GetTestConfiguration()) + var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { - PersistentStoreConfiguration = new PersistentStoreConfiguration - { - CheckpointingPageBufferSize = 1024 * 1024 // TODO: Use default (IGNITE-5717) - } + PersistentStoreConfiguration = new PersistentStoreConfiguration() }; + // Default config, inactive by default (IsActiveOnStart is ignored when persistence is enabled). using (var ignite = Ignition.Start(cfg)) { CheckIsActive(ignite, false); @@ -134,7 +130,7 @@ public void TestGridActivationWithPersistence() CheckIsActive(ignite, false); } } - + ///

/// Tests the grid activation without persistence (active by default). /// @@ -189,36 +185,5 @@ private static void CheckIsActive(IIgnite ignite, bool isActive) ex.Message.Substring(0, 62)); } } - - /// - /// Gets the test configuration. - /// - private static IgniteConfiguration GetTestConfiguration() - { - return new IgniteConfiguration(TestUtils.GetTestConfiguration()) - { - MemoryConfiguration = GetMemoryConfig() - }; - } - - /// - /// Gets the memory configuration with reduced MaxMemory to work around persistence bug. - /// - private static MemoryConfiguration GetMemoryConfig() - { - // TODO: Remove this method and use default config (IGNITE-5717). - return new MemoryConfiguration - { - MemoryPolicies = new[] - { - new MemoryPolicyConfiguration - { - Name = MemoryConfiguration.DefaultDefaultMemoryPolicyName, - InitialSize = 512*1024*1024, - MaxSize = 512*1024*1024 - } - } - }; - } } } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs index 5ac2258fd6642..14cd3756523db 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs @@ -1262,6 +1262,9 @@ public TimeSpan LongQueryWarningTimeout /// /// Gets or sets a value indicating whether grid should be active on start. /// See also and . + /// + /// This property is ignored when is present: + /// cluster is always inactive on start when Ignite Persistence is enabled. /// [DefaultValue(DefaultIsActiveOnStart)] public bool IsActiveOnStart From 68c100df28ddd97828fd67c2d46f6124ce080d4c Mon Sep 17 00:00:00 2001 From: Pavel Tupitsyn Date: Mon, 25 Sep 2017 13:07:35 +0300 Subject: [PATCH 04/13] IGNITE-6249 .NET: IgniteConfiguration.ConsistentId This closes #2727 --- .../utils/PlatformConfigurationUtils.java | 10 +++ .../IgniteConfigurationSerializerTest.cs | 7 +- .../IgniteConfigurationTest.cs | 73 +++++++++++++++++-- .../Apache.Ignite.Core/IgniteConfiguration.cs | 7 ++ .../IgniteConfigurationSection.xsd | 5 ++ .../IgniteConfigurationXmlSerializer.cs | 4 +- 6 files changed, 97 insertions(+), 9 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java index 7e17bdb3ed0ad..dc451668f4307 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.processors.platform.utils; +import java.io.Serializable; import java.lang.management.ManagementFactory; import java.net.InetSocketAddress; import java.security.AccessController; @@ -571,6 +572,14 @@ public static void readIgniteConfiguration(BinaryRawReaderEx in, IgniteConfigura if (in.readBoolean()) cfg.setActiveOnStart(in.readBoolean()); + Object consId = in.readObjectDetached(); + + if (consId instanceof Serializable) { + cfg.setConsistentId((Serializable) consId); + } else if (consId != null) { + throw new IgniteException("IgniteConfiguration.ConsistentId should be Serializable."); + } + // Thread pools. if (in.readBoolean()) cfg.setPublicThreadPoolSize(in.readInt()); @@ -1025,6 +1034,7 @@ public static void writeIgniteConfiguration(BinaryRawWriter w, IgniteConfigurati w.writeLong(cfg.getLongQueryWarningTimeout()); w.writeBoolean(true); w.writeBoolean(cfg.isActiveOnStart()); + w.writeObject(cfg.getConsistentId()); // Thread pools. w.writeBoolean(true); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs index ac214ce64cd47..23ee8845e1005 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs @@ -68,7 +68,7 @@ public class IgniteConfigurationSerializerTest [Test] public void TestPredefinedXml() { - var xml = @" + var xml = @" 127.1.1.1 @@ -145,6 +145,7 @@ public void TestPredefinedXml() + someId012 "; var cfg = IgniteConfiguration.FromXml(xml); @@ -171,6 +172,7 @@ public void TestPredefinedXml() Assert.IsTrue(cfg.AutoGenerateIgniteInstanceName); Assert.AreEqual(new TimeSpan(1, 2, 3), cfg.LongQueryWarningTimeout); Assert.IsFalse(cfg.IsActiveOnStart); + Assert.AreEqual("someId012", cfg.ConsistentId); Assert.AreEqual("secondCache", cfg.CacheConfiguration.Last().Name); @@ -927,7 +929,8 @@ private static IgniteConfiguration GetTestConfig() MetricsEnabled = true, RateTimeInterval = TimeSpan.FromDays(1) }, - IsActiveOnStart = false + IsActiveOnStart = false, + ConsistentId = "myId123" }; } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs index 5facb388ed5c6..4f8014fcd5c3c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs @@ -47,10 +47,10 @@ namespace Apache.Ignite.Core.Tests public class IgniteConfigurationTest { /// - /// Fixture setup. + /// Fixture tear down. /// [TestFixtureSetUp] - public void FixtureSetUp() + public void FixtureTearDown() { Ignition.StopAll(true); } @@ -195,6 +195,8 @@ public void TestAllConfigurationProperties() Assert.AreEqual(cfg.UtilityCacheThreadPoolSize, resCfg.UtilityCacheThreadPoolSize); Assert.AreEqual(cfg.QueryThreadPoolSize, resCfg.QueryThreadPoolSize); + Assert.AreEqual(cfg.ConsistentId, resCfg.ConsistentId); + var binCfg = cfg.BinaryConfiguration; Assert.IsFalse(binCfg.CompactFooter); @@ -462,6 +464,31 @@ public void TestWorkDirectory() Directory.Delete(cfg.WorkDirectory, true); } + /// + /// Tests the consistent id. + /// + [Test] + [NUnit.Framework.Category(TestUtils.CategoryIntensive)] + public void TestConsistentId() + { + var ids = new object[] + { + null, new MyConsistentId {Data = "foo"}, "str", 1, 1.1, DateTime.Now, Guid.NewGuid() + }; + + var cfg = TestUtils.GetTestConfiguration(); + + foreach (var id in ids) + { + cfg.ConsistentId = id; + + using (var ignite = Ignition.Start(cfg)) + { + Assert.AreEqual(id, ignite.GetConfiguration().ConsistentId); + } + } + } + /// /// Tests the ip finders. /// @@ -636,7 +663,7 @@ private static IgniteConfiguration GetCustomConfig() JoinTimeout = TimeSpan.FromSeconds(5), IpFinder = new TcpDiscoveryStaticIpFinder { - Endpoints = new[] { "127.0.0.1:49900", "127.0.0.1:49901" } + Endpoints = new[] {"127.0.0.1:49900", "127.0.0.1:49901"} }, ClientReconnectDisabled = true, ForceServerMode = true, @@ -718,7 +745,7 @@ private static IgniteConfiguration GetCustomConfig() } }, // Skip cache check because with persistence the grid is not active by default. - PluginConfigurations = new[] { new TestIgnitePluginConfiguration{ SkipCacheCheck = true } }, + PluginConfigurations = new[] {new TestIgnitePluginConfiguration {SkipCacheCheck = true}}, EventStorageSpi = new MemoryEventStorageSpi { ExpirationTimeout = TimeSpan.FromSeconds(5), @@ -754,7 +781,7 @@ private static IgniteConfiguration GetCustomConfig() EmptyPagesPoolSize = 66, SwapFilePath = "somePath2", MetricsEnabled = true - } + } } }, PublicThreadPoolSize = 3, @@ -798,8 +825,42 @@ private static IgniteConfiguration GetCustomConfig() MetricsEnabled = true, SubIntervals = 7, RateTimeInterval = TimeSpan.FromSeconds(9) - } + }, + ConsistentId = new MyConsistentId {Data = "abc"} }; } + + private class MyConsistentId + { + public string Data { get; set; } + + private bool Equals(MyConsistentId other) + { + return string.Equals(Data, other.Data); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((MyConsistentId) obj); + } + + public override int GetHashCode() + { + return (Data != null ? Data.GetHashCode() : 0); + } + + public static bool operator ==(MyConsistentId left, MyConsistentId right) + { + return Equals(left, right); + } + + public static bool operator !=(MyConsistentId left, MyConsistentId right) + { + return !Equals(left, right); + } + } } } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs index 14cd3756523db..cb91ee1bcc259 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs @@ -281,6 +281,7 @@ internal void Write(BinaryWriter writer) writer.WriteTimeSpanAsLongNullable(_clientFailureDetectionTimeout); writer.WriteTimeSpanAsLongNullable(_longQueryWarningTimeout); writer.WriteBooleanNullable(_isActiveOnStart); + writer.WriteObjectDetached(ConsistentId); // Thread pools writer.WriteIntNullable(_publicThreadPoolSize); @@ -546,6 +547,7 @@ private void ReadCore(BinaryReader r) _clientFailureDetectionTimeout = r.ReadTimeSpanNullable(); _longQueryWarningTimeout = r.ReadTimeSpanNullable(); _isActiveOnStart = r.ReadBooleanNullable(); + ConsistentId = r.ReadObject(); // Thread pools _publicThreadPoolSize = r.ReadIntNullable(); @@ -1272,5 +1274,10 @@ public bool IsActiveOnStart get { return _isActiveOnStart ?? DefaultIsActiveOnStart; } set { _isActiveOnStart = value; } } + + /// + /// Gets or sets consistent globally unique node identifier which survives node restarts. + /// + public object ConsistentId { get; set; } } } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd index ac1111b898e01..19ce1101a19e3 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd +++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd @@ -1484,6 +1484,11 @@ + + + Consistent globally unique node identifier which survives node restarts. + + diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteConfigurationXmlSerializer.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteConfigurationXmlSerializer.cs index 775add4dff0b3..8ee0c07bb23dd 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteConfigurationXmlSerializer.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteConfigurationXmlSerializer.cs @@ -518,7 +518,9 @@ private static IEnumerable GetNonDefaultProperties(object obj) { Debug.Assert(obj != null); - return obj.GetType().GetProperties().Where(p => !Equals(p.GetValue(obj, null), GetDefaultValue(p))); + return obj.GetType().GetProperties() + .Where(p => p.GetIndexParameters().Length == 0 && // Skip indexed properties. + !Equals(p.GetValue(obj, null), GetDefaultValue(p))); } /// From 21cc7a486d3adfb79f5540d217e1a759076fd7ba Mon Sep 17 00:00:00 2001 From: Dmitriy Govorukhin Date: Mon, 25 Sep 2017 13:28:42 +0300 Subject: [PATCH 05/13] IGNITE-6493 fix IgnitePdsWalTlbTest.testWalDirectOutOfMemory() incorrect usage dataStreamer, must be in try-with-resource Signed-off-by: Andrey Gura --- .../cache/persistence/db/wal/IgnitePdsWalTlbTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgnitePdsWalTlbTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgnitePdsWalTlbTest.java index fd0fd34fe9135..8b3cbf8ef57d7 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgnitePdsWalTlbTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/IgnitePdsWalTlbTest.java @@ -113,9 +113,7 @@ public void testWalDirectOutOfMemory() throws Exception { boolean locked = true; - try { - IgniteDataStreamer streamer = ig.dataStreamer(CACHE_NAME); - + try (IgniteDataStreamer streamer = ig.dataStreamer(CACHE_NAME)) { for (int i = 0; i < 100_000; i++) { streamer.addData(i, 1); From 737033ca69d94c0b7fbc5554e06a461489fa54ea Mon Sep 17 00:00:00 2001 From: Pavel Tupitsyn Date: Mon, 25 Sep 2017 19:09:29 +0300 Subject: [PATCH 06/13] .NET: Fix code coverage - exclude remote-only class --- .../dotnet/Apache.Ignite.Core.Tests.TestDll/TestExtensions.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests.TestDll/TestExtensions.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests.TestDll/TestExtensions.cs index 65a1484bea42e..f67295b286af4 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests.TestDll/TestExtensions.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests.TestDll/TestExtensions.cs @@ -17,11 +17,13 @@ namespace Apache.Ignite.Core.Tests.TestDll { + using System.Diagnostics.CodeAnalysis; using System.Linq; /// /// Extension methods for tests. /// + [ExcludeFromCodeCoverage] public static class TestExtensions { /// From 357f6035a917ad7be9b7002aea5638d9d61b5330 Mon Sep 17 00:00:00 2001 From: Pavel Tupitsyn Date: Tue, 26 Sep 2017 11:37:31 +0300 Subject: [PATCH 07/13] IGNITE-6494 .NET: Fix CacheConfiguration.WriteSynchronizationMode default value This closes #2741 --- .../Apache.Ignite.Core.Tests.csproj | 4 ++ .../Binary/BinaryDynamicRegistrationTest.cs | 15 +++-- .../Cache/CacheConfigurationTest.cs | 39 +++++++++++- .../Config/Dynamic/dynamic-data.xml | 2 + .../Config/cache-default.xml | 56 +++++++++++++++++ .../IgniteConfigurationSerializerTest.cs | 58 ++---------------- .../Apache.Ignite.Core.Tests/TestUtils.cs | 61 +++++++++++++++++++ .../Cache/Configuration/CacheConfiguration.cs | 14 ++++- 8 files changed, 187 insertions(+), 62 deletions(-) create mode 100644 modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-default.xml diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj index 9e6cfb29b3632..375b6b812be99 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj @@ -308,6 +308,10 @@ PreserveNewest + + Designer + PreserveNewest + Designer PreserveNewest diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs index 01804b7b6ceb5..e635bd12cdb20 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs @@ -113,7 +113,8 @@ public void TestStore() { CacheStoreFactory = new StoreFactory(), ReadThrough = true, - WriteThrough = true + WriteThrough = true, + KeepBinaryInStore = true } } }; @@ -125,7 +126,8 @@ public void TestStore() { CacheStoreFactory = new StoreFactory(), ReadThrough = true, - WriteThrough = true + WriteThrough = true, + KeepBinaryInStore = true }); dynCache[2] = new Foo { Str = "test2", Int = 3 }; @@ -203,7 +205,8 @@ public void TestStoreFactory() { CacheStoreFactory = new StoreFactory {StringProp = "test", IntProp = 9}, ReadThrough = true, - WriteThrough = true + WriteThrough = true, + KeepBinaryInStore = true } } }; @@ -410,7 +413,11 @@ public void TestRegistrationMultithreaded([Values(true, false)] bool useTypeName /// private static void Test(IIgnite ignite1, IIgnite ignite2) { - var cfg = new CacheConfiguration("cache") {CacheMode = CacheMode.Partitioned}; + var cfg = new CacheConfiguration("cache") + { + CacheMode = CacheMode.Partitioned, + WriteSynchronizationMode = CacheWriteSynchronizationMode.FullSync + }; // Put on one grid. var cache1 = ignite1.GetOrCreateCache(cfg); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs index 435e65f88a7d4..b400ef6a68aef 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs @@ -48,6 +48,9 @@ public class CacheConfigurationTest /** */ private const string CacheName2 = "cacheName2"; + /** */ + private const string SpringCacheName = "cache-default-spring"; + /** */ private static int _factoryProp; @@ -79,7 +82,8 @@ public void FixtureSetUp() MaxSize = 99 * 1024 * 1024 } } - } + }, + SpringConfigUrl = "Config\\cache-default.xml" }; _ignite = Ignition.Start(cfg); @@ -104,7 +108,24 @@ public void TestDefaultConfiguration() AssertConfigIsDefault(_ignite.GetCache(DefaultCacheName).GetConfiguration()); - AssertConfigIsDefault(_ignite.GetConfiguration().CacheConfiguration.Single(c => c.Name == DefaultCacheName)); + AssertConfigIsDefault(_ignite.GetConfiguration().CacheConfiguration + .Single(c => c.Name == DefaultCacheName)); + } + + /// + /// Tests that defaults are the same in Java. + /// + [Test] + public void TestDefaultsAreSameInJava() + { + var springConfig = _ignite.GetCache(SpringCacheName).GetConfiguration(); + + var ignoredProps = new[] {"AffinityFunction"}; + + TestUtils.AssertReflectionEqual(springConfig, new CacheConfiguration(SpringCacheName), + ignoredProperties: new HashSet(ignoredProps)); + + AssertConfigIsDefault(springConfig); } /// @@ -221,7 +242,7 @@ private static void AssertConfigIsDefault(CacheConfiguration cfg) Assert.AreEqual(CacheConfiguration.DefaultCopyOnRead, cfg.CopyOnRead); Assert.AreEqual(CacheConfiguration.DefaultEagerTtl, cfg.EagerTtl); Assert.AreEqual(CacheConfiguration.DefaultInvalidate, cfg.Invalidate); - Assert.AreEqual(CacheConfiguration.DefaultKeepVinaryInStore, cfg.KeepBinaryInStore); + Assert.AreEqual(CacheConfiguration.DefaultKeepBinaryInStore, cfg.KeepBinaryInStore); Assert.AreEqual(CacheConfiguration.DefaultLoadPreviousValue, cfg.LoadPreviousValue); Assert.AreEqual(CacheConfiguration.DefaultLockTimeout, cfg.LockTimeout); #pragma warning disable 618 @@ -240,6 +261,12 @@ private static void AssertConfigIsDefault(CacheConfiguration cfg) Assert.AreEqual(CacheConfiguration.DefaultWriteBehindFlushThreadCount, cfg.WriteBehindFlushThreadCount); Assert.AreEqual(CacheConfiguration.DefaultWriteBehindCoalescing, cfg.WriteBehindCoalescing); Assert.AreEqual(CacheConfiguration.DefaultPartitionLossPolicy, cfg.PartitionLossPolicy); + Assert.AreEqual(CacheConfiguration.DefaultWriteSynchronizationMode, cfg.WriteSynchronizationMode); + Assert.AreEqual(CacheConfiguration.DefaultWriteBehindCoalescing, cfg.WriteBehindCoalescing); + Assert.AreEqual(CacheConfiguration.DefaultWriteThrough, cfg.WriteThrough); + Assert.AreEqual(CacheConfiguration.DefaultReadThrough, cfg.ReadThrough); + Assert.AreEqual(CacheConfiguration.DefaultCopyOnRead, cfg.CopyOnRead); + Assert.AreEqual(CacheConfiguration.DefaultKeepBinaryInStore, cfg.KeepBinaryInStore); } /// @@ -272,13 +299,19 @@ private static void AssertConfigsAreEqual(CacheConfiguration x, CacheConfigurati Assert.AreEqual(x.EnableStatistics, y.EnableStatistics); Assert.AreEqual(x.MemoryPolicyName, y.MemoryPolicyName); Assert.AreEqual(x.PartitionLossPolicy, y.PartitionLossPolicy); + Assert.AreEqual(x.WriteBehindCoalescing, y.WriteBehindCoalescing); Assert.AreEqual(x.GroupName, y.GroupName); + Assert.AreEqual(x.WriteSynchronizationMode, y.WriteSynchronizationMode); if (x.ExpiryPolicyFactory != null) + { Assert.AreEqual(x.ExpiryPolicyFactory.CreateInstance().GetType(), y.ExpiryPolicyFactory.CreateInstance().GetType()); + } else + { Assert.IsNull(y.ExpiryPolicyFactory); + } AssertConfigsAreEqual(x.QueryEntities, y.QueryEntities); AssertConfigsAreEqual(x.NearConfiguration, y.NearConfiguration); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Dynamic/dynamic-data.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Dynamic/dynamic-data.xml index 682a517e704d0..3b37fa9959ec9 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Dynamic/dynamic-data.xml +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Dynamic/dynamic-data.xml @@ -35,12 +35,14 @@ + + diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-default.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-default.xml new file mode 100644 index 0000000000000..7832e8774e88f --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-default.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + 127.0.0.1:47500 + + + + + + + + + diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs index 23ee8845e1005..2177c6a723845 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs @@ -20,7 +20,6 @@ namespace Apache.Ignite.Core.Tests { using System; - using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Diagnostics.CodeAnalysis; @@ -514,15 +513,15 @@ public void TestFromXml() { // Empty section. var cfg = IgniteConfiguration.FromXml(""); - AssertReflectionEqual(new IgniteConfiguration(), cfg); + TestUtils.AssertReflectionEqual(new IgniteConfiguration(), cfg); // Empty section with XML header. cfg = IgniteConfiguration.FromXml(""); - AssertReflectionEqual(new IgniteConfiguration(), cfg); + TestUtils.AssertReflectionEqual(new IgniteConfiguration(), cfg); // Simple test. cfg = IgniteConfiguration.FromXml(@""); - AssertReflectionEqual(new IgniteConfiguration {IgniteInstanceName = "myGrid", ClientMode = true}, cfg); + TestUtils.AssertReflectionEqual(new IgniteConfiguration {IgniteInstanceName = "myGrid", ClientMode = true}, cfg); // Invalid xml. var ex = Assert.Throws(() => @@ -537,7 +536,7 @@ public void TestFromXml() { cfg = IgniteConfiguration.FromXml(xmlReader); } - AssertReflectionEqual(new IgniteConfiguration { IgniteInstanceName = "myGrid", ClientMode = true }, cfg); + TestUtils.AssertReflectionEqual(new IgniteConfiguration { IgniteInstanceName = "myGrid", ClientMode = true }, cfg); } /// @@ -589,7 +588,7 @@ private static void CheckSerializeDeserialize(IgniteConfiguration cfg) { var resCfg = SerializeDeserialize(cfg); - AssertReflectionEqual(cfg, resCfg); + TestUtils.AssertReflectionEqual(cfg, resCfg); } /// @@ -602,53 +601,6 @@ private static IgniteConfiguration SerializeDeserialize(IgniteConfiguration cfg) return IgniteConfiguration.FromXml(xml); } - /// - /// Asserts equality with reflection. - /// - private static void AssertReflectionEqual(object x, object y) - { - var type = x.GetType(); - - Assert.AreEqual(type, y.GetType()); - - if (type.IsValueType || type == typeof (string) || type.IsSubclassOf(typeof (Type))) - { - Assert.AreEqual(x, y); - return; - } - - var props = type.GetProperties().Where(p => p.GetIndexParameters().Length == 0); - - foreach (var propInfo in props) - { - var propType = propInfo.PropertyType; - - var xVal = propInfo.GetValue(x, null); - var yVal = propInfo.GetValue(y, null); - - if (xVal == null || yVal == null) - { - Assert.IsNull(xVal); - Assert.IsNull(yVal); - } - else if (propType != typeof(string) && propType.IsGenericType && - (propType.GetGenericTypeDefinition() == typeof(ICollection<>) || - propType.GetGenericTypeDefinition() == typeof(IDictionary<,>) )) - { - var xCol = ((IEnumerable) xVal).OfType().ToList(); - var yCol = ((IEnumerable) yVal).OfType().ToList(); - - Assert.AreEqual(xCol.Count, yCol.Count); - - for (int i = 0; i < xCol.Count; i++) - AssertReflectionEqual(xCol[i], yCol[i]); - } - else - { - AssertReflectionEqual(xVal, yVal); - } - } - } /// /// Gets the test configuration. diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs index 4b171b0a0dc96..34e356bfbb1f8 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs @@ -18,6 +18,7 @@ namespace Apache.Ignite.Core.Tests { using System; + using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; @@ -402,5 +403,65 @@ public static int GetPrimaryKey(IIgnite ignite, string cacheName, IClusterNode n { return GetPrimaryKeys(ignite, cacheName, node).First(); } + + /// + /// Asserts equality with reflection. + /// + public static void AssertReflectionEqual(object x, object y, string propertyPath = null, + HashSet ignoredProperties = null) + { + var type = x.GetType(); + + Assert.AreEqual(type, y.GetType()); + + propertyPath = propertyPath ?? type.Name; + + if (type.IsValueType || type == typeof(string) || type.IsSubclassOf(typeof(Type))) + { + Assert.AreEqual(x, y, propertyPath); + return; + } + + var props = type.GetProperties().Where(p => p.GetIndexParameters().Length == 0); + + foreach (var propInfo in props) + { + var propType = propInfo.PropertyType; + + if (ignoredProperties != null && ignoredProperties.Contains(propInfo.Name)) + { + continue; + } + + var propName = propertyPath + "." + propInfo.Name; + + var xVal = propInfo.GetValue(x, null); + var yVal = propInfo.GetValue(y, null); + + if (xVal == null || yVal == null) + { + Assert.IsNull(xVal, propName); + Assert.IsNull(yVal, propName); + } + else if (propType != typeof(string) && propType.IsGenericType && + (propType.GetGenericTypeDefinition() == typeof(ICollection<>) || + propType.GetGenericTypeDefinition() == typeof(IDictionary<,>))) + { + var xCol = ((IEnumerable)xVal).OfType().ToList(); + var yCol = ((IEnumerable)yVal).OfType().ToList(); + + Assert.AreEqual(xCol.Count, yCol.Count, propName); + + for (var i = 0; i < xCol.Count; i++) + { + AssertReflectionEqual(xCol[i], yCol[i], propName, ignoredProperties); + } + } + else + { + AssertReflectionEqual(xVal, yVal, propName, ignoredProperties); + } + } + } } } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs index d08a191aed64a..421f16f315b61 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs @@ -81,6 +81,10 @@ public class CacheConfiguration /// Default rebalance batch size in bytes. public const int DefaultRebalanceBatchSize = 512*1024; // 512K + /// Default value for property. + public const CacheWriteSynchronizationMode DefaultWriteSynchronizationMode = + CacheWriteSynchronizationMode.PrimarySync; + /// Default value for eager ttl flag. public const bool DefaultEagerTtl = true; @@ -112,8 +116,12 @@ public class CacheConfiguration public static readonly TimeSpan DefaultLongQueryWarningTimeout = TimeSpan.FromMilliseconds(3000); /// Default value for keep portable in store behavior . + [Obsolete("Use DefaultKeepBinaryInStore instead.")] public const bool DefaultKeepVinaryInStore = true; + /// Default value for property. + public const bool DefaultKeepBinaryInStore = false; + /// Default value for 'copyOnRead' flag. public const bool DefaultCopyOnRead = true; @@ -154,9 +162,10 @@ public CacheConfiguration(string name) AtomicityMode = DefaultAtomicityMode; CacheMode = DefaultCacheMode; CopyOnRead = DefaultCopyOnRead; + WriteSynchronizationMode = DefaultWriteSynchronizationMode; EagerTtl = DefaultEagerTtl; Invalidate = DefaultInvalidate; - KeepBinaryInStore = DefaultKeepVinaryInStore; + KeepBinaryInStore = DefaultKeepBinaryInStore; LoadPreviousValue = DefaultLoadPreviousValue; LockTimeout = DefaultLockTimeout; #pragma warning disable 618 @@ -438,6 +447,7 @@ internal void Validate(ILogger log) /// Gets or sets write synchronization mode. This mode controls whether the main /// caller should wait for update on other nodes to complete or not. /// + [DefaultValue(DefaultWriteSynchronizationMode)] public CacheWriteSynchronizationMode WriteSynchronizationMode { get; set; } /// @@ -467,7 +477,7 @@ internal void Validate(ILogger log) /// Gets or sets the flag indicating whether is working with binary objects /// instead of deserialized objects. /// - [DefaultValue(DefaultKeepVinaryInStore)] + [DefaultValue(DefaultKeepBinaryInStore)] public bool KeepBinaryInStore { get; set; } /// From aefa9a8a7c8e90ed0a285a2d4e0d3c223860e40d Mon Sep 17 00:00:00 2001 From: sboikov Date: Tue, 26 Sep 2017 12:39:28 +0300 Subject: [PATCH 08/13] Removed unused internal getTopologySafe method. --- .../cache/GatewayProtectedCacheProxy.java | 5 - .../processors/cache/GridCacheAdapter.java | 73 ++---- .../processors/cache/GridCacheProxyImpl.java | 12 - .../processors/cache/IgniteCacheProxy.java | 8 - .../cache/IgniteCacheProxyImpl.java | 16 -- .../processors/cache/IgniteInternalCache.java | 9 - .../dht/CacheDistributedGetFutureAdapter.java | 5 +- .../distributed/dht/GridDhtCacheAdapter.java | 5 - .../distributed/dht/GridDhtGetFuture.java | 2 - .../dht/GridDhtGetSingleFuture.java | 2 - .../dht/GridPartitionedGetFuture.java | 22 +- .../dht/GridPartitionedSingleGetFuture.java | 5 +- .../dht/atomic/GridDhtAtomicCache.java | 67 +----- .../dht/colocated/GridDhtColocatedCache.java | 24 +- .../distributed/near/GridNearAtomicCache.java | 2 - .../near/GridNearCacheAdapter.java | 3 - .../distributed/near/GridNearCacheEntry.java | 1 - .../distributed/near/GridNearGetFuture.java | 3 - .../near/GridNearTransactionalCache.java | 3 - .../distributed/near/GridNearTxLocal.java | 2 - .../local/atomic/GridLocalAtomicCache.java | 2 - .../IgniteCacheTopologySafeGetSelfTest.java | 222 ------------------ .../IgniteCacheFailoverTestSuite.java | 2 - .../cache/hibernate/HibernateCacheProxy.java | 5 - 24 files changed, 31 insertions(+), 469 deletions(-) delete mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTopologySafeGetSelfTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java index 5ba6810155440..37bf9bb788f46 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java @@ -1702,11 +1702,6 @@ private void onLeave(GridCacheGateway gate) { delegate.closeProxy(); } - /** {@inheritDoc} */ - @Override public V getTopologySafe(K key) { - return delegate.getTopologySafe(key); - } - /** {@inheritDoc} */ @Override public IgniteCache withAsync() { return delegate.withAsync(); 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 c7e40ec475c54..6d9f0d32c1ab8 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 @@ -629,9 +629,7 @@ public void onKernalStop() { /*subj id*/null, /*task name*/null, /*deserialize binary*/false, - /*skip values*/ - /*can remap*/true, - true, + /*skip values*/true, false); } @@ -659,10 +657,8 @@ public void onKernalStop() { /*task name*/null, /*deserialize binary*/false, opCtx != null && opCtx.recovery(), - /*skip values*/ - /*can remap*/true, - true, - false).chain(new CX1>, Boolean>() { + /*skip values*/true, + /*need ver*/false).chain(new CX1>, Boolean>() { @Override public Boolean applyx(IgniteInternalFuture> fut) throws IgniteCheckedException { Map kvMap = fut.get(); @@ -1267,10 +1263,8 @@ private boolean evictx(K key, GridCacheVersion ver, taskName, /*deserialize cache objects*/true, opCtx != null && opCtx.recovery(), - /*skip values*/ - /*can remap*/false, - true, - false).get().get(key); + /*skip values*/false, + /*need ver*/false).get().get(key); } /** {@inheritDoc} */ @@ -1287,35 +1281,14 @@ private boolean evictx(K key, GridCacheVersion ver, taskName, true, opCtx != null && opCtx.recovery(), - /*can remap*/false, - true, - false).chain(new CX1>, V>() { + /*skip vals*/false, + /*can remap*/false).chain(new CX1>, V>() { @Override public V applyx(IgniteInternalFuture> e) throws IgniteCheckedException { return e.get().get(key); } }); } - /** {@inheritDoc} */ - @Override public final V getTopologySafe(K key) throws IgniteCheckedException { - String taskName = ctx.kernalContext().job().currentTaskName(); - - CacheOperationContext opCtx = ctx.operationContextPerCall(); - - return getAllAsync( - F.asList(key), - /*force primary*/false, - /*skip tx*/false, - /*subject id*/null, - taskName, - /*deserialize cache objects*/true, - opCtx != null && opCtx.recovery(), - /*skip values*/ - /*can remap*/false, - false, - false).get().get(key); - } - /** {@inheritDoc} */ @Nullable @Override public final Map getAllOutTx(Set keys) throws IgniteCheckedException { return getAllOutTxAsync(keys).get(); @@ -1334,9 +1307,8 @@ private boolean evictx(K key, GridCacheVersion ver, taskName, !(opCtx != null && opCtx.isKeepBinary()), opCtx != null && opCtx.recovery(), - /*skip values*/ - /*can remap*/false, - true, false); + /*skip values*/false, + /*need ver*/false); } /** {@inheritDoc} */ @@ -1543,7 +1515,6 @@ private boolean evictx(K key, GridCacheVersion ver, !(opCtx != null && opCtx.isKeepBinary()), opCtx != null && opCtx.recovery(), /*skip vals*/false, - /*can remap*/true, /*need ver*/false); if (ctx.config().getInterceptor() != null) @@ -1582,7 +1553,6 @@ private boolean evictx(K key, GridCacheVersion ver, !(opCtx != null && opCtx.isKeepBinary()), opCtx != null && opCtx.recovery(), /*skip vals*/false, - /*can remap*/true, /*need ver*/true)); final boolean intercept = ctx.config().getInterceptor() != null; @@ -1705,7 +1675,6 @@ private Collection> interceptGetEntries( * @param taskName Task name. * @param deserializeBinary Deserialize binary. * @param skipVals Skip values. - * @param canRemap Can remap flag. * @param needVer Need version. * @return Future for the get operation. */ @@ -1717,7 +1686,6 @@ protected IgniteInternalFuture getAsync( String taskName, boolean deserializeBinary, final boolean skipVals, - boolean canRemap, final boolean needVer ) { CacheOperationContext opCtx = ctx.operationContextPerCall(); @@ -1730,7 +1698,6 @@ protected IgniteInternalFuture getAsync( deserializeBinary, opCtx != null && opCtx.recovery(), skipVals, - canRemap, needVer).chain( new CX1>, V>() { @Override public V applyx(IgniteInternalFuture> e) throws IgniteCheckedException { @@ -1758,7 +1725,6 @@ protected IgniteInternalFuture getAsync( * @param deserializeBinary Deserialize binary. * @param recovery Recovery mode flag. * @param skipVals Skip values. - * @param canRemap Can remap flag. * @param needVer Need version. * @return Future for the get operation. * @see GridCacheAdapter#getAllAsync(Collection) @@ -1772,7 +1738,6 @@ protected IgniteInternalFuture> getAllAsync( boolean deserializeBinary, boolean recovery, boolean skipVals, - boolean canRemap, final boolean needVer ) { CacheOperationContext opCtx = ctx.operationContextPerCall(); @@ -1790,7 +1755,6 @@ protected IgniteInternalFuture> getAllAsync( forcePrimary, skipVals ? null : expiryPolicy(opCtx != null ? opCtx.expiry() : null), skipVals, - canRemap, needVer); } @@ -1806,7 +1770,6 @@ protected IgniteInternalFuture> getAllAsync( * @param forcePrimary Froce primary. * @param expiry Expiry policy. * @param skipVals Skip values. - * @param canRemap Can remap flag. * @param needVer Need version. * @return Future for the get operation. * @see GridCacheAdapter#getAllAsync(Collection) @@ -1822,7 +1785,6 @@ public final IgniteInternalFuture> getAllAsync(@Nullable final Collect final boolean forcePrimary, @Nullable IgniteCacheExpiryPolicy expiry, final boolean skipVals, - boolean canRemap, final boolean needVer ) { ctx.checkSecurity(SecurityPermission.CACHE_READ); @@ -1841,7 +1803,6 @@ public final IgniteInternalFuture> getAllAsync(@Nullable final Collect skipVals, /*keep cache objects*/false, recovery, - canRemap, needVer); } @@ -1856,7 +1817,6 @@ public final IgniteInternalFuture> getAllAsync(@Nullable final Collect * @param expiry Expiry policy. * @param skipVals Skip values flag. * @param keepCacheObjects Keep cache objects. - * @param canRemap Can remap flag. * @param needVer If {@code true} returns values as tuples containing value and version. * @return Future. */ @@ -1872,7 +1832,6 @@ protected final IgniteInternalFuture> getAllAsync0( final boolean skipVals, final boolean keepCacheObjects, final boolean recovery, - boolean canRemap, final boolean needVer ) { if (F.isEmpty(keys)) @@ -1894,9 +1853,7 @@ protected final IgniteInternalFuture> getAllAsync0( if (tx == null || tx.implicit()) { Map misses = null; - final AffinityTopologyVersion topVer = tx == null ? - (canRemap ? - ctx.affinity().affinityTopologyVersion() : ctx.shared().exchange().readyAffinityVersion()) : + final AffinityTopologyVersion topVer = tx == null ? ctx.affinity().affinityTopologyVersion() : tx.topologyVersion(); try { @@ -4559,8 +4516,8 @@ protected V get0( null, taskName, deserializeBinary, - /*can remap*/false, - true, needVer).get(); + /*skip vals*/false, + needVer).get(); } catch (IgniteException e) { if (e.getCause(IgniteCheckedException.class) != null) @@ -4592,8 +4549,8 @@ public final IgniteInternalFuture getAsync(final K key, boolean deserializeBi null, taskName, deserializeBinary, - /*can remap*/false, - true, needVer); + /*skip vals*/false, + needVer); } /** @@ -4619,7 +4576,6 @@ protected Map getAll0(Collection keys, boolean deserializeBin deserializeBinary, opCtx != null && opCtx.recovery(), /*skip vals*/false, - /*can remap*/true, needVer).get(); } @@ -4645,7 +4601,6 @@ public IgniteInternalFuture> getAllAsync( deserializeBinary, recovery, /*skip vals*/false, - /*can remap*/true, needVer); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java index d81b9f73c72aa..30edbeadc9ffd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java @@ -345,18 +345,6 @@ public IgniteInternalCache delegate() { } } - /** {@inheritDoc} */ - @Override public V getTopologySafe(K key) throws IgniteCheckedException { - CacheOperationContext prev = gate.enter(opCtx); - - try { - return delegate.getTopologySafe(key); - } - finally { - gate.leave(prev); - } - } - /** {@inheritDoc} */ @Override public IgniteInternalFuture getAsync(K key) { CacheOperationContext prev = gate.enter(opCtx); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index 22bd676c69543..361764e2e8a2e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -91,14 +91,6 @@ public interface IgniteCacheProxy extends IgniteCache, Externalizabl */ public void closeProxy(); - /** - * Gets value without waiting for topology changes. - * - * @param key Key. - * @return Value. - */ - public V getTopologySafe(K key); - /** * @return Future that contains cache destroy operation. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java index 3056361132705..ae1c6f52f8679 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java @@ -1725,22 +1725,6 @@ public GridCacheProxyImpl internalProxy() { return new IgniteFutureImpl<>(fut); } - /** - * Gets value without waiting for toplogy changes. - * - * @param key Key. - * @return Value. - */ - @Override - public V getTopologySafe(K key) { - try { - return delegate.getTopologySafe(key); - } - catch (IgniteCheckedException | IgniteException e) { - throw cacheException(e); - } - } - /** * Throws {@code IgniteCacheRestartingException} if proxy is restarting. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java index 2f4a40e6e1c29..d01d5369b1723 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java @@ -1809,15 +1809,6 @@ public void localLoadCache(@Nullable IgniteBiPredicate p, @Nullable Object */ public IgniteInternalFuture localLoadCacheAsync(@Nullable IgniteBiPredicate p, @Nullable Object... args); - /** - * Gets value without waiting for toplogy changes. - * - * @param key Key. - * @return Value. - * @throws IgniteCheckedException If failed. - */ - public V getTopologySafe(K key) throws IgniteCheckedException; - /** * @param topVer Locked topology version. * @param key Key. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/CacheDistributedGetFutureAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/CacheDistributedGetFutureAdapter.java index 679732bd33bac..2257c9f35734a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/CacheDistributedGetFutureAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/CacheDistributedGetFutureAdapter.java @@ -92,7 +92,7 @@ public abstract class CacheDistributedGetFutureAdapter extends GridCacheCo protected IgniteCacheExpiryPolicy expiryPlc; /** Flag indicating that get should be done on a locked topology version. */ - protected boolean canRemap; + protected boolean canRemap = true; /** */ protected final boolean needVer; @@ -114,7 +114,6 @@ public abstract class CacheDistributedGetFutureAdapter extends GridCacheCo * @param deserializeBinary Deserialize binary flag. * @param expiryPlc Expiry policy. * @param skipVals Skip values flag. - * @param canRemap Flag indicating whether future can be remapped on a newer topology version. * @param needVer If {@code true} returns values as tuples containing value and version. * @param keepCacheObjects Keep cache objects flag. */ @@ -128,7 +127,6 @@ protected CacheDistributedGetFutureAdapter( boolean deserializeBinary, @Nullable IgniteCacheExpiryPolicy expiryPlc, boolean skipVals, - boolean canRemap, boolean needVer, boolean keepCacheObjects, boolean recovery @@ -146,7 +144,6 @@ protected CacheDistributedGetFutureAdapter( this.deserializeBinary = deserializeBinary; this.expiryPlc = expiryPlc; this.skipVals = skipVals; - this.canRemap = canRemap; this.needVer = needVer; this.keepCacheObjects = keepCacheObjects; this.recovery = recovery; 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 1f67c1da0290f..bbb2c5b4983d3 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 @@ -735,7 +735,6 @@ else if (log.isDebugEnabled()) boolean deserializeBinary, boolean recovery, boolean skipVals, - boolean canRemap, boolean needVer ) { CacheOperationContext opCtx = ctx.operationContextPerCall(); @@ -751,7 +750,6 @@ else if (log.isDebugEnabled()) forcePrimary, null, skipVals, - canRemap, needVer); } @@ -763,7 +761,6 @@ else if (log.isDebugEnabled()) * @param taskName Task name. * @param expiry Expiry policy. * @param skipVals Skip values flag. - * @param canRemap Can remap flag. * @return Get future. */ IgniteInternalFuture> getDhtAllAsync( @@ -774,7 +771,6 @@ IgniteInternalFuture> getDhtAllAsync( String taskName, @Nullable IgniteCacheExpiryPolicy expiry, boolean skipVals, - boolean canRemap, boolean recovery ) { return getAllAsync0(keys, @@ -788,7 +784,6 @@ IgniteInternalFuture> getDhtAllAsync( skipVals, /*keep cache objects*/true, recovery, - canRemap, /*need version*/true); } 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 8430f84ef4f94..431937441bd28 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 @@ -422,7 +422,6 @@ private IgniteInternalFuture> getAsync( taskName, expiryPlc, skipVals, - /*can remap*/true, recovery); } else { @@ -446,7 +445,6 @@ private IgniteInternalFuture> getAsync( taskName, expiryPlc, skipVals, - /*can remap*/true, recovery); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java index 439bb9d7fb702..7c6c0208a39db 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java @@ -365,7 +365,6 @@ private void getAsync() { taskName, expiryPlc, skipVals, - /*can remap*/true, recovery); } else { @@ -391,7 +390,6 @@ private void getAsync() { taskName, expiryPlc, skipVals, - /*can remap*/true, recovery); fut0.listen(createGetFutureListener()); 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 e7e0e0668b5e1..73c0ea5167605 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 @@ -73,29 +73,24 @@ public class GridPartitionedGetFuture extends CacheDistributedGetFutureAda /** Logger. */ private static IgniteLogger log; - /** Topology version. */ - private AffinityTopologyVersion topVer; - /** * @param cctx Context. * @param keys Keys. - * @param topVer Topology version. * @param readThrough Read through flag. * @param forcePrimary If {@code true} then will force network trip to primary node even * if called on backup node. * @param subjId Subject ID. * @param taskName Task name. * @param deserializeBinary Deserialize binary flag. + * @param recovery Recovery mode flag. * @param expiryPlc Expiry policy. * @param skipVals Skip values flag. - * @param canRemap Flag indicating whether future can be remapped on a newer topology version. * @param needVer If {@code true} returns values as tuples containing value and version. * @param keepCacheObjects Keep cache objects flag. */ public GridPartitionedGetFuture( GridCacheContext cctx, Collection keys, - AffinityTopologyVersion topVer, boolean readThrough, boolean forcePrimary, @Nullable UUID subjId, @@ -104,7 +99,6 @@ public GridPartitionedGetFuture( boolean recovery, @Nullable IgniteCacheExpiryPolicy expiryPlc, boolean skipVals, - boolean canRemap, boolean needVer, boolean keepCacheObjects ) { @@ -117,21 +111,20 @@ public GridPartitionedGetFuture( deserializeBinary, expiryPlc, skipVals, - canRemap, needVer, keepCacheObjects, recovery); - this.topVer = topVer; - if (log == null) log = U.logger(cctx.kernalContext(), logRef, GridPartitionedGetFuture.class); } /** * Initializes future. + * + * @param topVer Topology version. */ - public void init() { + public void init(AffinityTopologyVersion topVer) { AffinityTopologyVersion lockedTopVer = cctx.shared().lockedTopologyVersion(null); if (lockedTopVer != null) { @@ -140,7 +133,7 @@ public void init() { map(keys, Collections.>emptyMap(), lockedTopVer); } else { - AffinityTopologyVersion topVer = this.topVer.topologyVersion() > 0 ? this.topVer : + topVer = topVer.topologyVersion() > 0 ? topVer : canRemap ? cctx.affinity().affinityTopologyVersion() : cctx.shared().exchange().readyAffinityVersion(); map(keys, Collections.>emptyMap(), topVer); @@ -402,7 +395,7 @@ private boolean map( boolean fastLocGet = (!forcePrimary || affNodes.get(0).isLocal()) && cctx.allowFastLocalRead(part, affNodes, topVer); - if (fastLocGet && localGet(key, part, locVals)) + if (fastLocGet && localGet(topVer, key, part, locVals)) return false; ClusterNode node = affinityNode(affNodes); @@ -438,12 +431,13 @@ private boolean map( } /** + * @param topVer Topology version. * @param key Key. * @param part Partition. * @param locVals Local values. * @return {@code True} if there is no need to further search value. */ - private boolean localGet(KeyCacheObject key, int part, Map locVals) { + private boolean localGet(AffinityTopologyVersion topVer, KeyCacheObject key, int part, Map locVals) { assert cctx.affinityNode() : this; GridDhtCacheAdapter cache = cache(); 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 0828a80f6c6dc..234ee913b3be6 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 @@ -133,7 +133,6 @@ public class GridPartitionedSingleGetFuture extends GridCacheFutureAdapter near) { return near; } - /** - * @param key Key. - * @param deserializeBinary Deserialize binary. - * @param needVer Need version. - * @return Value. - * @throws IgniteCheckedException If failed. - */ - @Nullable public V get0(K key, boolean deserializeBinary, boolean needVer) throws IgniteCheckedException { - ctx.checkSecurity(SecurityPermission.CACHE_READ); - - if (keyCheck) - validateCacheKey(key); - - String taskName = ctx.kernalContext().job().currentTaskName(); - - CacheOperationContext opCtx = ctx.operationContextPerCall(); - - UUID subjId = ctx.subjectIdPerCall(null, opCtx); - - final ExpiryPolicy expiryPlc = opCtx != null ? opCtx.expiry() : null; - - final boolean skipStore = opCtx != null && opCtx.skipStore(); - - try { - return getAsync0(ctx.toCacheKeyObject(key), - !ctx.config().isReadFromBackup(), - subjId, - taskName, - deserializeBinary, - opCtx != null && opCtx.recovery(), - expiryPlc, - false, - skipStore, - true, - needVer).get(); - } - catch (IgniteException e) { - if (e.getCause(IgniteCheckedException.class) != null) - throw e.getCause(IgniteCheckedException.class); - else - throw e; - } - } - /** {@inheritDoc} */ @Override protected IgniteInternalFuture getAsync( final K key, @@ -492,7 +448,6 @@ public void near(GridNearAtomicCache near) { final String taskName, final boolean deserializeBinary, final boolean skipVals, - final boolean canRemap, final boolean needVer ) { ctx.checkSecurity(SecurityPermission.CACHE_READ); @@ -520,7 +475,6 @@ public void near(GridNearAtomicCache near) { expiryPlc, skipVals, skipStore, - canRemap, needVer); } }); @@ -538,7 +492,6 @@ public void near(GridNearAtomicCache near) { deserializeBinary, opCtx != null && opCtx.recovery(), false, - true, needVer, false).get(); } @@ -553,7 +506,6 @@ public void near(GridNearAtomicCache near) { final boolean deserializeBinary, final boolean recovery, final boolean skipVals, - final boolean canRemap, final boolean needVer ) { return getAllAsyncInternal(keys, @@ -563,7 +515,6 @@ public void near(GridNearAtomicCache near) { deserializeBinary, recovery, skipVals, - canRemap, needVer, true); } @@ -575,7 +526,6 @@ public void near(GridNearAtomicCache near) { * @param taskName Task name. * @param deserializeBinary Deserialize binary flag. * @param skipVals Skip values flag. - * @param canRemap Can remap flag. * @param needVer Need version flag. * @param asyncOp Async operation flag. * @return Future. @@ -588,7 +538,6 @@ private IgniteInternalFuture> getAllAsyncInternal( final boolean deserializeBinary, final boolean recovery, final boolean skipVals, - final boolean canRemap, final boolean needVer, boolean asyncOp ) { @@ -622,7 +571,6 @@ private IgniteInternalFuture> getAllAsyncInternal( expiryPlc, skipVals, skipStore, - canRemap, needVer); } }); @@ -637,7 +585,6 @@ private IgniteInternalFuture> getAllAsyncInternal( expiryPlc, skipVals, skipStore, - canRemap, needVer); } } @@ -1409,7 +1356,6 @@ private IgniteInternalFuture removeAllAsync0( * @param expiryPlc Expiry policy. * @param skipVals Skip values flag. * @param skipStore Skip store flag. - * @param canRemap Can remap flag. * @param needVer Need version. * @return Get future. */ @@ -1422,11 +1368,9 @@ private IgniteInternalFuture getAsync0(KeyCacheObject key, @Nullable ExpiryPolicy expiryPlc, boolean skipVals, boolean skipStore, - boolean canRemap, boolean needVer ) { - AffinityTopologyVersion topVer = canRemap ? ctx.affinity().affinityTopologyVersion() : - ctx.shared().exchange().readyAffinityVersion(); + AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion(); IgniteCacheExpiryPolicy expiry = skipVals ? null : expiryPolicy(expiryPlc); @@ -1440,7 +1384,6 @@ private IgniteInternalFuture getAsync0(KeyCacheObject key, deserializeBinary, expiry, skipVals, - canRemap, needVer, false, recovery); @@ -1473,11 +1416,9 @@ private IgniteInternalFuture> getAllAsync0(@Nullable Collection fut = new GridPartitionedGetFuture<>(ctx, keys, - topVer, !skipStore, forcePrimary, subjId, @@ -1649,11 +1589,10 @@ else if (!skipVals && ctx.config().isStatisticsEnabled()) recovery, expiry, skipVals, - canRemap, needVer, false); - fut.init(); + fut.init(topVer); return fut; } 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 8449f3a00c82b..edb4278609201 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 @@ -179,7 +179,6 @@ public GridDistributedCacheEntry entryExx( String taskName, final boolean deserializeBinary, final boolean skipVals, - boolean canRemap, final boolean needVer) { ctx.checkSecurity(SecurityPermission.CACHE_READ); @@ -226,9 +225,7 @@ public GridDistributedCacheEntry entryExx( }, opCtx, /*retry*/false); } - AffinityTopologyVersion topVer = tx == null ? - (canRemap ? ctx.affinity().affinityTopologyVersion() : ctx.shared().exchange().readyAffinityVersion()) : - tx.topologyVersion(); + AffinityTopologyVersion topVer = tx == null ? ctx.affinity().affinityTopologyVersion() : tx.topologyVersion(); subjId = ctx.subjectIdPerCall(subjId, opCtx); @@ -242,7 +239,6 @@ public GridDistributedCacheEntry entryExx( deserializeBinary, skipVals ? null : expiryPolicy(opCtx != null ? opCtx.expiry() : null), skipVals, - canRemap, needVer, /*keepCacheObjects*/false, opCtx != null && opCtx.recovery()); @@ -262,7 +258,6 @@ public GridDistributedCacheEntry entryExx( final boolean deserializeBinary, final boolean recovery, final boolean skipVals, - boolean canRemap, final boolean needVer ) { ctx.checkSecurity(SecurityPermission.CACHE_READ); @@ -293,9 +288,7 @@ public GridDistributedCacheEntry entryExx( }, opCtx, /*retry*/false); } - AffinityTopologyVersion topVer = tx == null ? - (canRemap ? ctx.affinity().affinityTopologyVersion() : ctx.shared().exchange().readyAffinityVersion()) : - tx.topologyVersion(); + AffinityTopologyVersion topVer = tx == null ? ctx.affinity().affinityTopologyVersion() : tx.topologyVersion(); subjId = ctx.subjectIdPerCall(subjId, opCtx); @@ -310,7 +303,6 @@ public GridDistributedCacheEntry entryExx( recovery, skipVals ? null : expiryPolicy(opCtx != null ? opCtx.expiry() : null), skipVals, - canRemap, needVer); } @@ -324,7 +316,6 @@ public GridDistributedCacheEntry entryExx( * @param deserializeBinary Deserialize binary flag. * @param expiryPlc Expiry policy. * @param skipVals Skip values flag. - * @param canRemap Can remap flag. * @param needVer Need version. * @return Loaded values. */ @@ -339,7 +330,6 @@ public IgniteInternalFuture> loadAsync( boolean recovery, @Nullable IgniteCacheExpiryPolicy expiryPlc, boolean skipVals, - boolean canRemap, boolean needVer) { return loadAsync(keys, readThrough, @@ -350,7 +340,6 @@ public IgniteInternalFuture> loadAsync( recovery, expiryPlc, skipVals, - canRemap, needVer, false); } @@ -365,7 +354,6 @@ public IgniteInternalFuture> loadAsync( * @param deserializeBinary Deserialize binary flag. * @param expiryPlc Expiry policy. * @param skipVals Skip values flag. - * @param canRemap Flag indicating whether future can be remapped on a newer topology version. * @param needVer If {@code true} returns values as tuples containing value and version. * @param keepCacheObj Keep cache objects flag. * @return Load future. @@ -380,7 +368,6 @@ public final IgniteInternalFuture loadAsync( boolean deserializeBinary, @Nullable IgniteCacheExpiryPolicy expiryPlc, boolean skipVals, - boolean canRemap, boolean needVer, boolean keepCacheObj, boolean recovery @@ -395,7 +382,6 @@ public final IgniteInternalFuture loadAsync( deserializeBinary, expiryPlc, skipVals, - canRemap, needVer, keepCacheObj, recovery); @@ -415,7 +401,6 @@ public final IgniteInternalFuture loadAsync( * @param deserializeBinary Deserialize binary flag. * @param expiryPlc Expiry policy. * @param skipVals Skip values flag. - * @param canRemap Flag indicating whether future can be remapped on a newer topology version. * @param needVer If {@code true} returns values as tuples containing value and version. * @param keepCacheObj Keep cache objects flag. * @return Load future. @@ -431,7 +416,6 @@ public final IgniteInternalFuture> loadAsync( boolean recovery, @Nullable IgniteCacheExpiryPolicy expiryPlc, boolean skipVals, - boolean canRemap, boolean needVer, boolean keepCacheObj ) { @@ -607,7 +591,6 @@ else if (!skipVals && ctx.config().isStatisticsEnabled()) GridPartitionedGetFuture fut = new GridPartitionedGetFuture<>( ctx, keys, - topVer, readThrough, forcePrimary, subjId, @@ -616,11 +599,10 @@ else if (!skipVals && ctx.config().isStatisticsEnabled()) recovery, expiryPlc, skipVals, - canRemap, needVer, keepCacheObj); - fut.init(); + fut.init(topVer); return fut; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java index e6c5c10b3c4ff..2f832b490ea25 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java @@ -405,7 +405,6 @@ private void processNearAtomicUpdateResponse( boolean deserializeBinary, boolean recovery, boolean skipVals, - boolean canRemap, boolean needVer ) { ctx.checkSecurity(SecurityPermission.CACHE_READ); @@ -430,7 +429,6 @@ private void processNearAtomicUpdateResponse( skipVals ? null : opCtx != null ? opCtx.expiry() : null, skipVals, opCtx != null && opCtx.skipStore(), - canRemap, needVer); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java index 428355cc87054..672693c4bb1b2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java @@ -216,7 +216,6 @@ public boolean isAllLockedNearOnly(Iterable keys) { * @param expiryPlc Expiry policy. * @param skipVal Skip value flag. * @param skipStore Skip store flag. - * @param canRemap Can remap flag. * @param needVer Need version. * @return Loaded values. */ @@ -231,7 +230,6 @@ public IgniteInternalFuture> loadAsync( @Nullable ExpiryPolicy expiryPlc, boolean skipVal, boolean skipStore, - boolean canRemap, boolean needVer ) { if (F.isEmpty(keys)) @@ -251,7 +249,6 @@ public IgniteInternalFuture> loadAsync( deserializeBinary, expiry, skipVal, - canRemap, needVer, false, recovery); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java index ce728b5b33b64..ea52766c6346e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java @@ -331,7 +331,6 @@ public final boolean recordDhtVersion(GridCacheVersion dhtVer) { null, false, /*skip store*/false, - /*can remap*/true, false ).get().get(keyValue(false)); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java index 1ab56a402a33e..807270d3bf565 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java @@ -93,7 +93,6 @@ public final class GridNearGetFuture extends CacheDistributedGetFutureAdap * @param deserializeBinary Deserialize binary flag. * @param expiryPlc Expiry policy. * @param skipVals Skip values flag. - * @param canRemap Flag indicating whether future can be remapped on a newer topology version. * @param needVer If {@code true} returns values as tuples containing value and version. * @param keepCacheObjects Keep cache objects flag. */ @@ -108,7 +107,6 @@ public GridNearGetFuture( boolean deserializeBinary, @Nullable IgniteCacheExpiryPolicy expiryPlc, boolean skipVals, - boolean canRemap, boolean needVer, boolean keepCacheObjects, boolean recovery @@ -122,7 +120,6 @@ public GridNearGetFuture( deserializeBinary, expiryPlc, skipVals, - canRemap, needVer, keepCacheObjects, recovery); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java index a13da3d64b7d9..0c5f43dfef26c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java @@ -122,7 +122,6 @@ public void dht(GridDhtCache dht) { final boolean deserializeBinary, final boolean recovery, final boolean skipVals, - boolean canRemap, final boolean needVer ) { ctx.checkSecurity(SecurityPermission.CACHE_READ); @@ -167,7 +166,6 @@ public void dht(GridDhtCache dht) { skipVals ? null : opCtx != null ? opCtx.expiry() : null, skipVals, skipStore, - canRemap, needVer); } @@ -202,7 +200,6 @@ IgniteInternalFuture> txLoadAsync(GridNearTxLocal tx, deserializeBinary, expiryPlc, skipVals, - /*can remap*/true, needVer, /*keepCacheObjects*/true, recovery); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java index 8b043d8d1284a..e73f34ba8c8a6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java @@ -2513,7 +2513,6 @@ else if (cacheCtx.isColocated()) { /*deserializeBinary*/false, expiryPlc0, skipVals, - /*can remap*/true, needVer, /*keepCacheObject*/true, recovery @@ -2546,7 +2545,6 @@ else if (cacheCtx.isColocated()) { recovery, expiryPlc0, skipVals, - /*can remap*/true, needVer, /*keepCacheObject*/true ).chain(new C1>, Void>() { 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 1be264d803c5a..40d1fac36a98e 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 @@ -340,7 +340,6 @@ public GridLocalAtomicCache(GridCacheContext ctx) { final boolean deserializeBinary, boolean recovery, final boolean skipVals, - boolean canRemap, final boolean needVer ) { A.notNull(keys, "keys"); @@ -543,7 +542,6 @@ private Map getAllInternal(@Nullable Collection keys, /*force primary*/false, expiry, skipVals, - /*can remap*/true, needVer).get(); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTopologySafeGetSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTopologySafeGetSelfTest.java deleted file mode 100644 index 0140000bdf182..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTopologySafeGetSelfTest.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache; - -import java.util.Collection; -import java.util.concurrent.Callable; -import java.util.concurrent.CountDownLatch; -import org.apache.ignite.cache.CacheAtomicityMode; -import org.apache.ignite.cluster.ClusterNode; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.configuration.NearCacheConfiguration; -import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.IgniteKernal; -import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.internal.U; -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 org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; -import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; -import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; -import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; - -/** - * - */ -public class IgniteCacheTopologySafeGetSelfTest extends GridCommonAbstractTest { - /** Number of initial grids. */ - public static final int GRID_CNT = 4; - - /** */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - - /** TX commit latch. */ - private CountDownLatch releaseLatch; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); - - cfg.setCacheConfiguration( - cacheCfg("tx", TRANSACTIONAL, false), - cacheCfg("atomic", ATOMIC, false), - cacheCfg("tx_near", TRANSACTIONAL, true), - cacheCfg("atomic_near", ATOMIC, true)); - - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - - disco.setIpFinder(IP_FINDER); - - cfg.setDiscoverySpi(disco); - - return cfg; - } - - /** - * @param name Cache name. - * @param cacheMode Cache mode. - * @param near Near enabled flag. - * @return Cache configuration. - */ - @SuppressWarnings("unchecked") - private CacheConfiguration cacheCfg(String name, CacheAtomicityMode cacheMode, boolean near) { - CacheConfiguration cfg = new CacheConfiguration(name); - - cfg.setAtomicityMode(cacheMode); - cfg.setBackups(1); - - if (near) - cfg.setNearConfiguration(new NearCacheConfiguration()); - else - cfg.setNearConfiguration(null); - - return cfg; - } - - /** - * @throws Exception If failed. - */ - public void testGetTopologySafeNodeJoin() throws Exception { - checkGetTopologySafeNodeJoin(false); - } - - /** - * @throws Exception If failed. - */ - public void testGetTopologySafeNodeJoinPrimaryLeave() throws Exception { - checkGetTopologySafeNodeJoin(true); - } - - /** - * @throws Exception If failed. - */ - public void checkGetTopologySafeNodeJoin(boolean failPrimary) throws Exception { - startGrids(GRID_CNT); - - awaitPartitionMapExchange(); - - try { - ClusterNode targetNode = ignite(1).cluster().localNode(); - - info(">>> Target node: " + targetNode.id()); - - // Populate caches with a key that does not belong to ignite(0). - int key = -1; - for (int i = 0; i < 100; i++) { - Collection nodes = ignite(0).affinity("tx").mapKeyToPrimaryAndBackups(i); - ClusterNode primaryNode = F.first(nodes); - - if (!nodes.contains(ignite(0).cluster().localNode()) && primaryNode.id().equals(targetNode.id())) { - ignite(1).cache("tx").put(i, i); - ignite(1).cache("atomic").put(i, i); - ignite(1).cache("tx_near").put(i, i); - ignite(1).cache("atomic_near").put(i, i); - - key = i; - - - break; - } - } - - assertTrue(key != -1); - - IgniteInternalFuture txFut = startBlockingTxAsync(); - - IgniteInternalFuture nodeFut = startNodeAsync(); - - if (failPrimary) - stopGrid(getTestIgniteInstanceName(1), false, false); - - assertEquals(key, ((IgniteKernal)ignite(0)).internalCache("tx").getTopologySafe(key)); - assertEquals(key, ((IgniteKernal)ignite(0)).internalCache("atomic").getTopologySafe(key)); - assertEquals(key, ((IgniteKernal)ignite(0)).internalCache("tx_near").getTopologySafe(key)); - assertEquals(key, ((IgniteKernal)ignite(0)).internalCache("atomic_near").getTopologySafe(key)); - - releaseTx(); - - txFut.get(); - nodeFut.get(); - } - finally { - stopAllGrids(); - } - } - - /** - * @return Future. - * @throws Exception If failed. - */ - private IgniteInternalFuture startNodeAsync() throws Exception { - IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable() { - @Override public Object call() throws Exception { - startGrid(GRID_CNT); - - return null; - } - }); - - U.sleep(1000); - - return fut; - } - - /** - * @return TX release future. - * @throws Exception If failed. - */ - private IgniteInternalFuture startBlockingTxAsync() throws Exception { - final CountDownLatch lockLatch = new CountDownLatch(1); - - IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable() { - @Override public Object call() throws Exception { - try (Transaction ignore = ignite(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { - for (int i = 0; i < 30; i++) - ignite(0).cache("tx").get("value-" + i); - - releaseLatch = new CountDownLatch(1); - - lockLatch.countDown(); - - releaseLatch.await(); - } - - return null; - } - }); - - lockLatch.await(); - - return fut; - } - - /** - * - */ - private void releaseTx() { - assert releaseLatch != null; - - releaseLatch.countDown(); - } -} \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java index 34eb2957cf324..7357d7e4c8f71 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java @@ -20,7 +20,6 @@ import java.util.Set; import junit.framework.TestSuite; import org.apache.ignite.internal.processors.cache.GridCacheIncrementTransformTest; -import org.apache.ignite.internal.processors.cache.IgniteCacheTopologySafeGetSelfTest; import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheAtomicNodeJoinTest; import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheSizeFailoverTest; import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheTxNearDisabledPutGetRestartTest; @@ -83,7 +82,6 @@ public static TestSuite suite(Set ignoredTests) throws Exception { suite.addTestSuite(IgniteCacheSizeFailoverTest.class); - suite.addTestSuite(IgniteCacheTopologySafeGetSelfTest.class); suite.addTestSuite(IgniteAtomicLongChangingTopologySelfTest.class); suite.addTestSuite(GridCacheTxNodeFailureSelfTest.class); diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java index aa1f83b716678..0fc2c2d3cede2 100644 --- a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java +++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java @@ -647,11 +647,6 @@ public HibernateKeyTransformer keyTransformer(){ return delegate.localLoadCacheAsync(p, args); } - /** {@inheritDoc} */ - @Override public Object getTopologySafe(Object key) throws IgniteCheckedException { - return delegate.getTopologySafe(keyTransformer.transform(key)); - } - /** {@inheritDoc} */ @Override public Collection lostPartitions() { return delegate.lostPartitions(); From 8aa279ea91546e1ac8233366679285df10620eba Mon Sep 17 00:00:00 2001 From: Sergey Chernolyas Date: Tue, 26 Sep 2017 15:16:26 +0300 Subject: [PATCH 09/13] IGNITE-6286: remove unused 'log.info' statement --- .../ignite/internal/processors/query/h2/IgniteH2Indexing.java | 1 - .../processors/query/IgniteSqlParameterizedQueryTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index c746b36e075b7..15f709fd5c0ee 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -509,7 +509,6 @@ public void executeStatement(String schema, String sql) throws IgniteCheckedExce */ private void bindObject(PreparedStatement stmt, int idx, @Nullable Object obj) throws IgniteCheckedException { try { - log.info("bindObject [idx=" +idx + ", obj=" + obj.getClass() + ']'); if (obj == null) stmt.setNull(idx, Types.VARCHAR); else if (obj instanceof BigInteger) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java index e2d3f9ad26831..af687dc28a724 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java @@ -74,7 +74,6 @@ private CacheConfiguration buildCacheConfiguration(String name) { for (Field currentField : Bookmark.class.getDeclaredFields()) { bookmarkQueryEntity.addQueryField(currentField.getName(), currentField.getType().getName(), null); } - log.info("createEntityCacheConfiguration. full QueryEntity info : :"+bookmarkQueryEntity.toString()); List queryEntities = new ArrayList<>(); queryEntities.add(bookmarkQueryEntity); ccfg.setQueryEntities(queryEntities); From a74c6966de6007362ebb1a7e4b2959b455ab405b Mon Sep 17 00:00:00 2001 From: Sergey Chernolyas Date: Mon, 25 Sep 2017 10:47:03 +0300 Subject: [PATCH 10/13] IGNITE-6286: fix org.h2.jdbc.JdbcSQLException changes: 1) develop test for check all supported types for parameterized queries 2) add support BigDecimal type as type of paraameter's value --- .../processors/query/h2/IgniteH2Indexing.java | 4 + .../IgniteSqlParameterizedQueryTest.java | 382 ++++++++++++++++++ 2 files changed, 386 insertions(+) create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index 03e2391fb3db0..c746b36e075b7 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -19,6 +19,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Connection; import java.sql.DriverManager; @@ -508,10 +509,13 @@ public void executeStatement(String schema, String sql) throws IgniteCheckedExce */ private void bindObject(PreparedStatement stmt, int idx, @Nullable Object obj) throws IgniteCheckedException { try { + log.info("bindObject [idx=" +idx + ", obj=" + obj.getClass() + ']'); if (obj == null) stmt.setNull(idx, Types.VARCHAR); else if (obj instanceof BigInteger) stmt.setObject(idx, obj, Types.JAVA_OBJECT); + else if (obj instanceof BigDecimal) + stmt.setObject(idx, obj, Types.DECIMAL); else stmt.setObject(idx, obj); } diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java new file mode 100644 index 0000000000000..8273dcdefafb5 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java @@ -0,0 +1,382 @@ +/* + * Hibernate OGM, Domain model persistence for NoSQL datastores + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.apache.ignite.internal.processors.query; + +import java.io.Serializable; +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.query.QueryCursor; +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.configuration.IgniteConfiguration; +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; + +/** + * Test sql queries with parameters for all types The test fix IGNITE-6286 + * + * @author Sergey Chernolyas &sergey_chernolyas@gmail.com& + * @see IGNITE-6286 + */ +public class IgniteSqlParameterizedQueryTest extends GridCommonAbstractTest { + /** IP finder. */ + private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + private static String CACHE_BOOKMARK = "Bookmark"; + private static String NODE_CLIENT = "client"; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration c = super.getConfiguration(gridName); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(IP_FINDER); + + c.setDiscoverySpi(disco); + + c.setCacheConfiguration(buildCacheConfiguration(CACHE_BOOKMARK)); + if (gridName.equals(NODE_CLIENT)) + c.setClientMode(true); + + return c; + } + + private CacheConfiguration buildCacheConfiguration(String name) { + CacheConfiguration ccfg = new CacheConfiguration(name); + QueryEntity bookmarkQueryEntity = new QueryEntity(String.class.getName(), Bookmark.class.getName()); + + for (Field currentField : Bookmark.class.getDeclaredFields()) { + bookmarkQueryEntity.addQueryField(currentField.getName(), currentField.getType().getName(), null); + } + log.info("createEntityCacheConfiguration. full QueryEntity info : :"+bookmarkQueryEntity.toString()); + List queryEntities = new ArrayList<>(); + queryEntities.add(bookmarkQueryEntity); + ccfg.setQueryEntities(queryEntities); + return ccfg; + + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + startGrid(0); + startGrid(NODE_CLIENT); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + + private Bookmark searchBookmarkBy(String field, Object value) { + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + SqlFieldsQuery query = new SqlFieldsQuery("SELECT _val from Bookmark where "+field+"=?"); + query.setArgs(value); + + QueryCursor> cursor = cache.query(query); + List> results = cursor.getAll(); + assertEquals(1, results.size()); + List row0 = results.get(0); + return (Bookmark)row0.get(0); + } + + public void testStringSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setDescription("description"); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("description", "description"); + assertEquals("String value does not match", bookmark.getDescription(), loadedBookmark.getDescription()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testIntegerSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setStockCount(Integer.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("stockCount", Integer.MAX_VALUE); + assertEquals("Integer value does not match", bookmark.getStockCount(), loadedBookmark.getStockCount()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testShortSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setUrlPort(Short.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("urlPort", Short.MAX_VALUE); + assertEquals("Short value does not match", bookmark.getUrlPort(), loadedBookmark.getUrlPort()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testLongSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setUserId(Long.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("userId", Long.MAX_VALUE); + assertEquals("Long value does not match", bookmark.getUserId(), loadedBookmark.getUserId()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testFloatSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setVisitRatio(Float.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("visitRatio", Float.MAX_VALUE); + assertEquals("Float value does not match", bookmark.getVisitRatio(), loadedBookmark.getVisitRatio()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testDoubleSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setTaxPercentage(Double.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("taxPercentage", Double.MAX_VALUE); + assertEquals("Double value does not match", bookmark.getTaxPercentage(), loadedBookmark.getTaxPercentage()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testBooleanSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setFavourite(true); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("favourite", true); + assertEquals("Boolean value does not match", bookmark.getFavourite(), loadedBookmark.getFavourite()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testByteSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + bookmark.setDisplayMask(Byte.MAX_VALUE); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("displayMask", Byte.MAX_VALUE); + assertEquals("Byte value does not match", bookmark.getDisplayMask(), loadedBookmark.getDisplayMask()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + public void testUUIDSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + final UUID uuid = UUID.randomUUID(); + bookmark.setSerialNumber(uuid); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("serialNumber", uuid); + assertEquals("UUID value does not match", bookmark.getSerialNumber(), loadedBookmark.getSerialNumber()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + public void testBigIntegerSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + BigInteger bi = new BigInteger("1000000000000000"); + bookmark.setVisitCount(bi); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("visitCount", bi); + assertEquals("BigInteger value does not match", bookmark.getVisitCount(), loadedBookmark.getVisitCount()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + public void testBigDecimalSupport() throws Exception { + + IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); + Bookmark bookmark = new Bookmark(); + bookmark.setId(UUID.randomUUID().toString()); + BigDecimal bd = new BigDecimal("1000000000000000.001"); + bookmark.setSiteWeight(bd); + cache.put(bookmark.id, bookmark); + + Bookmark loadedBookmark = searchBookmarkBy("siteWeight", bd); + assertEquals("BigDecimal value does not match", bookmark.getSiteWeight(), loadedBookmark.getSiteWeight()); + assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); + } + + /** + * Object with all types that supported in H2 + * @see H2 types + */ + + public static class Bookmark implements Serializable { + private String id; + + // basic types + private String description; + private Integer stockCount; + private Short urlPort; + private Long userId; + private Float visitRatio; + private Double taxPercentage; + private Boolean favourite; + private Byte displayMask; + + // "special" types + //http://www.h2database.com/html/datatypes.html#uuid_type + private UUID serialNumber; + private BigDecimal siteWeight; + private BigInteger visitCount; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + + public Integer getStockCount() { + return stockCount; + } + + public void setStockCount(Integer stockCount) { + this.stockCount = stockCount; + } + + public Short getUrlPort() { + return urlPort; + } + + public void setUrlPort(Short urlPort) { + this.urlPort = urlPort; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Float getVisitRatio() { + return visitRatio; + } + + public void setVisitRatio(Float visitRatio) { + this.visitRatio = visitRatio; + } + + public Double getTaxPercentage() { + return taxPercentage; + } + + public void setTaxPercentage(Double taxPercentage) { + this.taxPercentage = taxPercentage; + } + + public Boolean getFavourite() { + return favourite; + } + + public void setFavourite(Boolean favourite) { + this.favourite = favourite; + } + + public Byte getDisplayMask() { + return displayMask; + } + + public void setDisplayMask(Byte displayMask) { + this.displayMask = displayMask; + } + + public UUID getSerialNumber() { + return serialNumber; + } + + public void setSerialNumber(UUID serialNumber) { + this.serialNumber = serialNumber; + } + + public BigDecimal getSiteWeight() { + return siteWeight; + } + + public void setSiteWeight(BigDecimal siteWeight) { + this.siteWeight = siteWeight; + } + + public BigInteger getVisitCount() { + return visitCount; + } + + public void setVisitCount(BigInteger visitCount) { + this.visitCount = visitCount; + } + + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Bookmark bookmark = (Bookmark)o; + return Objects.equals(id, bookmark.id); + } + + @Override public int hashCode() { + return Objects.hash(id); + } + } + +} + + From ad8656549dfe5f211f58a87d9ecceebeb09defa8 Mon Sep 17 00:00:00 2001 From: Sergey Chernolyas Date: Mon, 25 Sep 2017 11:27:57 +0300 Subject: [PATCH 11/13] IGNITE-6286: correct header of class --- .../query/IgniteSqlParameterizedQueryTest.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java index 8273dcdefafb5..e2d3f9ad26831 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java @@ -1,9 +1,20 @@ /* - * Hibernate OGM, Domain model persistence for NoSQL datastores + * 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 * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or . + * 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.query; import java.io.Serializable; From 6e001c85dda855a90824ad9998c0baa4dce8ea7e Mon Sep 17 00:00:00 2001 From: Sergey Chernolyas Date: Tue, 26 Sep 2017 15:16:26 +0300 Subject: [PATCH 12/13] IGNITE-6286: remove unused 'log.info' statement --- .../ignite/internal/processors/query/h2/IgniteH2Indexing.java | 1 - .../processors/query/IgniteSqlParameterizedQueryTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index c746b36e075b7..15f709fd5c0ee 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -509,7 +509,6 @@ public void executeStatement(String schema, String sql) throws IgniteCheckedExce */ private void bindObject(PreparedStatement stmt, int idx, @Nullable Object obj) throws IgniteCheckedException { try { - log.info("bindObject [idx=" +idx + ", obj=" + obj.getClass() + ']'); if (obj == null) stmt.setNull(idx, Types.VARCHAR); else if (obj instanceof BigInteger) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java index e2d3f9ad26831..af687dc28a724 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java @@ -74,7 +74,6 @@ private CacheConfiguration buildCacheConfiguration(String name) { for (Field currentField : Bookmark.class.getDeclaredFields()) { bookmarkQueryEntity.addQueryField(currentField.getName(), currentField.getType().getName(), null); } - log.info("createEntityCacheConfiguration. full QueryEntity info : :"+bookmarkQueryEntity.toString()); List queryEntities = new ArrayList<>(); queryEntities.add(bookmarkQueryEntity); ccfg.setQueryEntities(queryEntities); From 8e47ab78f5ffc06744124f1ab561e017fec8d565 Mon Sep 17 00:00:00 2001 From: Sergey Chernolyas Date: Tue, 26 Sep 2017 15:29:18 +0300 Subject: [PATCH 13/13] IGNITE-6286: add Javadoc to all members --- .../IgniteSqlParameterizedQueryTest.java | 66 ++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java index af687dc28a724..bb4330dba849f 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java @@ -47,8 +47,8 @@ public class IgniteSqlParameterizedQueryTest extends GridCommonAbstractTest { /** IP finder. */ private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - private static String CACHE_BOOKMARK = "Bookmark"; - private static String NODE_CLIENT = "client"; + private static final String CACHE_BOOKMARK = "Bookmark"; + private static final String NODE_CLIENT = "client"; /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { @@ -67,6 +67,12 @@ public class IgniteSqlParameterizedQueryTest extends GridCommonAbstractTest { return c; } + /** + * build cache configuration + * @param name cache name + * @return configuration + * @see CacheConfiguration + */ private CacheConfiguration buildCacheConfiguration(String name) { CacheConfiguration ccfg = new CacheConfiguration(name); QueryEntity bookmarkQueryEntity = new QueryEntity(String.class.getName(), Bookmark.class.getName()); @@ -96,6 +102,13 @@ private CacheConfiguration buildCacheConfiguration(String name) { stopAllGrids(); } + /** + * method for create parametrized query and get first result + * @param field name of field + * @param value value + * @return fist searched object + * @see Bookmark + */ private Bookmark searchBookmarkBy(String field, Object value) { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); SqlFieldsQuery query = new SqlFieldsQuery("SELECT _val from Bookmark where "+field+"=?"); @@ -108,6 +121,10 @@ private Bookmark searchBookmarkBy(String field, Object value) { return (Bookmark)row0.get(0); } + /** + * Method for testing parametrized query by String field + * @throws Exception if any error occurs + */ public void testStringSupport() throws Exception { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); @@ -121,6 +138,10 @@ public void testStringSupport() throws Exception { assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); } + /** + * Method for testing parametrized query by Integer field + * @throws Exception if any error occurs + */ public void testIntegerSupport() throws Exception { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); @@ -134,6 +155,10 @@ public void testIntegerSupport() throws Exception { assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); } + /** + * Method for testing parametrized query by Short field + * @throws Exception if any error occurs + */ public void testShortSupport() throws Exception { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); @@ -147,6 +172,10 @@ public void testShortSupport() throws Exception { assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); } + /** + * Method for testing parametrized query by Long field + * @throws Exception if any error occurs + */ public void testLongSupport() throws Exception { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); @@ -160,6 +189,10 @@ public void testLongSupport() throws Exception { assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); } + /** + * Method for testing parametrized query by Float field + * @throws Exception if any error occurs + */ public void testFloatSupport() throws Exception { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); @@ -173,6 +206,10 @@ public void testFloatSupport() throws Exception { assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); } + /** + * Method for testing parametrized query by Double field + * @throws Exception if any error occurs + */ public void testDoubleSupport() throws Exception { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); @@ -186,6 +223,10 @@ public void testDoubleSupport() throws Exception { assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); } + /** + * Method for testing parametrized query by Boolean field + * @throws Exception if any error occurs + */ public void testBooleanSupport() throws Exception { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); @@ -199,6 +240,10 @@ public void testBooleanSupport() throws Exception { assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); } + /** + * Method for testing parametrized query by Byte field + * @throws Exception if any error occurs + */ public void testByteSupport() throws Exception { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); @@ -212,6 +257,11 @@ public void testByteSupport() throws Exception { assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); } + /** + * Method for testing parametrized query by UUID field + * @throws Exception if any error occurs + * @see UUID + */ public void testUUIDSupport() throws Exception { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); @@ -225,6 +275,12 @@ public void testUUIDSupport() throws Exception { assertEquals("UUID value does not match", bookmark.getSerialNumber(), loadedBookmark.getSerialNumber()); assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); } + + /** + * Method for testing parametrized query by BigInteger field + * @throws Exception if any error occurs + * @see BigInteger + */ public void testBigIntegerSupport() throws Exception { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK); @@ -238,6 +294,12 @@ public void testBigIntegerSupport() throws Exception { assertEquals("BigInteger value does not match", bookmark.getVisitCount(), loadedBookmark.getVisitCount()); assertEquals("Id value does not match", bookmark.getId(), loadedBookmark.getId()); } + + /** + * Method for testing parametrized query by BigDecimal field + * @throws Exception if any error occurs + * @see BigDecimal + */ public void testBigDecimalSupport() throws Exception { IgniteCache cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK);