IGNITE-14719 Thin clients: enable partition awareness by default (Java, .NET, C++)
diff --git a/docs/_docs/thin-clients/dotnet-thin-client.adoc b/docs/_docs/thin-clients/dotnet-thin-client.adoc
index 7a7392f..b326dd3 100644
--- a/docs/_docs/thin-clients/dotnet-thin-client.adoc
+++ b/docs/_docs/thin-clients/dotnet-thin-client.adoc
@@ -69,12 +69,6 @@
Partition awareness allows the thin client to send query requests directly to the node that owns the queried data.
-[WARNING]
-====
-[discrete]
-Partition awareness is an experimental feature whose API or design architecture might change before a GA version is released.
-====
-
Without partition awareness, an application that is connected to the cluster via a thin client executes all queries and operations via a single server node that acts as a proxy for the incoming requests.
These operations are then re-routed to the node that stores the data that is being requested.
This results in a bottleneck that could prevent the application from scaling linearly.
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/ClientConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/ClientConfiguration.java
index d403d39..69d9b7b 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/ClientConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/ClientConfiguration.java
@@ -106,12 +106,8 @@
/**
* Whether partition awareness should be enabled.
- *
- * When {@code true} client attempts to send the request directly to the primary node for the given cache key.
- * To do so, connection is established to every known server node.
- * By default {@code false} only one connection is established at a given moment to a random server node.
*/
- private boolean partitionAwarenessEnabled;
+ private boolean partitionAwarenessEnabled = true;
/**
* Reconnect throttling period (in milliseconds). There are no more than {@code reconnectThrottlingRetries}
@@ -478,14 +474,24 @@
}
/**
- * @return Whether partition awareness should be enabled.
+ * Gets a value indicating whether partition awareness should be enabled.
+ * <p>
+ * Default is {@code true}: client sends requests directly to the primary node for the given cache key.
+ * To do so, connection is established to every known server node.
+ * <p>
+ * When {@code false}, only one connection is established at a given moment to a random server node.
*/
public boolean isPartitionAwarenessEnabled() {
return partitionAwarenessEnabled;
}
/**
- * Enable or disable partition awareness.
+ * Sets a value indicating whether partition awareness should be enabled.
+ * <p>
+ * Default is {@code true}: client sends requests directly to the primary node for the given cache key.
+ * To do so, connection is established to every known server node.
+ * <p>
+ * When {@code false}, only one connection is established at a given moment to a random server node.
*
* @return {@code this} for chaining.
*/
diff --git a/modules/core/src/test/java/org/apache/ignite/client/SslParametersTest.java b/modules/core/src/test/java/org/apache/ignite/client/SslParametersTest.java
index c6def06..b1d34fd 100644
--- a/modules/core/src/test/java/org/apache/ignite/client/SslParametersTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/client/SslParametersTest.java
@@ -64,15 +64,11 @@
* @return Client config.
*/
protected ClientConfiguration getClientConfiguration() {
- ClientConfiguration cfg = new ClientConfiguration();
-
- cfg.setAddresses("127.0.0.1:10800");
-
- cfg.setSslMode(SslMode.REQUIRED);
-
- cfg.setSslContextFactory(createSslFactory());
-
- return cfg;
+ return new ClientConfiguration()
+ .setAddresses("127.0.0.1:10800")
+ .setSslMode(SslMode.REQUIRED)
+ .setSslContextFactory(createSslFactory())
+ .setPartitionAwarenessEnabled(false);
}
/**
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/AbstractThinClientTest.java b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/AbstractThinClientTest.java
index 486939d..0e33127 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/AbstractThinClientTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/AbstractThinClientTest.java
@@ -37,7 +37,7 @@
* Gets default client configuration.
*/
protected ClientConfiguration getClientConfiguration() {
- return new ClientConfiguration();
+ return new ClientConfiguration().setPartitionAwarenessEnabled(false);
}
/**
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/ReliableChannelTest.java b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/ReliableChannelTest.java
index 88ee8eb..6469afb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/ReliableChannelTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/ReliableChannelTest.java
@@ -173,7 +173,9 @@
*/
@Test
public void testNodeChannelsAreNotCleaned() {
- ClientConfiguration ccfg = new ClientConfiguration().setAddresses(dfltAddrs);
+ ClientConfiguration ccfg = new ClientConfiguration()
+ .setAddresses(dfltAddrs)
+ .setPartitionAwarenessEnabled(false);
ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
@@ -236,7 +238,9 @@
.nextAddresesResponse(dfltAddrs)
.nextAddresesResponse("127.0.0.1:10803", "127.0.0.1:10804");
- ClientConfiguration ccfg = new ClientConfiguration().setAddressesFinder(finder);
+ ClientConfiguration ccfg = new ClientConfiguration()
+ .setAddressesFinder(finder)
+ .setPartitionAwarenessEnabled(false);
ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
diff --git a/modules/platforms/cpp/thin-client/include/ignite/thin/ignite_client_configuration.h b/modules/platforms/cpp/thin-client/include/ignite/thin/ignite_client_configuration.h
index 617009f..acb8a53 100644
--- a/modules/platforms/cpp/thin-client/include/ignite/thin/ignite_client_configuration.h
+++ b/modules/platforms/cpp/thin-client/include/ignite/thin/ignite_client_configuration.h
@@ -46,7 +46,7 @@
*/
IgniteClientConfiguration() :
sslMode(SslMode::DISABLE),
- partitionAwareness(false),
+ partitionAwareness(true),
connectionsLimit(0)
{
// No-op.
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/ClientConnectionTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/ClientConnectionTest.cs
index b6b9d7d..fe7f88b 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/ClientConnectionTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/ClientConnectionTest.cs
@@ -726,7 +726,8 @@
{
UserName = "ignite",
Password = "ignite",
- SocketTimeout = TimeSpan.FromSeconds(10)
+ SocketTimeout = TimeSpan.FromSeconds(10),
+ EnablePartitionAwareness = false
};
}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/IgniteClientConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/IgniteClientConfigurationTest.cs
index 3261248..1aacaf2 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/IgniteClientConfigurationTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/IgniteClientConfigurationTest.cs
@@ -50,6 +50,7 @@
Assert.AreEqual(IgniteClientConfiguration.DefaultSocketBufferSize, cfg.SocketSendBufferSize);
Assert.AreEqual(IgniteClientConfiguration.DefaultTcpNoDelay, cfg.TcpNoDelay);
Assert.AreEqual(IgniteClientConfiguration.DefaultSocketTimeout, cfg.SocketTimeout);
+ Assert.AreEqual(IgniteClientConfiguration.DefaultEnablePartitionAwareness, cfg.EnablePartitionAwareness);
}
/// <summary>
@@ -326,7 +327,7 @@
#endif
/// <summary>
- /// Tests <see cref="TransactionClientConfiguration"/> copy ctor.
+ /// Tests <see cref="TransactionClientConfiguration"/> copy ctor.
/// </summary>
[Test]
public void TestTransactionConfigurationCopyCtor()
@@ -337,9 +338,9 @@
DefaultTransactionConcurrency = TransactionConcurrency.Pessimistic,
DefaultTransactionIsolation = TransactionIsolation.Serializable
};
-
+
var resultCfg = new TransactionClientConfiguration(sourceCfg);
-
+
Assert.AreEqual(sourceCfg.DefaultTimeout, resultCfg.DefaultTimeout);
Assert.AreEqual(sourceCfg.DefaultTransactionConcurrency, resultCfg.DefaultTransactionConcurrency);
Assert.AreEqual(sourceCfg.DefaultTransactionIsolation, resultCfg.DefaultTransactionIsolation);
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Client/IgniteClientConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Client/IgniteClientConfiguration.cs
index 0cd8e15..1ce504d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Client/IgniteClientConfiguration.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Client/IgniteClientConfiguration.cs
@@ -55,6 +55,11 @@
public const bool DefaultTcpNoDelay = true;
/// <summary>
+ /// Default value of <see cref="EnablePartitionAwareness" /> property.
+ /// </summary>
+ public const bool DefaultEnablePartitionAwareness = true;
+
+ /// <summary>
/// Default socket timeout.
/// </summary>
public static readonly TimeSpan DefaultSocketTimeout = TimeSpan.FromMilliseconds(5000);
@@ -72,6 +77,7 @@
TcpNoDelay = DefaultTcpNoDelay;
SocketTimeout = DefaultSocketTimeout;
Logger = new ConsoleLogger();
+ EnablePartitionAwareness = DefaultEnablePartitionAwareness;
}
/// <summary>
@@ -217,11 +223,13 @@
/// <summary>
/// Gets or sets a value indicating whether partition awareness should be enabled.
/// <para />
- /// Default is false: only one connection is established at a given moment to a random server node.
- /// When true: for cache operations, Ignite client attempts to send the request directly to
+ /// Default is true: for cache operations, Ignite client attempts to send the request directly to
/// the primary node for the given cache key.
/// To do so, connection is established to every known server node at all times.
+ /// <para />
+ /// When false: only one connection is established at a given moment to a random server node.
/// </summary>
+ [DefaultValue(DefaultEnablePartitionAwareness)]
public bool EnablePartitionAwareness { get; set; }
/// <summary>
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientFailoverSocket.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientFailoverSocket.cs
index a7dfb9b..dc22a67 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientFailoverSocket.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientFailoverSocket.cs
@@ -339,8 +339,9 @@
Justification = "There is no finalizer.")]
public void Dispose()
{
- lock (_socketLock)
+ // Lock order: same as in OnAffinityTopologyVersionChange.
lock (_topologyUpdateLock)
+ lock (_socketLock)
{
_disposed = true;