vldpyatkov commented on code in PR #3213:
URL: https://github.com/apache/ignite-3/pull/3213#discussion_r1507419119


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/RemotelyTriggeredResourceRegistry.java:
##########
@@ -86,29 +100,84 @@ public void close(UUID contextId) throws 
ResourceCloseException {
 
         Set<FullyQualifiedResourceId> closedResources = new HashSet<>();
 
+        // We assume that the resources of the same context are triggered by 
the same remote host.
+        String remoteHostId = null;
+
         for (Entry<FullyQualifiedResourceId, RemotelyTriggeredResource> entry 
: resourcesWithContext.entrySet()) {
             try {
                 entry.getValue().resource.close();
 
                 closedResources.add(entry.getKey());
+
+                if (remoteHostId == null) {
+                    remoteHostId = entry.getValue().remoteHostId();
+                }
+
+                assert remoteHostId.equals(entry.getValue().remoteHostId()) : 
"Resources of the same context triggered by different remote "
+                        + "hosts [" + remoteHostId + ", " + 
entry.getValue().remoteHostId() + "].";
             } catch (Exception e) {
                 if (ex == null) {
-                    ex = new ResourceCloseException("Close resource 
exception.", entry.getKey(), e);
+                    ex = new ResourceCloseException(entry.getKey(), 
entry.getValue().remoteHostId(), e);
                 } else {
                     ex.addSuppressed(e);
                 }
             }
         }
 
-        resourcesWithContext.keySet().removeAll(closedResources);
+        if (!closedResources.isEmpty()) {
+            assert remoteHostId != null : "Remote host is null, resources=" + 
resourcesWithContext;
+
+            for (FullyQualifiedResourceId resourceId : closedResources) {
+                resourcesWithContext.remove(resourceId);
+
+                remoteRemoteHostResource(remoteHostId, resourceId);
+            }
+        }
 
         if (ex != null) {
             throw ex;
         }
     }
 
+    /**
+     * Close all resources created by the given remote host.
+     *
+     * @param remoteHostId Remote host inconsistent id.
+     */
+    public void close(String remoteHostId) {
+        Set<FullyQualifiedResourceId> resourceIds = 
remoteHostsToResources.get(remoteHostId);
+
+        for (FullyQualifiedResourceId resourceId : resourceIds) {
+            try {
+                close(resourceId);
+            } catch (Exception e) {
+                LOG.warn("Exception occurred during the orphan resource 
closing.", e);

Review Comment:
   Add resource id in the message



-- 
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]

Reply via email to