This is an automated email from the ASF dual-hosted git repository.
timoninmaxim pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new dc4c60330e0 IGNITE-17321 Add docs for java client partition awareness
use cases (#10453)
dc4c60330e0 is described below
commit dc4c60330e0d3f347be5d37458f63775b84d0c71
Author: Julia Bakulina <[email protected]>
AuthorDate: Fri Mar 10 11:11:23 2023 +0300
IGNITE-17321 Add docs for java client partition awareness use cases (#10453)
---
.../org/apache/ignite/snippets/JavaThinClient.java | 3 ++
docs/_docs/thin-clients/java-thin-client.adoc | 6 ++++
.../ignite/configuration/ClientConfiguration.java | 38 ++++++++++++++++------
3 files changed, 37 insertions(+), 10 deletions(-)
diff --git
a/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JavaThinClient.java
b/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JavaThinClient.java
index c11241a4ae8..8a9c2fdc642 100644
---
a/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JavaThinClient.java
+++
b/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JavaThinClient.java
@@ -359,6 +359,9 @@ public class JavaThinClient {
try (IgniteClient client = Ignition.startClient(cfg)) {
ClientCache<Integer, String> cache = client.cache("myCache");
// Put, get or remove data from the cache...
+ cache.put(0, "Hello, world!");
+ // The partition number can be specified with
IndexQuery#setPartition(Integer) as well.
+ ScanQuery scanQuery = new ScanQuery().setPartition(part);
} catch (ClientException e) {
System.err.println(e.getMessage());
}
diff --git a/docs/_docs/thin-clients/java-thin-client.adoc
b/docs/_docs/thin-clients/java-thin-client.adoc
index 1469e446645..5f955d35615 100644
--- a/docs/_docs/thin-clients/java-thin-client.adoc
+++ b/docs/_docs/thin-clients/java-thin-client.adoc
@@ -79,6 +79,12 @@ Note that the code above provides a failover mechanism in
case of server node fa
include::includes/partition-awareness.adoc[]
+Partition awareness functionality helps to avoid an additional network hop in
the following scenarios:
+
+1. Single-key operations API, like put(), get(), etc. However, the
functionality has no effect on those operations within explicit transactions
(initiated via ClientTransaction#txStart() described in <<Transactions>>
section).
+
+2. ScanQuery and IndexQuery accept a partition number as a parameter with
which the query is routed to a particular server node that stores the requested
data. Refer to <<Executing Scan Queries>> and
link:key-value-api/using-cache-queries#executing-index-queries[Executing Index
Queries] sections for more information.
+
The following code sample illustrates how to use the partition awareness
feature with the java thin client.
[source, java]
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 a2d1cdbfbf9..59a8b1c6ac7 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
@@ -27,11 +27,14 @@ import javax.cache.configuration.Factory;
import javax.net.ssl.SSLContext;
import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cache.query.IndexQuery;
+import org.apache.ignite.cache.query.ScanQuery;
import org.apache.ignite.client.ClientAddressFinder;
import org.apache.ignite.client.ClientPartitionAwarenessMapper;
import org.apache.ignite.client.ClientPartitionAwarenessMapperFactory;
import org.apache.ignite.client.ClientRetryAllPolicy;
import org.apache.ignite.client.ClientRetryPolicy;
+import org.apache.ignite.client.ClientTransactions;
import org.apache.ignite.client.SslMode;
import org.apache.ignite.client.SslProtocol;
import org.apache.ignite.internal.client.thin.TcpIgniteClient;
@@ -529,12 +532,20 @@ public final class ClientConfiguration implements
Serializable {
}
/**
- * @return 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>
+ * <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.
+ * <p>
+ * Partition awareness functionality helps to avoid an additional network
hop in the following scenarios:
+ * <ul>
+ * <li>1. Single-key operations API, like put(), get(), etc. However,
the functionality has no effect on those
+ * operations within explicit transactions {@link
ClientTransactions#txStart()}.</li>
+ * <li>2. {@link ScanQuery#setPartition(Integer)} and {@link
IndexQuery#setPartition(Integer)} accept a
+ * partition number as a parameter with which the query is routed to a
particular server node that stores
+ * the requested data.</li>
+ * </ul>
+ * </p>
+ * @return A value indicating whether partition awareness should be
enabled.
*/
public boolean isPartitionAwarenessEnabled() {
return partitionAwarenessEnabled;
@@ -542,12 +553,19 @@ public final class ClientConfiguration implements
Serializable {
/**
* 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>
+ * <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.
- *
+ * <p>
+ * Partition awareness functionality helps to avoid an additional network
hop in the following scenarios:
+ * <ul>
+ * <li>1. Single-key operations API, like put(), get(), etc. However,
the functionality has no effect on
+ * those operations within explicit transactions {@link
ClientTransactions#txStart()}.</li>
+ * <li>2. {@link ScanQuery#setPartition(Integer)} and {@link
IndexQuery#setPartition(Integer)} accept
+ * a partition number as a parameter with which the query is routed to
a particular server node that stores
+ * the requested data.</li>
+ * </ul>
+ * </p>
* @param partitionAwarenessEnabled Value indicating whether partition
awareness should be enabled.
* @return {@code this} for chaining.
*/