Mmuzaf commented on code in PR #10140:
URL: https://github.com/apache/ignite/pull/10140#discussion_r941192895
##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientCacheAffinityContext.java:
##########
@@ -126,26 +141,50 @@ public synchronized boolean
readPartitionsUpdateResponse(PayloadInputChannel ch)
if (lastTop.get() == null)
return false;
- ClientCacheAffinityMapping newMapping =
ClientCacheAffinityMapping.readResponse(ch);
+ CacheMappingRequest rq0 = rq;
+
+ ClientCacheAffinityMapping newMapping =
ClientCacheAffinityMapping.readResponse(ch,
+ new Function<Integer, Function<Integer,
ClientPartitionAwarenessMapper>>() {
+ @Override public Function<Integer,
ClientPartitionAwarenessMapper> apply(Integer cacheId) {
+ synchronized (cacheKeyMapperFactoryMap) {
+ ClientPartitionAwarenessMapperHolder hld =
cacheKeyMapperFactoryMap.get(cacheId);
+
+ // Factory concurrently removed on cache destroy.
+ if (hld == null || hld.ts == REMOVED_TS)
+ return null;
+
+ return hld.factory;
+ }
+ }
+ }
+ );
+
+ // Clean up outdated factories.
+ rq0.caches.removeAll(newMapping.cacheIds());
+
+ synchronized (cacheKeyMapperFactoryMap) {
+ cacheKeyMapperFactoryMap.entrySet()
+ .removeIf(e -> rq0.caches.contains(e.getKey())
+ && e.getValue().ts <= rq0.ts);
+ }
+
+ rq = null;
ClientCacheAffinityMapping oldMapping = affinityMapping;
- if (oldMapping == null ||
newMapping.topologyVersion().compareTo(oldMapping.topologyVersion()) > 0) {
+ if (oldMapping == null || newMapping.compareTo(oldMapping) > 0) {
affinityMapping = newMapping;
+ // Re-request mappings that are out of date.
if (oldMapping != null)
pendingCacheIds.addAll(oldMapping.cacheIds());
- pendingCacheIds.removeAll(newMapping.cacheIds());
Review Comment:
Fixed.
##########
modules/core/src/test/java/org/apache/ignite/internal/client/thin/ThinClientPartitionAwarenessResourceReleaseTest.java:
##########
@@ -55,6 +63,81 @@ public void testResourcesReleasedAfterClientClosed() throws
Exception {
assertTrue(GridTestUtils.waitForCondition(() ->
threadsCount(THREAD_PREFIX) == 0, 1_000L));
}
+ /**
+ * @throws Exception If fails.
+ */
+ @Test
+ public void testResourcesReleasedAfterCacheDestroyed() throws Exception {
+ int cacheId = CU.cacheId(PART_CUSTOM_AFFINITY_CACHE_NAME);
+ startGrids(2);
+
+ initClient(getClientConfiguration(0, 1)
+ .setPartitionAwarenessMapperFactory(new
ClientPartitionAwarenessMapperFactory() {
+ /** {@inheritDoc} */
+ @Override public ClientPartitionAwarenessMapper create(String
cacheName, int partitions) {
+ assertEquals(cacheName, PART_CUSTOM_AFFINITY_CACHE_NAME);
+
+ AffinityFunction aff = new
RendezvousAffinityFunction(false, partitions);
+
+ return aff::partition;
+ }
+ }), 0, 1);
+
+ ClientCache<Object, Object> clientCache =
client.cache(PART_CUSTOM_AFFINITY_CACHE_NAME);
+ IgniteInternalCache<Object, Object> gridCache =
grid(0).context().cache().cache(PART_CUSTOM_AFFINITY_CACHE_NAME);
+
+ clientCache.put(0, 0);
+ TestTcpClientChannel opCh = affinityChannel(0, gridCache);
+
+ assertOpOnChannel(dfltCh, ClientOperation.CACHE_PARTITIONS);
+ assertOpOnChannel(opCh, ClientOperation.CACHE_PUT);
+
+ for (int i = 1; i < KEY_CNT; i++)
+ clientCache.put(i, i);
+
+ ClientCacheAffinityContext affCtx = clientAffinityContext(client);
+ AffinityTopologyVersion ver =
affCtx.currentMapping().topologyVersion();
+
+ grid(0).destroyCache(PART_CUSTOM_AFFINITY_CACHE_NAME);
+ awaitPartitionMapExchange();
+
+ // Cache destroyed, but mappings still exist on the client side.
+ assertEquals(opCh.serverNodeId(), affCtx.affinityNode(cacheId,
Integer.valueOf(0)));
+
+ client.cache(PART_CACHE_NAME).put(1, 1);
+
+ // await mappings updated.
+ assertTrue(GridTestUtils.waitForCondition(() -> {
+ ClientCacheAffinityMapping m = affCtx.currentMapping();
+
+ if (m == null)
+ return false;
+
+ return m.topologyVersion().equals(ver.nextMinorVersion());
+ }, 5_000L));
+
+ assertNull(affCtx.currentMapping().affinityNode(cacheId, 0));
Review Comment:
Fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]