sanpwc commented on code in PR #2825:
URL: https://github.com/apache/ignite-3/pull/2825#discussion_r1395753475


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -690,21 +689,23 @@ private void processOperation(ChannelHandlerContext ctx, 
ClientMessageUnpacker i
     }
 
     private void writeFlags(ClientMessagePacker out, ChannelHandlerContext 
ctx) {
-        boolean assignmentChanged = 
partitionAssignmentChanged.compareAndSet(true, false);
-
-        if (assignmentChanged && LOG.isInfoEnabled()) {
-            LOG.info("Partition assignment changed, notifying client 
[connectionId=" + connectionId + ", remoteAddress="
+        // Notify the client about primary replica change that happened for 
ANY table since the last request.
+        // We can't assume that the client only uses uses a particular table 
(e.g. the one present in the replica tracker), because
+        // the client can be connected to multiple nodes.
+        long localUpdateCount = primaryReplicaUpdateCount.get();
+        long updateCount = primaryReplicaTracker.updateCount();
+        boolean primaryReplicasChanged = localUpdateCount < updateCount
+                && primaryReplicaUpdateCount.compareAndSet(localUpdateCount, 
updateCount);
+
+        if (primaryReplicasChanged && LOG.isInfoEnabled()) {
+            LOG.info("Partition primary replica changed, notifying client 
[connectionId=" + connectionId + ", remoteAddress="
                     + ctx.channel().remoteAddress() + ']');
         }
 
-        var flags = ResponseFlags.getFlags(assignmentChanged);
+        var flags = ResponseFlags.getFlags(primaryReplicasChanged);

Review Comment:
   Ok, in that case, like we've discussed in person it's required to use some 
linearisable "counter" e.g. timestamp as you've proposed. And probably such 
counter should go to the client and backwards in order to handle races within 
multi-connections. 



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