This is an automated email from the ASF dual-hosted git repository.

alexpl 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 5ea0888dcd6 IGNITE-27816 Java Thin: Add ClientCache.sizeLong method - 
Fixes #12725.
5ea0888dcd6 is described below

commit 5ea0888dcd6f93d1de5c21e5ae604b437b0fbcce
Author: Aleksey Plekhanov <[email protected]>
AuthorDate: Fri Feb 13 12:18:54 2026 +0300

    IGNITE-27816 Java Thin: Add ClientCache.sizeLong method - Fixes #12725.
    
    Signed-off-by: Aleksey Plekhanov <[email protected]>
---
 .../java/org/apache/ignite/client/ClientCache.java | 30 +++++++++++++
 .../internal/client/thin/TcpClientCache.java       | 52 +++++++++++++++++-----
 .../internal/client/thin/CacheAsyncTest.java       |  5 +++
 .../internal/client/thin/FunctionalTest.java       |  3 ++
 4 files changed, 79 insertions(+), 11 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/client/ClientCache.java 
b/modules/core/src/main/java/org/apache/ignite/client/ClientCache.java
index cdccc13450d..0f5344e20e2 100644
--- a/modules/core/src/main/java/org/apache/ignite/client/ClientCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/client/ClientCache.java
@@ -150,7 +150,9 @@ public interface ClientCache<K, V> {
      *
      * @param peekModes Optional peek modes. If not provided, then total cache 
size is returned.
      * @return The number of all entries cached across all nodes.
+     * @deprecated Use {@link #sizeLong} instead.
      */
+    @Deprecated
     public int size(CachePeekMode... peekModes) throws ClientException;
 
     /**
@@ -162,9 +164,37 @@ public interface ClientCache<K, V> {
      *
      * @param peekModes Optional peek modes. If not provided, then total cache 
size is returned.
      * @return a Future representing pending completion of the operation, 
which wraps the cache size.
+     * @deprecated Use {@link #sizeLongAsync} instead.
      */
+    @Deprecated
     public IgniteClientFuture<Integer> sizeAsync(CachePeekMode... peekModes) 
throws ClientException;
 
+    /**
+     * Gets the number of all entries cached across all nodes as a long value. 
By default, if {@code peekModes} value
+     * isn't defined, only size of primary copies across all nodes will be 
returned. This behavior is identical to
+     * calling this method with {@link CachePeekMode#PRIMARY} peek mode.
+     * <p>
+     * NOTE: this operation is distributed and will query all participating 
nodes for their cache sizes.
+     *
+     * @param peekModes Optional peek modes. If not provided, then total cache 
size is returned.
+     * @return Cache size across all nodes.
+     * @throws ClientException On error.
+     */
+    public long sizeLong(CachePeekMode... peekModes) throws ClientException;
+
+    /**
+     * Asynchronously gets the number of all entries cached across all nodes 
as a long value. By default,
+     * if {@code peekModes} value isn't defined, only size of primary copies 
across all nodes will be returned.
+     * This behavior is identical to calling this method with {@link 
CachePeekMode#PRIMARY} peek mode.
+     * <p>
+     * NOTE: this operation is distributed and will query all participating 
nodes for their cache sizes.
+     *
+     * @param peekModes Optional peek modes. If not provided, then total cache 
size is returned.
+     * @return a Future representing pending completion of the operation.
+     * @throws ClientException On error.
+     */
+    public IgniteClientFuture<Long> sizeLongAsync(CachePeekMode... peekModes) 
throws ClientException;
+
     /**
      * Gets a collection of entries from the {@link ClientCache}, returning 
them as
      * {@link Map} of the values associated with the set of keys requested.
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientCache.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientCache.java
index c9d6f10f13d..dffc38043b7 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientCache.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientCache.java
@@ -313,23 +313,35 @@ public class TcpClientCache<K, V> implements 
ClientCache<K, V> {
     @Override public int size(CachePeekMode... peekModes) throws 
ClientException {
         return ch.service(
             ClientOperation.CACHE_GET_SIZE,
-            req -> {
-                writeCacheInfo(req);
-                ClientUtils.collection(peekModes, req.out(), (out, m) -> 
out.writeByte((byte)m.ordinal()));
-            },
-            res -> (int)res.in().readLong()
+            req -> writePeekModes(peekModes, req),
+            this::readCacheSizeInt
         );
     }
 
     /** {@inheritDoc} */
     @Override public IgniteClientFuture<Integer> sizeAsync(CachePeekMode... 
peekModes) throws ClientException {
         return ch.serviceAsync(
-                ClientOperation.CACHE_GET_SIZE,
-                req -> {
-                    writeCacheInfo(req);
-                    ClientUtils.collection(peekModes, req.out(), (out, m) -> 
out.writeByte((byte)m.ordinal()));
-                },
-                res -> (int)res.in().readLong()
+            ClientOperation.CACHE_GET_SIZE,
+            req -> writePeekModes(peekModes, req),
+            this::readCacheSizeInt
+        );
+    }
+
+    /** {@inheritDoc} */
+    @Override public long sizeLong(CachePeekMode... peekModes) throws 
ClientException {
+        return ch.service(
+            ClientOperation.CACHE_GET_SIZE,
+            req -> writePeekModes(peekModes, req),
+            res -> res.in().readLong()
+        );
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteClientFuture<Long> sizeLongAsync(CachePeekMode... 
peekModes) throws ClientException {
+        return ch.serviceAsync(
+            ClientOperation.CACHE_GET_SIZE,
+            req -> writePeekModes(peekModes, req),
+            res -> res.in().readLong()
         );
     }
 
@@ -1641,6 +1653,24 @@ public class TcpClientCache<K, V> implements 
ClientCache<K, V> {
             });
     }
 
+    /** */
+    private void writePeekModes(CachePeekMode[] peekModes, 
PayloadOutputChannel req) {
+        writeCacheInfo(req);
+        ClientUtils.collection(peekModes, req.out(), (out, m) -> 
out.writeByte((byte)m.ordinal()));
+    }
+
+    /** */
+    private int readCacheSizeInt(PayloadInputChannel res) {
+        long size = res.in().readLong();
+
+        if (size <= Integer.MAX_VALUE)
+            return (int)size;
+        else {
+            throw new ClientException("Cache size exceeded maximum value for 
int type, use " +
+                "sizeLong/sizeLongAsync methods to get correct value");
+        }
+    }
+
     /**
      * Check that data replication operations is supported by server.
      *
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/CacheAsyncTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/CacheAsyncTest.java
index 31920a300f5..db18b63d983 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/CacheAsyncTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/CacheAsyncTest.java
@@ -393,6 +393,11 @@ public class CacheAsyncTest extends AbstractThinClientTest 
{
         assertEquals(0, 
strCache.sizeAsync(CachePeekMode.BACKUP).get().intValue());
         assertEquals(3, 
strCache.sizeAsync(CachePeekMode.PRIMARY).get().intValue());
 
+        // SizeLong.
+        assertEquals(3L, strCache.sizeLongAsync().get().longValue());
+        assertEquals(0L, 
strCache.sizeLongAsync(CachePeekMode.BACKUP).get().longValue());
+        assertEquals(3L, 
strCache.sizeLongAsync(CachePeekMode.PRIMARY).get().longValue());
+
         // GetAll.
         strCache.put(3, "3");
         Map<Integer, String> getAllRes = 
strCache.getAllAsync(ImmutableSet.of(2, 3, 4, 5)).get();
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/FunctionalTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/FunctionalTest.java
index 61125b0bd5c..d434d966108 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/FunctionalTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/FunctionalTest.java
@@ -146,6 +146,9 @@ public class FunctionalTest extends 
AbstractBinaryArraysTest {
             assertEquals(1, cache.size());
             assertEquals(2, cache.size(CachePeekMode.ALL));
 
+            assertEquals(1L, cache.sizeLong());
+            assertEquals(2L, cache.sizeLong(CachePeekMode.ALL));
+
             cache = client.cache(CACHE_NAME);
 
             Person cachedVal = cache.get(key);

Reply via email to