Skip to content

Commit 0274af8

Browse files
ivandaschptupitsyn
authored andcommitted
IGNITE-6563 Implement GetSizeLong
apache#6082
1 parent 01f0e9e commit 0274af8

File tree

10 files changed

+301
-25
lines changed

10 files changed

+301
-25
lines changed

modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,15 @@ public class PlatformCache extends PlatformAbstractTarget {
344344
/** */
345345
public static final int OP_LOCAL_PRELOAD_PARTITION = 89;
346346

347+
/** */
348+
public static final int OP_SIZE_LONG = 90;
349+
350+
/** */
351+
public static final int OP_SIZE_LONG_ASYNC = 91;
352+
353+
/** */
354+
public static final int OP_SIZE_LONG_LOC = 92;
355+
347356
/** Underlying JCache in binary mode. */
348357
private final IgniteCacheProxy cache;
349358

@@ -594,6 +603,17 @@ public IgniteCache rawCache() {
594603
return TRUE;
595604
}
596605

606+
case OP_SIZE_LONG_ASYNC: {
607+
CachePeekMode[] modes = PlatformUtils.decodeCachePeekModes(reader.readInt());
608+
609+
Integer part = reader.readBoolean() ? reader.readInt() : null;
610+
611+
readAndListenFuture(reader, part != null ? cache.sizeLongAsync(part, modes) :
612+
cache.sizeLongAsync(modes));
613+
614+
return TRUE;
615+
}
616+
597617
case OP_CLEAR_ASYNC: {
598618
readAndListenFuture(reader, cache.clearAsync(reader.readObjectDetached()));
599619

@@ -777,6 +797,19 @@ public IgniteCache rawCache() {
777797

778798
case OP_LOCAL_PRELOAD_PARTITION:
779799
return cache.localPreloadPartition(reader.readInt()) ? TRUE : FALSE;
800+
801+
case OP_SIZE_LONG:
802+
case OP_SIZE_LONG_LOC: {
803+
CachePeekMode[] modes = PlatformUtils.decodeCachePeekModes(reader.readInt());
804+
805+
Integer part = reader.readBoolean() ? reader.readInt() : null;
806+
807+
if (type == OP_SIZE_LONG)
808+
return part != null ? cache.sizeLong(part, modes) : cache.sizeLong(modes);
809+
else
810+
return part != null ? cache.localSizeLong(part, modes) : cache.localSizeLong(modes);
811+
812+
}
780813
}
781814
}
782815
catch (Exception e) {

modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/ExpiryCacheHolderTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,36 @@ public Task<int> GetSizeAsync(params CachePeekMode[] modes)
416416
throw new NotImplementedException();
417417
}
418418

419+
public long GetSizeLong(params CachePeekMode[] modes)
420+
{
421+
throw new NotImplementedException();
422+
}
423+
424+
public long GetSizeLong(int partition, params CachePeekMode[] modes)
425+
{
426+
throw new NotImplementedException();
427+
}
428+
429+
public Task<long> GetSizeLongAsync(params CachePeekMode[] modes)
430+
{
431+
throw new NotImplementedException();
432+
}
433+
434+
public Task<long> GetSizeLongAsync(int partition, params CachePeekMode[] modes)
435+
{
436+
throw new NotImplementedException();
437+
}
438+
439+
public long GetLocalSizeLong(params CachePeekMode[] modes)
440+
{
441+
throw new NotImplementedException();
442+
}
443+
444+
public long GetLocalSizeLong(int partition, params CachePeekMode[] modes)
445+
{
446+
throw new NotImplementedException();
447+
}
448+
419449
public IQueryCursor<ICacheEntry<int, int>> Query(QueryBase qry)
420450
{
421451
throw new NotImplementedException();

modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/CacheParityTest.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ public class CacheParityTest
5353
{
5454
"queryDetailMetrics", // IGNITE-6680
5555
"resetQueryDetailMetrics", // IGNITE-6680
56-
"sizeLong", // IGNITE-6563
57-
"sizeLongAsync", // IGNITE-6563
58-
"localSizeLong", // IGNITE-6563
5956
"enableStatistics", // IGNITE-7276
6057
"clearStatistics", // IGNITE-9017
6158
};

modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,25 @@ protected static IIgnite GetIgnite(int idx)
117117
return Ignition.GetIgnite("grid-" + idx);
118118
}
119119

120-
private ICache<int, int> Cache(int idx) {
121-
return Cache<int, int>(idx);
120+
protected ICache<int, int> Cache(int idx, bool async = false)
121+
{
122+
return Cache<int, int>(idx, async);
122123
}
123124

124-
private ICache<TK, TV> Cache<TK, TV>(int idx) {
125-
return GetIgnite(idx).GetCache<TK, TV>(CacheName());
125+
private ICache<TK, TV> Cache<TK, TV>(int idx, bool async = false) {
126+
var cache = GetIgnite(idx).GetCache<TK, TV>(CacheName());
127+
128+
return async ? cache.WrapAsync() : cache;
126129
}
127130

128131
protected ICache<int, int> Cache(bool async = false)
129132
{
130-
var cache = Cache<int, int>(0);
131-
132-
return async ? cache.WrapAsync() : cache;
133+
return Cache<int, int>(0, async);
133134
}
134135

135136
private ICache<TK, TV> Cache<TK, TV>(bool async = false)
136137
{
137-
var cache = Cache<TK, TV>(0);
138-
139-
return async ? cache : cache.WrapAsync();
138+
return Cache<TK, TV>(0, async);
140139
}
141140

142141
private ICacheAffinity Affinity()
@@ -1199,24 +1198,34 @@ public void TestRemoveAllKeysAsync()
11991198
}
12001199

12011200
[Test]
1202-
public void TestSizes()
1201+
public void TestSizes([Values(true, false)] bool async)
12031202
{
12041203
for (int i = 0; i < GridCount(); i++)
12051204
{
1206-
var cache = Cache(i);
1205+
var cache = Cache(i, async);
12071206

12081207
List<int> keys = GetPrimaryKeysForCache(cache, 2);
12091208

12101209
foreach (int key in keys)
12111210
cache.Put(key, 1);
12121211

12131212
Assert.IsTrue(cache.GetSize() >= 2);
1213+
Assert.AreEqual(cache.GetSize(), cache.GetSizeLong());
1214+
Assert.AreEqual(2, cache.GetLocalSizeLong(CachePeekMode.Primary));
12141215
Assert.AreEqual(2, cache.GetLocalSize(CachePeekMode.Primary));
1216+
1217+
foreach (var key in keys)
1218+
{
1219+
var p = GetIgnite(i).GetAffinity(cache.Name).GetPartition(key);
1220+
1221+
Assert.GreaterOrEqual(cache.GetSizeLong(p, CachePeekMode.Primary), 1);
1222+
}
12151223
}
12161224

1217-
ICache<int, int> cache0 = Cache();
1225+
ICache<int, int> cache0 = Cache(async);
12181226

12191227
Assert.AreEqual(GridCount() * 2, cache0.GetSize(CachePeekMode.Primary));
1228+
Assert.AreEqual(GridCount() * 2, cache0.GetSizeLong(CachePeekMode.Primary));
12201229

12211230
if (!LocalCache() && !ReplicatedCache())
12221231
{
@@ -1225,6 +1234,7 @@ public void TestSizes()
12251234
cache0.Put(nearKey, 1);
12261235

12271236
Assert.AreEqual(NearEnabled() ? 1 : 0, cache0.GetSize(CachePeekMode.Near));
1237+
Assert.AreEqual(NearEnabled() ? 1 : 0, cache0.GetSizeLong(CachePeekMode.Near));
12281238
}
12291239
}
12301240

@@ -1238,15 +1248,26 @@ public void TestLocalSize()
12381248
cache.Put(keys[1], 2);
12391249

12401250
var localSize = cache.GetLocalSize();
1251+
Assert.AreEqual(localSize, cache.GetLocalSizeLong());
12411252

12421253
cache.LocalEvict(keys.Take(2).ToArray());
12431254

12441255
Assert.AreEqual(0, cache.GetLocalSize(CachePeekMode.Onheap));
1256+
Assert.AreEqual(0, cache.GetLocalSizeLong(CachePeekMode.Onheap));
12451257
Assert.AreEqual(localSize, cache.GetLocalSize(CachePeekMode.All));
1246-
1258+
Assert.AreEqual(localSize, cache.GetLocalSizeLong(CachePeekMode.All));
1259+
12471260
cache.Put(keys[2], 3);
12481261

12491262
Assert.AreEqual(localSize + 1, cache.GetLocalSize(CachePeekMode.All));
1263+
Assert.AreEqual(localSize + 1, cache.GetLocalSizeLong(CachePeekMode.All));
1264+
1265+
foreach (var key in keys)
1266+
{
1267+
var p = Affinity().GetPartition(key);
1268+
1269+
Assert.GreaterOrEqual(cache.GetLocalSizeLong(p, CachePeekMode.All), 1);
1270+
}
12501271

12511272
cache.RemoveAll(keys.Take(2).ToArray());
12521273
}

modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheTestAsyncWrapper.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,42 @@ public Task<int> GetSizeAsync(params CachePeekMode[] modes)
451451
return _cache.GetSizeAsync(modes);
452452
}
453453

454+
/** <inheritDoc /> */
455+
public long GetSizeLong(params CachePeekMode[] modes)
456+
{
457+
return _cache.GetSizeLongAsync(modes).GetResult();
458+
}
459+
460+
/** <inheritDoc /> */
461+
public long GetSizeLong(int partition, params CachePeekMode[] modes)
462+
{
463+
return _cache.GetSizeLongAsync(partition, modes).GetResult();
464+
}
465+
466+
/** <inheritDoc /> */
467+
public Task<long> GetSizeLongAsync(params CachePeekMode[] modes)
468+
{
469+
return _cache.GetSizeLongAsync(modes);
470+
}
471+
472+
/** <inheritDoc /> */
473+
public Task<long> GetSizeLongAsync(int partition, params CachePeekMode[] modes)
474+
{
475+
return _cache.GetSizeLongAsync(partition, modes);
476+
}
477+
478+
/** <inheritDoc /> */
479+
public long GetLocalSizeLong(params CachePeekMode[] modes)
480+
{
481+
return _cache.GetLocalSizeLong(modes);
482+
}
483+
484+
/** <inheritDoc /> */
485+
public long GetLocalSizeLong(int partition, params CachePeekMode[] modes)
486+
{
487+
return _cache.GetLocalSizeLong(partition, modes);
488+
}
489+
454490
/** <inheritDoc /> */
455491
public IQueryCursor<ICacheEntry<TK, TV>> Query(QueryBase qry)
456492
{
@@ -597,7 +633,7 @@ public void ResetQueryMetrics()
597633

598634
public void PreloadPartition(int partition)
599635
{
600-
_cache.PreloadPartition(partition);
636+
_cache.PreloadPartitionAsync(partition).WaitResult();
601637
}
602638

603639
public Task PreloadPartitionAsync(int partition)

modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/DataRegionMetricsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ private static IIgnite StartIgniteWithThreeDataRegions()
222222
cacheWithMetricsAndPersistence.Put(1, 1);
223223
cacheWithMetricsAndPersistence.Get(1);
224224

225-
// Wait for checkpoint.
226-
Thread.Sleep(CheckpointFrequency);
225+
// Wait for checkpoint. Wait for two times than CheckpointFrequency.
226+
Thread.Sleep(CheckpointFrequency.Add(CheckpointFrequency));
227227

228228
return ignite;
229229
}

modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ public void TestLoadCacheAsync()
182182
var cache = GetCache();
183183

184184
Assert.AreEqual(0, cache.GetSize());
185+
Assert.AreEqual(0, cache.GetSizeLongAsync().Result);
185186

186187
cache.LocalLoadCacheAsync(new CacheEntryFilter(), 100, 10).Wait();
187188

188189
Assert.AreEqual(5, cache.GetSizeAsync().Result);
190+
Assert.AreEqual(5, cache.GetSizeLongAsync().Result);
189191

190192
for (int i = 105; i < 110; i++)
191193
{

modules/platforms/dotnet/Apache.Ignite.Core/Cache/ICache.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,59 @@ public interface ICache<TK, TV> : IEnumerable<ICacheEntry<TK, TV>>
705705
/// <returns>Cache size across all nodes.</returns>
706706
Task<int> GetSizeAsync(params CachePeekMode[] modes);
707707

708+
/// <summary>
709+
/// Gets the number of all entries cached across all nodes as long value.
710+
/// <para />
711+
/// NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
712+
/// </summary>
713+
/// <param name="modes">Optional peek modes. If not provided, then total cache size is returned.</param>
714+
/// <returns>Cache size across all nodes.</returns>
715+
long GetSizeLong(params CachePeekMode[] modes);
716+
717+
/// <summary>
718+
/// Gets the number of all entries in partition cached across all nodes as long value.
719+
/// <para />
720+
/// NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
721+
/// </summary>
722+
/// <param name="partition">Cache partition.</param>
723+
/// <param name="modes">Optional peek modes. If not provided, then total cache size is returned.</param>
724+
/// <returns>Partition cache size across all nodes.</returns>>
725+
long GetSizeLong(int partition, params CachePeekMode[] modes);
726+
727+
/// <summary>
728+
/// Gets the number of all entries cached across all nodes as long value.
729+
/// <para />
730+
/// NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
731+
/// </summary>
732+
/// <param name="modes">Optional peek modes. If not provided, then total cache size is returned.</param>
733+
/// <returns>Cache size across all nodes.</returns>
734+
Task<long> GetSizeLongAsync(params CachePeekMode[] modes);
735+
736+
/// <summary>
737+
/// Gets the number of all entries in a partition cached across all nodes as long value.
738+
/// <para />
739+
/// NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
740+
/// </summary>
741+
/// <param name="partition">Cache partition.</param>
742+
/// <param name="modes">Optional peek modes. If not provided, then total cache size is returned.</param>
743+
/// <returns>Partition cache size across all nodes.</returns>
744+
Task<long> GetSizeLongAsync(int partition, params CachePeekMode[] modes);
745+
746+
/// <summary>
747+
/// Gets the number of all entries cached on this node as long value.
748+
/// </summary>
749+
/// <param name="modes">Optional peek modes. If not provided, then total cache size is returned.</param>
750+
/// <returns>Cache size on this node.</returns>
751+
long GetLocalSizeLong(params CachePeekMode[] modes);
752+
753+
/// <summary>
754+
/// Gets the number of all entries in a partition cached on this node as long value.
755+
/// </summary>
756+
/// <param name="partition">Cache partition.</param>
757+
/// <param name="modes">Optional peek modes. If not provided, then total cache size is returned.</param>
758+
/// <returns>Partition cache size on this node.</returns>
759+
long GetLocalSizeLong(int partition, params CachePeekMode[] modes);
760+
708761
/// <summary>
709762
/// Queries cache.
710763
/// </summary>

0 commit comments

Comments
 (0)